From patchwork Fri Jan 31 14:18:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 3561841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 751BAC02DC for ; Fri, 31 Jan 2014 14:26:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 27D2120213 for ; Fri, 31 Jan 2014 14:26:23 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7FFCA201BC for ; Fri, 31 Jan 2014 14:26:21 +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 1W9F2n-0004fC-Da; Fri, 31 Jan 2014 14:26:09 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1W9F2l-0001Xa-0S; Fri, 31 Jan 2014 14:26:07 +0000 Received: from mail-ea0-f179.google.com ([209.85.215.179]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1W9F2h-0001Ww-6D for linux-arm-kernel@lists.infradead.org; Fri, 31 Jan 2014 14:26:04 +0000 Received: by mail-ea0-f179.google.com with SMTP id q10so1980471ead.10 for ; Fri, 31 Jan 2014 06:25:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :content-type; bh=tHd85NkONLNimseTU07hDZNhV9x3IrFW5MiERD5Ukh0=; b=Sovv4piDOl1PTaIdXshsegAldXy1oy87nvGb+vsPpuzgAYrdFwTE0Al1Gn6RLqBTC/ Wp/LjulopHaMxw+2DEFxq1VBAzoQWr8wrfEe+N3RcWC2qMEZf/O1qF8LM1t04Auaxphl 4F+k2FCmM4ITXLrtfDXtM2kE/+PdYv1rTJ22Du5fqY2t09mHG76GBVRGLpcoa6Dh/b8a UfmszqzKkjSpa6SJmTMZbormKJwa/zdN8eE7p9AlOZSLwqBt8KZCvZf2BKYEn1mhVsIY PoX9RsnEt/R9jjoy9zYyAV2uVb1GEmBfl/jVE4Eu5btlh/SnEJKZPz1JcKLaKCOu/THm JQBg== X-Gm-Message-State: ALoCoQnd2rOAh6WbGD0PN0GJCKrb/y5h5nUmuggX+bd79vDY1Co6fbQ3xA5uBcp/Ru3C9138c8E9 X-Received: by 10.14.218.7 with SMTP id j7mr1382764eep.107.1391177913575; Fri, 31 Jan 2014 06:18:33 -0800 (PST) Received: from localhost (nat-63.starnet.cz. [178.255.168.63]) by mx.google.com with ESMTPSA id n7sm36882352eef.5.2014.01.31.06.18.32 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Fri, 31 Jan 2014 06:18:32 -0800 (PST) From: Michal Simek To: linux-kernel@vger.kernel.org, monstr@monstr.eu Subject: [PATCH 01/10] watchdog: xilinx: Convert driver to the watchdog framework Date: Fri, 31 Jan 2014 15:18:10 +0100 Message-Id: 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-20140131_092603_443668_C74BC36B X-CRM114-Status: GOOD ( 25.12 ) X-Spam-Score: -1.9 (-) Cc: Wim Van Sebroeck , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.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 X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - Remove uneeded headers, fops functions - Use xilinx_wdt prefix in start/stop/keepalive functions and in new structures Signed-off-by: Michal Simek Reviewed-by: Guenter Roeck --- drivers/watchdog/Kconfig | 1 + drivers/watchdog/of_xilinx_wdt.c | 204 ++++++--------------------------------- 2 files changed, 33 insertions(+), 172 deletions(-) -- 1.8.2.3 diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 4c4c566..9db5d3c 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig @@ -1025,6 +1025,7 @@ config M54xx_WATCHDOG config XILINX_WATCHDOG tristate "Xilinx Watchdog timer" depends on MICROBLAZE + select WATCHDOG_CORE ---help--- Watchdog driver for the xps_timebase_wdt ip core. diff --git a/drivers/watchdog/of_xilinx_wdt.c b/drivers/watchdog/of_xilinx_wdt.c index fb57103..8c2814e 100644 --- a/drivers/watchdog/of_xilinx_wdt.c +++ b/drivers/watchdog/of_xilinx_wdt.c @@ -1,6 +1,7 @@ /* * Watchdog Device Driver for Xilinx axi/xps_timebase_wdt * + * (C) Copyright 2013 - 2014 Xilinx, Inc. * (C) Copyright 2011 (Alejandro Cabrera ) * * This program is free software; you can redistribute it and/or @@ -14,13 +15,10 @@ #include #include #include -#include -#include #include #include #include #include -#include #include #include #include @@ -48,22 +46,18 @@ struct xwdt_device { struct resource res; void __iomem *base; - u32 nowayout; u32 wdt_interval; - u32 boot_status; }; static struct xwdt_device xdev; static u32 timeout; static u32 control_status_reg; -static u8 expect_close; static u8 no_timeout; -static unsigned long driver_open; static DEFINE_SPINLOCK(spinlock); -static void xwdt_start(void) +static int xilinx_wdt_start(struct watchdog_device *wdd) { spin_lock(&spinlock); @@ -77,9 +71,11 @@ static void xwdt_start(void) iowrite32(XWT_CSRX_EWDT2_MASK, xdev.base + XWT_TWCSR1_OFFSET); spin_unlock(&spinlock); + + return 0; } -static void xwdt_stop(void) +static int xilinx_wdt_stop(struct watchdog_device *wdd) { spin_lock(&spinlock); @@ -92,9 +88,11 @@ static void xwdt_stop(void) spin_unlock(&spinlock); pr_info("Stopped!\n"); + + return 0; } -static void xwdt_keepalive(void) +static int xilinx_wdt_keepalive(struct watchdog_device *wdd) { spin_lock(&spinlock); @@ -103,23 +101,28 @@ static void xwdt_keepalive(void) iowrite32(control_status_reg, xdev.base + XWT_TWCSR0_OFFSET); spin_unlock(&spinlock); -} -static void xwdt_get_status(int *status) -{ - int new_status; + return 0; +} - spin_lock(&spinlock); +static const struct watchdog_info xilinx_wdt_ident = { + .options = WDIOF_MAGICCLOSE | + WDIOF_KEEPALIVEPING, + .firmware_version = 1, + .identity = WATCHDOG_NAME, +}; - control_status_reg = ioread32(xdev.base + XWT_TWCSR0_OFFSET); - new_status = ((control_status_reg & - (XWT_CSR0_WRS_MASK | XWT_CSR0_WDS_MASK)) != 0); - spin_unlock(&spinlock); +static const struct watchdog_ops xilinx_wdt_ops = { + .owner = THIS_MODULE, + .start = xilinx_wdt_start, + .stop = xilinx_wdt_stop, + .ping = xilinx_wdt_keepalive, +}; - *status = 0; - if (new_status & 1) - *status |= WDIOF_CARDRESET; -} +static struct watchdog_device xilinx_wdt_wdd = { + .info = &xilinx_wdt_ident, + .ops = &xilinx_wdt_ops, +}; static u32 xwdt_selftest(void) { @@ -146,139 +149,6 @@ static u32 xwdt_selftest(void) return XWT_TIMER_FAILED; } -static int xwdt_open(struct inode *inode, struct file *file) -{ - /* Only one process can handle the wdt at a time */ - if (test_and_set_bit(0, &driver_open)) - return -EBUSY; - - /* Make sure that the module are always loaded...*/ - if (xdev.nowayout) - __module_get(THIS_MODULE); - - xwdt_start(); - pr_info("Started...\n"); - - return nonseekable_open(inode, file); -} - -static int xwdt_release(struct inode *inode, struct file *file) -{ - if (expect_close == 42) { - xwdt_stop(); - } else { - pr_crit("Unexpected close, not stopping watchdog!\n"); - xwdt_keepalive(); - } - - clear_bit(0, &driver_open); - expect_close = 0; - return 0; -} - -/* - * xwdt_write: - * @file: file handle to the watchdog - * @buf: buffer to write (unused as data does not matter here - * @count: count of bytes - * @ppos: pointer to the position to write. No seeks allowed - * - * A write to a watchdog device is defined as a keepalive signal. Any - * write of data will do, as we don't define content meaning. - */ -static ssize_t xwdt_write(struct file *file, const char __user *buf, - size_t len, loff_t *ppos) -{ - if (len) { - if (!xdev.nowayout) { - size_t i; - - /* In case it was set long ago */ - expect_close = 0; - - for (i = 0; i != len; i++) { - char c; - - if (get_user(c, buf + i)) - return -EFAULT; - if (c == 'V') - expect_close = 42; - } - } - xwdt_keepalive(); - } - return len; -} - -static const struct watchdog_info ident = { - .options = WDIOF_MAGICCLOSE | - WDIOF_KEEPALIVEPING, - .firmware_version = 1, - .identity = WATCHDOG_NAME, -}; - -/* - * xwdt_ioctl: - * @file: file handle to the device - * @cmd: watchdog command - * @arg: argument pointer - * - * The watchdog API defines a common set of functions for all watchdogs - * according to their available features. - */ -static long xwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) -{ - int status; - - union { - struct watchdog_info __user *ident; - int __user *i; - } uarg; - - uarg.i = (int __user *)arg; - - switch (cmd) { - case WDIOC_GETSUPPORT: - return copy_to_user(uarg.ident, &ident, - sizeof(ident)) ? -EFAULT : 0; - - case WDIOC_GETBOOTSTATUS: - return put_user(xdev.boot_status, uarg.i); - - case WDIOC_GETSTATUS: - xwdt_get_status(&status); - return put_user(status, uarg.i); - - case WDIOC_KEEPALIVE: - xwdt_keepalive(); - return 0; - - case WDIOC_GETTIMEOUT: - if (no_timeout) - return -ENOTTY; - else - return put_user(timeout, uarg.i); - - default: - return -ENOTTY; - } -} - -static const struct file_operations xwdt_fops = { - .owner = THIS_MODULE, - .llseek = no_llseek, - .write = xwdt_write, - .open = xwdt_open, - .release = xwdt_release, - .unlocked_ioctl = xwdt_ioctl, -}; - -static struct miscdevice xwdt_miscdev = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", - .fops = &xwdt_fops, -}; - static int xwdt_probe(struct platform_device *pdev) { int rc; @@ -314,7 +184,7 @@ static int xwdt_probe(struct platform_device *pdev) "xlnx,wdt-enable-once", NULL); if (tmptr == NULL) { pr_warn("Parameter \"xlnx,wdt-enable-once\" not found in device tree!\n"); - xdev.nowayout = WATCHDOG_NOWAYOUT; + watchdog_set_nowayout(&xilinx_wdt_wdd, true); } /* @@ -344,24 +214,14 @@ static int xwdt_probe(struct platform_device *pdev) goto unmap_io; } - xwdt_get_status(&xdev.boot_status); - - rc = misc_register(&xwdt_miscdev); + rc = watchdog_register_device(&xilinx_wdt_wdd); if (rc) { - pr_err("cannot register miscdev on minor=%d (err=%d)\n", - xwdt_miscdev.minor, rc); + pr_err("cannot register watchdog (err=%d)\n", rc); goto unmap_io; } - if (no_timeout) - pr_info("driver loaded (timeout=? sec, nowayout=%d)\n", - xdev.nowayout); - else - pr_info("driver loaded (timeout=%d sec, nowayout=%d)\n", - timeout, xdev.nowayout); - - expect_close = 0; - clear_bit(0, &driver_open); + dev_info(&pdev->dev, "Xilinx Watchdog Timer at %p with timeout %ds\n", + xdev.base, timeout); return 0; @@ -375,7 +235,7 @@ err_out: static int xwdt_remove(struct platform_device *dev) { - misc_deregister(&xwdt_miscdev); + watchdog_unregister_device(&xilinx_wdt_wdd); iounmap(xdev.base); release_mem_region(xdev.res.start, resource_size(&xdev.res));