On 9/1/20 9:17 AM, Ulrich Hecht wrote: > This patch ensures our parent is awake before a reboot takes place. This > prevents situations in which the I2C host has been suspended and cannot > be safely woken up anymore when it needs to talk to us. > Why not call pm_runtime_get_sync() in da9063_wdt_restart() ? What guarantees that the local notifier is called before the watchdog core's restart notifier ? And what is the point of using the watchdog core's reboot handler if it is bypassed anyway ? Also, why is it not necessary to call pm functions when the watchdog is started, when it is stopped, and during suspend/resume ? Thanks, Guenter > Signed-off-by: Ulrich Hecht <uli+renesas@xxxxxxxx> > --- > > Hi! > > This is supposed to resolve the issue that came up in the review of > "[PATCH v2] i2c: sh_mobile: implement atomic transfers" that the parent > controller may be suspended when the restart method is called. See > https://www.spinics.net/lists/linux-i2c/msg46367.html for details. > > CU > Uli > > > drivers/watchdog/da9063_wdt.c | 21 +++++++++++++++++++++ > include/linux/mfd/da9063/core.h | 2 ++ > 2 files changed, 23 insertions(+) > > diff --git a/drivers/watchdog/da9063_wdt.c b/drivers/watchdog/da9063_wdt.c > index 423584252606..89718733491e 100644 > --- a/drivers/watchdog/da9063_wdt.c > +++ b/drivers/watchdog/da9063_wdt.c > @@ -18,6 +18,8 @@ > #include <linux/mfd/da9063/registers.h> > #include <linux/mfd/da9063/core.h> > #include <linux/regmap.h> > +#include <linux/pm_runtime.h> > +#include <linux/reboot.h> > > /* > * Watchdog selector to timeout in seconds. > @@ -158,6 +160,21 @@ static int da9063_wdt_set_timeout(struct watchdog_device *wdd, > return ret; > } > > +static int da9063_reboot_notifier(struct notifier_block *nb, > + unsigned long code, void *unused) > +{ > + struct da9063 *da9063 = container_of(nb, struct da9063, reboot_nb); > + > + /* > + * Make sure parent device is running. This cannot be done in the > + * restart handler because it is no longer safe to do runtime PM > + * there. > + */ > + pm_runtime_get_sync(da9063->dev->parent); > + > + return NOTIFY_DONE; > +} > + > static int da9063_wdt_restart(struct watchdog_device *wdd, unsigned long action, > void *data) > { > @@ -233,6 +250,10 @@ static int da9063_wdt_probe(struct platform_device *pdev) > set_bit(WDOG_HW_RUNNING, &wdd->status); > } > > + /* Get early notification of reboot so we can wake up the parent. */ > + da9063->reboot_nb.notifier_call = da9063_reboot_notifier; > + devm_register_reboot_notifier(dev, &da9063->reboot_nb); > + > return devm_watchdog_register_device(dev, wdd); > } > > diff --git a/include/linux/mfd/da9063/core.h b/include/linux/mfd/da9063/core.h > index fa7a43f02f27..9a3283d488b7 100644 > --- a/include/linux/mfd/da9063/core.h > +++ b/include/linux/mfd/da9063/core.h > @@ -85,6 +85,8 @@ struct da9063 { > int chip_irq; > unsigned int irq_base; > struct regmap_irq_chip_data *regmap_irq; > + > + struct notifier_block reboot_nb; > }; > > int da9063_device_init(struct da9063 *da9063, unsigned int irq); >