From eb2c63ddccb94b134846f890fcada84554ba2896 Mon Sep 17 00:00:00 2001 From: Rui Miguel Silva Date: Sat, 12 Apr 2025 18:41:31 +0100 Subject: power: qcom_vbus_regulator: add and fix support for pmic variants Fix and add support for different pmic variants pm8x50b to handle the vbus regulator. Signed-off-by: Rui Miguel Silva Link: https://lore.kernel.org/r/20250412174157.104419-1-rui.silva@linaro.org Signed-off-by: Casey Connolly --- drivers/power/regulator/qcom_usb_vbus_regulator.c | 37 ++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) (limited to 'drivers/power') diff --git a/drivers/power/regulator/qcom_usb_vbus_regulator.c b/drivers/power/regulator/qcom_usb_vbus_regulator.c index 2d58ef5e111..07f118d4797 100644 --- a/drivers/power/regulator/qcom_usb_vbus_regulator.c +++ b/drivers/power/regulator/qcom_usb_vbus_regulator.c @@ -15,14 +15,33 @@ #include #include -#define CMD_OTG 0x50 +enum pm8x50b_vbus { + PM8150B, + PM8550B, +}; + #define OTG_EN BIT(0) -// The 0 bit in this register's bit field is undocumented -#define OTG_CFG 0x56 + #define OTG_EN_SRC_CFG BIT(1) +struct qcom_otg_regs { + u32 otg_cmd; + u32 otg_cfg; +}; struct qcom_usb_vbus_priv { phys_addr_t base; + struct qcom_otg_regs *regs; +}; + +static const struct qcom_otg_regs qcom_otg[] = { + [PM8150B] = { + .otg_cmd = 0x40, + .otg_cfg = 0x53, + }, + [PM8550B] = { + .otg_cmd = 0x50, + .otg_cfg = 0x56, + }, }; static int qcom_usb_vbus_regulator_of_to_plat(struct udevice *dev) @@ -38,8 +57,9 @@ static int qcom_usb_vbus_regulator_of_to_plat(struct udevice *dev) static int qcom_usb_vbus_regulator_get_enable(struct udevice *dev) { + const struct qcom_otg_regs *regs = &qcom_otg[dev_get_driver_data(dev)]; struct qcom_usb_vbus_priv *priv = dev_get_priv(dev); - int otg_en_reg = priv->base + CMD_OTG; + int otg_en_reg = priv->base + regs->otg_cmd; int ret; ret = pmic_reg_read(dev->parent, otg_en_reg); @@ -53,8 +73,9 @@ static int qcom_usb_vbus_regulator_get_enable(struct udevice *dev) static int qcom_usb_vbus_regulator_set_enable(struct udevice *dev, bool enable) { + const struct qcom_otg_regs *regs = &qcom_otg[dev_get_driver_data(dev)]; struct qcom_usb_vbus_priv *priv = dev_get_priv(dev); - int otg_en_reg = priv->base + CMD_OTG; + int otg_en_reg = priv->base + regs->otg_cmd; int ret; if (enable) { @@ -76,8 +97,9 @@ static int qcom_usb_vbus_regulator_set_enable(struct udevice *dev, bool enable) static int qcom_usb_vbus_regulator_probe(struct udevice *dev) { + const struct qcom_otg_regs *regs = &qcom_otg[dev_get_driver_data(dev)]; struct qcom_usb_vbus_priv *priv = dev_get_priv(dev); - int otg_cfg_reg = priv->base + OTG_CFG; + int otg_cfg_reg = priv->base + regs->otg_cfg; int ret; /* Disable HW logic for VBUS enable */ @@ -96,7 +118,8 @@ static const struct dm_regulator_ops qcom_usb_vbus_regulator_ops = { }; static const struct udevice_id qcom_usb_vbus_regulator_ids[] = { - { .compatible = "qcom,pm8150b-vbus-reg"}, + { .compatible = "qcom,pm8150b-vbus-reg", .data = PM8150B }, + { .compatible = "qcom,pm8550b-vbus-reg", .data = PM8550B }, { }, }; -- cgit v1.3.1 From f8f865ec0b17d756e10d4088bff1814744044dd3 Mon Sep 17 00:00:00 2001 From: Justin Klaassen Date: Fri, 23 May 2025 16:53:39 +0000 Subject: regulator: rk8xx: Add CONFIG_SPL_REGULATOR_RK8XX Allows use of the regulator functions of the RK8XX PMIC in SPL, which is necessary to support the functionality of the Rockchip IO-domain driver on relevant platforms. Signed-off-by: Justin Klaassen Reviewed-by: Quentin Schulz Reviewed-by: Kever Yang --- drivers/power/regulator/Kconfig | 9 +++++++++ drivers/power/regulator/rk8xx.c | 8 ++------ 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'drivers/power') diff --git a/drivers/power/regulator/Kconfig b/drivers/power/regulator/Kconfig index 7ed435f0202..65b99e89656 100644 --- a/drivers/power/regulator/Kconfig +++ b/drivers/power/regulator/Kconfig @@ -264,6 +264,15 @@ config REGULATOR_RK8XX by the PMIC device. This driver is controlled by a device tree node which includes voltage limits. +config SPL_REGULATOR_RK8XX + bool "Enable driver for RK8XX regulators in SPL" + depends on SPL_DM_REGULATOR && SPL_PMIC_RK8XX + help + Enable support for the regulator functions of the RK8XX PMIC in SPL. The + driver implements get/set api for the various BUCKS and LDOs supported + by the PMIC device. This driver is controlled by a device tree node + which includes voltage limits. + config DM_REGULATOR_S2MPS11 bool "Enable driver for S2MPS11 regulator" depends on DM_REGULATOR && PMIC_S2MPS11 diff --git a/drivers/power/regulator/rk8xx.c b/drivers/power/regulator/rk8xx.c index 368675ebb9f..88453bb7bdb 100644 --- a/drivers/power/regulator/rk8xx.c +++ b/drivers/power/regulator/rk8xx.c @@ -16,10 +16,6 @@ #include #include -#ifndef CONFIG_XPL_BUILD -#define ENABLE_DRIVER -#endif - /* Not used or exisit register and configure */ #define NA 0xff @@ -202,7 +198,7 @@ static const struct rk8xx_reg_info rk818_buck[] = { { 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f }, }; -#ifdef ENABLE_DRIVER +#if CONFIG_IS_ENABLED(REGULATOR_RK8XX) static const struct rk8xx_reg_info rk806_nldo[] = { /* nldo 1 */ { 500000, 12500, RK806_NLDO_ON_VSEL(1), RK806_NLDO_SLP_VSEL(1), NA, RK806_NLDO_VSEL_MASK, 0x00, 0xe7}, @@ -454,7 +450,7 @@ static int _buck_set_enable(struct udevice *pmic, int buck, bool enable) return ret; } -#ifdef ENABLE_DRIVER +#if CONFIG_IS_ENABLED(REGULATOR_RK8XX) static int _buck_set_suspend_value(struct udevice *pmic, int buck, int uvolt) { const struct rk8xx_reg_info *info = get_buck_reg(pmic, buck, uvolt); -- cgit v1.3.1 From b8101af3ce56a547f373d273d9ea37aefb74dc5a Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Wed, 28 May 2025 14:07:27 +0200 Subject: power: rk8xx: fix swapped mask and value in init registers for RK806 The val (the bits to set) is the second member of the reg_data structure and mask the third one. We obviously want to clear bits 6 and 7 in order to only set bit 7 in there instead of only clearing bit 7 in order to write bits 6 and 7 (which makes no sense). Fortunately, according to the datasheet, bit 6 value doesn't matter when bit 7 is set so this is essentially just a cosmetic change, no intended change in behavior. Fixes: f172575d92cd ("power: rk8xx: add support for RK806") Signed-off-by: Quentin Schulz Reviewed-by: Kever Yang --- drivers/power/pmic/rk8xx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/power') diff --git a/drivers/power/pmic/rk8xx.c b/drivers/power/pmic/rk8xx.c index a14555cf472..3bc696d4caa 100644 --- a/drivers/power/pmic/rk8xx.c +++ b/drivers/power/pmic/rk8xx.c @@ -91,7 +91,7 @@ void rk8xx_off_for_plugin(struct udevice *dev) static struct reg_data rk806_init_reg[] = { /* RST_FUN */ - { RK806_REG_SYS_CFG3, GENMASK(7, 6), BIT(7)}, + { RK806_REG_SYS_CFG3, BIT(7), GENMASK(7, 6)}, }; static struct reg_data rk817_init_reg[] = { -- cgit v1.3.1