Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7052607imu; Thu, 31 Jan 2019 04:15:04 -0800 (PST) X-Google-Smtp-Source: ALg8bN4zG5kAfjfY+xJoUXBN+P7YPN0rva4aSyglWvgUYthxdZunArI42H3svExr2qJXMKi6Gy0G X-Received: by 2002:a62:2fc3:: with SMTP id v186mr34790240pfv.82.1548936904273; Thu, 31 Jan 2019 04:15:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548936904; cv=none; d=google.com; s=arc-20160816; b=TfjYuZ/q0hZuJCPn2pl7s+4SfmuIjBIVkr4E2eNkJ1LnOuQSX7Ot6fzInyx5CsQ3wW CQmxlI7hVPscAH4ZMZAUbX+L2iV2AeyM2uP2xW6HUnPOdRNaIcLu73x7r7Isu9ZqmTdn ITx05d0nV3vOvG3dON3ukLqxq84DYNf2Vf9EXzgZLcPiYC9wNU6IT9dHtJKgakDQd4aT MXnHvXcAxXlynxVygE7gKuX0ACBsJ1j0j24EjO73cs0O0iPM6sQoSe4DlZ/itpiTPTtv +aA6aFItNz7aij2yq4G2PN4scNdBHbZPYmKaHMin8JGeEcI/U6MCZ5jSITIa0cvKkYfv Nflg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=dVu3my73PXK2Naj+si694fS8rZkB5+dCruJopAIPzSg=; b=a1FdFPf2W7ZOEmbW4h8YkTbCVjyFTh9BsAVf9ndMWSYAFgmTjb7ggTzybwkBgptGsY kOVtffJW5hwmk4DftqjCEB/1d5rlnk4+YLSCoy5tvR6Ce5AFVs4pzxYUOWXmvBovqlcw daLw0+zHGF6gK8Eu9REmSuHIb0x80OnaGVxHePr38+CI9Oe+/3HirPguo4Vs6znmvPdk E+4xJH9QtszWoJNhTf9wZiYe48MLJaK7kCkJw0Q595gxB5VlDnx9wQbuTJ13TIbLd6OY xDR3BqC8yhTxa94S/kAUEB/YUUypE1zQGNcmKAX9Ci3KboFWxRG/MucEAa67bwhqoLuQ cwPQ== 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 be11si4292630plb.134.2019.01.31.04.14.49; Thu, 31 Jan 2019 04:15:04 -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 S1732781AbfAaMNO (ORCPT + 99 others); Thu, 31 Jan 2019 07:13:14 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:45388 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726960AbfAaMNN (ORCPT ); Thu, 31 Jan 2019 07:13:13 -0500 Received: by mail-lj1-f193.google.com with SMTP id s5-v6so2411375ljd.12; Thu, 31 Jan 2019 04:13:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=dVu3my73PXK2Naj+si694fS8rZkB5+dCruJopAIPzSg=; b=GOJe8kSN0tbCIUFfuE4RK4E8bOUpIYfZW+bD0AgX5DvIlPYB1FjUw4UeI+pZSxQm1H dc6QGVyu5e7TJ7BtFesftNuCA8YsJqkoHPjrmkT8PL2laiDqIEyuP8WuI8m2a8fNjx1w LaLyxfG41sR+iJ4xuhL47KpNFcPiBVbd9xCKuyFdUcAEw0ZIG8mw+7RCwxO/1bVVaXv/ 1E/zYTyJVbyHnSuqMVjR7kD0kUd5MtKT32jCHDzqRgzgds1zGB8CRGY8IThxnrZfZaZZ oENI7gjnos0Jemo6Nz/22MlbOe/thLG5LcQ8uGVbuJXD4XMzLp+eLCWE8aFJjSLvZpJN 1byw== X-Gm-Message-State: AJcUukeLd2c6ejHOo09kxkKU+H0No6Icv9h+ZKIfdVbxvP5WSReV3+3X GBDr0hlgQLZ07L+/Zj6TdBc= X-Received: by 2002:a2e:9a16:: with SMTP id o22-v6mr27891147lji.112.1548936789389; Thu, 31 Jan 2019 04:13:09 -0800 (PST) Received: from localhost.localdomain ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id q8-v6sm749052lji.69.2019.01.31.04.13.07 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Jan 2019 04:13:08 -0800 (PST) Date: Thu, 31 Jan 2019 14:12:56 +0200 From: Matti Vaittinen To: mazziesaccount@gmail.com, matti.vaittinen@fi.rohmeurope.com Cc: heikki.haikola@fi.rohmeurope.com, mikko.mutanen@fi.rohmeurope.com, lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, broonie@kernel.org, gregkh@linuxfoundation.org, rafael@kernel.org, mturquette@baylibre.com, sboyd@kernel.org, linus.walleij@linaro.org, bgolaszewski@baylibre.com, sre@kernel.org, lgirdwood@gmail.com, a.zummo@towertech.it, alexandre.belloni@bootlin.com, wim@linux-watchdog.org, linux@roeck-us.net, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-gpio@vger.kernel.org, linux-pm@vger.kernel.org, linux-rtc@vger.kernel.org, linux-watchdog@vger.kernel.org Subject: [RFC PATCH v4 10/10] watchdog: bd70528: Initial support for ROHM BD70528 watchdog block Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Initial support for watchdog block included in ROHM BD70528 power management IC. Configurations for low power states are still to be checked. Signed-off-by: Matti Vaittinen --- drivers/watchdog/Kconfig | 12 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/bd70528_wdt.c | 187 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 drivers/watchdog/bd70528_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 57f017d74a97..f30e3a3e886e 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -90,6 +90,18 @@ config SOFT_WATCHDOG_PRETIMEOUT watchdog. Be aware that governors might affect the watchdog because it is purely software, e.g. the panic governor will stall it! +config BD70528_WATCHDOG + tristate "ROHM BD70528 PMIC Watchdog" + depends on MFD_ROHM_BD70528 + select WATCHDOG_CORE + help + Support for the watchdog in the ROHM BD70528 PMIC. Watchdog trigger + cause system reset. + + Say Y here to include support for the ROHM BD70528 watchdog. + Alternatively say M to compile the driver as a module, + which will be called bd70528_wdt. + config DA9052_WATCHDOG tristate "Dialog DA9052 Watchdog" depends on PMIC_DA9052 || COMPILE_TEST diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index a0917ef28e07..1ce87a3b1172 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -204,6 +204,7 @@ obj-$(CONFIG_WATCHDOG_SUN4V) += sun4v_wdt.o obj-$(CONFIG_XEN_WDT) += xen_wdt.o # Architecture Independent +obj-$(CONFIG_BD70528_WATCHDOG) += bd70528_wdt.o obj-$(CONFIG_DA9052_WATCHDOG) += da9052_wdt.o obj-$(CONFIG_DA9055_WATCHDOG) += da9055_wdt.o obj-$(CONFIG_DA9062_WATCHDOG) += da9062_wdt.o diff --git a/drivers/watchdog/bd70528_wdt.c b/drivers/watchdog/bd70528_wdt.c new file mode 100644 index 000000000000..c24d4cce5e9c --- /dev/null +++ b/drivers/watchdog/bd70528_wdt.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 ROHM Semiconductors +// ROHM BD70528MWV watchdog driver + +#include +#include +#include +#include +#include +#include +#include +#include + +struct wdtbd70528 { + struct device *dev; + struct regmap *regmap; + struct mutex *rtc_lock; + struct watchdog_device wdt; +}; + +static int bd70528_wdt_set_locked(struct wdtbd70528 *w, int enable) +{ + struct bd70528 *bd70528; + + bd70528 = container_of(w->rtc_lock, struct bd70528, rtc_timer_lock); + return bd70528->wdt_set(bd70528, enable, NULL); +} +static int bd70528_wdt_set(struct wdtbd70528 *w, int enable) +{ + int ret; + + mutex_lock(w->rtc_lock); + ret = bd70528_wdt_set_locked(w, enable); + mutex_unlock(w->rtc_lock); + + return ret; +} + +static int bd70528_wdt_start(struct watchdog_device *wdt) +{ + struct wdtbd70528 *w = watchdog_get_drvdata(wdt); + + dev_dbg(w->dev, "WDT ping...\n"); + return bd70528_wdt_set(w, 1); +} + +static int bd70528_wdt_stop(struct watchdog_device *wdt) +{ + struct wdtbd70528 *w = watchdog_get_drvdata(wdt); + + dev_dbg(w->dev, "WDT stopping...\n"); + return bd70528_wdt_set(w, 0); +} + +static int bd70528_wdt_set_timeout(struct watchdog_device *wdt, + unsigned int timeout) +{ + unsigned int hours; + unsigned int minutes; + unsigned int seconds; + int ret; + struct wdtbd70528 *w = watchdog_get_drvdata(wdt); + + seconds = timeout; + hours = timeout / (60 * 60); + /* Maximum timeout is 1h 59m 59s => hours is 1 or 0 */ + if (hours) + seconds -= (60 * 60); + minutes = seconds / 60; + seconds = seconds % 60; + + mutex_lock(w->rtc_lock); + + ret = bd70528_wdt_set_locked(w, 0); + if (ret) + goto out_unlock; + + ret = regmap_update_bits(w->regmap, BD70528_REG_WDT_HOUR, + BD70528_MASK_WDT_HOUR, hours); + if (ret) { + dev_err(w->dev, "Failed to set WDT hours\n"); + goto out_en_unlock; + } + ret = regmap_update_bits(w->regmap, BD70528_REG_WDT_MINUTE, + BD70528_MASK_WDT_MINUTE, bin2bcd(minutes)); + if (ret) { + dev_err(w->dev, "Failed to set WDT minutes\n"); + goto out_en_unlock; + } + ret = regmap_update_bits(w->regmap, BD70528_REG_WDT_SEC, + BD70528_MASK_WDT_SEC, bin2bcd(seconds)); + if (ret) + dev_err(w->dev, "Failed to set WDT seconds\n"); + else + dev_dbg(w->dev, "WDT tmo set to %u\n", timeout); + +out_en_unlock: + ret = bd70528_wdt_set_locked(w, 1); +out_unlock: + mutex_unlock(w->rtc_lock); + + return ret; +} + +static const struct watchdog_info bd70528_wdt_info = { + .identity = "bd70528-wdt", + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, +}; + +static const struct watchdog_ops bd70528_wdt_ops = { + .start = bd70528_wdt_start, + .stop = bd70528_wdt_stop, + .set_timeout = bd70528_wdt_set_timeout, +}; + +/* Max time we can set is 1 hour, 59 minutes and 59 seconds */ +#define WDT_MAX_MS ((2 * 60 * 60 - 1) * 1000) +/* Minimum time is 1 second */ +#define WDT_MIN_MS 1000 +#define DEFAULT_TIMEOUT 60 + +static int bd70528_wdt_probe(struct platform_device *pdev) +{ + struct bd70528 *bd70528; + struct wdtbd70528 *w; + int ret; + unsigned int reg; + + bd70528 = dev_get_drvdata(pdev->dev.parent); + if (!bd70528) { + dev_err(&pdev->dev, "No MFD driver data\n"); + return -EINVAL; + } + w = devm_kzalloc(&pdev->dev, sizeof(*w), GFP_KERNEL); + if (!w) + return -ENOMEM; + + w->regmap = bd70528->chip.regmap; + w->rtc_lock = &bd70528->rtc_timer_lock; + w->dev = &pdev->dev; + + w->wdt.info = &bd70528_wdt_info; + w->wdt.ops = &bd70528_wdt_ops; + w->wdt.min_hw_heartbeat_ms = WDT_MIN_MS; + w->wdt.max_hw_heartbeat_ms = WDT_MAX_MS; + w->wdt.parent = pdev->dev.parent; + w->wdt.timeout = DEFAULT_TIMEOUT; + watchdog_set_drvdata(&w->wdt, w); + watchdog_init_timeout(&w->wdt, 0, pdev->dev.parent); + + ret = bd70528_wdt_set_timeout(&w->wdt, w->wdt.timeout); + if (ret) { + dev_err(&pdev->dev, "Failed to set the watchdog timeout\n"); + return ret; + } + + mutex_lock(w->rtc_lock); + ret = regmap_read(w->regmap, BD70528_REG_WDT_CTRL, ®); + mutex_unlock(w->rtc_lock); + + if (ret) { + dev_err(&pdev->dev, "Failed to get the watchdog state\n"); + return ret; + } + if (reg & BD70528_MASK_WDT_EN) { + dev_dbg(&pdev->dev, "watchdog was running during probe\n"); + set_bit(WDOG_HW_RUNNING, &w->wdt.status); + } + + ret = devm_watchdog_register_device(&pdev->dev, &w->wdt); + if (ret < 0) + dev_err(&pdev->dev, "watchdog registration failed: %d\n", ret); + + return ret; +} +static struct platform_driver bd70528_wdt = { + .driver = { + .name = "bd70528-wdt" + }, + .probe = bd70528_wdt_probe, +}; + +module_platform_driver(bd70528_wdt); + +MODULE_AUTHOR("Matti Vaittinen "); +MODULE_DESCRIPTION("BD70528 watchdog driver"); +MODULE_LICENSE("GPL"); -- 2.14.3 -- Matti Vaittinen, Linux device drivers ROHM Semiconductors, Finland SWDC Kiviharjunlenkki 1E 90220 OULU FINLAND ~~~ "I don't think so," said Rene Descartes. Just then, he vanished ~~~