rtc: don't use __exit_p to wrap ds1302_rtc_remove
[safe/jmp/linux-2.6] / drivers / rtc / rtc-ds1374.c
index 45bda18..713f7bf 100644 (file)
 #define DS1374_REG_SR_AF       0x01 /* Alarm Flag */
 #define DS1374_REG_TCR         0x09 /* Trickle Charge */
 
+static const struct i2c_device_id ds1374_id[] = {
+       { "ds1374", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, ds1374_id);
+
 struct ds1374 {
        struct i2c_client *client;
        struct rtc_device *rtc;
@@ -167,7 +173,7 @@ static int ds1374_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
        int cr, sr;
        int ret = 0;
 
-       if (client->irq < 0)
+       if (client->irq <= 0)
                return -EINVAL;
 
        mutex_lock(&ds1374->mutex);
@@ -206,7 +212,7 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
        int cr;
        int ret = 0;
 
-       if (client->irq < 0)
+       if (client->irq <= 0)
                return -EINVAL;
 
        ret = ds1374_read_time(dev, &now);
@@ -216,16 +222,16 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
        rtc_tm_to_time(&alarm->time, &new_alarm);
        rtc_tm_to_time(&now, &itime);
 
-       new_alarm -= itime;
-
        /* This can happen due to races, in addition to dates that are
         * truly in the past.  To avoid requiring the caller to check for
         * races, dates in the past are assumed to be in the recent past
         * (i.e. not something that we'd rather the caller know about via
         * an error), and the alarm is set to go off as soon as possible.
         */
-       if (new_alarm <= 0)
+       if (time_before_eq(new_alarm, itime))
                new_alarm = 1;
+       else
+               new_alarm -= itime;
 
        mutex_lock(&ds1374->mutex);
 
@@ -277,7 +283,7 @@ static void ds1374_work(struct work_struct *work)
 
        stat = i2c_smbus_read_byte_data(client, DS1374_REG_SR);
        if (stat < 0)
-               return;
+               goto unlock;
 
        if (stat & DS1374_REG_SR_AF) {
                stat &= ~DS1374_REG_SR_AF;
@@ -290,18 +296,13 @@ static void ds1374_work(struct work_struct *work)
                control &= ~(DS1374_REG_CR_WACE | DS1374_REG_CR_AIE);
                i2c_smbus_write_byte_data(client, DS1374_REG_CR, control);
 
-               /* rtc_update_irq() assumes that it is called
-                * from IRQ-disabled context.
-                */
-               local_irq_disable();
                rtc_update_irq(ds1374->rtc, 1, RTC_AF | RTC_IRQF);
-               local_irq_enable();
        }
 
 out:
        if (!ds1374->exiting)
                enable_irq(client->irq);
-
+unlock:
        mutex_unlock(&ds1374->mutex);
 }
 
@@ -355,7 +356,8 @@ static const struct rtc_class_ops ds1374_rtc_ops = {
        .ioctl = ds1374_ioctl,
 };
 
-static int ds1374_probe(struct i2c_client *client)
+static int ds1374_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
 {
        struct ds1374 *ds1374;
        int ret;
@@ -374,7 +376,7 @@ static int ds1374_probe(struct i2c_client *client)
        if (ret)
                goto out_free;
 
-       if (client->irq >= 0) {
+       if (client->irq > 0) {
                ret = request_irq(client->irq, ds1374_irq, 0,
                                  "ds1374", client);
                if (ret) {
@@ -394,7 +396,7 @@ static int ds1374_probe(struct i2c_client *client)
        return 0;
 
 out_irq:
-       if (client->irq >= 0)
+       if (client->irq > 0)
                free_irq(client->irq, client);
 
 out_free:
@@ -407,7 +409,7 @@ static int __devexit ds1374_remove(struct i2c_client *client)
 {
        struct ds1374 *ds1374 = i2c_get_clientdata(client);
 
-       if (client->irq >= 0) {
+       if (client->irq > 0) {
                mutex_lock(&ds1374->mutex);
                ds1374->exiting = 1;
                mutex_unlock(&ds1374->mutex);
@@ -422,13 +424,35 @@ static int __devexit ds1374_remove(struct i2c_client *client)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int ds1374_suspend(struct i2c_client *client, pm_message_t state)
+{
+       if (client->irq >= 0 && device_may_wakeup(&client->dev))
+               enable_irq_wake(client->irq);
+       return 0;
+}
+
+static int ds1374_resume(struct i2c_client *client)
+{
+       if (client->irq >= 0 && device_may_wakeup(&client->dev))
+               disable_irq_wake(client->irq);
+       return 0;
+}
+#else
+#define ds1374_suspend NULL
+#define ds1374_resume  NULL
+#endif
+
 static struct i2c_driver ds1374_driver = {
        .driver = {
                .name = "rtc-ds1374",
                .owner = THIS_MODULE,
        },
        .probe = ds1374_probe,
+       .suspend = ds1374_suspend,
+       .resume = ds1374_resume,
        .remove = __devexit_p(ds1374_remove),
+       .id_table = ds1374_id,
 };
 
 static int __init ds1374_init(void)