X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/bb4717095cec123c23417303f552ff47fb2b6531..20abafaaf5fdb4dd7cb1e09a028b1c2c689557b7:/target/linux/danube/files/drivers/char/watchdog/danube_wdt.c diff --git a/target/linux/danube/files/drivers/char/watchdog/danube_wdt.c b/target/linux/danube/files/drivers/char/watchdog/danube_wdt.c index 59901b7be..be2b33938 100644 --- a/target/linux/danube/files/drivers/char/watchdog/danube_wdt.c +++ b/target/linux/danube/files/drivers/char/watchdog/danube_wdt.c @@ -18,28 +18,17 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include -#include -#include -#include -#include -#include -#include #include -#include -#include +#include #include #include + +// TODO remove magic numbers and weirdo macros + extern unsigned int danube_get_fpi_hz (void); static int danube_wdt_inuse = 0; @@ -90,8 +79,8 @@ danube_wdt_enable (unsigned int timeout) DANUBE_BIU_WDT_CR_RELOAD_SET(wdt_reload) | DANUBE_BIU_WDT_CR_GEN); - /* Set reload value in second password access */ writel(wdt_cr, DANUBE_BIU_WDT_CR); + printk("watchdog enabled\n"); out: @@ -101,16 +90,15 @@ out: void danube_wdt_disable (void) { - /* Write first part of password access */ writel(DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW1), DANUBE_BIU_WDT_CR); - - /* Disable the watchdog in second password access (GEN=0) */ writel(DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW2), DANUBE_BIU_WDT_CR); + + printk("watchdog disabled\n"); } /* passed LPEN or DSEN */ void -danube_wdt_low_power_or_debug (int en, int type) +danube_wdt_enable_feature (int en, int type) { unsigned int wdt_cr = 0; @@ -127,7 +115,6 @@ danube_wdt_low_power_or_debug (int en, int type) wdt_cr |= DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW2); } - /* Set reload value in second password access */ writel(wdt_cr, DANUBE_BIU_WDT_CR); } @@ -140,8 +127,7 @@ danube_wdt_prewarning_limit (int pwl) writel(DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW1), DANUBE_BIU_WDT_CR); wdt_cr &= 0xf300ffff; - wdt_cr |= (DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW2) | - DANUBE_BIU_WDT_CR_PWL_SET(pwl)); + wdt_cr |= (DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW2) | DANUBE_BIU_WDT_CR_PWL_SET(pwl)); /* Set reload value in second password access */ writel(wdt_cr, DANUBE_BIU_WDT_CR); @@ -156,8 +142,7 @@ danube_wdt_set_clkdiv (int clkdiv) writel(DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW1), DANUBE_BIU_WDT_CR); wdt_cr &= 0xfc00ffff; - wdt_cr |= (DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW2) | - DANUBE_BIU_WDT_CR_CLKDIV_SET(clkdiv)); + wdt_cr |= (DANUBE_BIU_WDT_CR_PW_SET(DANUBE_WDT_PW2) | DANUBE_BIU_WDT_CR_CLKDIV_SET(clkdiv)); /* Set reload value in second password access */ writel(wdt_cr, DANUBE_BIU_WDT_CR); @@ -168,28 +153,28 @@ danube_wdt_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { int result = 0; - int en = 0; - int istatus; - int pwl, clkdiv; static int timeout = -1; + unsigned int user_arg; - switch (cmd) + if ((cmd != DANUBE_WDT_IOC_STOP) && (cmd != DANUBE_WDT_IOC_PING) && (cmd != DANUBE_WDT_IOC_GET_STATUS)) { - case DANUBE_WDT_IOC_START: - printk("enable watch dog timer!\n"); - if (copy_from_user((void *) &timeout, (void *) arg, sizeof (int))) - { - printk ("invalid argument\n"); + if (copy_from_user((void *) &user_arg, (void *) arg, sizeof (int))){ result = -EINVAL; - } else { - if ((result = danube_wdt_enable (timeout)) < 0) - timeout = -1; + goto out; } + } + + switch (cmd) + { + case DANUBE_WDT_IOC_START: + if ((result = danube_wdt_enable(user_arg)) < 0) + timeout = -1; + else + timeout = user_arg; break; case DANUBE_WDT_IOC_STOP: printk("disable watch dog timer\n"); - timeout = -1; danube_wdt_disable(); break; @@ -201,35 +186,31 @@ danube_wdt_ioctl (struct inode *inode, struct file *file, unsigned int cmd, break; case DANUBE_WDT_IOC_GET_STATUS: - istatus = readl(DANUBE_BIU_WDT_SR); - copy_to_user((int *) arg, (int *) &istatus, sizeof (int)); + user_arg = readl(DANUBE_BIU_WDT_SR); + copy_to_user((int*)arg, (int*)&user_arg, sizeof(int)); break; case DANUBE_WDT_IOC_SET_PWL: - if (copy_from_user((void *) &pwl, (void *) arg, sizeof (int))) - result = -EINVAL; - danube_wdt_prewarning_limit(pwl); + danube_wdt_prewarning_limit(user_arg); break; case DANUBE_WDT_IOC_SET_DSEN: - if (copy_from_user((void *) &en, (void *) arg, sizeof (int))) - result = -EINVAL; - danube_wdt_low_power_or_debug(en, DANUBE_BIU_WDT_CR_DSEN); + danube_wdt_enable_feature(user_arg, DANUBE_BIU_WDT_CR_DSEN); break; case DANUBE_WDT_IOC_SET_LPEN: - if (copy_from_user((void *) &en, (void *) arg, sizeof (int))) - result = -EINVAL; - danube_wdt_low_power_or_debug(en, DANUBE_BIU_WDT_CR_LPEN); + danube_wdt_enable_feature(user_arg, DANUBE_BIU_WDT_CR_LPEN); break; case DANUBE_WDT_IOC_SET_CLKDIV: - if (copy_from_user((void *) &clkdiv, (void *) arg, sizeof (int))) - result = -EINVAL; - danube_wdt_set_clkdiv(clkdiv); + danube_wdt_set_clkdiv(user_arg); break; + + default: + printk("unknown watchdog iotcl\n"); } +out: return result; }