]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/rtc/rtc-pcf2123.c
Merge tag 'nios2-v5.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/lftan/nios2
[linux.git] / drivers / rtc / rtc-pcf2123.c
index df20dd2291407bc8262688fb7d5f7eee4606544b..c3691fa4210e544b030d0246d0a46f23c87c318a 100644 (file)
@@ -194,9 +194,7 @@ static int pcf2123_rtc_read_time(struct device *dev, struct rtc_time *tm)
        tm->tm_mday = bcd2bin(rxbuf[3] & 0x3F);
        tm->tm_wday = rxbuf[4] & 0x07;
        tm->tm_mon = bcd2bin(rxbuf[5] & 0x1F) - 1; /* rtc mn 1-12 */
-       tm->tm_year = bcd2bin(rxbuf[6]);
-       if (tm->tm_year < 70)
-               tm->tm_year += 100;     /* assume we are in 1970...2069 */
+       tm->tm_year = bcd2bin(rxbuf[6]) + 100;
 
        dev_dbg(dev, "%s: tm is %ptR\n", __func__, tm);
 
@@ -223,7 +221,7 @@ static int pcf2123_rtc_set_time(struct device *dev, struct rtc_time *tm)
        txbuf[3] = bin2bcd(tm->tm_mday & 0x3F);
        txbuf[4] = tm->tm_wday & 0x07;
        txbuf[5] = bin2bcd((tm->tm_mon + 1) & 0x1F); /* rtc mn 1-12 */
-       txbuf[6] = bin2bcd(tm->tm_year < 100 ? tm->tm_year : tm->tm_year - 100);
+       txbuf[6] = bin2bcd(tm->tm_year - 100);
 
        ret = regmap_bulk_write(pcf2123->map, PCF2123_REG_SC, txbuf,
                                sizeof(txbuf));
@@ -390,10 +388,9 @@ static int pcf2123_probe(struct spi_device *spi)
        dev_set_drvdata(&spi->dev, pcf2123);
 
        pcf2123->map = devm_regmap_init_spi(spi, &pcf2123_regmap_config);
-
        if (IS_ERR(pcf2123->map)) {
                dev_err(&spi->dev, "regmap init failed.\n");
-               goto kfree_exit;
+               return PTR_ERR(pcf2123->map);
        }
 
        ret = pcf2123_rtc_read_time(&spi->dev, &tm);
@@ -401,7 +398,7 @@ static int pcf2123_probe(struct spi_device *spi)
                ret = pcf2123_reset(&spi->dev);
                if (ret < 0) {
                        dev_err(&spi->dev, "chip not found\n");
-                       goto kfree_exit;
+                       return ret;
                }
        }
 
@@ -409,18 +406,12 @@ static int pcf2123_probe(struct spi_device *spi)
                        (spi->max_speed_hz + 500) / 1000);
 
        /* Finalize the initialization */
-       rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
-                       &pcf2123_rtc_ops, THIS_MODULE);
-
-       if (IS_ERR(rtc)) {
-               dev_err(&spi->dev, "failed to register.\n");
-               ret = PTR_ERR(rtc);
-               goto kfree_exit;
-       }
+       rtc = devm_rtc_allocate_device(&spi->dev);
+       if (IS_ERR(rtc))
+               return PTR_ERR(rtc);
 
        pcf2123->rtc = rtc;
 
-
        /* Register alarm irq */
        if (spi->irq > 0) {
                ret = devm_request_threaded_irq(&spi->dev, spi->irq, NULL,
@@ -437,18 +428,25 @@ static int pcf2123_probe(struct spi_device *spi)
         * support to this driver to generate interrupts more than once
         * per minute.
         */
-       pcf2123->rtc->uie_unsupported = 1;
+       rtc->uie_unsupported = 1;
+       rtc->ops = &pcf2123_rtc_ops;
+       rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
+       rtc->range_max = RTC_TIMESTAMP_END_2099;
+       rtc->set_start_time = true;
 
-       return 0;
+       ret = rtc_register_device(rtc);
+       if (ret)
+               return ret;
 
-kfree_exit:
-       return ret;
+       return 0;
 }
 
 #ifdef CONFIG_OF
 static const struct of_device_id pcf2123_dt_ids[] = {
-       { .compatible = "nxp,rtc-pcf2123", },
+       { .compatible = "nxp,pcf2123", },
        { .compatible = "microcrystal,rv2123", },
+       /* Deprecated, do not use */
+       { .compatible = "nxp,rtc-pcf2123", },
        { /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, pcf2123_dt_ids);