public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Peng Fan <van.freenix@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH V2 11/20] wdog: Add the watchdog driver for MX7ULP.
Date: Wed, 22 Feb 2017 14:59:46 +0800	[thread overview]
Message-ID: <20170222065945.GB23339@linux-7smt.suse> (raw)
In-Reply-To: <da36cf1a-2ae9-c6ab-6f0c-75cd4ccba625@denx.de>

On Sun, Feb 12, 2017 at 10:25:02AM +0100, Stefano Babic wrote:
>
>
>On 27/12/2016 11:04, Peng Fan wrote:
>> From: Ye Li <ye.li@nxp.com>
>> 
>> This driver implements the HW WATCHDOG functions. Which needs
>> to set CONFIG_HW_WATCHDOG to use them. This is disabled by default for
>> mx7ulp.
>> 
>> Use watchdog for reset cpu. Implement this in the driver.
>> Need to define CONFIG_ULP_WATCHDOG to build it.
>> 
>> Signed-off-by: Peng Fan <peng.fan@nxp.com>
>> Signed-off-by: Ye Li <ye.li@nxp.com>
>> Cc: Stefano Babic <sbabic@denx.de>
>> ---
>> 
>> V2:
>>  Add License
>> 
>>  drivers/watchdog/Kconfig    |  8 ++++
>>  drivers/watchdog/Makefile   |  1 +
>>  drivers/watchdog/ulp_wdog.c | 98 +++++++++++++++++++++++++++++++++++++++++++++
>>  3 files changed, 107 insertions(+)
>>  create mode 100644 drivers/watchdog/ulp_wdog.c
>> 
>> diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
>> index e69de29..dbdaafc 100644
>> --- a/drivers/watchdog/Kconfig
>> +++ b/drivers/watchdog/Kconfig
>> @@ -0,0 +1,8 @@
>> +menu "WATCHDOG support"
>> +
>> +config ULP_WATCHDOG
>> +	bool "i.MX7ULP watchdog"
>> +	help
>> +	  Say Y here to enable i.MX7ULP watchdog driver.
>> +
>> +endmenu
>> diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
>> index a007ae8..dea1836 100644
>> --- a/drivers/watchdog/Makefile
>> +++ b/drivers/watchdog/Makefile
>> @@ -15,3 +15,4 @@ obj-$(CONFIG_XILINX_TB_WATCHDOG) += xilinx_tb_wdt.o
>>  obj-$(CONFIG_BFIN_WATCHDOG)  += bfin_wdt.o
>>  obj-$(CONFIG_OMAP_WATCHDOG) += omap_wdt.o
>>  obj-$(CONFIG_DESIGNWARE_WATCHDOG) += designware_wdt.o
>> +obj-$(CONFIG_ULP_WATCHDOG) += ulp_wdog.o
>> diff --git a/drivers/watchdog/ulp_wdog.c b/drivers/watchdog/ulp_wdog.c
>> new file mode 100644
>> index 0000000..72ec694
>> --- /dev/null
>> +++ b/drivers/watchdog/ulp_wdog.c
>> @@ -0,0 +1,98 @@
>> +/*
>> + * Copyright (C) 2016 Freescale Semiconductor, Inc.
>> + *
>> + * SPDX-License-Identifier:	GPL-2.0+
>> + */
>> +
>> +#include <common.h>
>> +#include <asm/io.h>
>> +#include <asm/arch/imx-regs.h>
>> +
>> +/*
>> + * MX7ULP WDOG Register Map
>> + */
>> +struct wdog_regs {
>> +	u8 cs1;
>> +	u8 cs2;
>> +	u16 reserve0;
>> +	u32 cnt;
>> +	u32 toval;
>> +	u32 win;
>> +};
>> +
>> +#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
>> +#define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500
>> +#endif
>> +
>> +#define REFRESH_WORD0 0xA602 /* 1st refresh word */
>> +#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
>> +
>> +#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
>> +#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
>> +
>> +#define WDGCS1_WDGE                      (1<<7)
>> +#define WDGCS1_WDGUPDATE                 (1<<5)
>> +
>> +#define WDGCS2_FLG                       (1<<6)
>> +
>> +#define WDG_BUS_CLK                      (0x0)
>> +#define WDG_LPO_CLK                      (0x1)
>> +#define WDG_32KHZ_CLK                    (0x2)
>> +#define WDG_EXT_CLK                      (0x3)
>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>> +
>> +void hw_watchdog_set_timeout(u16 val)
>> +{
>> +	/* setting timeout value */
>> +	struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
>> +
>> +	writel(val, &wdog->toval);
>> +}
>> +
>> +void hw_watchdog_reset(void)
>> +{
>> +	struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
>> +
>> +	writel(REFRESH_WORD0, &wdog->cnt);
>> +	writel(REFRESH_WORD1, &wdog->cnt);
>> +}
>> +
>> +void hw_watchdog_init(void)
>> +{
>> +	u8 val;
>> +	struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
>> +
>> +	writel(UNLOCK_WORD0, &wdog->cnt);
>> +	writel(UNLOCK_WORD1, &wdog->cnt);
>> +
>> +	val = readb(&wdog->cs2);
>> +	val |= WDGCS2_FLG;
>> +	writeb(val, &wdog->cs2);
>> +
>> +	hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
>> +	writel(0, &wdog->win);
>> +
>> +	writeb(WDG_LPO_CLK, &wdog->cs2);/* setting 1-kHz clock source */
>> +	writeb((WDGCS1_WDGE | WDGCS1_WDGUPDATE), &wdog->cs1);/* enable counter running */
>> +
>> +	hw_watchdog_reset();
>> +}
>> +
>> +void reset_cpu(ulong addr)
>> +{
>> +	struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
>> +
>> +	writel(UNLOCK_WORD0, &wdog->cnt);
>> +	writel(UNLOCK_WORD1, &wdog->cnt);
>> +
>> +	hw_watchdog_set_timeout(5); /* 5ms timeout */
>> +	writel(0, &wdog->win);
>> +
>> +	writeb(WDG_LPO_CLK, &wdog->cs2);/* setting 1-kHz clock source */
>> +	writeb(WDGCS1_WDGE, &wdog->cs1);/* enable counter running */
>> +
>> +	hw_watchdog_reset();
>> +
>> +	while (1);
>> +}
>> 
>
>This goes into drivers/watchdog, and it slightly differs from the
>implementation in imx-watchdog.c. Code is quite simple, too, I think it
>could be merged into the same file.

I prefer to keep it in different files, the watchdog ip on i.MX7ULP is a different one.
>
>Best regards,
>Stefano Babic
>
>-- 
>=====================================================================
>DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
>HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
>Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
>=====================================================================
>_______________________________________________
>U-Boot mailing list
>U-Boot at lists.denx.de
>http://lists.denx.de/mailman/listinfo/u-boot

  reply	other threads:[~2017-02-22  6:59 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-27 10:04 [U-Boot] [PATCH V2 00/20] imx: add i.MX7ULP support Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 01/20] imx: mx7ulp: Add mx7ulp to Kconfig Peng Fan
2017-02-12  8:39   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 02/20] imx: mx7ulp: add registers header file Peng Fan
2017-02-12  8:40   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 03/20] imx: mx7ulp: add iomux driver to support IOMUXC0 and IOMUXC1 Peng Fan
2017-02-12  8:45   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 04/20] imx: mx7ulp: Add clock framework and functions Peng Fan
2017-02-12  9:12   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 05/20] imx: mx7ulp: Add soc level initialization codes " Peng Fan
2017-02-12  9:19   ` Stefano Babic
2017-02-22  6:48     ` Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 06/20] imx: mx7ulp: handle all the lpuarts in get_lpuart_clk Peng Fan
2017-02-12  9:20   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 07/20] imx: mx7ulp: Implement the clock functions for i2c driver Peng Fan
2017-02-12  9:20   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 08/20] gpio: Add Rapid GPIO2P driver for i.MX7ULP Peng Fan
2017-02-12  9:21   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 09/20] mxc_ocotp: Update driver to support OCOTP controller on i.MX7ULP Peng Fan
2017-02-12  9:22   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 10/20] mx7ulp: Add iomux pins header file Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 11/20] wdog: Add the watchdog driver for MX7ULP Peng Fan
2017-02-12  9:25   ` Stefano Babic
2017-02-22  6:59     ` Peng Fan [this message]
2017-02-22  8:18       ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 12/20] pinctrl: Add i.MX7ULP pinctrl driver Peng Fan
2017-01-12  5:07   ` Simon Glass
2017-02-12  9:25   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 13/20] i2c: lpi2c: add lpi2c driver for i.MX7ULP Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 14/20] serial: lpuart: restructure lpuart driver Peng Fan
2016-12-29  9:28   ` Bhuvanchandra DV
2017-02-12  9:27   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 15/20] serial: lpuart: add i.MX7ULP support Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 16/20] mx7ulp: Add HAB boot support Peng Fan
2017-02-12  9:28   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 17/20] arm: dts: add i.MX7ULP dtsi file Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 18/20] mmc: fsl_esdhc: support i.MX7ULP Peng Fan
2016-12-27 22:17   ` Jaehoon Chung
2017-02-12  9:29   ` Stefano Babic
2016-12-27 10:04 ` [U-Boot] [PATCH V2 19/20] imx: imx7ulp: add EVK board support Peng Fan
2016-12-27 10:04 ` [U-Boot] [PATCH V2 20/20] imx: mx7ulp_evk: enable mmc/regulator support Peng Fan
2016-12-27 11:22   ` Fabio Estevam
2016-12-27 12:07     ` Peng Fan
2017-01-03  9:05       ` Peng Fan
2017-01-12  2:23         ` Peng Fan
2017-01-12  2:24           ` Peng Fan
2017-02-08  8:36 ` [U-Boot] [PATCH V2 00/20] imx: add i.MX7ULP support Peng Fan
2017-02-08 12:16   ` Stefano Babic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170222065945.GB23339@linux-7smt.suse \
    --to=van.freenix@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox