rtc: pcf2127: Fix typo in comment
[linux-2.6-microblaze.git] / drivers / rtc / rtc-rx8025.c
index d38aaf0..5bfdd34 100644 (file)
@@ -248,9 +248,6 @@ static int rx8025_set_time(struct device *dev, struct rtc_time *dt)
        u8 date[7];
        int ret;
 
-       if ((dt->tm_year < 100) || (dt->tm_year > 199))
-               return -EINVAL;
-
        /*
         * Here the read-only bits are written as "0".  I'm not sure if that
         * is sound.
@@ -318,9 +315,6 @@ static int rx8025_read_alarm(struct device *dev, struct rtc_wkalrm *t)
        u8 ald[2];
        int ctrl2, err;
 
-       if (client->irq <= 0)
-               return -EINVAL;
-
        err = rx8025_read_regs(client, RX8025_REG_ALDMIN, 2, ald);
        if (err)
                return err;
@@ -355,20 +349,6 @@ static int rx8025_set_alarm(struct device *dev, struct rtc_wkalrm *t)
        u8 ald[2];
        int err;
 
-       if (client->irq <= 0)
-               return -EINVAL;
-
-       /*
-        * Hardware alarm precision is 1 minute!
-        * round up to nearest minute
-        */
-       if (t->time.tm_sec) {
-               time64_t alarm_time = rtc_tm_to_time64(&t->time);
-
-               alarm_time += 60 - t->time.tm_sec;
-               rtc_time64_to_tm(alarm_time, &t->time);
-       }
-
        ald[0] = bin2bcd(t->time.tm_min);
        if (rx8025->ctrl1 & RX8025_BIT_CTRL1_1224)
                ald[1] = bin2bcd(t->time.tm_hour);
@@ -423,17 +403,7 @@ static int rx8025_alarm_irq_enable(struct device *dev, unsigned int enabled)
        return 0;
 }
 
-static const struct rtc_class_ops rx8025_rtc_ops = {
-       .read_time = rx8025_get_time,
-       .set_time = rx8025_set_time,
-       .read_alarm = rx8025_read_alarm,
-       .set_alarm = rx8025_set_alarm,
-       .alarm_irq_enable = rx8025_alarm_irq_enable,
-};
-
 /*
- * Clock precision adjustment support
- *
  * According to the RX8025 SA/NB application manual the frequency and
  * temperature characteristics can be approximated using the following
  * equation:
@@ -444,11 +414,8 @@ static const struct rtc_class_ops rx8025_rtc_ops = {
  *   a : Coefficient = (-35 +-5) * 10**-9
  *   ut: Ultimate temperature in degree = +25 +-5 degree
  *   t : Any temperature in degree
- *
- * Note that the clock adjustment in ppb must be entered (which is
- * the negative value of the deviation).
  */
-static int rx8025_get_clock_adjust(struct device *dev, int *adj)
+static int rx8025_read_offset(struct device *dev, long *offset)
 {
        struct i2c_client *client = to_i2c_client(dev);
        int digoff;
@@ -457,63 +424,75 @@ static int rx8025_get_clock_adjust(struct device *dev, int *adj)
        if (digoff < 0)
                return digoff;
 
-       *adj = digoff >= 64 ? digoff - 128 : digoff;
-       if (*adj > 0)
-               (*adj)--;
-       *adj *= -RX8025_ADJ_RESOLUTION;
+       *offset = digoff >= 64 ? digoff - 128 : digoff;
+       if (*offset > 0)
+               (*offset)--;
+       *offset *= RX8025_ADJ_RESOLUTION;
 
        return 0;
 }
 
-static int rx8025_set_clock_adjust(struct device *dev, int adj)
+static int rx8025_set_offset(struct device *dev, long offset)
 {
        struct i2c_client *client = to_i2c_client(dev);
        u8 digoff;
        int err;
 
-       adj /= -RX8025_ADJ_RESOLUTION;
-       if (adj > RX8025_ADJ_DATA_MAX)
-               adj = RX8025_ADJ_DATA_MAX;
-       else if (adj < RX8025_ADJ_DATA_MIN)
-               adj = RX8025_ADJ_DATA_MIN;
-       else if (adj > 0)
-               adj++;
-       else if (adj < 0)
-               adj += 128;
-       digoff = adj;
+       offset /= RX8025_ADJ_RESOLUTION;
+       if (offset > RX8025_ADJ_DATA_MAX)
+               offset = RX8025_ADJ_DATA_MAX;
+       else if (offset < RX8025_ADJ_DATA_MIN)
+               offset = RX8025_ADJ_DATA_MIN;
+       else if (offset > 0)
+               offset++;
+       else if (offset < 0)
+               offset += 128;
+       digoff = offset;
 
        err = rx8025_write_reg(client, RX8025_REG_DIGOFF, digoff);
        if (err)
                return err;
 
-       dev_dbg(dev, "%s: write 0x%02x\n", __func__, digoff);
-
        return 0;
 }
 
+static const struct rtc_class_ops rx8025_rtc_ops = {
+       .read_time = rx8025_get_time,
+       .set_time = rx8025_set_time,
+       .read_alarm = rx8025_read_alarm,
+       .set_alarm = rx8025_set_alarm,
+       .alarm_irq_enable = rx8025_alarm_irq_enable,
+       .read_offset = rx8025_read_offset,
+       .set_offset = rx8025_set_offset,
+};
+
 static ssize_t rx8025_sysfs_show_clock_adjust(struct device *dev,
                                              struct device_attribute *attr,
                                              char *buf)
 {
-       int err, adj;
+       long adj;
+       int err;
 
-       err = rx8025_get_clock_adjust(dev, &adj);
+       dev_warn_once(dev, "clock_adjust_ppb is deprecated, use offset\n");
+       err = rx8025_read_offset(dev, &adj);
        if (err)
                return err;
 
-       return sprintf(buf, "%d\n", adj);
+       return sprintf(buf, "%ld\n", -adj);
 }
 
 static ssize_t rx8025_sysfs_store_clock_adjust(struct device *dev,
                                               struct device_attribute *attr,
                                               const char *buf, size_t count)
 {
-       int adj, err;
+       long adj;
+       int err;
 
-       if (sscanf(buf, "%i", &adj) != 1)
+       dev_warn_once(dev, "clock_adjust_ppb is deprecated, use offset\n");
+       if (kstrtol(buf, 10, &adj) != 0)
                return -EINVAL;
 
-       err = rx8025_set_clock_adjust(dev, adj);
+       err = rx8025_set_offset(dev, -adj);
 
        return err ? err : count;
 }
@@ -522,15 +501,14 @@ static DEVICE_ATTR(clock_adjust_ppb, S_IRUGO | S_IWUSR,
                   rx8025_sysfs_show_clock_adjust,
                   rx8025_sysfs_store_clock_adjust);
 
-static int rx8025_sysfs_register(struct device *dev)
-{
-       return device_create_file(dev, &dev_attr_clock_adjust_ppb);
-}
+static struct attribute *rx8025_attrs[] = {
+       &dev_attr_clock_adjust_ppb.attr,
+       NULL
+};
 
-static void rx8025_sysfs_unregister(struct device *dev)
-{
-       device_remove_file(dev, &dev_attr_clock_adjust_ppb);
-}
+static const struct attribute_group rx8025_attr_group = {
+       .attrs  = rx8025_attrs,
+};
 
 static int rx8025_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
@@ -559,12 +537,13 @@ static int rx8025_probe(struct i2c_client *client,
        if (err)
                return err;
 
-       rx8025->rtc = devm_rtc_device_register(&client->dev, client->name,
-                                         &rx8025_rtc_ops, THIS_MODULE);
-       if (IS_ERR(rx8025->rtc)) {
-               dev_err(&client->dev, "unable to register the class device\n");
+       rx8025->rtc = devm_rtc_allocate_device(&client->dev);
+       if (IS_ERR(rx8025->rtc))
                return PTR_ERR(rx8025->rtc);
-       }
+
+       rx8025->rtc->ops = &rx8025_rtc_ops;
+       rx8025->rtc->range_min = RTC_TIMESTAMP_BEGIN_1900;
+       rx8025->rtc->range_max = RTC_TIMESTAMP_END_2099;
 
        if (client->irq > 0) {
                dev_info(&client->dev, "IRQ %d supplied\n", client->irq);
@@ -572,25 +551,20 @@ static int rx8025_probe(struct i2c_client *client,
                                                rx8025_handle_irq,
                                                IRQF_ONESHOT,
                                                "rx8025", client);
-               if (err) {
-                       dev_err(&client->dev, "unable to request IRQ, alarms disabled\n");
-                       client->irq = 0;
-               }
+               if (err)
+                       clear_bit(RTC_FEATURE_ALARM, rx8025->rtc->features);
        }
 
        rx8025->rtc->max_user_freq = 1;
 
-       /* the rx8025 alarm only supports a minute accuracy */
-       rx8025->rtc->uie_unsupported = 1;
+       set_bit(RTC_FEATURE_ALARM_RES_MINUTE, rx8025->rtc->features);
+       clear_bit(RTC_FEATURE_UPDATE_INTERRUPT, rx8025->rtc->features);
 
-       err = rx8025_sysfs_register(&client->dev);
-       return err;
-}
+       err = rtc_add_group(rx8025->rtc, &rx8025_attr_group);
+       if (err)
+               return err;
 
-static int rx8025_remove(struct i2c_client *client)
-{
-       rx8025_sysfs_unregister(&client->dev);
-       return 0;
+       return devm_rtc_register_device(rx8025->rtc);
 }
 
 static struct i2c_driver rx8025_driver = {
@@ -598,7 +572,6 @@ static struct i2c_driver rx8025_driver = {
                .name = "rtc-rx8025",
        },
        .probe          = rx8025_probe,
-       .remove         = rx8025_remove,
        .id_table       = rx8025_id,
 };