linux-watchdog.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] watchdog: meson: keep running if already active
@ 2022-08-01  9:21 Philippe Boos
  2022-08-08 11:58 ` Guenter Roeck
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Philippe Boos @ 2022-08-01  9:21 UTC (permalink / raw)
  To: Wim Van Sebroeck, Guenter Roeck, Neil Armstrong
  Cc: Philippe Boos, Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	open list:WATCHDOG DEVICE DRIVERS,
	moderated list:ARM/Amlogic Meson SoC support,
	open list:ARM/Amlogic Meson SoC support, open list

If the watchdog is already running (e.g.: started by bootloader) then
the kernel driver should keep the watchdog active but the amlogic driver
turns it off.

Let the driver fix the clock rate if already active because we do not
know the previous timebase value. To avoid unintentional resetting we
temporarily set it to its maximum value.

Then keep the enable bit if is was previously active.

Signed-off-by: Philippe Boos <pboos@baylibre.com>
---
 drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
index 5a9ca10fbcfa..8be8fd9e5637 100644
--- a/drivers/watchdog/meson_gxbb_wdt.c
+++ b/drivers/watchdog/meson_gxbb_wdt.c
@@ -146,6 +146,7 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct meson_gxbb_wdt *data;
 	int ret;
+	u32 ctrl_reg;
 
 	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -177,13 +178,26 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
 	data->wdt_dev.timeout = DEFAULT_TIMEOUT;
 	watchdog_set_drvdata(&data->wdt_dev, data);
 
+	ctrl_reg = readl(data->reg_base + GXBB_WDT_CTRL_REG) &
+				GXBB_WDT_CTRL_EN;
+
+	if (ctrl_reg) {
+		/* Watchdog is running - keep it running but extend timeout
+		 * to the maximum while setting the timebase
+		 */
+		set_bit(WDOG_HW_RUNNING, &data->wdt_dev.status);
+		meson_gxbb_wdt_set_timeout(&data->wdt_dev,
+				GXBB_WDT_TCNT_SETUP_MASK / 1000);
+	}
+
 	/* Setup with 1ms timebase */
-	writel(((clk_get_rate(data->clk) / 1000) & GXBB_WDT_CTRL_DIV_MASK) |
-		GXBB_WDT_CTRL_EE_RESET |
-		GXBB_WDT_CTRL_CLK_EN |
-		GXBB_WDT_CTRL_CLKDIV_EN,
-		data->reg_base + GXBB_WDT_CTRL_REG);
+	ctrl_reg |= ((clk_get_rate(data->clk) / 1000) &
+			GXBB_WDT_CTRL_DIV_MASK) |
+			GXBB_WDT_CTRL_EE_RESET |
+			GXBB_WDT_CTRL_CLK_EN |
+			GXBB_WDT_CTRL_CLKDIV_EN;
 
+	writel(ctrl_reg, data->reg_base + GXBB_WDT_CTRL_REG);
 	meson_gxbb_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
 
 	watchdog_stop_on_reboot(&data->wdt_dev);
-- 
2.20.1


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

* Re: [PATCH v2] watchdog: meson: keep running if already active
  2022-08-01  9:21 [PATCH v2] watchdog: meson: keep running if already active Philippe Boos
@ 2022-08-08 11:58 ` Guenter Roeck
  2022-08-11 14:03   ` Philippe Boos
  2022-09-06 12:21 ` Jerome Brunet
  2022-09-25 15:40 ` Guenter Roeck
  2 siblings, 1 reply; 5+ messages in thread
From: Guenter Roeck @ 2022-08-08 11:58 UTC (permalink / raw)
  To: Philippe Boos, Wim Van Sebroeck, Neil Armstrong
  Cc: Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	open list:WATCHDOG DEVICE DRIVERS,
	moderated list:ARM/Amlogic Meson SoC support,
	open list:ARM/Amlogic Meson SoC support, open list

On 8/1/22 02:21, Philippe Boos wrote:
> If the watchdog is already running (e.g.: started by bootloader) then
> the kernel driver should keep the watchdog active but the amlogic driver
> turns it off.
> 
> Let the driver fix the clock rate if already active because we do not
> know the previous timebase value. To avoid unintentional resetting we
> temporarily set it to its maximum value.
> 
> Then keep the enable bit if is was previously active.
> 
> Signed-off-by: Philippe Boos <pboos@baylibre.com>

What changed since v1 ?

Guenter

> ---
>   drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++-----
>   1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
> index 5a9ca10fbcfa..8be8fd9e5637 100644
> --- a/drivers/watchdog/meson_gxbb_wdt.c
> +++ b/drivers/watchdog/meson_gxbb_wdt.c
> @@ -146,6 +146,7 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>   	struct device *dev = &pdev->dev;
>   	struct meson_gxbb_wdt *data;
>   	int ret;
> +	u32 ctrl_reg;
>   
>   	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
>   	if (!data)
> @@ -177,13 +178,26 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>   	data->wdt_dev.timeout = DEFAULT_TIMEOUT;
>   	watchdog_set_drvdata(&data->wdt_dev, data);
>   
> +	ctrl_reg = readl(data->reg_base + GXBB_WDT_CTRL_REG) &
> +				GXBB_WDT_CTRL_EN;
> +
> +	if (ctrl_reg) {
> +		/* Watchdog is running - keep it running but extend timeout
> +		 * to the maximum while setting the timebase
> +		 */
> +		set_bit(WDOG_HW_RUNNING, &data->wdt_dev.status);
> +		meson_gxbb_wdt_set_timeout(&data->wdt_dev,
> +				GXBB_WDT_TCNT_SETUP_MASK / 1000);
> +	}
> +
>   	/* Setup with 1ms timebase */
> -	writel(((clk_get_rate(data->clk) / 1000) & GXBB_WDT_CTRL_DIV_MASK) |
> -		GXBB_WDT_CTRL_EE_RESET |
> -		GXBB_WDT_CTRL_CLK_EN |
> -		GXBB_WDT_CTRL_CLKDIV_EN,
> -		data->reg_base + GXBB_WDT_CTRL_REG);
> +	ctrl_reg |= ((clk_get_rate(data->clk) / 1000) &
> +			GXBB_WDT_CTRL_DIV_MASK) |
> +			GXBB_WDT_CTRL_EE_RESET |
> +			GXBB_WDT_CTRL_CLK_EN |
> +			GXBB_WDT_CTRL_CLKDIV_EN;
>   
> +	writel(ctrl_reg, data->reg_base + GXBB_WDT_CTRL_REG);
>   	meson_gxbb_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
>   
>   	watchdog_stop_on_reboot(&data->wdt_dev);


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

* Re: [PATCH v2] watchdog: meson: keep running if already active
  2022-08-08 11:58 ` Guenter Roeck
@ 2022-08-11 14:03   ` Philippe Boos
  0 siblings, 0 replies; 5+ messages in thread
From: Philippe Boos @ 2022-08-11 14:03 UTC (permalink / raw)
  To: Guenter Roeck, Wim Van Sebroeck, Neil Armstrong
  Cc: Kevin Hilman, Jerome Brunet, Martin Blumenstingl,
	open list:WATCHDOG DEVICE DRIVERS,
	moderated list:ARM/Amlogic Meson SoC support,
	open list:ARM/Amlogic Meson SoC support, open list

On 8/8/22 13:58, Guenter Roeck wrote:
> On 8/1/22 02:21, Philippe Boos wrote:
>> If the watchdog is already running (e.g.: started by bootloader) then
>> the kernel driver should keep the watchdog active but the amlogic driver
>> turns it off.
>>
>> Let the driver fix the clock rate if already active because we do not
>> know the previous timebase value. To avoid unintentional resetting we
>> temporarily set it to its maximum value.
>>
>> Then keep the enable bit if is was previously active.
>>
>> Signed-off-by: Philippe Boos <pboos@baylibre.com>
> 
> What changed since v1 ?
In v1, we read watchdog's enable bit before writing its config register,
then we write the register, this will always stop the watchdog. If it
was previously active we restart it. So, in v1, if the kernel crashes
just before the watchdog restarts it will be stuck forever.

In v2, we read watchdog's enable bit before writing its config register,
if it is already active we keep the enable bit when writing the
register.

Regards,

Philippe Boos
> 
> Guenter
> 
>> ---
>>   drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++-----
>>   1 file changed, 19 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
>> index 5a9ca10fbcfa..8be8fd9e5637 100644
>> --- a/drivers/watchdog/meson_gxbb_wdt.c
>> +++ b/drivers/watchdog/meson_gxbb_wdt.c
>> @@ -146,6 +146,7 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>>       struct device *dev = &pdev->dev;
>>       struct meson_gxbb_wdt *data;
>>       int ret;
>> +    u32 ctrl_reg;
>>         data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
>>       if (!data)
>> @@ -177,13 +178,26 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>>       data->wdt_dev.timeout = DEFAULT_TIMEOUT;
>>       watchdog_set_drvdata(&data->wdt_dev, data);
>>   +    ctrl_reg = readl(data->reg_base + GXBB_WDT_CTRL_REG) &
>> +                GXBB_WDT_CTRL_EN;
>> +
>> +    if (ctrl_reg) {
>> +        /* Watchdog is running - keep it running but extend timeout
>> +         * to the maximum while setting the timebase
>> +         */
>> +        set_bit(WDOG_HW_RUNNING, &data->wdt_dev.status);
>> +        meson_gxbb_wdt_set_timeout(&data->wdt_dev,
>> +                GXBB_WDT_TCNT_SETUP_MASK / 1000);
>> +    }
>> +
>>       /* Setup with 1ms timebase */
>> -    writel(((clk_get_rate(data->clk) / 1000) & GXBB_WDT_CTRL_DIV_MASK) |
>> -        GXBB_WDT_CTRL_EE_RESET |
>> -        GXBB_WDT_CTRL_CLK_EN |
>> -        GXBB_WDT_CTRL_CLKDIV_EN,
>> -        data->reg_base + GXBB_WDT_CTRL_REG);
>> +    ctrl_reg |= ((clk_get_rate(data->clk) / 1000) &
>> +            GXBB_WDT_CTRL_DIV_MASK) |
>> +            GXBB_WDT_CTRL_EE_RESET |
>> +            GXBB_WDT_CTRL_CLK_EN |
>> +            GXBB_WDT_CTRL_CLKDIV_EN;
>>   +    writel(ctrl_reg, data->reg_base + GXBB_WDT_CTRL_REG);
>>       meson_gxbb_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
>>         watchdog_stop_on_reboot(&data->wdt_dev);
> 


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

* Re: [PATCH v2] watchdog: meson: keep running if already active
  2022-08-01  9:21 [PATCH v2] watchdog: meson: keep running if already active Philippe Boos
  2022-08-08 11:58 ` Guenter Roeck
@ 2022-09-06 12:21 ` Jerome Brunet
  2022-09-25 15:40 ` Guenter Roeck
  2 siblings, 0 replies; 5+ messages in thread
From: Jerome Brunet @ 2022-09-06 12:21 UTC (permalink / raw)
  To: Philippe Boos, Wim Van Sebroeck, Guenter Roeck, Neil Armstrong
  Cc: Kevin Hilman, Martin Blumenstingl,
	open list:WATCHDOG DEVICE DRIVERS,
	moderated list:ARM/Amlogic Meson SoC support,
	open list:ARM/Amlogic Meson SoC support, open list


On Mon 01 Aug 2022 at 11:21, Philippe Boos <pboos@baylibre.com> wrote:

> If the watchdog is already running (e.g.: started by bootloader) then
> the kernel driver should keep the watchdog active but the amlogic driver
> turns it off.
>
> Let the driver fix the clock rate if already active because we do not
> know the previous timebase value. To avoid unintentional resetting we
> temporarily set it to its maximum value.
>
> Then keep the enable bit if is was previously active.
>
> Signed-off-by: Philippe Boos <pboos@baylibre.com>

Reviewed-by: Jerome Brunet <jbrunet@baylibre.com>

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

* Re: [PATCH v2] watchdog: meson: keep running if already active
  2022-08-01  9:21 [PATCH v2] watchdog: meson: keep running if already active Philippe Boos
  2022-08-08 11:58 ` Guenter Roeck
  2022-09-06 12:21 ` Jerome Brunet
@ 2022-09-25 15:40 ` Guenter Roeck
  2 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2022-09-25 15:40 UTC (permalink / raw)
  To: Philippe Boos
  Cc: Wim Van Sebroeck, Neil Armstrong, Kevin Hilman, Jerome Brunet,
	Martin Blumenstingl, open list:WATCHDOG DEVICE DRIVERS,
	moderated list:ARM/Amlogic Meson SoC support,
	open list:ARM/Amlogic Meson SoC support, open list

On Mon, Aug 01, 2022 at 11:21:50AM +0200, Philippe Boos wrote:
> If the watchdog is already running (e.g.: started by bootloader) then
> the kernel driver should keep the watchdog active but the amlogic driver
> turns it off.
> 
> Let the driver fix the clock rate if already active because we do not
> know the previous timebase value. To avoid unintentional resetting we
> temporarily set it to its maximum value.
> 
> Then keep the enable bit if is was previously active.
> 
> Signed-off-by: Philippe Boos <pboos@baylibre.com>
> Reviewed-by: Jerome Brunet <jbrunet@baylibre.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/watchdog/meson_gxbb_wdt.c b/drivers/watchdog/meson_gxbb_wdt.c
> index 5a9ca10fbcfa..8be8fd9e5637 100644
> --- a/drivers/watchdog/meson_gxbb_wdt.c
> +++ b/drivers/watchdog/meson_gxbb_wdt.c
> @@ -146,6 +146,7 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>  	struct device *dev = &pdev->dev;
>  	struct meson_gxbb_wdt *data;
>  	int ret;
> +	u32 ctrl_reg;
>  
>  	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
>  	if (!data)
> @@ -177,13 +178,26 @@ static int meson_gxbb_wdt_probe(struct platform_device *pdev)
>  	data->wdt_dev.timeout = DEFAULT_TIMEOUT;
>  	watchdog_set_drvdata(&data->wdt_dev, data);
>  
> +	ctrl_reg = readl(data->reg_base + GXBB_WDT_CTRL_REG) &
> +				GXBB_WDT_CTRL_EN;
> +
> +	if (ctrl_reg) {
> +		/* Watchdog is running - keep it running but extend timeout
> +		 * to the maximum while setting the timebase
> +		 */
> +		set_bit(WDOG_HW_RUNNING, &data->wdt_dev.status);
> +		meson_gxbb_wdt_set_timeout(&data->wdt_dev,
> +				GXBB_WDT_TCNT_SETUP_MASK / 1000);
> +	}
> +
>  	/* Setup with 1ms timebase */
> -	writel(((clk_get_rate(data->clk) / 1000) & GXBB_WDT_CTRL_DIV_MASK) |
> -		GXBB_WDT_CTRL_EE_RESET |
> -		GXBB_WDT_CTRL_CLK_EN |
> -		GXBB_WDT_CTRL_CLKDIV_EN,
> -		data->reg_base + GXBB_WDT_CTRL_REG);
> +	ctrl_reg |= ((clk_get_rate(data->clk) / 1000) &
> +			GXBB_WDT_CTRL_DIV_MASK) |
> +			GXBB_WDT_CTRL_EE_RESET |
> +			GXBB_WDT_CTRL_CLK_EN |
> +			GXBB_WDT_CTRL_CLKDIV_EN;
>  
> +	writel(ctrl_reg, data->reg_base + GXBB_WDT_CTRL_REG);
>  	meson_gxbb_wdt_set_timeout(&data->wdt_dev, data->wdt_dev.timeout);
>  
>  	watchdog_stop_on_reboot(&data->wdt_dev);

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

end of thread, other threads:[~2022-09-25 15:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01  9:21 [PATCH v2] watchdog: meson: keep running if already active Philippe Boos
2022-08-08 11:58 ` Guenter Roeck
2022-08-11 14:03   ` Philippe Boos
2022-09-06 12:21 ` Jerome Brunet
2022-09-25 15:40 ` Guenter Roeck

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).