Skip to content

Commit

Permalink
watchdog: da9062: make restart handler atomic safe
Browse files Browse the repository at this point in the history
The restart handler is executed during the shutdown phase which is
atomic/irq-less. The i2c framework supports atomic transfers since
commit 63b9698 ("i2c: core: introduce callbacks for atomic
transfers") to address this use case. Using regmap within an atomic
context is allowed only if the regmap type is MMIO and the cache type
'flat' or no cache is used. Using the i2c_smbus_write_byte_data()
function can be done without additional tests because:
 1) the DA9062 is an i2c-only device and
 2) the i2c framework emulates the smbus protocol if the host adapter
    does not support smbus_xfer by using the master_xfer.

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Stefan Lengfeld <contact@stefanchrist.eu>
Tested-by: Stefan Lengfeld <contact@stefanchrist.eu>
Reviewed-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Link: https://lore.kernel.org/r/20200115162307.7336-1-m.felsch@pengutronix.de
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
  • Loading branch information
Marco Felsch authored and Wim Van Sebroeck committed Jan 27, 2020
1 parent 9e5236e commit 057b52b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions drivers/watchdog/da9062_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <linux/platform_device.h>
#include <linux/uaccess.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/mfd/da9062/registers.h>
Expand Down Expand Up @@ -147,12 +148,13 @@ static int da9062_wdt_restart(struct watchdog_device *wdd, unsigned long action,
void *data)
{
struct da9062_watchdog *wdt = watchdog_get_drvdata(wdd);
struct i2c_client *client = to_i2c_client(wdt->hw->dev);
int ret;

ret = regmap_write(wdt->hw->regmap,
DA9062AA_CONTROL_F,
DA9062AA_SHUTDOWN_MASK);
if (ret)
/* Don't use regmap because it is not atomic safe */
ret = i2c_smbus_write_byte_data(client, DA9062AA_CONTROL_F,
DA9062AA_SHUTDOWN_MASK);
if (ret < 0)
dev_alert(wdt->hw->dev, "Failed to shutdown (err = %d)\n",
ret);

Expand Down

0 comments on commit 057b52b

Please sign in to comment.