From patchwork Fri Mar 16 08:14:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 7329 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 40ED623E0E for ; Fri, 16 Mar 2012 08:14:35 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id E0C7EA1826F for ; Fri, 16 Mar 2012 08:14:34 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id e36so6822589iag.11 for ; Fri, 16 Mar 2012 01:14:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:mime-version:content-type :x-gm-message-state; bh=6BpPAQz/bUd4/FozY+K520cr2zCYmvsKQDZ5NBaaOzM=; b=L8Q3kIgOlL0Ye1RUYbWrWm/R4U0jTuT1VHFqXxrmwKiy4LKZT/4tOvy/VohvN1DNbn /HySNdbS+IWYmX1I+PINwF5oXumMpmfm6afl6R1AYavMe3KB82p+JOXK4cB+CGfa1L3X kACj1FUFp8rYObAWd5tGeji9cleGzebM+Vlnfty84FH3T0IieVqT0Dn8jSL36JNUsw/M 8I+exhpXQz9DQuvf7mgbbeOZwujvTNEm2KVXs1t4gELFZBihKVJW70btDAXxgUqZben7 CdeRhtfFmCY3Nzhd5hErealx19VCqDTwxUr8XkYDhtQJdnGM7crki4J+HDjXq7161CBA AbCg== Received: by 10.50.197.132 with SMTP id iu4mr1630137igc.74.1331885674664; Fri, 16 Mar 2012 01:14:34 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.53.18 with SMTP id k18csp2581ibg; Fri, 16 Mar 2012 01:14:34 -0700 (PDT) Received: by 10.14.39.197 with SMTP id d45mr70311eeb.89.1331885672928; Fri, 16 Mar 2012 01:14:32 -0700 (PDT) Received: from eu1sys200aog106.obsmtp.com (eu1sys200aog106.obsmtp.com. [207.126.144.121]) by mx.google.com with SMTP id n13si454084eea.128.2012.03.16.01.14.24 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 16 Mar 2012 01:14:32 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.121 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) client-ip=207.126.144.121; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.121 is neither permitted nor denied by best guess record for domain of linus.walleij@stericsson.com) smtp.mail=linus.walleij@stericsson.com Received: from beta.dmz-ap.st.com ([138.198.100.35]) (using TLSv1) by eu1sys200aob106.postini.com ([207.126.147.11]) with SMTP ID DSNKT2L2XRd8E4pDv0cvwQkX62awnV6mnjdz@postini.com; Fri, 16 Mar 2012 08:14:32 UTC Received: from zeta.dmz-ap.st.com (ns6.st.com [138.198.234.13]) by beta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 7C1C4102; Fri, 16 Mar 2012 08:05:54 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-ap.st.com (STMicroelectronics) with ESMTP id 830E210ED; Fri, 16 Mar 2012 08:14:17 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 6E7BEA807D; Fri, 16 Mar 2012 09:14:13 +0100 (CET) Received: from steludxu4075.lud.stericsson.com (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Fri, 16 Mar 2012 09:14:16 +0100 From: Linus Walleij To: Wim Van Sebroeck , Cc: , Linus Walleij , Wolfram Sang Subject: [PATCH 2/2 v2] watchdog/coh901327: convert to use watchdog core Date: Fri, 16 Mar 2012 09:14:12 +0100 Message-ID: <1331885652-21750-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.9.2 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQm2OKT398GolVo2v4eC5785ROzJ3ZjU2QzCsCp9aTcDcAdZxnKbSABMu4rFxal2hjFVg315 From: Linus Walleij This converts the COH901327 watchdog to use the watchdog core. I followed Wolframs document, looked at some other drivers and tested it on the U300. Cc: Wolfram Sang Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebased on top of Viresh's GETTIMELEFT patch and consequently dropped the ioctl() call. --- drivers/watchdog/Kconfig | 1 + drivers/watchdog/coh901327_wdt.c | 192 +++++++++++--------------------------- 2 files changed, 56 insertions(+), 137 deletions(-) diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index df9e8f0..2a4c640 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -283,6 +283,7 @@ config COH901327_WATCHDOG bool "ST-Ericsson COH 901 327 watchdog" depends on ARCH_U300 default y if MACH_U300 + select WATCHDOG_CORE help Say Y here to include Watchdog timer support for the watchdog embedded into the ST-Ericsson U300 series platforms. diff --git a/drivers/watchdog/coh901327_wdt.c b/drivers/watchdog/coh901327_wdt.c index 5b89f7d..7f0cbeb 100644 --- a/drivers/watchdog/coh901327_wdt.c +++ b/drivers/watchdog/coh901327_wdt.c @@ -8,17 +8,15 @@ */ #include #include -#include -#include #include #include #include #include #include #include -#include #include #include +#include #define DRV_NAME "WDOG COH 901 327" @@ -74,8 +72,6 @@ static resource_size_t phybase; static resource_size_t physize; static int irq; static void __iomem *virtbase; -static unsigned long coh901327_users; -static unsigned long boot_status; static struct device *parent; /* @@ -155,30 +151,31 @@ static void coh901327_disable(void) __func__, val); } -static void coh901327_start(void) +static int coh901327_start(struct watchdog_device *wdt_dev) { coh901327_enable(margin * 100); + return 0; +} + +static int coh901327_stop(struct watchdog_device *wdt_dev) +{ + coh901327_disable(); + return 0; } -static void coh901327_keepalive(void) +static int coh901327_ping(struct watchdog_device *wdd) { clk_enable(clk); /* Feed the watchdog */ writew(U300_WDOG_FR_FEED_RESTART_TIMER, virtbase + U300_WDOG_FR); clk_disable(clk); + return 0; } -static int coh901327_settimeout(int time) +static int coh901327_settimeout(struct watchdog_device *wdt_dev, + unsigned int time) { - /* - * Max margin is 327 since the 10ms - * timeout register is max - * 0x7FFF = 327670ms ~= 327s. - */ - if (time <= 0 || time > 327) - return -EINVAL; - margin = time; clk_enable(clk); /* Set new timeout value */ @@ -190,6 +187,23 @@ static int coh901327_settimeout(int time) return 0; } +static unsigned int coh901327_gettimeleft(struct watchdog_device *wdt_dev) +{ + u16 val; + + clk_enable(clk); + /* Read repeatedly until the value is stable! */ + val = readw(virtbase + U300_WDOG_CR); + while (val & U300_WDOG_CR_VALID_IND) + val = readw(virtbase + U300_WDOG_CR); + val &= U300_WDOG_CR_COUNT_VALUE_MASK; + clk_disable(clk); + if (val != 0) + val /= 100; + + return val; +} + /* * This interrupt occurs 10 ms before the watchdog WILL bark. */ @@ -218,130 +232,35 @@ static irqreturn_t coh901327_interrupt(int irq, void *data) return IRQ_HANDLED; } -/* - * Allow only one user (daemon) to open the watchdog - */ -static int coh901327_open(struct inode *inode, struct file *file) -{ - if (test_and_set_bit(1, &coh901327_users)) - return -EBUSY; - coh901327_start(); - return nonseekable_open(inode, file); -} - -static int coh901327_release(struct inode *inode, struct file *file) -{ - clear_bit(1, &coh901327_users); - coh901327_disable(); - return 0; -} - -static ssize_t coh901327_write(struct file *file, const char __user *data, - size_t len, loff_t *ppos) -{ - if (len) - coh901327_keepalive(); - return len; -} - -static long coh901327_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - int ret = -ENOTTY; - u16 val; - int time; - int new_options; - union { - struct watchdog_info __user *ident; - int __user *i; - } uarg; - static const struct watchdog_info ident = { - .options = WDIOF_CARDRESET | - WDIOF_SETTIMEOUT | - WDIOF_KEEPALIVEPING, - .identity = "COH 901 327 Watchdog", - .firmware_version = 1, - }; - uarg.i = (int __user *)arg; - - switch (cmd) { - case WDIOC_GETSUPPORT: - ret = copy_to_user(uarg.ident, &ident, - sizeof(ident)) ? -EFAULT : 0; - break; - - case WDIOC_GETSTATUS: - ret = put_user(0, uarg.i); - break; - - case WDIOC_GETBOOTSTATUS: - ret = put_user(boot_status, uarg.i); - break; - - case WDIOC_SETOPTIONS: - ret = get_user(new_options, uarg.i); - if (ret) - break; - if (new_options & WDIOS_DISABLECARD) - coh901327_disable(); - if (new_options & WDIOS_ENABLECARD) - coh901327_start(); - ret = 0; - break; - - case WDIOC_KEEPALIVE: - coh901327_keepalive(); - ret = 0; - break; - - case WDIOC_SETTIMEOUT: - ret = get_user(time, uarg.i); - if (ret) - break; - - ret = coh901327_settimeout(time); - if (ret) - break; - /* Then fall through to return set value */ - - case WDIOC_GETTIMEOUT: - ret = put_user(margin, uarg.i); - break; - - case WDIOC_GETTIMELEFT: - clk_enable(clk); - /* Read repeatedly until the value is stable! */ - val = readw(virtbase + U300_WDOG_CR); - while (val & U300_WDOG_CR_VALID_IND) - val = readw(virtbase + U300_WDOG_CR); - val &= U300_WDOG_CR_COUNT_VALUE_MASK; - clk_disable(clk); - if (val != 0) - val /= 100; - ret = put_user(val, uarg.i); - break; - } - return ret; -} +static const struct watchdog_info coh901327_ident = { + .options = WDIOF_CARDRESET | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, + .identity = DRV_NAME, +}; -static const struct file_operations coh901327_fops = { - .owner = THIS_MODULE, - .llseek = no_llseek, - .write = coh901327_write, - .unlocked_ioctl = coh901327_ioctl, - .open = coh901327_open, - .release = coh901327_release, +static struct watchdog_ops coh901327_ops = { + .owner = THIS_MODULE, + .start = coh901327_start, + .stop = coh901327_stop, + .ping = coh901327_ping, + .set_timeout = coh901327_settimeout, + .get_timeleft = coh901327_gettimeleft, }; -static struct miscdevice coh901327_miscdev = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", - .fops = &coh901327_fops, +static struct watchdog_device coh901327_wdt = { + .info = &coh901327_ident, + .ops = &coh901327_ops, + /* + * Max margin is 327 since the 10ms + * timeout register is max + * 0x7FFF = 327670ms ~= 327s. + */ + .min_timeout = 0, + .max_timeout = 327, }; static int __exit coh901327_remove(struct platform_device *pdev) { - misc_deregister(&coh901327_miscdev); + watchdog_unregister_device(&coh901327_wdt); coh901327_disable(); free_irq(irq, pdev); clk_put(clk); @@ -350,7 +269,6 @@ static int __exit coh901327_remove(struct platform_device *pdev) return 0; } - static int __init coh901327_probe(struct platform_device *pdev) { int ret; @@ -393,7 +311,7 @@ static int __init coh901327_probe(struct platform_device *pdev) case U300_WDOG_SR_STATUS_TIMED_OUT: dev_info(&pdev->dev, "watchdog timed out since last chip reset!\n"); - boot_status = WDIOF_CARDRESET; + coh901327_wdt.bootstatus |= WDIOF_CARDRESET; /* Status will be cleared below */ break; case U300_WDOG_SR_STATUS_NORMAL: @@ -435,7 +353,7 @@ static int __init coh901327_probe(struct platform_device *pdev) clk_disable(clk); - ret = misc_register(&coh901327_miscdev); + ret = watchdog_register_device(&coh901327_wdt); if (ret == 0) dev_info(&pdev->dev, "initialized. timer margin=%d sec\n", margin); @@ -547,4 +465,4 @@ module_param(margin, int, 0); MODULE_PARM_DESC(margin, "Watchdog margin in seconds (default 60s)"); MODULE_LICENSE("GPL"); -MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); +MODULE_ALIAS("platform:coh901327-watchdog");