From patchwork Fri Mar 22 13:36:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lartey X-Patchwork-Id: 2320231 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id A69BD3FD8C for ; Fri, 22 Mar 2013 13:43:05 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UJ2Bp-0006Bm-GD; Fri, 22 Mar 2013 13:39:26 +0000 Received: from slimlogic.co.uk ([89.16.172.20]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UJ28l-00055e-Ep for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2013 13:36:26 +0000 Received: from localhost.localdomain (cpc3-sgyl22-0-0-cust168.18-2.cable.virginmedia.com [82.42.202.169]) by slimlogic.co.uk (Postfix) with ESMTPSA id CCF5C130A57; Fri, 22 Mar 2013 13:36:10 +0000 (GMT) From: Ian Lartey To: linux-kernel@vger.kernel.org Subject: [PATCH v9 03/11] watchdog: add Palmas Watchdog support Date: Fri, 22 Mar 2013 13:36:05 +0000 Message-Id: <1363959373-10671-4-git-send-email-ian@slimlogic.co.uk> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1363959373-10671-1-git-send-email-ian@slimlogic.co.uk> References: <1363959373-10671-1-git-send-email-ian@slimlogic.co.uk> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130322_093615_986710_AEEE8710 X-CRM114-Status: GOOD ( 17.53 ) X-Spam-Score: -4.4 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.5 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.0 T_FRT_COCK BODY: ReplaceTags: Cock -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-doc@vger.kernel.org, linus.walleij@linaro.org, grant.likely@secretlab.ca, wim@iguana.be, ldewangan@nvidia.com, gg@slimlogic.co.uk, linux-leds@vger.kernel.org, sfr@canb.auug.org.au, mturquette@linaro.org, sameo@linux.intel.com, linux-watchdog@vger.kernel.org, swarren@wwwdotorg.org, devicetree-discuss@lists.ozlabs.org, cooloney@gmail.com, rob.herring@calxeda.com, linux-arm-kernel@lists.infradead.org, j-keerthy@ti.com, broonie@opensource.wolfsonmicro.com, lgirdwood@gmail.com, t-kristo@ti.com, rpurdie@rpsys.net, rob@landley.net, akpm@linux-foundation.org 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 From: Graeme Gregory Add support for the Palmas watchdog timer which has a timeout configurable from 1s to 128s. Signed-off-by: Graeme Gregory Signed-off-by: Ian Lartey --- drivers/watchdog/palmas_wdt.c | 169 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 169 insertions(+), 0 deletions(-) create mode 100644 drivers/watchdog/palmas_wdt.c diff --git a/drivers/watchdog/palmas_wdt.c b/drivers/watchdog/palmas_wdt.c new file mode 100644 index 0000000..da7e379 --- /dev/null +++ b/drivers/watchdog/palmas_wdt.c @@ -0,0 +1,169 @@ +/* + * Driver for Watchdog part of Palmas PMIC Chips + * + * Copyright 2011-2013 Texas Instruments Inc. + * + * Author: Graeme Gregory + * Author: Ian Lartey + * + * Based on twl4030_wdt.c + * + * Author: Timo Kokkonen + * + * 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. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct palmas_wdt { + struct palmas *palmas; + struct watchdog_device wdt; + struct device *dev; + + int timer_margin; +}; + + +static int nowayout = WATCHDOG_NOWAYOUT; +module_param(nowayout, int, 0); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " + "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static int palmas_wdt_write(struct palmas *palmas, unsigned int data) +{ + unsigned int addr; + + addr = PALMAS_BASE_TO_REG(PALMAS_PMU_CONTROL_BASE, PALMAS_WATCHDOG); + + return palmas_write(palmas, PALMAS_PMU_CONTROL_BASE, addr, addr); +} + +static int palmas_wdt_enable(struct watchdog_device *wdt) +{ + struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt); + struct palmas *palmas = driver_data->palmas; + + return palmas_wdt_write(palmas, driver_data->timer_margin | + PALMAS_WATCHDOG_ENABLE); +} + +static int palmas_wdt_disable(struct watchdog_device *wdt) +{ + struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt); + struct palmas *palmas = driver_data->palmas; + + return palmas_wdt_write(palmas, driver_data->timer_margin); +} + +static int palmas_wdt_set_timeout(struct watchdog_device *wdt, unsigned timeout) +{ + struct palmas_wdt *driver_data = watchdog_get_drvdata(wdt); + + if (timeout < 1 || timeout > 128) { + dev_warn(driver_data->dev, + "Timeout can only be in the range [1-128] seconds"); + return -EINVAL; + } + driver_data->timer_margin = fls(timeout) - 1; + return 0; +} + +static const struct watchdog_info palmas_wdt_info = { + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, + .identity = "Palmas Watchdog", + .firmware_version = 0, +}; + +static const struct watchdog_ops palmas_wdt_ops = { + .owner = THIS_MODULE, + .start = palmas_wdt_enable, + .stop = palmas_wdt_disable, + .ping = palmas_wdt_enable, + .set_timeout = palmas_wdt_set_timeout, +}; + +static int palmas_wdt_probe(struct platform_device *pdev) +{ + struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); + struct palmas_wdt *driver_data; + struct watchdog_device *palmas_wdt; + int ret = 0; + + driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data), + GFP_KERNEL); + if (!driver_data) { + dev_err(&pdev->dev, "Unable to alloacate watchdog device\n"); + ret = -ENOMEM; + goto err; + } + + driver_data->palmas = palmas; + + palmas_wdt = &driver_data->wdt; + + palmas_wdt->info = &palmas_wdt_info; + palmas_wdt->ops = &palmas_wdt_ops; + watchdog_set_nowayout(palmas_wdt, nowayout); + watchdog_set_drvdata(palmas_wdt, driver_data); + + ret = watchdog_register_device(&driver_data->wdt); + if (ret) { + platform_set_drvdata(pdev, NULL); + goto err; + } + + dev_set_drvdata(&pdev->dev, driver_data); + + return 0; +err: + return ret; +} + +static int palmas_wdt_remove(struct platform_device *pdev) +{ + struct palmas_wdt *driver_data = dev_get_drvdata(&pdev->dev); + + watchdog_unregister_device(&driver_data->wdt); + + return 0; +} + +static struct of_device_id of_palmas_match_tbl[] = { + { .compatible = "ti,palmas-wdt", }, + { .compatible = "ti,twl6035-wdt", }, + { .compatible = "ti,twl6036-wdt", }, + { .compatible = "ti,twl6037-wdt", }, + { .compatible = "ti,tps65913-wdt", }, + { .compatible = "ti,tps65914-wdt", }, + { .compatible = "ti,tps80036-wdt", }, + { /* end */ } +}; + +static struct platform_driver palmas_wdt_driver = { + .probe = palmas_wdt_probe, + .remove = palmas_wdt_remove, + .driver = { + .owner = THIS_MODULE, + .of_match_table = of_palmas_match_tbl, + .name = "palmas-wdt", + }, +}; + +module_platform_driver(palmas_wdt_driver); + +MODULE_AUTHOR("Graeme Gregory "); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:palmas-wdt"); +MODULE_DEVICE_TABLE(of, of_palmas_match_tbl);