Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7194121imu; Tue, 22 Jan 2019 01:51:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN5NB8/avjqd4PV05QZDAWQ+fXFBV3w42g2w2G6uwa51Dn0p1ivAKnzJwov0oKybmJXQ4qEs X-Received: by 2002:a62:5444:: with SMTP id i65mr33892664pfb.193.1548150698198; Tue, 22 Jan 2019 01:51:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548150698; cv=none; d=google.com; s=arc-20160816; b=GXMaefq/+aa/urRwIAkij1t761Aq4Mthjl0ke8oD3Qj6Q4hn2R4qLS65LdC5C9SbDE OtQeTkk9ckjb1JYRVc3oP23nZhqNaxae/HVhD8x7vAUrLfQlFlHyfIslM1FdQS8BbFQZ ogcOqt36h/cvQXjWIbKdHlzt+t7sfjmJoBGFL+ij2IpwAZb71zleP6iFCUdYQpJ9EwZL cn6ftU5gayY38iBpfNz6OK/neGlDM43NEku8b+/eYDrQ9ome4tDIMdsqeLkIt/2Zsci4 VWSINcz6RO2MR4AMi1kR0YF/VRSmVcob6bMpAV6v55v3dhfRdBkG+j3+LE0JR6LatFFy UEyw== 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=wlULum/2bmzy/sHq/nzB9YnLl8fucwDhlg0aNAcw10I=; b=lGIpcTXwNp3rR8zZ099Yob2QNzip1XDOT1t3Tpm+G0tUSPJG1sT46WfI2PHbWCfECu OxlW17HnPTdN8IDkiD0o/R26omz2Ki3LDX3+Qk1ZEbaoIt21mFcrtiN6b+USo2ZPUriA rvqw91fASt41H6dheH2qWQO7YzDRj+QteeYiJlwSPiJY2AVRXXZ0ZARVXR+RjK5vZDhI n4PuKKjpvcNUY4rXEnkA1zRGQLn6Ot1zQAQ3qfPaCTV7VoiscDNxDGcpoDXlWs/xgIcg 0nzkXI8cvnt/pdoeNzFPg8jQtUtd6OcxNRqdFv1qQ3OzxqXlEHhhiK2ENiGfEymRfSEJ PACg== 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 i2si15680296pgl.153.2019.01.22.01.51.22; Tue, 22 Jan 2019 01:51:38 -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 S1728176AbfAVJsz (ORCPT + 99 others); Tue, 22 Jan 2019 04:48:55 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:46741 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbfAVJsy (ORCPT ); Tue, 22 Jan 2019 04:48:54 -0500 Received: by mail-lj1-f193.google.com with SMTP id v15-v6so19944076ljh.13; Tue, 22 Jan 2019 01:48:51 -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=wlULum/2bmzy/sHq/nzB9YnLl8fucwDhlg0aNAcw10I=; b=jYsEus/vrRyp/qGnzc+xeivXVdAIB1XLj1ukMNKc2BRoWC2ymxo9Q3cNCj3E61bzuB VDUvuActavUXFEOB5d7wszq5qBz3C54qv6ampK7jUoZlQj/dEYyRvoQ+bX6MMnn6ukKr hi0FG0ZR1PWYBiQRcNT/K+M6Rai+xvD2/UO5WkesJsVhQrMb8uacqBAUmYjJ+7LWZKar hQ82QYMQ1UzuWyOz5vlo8DsxS66Mbr9DDoLeGz/xnbqkOrvz773G/7Zmn/sk2hI9HxDD TijbljwDj6cvMMWaFFPRjv4++k9YSaBUdV8pWGUwCWIRSKG1mj4FNgtlbcjz5OTuzPN/ KgXw== X-Gm-Message-State: AJcUukdi70UTRa0xJn84ZfHIfdNODeC1DzKLZ6AUDTNLaGRTDqNoOCIe JyU3KbfoSvuZLRO1+dBi+NY= X-Received: by 2002:a2e:9d8e:: with SMTP id c14-v6mr19780027ljj.146.1548150530733; Tue, 22 Jan 2019 01:48:50 -0800 (PST) Received: from localhost.localdomain ([213.255.186.46]) by smtp.gmail.com with ESMTPSA id q10-v6sm2744204ljj.3.2019.01.22.01.48.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Jan 2019 01:48:50 -0800 (PST) Date: Tue, 22 Jan 2019 11:48:36 +0200 From: Matti Vaittinen To: matti.vaittinen@fi.rohmeurope.com, mazziesaccount@gmail.com Cc: lee.jones@linaro.org, robh+dt@kernel.org, mark.rutland@arm.com, lgirdwood@gmail.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, 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, mikko.mutanen@fi.rohmeurope.com, heikki.haikola@fi.rohmeurope.com Subject: [RFC PATCH v1 13/13] 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 | 161 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 174 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..e9a32566f595 --- /dev/null +++ b/drivers/watchdog/bd70528_wdt.c @@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2018 ROHM Semiconductors +// ROHM BD70528MWV watchdog driver + +#include +#include +#include +#include +#include +#include +#include +#include + +static int bd70528_wdt_set(struct bd70528 *bd70528, int enable) +{ + int ret; + + if (bd70528->rtc_timer_lock) + mutex_lock(bd70528->rtc_timer_lock); + + ret = bd70528->wdt_set(bd70528, enable, NULL); + + if (bd70528->rtc_timer_lock) + mutex_unlock(bd70528->rtc_timer_lock); + return ret; +} + +static int bd70528_wdt_start(struct watchdog_device *wdt) +{ + struct bd70528 *bd70528 = watchdog_get_drvdata(wdt); + + return bd70528_wdt_set(bd70528, 1); +} + +static int bd70528_wdt_stop(struct watchdog_device *wdt) +{ + struct bd70528 *bd70528 = watchdog_get_drvdata(wdt); + + return bd70528_wdt_set(bd70528, 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 bd70528 *bd70528 = 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; + + if (bd70528->rtc_timer_lock) + mutex_lock(bd70528->rtc_timer_lock); + + ret = bd70528->wdt_set(bd70528, 0, NULL); + if (ret) + goto out_unlock; + + ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_HOUR, + BD70528_MASK_WDT_HOUR, hours); + if (ret) { + dev_err(bd70528->chip.dev, "Failed to set WDT hours\n"); + goto out_en_unlock; + } + ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_MINUTE, + BD70528_MASK_WDT_MINUTE, bin2bcd(minutes)); + if (ret) { + dev_err(bd70528->chip.dev, "Failed to set WDT minutes\n"); + goto out_en_unlock; + } + ret = regmap_update_bits(bd70528->chip.regmap, BD70528_REG_WDT_SEC, + BD70528_MASK_WDT_SEC, bin2bcd(seconds)); + if (ret) { + dev_err(bd70528->chip.dev, "Failed to set WDT seconds\n"); + goto out_en_unlock; + } + +out_en_unlock: + ret = bd70528->wdt_set(bd70528, 1, NULL); +out_unlock: + if (bd70528->rtc_timer_lock) + mutex_lock(bd70528->rtc_timer_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, + /* + * bd70528 WDT ping is same as enable. Eg, writing 'enable' to enabled + * WDT will restart the timeout + */ + .ping = bd70528_wdt_start, + .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 +static struct watchdog_device bd70528_wd = { + .info = &bd70528_wdt_info, + .ops = &bd70528_wdt_ops, + .min_hw_heartbeat_ms = WDT_MIN_MS, + .max_hw_heartbeat_ms = WDT_MAX_MS, +}; + +static int bd70528_wdt_probe(struct platform_device *pdev) +{ + struct bd70528 *tmp; + struct bd70528 *bd70528; + int ret; + + tmp = dev_get_drvdata(pdev->dev.parent); + if (!tmp) { + dev_err(&pdev->dev, "No MFD driver data\n"); + return -EINVAL; + } + bd70528 = devm_kzalloc(&pdev->dev, sizeof(*bd70528), GFP_KERNEL); + if (!bd70528) + return -ENOMEM; + + *bd70528 = *tmp; + bd70528->chip.dev = &pdev->dev; + + /* + * TODO: Set the initial state and timeout. + * See whether the low power states require special handling + */ + watchdog_set_drvdata(&bd70528_wd, bd70528); + ret = devm_watchdog_register_device(&pdev->dev, &bd70528_wd); + 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 ROHM Semiconductors ~~~ "I don't think so," said Rene Descartes. Just then, he vanished ~~~