From patchwork Thu Sep 4 14:39:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 36720 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ig0-f197.google.com (mail-ig0-f197.google.com [209.85.213.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4FE06202E4 for ; Thu, 4 Sep 2014 14:41:49 +0000 (UTC) Received: by mail-ig0-f197.google.com with SMTP id r2sf49109979igi.4 for ; Thu, 04 Sep 2014 07:41:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=0C3SdOpKOkSiMsBB7/4qZSLACDoWM/l6DaDgGTJDqOA=; b=KnFbhIQtLh1r9/hZM6hkNJRAFjZ8QDBfVUiD5TC4B2wvQhYAVmGY0mDwRoArI9byEu 0kGlkl8n1TZUb0t5RYD3wVU7HHmMQxm8SibjFs9GhYXIrDBZGp4Dlaic+O4cRwN0VwHo iVEZRWAmDiyLksPJhoLGKSUj1gfzxvThkRmqxiYM6xTlqndb3/y9JfEe/JKLZL6/IwCc liAZ+Iu6ikaLANvwxen7Vjb/+b4z/aHvamzP9/Ko7pNTyytCXpjQ+hgomgVylJiCNPjb OXhvbMHo3FXHQgJNQsafLL65IR66u4rw42S7PbRTlmpDclU5LKSuJGDfvPegfQTORU5i sTgw== X-Gm-Message-State: ALoCoQlVk7RgHIrVW1rANjtMCeCBfX+Vag1D9d5MaHjlk+0VPa9IidFjmsnA4rkpSPimZPW7/KXK X-Received: by 10.50.25.129 with SMTP id c1mr2671667igg.7.1409841708984; Thu, 04 Sep 2014 07:41:48 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.107.182 with SMTP id h51ls330143qgf.80.gmail; Thu, 04 Sep 2014 07:41:48 -0700 (PDT) X-Received: by 10.52.129.165 with SMTP id nx5mr2788675vdb.25.1409841708909; Thu, 04 Sep 2014 07:41:48 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id o4si5786715vcy.87.2014.09.04.07.41.48 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Sep 2014 07:41:48 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id im17so10742131vcb.32 for ; Thu, 04 Sep 2014 07:41:48 -0700 (PDT) X-Received: by 10.52.94.108 with SMTP id db12mr3697621vdb.8.1409841708816; Thu, 04 Sep 2014 07:41:48 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp848698vcb; Thu, 4 Sep 2014 07:41:48 -0700 (PDT) X-Received: by 10.70.96.102 with SMTP id dr6mr9620114pdb.86.1409841707480; Thu, 04 Sep 2014 07:41:47 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qz5si3902548pab.214.2014.09.04.07.41.47 for ; Thu, 04 Sep 2014 07:41:47 -0700 (PDT) Received-SPF: none (google.com: linux-watchdog-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753886AbaIDOkz (ORCPT ); Thu, 4 Sep 2014 10:40:55 -0400 Received: from mail-yh0-f47.google.com ([209.85.213.47]:37667 "EHLO mail-yh0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754029AbaIDOky (ORCPT ); Thu, 4 Sep 2014 10:40:54 -0400 Received: by mail-yh0-f47.google.com with SMTP id c41so6338567yho.6 for ; Thu, 04 Sep 2014 07:40:53 -0700 (PDT) X-Received: by 10.236.177.71 with SMTP id c47mr6006580yhm.116.1409841653491; Thu, 04 Sep 2014 07:40:53 -0700 (PDT) Received: from localhost.localdomain (host109-149-129-153.range109-149.btcentralplus.com. [109.149.129.153]) by mx.google.com with ESMTPSA id m28sm8695336yhb.50.2014.09.04.07.40.51 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Sep 2014 07:40:52 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: lee.jones@linaro.org, kernel@stlinux.com, wim@iguana.be, linux-watchdog@vger.kernel.org, David Paris Subject: [PATCH 4/4] watchdog: st_wdt: Add new driver for ST's LPC Watchdog Date: Thu, 4 Sep 2014 15:39:52 +0100 Message-Id: <1409841592-18890-6-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409841592-18890-1-git-send-email-lee.jones@linaro.org> References: <1409841592-18890-1-git-send-email-lee.jones@linaro.org> Sender: linux-watchdog-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: David Paris Signed-off-by: Lee Jones --- drivers/watchdog/Kconfig | 16 +++ drivers/watchdog/Makefile | 1 + drivers/watchdog/st_wdt.c | 314 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 331 insertions(+) create mode 100644 drivers/watchdog/st_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index f57312f..c8abf57 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -432,6 +432,22 @@ config SIRFSOC_WATCHDOG Support for CSR SiRFprimaII and SiRFatlasVI watchdog. When the watchdog triggers the system will be reset. +config ST_WATCHDOG + tristate "STMicroelectronics LPC Watchdog" + depends on ARCH_STI && OF + depends on !RTC_DRV_ST_LPC + select WATCHDOG_CORE + help + Say Y here to include Watchdog timer support for the watchdog + existing in the LPC of STMicroelectronics SOCs. + !!! BE CARREFUL !!! + This driver shares hardware resources with RTC Alarm part of the + LPC. Both LPC Watchdog driver and LPC RTC driver cannot be + used together. + + To compile this driver as a module, choose M here: the + module will be called st-wdt. + config TEGRA_WATCHDOG tristate "Tegra watchdog" depends on ARCH_TEGRA || COMPILE_TEST diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 468c320..eb19937 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -57,6 +57,7 @@ obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o +obj-$(CONFIG_ST_WATCHDOG) += st_wdt.o obj-$(CONFIG_BCM_KONA_WDT) += bcm_kona_wdt.o obj-$(CONFIG_TEGRA_WATCHDOG) += tegra_wdt.o diff --git a/drivers/watchdog/st_wdt.c b/drivers/watchdog/st_wdt.c new file mode 100644 index 0000000..b5dbc7d --- /dev/null +++ b/drivers/watchdog/st_wdt.c @@ -0,0 +1,314 @@ +/* + * st-wdt.c -- ST's LPC Watchdog + * + * Copyright (C) 2014 STMicroelectronics -- All Rights Reserved + * + * Author: David Paris for STMicroelectronics + * Contributor: Lee Jones for STMicroelectronics + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public Licence + * as published by the Free Software Foundation; either version + * 2 of the Licence, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Low Power Alarm */ +#define LPC_LPA_LSB_OFF 0x410 +#define LPC_LPA_START_OFF 0x418 + +/* LPC as WDT */ +#define LPC_WDT_OFF 0x510 + +#define WATCHDOG_MIN 1 +#define WATCHDOG_MAX32 4294967 /* 32bit resolution */ + +#define WDT_ENABLE 1 +#define WDT_DISABLE 0 + +struct st_wdog_syscfg { + struct regmap *regmap; + unsigned int type_reg; + unsigned int type_mask; + unsigned int enable_reg; + unsigned int enable_mask; +}; + +struct st_wdog { + void __iomem *base; + struct st_wdog_syscfg *syscfg; + struct clk *clk; + int warm_reset; +}; + +static struct st_wdog_syscfg stid127_syscfg = { + .type_mask = BIT(2), + .enable_mask = BIT(2), +}; + +static struct st_wdog_syscfg stih415_syscfg = { + .type_mask = BIT(6), + .enable_mask = BIT(7), +}; + +static struct st_wdog_syscfg stih416_syscfg = { + .type_mask = BIT(6), + .enable_mask = BIT(7), +}; + +static struct st_wdog_syscfg stih407_syscfg = { + .enable_mask = BIT(19), +}; + +static struct of_device_id st_wdog_match[] = { + { + .compatible = "st,stih407-watchdog", + .data = (void *)&stih407_syscfg, + }, + { + .compatible = "st,stih416-watchdog", + .data = (void *)&stih416_syscfg, + }, + { + .compatible = "st,stih415-watchdog", + .data = (void *)&stih415_syscfg, + }, + { + .compatible = "st,stid127-watchdog", + .data = (void *)&stid127_syscfg, + }, + {}, +}; +MODULE_DEVICE_TABLE(of, st_wdog_match); + +static void st_wdog_setup(struct st_wdog *st_wdog, bool enable) +{ + /* Type of watchdog reset - 0: Cold 1: Warm */ + if (st_wdog->syscfg->type_reg) + regmap_update_bits(st_wdog->syscfg->regmap, + st_wdog->syscfg->type_reg, + st_wdog->syscfg->type_mask, + st_wdog->warm_reset); + + /* Mask/unmask watchdog reset */ + regmap_update_bits(st_wdog->syscfg->regmap, + st_wdog->syscfg->enable_reg, + st_wdog->syscfg->enable_mask, + !enable); +} + +static void st_wdog_load_timer(struct st_wdog *st_wdog, unsigned int timeout) +{ + timeout *= clk_get_rate(st_wdog->clk); + + /* Write only LSB as timeout in Watchdog framework is 32bits only */ + writel_relaxed(timeout, st_wdog->base + LPC_LPA_LSB_OFF); + writel_relaxed(1, st_wdog->base + LPC_LPA_START_OFF); +} + +static int st_wdog_start(struct watchdog_device *wdd) +{ + struct st_wdog *st_wdog = watchdog_get_drvdata(wdd); + + writel_relaxed(1, st_wdog->base + LPC_WDT_OFF); + + return 0; +} + +static int st_wdog_stop(struct watchdog_device *wdd) +{ + struct st_wdog *st_wdog = watchdog_get_drvdata(wdd); + + writel_relaxed(0, st_wdog->base + LPC_WDT_OFF); + + return 0; +} + +static int st_wdog_set_timeout(struct watchdog_device *wdd, + unsigned int timeout) +{ + struct st_wdog *st_wdog = watchdog_get_drvdata(wdd); + + wdd->timeout = timeout; + st_wdog_load_timer(st_wdog, timeout); + + return 0; +} + +static int st_wdog_keepalive(struct watchdog_device *wdd) +{ + struct st_wdog *st_wdog = watchdog_get_drvdata(wdd); + + st_wdog_load_timer(st_wdog, wdd->timeout); + + return 0; +} + +static const struct watchdog_info st_wdog_info = { + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, + .identity = "ST LPC WDT", +}; + +static const struct watchdog_ops st_wdog_ops = { + .owner = THIS_MODULE, + .start = st_wdog_start, + .stop = st_wdog_stop, + .ping = st_wdog_keepalive, + .set_timeout = st_wdog_set_timeout, +}; + +static struct watchdog_device st_wdog_dev = { + .info = &st_wdog_info, + .ops = &st_wdog_ops, + .min_timeout = WATCHDOG_MIN, + .max_timeout = WATCHDOG_MAX32, +}; + +static int st_wdog_probe(struct platform_device *pdev) +{ + const struct of_device_id *match; + struct device_node *np = pdev->dev.of_node; + struct st_wdog *st_wdog; + struct regmap *regmap; + struct resource *res; + struct clk *clk; + void __iomem *base; + int ret; + + st_wdog = devm_kzalloc(&pdev->dev, sizeof(*st_wdog), GFP_KERNEL); + if (!st_wdog) + return -ENOMEM; + + match = of_match_device(st_wdog_match, &pdev->dev); + if (!match) { + dev_err(&pdev->dev, "Couldn't match device\n"); + return -ENODEV; + } + st_wdog->syscfg = (struct st_wdog_syscfg *)match->data; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "base"); + base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(base)) { + dev_err(&pdev->dev, "Failed to ioremap base\n"); + return PTR_ERR(base); + } + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-en"); + if (!res) { + dev_err(&pdev->dev, "Failed to get enable register address\n"); + return -EINVAL; + } + st_wdog->syscfg->enable_reg = res->start; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "syscfg-type"); + if (res) + st_wdog->syscfg->type_reg = res->start; + + regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg"); + if (IS_ERR(regmap)) { + dev_err(&pdev->dev, "No syscfg phandle specified\n"); + return PTR_ERR(regmap); + } + + clk = of_clk_get_by_name(np, "st_wdog"); + if (IS_ERR(clk)) { + dev_err(&pdev->dev, "Unable to request clock\n"); + return PTR_ERR(clk); + } + clk_prepare_enable(st_wdog->clk); + + st_wdog->base = base; + st_wdog->clk = clk; + st_wdog->warm_reset = of_property_read_bool(np, "st,warm_reset"); + st_wdog->syscfg->regmap = regmap; + + watchdog_set_drvdata(&st_wdog_dev, st_wdog); + watchdog_set_nowayout(&st_wdog_dev, WATCHDOG_NOWAYOUT); + + ret = watchdog_register_device(&st_wdog_dev); + if (ret) { + dev_err(&pdev->dev, "Unable to register watchdog\n"); + clk_disable_unprepare(clk); + return ret; + } + + /* Init Watchdog timeout with value in DT */ + ret = watchdog_init_timeout(&st_wdog_dev, 0, &pdev->dev); + if (ret) { + dev_err(&pdev->dev, "Unable to initialise watchdog timeout\n"); + return ret; + } + + st_wdog_setup(st_wdog, WDT_ENABLE); + + dev_info(&pdev->dev, "LPC Watchdog driver registered, reset type is %s", + st_wdog->warm_reset ? "warm" : "cold"); + + return ret; +} + +static int st_wdog_remove(struct platform_device *pdev) +{ + struct st_wdog *st_wdog = watchdog_get_drvdata(&st_wdog_dev); + + if (watchdog_active(&st_wdog_dev)) + st_wdog_stop(&st_wdog_dev); + + st_wdog_setup(st_wdog, WDT_DISABLE); + + watchdog_unregister_device(&st_wdog_dev); + + return 0; +} + +#ifdef CONFIG_PM +static int st_wdog_suspend(struct device *dev) +{ + if (watchdog_active(&st_wdog_dev)) + st_wdog_stop(&st_wdog_dev); + + return 0; +} + +static int st_wdog_resume(struct device *dev) +{ + struct st_wdog *st_wdog = watchdog_get_drvdata(&st_wdog_dev); + + if (watchdog_active(&st_wdog_dev)) { + st_wdog_load_timer(st_wdog, st_wdog_dev.timeout); + st_wdog_start(&st_wdog_dev); + } + + return 0; +} +#endif + +static SIMPLE_DEV_PM_OPS(st_wdog_pm_ops, + st_wdog_suspend, + st_wdog_resume); + +static struct platform_driver st_wdog_driver = { + .driver = { + .name = "st-wdt", + .pm = &st_wdog_pm_ops, + .of_match_table = st_wdog_match, + }, + .probe = st_wdog_probe, + .remove = st_wdog_remove, +}; +module_platform_driver(st_wdog_driver); + +MODULE_AUTHOR("David PARIS "); +MODULE_DESCRIPTION("ST LPC Watchdog Driver"); +MODULE_LICENSE("GPL v2");