From patchwork Thu Feb 28 08:52:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v2] Enhanced support for MPC8xx/8xxx watchdog Date: Wed, 27 Feb 2013 22:52:22 -0000 From: LEROY Christophe X-Patchwork-Id: 223855 Message-Id: <201302280852.r1S8qMYu003742@localhost.localdomain> To: Wim Van Sebroeck Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org This patch modifies the behaviour of the MPC8xx/8xxx watchdog. On the MPC8xx, at 133Mhz, the maximum timeout of the watchdog timer is 1s, which means it must be pinged twice a second. This is not in line with the Linux watchdog concept which is based on a default watchdog timeout around 60s. This patch introduces an intermediate layer between the CPU and the userspace. The kernel pings the watchdog at the required frequency at the condition that userspace tools refresh it regularly. Existing parameter 'timeout' is renamed 'hw_time'. The new parameter 'timeout' allows to set up the userspace timeout. The driver also implements the WDIOC_SETTIMEOUT ioctl. Signed-off-by: Christophe Leroy diff -ur linux-3.7.9/drivers/watchdog/mpc8xxx_wdt.c linux/drivers/watchdog/mpc8xxx_wdt.c --- linux-3.7.9/drivers/watchdog/mpc8xxx_wdt.c 2013-02-17 19:53:32.000000000 +0100 +++ linux/drivers/watchdog/mpc8xxx_wdt.c 2013-02-27 16:00:07.000000000 +0100 @@ -52,10 +52,17 @@ static struct mpc8xxx_wdt __iomem *wd_base; static int mpc8xxx_wdt_init_late(void); -static u16 timeout = 0xffff; -module_param(timeout, ushort, 0); +#define WD_TIMO 10 /* Default timeout = 10 seconds */ + +static uint timeout = WD_TIMO; +module_param(timeout, uint, 0); MODULE_PARM_DESC(timeout, - "Watchdog timeout in ticks. (0swcrr, tmp); - del_timer_sync(&wdt_timer); + wdt_auto = 0; return nonseekable_open(inode, file); } @@ -138,7 +158,8 @@ static int mpc8xxx_wdt_release(struct inode *inode, struct file *file) { if (!nowayout) - mpc8xxx_wdt_timer_ping(0); + wdt_auto = 1; + else mpc8xxx_wdt_pr_warn("watchdog closed"); clear_bit(0, &wdt_is_open); @@ -163,10 +184,12 @@ case WDIOC_GETBOOTSTATUS: return put_user(0, p); case WDIOC_KEEPALIVE: - mpc8xxx_wdt_keepalive(); + mpc8xxx_wdt_sw_keepalive(); return 0; case WDIOC_GETTIMEOUT: - return put_user(timeout_sec, p); + return put_user(timeout, p); + case WDIOC_SETTIMEOUT: + return get_user(timeout, p); default: return -ENOTTY; } @@ -215,12 +238,14 @@ ret = -ENOSYS; goto err_unmap; } + if (enabled) + hw_timo = in_be32(&wd_base->swcrr) >> 16; /* Calculate the timeout in seconds */ if (prescale) - timeout_sec = (timeout * wdt_type->prescaler) / freq; + hw_timo_sec = (hw_timo * wdt_type->prescaler) / freq; else - timeout_sec = timeout / freq; + hw_timo_sec = hw_timo / freq; #ifdef MODULE ret = mpc8xxx_wdt_init_late(); @@ -228,8 +253,8 @@ goto err_unmap; #endif - pr_info("WDT driver for MPC8xxx initialized. mode:%s timeout=%d (%d seconds)\n", - reset ? "reset" : "interrupt", timeout, timeout_sec); + pr_info("WDT driver for MPC8xxx initialized. mode:%s timeout = %d (%d seconds)\n", + reset ? "reset" : "interrupt", hw_timo, hw_timo_sec); /* * If the watchdog was previously enabled or we're running on @@ -273,6 +298,7 @@ .compatible = "fsl,mpc823-wdt", .data = &(struct mpc8xxx_wdt_type) { .prescaler = 0x800, + .hw_enabled = true, }, }, {},