X-Git-Url: http://git.rohieb.name/openwrt.git/blobdiff_plain/5d5ede9aca3a45494b3b3f4451500bed87fe5bd1..6f5aac5856eafca6766fe098aeeeca4419661fd5:/package/rtc-rv5c386a/src/rtc.c?ds=sidebyside diff --git a/package/rtc-rv5c386a/src/rtc.c b/package/rtc-rv5c386a/src/rtc.c index 34d0a83aa..7c51bf4bf 100644 --- a/package/rtc-rv5c386a/src/rtc.c +++ b/package/rtc-rv5c386a/src/rtc.c @@ -47,16 +47,20 @@ #include #include #include +#include #include #include #include #include #include +#include +#include -#include +#include #include -#include "gpio.h" +#include +#include #define RTC_IS_OPEN 0x01 /* Means /dev/rtc is in use. */ @@ -65,8 +69,6 @@ static int rtc_debug = 0; static unsigned long rtc_status = 0; /* Bitmapped status byte. */ -static spinlock_t rtc_lock = SPIN_LOCK_UNLOCKED; - /* These settings are platform dependents. */ unsigned int sda_index = 0; unsigned int scl_index = 0; @@ -97,11 +99,7 @@ MODULE_AUTHOR("Andreas Engel"); MODULE_LICENSE("GPL"); /* Test stolen from switch-adm.c. */ -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,52) module_param(rtc_debug, int, 0); -#else -MODULE_PARM(rtc_debug, "i"); -#endif static inline void sdalo(void) { @@ -236,7 +234,7 @@ static int i2c_inb(int ack) static void i2c_init(void) { /* no gpio_control for EXTIF */ - // gpio_control(sda_mask | scl_mask, 0); + // ssb_gpio_control(&ssb, sda_mask | scl_mask, 0); gpio_set_value(sda_index, 0); gpio_set_value(scl_index, 0); @@ -307,6 +305,7 @@ static void get_rtc_time(struct rtc_time *rtc_tm) * Read date and time from the RTC. We use read method (3). */ + spin_lock_irq(&rtc_lock); i2c_start(); i2c_outb(RTC_I2C_ADDRESS | I2C_READ_MASK); cr2 = i2c_inb(I2C_ACK); @@ -318,6 +317,7 @@ static void get_rtc_time(struct rtc_time *rtc_tm) rtc_tm->tm_mon = i2c_inb(I2C_ACK); rtc_tm->tm_year = i2c_inb(I2C_NAK); i2c_stop(); + spin_unlock_irq(&rtc_lock); if (cr2 & RTC_VDET_MASK) { printk(KERN_WARNING "***RTC BATTERY FAILURE***\n"); @@ -353,6 +353,7 @@ static void set_rtc_time(struct rtc_time *rtc_tm) rtc_tm->tm_mon |= RTC_Y2K_MASK; } + spin_lock_irq(&rtc_lock); i2c_start(); i2c_outb(RTC_I2C_ADDRESS | I2C_WRITE_MASK); i2c_outb(0x00); /* set starting register to 0 (=seconds) */ @@ -364,6 +365,7 @@ static void set_rtc_time(struct rtc_time *rtc_tm) i2c_outb(rtc_tm->tm_mon); i2c_outb(rtc_tm->tm_year); i2c_stop(); + spin_unlock_irq(&rtc_lock); } static ssize_t rtc_write(UNUSED struct file *filp, const char *buf, @@ -461,8 +463,7 @@ static ssize_t rtc_read(UNUSED struct file *filp, char *buf, size_t count, return len; } -static int rtc_ioctl(UNUSED struct inode *inode, UNUSED struct file *filp, - unsigned int cmd, unsigned long arg) +static int rtc_do_ioctl(unsigned int cmd, unsigned long arg) { struct rtc_time rtc_tm; @@ -492,14 +493,21 @@ static int rtc_ioctl(UNUSED struct inode *inode, UNUSED struct file *filp, return 0; } -static struct file_operations rtc_fops = { - .owner = THIS_MODULE, - .llseek = no_llseek, - .read = rtc_read, - .write = rtc_write, - .ioctl = rtc_ioctl, - .open = rtc_open, - .release = rtc_release, +static long rtc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + long ret; + ret = rtc_do_ioctl(cmd, arg); + return ret; +} + +static const struct file_operations rtc_fops = { + .owner = THIS_MODULE, + .llseek = no_llseek, + .read = rtc_read, + .write = rtc_write, + .unlocked_ioctl = rtc_ioctl, + .open = rtc_open, + .release = rtc_release, }; static struct miscdevice rtc_dev = { @@ -509,27 +517,33 @@ static struct miscdevice rtc_dev = { }; /* Savagely ripped from diag.c. */ -extern char *nvram_get(char *str); -#define getvar(str) (nvram_get(str)?:"") static inline int startswith (char *source, char *cmp) -{ return !strncmp(source,cmp,strlen(cmp)); } +{ + return !strncmp(source, cmp, strlen(cmp)); +} + static void platform_detect(void) { - char *buf; + char buf[20]; + int et0phyaddr, et1phyaddr; /* Based on "model_no". */ - if ((buf = nvram_get("model_no"))) { - if (startswith(buf,"WL700")) { /* WL700* */ + if (nvram_getenv("model_no", buf, sizeof(buf)) >= 0) { + if (startswith(buf, "WL700")) { /* WL700* */ sda_index = 2; scl_index = 5; return; } } - if (startswith(getvar("hardware_version"), "WL300-")) { + if (nvram_getenv("et0phyaddr", buf, sizeof(buf)) >= 0 ) + et0phyaddr = simple_strtoul(buf, NULL, 0); + if (nvram_getenv("et1phyaddr", buf, sizeof(buf)) >= 0 ) + et1phyaddr = simple_strtoul(buf, NULL, 0); + + if (nvram_getenv("hardware_version", buf, sizeof(buf)) >= 0) { /* Either WL-300g or WL-HDD, do more extensive checks */ - if ((simple_strtoul(getvar("et0phyaddr"), NULL, 0) == 0) && - (simple_strtoul(getvar("et1phyaddr"), NULL, 0) == 1)) { + if (startswith(buf, "WL300-") && et0phyaddr == 0 && et1phyaddr == 1) { sda_index = 4; scl_index = 5; return; @@ -554,19 +568,23 @@ static int __init rtc_init(void) /* * Switch RTC to 24h mode */ + spin_lock_irq(&rtc_lock); i2c_start(); i2c_outb(RTC_I2C_ADDRESS | I2C_WRITE_MASK); i2c_outb(0xE4); /* start at address 0xE, transmission mode 4 */ cr1 = i2c_inb(I2C_NAK); i2c_stop(); + spin_unlock_irq(&rtc_lock); if ((cr1 & RTC_24HOUR_MODE_MASK) == 0) { /* RTC is running in 12h mode */ printk(KERN_INFO "rtc.o: switching to 24h mode\n"); + spin_lock_irq(&rtc_lock); i2c_start(); i2c_outb(RTC_I2C_ADDRESS | I2C_WRITE_MASK); i2c_outb(0xE0); i2c_outb(cr1 | RTC_24HOUR_MODE_MASK); i2c_stop(); + spin_unlock_irq(&rtc_lock); } misc_register(&rtc_dev);