p54usb: Add device ID for Dell WLA3310 USB
[safe/jmp/linux-2.6] / drivers / rtc / rtc-cmos.c
index d37bb86..e9aa814 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
 #include <linux/mod_devicetable.h>
+#include <linux/log2.h>
 
 /* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
 #include <asm-generic/rtc.h>
@@ -58,7 +59,7 @@ struct cmos_rtc {
 };
 
 /* both platform and pnp busses use negative numbers for invalid irqs */
-#define is_valid_irq(n)                ((n) >= 0)
+#define is_valid_irq(n)                ((n) > 0)
 
 static const char driver_name[] = "rtc_cmos";
 
@@ -384,6 +385,8 @@ static int cmos_irq_set_freq(struct device *dev, int freq)
        if (!is_valid_irq(cmos->irq))
                return -ENXIO;
 
+       if (!is_power_of_2(freq))
+               return -EINVAL;
        /* 0 = no irqs; 1 = 2^15 Hz ... 15 = 2^0 Hz */
        f = ffs(freq);
        if (f-- > 16)
@@ -417,49 +420,43 @@ static int cmos_irq_set_state(struct device *dev, int enabled)
        return 0;
 }
 
-#if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
-
-static int
-cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
+static int cmos_alarm_irq_enable(struct device *dev, unsigned int enabled)
 {
        struct cmos_rtc *cmos = dev_get_drvdata(dev);
        unsigned long   flags;
 
-       switch (cmd) {
-       case RTC_AIE_OFF:
-       case RTC_AIE_ON:
-       case RTC_UIE_OFF:
-       case RTC_UIE_ON:
-               if (!is_valid_irq(cmos->irq))
-                       return -EINVAL;
-               break;
-       /* PIE ON/OFF is handled by cmos_irq_set_state() */
-       default:
-               return -ENOIOCTLCMD;
-       }
+       if (!is_valid_irq(cmos->irq))
+               return -EINVAL;
 
        spin_lock_irqsave(&rtc_lock, flags);
-       switch (cmd) {
-       case RTC_AIE_OFF:       /* alarm off */
-               cmos_irq_disable(cmos, RTC_AIE);
-               break;
-       case RTC_AIE_ON:        /* alarm on */
+
+       if (enabled)
                cmos_irq_enable(cmos, RTC_AIE);
-               break;
-       case RTC_UIE_OFF:       /* update off */
-               cmos_irq_disable(cmos, RTC_UIE);
-               break;
-       case RTC_UIE_ON:        /* update on */
-               cmos_irq_enable(cmos, RTC_UIE);
-               break;
-       }
+       else
+               cmos_irq_disable(cmos, RTC_AIE);
+
        spin_unlock_irqrestore(&rtc_lock, flags);
        return 0;
 }
 
-#else
-#define        cmos_rtc_ioctl  NULL
-#endif
+static int cmos_update_irq_enable(struct device *dev, unsigned int enabled)
+{
+       struct cmos_rtc *cmos = dev_get_drvdata(dev);
+       unsigned long   flags;
+
+       if (!is_valid_irq(cmos->irq))
+               return -EINVAL;
+
+       spin_lock_irqsave(&rtc_lock, flags);
+
+       if (enabled)
+               cmos_irq_enable(cmos, RTC_UIE);
+       else
+               cmos_irq_disable(cmos, RTC_UIE);
+
+       spin_unlock_irqrestore(&rtc_lock, flags);
+       return 0;
+}
 
 #if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
 
@@ -500,14 +497,15 @@ static int cmos_procfs(struct device *dev, struct seq_file *seq)
 #endif
 
 static const struct rtc_class_ops cmos_rtc_ops = {
-       .ioctl          = cmos_rtc_ioctl,
-       .read_time      = cmos_read_time,
-       .set_time       = cmos_set_time,
-       .read_alarm     = cmos_read_alarm,
-       .set_alarm      = cmos_set_alarm,
-       .proc           = cmos_procfs,
-       .irq_set_freq   = cmos_irq_set_freq,
-       .irq_set_state  = cmos_irq_set_state,
+       .read_time              = cmos_read_time,
+       .set_time               = cmos_set_time,
+       .read_alarm             = cmos_read_alarm,
+       .set_alarm              = cmos_set_alarm,
+       .proc                   = cmos_procfs,
+       .irq_set_freq           = cmos_irq_set_freq,
+       .irq_set_state          = cmos_irq_set_state,
+       .alarm_irq_enable       = cmos_alarm_irq_enable,
+       .update_irq_enable      = cmos_update_irq_enable,
 };
 
 /*----------------------------------------------------------------*/
@@ -688,7 +686,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
         */
 #if    defined(CONFIG_ATARI)
        address_space = 64;
-#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) || defined(__sparc__)
+#elif defined(__i386__) || defined(__x86_64__) || defined(__arm__) \
+                       || defined(__sparc__) || defined(__mips__)
        address_space = 128;
 #else
 #warning Assuming 128 bytes of RTC+NVRAM address space, not 64 bytes.
@@ -794,17 +793,15 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
                goto cleanup2;
        }
 
-       pr_info("%s: alarms up to one %s%s, %zd bytes nvram%s\n",
-                       dev_name(&cmos_rtc.rtc->dev),
-                       is_valid_irq(rtc_irq)
-                               ?  (cmos_rtc.mon_alrm
-                                       ? "year"
-                                       : (cmos_rtc.day_alrm
-                                               ? "month" : "day"))
-                               : "no",
-                       cmos_rtc.century ? ", y3k" : "",
-                       nvram.size,
-                       is_hpet_enabled() ? ", hpet irqs" : "");
+       pr_info("%s: %s%s, %zd bytes nvram%s\n",
+               dev_name(&cmos_rtc.rtc->dev),
+               !is_valid_irq(rtc_irq) ? "no alarms" :
+                       cmos_rtc.mon_alrm ? "alarms up to one year" :
+                       cmos_rtc.day_alrm ? "alarms up to one month" :
+                       "alarms up to one day",
+               cmos_rtc.century ? ", y3k" : "",
+               nvram.size,
+               is_hpet_enabled() ? ", hpet irqs" : "");
 
        return 0;
 
@@ -870,8 +867,9 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
                        mask = RTC_IRQMASK;
                tmp &= ~mask;
                CMOS_WRITE(tmp, RTC_CONTROL);
-               hpet_mask_rtc_irq_bit(mask);
 
+               /* shut down hpet emulation - we don't need it for alarm */
+               hpet_mask_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE);
                cmos_checkintr(cmos, tmp);
        }
        spin_unlock_irq(&rtc_lock);
@@ -1098,9 +1096,9 @@ static int cmos_pnp_resume(struct pnp_dev *pnp)
 #define        cmos_pnp_resume         NULL
 #endif
 
-static void cmos_pnp_shutdown(struct device *pdev)
+static void cmos_pnp_shutdown(struct pnp_dev *pnp)
 {
-       if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(pdev))
+       if (system_state == SYSTEM_POWER_OFF && !cmos_poweroff(&pnp->dev))
                return;
 
        cmos_do_shutdown();
@@ -1119,15 +1117,12 @@ static struct pnp_driver cmos_pnp_driver = {
        .id_table       = rtc_ids,
        .probe          = cmos_pnp_probe,
        .remove         = __exit_p(cmos_pnp_remove),
+       .shutdown       = cmos_pnp_shutdown,
 
        /* flag ensures resume() gets called, and stops syslog spam */
        .flags          = PNP_DRIVER_RES_DO_NOT_CHANGE,
        .suspend        = cmos_pnp_suspend,
        .resume         = cmos_pnp_resume,
-       .driver         = {
-               .name     = (char *)driver_name,
-               .shutdown = cmos_pnp_shutdown,
-       }
 };
 
 #endif /* CONFIG_PNP */
@@ -1173,23 +1168,34 @@ static struct platform_driver cmos_platform_driver = {
        }
 };
 
+#ifdef CONFIG_PNP
+static bool pnp_driver_registered;
+#endif
+static bool platform_driver_registered;
+
 static int __init cmos_init(void)
 {
        int retval = 0;
 
 #ifdef CONFIG_PNP
-       pnp_register_driver(&cmos_pnp_driver);
+       retval = pnp_register_driver(&cmos_pnp_driver);
+       if (retval == 0)
+               pnp_driver_registered = true;
 #endif
 
-       if (!cmos_rtc.dev)
+       if (!cmos_rtc.dev) {
                retval = platform_driver_probe(&cmos_platform_driver,
                                               cmos_platform_probe);
+               if (retval == 0)
+                       platform_driver_registered = true;
+       }
 
        if (retval == 0)
                return 0;
 
 #ifdef CONFIG_PNP
-       pnp_unregister_driver(&cmos_pnp_driver);
+       if (pnp_driver_registered)
+               pnp_unregister_driver(&cmos_pnp_driver);
 #endif
        return retval;
 }
@@ -1198,9 +1204,11 @@ module_init(cmos_init);
 static void __exit cmos_exit(void)
 {
 #ifdef CONFIG_PNP
-       pnp_unregister_driver(&cmos_pnp_driver);
+       if (pnp_driver_registered)
+               pnp_unregister_driver(&cmos_pnp_driver);
 #endif
-       platform_driver_unregister(&cmos_platform_driver);
+       if (platform_driver_registered)
+               platform_driver_unregister(&cmos_platform_driver);
 }
 module_exit(cmos_exit);