Commit 720fb4b8 authored by Hugo Villeneuve's avatar Hugo Villeneuve Committed by Alexandre Belloni
Browse files

rtc: pcf2127: improve timestamp reading performance



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: default avatarHugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://lore.kernel.org/r/20230622145800.2442116-3-hugo@hugovil.com


Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
parent 31f077c3
Loading
Loading
Loading
Loading
+11 −21
Original line number Diff line number Diff line
@@ -66,12 +66,6 @@
#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 */