[PATCH] rtc: rv3028: add support to manage VDD regulator
arturo.buzarra at digi.com
arturo.buzarra at digi.com
Mon Sep 23 10:25:18 CEST 2024
From: Arturo Buzarra <arturo.buzarra at digi.com>
This commit adds support to manage an external regulator to enable the main
power supply VDD.
Signed-off-by: Arturo Buzarra <arturo.buzarra at digi.com>
---
drivers/rtc/rv3028.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/rtc/rv3028.c b/drivers/rtc/rv3028.c
index 9f63afc14a8..b14d2a246ff 100644
--- a/drivers/rtc/rv3028.c
+++ b/drivers/rtc/rv3028.c
@@ -12,6 +12,9 @@
#include <dm.h>
#include <i2c.h>
#include <rtc.h>
+#include <dm/device_compat.h>
+#include <linux/delay.h>
+#include <power/regulator.h>
#define RV3028_SEC 0x00
#define RV3028_MIN 0x01
@@ -78,6 +81,12 @@
#define RTC_RV3028_LEN 7
+#define VDD_START_TIME_US 200000
+
+struct rv3028_priv {
+ struct udevice *vdd;
+};
+
static int rv3028_rtc_get(struct udevice *dev, struct rtc_time *tm)
{
u8 regs[RTC_RV3028_LEN];
@@ -180,6 +189,28 @@ static int rv3028_rtc_write8(struct udevice *dev, unsigned int reg, int val)
static int rv3028_probe(struct udevice *dev)
{
+ struct rv3028_priv *priv = dev_get_priv(dev);
+ int ret;
+
+ if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
+ ret = device_get_supply_regulator(dev, "vdd-supply", &priv->vdd);
+ if (ret && ret != -ENOENT) {
+ dev_err(dev, "Warning: cannot get VDD supply\n");
+ return ret;
+ }
+
+ if (priv->vdd) {
+ ret = regulator_set_enable_if_allowed(priv->vdd, true);
+ if (ret) {
+ dev_err(dev, "failed to enable vdd-supply\n");
+ return ret;
+ }
+
+ /* We must wait Tstart = 0.2s before access to I2C */
+ udelay(VDD_START_TIME_US);
+ }
+ }
+
i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS |
DM_I2C_CHIP_WR_ADDRESS);
@@ -205,4 +236,5 @@ U_BOOT_DRIVER(rtc_rv3028) = {
.probe = rv3028_probe,
.of_match = rv3028_rtc_ids,
.ops = &rv3028_rtc_ops,
+ .priv_auto = sizeof(struct rv3028_priv),
};
--
2.46.0
More information about the U-Boot
mailing list