watchdog: meson: keep running if already active
Subsystems (2)
PATCH v2 1/1 watchdog: meson: keep running if already active
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.
--- drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/watchdog/meson_gxbb_wdt.c +19 -5
@@ -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);
Signature · 1 line
2.20.1
Guenter Roeck
maintainerQuoted 11 lines · Philippe Boos
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 <[email protected]>
What changed since v1 ?
Guenter
Quoted 48 lines
--- drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/watchdog/meson_gxbb_wdt.c +19
-5@@ -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);
Quoted 9 lines · Guenter Roeck
Quoted 8 lines · Philippe Boos
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.
Quoted 5 lines
Quoted 3 lines
Then keep the enable bit if is was previously active.
Signed-off-by Philippe Boos <[email protected]>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
Quoted 39 lines
Guenter
Quoted 36 lines
---
drivers/watchdog/meson_gxbb_wdt.c| 24 +++++++++++++++++++-----1 file changed, 19 insertions(+), 5 deletions(-)drivers/watchdog/meson_gxbb_wdt.c +1
-0@@ -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;drivers/watchdog/meson_gxbb_wdt.c +10
-0+ + 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);
Quoted 9 lines
Quoted 8 lines
+
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);
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Quoted 11 lines · Philippe Boos
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 <[email protected]>
_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic
Quoted 4 lines · Philippe Boos
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.
Quoted 8 lines
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 <[email protected]>Reviewed-by Jerome Brunet <[email protected]>
Quoted 48 lines
--- drivers/watchdog/meson_gxbb_wdt.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)drivers/watchdog/meson_gxbb_wdt.c +19
-5@@ -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);