string: factorize skip_spaces and export it to be generally available
[safe/jmp/linux-2.6] / drivers / rtc / rtc-ds1511.c
index a83a40b..539676e 100644 (file)
@@ -2,7 +2,7 @@
  * An rtc driver for the Dallas DS1511
  *
  * Copyright (C) 2006 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
- * Copyright (C) 2007 Andrew Sharp <andy.sharp@onstor.com>
+ * Copyright (C) 2007 Andrew Sharp <andy.sharp@lsi.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -153,8 +153,8 @@ ds1511_wdog_set(unsigned long deciseconds)
        /*
         * set the wdog values in the wdog registers
         */
-       rtc_write(BIN2BCD(deciseconds % 100), DS1511_WD_MSEC);
-       rtc_write(BIN2BCD(deciseconds / 100), DS1511_WD_SEC);
+       rtc_write(bin2bcd(deciseconds % 100), DS1511_WD_MSEC);
+       rtc_write(bin2bcd(deciseconds / 100), DS1511_WD_SEC);
        /*
         * set wdog enable and wdog 'steering' bit to issue a reset
         */
@@ -184,7 +184,7 @@ ds1511_wdog_disable(void)
 static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
 {
        u8 mon, day, dow, hrs, min, sec, yrs, cen;
-       unsigned int flags;
+       unsigned long flags;
 
        /*
         * won't have to change this for a while
@@ -220,13 +220,13 @@ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
        /*
         * each register is a different number of valid bits
         */
-       sec = BIN2BCD(sec) & 0x7f;
-       min = BIN2BCD(min) & 0x7f;
-       hrs = BIN2BCD(hrs) & 0x3f;
-       day = BIN2BCD(day) & 0x3f;
-       mon = BIN2BCD(mon) & 0x1f;
-       yrs = BIN2BCD(yrs) & 0xff;
-       cen = BIN2BCD(cen) & 0xff;
+       sec = bin2bcd(sec) & 0x7f;
+       min = bin2bcd(min) & 0x7f;
+       hrs = bin2bcd(hrs) & 0x3f;
+       day = bin2bcd(day) & 0x3f;
+       mon = bin2bcd(mon) & 0x1f;
+       yrs = bin2bcd(yrs) & 0xff;
+       cen = bin2bcd(cen) & 0xff;
 
        spin_lock_irqsave(&ds1511_lock, flags);
        rtc_disable_update();
@@ -247,7 +247,7 @@ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
 static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
 {
        unsigned int century;
-       unsigned int flags;
+       unsigned long flags;
 
        spin_lock_irqsave(&ds1511_lock, flags);
        rtc_disable_update();
@@ -264,14 +264,14 @@ static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
        rtc_enable_update();
        spin_unlock_irqrestore(&ds1511_lock, flags);
 
-       rtc_tm->tm_sec = BCD2BIN(rtc_tm->tm_sec);
-       rtc_tm->tm_min = BCD2BIN(rtc_tm->tm_min);
-       rtc_tm->tm_hour = BCD2BIN(rtc_tm->tm_hour);
-       rtc_tm->tm_mday = BCD2BIN(rtc_tm->tm_mday);
-       rtc_tm->tm_wday = BCD2BIN(rtc_tm->tm_wday);
-       rtc_tm->tm_mon = BCD2BIN(rtc_tm->tm_mon);
-       rtc_tm->tm_year = BCD2BIN(rtc_tm->tm_year);
-       century = BCD2BIN(century) * 100;
+       rtc_tm->tm_sec = bcd2bin(rtc_tm->tm_sec);
+       rtc_tm->tm_min = bcd2bin(rtc_tm->tm_min);
+       rtc_tm->tm_hour = bcd2bin(rtc_tm->tm_hour);
+       rtc_tm->tm_mday = bcd2bin(rtc_tm->tm_mday);
+       rtc_tm->tm_wday = bcd2bin(rtc_tm->tm_wday);
+       rtc_tm->tm_mon = bcd2bin(rtc_tm->tm_mon);
+       rtc_tm->tm_year = bcd2bin(rtc_tm->tm_year);
+       century = bcd2bin(century) * 100;
 
        /*
         * Account for differences between how the RTC uses the values
@@ -304,16 +304,16 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
 
        spin_lock_irqsave(&pdata->rtc->irq_lock, flags);
        rtc_write(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
-              0x80 : BIN2BCD(pdata->alrm_mday) & 0x3f,
+              0x80 : bin2bcd(pdata->alrm_mday) & 0x3f,
               RTC_ALARM_DATE);
        rtc_write(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
-              0x80 : BIN2BCD(pdata->alrm_hour) & 0x3f,
+              0x80 : bin2bcd(pdata->alrm_hour) & 0x3f,
               RTC_ALARM_HOUR);
        rtc_write(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
-              0x80 : BIN2BCD(pdata->alrm_min) & 0x7f,
+              0x80 : bin2bcd(pdata->alrm_min) & 0x7f,
               RTC_ALARM_MIN);
        rtc_write(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
-              0x80 : BIN2BCD(pdata->alrm_sec) & 0x7f,
+              0x80 : bin2bcd(pdata->alrm_sec) & 0x7f,
               RTC_ALARM_SEC);
        rtc_write(rtc_read(RTC_CMD) | (pdata->irqen ? RTC_TIE : 0), RTC_CMD);
        rtc_read(RTC_CMD1);     /* clear interrupts */
@@ -326,9 +326,9 @@ ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
        struct platform_device *pdev = to_platform_device(dev);
        struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 
-       if (pdata->irq < 0) {
+       if (pdata->irq <= 0)
                return -EINVAL;
-       }
+
        pdata->alrm_mday = alrm->time.tm_mday;
        pdata->alrm_hour = alrm->time.tm_hour;
        pdata->alrm_min = alrm->time.tm_min;
@@ -346,9 +346,9 @@ ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
        struct platform_device *pdev = to_platform_device(dev);
        struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 
-       if (pdata->irq < 0) {
+       if (pdata->irq <= 0)
                return -EINVAL;
-       }
+
        alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday;
        alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour;
        alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min;
@@ -379,25 +379,13 @@ ds1511_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
- static void
-ds1511_rtc_release(struct device *dev)
-{
-       struct platform_device *pdev = to_platform_device(dev);
-       struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
-
-       if (pdata->irq >= 0) {
-               pdata->irqen = 0;
-               ds1511_rtc_update_alarm(pdata);
-       }
-}
-
  static int
 ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
 {
        struct platform_device *pdev = to_platform_device(dev);
        struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
 
-       if (pdata->irq < 0) {
+       if (pdata->irq <= 0) {
                return -ENOIOCTLCMD; /* fall back into rtc-dev's emulation */
        }
        switch (cmd) {
@@ -428,7 +416,6 @@ static const struct rtc_class_ops ds1511_rtc_ops = {
        .set_time       = ds1511_rtc_set_time,
        .read_alarm     = ds1511_rtc_read_alarm,
        .set_alarm      = ds1511_rtc_set_alarm,
-       .release        = ds1511_rtc_release,
        .ioctl          = ds1511_rtc_ioctl,
 };
 
@@ -494,7 +481,6 @@ static struct bin_attribute ds1511_nvram_attr = {
        .attr = {
                .name = "nvram",
                .mode = S_IRUGO | S_IWUGO,
-               .owner = THIS_MODULE,
        },
        .size = DS1511_RAM_MAX,
        .read = ds1511_nvram_read,
@@ -517,7 +503,6 @@ ds1511_rtc_probe(struct platform_device *pdev)
        if (!pdata) {
                return -ENOMEM;
        }
-       pdata->irq = -1;
        pdata->size = res->end - res->start + 1;
        if (!request_mem_region(res->start, pdata->size, pdev->name)) {
                ret = -EBUSY;
@@ -559,13 +544,13 @@ ds1511_rtc_probe(struct platform_device *pdev)
         * if the platform has an interrupt in mind for this device,
         * then by all means, set it
         */
-       if (pdata->irq >= 0) {
+       if (pdata->irq > 0) {
                rtc_read(RTC_CMD1);
                if (request_irq(pdata->irq, ds1511_interrupt,
                        IRQF_DISABLED | IRQF_SHARED, pdev->name, pdev) < 0) {
 
                        dev_warn(&pdev->dev, "interrupt not available.\n");
-                       pdata->irq = -1;
+                       pdata->irq = 0;
                }
        }
 
@@ -586,7 +571,7 @@ ds1511_rtc_probe(struct platform_device *pdev)
        if (pdata->rtc) {
                rtc_device_unregister(pdata->rtc);
        }
-       if (pdata->irq >= 0) {
+       if (pdata->irq > 0) {
                free_irq(pdata->irq, pdev);
        }
        if (ds1511_base) {
@@ -609,7 +594,7 @@ ds1511_rtc_remove(struct platform_device *pdev)
        sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
        rtc_device_unregister(pdata->rtc);
        pdata->rtc = NULL;
-       if (pdata->irq >= 0) {
+       if (pdata->irq > 0) {
                /*
                 * disable the alarm interrupt
                 */
@@ -645,13 +630,13 @@ ds1511_rtc_init(void)
  static void __exit
 ds1511_rtc_exit(void)
 {
-       return platform_driver_unregister(&ds1511_rtc_driver);
+       platform_driver_unregister(&ds1511_rtc_driver);
 }
 
 module_init(ds1511_rtc_init);
 module_exit(ds1511_rtc_exit);
 
-MODULE_AUTHOR("Andrew Sharp <andy.sharp@onstor.com>");
+MODULE_AUTHOR("Andrew Sharp <andy.sharp@lsi.com>");
 MODULE_DESCRIPTION("Dallas DS1511 RTC driver");
 MODULE_LICENSE("GPL");
 MODULE_VERSION(DRV_VERSION);