.../devicetree/bindings/rtc/ti,bq32000.yaml | 5 +++ drivers/rtc/rtc-bq32k.c | 34 +++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-)
This series addresses a limitation in the TI BQ32000 RTC where aggressive I2C polling (done by userspace tools like hwclock on systems where the interrupt line is not connected to the CPU) can prevent the refresh of RTC registers. This results in stale data reads or select() timeouts in userspace. The series introduces a configurable "settle delay" via device tree to ensure the hardware has sufficient idle time between read attempts. Patch 1: Adds the 'ti,read-settle-us' property to the YAML bindings. Patch 2: Implements the delay in the driver using usleep_range. Adriana Stancu (2): dt-bindings: rtc: ti,bq32k: Add delay on rtc reads rtc: bq32000: add configurable delay between RTC reads .../devicetree/bindings/rtc/ti,bq32000.yaml | 5 +++ drivers/rtc/rtc-bq32k.c | 34 +++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) -- 2.51.0
This series addresses a limitation in the TI BQ32000 RTC where aggressive I2C polling (done by userspace tools like hwclock on systems where the interrupt line is not connected to the CPU) can prevent the refresh of RTC registers. This results in stale data reads or select() timeouts in userspace. The series introduces a configurable "settle delay" via device tree to ensure that the hardware has sufficient idle time between read attempts. Patch 1: Adds the "ti,read-settle-us" property to the YAML bindings. Patch 2: Implements the delay in the driver using usleep_range. Changes in v2: - Expanded dt-binding property description to explain use case. - Updated commit messages on dt change to describe the scenario when the dt property would be necessary. - Reword the commit messages to respect wrapping at 75 columns. Adriana Stancu (2): dt-bindings: rtc: ti,bq32k: Add delay on rtc reads rtc: bq32000: add configurable delay between RTC reads .../devicetree/bindings/rtc/ti,bq32000.yaml | 9 +++++ drivers/rtc/rtc-bq32k.c | 34 +++++++++++++++---- 2 files changed, 37 insertions(+), 6 deletions(-) -- 2.51.0
Add a configurable "ti,read-settle-us" property to resolve a limitation
where aggressive I2C polling prevents the BQ32000's internal register to
update. This ensures the hardware has sufficient idle time to update its
buffer, preventing stale data reads on systems where the "interrupts" are
not configured.
Signed-off-by: Adriana Stancu <adriana@arista.com>
---
Documentation/devicetree/bindings/rtc/ti,bq32000.yaml | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/Documentation/devicetree/bindings/rtc/ti,bq32000.yaml b/Documentation/devicetree/bindings/rtc/ti,bq32000.yaml
index bf9c1c4ddb7e..46403f0c85a5 100644
--- a/Documentation/devicetree/bindings/rtc/ti,bq32000.yaml
+++ b/Documentation/devicetree/bindings/rtc/ti,bq32000.yaml
@@ -29,6 +29,15 @@ properties:
trickle-diode-disable: true
+ ti,read-settle-us:
+ default: 0
+ description:
+ Delay in microseconds to wait before reading RTC registers.
+ Aggressive I2C polling on systems without an interrupt line
+ can prevent the BQ32000's internal refresh cycle, leading to
+ stale data. This delay ensures the hardware has sufficient
+ idle time to update its registers.
+
required:
- compatible
- reg
--
2.51.0
On 16/04/2026 11:57, Adriana Stancu wrote: > Add a configurable "ti,read-settle-us" property to resolve a limitation > where aggressive I2C polling prevents the BQ32000's internal register to > update. This ensures the hardware has sufficient idle time to update its > buffer, preventing stale data reads on systems where the "interrupts" are > not configured. And why does the value different between each board layouts? Same device, different board and you need different value? Do not attach (thread) your patchsets to some other threads (unrelated or older versions). This buries them deep in the mailbox and might interfere with applying entire sets. See also: https://elixir.bootlin.com/linux/v6.16-rc2/source/Documentation/process/submitting-patches.rst#L830 Best regards, Krzysztof
On Thu, Apr 16, 2026 at 2:00 PM Krzysztof Kozlowski <krzk@kernel.org> wrote: > > On 16/04/2026 11:57, Adriana Stancu wrote: > > Add a configurable "ti,read-settle-us" property to resolve a limitation > > where aggressive I2C polling prevents the BQ32000's internal register to > > update. This ensures the hardware has sufficient idle time to update its > > buffer, preventing stale data reads on systems where the "interrupts" are > > not configured. > > And why does the value different between each board layouts? Same > device, different board and you need different value? > > Do not attach (thread) your patchsets to some other threads (unrelated > or older versions). This buries them deep in the mailbox and might > interfere with applying entire sets. See also: > https://elixir.bootlin.com/linux/v6.16-rc2/source/Documentation/process/submitting-patches.rst#L830 > You are right, the delay should be specific to the RTC chip, not the board layout. I will drop the dt property and send a v3 that implements a fixed 2ms delay in the driver. This will be applied only when an interrupt is not present, because this is when the userspace will use polling. Best regards, Adriana
On 16/04/2026 02:57:05-0700, Adriana Stancu wrote: > Add a configurable "ti,read-settle-us" property to resolve a limitation > where aggressive I2C polling prevents the BQ32000's internal register to > update. This ensures the hardware has sufficient idle time to update its > buffer, preventing stale data reads on systems where the "interrupts" are > not configured. > Why does it need to be configured? -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
On Thu, Apr 16, 2026 at 1:03 PM Alexandre Belloni <alexandre.belloni@bootlin.com> wrote: > > On 16/04/2026 02:57:05-0700, Adriana Stancu wrote: > > Add a configurable "ti,read-settle-us" property to resolve a limitation > > where aggressive I2C polling prevents the BQ32000's internal register to > > update. This ensures the hardware has sufficient idle time to update its > > buffer, preventing stale data reads on systems where the "interrupts" are > > not configured. > > > > Why does it need to be configured? > In my testing on a 100kHz bus, 2ms was the stable value that resolved the issue with the hwclock version I tested. But it might be a delay too long for other systems becuase the required "settle" time may vary depending on the I2C bus speed and how fast the userspace is polling. I chose to make it configurable to avoid forcing an empirical value on all systems, especially those where a shorter delay might work, or where the interrupt line is properly connected and no polling is needed. If you prefer, I can change this to a fixed specific delay in the driver instead of a device tree property, but I thought a configurable value was more flexible for different board designs.
When the RTC is used on systems without a interrupt line, userspace tools
like "hwclock" fall back to a frequent polling loop to synchronize with
the edge of the next second.
On the BQ32000, this aggressive polling can temporarly lock the register
refresh cycle, because the continuous transfers prevent the hardware from
updating the buffer. This results in stale data reads or select() timeouts
in userspace.
This patch introduces a configurable settle delay via "ti,read-settle-us"
property. If this property is specified, the driver uses a delay before
reading the RTC registers. This provides a sufficient idle time for the
hardware to sync with the register buffer.
Signed-off-by: Adriana Stancu <adriana@arista.com>
---
drivers/rtc/rtc-bq32k.c | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 7ad34539be4d..0cbfa0909732 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -16,6 +16,7 @@
#include <linux/kstrtox.h>
#include <linux/errno.h>
#include <linux/bcd.h>
+#include <linux/delay.h>
#define BQ32K_SECONDS 0x00 /* Seconds register address */
#define BQ32K_SECONDS_MASK 0x7F /* Mask over seconds value */
@@ -48,6 +49,11 @@ struct bq32k_regs {
uint8_t years;
};
+struct bq32k_data {
+ struct rtc_device *rtc;
+ u32 read_delay_us;
+};
+
static struct i2c_driver bq32k_driver;
static int bq32k_read(struct device *dev, void *data, uint8_t off, uint8_t len)
@@ -89,9 +95,17 @@ static int bq32k_write(struct device *dev, void *data, uint8_t off, uint8_t len)
static int bq32k_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
+ struct bq32k_data *bq32k = dev_get_drvdata(dev);
struct bq32k_regs regs;
int error;
+ /*
+ * When the device doesn't have the interrupt connected, prevent
+ * userpace from polling the RTC registers to frequently.
+ */
+ if (bq32k && bq32k->read_delay_us)
+ usleep_range(bq32k->read_delay_us, bq32k->read_delay_us + 50);
+
error = bq32k_read(dev, ®s, 0, sizeof(regs));
if (error)
return error;
@@ -253,13 +267,18 @@ static void bq32k_sysfs_unregister(struct device *dev)
static int bq32k_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
- struct rtc_device *rtc;
+ struct bq32k_data *bq32k;
uint8_t reg;
int error;
+ uint32_t settle_us = 0;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
return -ENODEV;
+ bq32k = devm_kzalloc(dev, sizeof(*bq32k), GFP_KERNEL);
+ if (!bq32k)
+ return -ENOMEM;
+
/* Check Oscillator Stop flag */
error = bq32k_read(dev, ®, BQ32K_SECONDS, 1);
if (!error && (reg & BQ32K_STOP)) {
@@ -280,10 +299,13 @@ static int bq32k_probe(struct i2c_client *client)
if (client->dev.of_node)
trickle_charger_of_init(dev, client->dev.of_node);
- rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name,
- &bq32k_rtc_ops, THIS_MODULE);
- if (IS_ERR(rtc))
- return PTR_ERR(rtc);
+ bq32k->rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name,
+ &bq32k_rtc_ops, THIS_MODULE);
+ if (IS_ERR(bq32k->rtc))
+ return PTR_ERR(bq32k->rtc);
+
+ device_property_read_u32(dev, "ti,read-settle-us", &settle_us);
+ bq32k->read_delay_us = settle_us;
error = bq32k_sysfs_register(&client->dev);
if (error) {
@@ -293,7 +315,7 @@ static int bq32k_probe(struct i2c_client *client)
}
- i2c_set_clientdata(client, rtc);
+ i2c_set_clientdata(client, bq32k);
return 0;
}
--
2.51.0
© 2016 - 2026 Red Hat, Inc.