]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/rtc/rtc-pcf8563.c
Merge tag 'pci-v5.4-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
[linux.git] / drivers / rtc / rtc-pcf8563.c
index ac159d24286dd16c1202da227a4b1353a78e204a..24baa4767b1117009c779534904bcd51cea21284 100644 (file)
@@ -196,8 +196,9 @@ static irqreturn_t pcf8563_irq(int irq, void *dev_id)
  * In the routines that deal directly with the pcf8563 hardware, we use
  * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
  */
-static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
+static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
 {
+       struct i2c_client *client = to_i2c_client(dev);
        struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
        unsigned char buf[9];
        int err;
@@ -228,9 +229,7 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
        tm->tm_mday = bcd2bin(buf[PCF8563_REG_DM] & 0x3F);
        tm->tm_wday = buf[PCF8563_REG_DW] & 0x07;
        tm->tm_mon = bcd2bin(buf[PCF8563_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
-       tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]);
-       if (tm->tm_year < 70)
-               tm->tm_year += 100;     /* assume we are in 1970...2069 */
+       tm->tm_year = bcd2bin(buf[PCF8563_REG_YR]) + 100;
        /* detect the polarity heuristically. see note above. */
        pcf8563->c_polarity = (buf[PCF8563_REG_MO] & PCF8563_MO_C) ?
                (tm->tm_year >= 100) : (tm->tm_year < 100);
@@ -244,8 +243,9 @@ static int pcf8563_get_datetime(struct i2c_client *client, struct rtc_time *tm)
        return 0;
 }
 
-static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
+static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
 {
+       struct i2c_client *client = to_i2c_client(dev);
        struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
        unsigned char buf[9];
 
@@ -266,7 +266,7 @@ static int pcf8563_set_datetime(struct i2c_client *client, struct rtc_time *tm)
        buf[PCF8563_REG_MO] = bin2bcd(tm->tm_mon + 1);
 
        /* year and century */
-       buf[PCF8563_REG_YR] = bin2bcd(tm->tm_year % 100);
+       buf[PCF8563_REG_YR] = bin2bcd(tm->tm_year - 100);
        if (pcf8563->c_polarity ? (tm->tm_year >= 100) : (tm->tm_year < 100))
                buf[PCF8563_REG_MO] |= PCF8563_MO_C;
 
@@ -299,8 +299,8 @@ static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
                 * because of the cached voltage_low value but do it
                 * anyway for consistency.
                 */
-               if (pcf8563_get_datetime(to_i2c_client(dev), &tm))
-                       pcf8563_set_datetime(to_i2c_client(dev), &tm);
+               if (pcf8563_rtc_read_time(dev, &tm))
+                       pcf8563_rtc_set_time(dev, &tm);
 
                /* Clear the cached value. */
                pcf8563->voltage_low = 0;
@@ -314,16 +314,6 @@ static int pcf8563_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
 #define pcf8563_rtc_ioctl NULL
 #endif
 
-static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
-{
-       return pcf8563_get_datetime(to_i2c_client(dev), tm);
-}
-
-static int pcf8563_rtc_set_time(struct device *dev, struct rtc_time *tm)
-{
-       return pcf8563_set_datetime(to_i2c_client(dev), tm);
-}
-
 static int pcf8563_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *tm)
 {
        struct i2c_client *client = to_i2c_client(dev);
@@ -591,13 +581,17 @@ static int pcf8563_probe(struct i2c_client *client,
                return err;
        }
 
-       pcf8563->rtc = devm_rtc_device_register(&client->dev,
-                               pcf8563_driver.driver.name,
-                               &pcf8563_rtc_ops, THIS_MODULE);
-
+       pcf8563->rtc = devm_rtc_allocate_device(&client->dev);
        if (IS_ERR(pcf8563->rtc))
                return PTR_ERR(pcf8563->rtc);
 
+       pcf8563->rtc->ops = &pcf8563_rtc_ops;
+       /* the pcf8563 alarm only supports a minute accuracy */
+       pcf8563->rtc->uie_unsupported = 1;
+       pcf8563->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+       pcf8563->rtc->range_max = RTC_TIMESTAMP_END_2099;
+       pcf8563->rtc->set_start_time = true;
+
        if (client->irq > 0) {
                err = devm_request_threaded_irq(&client->dev, client->irq,
                                NULL, pcf8563_irq,
@@ -608,17 +602,17 @@ static int pcf8563_probe(struct i2c_client *client,
                                                                client->irq);
                        return err;
                }
-
        }
 
+       err = rtc_register_device(pcf8563->rtc);
+       if (err)
+               return err;
+
 #ifdef CONFIG_COMMON_CLK
        /* register clk in common clk framework */
        pcf8563_clkout_register_clk(pcf8563);
 #endif
 
-       /* the pcf8563 alarm only supports a minute accuracy */
-       pcf8563->rtc->uie_unsupported = 1;
-
        return 0;
 }
 
@@ -632,6 +626,8 @@ MODULE_DEVICE_TABLE(i2c, pcf8563_id);
 #ifdef CONFIG_OF
 static const struct of_device_id pcf8563_of_match[] = {
        { .compatible = "nxp,pcf8563" },
+       { .compatible = "epson,rtc8564" },
+       { .compatible = "microcrystal,rv8564" },
        {}
 };
 MODULE_DEVICE_TABLE(of, pcf8563_of_match);