From patchwork Sat May 25 10:59:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carlo Caione X-Patchwork-Id: 2613101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by patchwork2.kernel.org (Postfix) with ESMTP id 24576DF2A2 for ; Sat, 25 May 2013 11:00:40 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UgCD7-0007uP-5W; Sat, 25 May 2013 11:00:29 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UgCD4-0007Pd-A6; Sat, 25 May 2013 11:00:26 +0000 Received: from mail-ee0-f53.google.com ([74.125.83.53]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UgCD0-0007Oz-Nr for linux-arm-kernel@lists.infradead.org; Sat, 25 May 2013 11:00:24 +0000 Received: by mail-ee0-f53.google.com with SMTP id c1so2955637eek.26 for ; Sat, 25 May 2013 04:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=o1bjV1uNeb1/WL/da1pfUBj1Rb02i4XzEw+6+ZYay3w=; b=J5VzmrrZWi7WUZowjC40HYYon1Wf4q5wDTpn17PPpbBF549L7tsaujfXLl8cgYVLvN T94Fwc20xRw9vFlR9KmKUcsF1hcraEVH70IakWBTo0xYbtcwM8zkhV4oaBAwnkrAoOpw AFpRtjePh8YEQYqjymHi3nTXw5j1UIbPe7XWswbUTFwma2Mhpq4J6njviddKUBysljSZ l/hamnmL1lmMOlLUikhCYxyHn1r6NSlgXbqqnakCdW1yKCZ1IRKyyen8VXubk7TyCg9H atxGvzyznqjSi0WhQklz2Mjd4AErDGJZmnCQJdLd0mBEUCTLvR2jdNh3fjxwL4ZFjWi3 nkKA== X-Received: by 10.14.211.69 with SMTP id v45mr47354263eeo.45.1369479600241; Sat, 25 May 2013 04:00:00 -0700 (PDT) Received: from satan.fastwebnet.it (2-238-57-164.ip242.fastwebnet.it. [2.238.57.164]) by mx.google.com with ESMTPSA id z52sm29181966eea.1.2013.05.25.03.59.58 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 25 May 2013 03:59:59 -0700 (PDT) From: Carlo Caione To: wim@iguana.be, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, maxime.ripard@free-electrons.com, linux-sunxi@googlegroups.com, henrik@henriknordstrom.net Subject: [PATCH v3] ARM: sunxi: New watchdog driver for Allwinner A10/A13 Date: Sat, 25 May 2013 12:59:27 +0200 Message-Id: <1369479567-15104-1-git-send-email-carlo.caione@gmail.com> X-Mailer: git-send-email 1.8.2.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130525_070023_056865_4033855D X-CRM114-Status: GOOD ( 22.79 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (carlo.caione[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.83.53 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Carlo Caione X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch adds the driver for the watchdog found in the Allwinner A10 and A13 SoCs. It has DT-support and uses the new watchdog framework. Signed-off-by: Carlo Caione Acked-by: Maxime Ripard --- drivers/watchdog/Kconfig | 10 ++ drivers/watchdog/Makefile | 1 + drivers/watchdog/sunxi_wdt.c | 224 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+) create mode 100644 drivers/watchdog/sunxi_wdt.c diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index e89fc31..8ad2238 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -299,6 +299,16 @@ config ORION_WATCHDOG To compile this driver as a module, choose M here: the module will be called orion_wdt. +config SUNXI_WATCHDOG + tristate "Allwinner SoCs watchdog support" + depends on ARCH_SUNXI + select WATCHDOG_CORE + help + Say Y here to include support for the watchdog timer + in Allwinner SoCs. + To compile this driver as a module, choose M here: the + module will be called sunxi_wdt. + config COH901327_WATCHDOG bool "ST-Ericsson COH 901 327 watchdog" depends on ARCH_U300 diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index a300b94..5012d5f 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_PNX4008_WATCHDOG) += pnx4008_wdt.o obj-$(CONFIG_IOP_WATCHDOG) += iop_wdt.o obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o +obj-$(CONFIG_SUNXI_WATCHDOG) += sunxi_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_RTC_WATCHDOG) += stmp3xxx_rtc_wdt.o obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o diff --git a/drivers/watchdog/sunxi_wdt.c b/drivers/watchdog/sunxi_wdt.c new file mode 100644 index 0000000..270d41e --- /dev/null +++ b/drivers/watchdog/sunxi_wdt.c @@ -0,0 +1,224 @@ +/* + * sunxi Watchdog Driver + * + * Copyright (c) 2013 Carlo Caione + * 2012 Henrik Nordstrom + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * Based on xen_wdt.c + * (c) Copyright 2010 Novell, Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WDT_MAX_TIMEOUT 16 +#define WDT_MIN_TIMEOUT 1 +#define WDT_MODE_TIMEOUT(n) ((n) << 3) +#define WDT_TIMEOUT_MASK WDT_MODE_TIMEOUT(0x0F) + +#define WDT_CTRL 0x00 +#define WDT_CTRL_RELOAD ((1 << 0) | (0x0a57 << 1)) + +#define WDT_MODE 0x04 +#define WDT_MODE_EN (1 << 0) +#define WDT_MODE_RST_EN (1 << 1) + +#define DRV_NAME "sunxi-wdt" +#define DRV_VERSION "1.0" + +static bool nowayout = WATCHDOG_NOWAYOUT; +static int heartbeat = WDT_MAX_TIMEOUT; + +/* + * wdt_timeout_map maps the watchdog timer interval value in seconds to + * the value of the register WDT_MODE bit 3:6 + * + * [timeout seconds] = register value + * + */ + +static const int wdt_timeout_map[] = { + [1] = 0b0001, /* 1s */ + [2] = 0b0010, /* 2s */ + [3] = 0b0011, /* 3s */ + [4] = 0b0100, /* 4s */ + [5] = 0b0101, /* 5s */ + [6] = 0b0110, /* 6s */ + [8] = 0b0111, /* 8s */ + [10] = 0b1000, /* 10s */ + [12] = 0b1001, /* 12s */ + [14] = 0b1010, /* 14s */ + [16] = 0b1011, /* 16s */ +}; + +static int sunxi_wdt_ping(struct watchdog_device *sunxi_wdt_dev) +{ + void __iomem *wdt_base = watchdog_get_drvdata(sunxi_wdt_dev); + + iowrite32(WDT_CTRL_RELOAD, wdt_base + WDT_CTRL); + + return 0; +} + +static int sunxi_wdt_set_timeout(struct watchdog_device *sunxi_wdt_dev, + unsigned int timeout) +{ + u32 reg; + int ret = 0; + void __iomem *wdt_base = watchdog_get_drvdata(sunxi_wdt_dev); + + if ((timeout > WDT_MAX_TIMEOUT) || (0 == wdt_timeout_map[timeout])) { + ret = -EINVAL; + goto exit; + } + + sunxi_wdt_dev->timeout = timeout; + + reg = ioread32(wdt_base + WDT_MODE); + reg &= ~(WDT_TIMEOUT_MASK); + reg |= WDT_MODE_TIMEOUT(wdt_timeout_map[sunxi_wdt_dev->timeout]); + iowrite32(reg, wdt_base + WDT_MODE); + + sunxi_wdt_ping(sunxi_wdt_dev); + +exit: + return ret; +} + +static int sunxi_wdt_stop(struct watchdog_device *sunxi_wdt_dev) +{ + void __iomem *wdt_base = watchdog_get_drvdata(sunxi_wdt_dev); + + iowrite32(0, wdt_base + WDT_MODE); + + return 0; +} + +static int sunxi_wdt_start(struct watchdog_device *sunxi_wdt_dev) +{ + u32 reg; + int ret = 0; + void __iomem *wdt_base = watchdog_get_drvdata(sunxi_wdt_dev); + + ret = sunxi_wdt_set_timeout(sunxi_wdt_dev, sunxi_wdt_dev->timeout); + if (ret < 0) + goto exit; + + reg = ioread32(wdt_base + WDT_MODE); + reg |= (WDT_MODE_RST_EN | WDT_MODE_EN); + iowrite32(reg, wdt_base + WDT_MODE); + +exit: + return ret; +} + +static const struct watchdog_info sunxi_wdt_info = { + .identity = DRV_NAME, + .options = WDIOF_SETTIMEOUT | + WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE, +}; + +static const struct watchdog_ops sunxi_wdt_ops = { + .owner = THIS_MODULE, + .start = sunxi_wdt_start, + .stop = sunxi_wdt_stop, + .ping = sunxi_wdt_ping, + .set_timeout = sunxi_wdt_set_timeout, +}; + +static struct watchdog_device sunxi_wdt_dev = { + .info = &sunxi_wdt_info, + .ops = &sunxi_wdt_ops, + .timeout = WDT_MAX_TIMEOUT, + .max_timeout = WDT_MAX_TIMEOUT, + .min_timeout = WDT_MIN_TIMEOUT, +}; + +static int __init sunxi_wdt_probe(struct platform_device *pdev) +{ + int err; + void __iomem *wdt_base; + + wdt_base = of_iomap(pdev->dev.of_node, 0); + if (unlikely(!wdt_base)) { + err = -ENOMEM; + goto error_mem_out; + } + + sunxi_wdt_dev.parent = &pdev->dev; + watchdog_init_timeout(&sunxi_wdt_dev, heartbeat, &pdev->dev); + watchdog_set_nowayout(&sunxi_wdt_dev, nowayout); + + err = watchdog_register_device(&sunxi_wdt_dev); + if (unlikely(err)) + goto error_wdt; + + watchdog_set_drvdata(&sunxi_wdt_dev, wdt_base); + + pr_info("Watchdog enabled (heartbeat=%d sec, nowayout=%d)", + sunxi_wdt_dev.timeout, nowayout); + return 0; + +error_wdt: + iounmap(wdt_base); +error_mem_out: + return err; +} + +static int __exit sunxi_wdt_remove(struct platform_device *pdev) +{ + void __iomem *wdt_base = watchdog_get_drvdata(&sunxi_wdt_dev); + + sunxi_wdt_stop(&sunxi_wdt_dev); + watchdog_unregister_device(&sunxi_wdt_dev); + iounmap(wdt_base); + + return 0; +} + +static const struct of_device_id sunxi_wdt_dt_ids[] = { + { .compatible = "allwinner,sun4i-wdt" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, sunxi_wdt_dt_ids); + +static struct platform_driver sunxi_wdt_driver = { + .probe = sunxi_wdt_probe, + .remove = sunxi_wdt_remove, + .driver = { + .owner = THIS_MODULE, + .name = DRV_NAME, + .of_match_table = of_match_ptr(sunxi_wdt_dt_ids) + }, +}; + +module_platform_driver(sunxi_wdt_driver); + +module_param(heartbeat, int, 0); +MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds"); + +module_param(nowayout, bool, 0); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Carlo Caione "); +MODULE_AUTHOR("Henrik Nordstrom "); +MODULE_DESCRIPTION("sunxi WatchDog Timer Driver"); +MODULE_VERSION(DRV_VERSION);