Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6675560ybl; Wed, 15 Jan 2020 08:25:42 -0800 (PST) X-Google-Smtp-Source: APXvYqysqdpo+ZWGNPV9ZnXlWjjuwvDqjyDRhc6Ef9up3+LIeGfuxqp9dskuGh3xAyJm/7pUJ/7K X-Received: by 2002:a05:6830:1487:: with SMTP id s7mr3141038otq.269.1579105542125; Wed, 15 Jan 2020 08:25:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579105542; cv=none; d=google.com; s=arc-20160816; b=UUpgV1/QzpLvDPjfLftxoBxxGDYY8T2Y7PSdF4ISf0rdVNNYsFUx6dlrvSjVsgzcQx sp/cQCzIvusXHeO2nEXRZJh9nC8XJSj9M96OTl14UfIaplWLuqi8rKVoW59DiV+sEB4S iZtxgZm6mlBxo7Vv/NtKfvSTvJrkYVaM1hlU5028Q386cOYKJC8Vc76i2nxWh3VMmAh0 QLZ3x04HBbFQaYSlsOESNWpM2Oc8GebWlXskwG3PvFkxU0BZOB2PLQiuBorgjnhjI+q1 TUiIaxz06G3gY8IRvhNBswc2kQPlVM83qIM0/+/XjGmqxwT4vYKESu4eboAmPfcFR8QD /F7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=1nTmhqLxZ+7bCGQzQx65Fd+ZBqd2tB4dCyc7Zw7dXyo=; b=XI7tpiaZzGJXjvvhSo42NlANp8seiWkE23Z5vUt+kKljWZHFWxPCVHwd4+uVZgCDw0 9Lf27fJaLdrEjTsOn2MOosHyx2e3dbgDe9UIgmehLBHmWj07MINWeyVmsHI3RQOXjEnV 1nbBKMzw0pci2QtoupO5MCuN041jBcX5emKafx41auMdsotxXyN7VtrvQJ90m+YzsIvj s95Btzcy7jELBWDtyIGPi/F5TivdRoN7ci6DfP0Ywm/+D1mumzWQSr1s1fu6hG6Di8nY he/2BSWpbXYSSLCIruMb9/DeFmoCXKKlgd6z571y68whD8D3zqW13R7qwYufYYB8UaF2 xXAQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z194si9786982oia.50.2020.01.15.08.25.29; Wed, 15 Jan 2020 08:25:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728946AbgAOQXT (ORCPT + 99 others); Wed, 15 Jan 2020 11:23:19 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:57985 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbgAOQXT (ORCPT ); Wed, 15 Jan 2020 11:23:19 -0500 Received: from dude02.hi.pengutronix.de ([2001:67c:670:100:1d::28] helo=dude02.lab.pengutronix.de) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1irlRq-0004DR-8L; Wed, 15 Jan 2020 17:23:14 +0100 Received: from mfe by dude02.lab.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1irlRp-0002ZC-CI; Wed, 15 Jan 2020 17:23:13 +0100 From: Marco Felsch To: support.opensource@diasemi.com, linux@roeck-us.net, contact@stefanchrist.eu, Adam.Thomson.Opensource@diasemi.com Cc: linux-watchdog@vger.kernel.org, kernel@pengutronix.de, linux-kernel@vger.kernel.org Subject: [PATCH v2] watchdog: da9062: make restart handler atomic safe Date: Wed, 15 Jan 2020 17:23:07 +0100 Message-Id: <20200115162307.7336-1-m.felsch@pengutronix.de> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::28 X-SA-Exim-Mail-From: mfe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The restart handler is executed during the shutdown phase which is atomic/irq-less. The i2c framework supports atomic transfers since commit 63b96983a5dd ("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 --- Hi, This patch is based on Stefan Lengfeld's RFC Patch [1]. [1] https://patchwork.ozlabs.org/patch/1085942/ Changes: v2: - adapt commit message - add comment - make use of i2c_smbus_write_byte_data() --- drivers/watchdog/da9062_wdt.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/da9062_wdt.c b/drivers/watchdog/da9062_wdt.c index c9b9d6394525..77b6b5336067 100644 --- a/drivers/watchdog/da9062_wdt.c +++ b/drivers/watchdog/da9062_wdt.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -149,12 +150,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); -- 2.20.1