linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] watchdog: sp805: add restart handler
@ 2018-04-30  6:44 Jongsung Kim
  2018-04-30 11:18 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Jongsung Kim @ 2018-04-30  6:44 UTC (permalink / raw)
  To: Viresh Kumar, Wim Van Sebroeck, linux-watchdog, linux-kernel
  Cc: Chanho Min, Jongsung Kim

Add restart handler for SP805 watchdog so that the driver can be
used to reboot the system.

Signed-off-by: Jongsung Kim <neidhard.kim@lge.com>
---
 drivers/watchdog/sp805_wdt.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
index 01d816251302..01f7b6c29f92 100644
--- a/drivers/watchdog/sp805_wdt.c
+++ b/drivers/watchdog/sp805_wdt.c
@@ -23,6 +23,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/pm.h>
+#include <linux/reboot.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/types.h>
@@ -67,6 +68,7 @@ struct sp805_wdt {
 	struct clk			*clk;
 	struct amba_device		*adev;
 	unsigned int			load_val;
+	struct notifier_block		restart;
 };
 
 static bool nowayout = WATCHDOG_NOWAYOUT;
@@ -200,6 +202,18 @@ static const struct watchdog_ops wdt_ops = {
 	.get_timeleft	= wdt_timeleft,
 };
 
+static int
+wdt_restart(struct notifier_block *this, unsigned long mode, void *cmd)
+{
+	struct sp805_wdt *wdt = container_of(this, struct sp805_wdt, restart);
+
+	writel_relaxed(0, wdt->base + WDTCONTROL);
+	writel_relaxed(0, wdt->base + WDTLOAD);
+	writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL);
+
+	return 0;
+}
+
 static int
 sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
 {
@@ -241,6 +255,10 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
 	}
 	amba_set_drvdata(adev, wdt);
 
+	wdt->restart.notifier_call = wdt_restart;
+	wdt->restart.priority = 128;
+	register_restart_handler(&wdt->restart);
+
 	dev_info(&adev->dev, "registration successful\n");
 	return 0;
 
@@ -253,6 +271,7 @@ static int sp805_wdt_remove(struct amba_device *adev)
 {
 	struct sp805_wdt *wdt = amba_get_drvdata(adev);
 
+	unregister_restart_handler(&wdt->restart);
 	watchdog_unregister_device(&wdt->wdd);
 	watchdog_set_drvdata(&wdt->wdd, NULL);
 
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] watchdog: sp805: add restart handler
  2018-04-30  6:44 [PATCH] watchdog: sp805: add restart handler Jongsung Kim
@ 2018-04-30 11:18 ` Guenter Roeck
  2018-05-02  7:55   ` Jongsung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2018-04-30 11:18 UTC (permalink / raw)
  To: Jongsung Kim, Viresh Kumar, Wim Van Sebroeck, linux-watchdog,
	linux-kernel
  Cc: Chanho Min

On 04/29/2018 11:44 PM, Jongsung Kim wrote:
> Add restart handler for SP805 watchdog so that the driver can be
> used to reboot the system.
> 
> Signed-off-by: Jongsung Kim <neidhard.kim@lge.com>
> ---
>   drivers/watchdog/sp805_wdt.c | 19 +++++++++++++++++++
>   1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
> index 01d816251302..01f7b6c29f92 100644
> --- a/drivers/watchdog/sp805_wdt.c
> +++ b/drivers/watchdog/sp805_wdt.c
> @@ -23,6 +23,7 @@
>   #include <linux/module.h>
>   #include <linux/moduleparam.h>
>   #include <linux/pm.h>
> +#include <linux/reboot.h>
>   #include <linux/slab.h>
>   #include <linux/spinlock.h>
>   #include <linux/types.h>
> @@ -67,6 +68,7 @@ struct sp805_wdt {
>   	struct clk			*clk;
>   	struct amba_device		*adev;
>   	unsigned int			load_val;
> +	struct notifier_block		restart;
>   };
>   
>   static bool nowayout = WATCHDOG_NOWAYOUT;
> @@ -200,6 +202,18 @@ static const struct watchdog_ops wdt_ops = {
>   	.get_timeleft	= wdt_timeleft,
>   };
>   
> +static int
> +wdt_restart(struct notifier_block *this, unsigned long mode, void *cmd)
> +{
> +	struct sp805_wdt *wdt = container_of(this, struct sp805_wdt, restart);
> +
> +	writel_relaxed(0, wdt->base + WDTCONTROL);
> +	writel_relaxed(0, wdt->base + WDTLOAD);
> +	writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL);
> +
> +	return 0;
> +}
> +
>   static int
>   sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
>   {
> @@ -241,6 +255,10 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
>   	}
>   	amba_set_drvdata(adev, wdt);
>   
> +	wdt->restart.notifier_call = wdt_restart;
> +	wdt->restart.priority = 128;
> +	register_restart_handler(&wdt->restart);
> +

Why not use the watchdog core ?

Guenter

>   	dev_info(&adev->dev, "registration successful\n");
>   	return 0;
>   
> @@ -253,6 +271,7 @@ static int sp805_wdt_remove(struct amba_device *adev)
>   {
>   	struct sp805_wdt *wdt = amba_get_drvdata(adev);
>   
> +	unregister_restart_handler(&wdt->restart);
>   	watchdog_unregister_device(&wdt->wdd);
>   	watchdog_set_drvdata(&wdt->wdd, NULL);
>   
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] watchdog: sp805: add restart handler
  2018-04-30 11:18 ` Guenter Roeck
@ 2018-05-02  7:55   ` Jongsung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Jongsung Kim @ 2018-05-02  7:55 UTC (permalink / raw)
  To: Guenter Roeck, Viresh Kumar, Wim Van Sebroeck, linux-watchdog,
	linux-kernel
  Cc: Chanho Min

On 04/30/2018 08:18 PM, Guenter Roeck wrote:
> On 04/29/2018 11:44 PM, Jongsung Kim wrote:
>> Add restart handler for SP805 watchdog so that the driver can be
>> used to reboot the system.
>>
>> Signed-off-by: Jongsung Kim <neidhard.kim@lge.com>
>> ---
>>   drivers/watchdog/sp805_wdt.c | 19 +++++++++++++++++++
>>   1 file changed, 19 insertions(+)
>>
>> diff --git a/drivers/watchdog/sp805_wdt.c b/drivers/watchdog/sp805_wdt.c
>> index 01d816251302..01f7b6c29f92 100644
>> --- a/drivers/watchdog/sp805_wdt.c
>> +++ b/drivers/watchdog/sp805_wdt.c
>> @@ -23,6 +23,7 @@
>>   #include <linux/module.h>
>>   #include <linux/moduleparam.h>
>>   #include <linux/pm.h>
>> +#include <linux/reboot.h>
>>   #include <linux/slab.h>
>>   #include <linux/spinlock.h>
>>   #include <linux/types.h>
>> @@ -67,6 +68,7 @@ struct sp805_wdt {
>>       struct clk            *clk;
>>       struct amba_device        *adev;
>>       unsigned int            load_val;
>> +    struct notifier_block        restart;
>>   };
>>     static bool nowayout = WATCHDOG_NOWAYOUT;
>> @@ -200,6 +202,18 @@ static const struct watchdog_ops wdt_ops = {
>>       .get_timeleft    = wdt_timeleft,
>>   };
>>   +static int
>> +wdt_restart(struct notifier_block *this, unsigned long mode, void *cmd)
>> +{
>> +    struct sp805_wdt *wdt = container_of(this, struct sp805_wdt, restart);
>> +
>> +    writel_relaxed(0, wdt->base + WDTCONTROL);
>> +    writel_relaxed(0, wdt->base + WDTLOAD);
>> +    writel_relaxed(INT_ENABLE | RESET_ENABLE, wdt->base + WDTCONTROL);
>> +
>> +    return 0;
>> +}
>> +
>>   static int
>>   sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
>>   {
>> @@ -241,6 +255,10 @@ sp805_wdt_probe(struct amba_device *adev, const struct amba_id *id)
>>       }
>>       amba_set_drvdata(adev, wdt);
>>   +    wdt->restart.notifier_call = wdt_restart;
>> +    wdt->restart.priority = 128;
>> +    register_restart_handler(&wdt->restart);
>> +
>
> Why not use the watchdog core ?

Thank you for pointing this. I didn't noticed core changes about restart function because I'm still using old v4.4.xx..

>
> Guenter
>
>>       dev_info(&adev->dev, "registration successful\n");
>>       return 0;
>>   @@ -253,6 +271,7 @@ static int sp805_wdt_remove(struct amba_device *adev)
>>   {
>>       struct sp805_wdt *wdt = amba_get_drvdata(adev);
>>   +    unregister_restart_handler(&wdt->restart);
>>       watchdog_unregister_device(&wdt->wdd);
>>       watchdog_set_drvdata(&wdt->wdd, NULL);
>>  
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-02  7:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-30  6:44 [PATCH] watchdog: sp805: add restart handler Jongsung Kim
2018-04-30 11:18 ` Guenter Roeck
2018-05-02  7:55   ` Jongsung Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).