watchdog: da9063: Fix setting/changing timeout
Subsystems (2)
PATCH v2 1/1 watchdog: da9063: Fix setting/changing timeout
The DA9063 watchdog always resets the system when it changes the timeout value after the bootloader (e.g. Barebox) has it already set.
To update the timeout value we have to disable the watchdog, clear the watchdog counter value and write the new timeout value to the watchdog. Clearing the counter value is a feature to be on the safe side, because the data sheet doesn't describe the behaviour of the watchdog counter value after a watchdog disabling-enable-sequence.
The patch is based on Philipp Zabel's <[email protected]> previous patch but doesn't wait 150us because the DA9063 doesn't need this delay.
--- drivers/watchdog/da9063_wdt.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
drivers/watchdog/da9063_wdt.c +31 -2
@@ -45,8 +45,38 @@ static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs)return DA9063_TWDSCALE_MAX ; } +/* +* Writing a '1' to the self-clearing WATCHDOG bit resets the watchdog counter +* value. +*/ +static int _da9063_wdt_reset_timer (struct da9063 *da9063) +{ +return regmap_write (da9063->regmap,DA9063_REG_CONTROL_F , +DA9063_WATCHDOG ); +} +static int _da9063_wdt_set_timeout (struct da9063 *da9063,unsigned int regval) { +int ret; + +/* +* The watchdog trigger a reboot if a timeout value is already +* programmed. Because the timeout value combines two functions in +* one: indicating the counter limit and starting the watchdog. To be +* able to set the watchdog a second time (first time was done by the +* bootloader) disable the watchdog clear the counter value manually and +* set the new timeout value. +*/ + ret =regmap_update_bits (da9063->regmap,DA9063_REG_CONTROL_D , +DA9063_TWDSCALE_MASK ,DA9063_TWDSCALE_DISABLE ); +if (ret) +dev_warn (da9063->dev, +"Failed to disable watchdog before setting new timeout\n" ); + + ret =_da9063_wdt_reset_timer (da9063); +if (ret) +dev_warn (da9063->dev,"Failed to reset watchdog counter\n" ); +return regmap_update_bits (da9063->regmap,DA9063_REG_CONTROL_D ,DA9063_TWDSCALE_MASK , regval); }
@@ -85,8 +115,7 @@ static int da9063_wdt_ping(struct watchdog_device *wdd)struct da9063 *da9063 =watchdog_get_drvdata (wdd);int ret; - ret =regmap_write (da9063->regmap,DA9063_REG_CONTROL_F , -DA9063_WATCHDOG ); + ret =_da9063_wdt_reset_timer (da9063);if (ret)dev_alert (da9063->dev,"Failed to ping the watchdog (err = %d)\n" , ret);
Signature · 1 line
2.17.0
Hi Marco,
Quoted 6 lines · Marco Felsch
To: [email protected]; [email protected]
Subject: [PATCH v2] watchdog: da9063: Fix setting/changing timeoutThe DA9063 watchdog always resets the system when it changes the timeout value after the bootloader (e.g. Barebox) has it already set.
Quoted 8 lines
To update the timeout value we have to disable the watchdog, clear the watchdog counter value and write the new timeout value to the watchdog. Clearing the counter value is a feature to be on the safe side, because the data sheet doesn't describe the behaviour of the watchdog counter value after a watchdog disabling-enable-sequence.
The patch is based on Philipp Zabel's <[email protected]> previous patch but doesn't wait 150us because the DA9063 doesn't need this delay.
https://www.dialog-semiconductor.com/products/DA9063
Yes, according to the Dialog datasheet DA9063_2v1, there is no 150us minimum assert time limit. But ... that doesn't seem correct to me, because the DA9062 driver and DA9062 datasheet both show a minimum assertion time, like you said.
So let me check with the hardware engineers.
Regards,
Steve
Quoted 65 lines
Fixes 5e9c16e37608 ("watchdog: Add DA9063 PMIC watchdog driver.")Signed-off-by Marco Felsch <[email protected]>--- drivers/watchdog/da9063_wdt.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)drivers/watchdog/da9063_wdt.c +30
-0@@ -45,8 +45,38 @@ static unsigned int da9063_wdt_timeout_to_sel(unsigned int secs) return DA9063_TWDSCALE_MAX; } +/* +* Writing a '1' to the self-clearing WATCHDOG bit resets the watchdog counter +* value. +*/ +static int _da9063_wdt_reset_timer (struct da9063 *da9063) +{ +return regmap_write (da9063->regmap,DA9063_REG_CONTROL_F , +DA9063_WATCHDOG ); +} +static int _da9063_wdt_set_timeout (struct da9063 *da9063,unsigned int regval) { +int ret; + +/* +* The watchdog trigger a reboot if a timeout value is already +* programmed. Because the timeout value combines two functions in +* one: indicating the counter limit and starting the watchdog. To be +* able to set the watchdog a second time (first time was done by the +* bootloader) disable the watchdog clear the counter value manually and +* set the new timeout value. +*/ + ret =regmap_update_bits (da9063->regmap,DA9063_REG_CONTROL_D , +DA9063_TWDSCALE_MASK ,DA9063_TWDSCALE_DISABLE ); +if (ret) +dev_warn (da9063->dev, +"Failed to disable watchdog before setting new timeout\n" ); + + ret =_da9063_wdt_reset_timer (da9063); +if (ret) +dev_warn (da9063->dev,"Failed to reset watchdog counter\n" ); +return regmap_update_bits (da9063->regmap,DA9063_REG_CONTROL_D ,DA9063_TWDSCALE_MASK , regval);}
drivers/watchdog/da9063_wdt.c +1
-3@@ -85,8 +115,7 @@ static int da9063_wdt_ping(struct watchdog_device *wdd)struct da9063 *da9063 =watchdog_get_drvdata (wdd);int ret; - ret =regmap_write (da9063->regmap,DA9063_REG_CONTROL_F , -DA9063_WATCHDOG ); + ret =_da9063_wdt_reset_timer (da9063);if (ret)dev_alert (da9063->dev,"Failed to ping the watchdog (err = %d)\n" , ret); --2.17.0
Hi Steve,
Quoted 20 lines · Steve Twiss
Hi Marco,
Quoted 6 lines · Marco Felsch
To: [email protected]; [email protected]
Subject: [PATCH v2] watchdog: da9063: Fix setting/changing timeoutThe DA9063 watchdog always resets the system when it changes the timeout value after the bootloader (e.g. Barebox) has it already set.
Quoted 8 lines
To update the timeout value we have to disable the watchdog, clear the watchdog counter value and write the new timeout value to the watchdog. Clearing the counter value is a feature to be on the safe side, because the data sheet doesn't describe the behaviour of the watchdog counter value after a watchdog disabling-enable-sequence.
The patch is based on Philipp Zabel's <[email protected]>previous patch but doesn't wait 150us because the DA9063 doesn't need this delay.
Quoted 7 lines
Yes, according to the Dialog datasheet
DA9063_2v1, there is no 150us minimum assert time limit. But ... that doesn't seem correct to me, because the DA9062 driver and DA9062 datasheet both show a minimum assertion time, like you said.So let me check with the hardware engineers.
That would be great looking forward to hear from you. I will prepare a v3 if it is.
Quoted 18 lines
Quoted 18 lines
+
static int_da9063_wdt_set_timeout(struct da9063 *da9063, unsigned int regval){
+ int ret;
+
+ /*
+ * The watchdog trigger a reboot if a timeout value is already + * programmed. Because the timeout value combines two functions in + * one: indicating the counter limit and starting the watchdog. To be
+ * able to set the watchdog a second time (first time was done by the
+ * bootloader) disable the watchdog clear the counter value manually and
+ * set the new timeout value.
+ */
+ ret = regmap_update_bits(da9063->regmap,DA9063_REG_CONTROL_D, +DA9063_TWDSCALE_MASK,DA9063_TWDSCALE_DISABLE);
Quoted 8 lines
Quoted 8 lines
+ if (ret)
+ dev_warn(da9063->dev,
+ "Failed to disable watchdog before setting new timeout\n");
+
+ ret =_da9063_wdt_reset_timer(da9063);
+ if (ret)
+dev_warn(da9063->dev, "Failed to reset watchdog counter\n");
BTW. can you ask them if it is necessary to reset the counter value register manually or if this is done by disabling the watchdog.
Regards,
Marco
Guenter Roeck
maintainerQuoted 31 lines · Marco Felsch
Hi Steve,
Quoted 28 lines · Steve Twiss
Hi Marco,
Quoted 13 lines · Marco Felsch
To: [email protected]; [email protected]
Subject: [PATCH v2] watchdog: da9063: Fix setting/changing timeoutThe DA9063 watchdog always resets the system when it changes the timeout value after the bootloader (e.g. Barebox) has it already set.
To update the timeout value we have to disable the watchdog, clear the watchdog counter value and write the new timeout value to the watchdog. Clearing the counter value is a feature to be on the safe side, because the
data sheet doesn't describe the behaviour of the watchdog counter value after a watchdog disabling-enable-sequence.Quoted 2 lines
The patch is based on Philipp Zabel's <[email protected]>previous patch but doesn't wait 150us because the DA9063 doesn't need this delay.
https://www.dialog-semiconductor.com/products/DA9063
Yes, according to the Dialog datasheet
DA9063_2v1, there is no 150us minimum
assert time limit. But ... that doesn't seem correct to me, because the DA9062
driver and DA9062 datasheet both show a minimum assertion time, like you said.
Quoted 7 lines
Quoted 3 lines
So let me check with the hardware engineers.
That would be great looking forward to hear from you. I will prepare a v3 if it is.
Any updates ?
Guenter
Quoted 33 lines
Quoted 19 lines
Quoted 19 lines
+
static int_da9063_wdt_set_timeout(struct da9063 *da9063, unsigned int regval)
{
+ int ret;
+
+ /*
+ * The watchdog trigger a reboot if a timeout value is already + * programmed. Because the timeout value combines two functions in + * one: indicating the counter limit and starting the watchdog. To be
+ * able to set the watchdog a second time (first time was done by the
+ * bootloader) disable the watchdog clear the counter value manually and
+ * set the new timeout value.
+ */
+ ret = regmap_update_bits(da9063->regmap,DA9063_REG_CONTROL_D, +DA9063_TWDSCALE_MASK,DA9063_TWDSCALE_DISABLE);Quoted 8 lines
Quoted 8 lines
+ if (ret)
+ dev_warn(da9063->dev,
+ "Failed to disable watchdog before setting new timeout\n");
+
+ ret =_da9063_wdt_reset_timer(da9063);
+ if (ret)
+dev_warn(da9063->dev, "Failed to reset watchdog counter\n");BTW. can you ask them if it is necessary to reset the counter value register manually or if this is done by disabling the watchdog.
Regards,
Marco
On 15 May 2018 19:44, Guenter Roeck wrote,
Quoted 29 lines
Subject: Re: [PATCH v2] watchdog: da9063: Fix setting/changing timeout
Quoted 26 lines · Marco Felsch
Hi Steve,
Quoted 23 lines · Steve Twiss
Quoted 10 lines · Marco Felsch
The DA9063 watchdog always resets the system when it changes the timeout value after the bootloader (e.g. Barebox) has it already set.
To update the timeout value we have to disable the watchdog, clear the watchdog counter value and write the new timeout value to the watchdog. Clearing the counter value is a feature to be on the safe side, because the data sheet doesn't describe the behaviour of the watchdog counter value after a watchdog disabling-enable-sequence.
Quoted 3 lines
The patch is based on Philipp Zabel's <[email protected]>previous patch but doesn't wait 150us because the DA9063 doesn't need this delay.
https://www.dialog-semiconductor.com/products/DA9063Yes, according to the Dialog datasheet
DA9063_2v1, there is no 150us minimum assert time limit. But ... that doesn't seem correct to me, because the DA9062 driver and DA9062 datasheet both show a minimum assertion time, like you said.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
So let me check with the hardware engineers.
That would be great looking forward to hear from you. I will prepare a v3 if it is.
Any updates ?
Guenter
Hi Guenter and Marco,
Thank you for your patience.
The best advice I can give at the moment is:
Please follow what has been done in the DA9062 and DA9053 device drivers.
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/da9062_wdt.c#L90
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/da9052_wdt.c#L76
In these cases:
"setting TWDSCALE to zero for at least 150 us before writing the new value"
There will be a longer answer, but that must wait until the formal datasheets have been clarified by the hardware engineers.
Regards,
Steve
Quoted 29 lines
Quoted 29 lines
Quoted 15 lines
Quoted 15 lines
+
static int_da9063_wdt_set_timeout(struct da9063 *da9063, unsigned int regval){
+ int ret;
+
+ /*
+ * The watchdog trigger a reboot if a timeout value is already + * programmed. Because the timeout value combines two functions in + * one: indicating the counter limit and starting the watchdog. To be + * able to set the watchdog a second time (first time was done by the + * bootloader) disable the watchdog clear the counter value manually and + * set the new timeout value.
+ */
+ ret = regmap_update_bits(da9063->regmap,DA9063_REG_CONTROL_D,Quoted 8 lines
Quoted 8 lines
+
DA9063_TWDSCALE_MASK,DA9063_TWDSCALE_DISABLE); + if (ret)
+ dev_warn(da9063->dev,
+ "Failed to disable watchdog before setting new timeout\n"); +
+ ret =_da9063_wdt_reset_timer(da9063);
+ if (ret)
+dev_warn(da9063->dev, "Failed to reset watchdog counter\n");BTW. can you ask them if it is necessary to reset the counter value register manually or if this is done by disabling the watchdog.
Regards,
Marco
Hi Steve and Guenter,
Quoted 19 lines · Steve Twiss
On 15 May 2018 19:44, Guenter Roeck wrote,
Quoted 11 lines
Subject: Re: [PATCH v2] watchdog: da9063: Fix setting/changing timeout
Quoted 5 lines · Marco Felsch
Hi Steve,
That would be great looking forward to hear from you. I will prepare a v3 if it is.
Any updates ?
Guenter
Hi Guenter and Marco,
Thank you for your patience.
The best advice I can give at the moment is:
Quoted 6 lines
Please follow what has been done in the DA9062 and DA9053 device drivers.
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/da9062_wdt.c#L90
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/da9052_wdt.c#L76In these cases:
"setting TWDSCALE to zero for at least 150 us before writing the new value"
Okay. I tested it without a delay and saw no issues but I will add the delay to be on the safe side.
Is that okay for you Guenter?
Quoted 6 lines
There will be a longer answer, but that must wait until the formal datasheets have been clarified by the hardware engineers.
Regards,
Steve
Regards,
Marco
Quoted 25 lines · Marco Felsch
Hi Steve and Guenter,
Quoted 22 lines · Steve Twiss
On 15 May 2018 19:44, Guenter Roeck wrote,
Quoted 11 lines
Subject: Re: [PATCH v2] watchdog: da9063: Fix setting/changing timeout
Quoted 5 lines · Marco Felsch
Hi Steve,
That would be great looking forward to hear from you. I will prepare a v3 if it is.
Any updates ?
Guenter
Hi Guenter and Marco,
Thank you for your patience.
The best advice I can give at the moment is:Please follow what has been done in the DA9062 and DA9053 device drivers.
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/da9062_wdt.c#L90
https://elixir.bootlin.com/linux/latest/source/drivers/watchdog/da9052_wdt.c#L76
Quoted 5 lines
Quoted 2 lines
In these cases:
"setting TWDSCALE to zero for at least 150 us before writing the new value"Okay. I tested it without a delay and saw no issues but I will add the delay to be on the safe side.
Is that okay for you Guenter?
Yes. Better safe than sorry.
Thanks,
Guenter
Quoted 9 lines
Quoted 6 lines
There will be a longer answer, but that must wait until the formal datasheets have been clarified by the hardware engineers.
Regards,
SteveRegards,
Marco