Add watchdog driver for w90p910
PATCH 1/1 Add watchdog driver for w90p910
Dear Wim Van Sebroeck,
This is a watchdog driver for my w90p910 platform.
Thanks!
Add watchdog driver for w90p910 platform.
--- drivers/watchdog/Kconfig | 9 + drivers/watchdog/Makefile | 1 + drivers/watchdog/w90p910_wdt.c | 340 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 350 insertions(+), 0 deletions(-) create mode 100644 drivers/watchdog/w90p910_wdt.c
drivers/watchdog/Kconfig +9 -0
@@ -266,6 +266,15 @@ config STMP3XXX_WATCHDOG To compile this driver as a module, choose M here: the module will be called stmp3xxx_wdt. +config W90P910_WATCHDOG + tristate "Nuvoton W90P910 watchdog" + depends on ARCH_W90X900 + help + Say Y here if to include support for the watchdog timer + for the Nuvoton W90P910 SoC. + To compile this driver as a module, choose M here: the + module will be called w90p910_wdt. + # AVR32 Architecture config AT32AP700X_WDT
drivers/watchdog/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o +obj-$(CONFIG_W90P910_WATCHDOG) += w90p910_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
drivers/watchdog/w90p910_wdt.c new file +340 -0
340 lines not on this page · raw message
Signature · 1 line
1.5.6.3
Dear Wim,
How about this watchdog patch?
Would you mind applying?
Thanks for your help.
2009/7/24, Wan ZongShun <[email protected]>:
Quoted 400 lines
Dear Wim Van Sebroeck,
This is a watchdog driver for my w90p910 platform.
Thanks!
Add watchdog driver for w90p910 platform.
Signed-off-by Wan ZongShun <[email protected]>--- drivers/watchdog/Kconfig | 9 + drivers/watchdog/Makefile | 1 + drivers/watchdog/w90p910_wdt.c | 340 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 350 insertions(+), 0 deletions(-) create mode 100644 drivers/watchdog/w90p910_wdt.cdrivers/watchdog/Kconfig +9
-0@@ -266,6 +266,15 @@ config STMP3XXX_WATCHDOG To compile this driver as a module, choose M here: the module will be called stmp3xxx_wdt. +config W90P910_WATCHDOG + tristate "Nuvoton W90P910 watchdog" + depends on ARCH_W90X900 + help + Say Y here if to include support for the watchdog timer + for the Nuvoton W90P910 SoC. + To compile this driver as a module, choose M here: the + module will be called w90p910_wdt. + # AVR32 Architecture config AT32AP700X_WDTdrivers/watchdog/Makefile +1
-0@@ -44,6 +44,7 @@ obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o +obj-$(CONFIG_W90P910_WATCHDOG) += w90p910_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.odrivers/watchdog/w90p910_wdt.c new file +340
-1@@ -0,0 +1,340 @@ +/* +* Copyright (c) 2009 Nuvoton technology corporation. +* +* Wan ZongShun <[email protected]> +* +* 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;version 2 of the License. +* +*/ + +#include <linux/bitops.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/clk.h> +#include <linux/kernel.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/platform_device.h> +#include <linux/interrupt.h> +#include <linux/types.h> +#include <linux/watchdog.h> +#include <linux/uaccess.h> + +#define WDT_DEFAULT_TIME_LEVEL 0/* if 0, time = 2^14 clocks */ +#define WDT_MAX_TIME_LEVEL 3/* if 3, time = 2^20 clocks */ +#define REG_WTCR 0x1c +#define WTCLK (0x01 << 10) +#define WTE (0x01 << 7)/*wdt enable*/ +#define WTIE (0x01 << 6)/*wdt interrupt enable*/ +#define WTISBIT (0x04) +#define WTIS (0x03 << 4) +#define WTIF (0x01 << 3) +#define WTRF (0x01 << 2) +#define WTRE (0x01 << 1) +#define WTR 0x01 + +static int wdt_time =WDT_DEFAULT_TIME_LEVEL ; +static int nowayout =WATCHDOG_NOWAYOUT ; + +module_param (wdt_time, int,0 ); +MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" + __MODULE_STRING(WDT_DEFAULT_TIME) ")"); + +#ifdef CONFIG_WATCHDOG_NOWAYOUT +module_param (nowayout, int,0 ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +#endif + +struct w90p910_wdt { +struct resource *res; +struct clk *wdt_clock; +struct platform_device *pdev; +unsigned int open_lock; +unsigned int wdt_irq; +void __iomem *wdt_base; +char expect_close; +spinlock_t wdt_lock; +}; + +static unsigned long w90p910wdt_busy; +struct w90p910_wdt *w90p910_wdt; + +static void w90p910_wdt_keepalive (void ) +{ +unsigned int val; + +spin_lock (&w90p910_wdt->wdt_lock); + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val |= (WTR |WTIF ); +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + +spin_unlock (&w90p910_wdt->wdt_lock); +} + +static irqreturn_t w90p910_wdt_irq (int irq,void *dev_id) +{ +w90p910_wdt_keepalive (); +return IRQ_HANDLED ; +} + +static inline void w90p910_wdt_stop (void ) +{ +unsigned int val; + +spin_lock (&w90p910_wdt->wdt_lock); + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val &= ~WTE ; +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + +spin_unlock (&w90p910_wdt->wdt_lock); +} + +static inline void w90p910_wdt_start (void ) +{ +unsigned int val; + +spin_lock (&w90p910_wdt->wdt_lock); + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val |= (WTRE |WTIE |WTE |WTR |WTCLK |WTIF ); + val |= (wdt_time <<0x04 ); +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + +spin_unlock (&w90p910_wdt->wdt_lock); +} + +static int w90p910_wdt_open (struct inode *inode,struct file *file) +{ + +if (test_and_set_bit (0 , &w90p910wdt_busy)) +return -EBUSY ; + +w90p910_wdt_start (); +return nonseekable_open (inode, file); +} + +static int w90p910_wdt_close (struct inode *inode,struct file *file) +{ +if (!nowayout) +w90p910_wdt_stop (); + +clear_bit (0 , &w90p910wdt_busy); +return 0 ; +} + +static int w90p910_wdt_settimeout (int new_time_level) +{ +unsigned int val; + +if ((new_time_level <0 ) || (new_time_level >WDT_MAX_TIME_LEVEL )) +return -EINVAL ; + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val &= ~WTIS ; + val |= new_time_level; +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + + wdt_time = new_time_level; +return 0 ; +} + +static struct watchdog_info w90p910_wdt_info = { + .identity ="w90p910 watchdog" , + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING , +}; + +static long w90p910_wdt_ioctl (struct file *file, +unsigned int cmd,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +int __user *p = argp; +int new_value; + +switch (cmd) { +case WDIOC_GETSUPPORT : +return copy_to_user (argp, &w90p910_wdt_info, +sizeof (w90p910_wdt_info)) ? -EFAULT :0 ; +case WDIOC_GETSTATUS : +case WDIOC_GETBOOTSTATUS : +return put_user (0 , p); +case WDIOC_SETOPTIONS : +if (get_user (new_value, p)) +return -EFAULT ; +if (new_value &WDIOS_DISABLECARD ) +w90p910_wdt_stop (); +if (new_value &WDIOS_ENABLECARD ) +w90p910_wdt_start (); +return 0 ; +case WDIOC_KEEPALIVE : +w90p910_wdt_keepalive (); +return 0 ; +case WDIOC_SETTIMEOUT : +if (get_user (new_value, p)) +return -EFAULT ; +if (w90p910_wdt_settimeout (new_value)) +return -EINVAL ; + +w90p910_wdt_start (); + +return put_user (wdt_time, p); +case WDIOC_GETTIMEOUT : +return put_user (wdt_time, p); +default : +return -ENOTTY ; + } +} + +static ssize_t w90p910_wdt_write (struct file *file,const char *data, +size_t len,loff_t *ppos) +{ +w90p910_wdt_keepalive (); +return len; +} + +static const struct file_operations w90p910wdt_fops = { + .owner =THIS_MODULE , + .llseek = no_llseek, + .unlocked_ioctl = w90p910_wdt_ioctl, + .open = w90p910_wdt_open, + .release = w90p910_wdt_close, + .write = w90p910_wdt_write, +}; + +static struct miscdevice w90p910wdt_miscdev = { + .minor =WATCHDOG_MINOR , + .name ="watchdog" , + .fops = &w90p910wdt_fops, +}; + +static int __devinit w90p910wdt_probe (struct platform_device *pdev) +{ +int ret; + + w90p910_wdt =kzalloc (sizeof (struct w90p910_wdt ),GFP_KERNEL ); +if (!w90p910_wdt) +return -ENOMEM ; + + w90p910_wdt->pdev = pdev; + + w90p910_wdt->res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (w90p910_wdt->res ==NULL ) { +dev_err (&pdev->dev,"no memory resource specified\n" ); + ret = -ENOENT ; + goto err_get; + } + +if (!request_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res), pdev->name)) { +dev_err (&pdev->dev,"failed to get memory region\n" ); + ret = -ENOENT ; + goto err_req; + } + + w90p910_wdt->wdt_base =ioremap (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); +if (w90p910_wdt->wdt_base ==NULL ) { +dev_err (&pdev->dev,"failed to ioremap() region\n" ); + ret = -EINVAL ; + goto err_req; + } + + w90p910_wdt->wdt_irq =platform_get_irq (pdev,0 ); + ret =request_irq (w90p910_wdt->wdt_irq, + w90p910_wdt_irq,0 , pdev->name,NULL ); +if (ret !=0 ) { +dev_err (&pdev->dev,"failed to install irq (%d)\n" , ret); + goto err_map; + } + + w90p910_wdt->wdt_clock =clk_get (&pdev->dev,NULL ); +if (IS_ERR (w90p910_wdt->wdt_clock)) { +dev_err (&pdev->dev,"failed to find watchdog clock source\n" ); + ret =PTR_ERR (w90p910_wdt->wdt_clock); + goto err_irq; + } + +clk_enable (w90p910_wdt->wdt_clock); + +if (misc_register (&w90p910wdt_miscdev)) { +dev_err (&pdev->dev,"err register miscdev on minor=%d (%d)\n" , +WATCHDOG_MINOR , ret); + goto err_clk; + } + +return 0 ; + +err_clk: +clk_disable (w90p910_wdt->wdt_clock); +clk_put (w90p910_wdt->wdt_clock); +err_irq: +free_irq (w90p910_wdt->wdt_irq,NULL ); +err_map: +iounmap (w90p910_wdt->wdt_base); +err_req: +release_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); +err_get: +kfree (w90p910_wdt); +return ret; +} + +static int __devexit w90p910wdt_remove(struct platform_device *pdev) +{ +free_irq (w90p910_wdt->wdt_irq,NULL ); + +clk_disable (w90p910_wdt->wdt_clock); +clk_put (w90p910_wdt->wdt_clock); + +iounmap (w90p910_wdt->wdt_base); + +release_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); + +kfree (w90p910_wdt); + +misc_deregister (&w90p910wdt_miscdev); +return 0 ; +} + +static void w90p910wdt_shutdown (struct platform_device *pdev) +{ +w90p910_wdt_stop (); +} + +static struct platform_driver w90p910wdt_driver = { + .probe = w90p910wdt_probe, + .remove =__devexit_p (w90p910wdt_remove), + .shutdown = w90p910wdt_shutdown, + .driver = { + .name ="w90p910-wdt" , + .owner =THIS_MODULE , + }, +}; + +static int __init w90p910_wdt_init (void ) +{ +return platform_driver_register (&w90p910wdt_driver); +} + +static void __exit w90p910_wdt_exit(void) +{ +platform_driver_unregister (&w90p910wdt_driver); +} + +module_init (w90p910_wdt_init); +module_exit (w90p910_wdt_exit); + +MODULE_AUTHOR ("Wan ZongShun <[email protected]>" ); +MODULE_DESCRIPTION ("Watchdog driver for W90P910" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_MISCDEV (WATCHDOG_MINOR ); +MODULE_ALIAS ("platform:w90p910-wdt" ); --1.5.6.3
Signature · 1 line
Wan z.s
Hi Wan,
will be reviewed still this week.
Kind regards,
Wim.
Quoted 412 lines
Dear Wim,
How about this watchdog patch?
Would you mind applying?Thanks for your help.
2009/7/24, Wan ZongShun <[email protected]>:
Quoted 400 lines
Dear Wim Van Sebroeck,
This is a watchdog driver for my w90p910 platform.
Thanks!
Add watchdog driver for w90p910 platform.
Signed-off-by Wan ZongShun <[email protected]>--- drivers/watchdog/Kconfig | 9 + drivers/watchdog/Makefile | 1 + drivers/watchdog/w90p910_wdt.c | 340 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 350 insertions(+), 0 deletions(-) create mode 100644 drivers/watchdog/w90p910_wdt.cdrivers/watchdog/Kconfig +9
-0@@ -266,6 +266,15 @@ config STMP3XXX_WATCHDOG To compile this driver as a module, choose M here: the module will be called stmp3xxx_wdt. +config W90P910_WATCHDOG + tristate "Nuvoton W90P910 watchdog" + depends on ARCH_W90X900 + help + Say Y here if to include support for the watchdog timer + for the Nuvoton W90P910 SoC. + To compile this driver as a module, choose M here: the + module will be called w90p910_wdt. + # AVR32 Architecture config AT32AP700X_WDTdrivers/watchdog/Makefile +1
-0@@ -44,6 +44,7 @@ obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o +obj-$(CONFIG_W90P910_WATCHDOG) += w90p910_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.odrivers/watchdog/w90p910_wdt.c new file +340
-1@@ -0,0 +1,340 @@ +/* +* Copyright (c) 2009 Nuvoton technology corporation. +* +* Wan ZongShun <[email protected]> +* +* 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;version 2 of the License. +* +*/ + +#include <linux/bitops.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/clk.h> +#include <linux/kernel.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/platform_device.h> +#include <linux/interrupt.h> +#include <linux/types.h> +#include <linux/watchdog.h> +#include <linux/uaccess.h> + +#define WDT_DEFAULT_TIME_LEVEL 0/* if 0, time = 2^14 clocks */ +#define WDT_MAX_TIME_LEVEL 3/* if 3, time = 2^20 clocks */ +#define REG_WTCR 0x1c +#define WTCLK (0x01 << 10) +#define WTE (0x01 << 7)/*wdt enable*/ +#define WTIE (0x01 << 6)/*wdt interrupt enable*/ +#define WTISBIT (0x04) +#define WTIS (0x03 << 4) +#define WTIF (0x01 << 3) +#define WTRF (0x01 << 2) +#define WTRE (0x01 << 1) +#define WTR 0x01 + +static int wdt_time =WDT_DEFAULT_TIME_LEVEL ; +static int nowayout =WATCHDOG_NOWAYOUT ; + +module_param (wdt_time, int,0 ); +MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" + __MODULE_STRING(WDT_DEFAULT_TIME) ")"); + +#ifdef CONFIG_WATCHDOG_NOWAYOUT +module_param (nowayout, int,0 ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +#endif + +struct w90p910_wdt { +struct resource *res; +struct clk *wdt_clock; +struct platform_device *pdev; +unsigned int open_lock; +unsigned int wdt_irq; +void __iomem *wdt_base; +char expect_close; +spinlock_t wdt_lock; +}; + +static unsigned long w90p910wdt_busy; +struct w90p910_wdt *w90p910_wdt; + +static void w90p910_wdt_keepalive (void ) +{ +unsigned int val; + +spin_lock (&w90p910_wdt->wdt_lock); + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val |= (WTR |WTIF ); +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + +spin_unlock (&w90p910_wdt->wdt_lock); +} + +static irqreturn_t w90p910_wdt_irq (int irq,void *dev_id) +{ +w90p910_wdt_keepalive (); +return IRQ_HANDLED ; +} + +static inline void w90p910_wdt_stop (void ) +{ +unsigned int val; + +spin_lock (&w90p910_wdt->wdt_lock); + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val &= ~WTE ; +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + +spin_unlock (&w90p910_wdt->wdt_lock); +} + +static inline void w90p910_wdt_start (void ) +{ +unsigned int val; + +spin_lock (&w90p910_wdt->wdt_lock); + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val |= (WTRE |WTIE |WTE |WTR |WTCLK |WTIF ); + val |= (wdt_time <<0x04 ); +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + +spin_unlock (&w90p910_wdt->wdt_lock); +} + +static int w90p910_wdt_open (struct inode *inode,struct file *file) +{ + +if (test_and_set_bit (0 , &w90p910wdt_busy)) +return -EBUSY ; + +w90p910_wdt_start (); +return nonseekable_open (inode, file); +} + +static int w90p910_wdt_close (struct inode *inode,struct file *file) +{ +if (!nowayout) +w90p910_wdt_stop (); + +clear_bit (0 , &w90p910wdt_busy); +return 0 ; +} + +static int w90p910_wdt_settimeout (int new_time_level) +{ +unsigned int val; + +if ((new_time_level <0 ) || (new_time_level >WDT_MAX_TIME_LEVEL )) +return -EINVAL ; + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val &= ~WTIS ; + val |= new_time_level; +__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); + + wdt_time = new_time_level; +return 0 ; +} + +static struct watchdog_info w90p910_wdt_info = { + .identity ="w90p910 watchdog" , + .options =WDIOF_SETTIMEOUT |WDIOF_KEEPALIVEPING , +}; + +static long w90p910_wdt_ioctl (struct file *file, +unsigned int cmd,unsigned long arg) +{ +void __user *argp = (void __user *)arg; +int __user *p = argp; +int new_value; + +switch (cmd) { +case WDIOC_GETSUPPORT : +return copy_to_user (argp, &w90p910_wdt_info, +sizeof (w90p910_wdt_info)) ? -EFAULT :0 ; +case WDIOC_GETSTATUS : +case WDIOC_GETBOOTSTATUS : +return put_user (0 , p); +case WDIOC_SETOPTIONS : +if (get_user (new_value, p)) +return -EFAULT ; +if (new_value &WDIOS_DISABLECARD ) +w90p910_wdt_stop (); +if (new_value &WDIOS_ENABLECARD ) +w90p910_wdt_start (); +return 0 ; +case WDIOC_KEEPALIVE : +w90p910_wdt_keepalive (); +return 0 ; +case WDIOC_SETTIMEOUT : +if (get_user (new_value, p)) +return -EFAULT ; +if (w90p910_wdt_settimeout (new_value)) +return -EINVAL ; + +w90p910_wdt_start (); + +return put_user (wdt_time, p); +case WDIOC_GETTIMEOUT : +return put_user (wdt_time, p); +default : +return -ENOTTY ; + } +} + +static ssize_t w90p910_wdt_write (struct file *file,const char *data, +size_t len,loff_t *ppos) +{ +w90p910_wdt_keepalive (); +return len; +} + +static const struct file_operations w90p910wdt_fops = { + .owner =THIS_MODULE , + .llseek = no_llseek, + .unlocked_ioctl = w90p910_wdt_ioctl, + .open = w90p910_wdt_open, + .release = w90p910_wdt_close, + .write = w90p910_wdt_write, +}; + +static struct miscdevice w90p910wdt_miscdev = { + .minor =WATCHDOG_MINOR , + .name ="watchdog" , + .fops = &w90p910wdt_fops, +}; + +static int __devinit w90p910wdt_probe (struct platform_device *pdev) +{ +int ret; + + w90p910_wdt =kzalloc (sizeof (struct w90p910_wdt ),GFP_KERNEL ); +if (!w90p910_wdt) +return -ENOMEM ; + + w90p910_wdt->pdev = pdev; + + w90p910_wdt->res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (w90p910_wdt->res ==NULL ) { +dev_err (&pdev->dev,"no memory resource specified\n" ); + ret = -ENOENT ; + goto err_get; + } + +if (!request_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res), pdev->name)) { +dev_err (&pdev->dev,"failed to get memory region\n" ); + ret = -ENOENT ; + goto err_req; + } + + w90p910_wdt->wdt_base =ioremap (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); +if (w90p910_wdt->wdt_base ==NULL ) { +dev_err (&pdev->dev,"failed to ioremap() region\n" ); + ret = -EINVAL ; + goto err_req; + } + + w90p910_wdt->wdt_irq =platform_get_irq (pdev,0 ); + ret =request_irq (w90p910_wdt->wdt_irq, + w90p910_wdt_irq,0 , pdev->name,NULL ); +if (ret !=0 ) { +dev_err (&pdev->dev,"failed to install irq (%d)\n" , ret); + goto err_map; + } + + w90p910_wdt->wdt_clock =clk_get (&pdev->dev,NULL ); +if (IS_ERR (w90p910_wdt->wdt_clock)) { +dev_err (&pdev->dev,"failed to find watchdog clock source\n" ); + ret =PTR_ERR (w90p910_wdt->wdt_clock); + goto err_irq; + } + +clk_enable (w90p910_wdt->wdt_clock); + +if (misc_register (&w90p910wdt_miscdev)) { +dev_err (&pdev->dev,"err register miscdev on minor=%d (%d)\n" , +WATCHDOG_MINOR , ret); + goto err_clk; + } + +return 0 ; + +err_clk: +clk_disable (w90p910_wdt->wdt_clock); +clk_put (w90p910_wdt->wdt_clock); +err_irq: +free_irq (w90p910_wdt->wdt_irq,NULL ); +err_map: +iounmap (w90p910_wdt->wdt_base); +err_req: +release_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); +err_get: +kfree (w90p910_wdt); +return ret; +} + +static int __devexit w90p910wdt_remove(struct platform_device *pdev) +{ +free_irq (w90p910_wdt->wdt_irq,NULL ); + +clk_disable (w90p910_wdt->wdt_clock); +clk_put (w90p910_wdt->wdt_clock); + +iounmap (w90p910_wdt->wdt_base); + +release_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); + +kfree (w90p910_wdt); + +misc_deregister (&w90p910wdt_miscdev); +return 0 ; +} + +static void w90p910wdt_shutdown (struct platform_device *pdev) +{ +w90p910_wdt_stop (); +} + +static struct platform_driver w90p910wdt_driver = { + .probe = w90p910wdt_probe, + .remove =__devexit_p (w90p910wdt_remove), + .shutdown = w90p910wdt_shutdown, + .driver = { + .name ="w90p910-wdt" , + .owner =THIS_MODULE , + }, +}; + +static int __init w90p910_wdt_init (void ) +{ +return platform_driver_register (&w90p910wdt_driver); +} + +static void __exit w90p910_wdt_exit(void) +{ +platform_driver_unregister (&w90p910wdt_driver); +} + +module_init (w90p910_wdt_init); +module_exit (w90p910_wdt_exit); + +MODULE_AUTHOR ("Wan ZongShun <[email protected]>" ); +MODULE_DESCRIPTION ("Watchdog driver for W90P910" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_MISCDEV (WATCHDOG_MINOR ); +MODULE_ALIAS ("platform:w90p910-wdt" ); --1.5.6.3
Signature · 1 line
Wan z.s
Hi Wim ,
Okay, got it, thanks a lot for your help!
2009/7/30 Wim Van Sebroeck <[email protected]>:
Quoted 420 lines
Hi Wan,
will be reviewed still this week.
Kind regards,
Wim.Quoted 412 lines
Dear Wim,
How about this watchdog patch?
Would you mind applying?Thanks for your help.
2009/7/24, Wan ZongShun <[email protected]>:
Quoted 398 lines
Dear Wim Van Sebroeck,
This is a watchdog driver for my w90p910 platform.
Thanks!
Add watchdog driver for w90p910 platform.
Signed-off-by Wan ZongShun <[email protected]>---
drivers/watchdog/Kconfig | 9 +
drivers/watchdog/Makefile | 1 +drivers/watchdog/w90p910_wdt.c| 340 ++++++++++++++++++++++++++++++++++++++++3 files changed, 350 insertions(+), 0 deletions(-)create mode 100644
drivers/watchdog/w90p910_wdt.cdrivers/watchdog/Kconfig +0
-0@@ -266,6 +266,15 @@ config STMP3XXX_WATCHDOGTo compile this driver as a module, choose M here: the module will be called
stmp3xxx_wdt.drivers/watchdog/Kconfig +9
-0+config W90P910_WATCHDOG + tristate "Nuvoton W90P910 watchdog" + depends on ARCH_W90X900 + help + Say Y here if to include support for the watchdog timer + for the Nuvoton W90P910 SoC. + To compile this driver as a module, choose M here: the + module will be called w90p910_wdt. +# AVR32 Architecture
config
AT32AP700X_WDTdrivers/watchdog/Makefile +0
-0@@ -44,6 +44,7 @@ obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.oobj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o +obj-$(CONFIG_W90P910_WATCHDOG) += w90p910_wdt.o
# AVR32 Architecture
obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.odrivers/watchdog/w90p910_wdt.c new file +340
-1@@ -0,0 +1,340 @@ +/* +* Copyright (c) 2009 Nuvoton technology corporation. +* +* Wan ZongShun <[email protected]> +* +* 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;version 2 of the License. +* +*/ + +#include <linux/bitops.h> +#include <linux/errno.h> +#include <linux/fs.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/clk.h> +#include <linux/kernel.h> +#include <linux/miscdevice.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/platform_device.h> +#include <linux/interrupt.h> +#include <linux/types.h> +#include <linux/watchdog.h> +#include <linux/uaccess.h> + +#define WDT_DEFAULT_TIME_LEVEL 0/* if 0, time = 2^14 clocks */ +#define WDT_MAX_TIME_LEVEL 3/* if 3, time = 2^20 clocks */ +#define REG_WTCR 0x1c +#define WTCLK (0x01 << 10) +#define WTE (0x01 << 7)/*wdt enable*/ +#define WTIE (0x01 << 6)/*wdt interrupt enable*/ +#define WTISBIT (0x04) +#define WTIS (0x03 << 4) +#define WTIF (0x01 << 3) +#define WTRF (0x01 << 2) +#define WTRE (0x01 << 1) +#define WTR 0x01 + +static int wdt_time =WDT_DEFAULT_TIME_LEVEL ; +static int nowayout =WATCHDOG_NOWAYOUT ; + +module_param (wdt_time, int,0 ); +MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" + __MODULE_STRING(WDT_DEFAULT_TIME) ")"); + +#ifdef CONFIG_WATCHDOG_NOWAYOUT +module_param (nowayout, int,0 ); +MODULE_PARM_DESC (nowayout, + "Watchdog cannot be stopped once started (default=" + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +#endif + +struct w90p910_wdt { + struct resource *res; + struct clk *wdt_clock; + struct platform_device *pdev; + unsigned int open_lock; + unsigned int wdt_irq; + void __iomem *wdt_base; + char expect_close; + spinlock_t wdt_lock; +}; + +static unsigned long w90p910wdt_busy; +struct w90p910_wdt *w90p910_wdt; + +static void w90p910_wdt_keepalive (void ) +{ + unsigned int val; + + spin_lock(&w90p910_wdt->wdt_lock); + + val = __raw_readl(w90p910_wdt->wdt_base + REG_WTCR); + val |= (WTR | WTIF); + __raw_writel(val, w90p910_wdt->wdt_base + REG_WTCR); + + spin_unlock(&w90p910_wdt->wdt_lock); +} + +static irqreturn_t w90p910_wdt_irq (int irq,void *dev_id) +{ + w90p910_wdt_keepalive(); + return IRQ_HANDLED; +} + +static inline void w90p910_wdt_stop (void ) +{ + unsigned int val; + + spin_lock(&w90p910_wdt->wdt_lock); + + val = __raw_readl(w90p910_wdt->wdt_base + REG_WTCR); + val &= ~WTE; + __raw_writel(val, w90p910_wdt->wdt_base + REG_WTCR); + + spin_unlock(&w90p910_wdt->wdt_lock); +} + +static inline void w90p910_wdt_start (void ) +{ + unsigned int val; + + spin_lock(&w90p910_wdt->wdt_lock); + + val = __raw_readl(w90p910_wdt->wdt_base + REG_WTCR); + val |= (WTRE | WTIE | WTE | WTR | WTCLK | WTIF); + val |= (wdt_time << 0x04); + __raw_writel(val, w90p910_wdt->wdt_base + REG_WTCR); + + spin_unlock(&w90p910_wdt->wdt_lock); +} + +static int w90p910_wdt_open (struct inode *inode,struct file *file) +{ + + if (test_and_set_bit(0, &w90p910wdt_busy)) + return -EBUSY; + + w90p910_wdt_start(); + return nonseekable_open(inode, file); +} + +static int w90p910_wdt_close (struct inode *inode,struct file *file) +{ + if (!nowayout) + w90p910_wdt_stop(); + + clear_bit(0, &w90p910wdt_busy); + return 0; +} + +static int w90p910_wdt_settimeout (int new_time_level) +{ + unsigned int val; + + if ((new_time_level < 0) || (new_time_level > WDT_MAX_TIME_LEVEL)) + return -EINVAL; + + val = __raw_readl(w90p910_wdt->wdt_base + REG_WTCR); + val &= ~WTIS; + val |= new_time_level; + __raw_writel(val, w90p910_wdt->wdt_base + REG_WTCR); + + wdt_time = new_time_level; + return 0; +} + +static struct watchdog_info w90p910_wdt_info = { + .identity = "w90p910 watchdog", + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING, +}; + +static long w90p910_wdt_ioctl (struct file *file, + unsigned int cmd, unsigned long arg) +{ + void __user *argp = (void __user *)arg; + int __user *p = argp; + int new_value; + + switch (cmd) { + case WDIOC_GETSUPPORT: + return copy_to_user(argp, &w90p910_wdt_info, + sizeof(w90p910_wdt_info)) ? -EFAULT : 0; + case WDIOC_GETSTATUS: + case WDIOC_GETBOOTSTATUS: + return put_user(0, p); + case WDIOC_SETOPTIONS: + if (get_user(new_value, p)) + return -EFAULT; + if (new_value & WDIOS_DISABLECARD) + w90p910_wdt_stop(); + if (new_value & WDIOS_ENABLECARD) + w90p910_wdt_start(); + return 0; + case WDIOC_KEEPALIVE: + w90p910_wdt_keepalive(); + return 0; + case WDIOC_SETTIMEOUT: + if (get_user(new_value, p)) + return -EFAULT; + if (w90p910_wdt_settimeout(new_value)) + return -EINVAL; + + w90p910_wdt_start(); + + return put_user(wdt_time, p); + case WDIOC_GETTIMEOUT: + return put_user(wdt_time, p); + default: + return -ENOTTY; + } +} + +static ssize_t w90p910_wdt_write (struct file *file,const char *data, + size_t len, loff_t *ppos) +{ + w90p910_wdt_keepalive(); + return len; +} + +static const struct file_operations w90p910wdt_fops = { + .owner = THIS_MODULE, + .llseek = no_llseek, + .unlocked_ioctl = w90p910_wdt_ioctl, + .open = w90p910_wdt_open, + .release = w90p910_wdt_close, + .write = w90p910_wdt_write, +}; + +static struct miscdevice w90p910wdt_miscdev = { + .minor = WATCHDOG_MINOR, + .name = "watchdog", + .fops = &w90p910wdt_fops, +}; + +static int __devinit w90p910wdt_probe (struct platform_device *pdev) +{ + int ret; + + w90p910_wdt = kzalloc(sizeof(struct w90p910_wdt), GFP_KERNEL); + if (!w90p910_wdt) + return -ENOMEM; + + w90p910_wdt->pdev = pdev; + + w90p910_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (w90p910_wdt->res == NULL) { + dev_err(&pdev->dev, "no memory resource specified\n"); + ret = -ENOENT; + goto err_get; + } + + if (!request_mem_region(w90p910_wdt->res->start, + resource_size(w90p910_wdt->res), pdev->name)) { + dev_err(&pdev->dev, "failed to get memory region\n"); + ret = -ENOENT; + goto err_req; + } + + w90p910_wdt->wdt_base = ioremap(w90p910_wdt->res->start, + resource_size(w90p910_wdt->res)); + if (w90p910_wdt->wdt_base == NULL) { + dev_err(&pdev->dev, "failed to ioremap() region\n"); + ret = -EINVAL; + goto err_req; + } + + w90p910_wdt->wdt_irq = platform_get_irq(pdev, 0); + ret = request_irq(w90p910_wdt->wdt_irq, + w90p910_wdt_irq, 0, pdev->name, NULL); + if (ret != 0) { + dev_err(&pdev->dev, "failed to install irq (%d)\n", ret); + goto err_map; + } + + w90p910_wdt->wdt_clock = clk_get(&pdev->dev, NULL); + if (IS_ERR(w90p910_wdt->wdt_clock)) { + dev_err(&pdev->dev, "failed to find watchdog clock source\n"); + ret = PTR_ERR(w90p910_wdt->wdt_clock); + goto err_irq; + } + + clk_enable(w90p910_wdt->wdt_clock); + + if (misc_register(&w90p910wdt_miscdev)) { + dev_err(&pdev->dev, "err register miscdev on minor=%d (%d)\n", + WATCHDOG_MINOR, ret); + goto err_clk; + } + + return 0; + +err_clk: + clk_disable(w90p910_wdt->wdt_clock); + clk_put(w90p910_wdt->wdt_clock); +err_irq: + free_irq(w90p910_wdt->wdt_irq, NULL); +err_map: + iounmap(w90p910_wdt->wdt_base); +err_req: + release_mem_region(w90p910_wdt->res->start, + resource_size(w90p910_wdt->res)); +err_get: + kfree(w90p910_wdt); + return ret; +} + +static int __devexit w90p910wdt_remove(struct platform_device *pdev) +{ + free_irq(w90p910_wdt->wdt_irq, NULL); + + clk_disable(w90p910_wdt->wdt_clock); + clk_put(w90p910_wdt->wdt_clock); + + iounmap(w90p910_wdt->wdt_base); + + release_mem_region(w90p910_wdt->res->start, + resource_size(w90p910_wdt->res)); + + kfree(w90p910_wdt); + + misc_deregister(&w90p910wdt_miscdev); + return 0; +} + +static void w90p910wdt_shutdown (struct platform_device *pdev) +{ + w90p910_wdt_stop(); +} + +static struct platform_driver w90p910wdt_driver = { + .probe = w90p910wdt_probe, + .remove = __devexit_p(w90p910wdt_remove), + .shutdown = w90p910wdt_shutdown, + .driver = { + .name = "w90p910-wdt", + .owner = THIS_MODULE, + }, +}; + +static int __init w90p910_wdt_init (void ) +{ + return platform_driver_register(&w90p910wdt_driver); +} + +static void __exit w90p910_wdt_exit(void) +{ + platform_driver_unregister(&w90p910wdt_driver); +} + +module_init (w90p910_wdt_init); +module_exit (w90p910_wdt_exit); + +MODULE_AUTHOR ("Wan ZongShun <[email protected]>" ); +MODULE_DESCRIPTION ("Watchdog driver for W90P910" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS_MISCDEV (WATCHDOG_MINOR ); +MODULE_ALIAS ("platform:w90p910-wdt" ); --Quoted 2 lines
1.5.6.3
--
Wan z.s
Signature · 1 line
Wan z.s
Hi Wan,
I reviewed your code and have some comments and questions.
...
drivers/watchdog/w90p910_wdt.c line 64
Quoted 10 lines
drivers/watchdog/w90p910_wdt.c new file +10
-0+struct w90p910_wdt { +struct resource *res; +struct clk *wdt_clock; +struct platform_device *pdev; +unsigned int open_lock; +unsigned int wdt_irq; +void __iomem *wdt_base; +char expect_close; +spinlock_t wdt_lock; +};
Where is the spinlock initialized?
...
drivers/watchdog/w90p910_wdt.c line 86
Quoted 5 lines
drivers/watchdog/w90p910_wdt.c new file +5
-0+static irqreturn_t w90p910_wdt_irq (int irq,void *dev_id) +{ +w90p910_wdt_keepalive (); +return IRQ_HANDLED ; +}
How does the interrupt work? what does the watchdog do when it times out? (Is there a datasheet available somewhere?)
...
drivers/watchdog/w90p910_wdt.c line 143
Quoted 10 lines
drivers/watchdog/w90p910_wdt.c new file +10
-0+static int w90p910_wdt_settimeout (int new_time_level) +{ +unsigned int val; + +if ((new_time_level <0 ) || (new_time_level >WDT_MAX_TIME_LEVEL )) +return -EINVAL ; + + val =__raw_readl (w90p910_wdt->wdt_base +REG_WTCR ); + val &= ~WTIS ; + val |= new_time_level;
Shouldn't this be val |= (new_time_level << 0x04); ?
The read-write cyclus to REG_WTCR should also be guarded with a spinlock. Can you incorporate the call to w90p910_wdt_start() in the ioctl code into this function?
...
drivers/watchdog/w90p910_wdt.c line 197
Quoted 2 lines
drivers/watchdog/w90p910_wdt.c new file +2
-0+static ssize_t w90p910_wdt_write (struct file *file,const char *data, +size_t len,loff_t *ppos)
should be: ..., const char __user *data, ...
...
Quoted 12 lines
drivers/watchdog/w90p910_wdt.c new file +12
-0+static int __devinit w90p910wdt_probe (struct platform_device *pdev) +{ +int ret; + + w90p910_wdt =kzalloc (sizeof (struct w90p910_wdt ),GFP_KERNEL ); +if (!w90p910_wdt) +return -ENOMEM ; + + w90p910_wdt->pdev = pdev; + + w90p910_wdt->res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (w90p910_wdt->res ==NULL ) {
drivers/watchdog/w90p910_wdt.c line 239
Quoted 10 lines
drivers/watchdog/w90p910_wdt.c new file +10
-0+dev_err (&pdev->dev,"no memory resource specified\n" ); + ret = -ENOENT ; + goto err_get; + } + +if (!request_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res), pdev->name)) { +dev_err (&pdev->dev,"failed to get memory region\n" ); + ret = -ENOENT ; + goto err_req;
This should be: goto err_get;
...
drivers/watchdog/w90p910_wdt.c line 291
Quoted 3 lines
drivers/watchdog/w90p910_wdt.c new file +3
-0+ +static int __devexit w90p910wdt_remove(struct platform_device *pdev) +{
The misc_deregister(&w90p910wdt_miscdev); should go first. We don't want userspace interactivity when we clean up all reservations.
drivers/watchdog/w90p910_wdt.c line 304
Quoted 13 lines
drivers/watchdog/w90p910_wdt.c new file +13
-0+free_irq (w90p910_wdt->wdt_irq,NULL ); + +clk_disable (w90p910_wdt->wdt_clock); +clk_put (w90p910_wdt->wdt_clock); + +iounmap (w90p910_wdt->wdt_base); + +release_mem_region (w90p910_wdt->res->start, +resource_size (w90p910_wdt->res)); + +kfree (w90p910_wdt); + +misc_deregister (&w90p910wdt_miscdev);
see comment about misc_deregister above.
For the rest the code looks good to me.
Kind regards,
Wim.
Dear Wim,
I'm much obliged to you for helping me.
Before resubmitting fixed patch, I think it better to answer you regarding your questions.
2009/8/5 Wim Van Sebroeck <[email protected]>:
Quoted 6 lines
Hi Wan,
I reviewed your code and have some comments and questions.
...
Quoted 12 lines
drivers/watchdog/w90p910_wdt.c line 64
Quoted 10 lines
drivers/watchdog/w90p910_wdt.c new file +10
-0+struct w90p910_wdt { + struct resource *res; + struct clk *wdt_clock; + struct platform_device *pdev; + unsigned int open_lock; + unsigned int wdt_irq; + void __iomem *wdt_base; + char expect_close; + spinlock_t wdt_lock; +};Where is the spinlock initialized?
Sure, I forget it. sorry.
Quoted 10 lines
drivers/watchdog/w90p910_wdt.c line 86
Quoted 6 lines
drivers/watchdog/w90p910_wdt.c new file +5
-0+static irqreturn_t w90p910_wdt_irq (int irq,void *dev_id) +{ + w90p910_wdt_keepalive(); + return IRQ_HANDLED; +}How does the interrupt work? what does the watchdog do when it times out? (Is there a datasheet available somewhere?)
The mechanism of watchdog of w90p910 is that the interrupt will occur periodicity every a given time interval.
Hmm, there are only two choices to confirm the system running, one to clear this WTIF and WTR bits in handler of interrupt, the other to reset them in user application before interrupt occurs.
Quoted 4 lines
Quoted 4 lines
drivers/watchdog/w90p910_wdt.c new file +4
-0+static int w90p910_wdt_settimeout (int new_time_level) +{ + unsigned int val; +
Quoted 8 lines
Quoted 6 lines
+ if ((
new_time_level< 0) || (new_time_level>WDT_MAX_TIME_LEVEL))
+ return-EINVAL;
+
+ val =__raw_readl(w90p910_wdt->wdt_base + REG_WTCR);
+ val &= ~WTIS;
+ val |=new_time_level;Shouldn't this be val |= (
new_time_level<<0x04); ?
sure.
Quoted 3 lines
The read-write cyclus to
REG_WTCRshould also be guarded with a spinlock. Can you incorporate the call tow90p910_wdt_start()in the ioctl code into this function?
Do you mean that I should merge the "w90p910_wdt_settimeout" to "w90p910_wdt_start()"? or contrary?
Quoted 6 lines
Quoted 3 lines
+static
ssize_tw90p910_wdt_write(struct file *file, const char *data,
+size_tlen,loff_t*ppos)should be: ..., const char
__user*data, ...
sure.
Quoted 17 lines
Quoted 17 lines
drivers/watchdog/w90p910_wdt.c new file +16
-0+static int __devinit w90p910wdt_probe (struct platform_device *pdev) +{ + int ret; + + w90p910_wdt = kzalloc(sizeof(struct w90p910_wdt), GFP_KERNEL); + if (!w90p910_wdt) + return -ENOMEM; + + w90p910_wdt->pdev = pdev; + + w90p910_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (w90p910_wdt->res == NULL) { + dev_err(&pdev->dev, "no memory resource specified\n"); + ret = -ENOENT; + goto err_get; + }
Quoted 8 lines
Quoted 6 lines
+
+ if (!request_mem_region(w90p910_wdt->res->start,
+resource_size(w90p910_wdt->res),pdev->name)) {
+dev_err(&pdev->dev, "failed to get memory region\n");
+ ret =-ENOENT;
+ gotoerr_req;This should be: goto
err_get;
sure.
Quoted 30 lines
...
drivers/watchdog/w90p910_wdt.c line 291
Quoted 3 lines
drivers/watchdog/w90p910_wdt.c new file +3
-0+ +static int __devexit w90p910wdt_remove(struct platform_device *pdev) +{The
misc_deregister(&w90p910wdt_miscdev); should go first. We don't want userspace interactivity when we clean up all reservations.drivers/watchdog/w90p910_wdt.c line 304
Quoted 13 lines
+
free_irq(w90p910_wdt->wdt_irq, NULL);drivers/watchdog/w90p910_wdt.c new file +12
-0+ + clk_disable(w90p910_wdt->wdt_clock); + clk_put(w90p910_wdt->wdt_clock); + + iounmap(w90p910_wdt->wdt_base); + + release_mem_region(w90p910_wdt->res->start, + resource_size(w90p910_wdt->res)); + + kfree(w90p910_wdt); + + misc_deregister(&w90p910wdt_miscdev);see comment about
misc_deregisterabove.For the rest the code looks good to me.
Kind regards,
Wim.
Signature · 1 line
Wan z.s
Hi Wan,
Quoted 1 line
I'm much obliged to you for helping me.
With pleasure :-).
Quoted 10 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static irqreturn_t w90p910_wdt_irq(int irq, void *dev_id) +{ + w90p910_wdt_keepalive(); + return IRQ_HANDLED; +}How does the interrupt work? what does the watchdog do when it times out? (Is there a datasheet available somewhere?)
Quoted 6 lines
The mechanism of watchdog of w90p910 is that the interrupt will occur periodicity every a given time interval.
Hmm, there are only two choices to confirm the system running, one to clear this WTIF and WTR bits in handler of interrupt, the other to reset them in user application before interrupt occurs.
Hmm, I'm confused now. how does the watchdog then reboot your system?
The way we implement watchdog's in linux is that you start the watchdog and that userspace needs to trigger/ping/keep-the-watchdog-alive before the timeout period is finished/over. If the userspace daemon can keep doing this (or with other words: the system is healthy enough to operate normally without to much delay) your system doesn't get rebooted. If it doesn't manage to do it, then the watchdog knows that your system is not stable/healthy enough and will reboot your system.
Here I think that the watchdog is started. Then userspace start pinging the watchdog and everything is OK. If userspace doesn't ping the watchdog in time an interrupt is being generated and instead of rebooting the system, the watchdog is being triggered... If this is indeed what it does then this is wrong.
Quoted 6 lines
Quoted 3 lines
The read-write cyclus to
REG_WTCRshould also be guarded with a spinlock. Can you incorporate the call tow90p910_wdt_start()in the ioctl code into this function?Do you mean that I should merge the "
w90p910_wdt_settimeout" to "w90p910_wdt_start()"? or contrary?
I mean the contrary.
If your watchdog needs to be restarted when you set a new timeout, then it is best to have this in the settimeout function.
It is also better to do a ping to the watchdog once the new timeout was set. It might however be that a ping is enough and that a restart is not needed. So something like the following diff could be it:
w90p910_wdt.c +4 -3
@@ -144,6 +144,9 @@__raw_writel (val, w90p910_wdt->wdt_base +REG_WTCR ); wdt_time = new_time_level; + +w90p910_wdt_start (); +return 0 ; }
@@ -182,9 +185,7 @@return -EFAULT ;if (w90p910_wdt_settimeout (new_value))return -EINVAL ; - -w90p910_wdt_start (); - +w90p910_wdt_keepalive ();return put_user (wdt_time, p);case WDIOC_GETTIMEOUT :return put_user (wdt_time, p);
---
I have an additional question: which timeout values can you set? is it 0, 1, 2 and 3 seconds?
Kind regards,
Wim.
Dear wim,
2009/8/5 Wim Van Sebroeck <[email protected]>:
Quoted 19 lines
Hi Wan,
Quoted 1 line
I'm much obliged to you for helping me.
With pleasure :-).
Quoted 13 lines
Quoted 9 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static irqreturn_t w90p910_wdt_irq(int irq, void *dev_id) +{ + w90p910_wdt_keepalive(); + return IRQ_HANDLED; +}How does the interrupt work? what does the watchdog do when it times out? (Is there a datasheet available somewhere?)
The mechanism of watchdog of w90p910 is that the interrupt will occur periodicity every a given time interval.
Quoted 6 lines
Quoted 3 lines
Hmm, there are only two choices to confirm the system running, one to clear this WTIF and WTR bits in handler of interrupt, the other to reset them in user application before interrupt occurs.
Hmm, I'm confused now. how does the watchdog then reboot your system?
The way we implement watchdog's in linux is that you start the watchdog and that userspace needs to trigger/ping/keep-the-watchdog-alive before the timeout period is finished/over. If the userspace daemon can keep doing this (or with other words: the system is healthy enough to operate normally without to much delay) your system doesn't get rebooted. If it doesn't manage to do it, then the watchdog knows that your system is not stable/healthy enough and will reboot your system.
Thanks a lot for your reviewing again.
Good, above what you said is just apply to my watchdog.
Quoted 1 line
Here I think that the watchdog is started. Then userspace start pinging the watchdog and everything is OK. If userspace doesn't ping the watchdog in time an interrupt is being generated and instead of rebooting the system, the watchdog is being triggered... If this is indeed what it does then this is wrong.
If so, I can not do handling the interrupt and only provide a api for userspace to trigger/ping/keep-the-watchdog-alive.
Quoted 33 lines
Quoted 7 lines
Quoted 4 lines
The read-write cyclus to
REG_WTCRshould also be guarded with a spinlock. Can you incorporate the call tow90p910_wdt_start()in the ioctl code into this function?Do you mean that I should merge the "
w90p910_wdt_settimeout" to "w90p910_wdt_start()"? or contrary?I mean the contrary.
If your watchdog needs to be restarted when you set a new timeout, then it is best to have this in the settimeout function.
It is also better to do a ping to the watchdog once the new timeout was set. It might however be that a ping is enough and that a restart is not needed. So something like the following diff could be it:w90p910_wdt.c 2009-08-05 06:46:04.496353102 +0000 renamed from w90p910_wdt.c 2009-08-05 06:44:14.286477908 +0000 +4
-3@@ -144,6 +144,9 @@ __raw_writel(val, w90p910_wdt->wdt_base + REG_WTCR); wdt_time = new_time_level; + + w90p910_wdt_start(); + return 0; }@@ -182,9 +185,7 @@ return -EFAULT; if (w90p910_wdt_settimeout(new_value)) return -EINVAL; - - w90p910_wdt_start(); - + w90p910_wdt_keepalive(); return put_user(wdt_time, p);
Quoted 4 lines
case
WDIOC_GETTIMEOUT:
returnput_user(wdt_time, p);
---
Okay, got it.
Quoted 1 line
I have an additional question: which timeout values can you set? is it 0, 1, 2 and 3 seconds?
The 0, 1, 2 and 3 is not seconds, rather than 'level' , it means my watchdog controller can only set four grades,
When WTIS bit of REG_WTCR was set one value of the 0, 1, 2 and 3, the
real time interval can be calculated via following formula .
WTIS real time interval (formula)
0x00 ((2^ 14 ) * ((external crystal freq) / 256))seconds 0x01 ((2^ 16 ) * ((external crystal freq) / 256))seconds 0x02 ((2^ 18 ) * ((external crystal freq) / 256))seconds 0x03 ((2^ 20 ) * ((external crystal freq) / 256))seconds
The external crystal freq is 15Mhz in w90p910 evaluation board. so I set the '0x00' as a default value, it means the real time interval is 0.28 second approximately.
Quoted 5 lines
Kind regards,
Wim.
Signature · 1 line
Wan z.s
Hi Wan,
Quoted 8 lines
Quoted 1 line
I have an additional question: which timeout values can you set? is it 0, 1, 2 and 3 seconds?
The 0, 1, 2 and 3 is not seconds, rather than 'level' , it means my watchdog controller can only set four grades,
When WTIS bit ofREG_WTCRwas set one value of the 0, 1, 2 and 3, the
real time interval can be calculated via following formula .WTIS real time interval (formula)
Quoted 8 lines
0x00 ((2^ 14 ) * ((external crystal freq) / 256))seconds 0x01 ((2^ 16 ) * ((external crystal freq) / 256))seconds 0x02 ((2^ 18 ) * ((external crystal freq) / 256))seconds 0x03 ((2^ 20 ) * ((external crystal freq) / 256))secondsThe external crystal freq is 15Mhz in w90p910 evaluation board. so I set the '
0x00' as a default value, it means the real time interval is 0.28 second approximately.
Hmm, the watchdog API works in seconds.
A timer will need to be used like in similar watchdog drivers (like at91sam9_wdt.c, pcwd.c).
Kind regards,
Wim.
Dear Wim,
2009/8/5, Wim Van Sebroeck <[email protected]>:
Quoted 15 lines
Hi Wan,
Quoted 13 lines
Quoted 1 line
I have an additional question: which timeout values can you set? is it 0, 1, 2 and 3 seconds?
The 0, 1, 2 and 3 is not seconds, rather than 'level' , it means my watchdog controller can only set four grades,
When WTIS bit ofREG_WTCRwas set one value of the 0, 1, 2 and 3, the
real time interval can be calculated via following formula .WTIS real time interval (formula)
0x00 ((2^ 14 ) * ((external crystal freq) / 256))seconds 0x01 ((2^ 16 ) * ((external crystal freq) / 256))seconds 0x02 ((2^ 18 ) * ((external crystal freq) / 256))seconds 0x03 ((2^ 20 ) * ((external crystal freq) / 256))seconds
Quoted 6 lines
Quoted 3 lines
The external crystal freq is 15Mhz in w90p910 evaluation board. so I set the '
0x00' as a default value, it means the real time interval is 0.28 second approximately.Hmm, the watchdog API works in seconds.
A timer will need to be used like in similar watchdog drivers (likeat91sam9_wdt.c,pcwd.c).
Do you mean that we should provide userspace a setting seconds api? it like following:
ioctl(fd, WDIOC_SETTIMEOUT,&value);
the value must be seconds?
Hmm, but the w90p910 only provides four grades seconds setting, rather than all seconds time can be set, if so, how to write the wdt driver so that the patch can be accepted for you?any idea?
Quoted 5 lines
Kind regards,
Wim.
Signature · 1 line
Wan z.s
Dear Wim,
Quoted 9 lines
drivers/watchdog/w90p910_wdt.c line 86
Quoted 5 lines
drivers/watchdog/w90p910_wdt.c new file +5
-0+static irqreturn_t w90p910_wdt_irq (int irq,void *dev_id) +{ + w90p910_wdt_keepalive(); + return IRQ_HANDLED; +}How does the interrupt work? what does the watchdog do when it times out? (Is there a datasheet available somewhere?)
Here is the w90p910 datasheet link, now the ic was renames nuc910. Maybe you can give me a good idea,
hmm, regarding the timer as your mentioned (at91sam9_wdt.c), I am studying it and will resubmit a updated patch to you. thanks a lot for your help !
Quoted 7 lines
Quoted 6 lines
drivers/watchdog/w90p910_wdt.c new file +5
-0+static int w90p910_wdt_settimeout (int new_time_level) +{ + unsigned int val; + + if ((new_time_level < 0) || (new_time_level > WDT_MAX_TIME_LEVEL))
Dear Wim,
Maybe I did not know well regarding linux watchdog driver before, but, now Via your help and researching further the timer used in watchdog driver,I rewrite my wdt driver, Now, I can set any time interval in userspace rather than setting the time level. :)
--- drivers/watchdog/Kconfig | 9 + drivers/watchdog/Makefile | 1 + drivers/watchdog/w90p910_wdt.c | 330 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+), 0 deletions(-) create mode 100644 drivers/watchdog/w90p910_wdt.c
drivers/watchdog/Kconfig +9 -0
@@ -266,6 +266,15 @@ config STMP3XXX_WATCHDOG To compile this driver as a module, choose M here: the module will be called stmp3xxx_wdt. +config W90P910_WATCHDOG + tristate "Nuvoton W90P910 watchdog" + depends on ARCH_W90X900 + help + Say Y here if to include support for the watchdog timer + for the Nuvoton W90P910 SoC. + To compile this driver as a module, choose M here: the + module will be called w90p910_wdt. + # AVR32 Architecture config AT32AP700X_WDT
drivers/watchdog/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o +obj-$(CONFIG_W90P910_WATCHDOG) += w90p910_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
drivers/watchdog/w90p910_wdt.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
1.5.6.3
Dear Wim,
Thanks for your w90p910-v2.diff, I appreciated it.
I have tested it and only modified the quote of 'expect_close', and now the patch works very well.:)
At the same time, I renamed this driver name, due to I have changed the corresponding device name in my arch file.
The attached file is fixed patch relative to this w90p910-v2.diff.
--- drivers/watchdog/w90p910_wdt.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/watchdog/w90p910_wdt.c +3 -3
@@ -137,7 +137,7 @@ static int w90p910_wdt_open(struct inode *inode, struct file *file)static int w90p910_wdt_close (struct inode *inode,struct file *file) { -if (expect_close ==42 ) +if (w90p910_wdt->expect_close ==42 )w90p910_wdt_stop ();else { dev_crit(&w90p910_wdt->pdev->dev,
@@ -328,7 +328,7 @@ static struct platform_driver w90p910wdt_driver = { .probe = w90p910wdt_probe, .remove = __devexit_p(w90p910wdt_remove), .driver = { - .name = "w90p910-wdt", + .name = "nuc900-wdt", .owner = THIS_MODULE, }, };
@@ -350,4 +350,4 @@ MODULE_AUTHOR("Wan ZongShun <[email protected]>");MODULE_DESCRIPTION ("Watchdog driver for W90P910" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_MISCDEV (WATCHDOG_MINOR ); -MODULE_ALIAS ("platform:w90p910-wdt" ); +MODULE_ALIAS ("platform:nuc900-wdt" );
Signature · 1 line
1.5.6.3
Fix watchdog driver for w90p910 platform.
--- drivers/watchdog/w90p910_wdt.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/watchdog/w90p910_wdt.c +3 -3
@@ -137,7 +137,7 @@ static int w90p910_wdt_open(struct inode *inode, struct file *file)static int w90p910_wdt_close (struct inode *inode,struct file *file) { -if (expect_close ==42 ) +if (w90p910_wdt->expect_close ==42 )w90p910_wdt_stop ();else { dev_crit(&w90p910_wdt->pdev->dev,
@@ -328,7 +328,7 @@ static struct platform_driver w90p910wdt_driver = { .probe = w90p910wdt_probe, .remove = __devexit_p(w90p910wdt_remove), .driver = { - .name = "w90p910-wdt", + .name = "nuc900-wdt", .owner = THIS_MODULE, }, };
@@ -350,4 +350,4 @@ MODULE_AUTHOR("Wan ZongShun <[email protected]>");MODULE_DESCRIPTION ("Watchdog driver for W90P910" );MODULE_LICENSE ("GPL" );MODULE_ALIAS_MISCDEV (WATCHDOG_MINOR ); -MODULE_ALIAS ("platform:w90p910-wdt" ); +MODULE_ALIAS ("platform:nuc900-wdt" );
Signature · 1 line
1.5.6.3
Hi Wan,
Quoted 2 lines
At the same time, I renamed this driver name, due to I have changed the corresponding device name in my arch file.
Isn't it best to rename the driver in drivers/watchdog also to nuc900_wdt.c ?
Thanks,
Wim.
Dear Wim,
2009/8/17 Wim Van Sebroeck <[email protected]>:
Quoted 6 lines
Hi Wan,
Quoted 2 lines
At the same time, I renamed this driver name, due to I have changed the corresponding device name in my arch file.
Isn't it best to rename the driver in
drivers/watchdogalso tonuc900_wdt.c?
Of course , If you permit :).
Waiting for me, I will fix the patch regarding this, and re-submit it to you.
Thanks for your help.
Quoted 4 lines
Thanks,
Wim.
Signature · 1 line
Wan z.s
Dear Wim,
Wim Van Sebroeck:
Quoted 6 lines
Hi Wan,
Quoted 2 lines
At the same time, I renamed this driver name, due to I have changed the corresponding device name in my arch file.
Isn't it best to rename the driver in
drivers/watchdogalso tonuc900_wdt.c?
The attached file is my fix patch relative to w90p910-v2.diff. Also, I renamed all w90p910 to nuc900, Due to it applies to all Nuc9xx series SoCs.
Thanks a lot for your help.
Quoted 4 lines
Thanks,
Wim.
fix watchdog driver for w90p910 platform.
--- drivers/watchdog/Kconfig | 8 +- drivers/watchdog/Makefile | 2 +- drivers/watchdog/nuc900_wdt.c | 353 ++++++++++++++++++++++++++++++++++++++++ drivers/watchdog/w90p910_wdt.c | 353 ---------------------------------------- 4 files changed, 358 insertions(+), 358 deletions(-) create mode 100644 drivers/watchdog/nuc900_wdt.c delete mode 100644 drivers/watchdog/w90p910_wdt.c
drivers/watchdog/Kconfig +4 -4
@@ -266,14 +266,14 @@ config STMP3XXX_WATCHDOG To compile this driver as a module, choose M here: the module will be called stmp3xxx_wdt. -config W90P910_WATCHDOG - tristate "Nuvoton W90P910 watchdog" +config NUC900_WATCHDOG + tristate "Nuvoton NUC900 watchdog" depends on ARCH_W90X900 help Say Y here if to include support for the watchdog timer - for the Nuvoton W90P910 SoC. + for the Nuvoton NUC900 series SoCs. To compile this driver as a module, choose M here: the - module will be called w90p910_wdt. + module will be called nuc900_wdt. # AVR32 Architecture
drivers/watchdog/Makefile +1 -1
@@ -44,7 +44,7 @@ obj-$(CONFIG_DAVINCI_WATCHDOG) += davinci_wdt.o obj-$(CONFIG_ORION_WATCHDOG) += orion_wdt.o obj-$(CONFIG_COH901327_WATCHDOG) += coh901327_wdt.o obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o -obj-$(CONFIG_W90P910_WATCHDOG) += w90p910_wdt.o +obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o # AVR32 Architecture obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
drivers/watchdog/nuc900_wdt.c new file +353 -0
353 lines not on this page · raw message
drivers/watchdog/w90p910_wdt.c deleted +0 -353
353 lines not on this page · raw message
Signature · 1 line
1.5.6.3
Hi Wan,
I added your nuc900_wdt driver to the linux-2.6-watchdog-next tree.
Kind regards,
Wim.
Hi Wim,
I am profoundly grateful.
Thanks a lot for your help.
2009/8/17 Wim Van Sebroeck <[email protected]>:
Quoted 8 lines
Hi Wan,
I added your
nuc900_wdtdriver to the linux-2.6-watchdog-next tree.Kind regards,
Wim.
Signature · 1 line
Wan z.s
Hi Wan,
Quoted 7 lines
Here is the w90p910 datasheet link, now the ic was renames nuc910. Maybe you can give me a good idea,
hmm, regarding the timer as your mentioned (at91sam9_wdt.c), I am studying it and will resubmit a updated patch to you. thanks a lot for your help !
This is the hardware reference manual. Is there one that describes the registers?
Thanks in advance,
Wim.