]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
rtc: pcf2127: improve timestamp reading performance
authorHugo Villeneuve <hvilleneuve@dimonoff.com>
Thu, 22 Jun 2023 14:57:45 +0000 (10:57 -0400)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 27 Jul 2023 20:54:51 +0000 (22:54 +0200)
Reading the 7 timetamp registers currently involves reading 25 registers
solely to be able to print the content of the three control registers,
in addition to the 7 timestamp registers. This print never occurs,
unless the user enables dynamic debug in this driver or set
CONFIG_RTC_DEBUG.

Reading the timestamp registers should consist of reading 7
consecutive timestamp registers.

This patch optimize the performance of reading the timestamp registers
by reading 7 consecutive registers instead of 25, and dropping the
print of the control registers.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://lore.kernel.org/r/20230622145800.2442116-3-hugo@hugovil.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-pcf2127.c

index 8d40a413a8fe3ab29e01766194615d4d54353936..3332d26aee118354c0d88f4feb1b8d1d15a3a119 100644 (file)
 #define PCF2127_REG_TS_CTRL            0x12
 #define PCF2127_BIT_TS_CTRL_TSOFF              BIT(6)
 #define PCF2127_BIT_TS_CTRL_TSM                        BIT(7)
-#define PCF2127_REG_TS_SC              0x13
-#define PCF2127_REG_TS_MN              0x14
-#define PCF2127_REG_TS_HR              0x15
-#define PCF2127_REG_TS_DM              0x16
-#define PCF2127_REG_TS_MO              0x17
-#define PCF2127_REG_TS_YR              0x18
 /*
  * RAM registers
  * PCF2127 has 512 bytes general-purpose static RAM (SRAM) that is
@@ -440,9 +434,9 @@ static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts)
        struct pcf2127 *pcf2127 = dev_get_drvdata(dev);
        struct rtc_time tm;
        int ret;
-       unsigned char data[25];
+       unsigned char data[7];
 
-       ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_CTRL1, data,
+       ret = regmap_bulk_read(pcf2127->regmap, PCF2127_REG_TS_CTRL, data,
                               sizeof(data));
        if (ret) {
                dev_err(dev, "%s: read error ret=%d\n", __func__, ret);
@@ -450,20 +444,16 @@ static int pcf2127_rtc_ts_read(struct device *dev, time64_t *ts)
        }
 
        dev_dbg(dev,
-               "%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, ts_sc=%02x, ts_mn=%02x, ts_hr=%02x, ts_dm=%02x, ts_mo=%02x, ts_yr=%02x\n",
-               __func__, data[PCF2127_REG_CTRL1], data[PCF2127_REG_CTRL2],
-               data[PCF2127_REG_CTRL3], data[PCF2127_REG_TS_SC],
-               data[PCF2127_REG_TS_MN], data[PCF2127_REG_TS_HR],
-               data[PCF2127_REG_TS_DM], data[PCF2127_REG_TS_MO],
-               data[PCF2127_REG_TS_YR]);
-
-       tm.tm_sec = bcd2bin(data[PCF2127_REG_TS_SC] & 0x7F);
-       tm.tm_min = bcd2bin(data[PCF2127_REG_TS_MN] & 0x7F);
-       tm.tm_hour = bcd2bin(data[PCF2127_REG_TS_HR] & 0x3F);
-       tm.tm_mday = bcd2bin(data[PCF2127_REG_TS_DM] & 0x3F);
+               "%s: raw data is ts_sc=%02x, ts_mn=%02x, ts_hr=%02x, ts_dm=%02x, ts_mo=%02x, ts_yr=%02x\n",
+               __func__, data[1], data[2], data[3], data[4], data[5], data[6]);
+
+       tm.tm_sec = bcd2bin(data[1] & 0x7F);
+       tm.tm_min = bcd2bin(data[2] & 0x7F);
+       tm.tm_hour = bcd2bin(data[3] & 0x3F);
+       tm.tm_mday = bcd2bin(data[4] & 0x3F);
        /* TS_MO register (month) value range: 1-12 */
-       tm.tm_mon = bcd2bin(data[PCF2127_REG_TS_MO] & 0x1F) - 1;
-       tm.tm_year = bcd2bin(data[PCF2127_REG_TS_YR]);
+       tm.tm_mon = bcd2bin(data[5] & 0x1F) - 1;
+       tm.tm_year = bcd2bin(data[6]);
        if (tm.tm_year < 70)
                tm.tm_year += 100; /* assume we are in 1970...2069 */