The previous pcf2127 RTC chip could not read and set the correct time.
When reading the data of internal registers, the read address was the
value of register plus 1. This is because this chip requires the host
to send a stop signal after setting the register address and before
reading the register data.

This patch sets the flag that the stop signal is needed and fixes the
bug of the original read and write time.

Signed-off-by: Biwen Li <biwen...@nxp.com>
Signed-off-by: Chuanhua Han <chuanhua....@nxp.com>
---
Changes in v2: 
        - Split the original patch into 3 patches
        - Add detailed description information for each patch

 drivers/rtc/pcf2127.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/rtc/pcf2127.c b/drivers/rtc/pcf2127.c
index dcf0340b4d..010c45ecbf 100644
--- a/drivers/rtc/pcf2127.c
+++ b/drivers/rtc/pcf2127.c
@@ -24,12 +24,9 @@
 
 static int pcf2127_rtc_set(struct udevice *dev, const struct rtc_time *tm)
 {
-       uchar buf[8];
+       uchar buf[7] = {0};
        int i = 0, ret;
 
-       /* start register address */
-       buf[i++] = PCF2127_REG_SC;
-
        /* hours, minutes and seconds */
        buf[i++] = bin2bcd(tm->tm_sec);
        buf[i++] = bin2bcd(tm->tm_min);
@@ -44,7 +41,7 @@ static int pcf2127_rtc_set(struct udevice *dev, const struct 
rtc_time *tm)
        buf[i++] = bin2bcd(tm->tm_year % 100);
 
        /* write register's data */
-       ret = dm_i2c_write(dev, PCF2127_REG_CTRL1, buf, sizeof(buf));
+       ret = dm_i2c_write(dev, PCF2127_REG_SC, buf, i);
 
        return ret;
 }
@@ -54,9 +51,6 @@ static int pcf2127_rtc_get(struct udevice *dev, struct 
rtc_time *tm)
        int ret = 0;
        uchar buf[10] = { PCF2127_REG_CTRL1 };
 
-       ret = dm_i2c_write(dev, PCF2127_REG_CTRL1, buf, 1);
-       if (ret < 0)
-               return ret;
        ret = dm_i2c_read(dev, PCF2127_REG_CTRL1, buf, sizeof(buf));
        if (ret < 0)
                return ret;
@@ -90,6 +84,13 @@ static int pcf2127_rtc_reset(struct udevice *dev)
        return 0;
 }
 
+static int pcf2127_probe(struct udevice *dev)
+{
+       i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_NEED_STOP_BIT);
+
+       return 0;
+}
+
 static const struct rtc_ops pcf2127_rtc_ops = {
        .get = pcf2127_rtc_get,
        .set = pcf2127_rtc_set,
@@ -104,6 +105,7 @@ static const struct udevice_id pcf2127_rtc_ids[] = {
 U_BOOT_DRIVER(rtc_pcf2127) = {
        .name   = "rtc-pcf2127",
        .id     = UCLASS_RTC,
+       .probe  = pcf2127_probe,
        .of_match = pcf2127_rtc_ids,
        .ops    = &pcf2127_rtc_ops,
 };
-- 
2.17.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to