This patch lets netconfig support the asus wl-500w. Signed-off-by: Ben Pfountz <netpr...
[librecmc/librecmc.git] / target / linux / ifxmips / files / drivers / char / watchdog / ifxmips_wdt.c
index 8fcbc88030cf417b8a01d06decabed9c83c92799..d631f4aac42e85bbe8179a2dd8b09e11f23c0536 100644 (file)
 #include <linux/proc_fs.h>
 #include <linux/ioctl.h>
 #include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/watchdog.h>
+#include <linux/miscdevice.h>
 #include <asm-mips/ifxmips/ifxmips_wdt.h>
 #include <asm-mips/ifxmips/ifxmips.h>
 
+#define DRVNAME                        "ifxmips_wdt"
 
 // TODO remove magic numbers and weirdo macros
-
 extern unsigned int ifxmips_get_fpi_hz (void);
 
 static int ifxmips_wdt_inuse = 0;
@@ -54,12 +57,12 @@ ifxmips_wdt_enable (unsigned int timeout)
        /* caculate reload value */
        wdt_reload = (timeout * (ffpi / wdt_clkdiv)) + wdt_pwl;
 
-       printk("wdt_pwl=0x%x, wdt_clkdiv=%d, ffpi=%d, wdt_reload = 0x%x\n",
+       printk(KERN_WARNING DRVNAME ": wdt_pwl=0x%x, wdt_clkdiv=%d, ffpi=%d, wdt_reload = 0x%x\n",
                wdt_pwl, wdt_clkdiv, ffpi, wdt_reload);
 
        if (wdt_reload > 0xFFFF)
        {
-               printk ("timeout too large %d\n", timeout);
+               printk(KERN_WARNING DRVNAME ": timeout too large %d\n", timeout);
                retval = -EINVAL;
                goto out;
        }
@@ -174,7 +177,7 @@ ifxmips_wdt_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
                break;
 
        case IFXMIPS_WDT_IOC_STOP:
-               printk("disable watch dog timer\n");
+               printk(KERN_INFO DRVNAME ": disable watch dog timer\n");
                ifxmips_wdt_disable();
                break;
 
@@ -207,7 +210,7 @@ ifxmips_wdt_ioctl (struct inode *inode, struct file *file, unsigned int cmd,
                break;
 
        default:
-               printk("unknown watchdog iotcl\n");
+               printk(KERN_WARNING DRVNAME ": unknown watchdog iotcl\n");
        }
 
 out:
@@ -250,38 +253,73 @@ ifxmips_wdt_register_proc_read (char *buf, char **start, off_t offset, int count
        return len;
 }
 
-static struct file_operations wdt_fops = {
-      .owner = THIS_MODULE,
-      .ioctl = ifxmips_wdt_ioctl,
-      .open = ifxmips_wdt_open,
-      .release = ifxmips_wdt_release,
+static const struct file_operations ifxmips_wdt_fops = {
+       .owner          = THIS_MODULE,
+       .llseek         = no_llseek,
+       .ioctl          = ifxmips_wdt_ioctl,
+       .open           = ifxmips_wdt_open,
+       .release        = ifxmips_wdt_release,
+//     .write          = at91_wdt_write,
 };
 
-int __init
-ifxmips_wdt_init_module (void)
-{
-       ifxmips_wdt_major = register_chrdev(0, "wdt", &wdt_fops);
+static struct miscdevice ifxmips_wdt_miscdev = {
+       .minor          = WATCHDOG_MINOR,
+       .name           = "ifxmips_wdt",
+       .fops           = &ifxmips_wdt_fops,
+};
 
-       if (ifxmips_wdt_major < 0)
-       {
-               printk("cannot register watchdog device\n");
 
-               return -EINVAL;
-       }
+static int
+ifxmips_wdt_probe (struct platform_device *pdev)
+{
+       int ret = misc_register(&ifxmips_wdt_miscdev);
+       if (ret)
+               return ret;
 
-       create_proc_read_entry("ifxmips_wdt", 0, NULL, ifxmips_wdt_register_proc_read, NULL);
+       create_proc_read_entry(DRVNAME, 0, NULL, ifxmips_wdt_register_proc_read, NULL);
 
-       printk("ifxmips watchdog loaded\n");
+       printk(KERN_INFO DRVNAME ": ifxmips watchdog loaded\n");
+
+       return 0;
+}
 
+static int
+ifxmips_wdt_remove (struct platform_device *pdev)
+{
+       misc_deregister(&ifxmips_wdt_miscdev);
+       remove_proc_entry(DRVNAME, NULL);
        return 0;
 }
 
+static struct
+platform_driver ifxmips_wdt_driver = {
+       .probe = ifxmips_wdt_probe,
+       .remove = ifxmips_wdt_remove,
+       .driver = {
+               .name = DRVNAME,
+               .owner = THIS_MODULE,
+       },
+};
+
+int __init
+ifxmips_wdt_init_module (void)
+{
+       int ret = platform_driver_register(&ifxmips_wdt_driver);
+       if (ret)
+               printk(KERN_INFO DRVNAME ": Error registering platfom driver!");
+       return ret;
+}
+
 void
 ifxmips_wdt_cleanup_module (void)
 {
-       unregister_chrdev(ifxmips_wdt_major, "wdt");
-       remove_proc_entry("ifxmips_wdt", NULL);
+       platform_driver_unregister(&ifxmips_wdt_driver);
 }
 
 module_init(ifxmips_wdt_init_module);
 module_exit(ifxmips_wdt_cleanup_module);
+
+MODULE_AUTHOR("John Crispin <blogic@openwrt.org>");
+MODULE_DESCRIPTION("Watchdog driver for infineon ifxmips family");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);