From mboxrd@z Thu Jan 1 00:00:00 1970 From: Guenter Roeck Subject: [PATCH v7 09/11] watchdog: s3c2410: add restart handler Date: Tue, 19 Aug 2014 17:45:36 -0700 Message-ID: <1408495538-27480-10-git-send-email-linux@roeck-us.net> References: <1408495538-27480-1-git-send-email-linux@roeck-us.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: In-Reply-To: <1408495538-27480-1-git-send-email-linux@roeck-us.net> Sender: linux-kernel-owner@vger.kernel.org To: Russell King , Wim Van Sebroeck , Catalin Marinas , Maxime Ripard , Andrew Morton Cc: linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-samsung-soc@vger.kernel.org, Will Deacon , Arnd Bergmann , Heiko Stuebner , Jonas Jensen , Randy Dunlap , Steven Rostedt , Ingo Molnar , Dmitry Eremin-Solenikov , David Woodhouse , Tomasz Figa , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Guenter Roeck List-Id: linux-pm@vger.kernel.org =46rom: Heiko St=C3=BCbner On a lot of Samsung systems the watchdog is responsible for restarting = the system and until now this code was contained in plat-samsung/watchdog-r= eset.c. With the introduction of the restart handlers, this code can now move i= nto driver itself, removing the need for arch-specific code. Tested on a S3C2442 based GTA02 Signed-off-by: Heiko Stuebner Signed-off-by: Guenter Roeck --- v7: Added patch to series. drivers/watchdog/s3c2410_wdt.c | 36 ++++++++++++++++++++++++++++++++++= ++ 1 file changed, 36 insertions(+) diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_= wdt.c index 7c6ccd0..2955aef 100644 --- a/drivers/watchdog/s3c2410_wdt.c +++ b/drivers/watchdog/s3c2410_wdt.c @@ -41,6 +41,8 @@ #include #include #include +#include +#include =20 #define S3C2410_WTCON 0x00 #define S3C2410_WTDAT 0x04 @@ -128,6 +130,7 @@ struct s3c2410_wdt { unsigned long wtdat_save; struct watchdog_device wdt_device; struct notifier_block freq_transition; + struct notifier_block restart_handler; struct s3c2410_wdt_variant *drv_data; struct regmap *pmureg; }; @@ -438,6 +441,31 @@ static inline void s3c2410wdt_cpufreq_deregister(s= truct s3c2410_wdt *wdt) } #endif =20 +static int s3c2410wdt_restart(struct notifier_block *this, + unsigned long mode, void *cmd) +{ + struct s3c2410_wdt *wdt =3D container_of(this, struct s3c2410_wdt, + restart_handler); + void __iomem *wdt_base =3D wdt->reg_base; + + /* disable watchdog, to be safe */ + writel(0, wdt_base + S3C2410_WTCON); + + /* put initial values into count and data */ + writel(0x80, wdt_base + S3C2410_WTCNT); + writel(0x80, wdt_base + S3C2410_WTDAT); + + /* set the watchdog to go and reset... */ + writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 | + S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x20), + wdt_base + S3C2410_WTCON); + + /* wait for reset to assert... */ + mdelay(500); + + return NOTIFY_DONE; +} + static inline unsigned int s3c2410wdt_get_bootstatus(struct s3c2410_wd= t *wdt) { unsigned int rst_stat; @@ -592,6 +620,12 @@ static int s3c2410wdt_probe(struct platform_device= *pdev) =20 platform_set_drvdata(pdev, wdt); =20 + wdt->restart_handler.notifier_call =3D s3c2410wdt_restart; + wdt->restart_handler.priority =3D 128; + ret =3D register_restart_handler(&wdt->restart_handler); + if (ret) + pr_err("cannot register restart handler, %d\n", ret); + /* print out a statement of readiness */ =20 wtcon =3D readl(wdt->reg_base + S3C2410_WTCON); @@ -621,6 +655,8 @@ static int s3c2410wdt_remove(struct platform_device= *dev) int ret; struct s3c2410_wdt *wdt =3D platform_get_drvdata(dev); =20 + unregister_restart_handler(&wdt->restart_handler); + ret =3D s3c2410wdt_mask_and_disable_reset(wdt, true); if (ret < 0) return ret; --=20 1.9.1