From: Arturo Buzarra Date: Mon, 23 Sep 2024 08:25:18 +0000 (+0200) Subject: rtc: rv3028: add support to manage VDD regulator X-Git-Url: http://git.dujemihanovic.xyz/%22http:/www.sics.se/static/git-favicon.png?a=commitdiff_plain;h=718c225cbcd1543ab973e5d98160d97d2e5817ef;p=u-boot.git rtc: rv3028: add support to manage VDD regulator This commit adds support to manage an external regulator to enable the main power supply VDD. Signed-off-by: Arturo Buzarra --- diff --git a/drivers/rtc/rv3028.c b/drivers/rtc/rv3028.c index 9f63afc14a..b14d2a246f 100644 --- a/drivers/rtc/rv3028.c +++ b/drivers/rtc/rv3028.c @@ -12,6 +12,9 @@ #include #include #include +#include +#include +#include #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), };