From: Bryan O'Donoghue <bod@kernel.org>
To: Rakesh Kota <rakesh.kota@oss.qualcomm.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Wesley Cheng <quic_wcheng@quicinc.com>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, jishnu.prakash@oss.qualcomm.com,
kamal.wadhwa@oss.qualcomm.com,
Krzysztof Kozlowski <krzk@kernel.org>
Subject: Re: [PATCH v3 2/4] regulator: qcom_usb_vbus: add register abstraction and PM8150B support
Date: Mon, 6 Jul 2026 14:45:26 +0100 [thread overview]
Message-ID: <477e95d5-ee3f-4a75-acef-a01f317f16c9@kernel.org> (raw)
In-Reply-To: <20260706-add_pm4125-vbus-reg-v3-2-999d78a87b81@oss.qualcomm.com>
On 06/07/2026 13:31, Rakesh Kota wrote:
> Introduce per-compatible regulator descriptor data via struct
> qcom_usb_vbus_reg_data to abstract register layout differences between
> PMICs. This allows the probe function to dynamically populate the
> regulator_desc fields rather than relying on compile-time constants.
>
> Refactor the existing PM8150B support to use this abstraction, wiring in
> its CMD_OTG, OTG_CFG, and current-limit registers through pm8150b_data.
> No functional change is intended for PM8150B.
>
> Signed-off-by: Rakesh Kota <rakesh.kota@oss.qualcomm.com>
> ---
> drivers/regulator/qcom_usb_vbus-regulator.c | 71 +++++++++++++++++++++++------
> 1 file changed, 57 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/regulator/qcom_usb_vbus-regulator.c b/drivers/regulator/qcom_usb_vbus-regulator.c
> index cd94ed67621fee9f6d7a0327054db0ebab6cc7ee..0201a3983981eec1f475d4b8cdccc9148b5e3b2e 100644
> --- a/drivers/regulator/qcom_usb_vbus-regulator.c
> +++ b/drivers/regulator/qcom_usb_vbus-regulator.c
> @@ -20,6 +20,21 @@
> #define OTG_CFG 0x53
> #define OTG_EN_SRC_CFG BIT(1)
>
> +struct qcom_usb_vbus_reg_data {
> + u16 cmd_otg;
> + u16 otg_cfg;
> + u8 otg_en_src_cfg;
> + u16 csel_reg;
> + u8 csel_mask;
> + const unsigned int *curr_table;
> + unsigned int n_current_limits;
> + u16 vsel_reg;
> + u8 vsel_mask;
> + const unsigned int *volt_table;
> + unsigned int n_voltages;
> + const struct regulator_ops *ops;
> +};
> +
> static const unsigned int curr_table[] = {
> 500000, 1000000, 1500000, 2000000, 2500000, 3000000,
> };
> @@ -32,19 +47,23 @@ static const struct regulator_ops qcom_usb_vbus_reg_ops = {
> .set_current_limit = regulator_set_current_limit_regmap,
> };
>
> -static struct regulator_desc qcom_usb_vbus_rdesc = {
> - .name = "usb_vbus",
> - .ops = &qcom_usb_vbus_reg_ops,
> - .owner = THIS_MODULE,
> - .type = REGULATOR_VOLTAGE,
> +static const struct qcom_usb_vbus_reg_data pm8150b_data = {
> + .cmd_otg = CMD_OTG,
> + .otg_cfg = OTG_CFG,
> + .otg_en_src_cfg = OTG_EN_SRC_CFG,
> + .csel_reg = OTG_CURRENT_LIMIT_CFG,
> + .csel_mask = OTG_CURRENT_LIMIT_MASK,
> .curr_table = curr_table,
> .n_current_limits = ARRAY_SIZE(curr_table),
> + .ops = &qcom_usb_vbus_reg_ops,
> };
>
> static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> + const struct qcom_usb_vbus_reg_data *data;
> struct regulator_dev *rdev;
> + struct regulator_desc *rdesc;
> struct regmap *regmap;
> struct regulator_config config = { };
> struct regulator_init_data *init_data;
> @@ -57,27 +76,51 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
> return ret;
> }
>
> + data = of_device_get_match_data(dev);
> + if (!data)
> + return -EINVAL;
> +
> regmap = dev_get_regmap(dev->parent, NULL);
> if (!regmap) {
> dev_err(dev, "Failed to get regmap\n");
> return -ENOENT;
> }
>
> - init_data = of_get_regulator_init_data(dev, dev->of_node,
> - &qcom_usb_vbus_rdesc);
> + rdesc = devm_kzalloc(dev, sizeof(*rdesc), GFP_KERNEL);
> + if (!rdesc)
> + return -ENOMEM;
> +
> + rdesc->name = "usb_vbus";
> + rdesc->ops = data->ops;
> + rdesc->owner = THIS_MODULE;
> + rdesc->type = REGULATOR_VOLTAGE;
> + rdesc->enable_reg = base + data->cmd_otg;
> + rdesc->enable_mask = OTG_EN;
> +
> + if (data->curr_table) {
> + rdesc->curr_table = data->curr_table;
> + rdesc->n_current_limits = data->n_current_limits;
> + rdesc->csel_reg = base + data->csel_reg;
> + rdesc->csel_mask = data->csel_mask;
> + }
> +
> + if (data->volt_table) {
> + rdesc->volt_table = data->volt_table;
> + rdesc->n_voltages = data->n_voltages;
> + rdesc->vsel_reg = base + data->vsel_reg;
> + rdesc->vsel_mask = data->vsel_mask;
> + }
> +
> + init_data = of_get_regulator_init_data(dev, dev->of_node, rdesc);
> if (!init_data)
> return -ENOMEM;
>
> - qcom_usb_vbus_rdesc.enable_reg = base + CMD_OTG;
> - qcom_usb_vbus_rdesc.enable_mask = OTG_EN;
> - qcom_usb_vbus_rdesc.csel_reg = base + OTG_CURRENT_LIMIT_CFG;
> - qcom_usb_vbus_rdesc.csel_mask = OTG_CURRENT_LIMIT_MASK;
> config.dev = dev;
> config.init_data = init_data;
> config.of_node = dev->of_node;
> config.regmap = regmap;
>
> - rdev = devm_regulator_register(dev, &qcom_usb_vbus_rdesc, &config);
> + rdev = devm_regulator_register(dev, rdesc, &config);
> if (IS_ERR(rdev)) {
> ret = PTR_ERR(rdev);
> dev_err(dev, "not able to register vbus reg %d\n", ret);
> @@ -85,13 +128,13 @@ static int qcom_usb_vbus_regulator_probe(struct platform_device *pdev)
> }
>
> /* Disable HW logic for VBUS enable */
> - regmap_update_bits(regmap, base + OTG_CFG, OTG_EN_SRC_CFG, 0);
> + regmap_update_bits(regmap, base + data->otg_cfg, data->otg_en_src_cfg, 0);
>
> return 0;
> }
>
> static const struct of_device_id qcom_usb_vbus_regulator_match[] = {
> - { .compatible = "qcom,pm8150b-vbus-reg" },
> + { .compatible = "qcom,pm8150b-vbus-reg", .data = &pm8150b_data },
> { }
> };
> MODULE_DEVICE_TABLE(of, qcom_usb_vbus_regulator_match);
>
> --
> 2.34.1
>
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
next prev parent reply other threads:[~2026-07-06 13:45 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 12:31 [PATCH v3 0/4] regulator: qcom_usb_vbus: add pm4125 VBUS regulator support Rakesh Kota
2026-07-06 12:31 ` [PATCH v3 1/4] dt-bindings: regulator: qcom,usb-vbus-regulator: add qcom,pm4125-vbus-reg Rakesh Kota
2026-07-06 17:24 ` Mark Brown
2026-07-06 12:31 ` [PATCH v3 2/4] regulator: qcom_usb_vbus: add register abstraction and PM8150B support Rakesh Kota
2026-07-06 13:45 ` Bryan O'Donoghue [this message]
2026-07-06 13:46 ` Mark Brown
2026-07-06 14:29 ` Dmitry Baryshkov
2026-07-06 12:31 ` [PATCH v3 3/4] regulator: qcom_usb_vbus: add support for qcom,pm4125-vbus-reg Rakesh Kota
2026-07-06 13:48 ` Bryan O'Donoghue
2026-07-06 14:29 ` Dmitry Baryshkov
2026-07-06 15:31 ` Konrad Dybcio
2026-07-06 12:31 ` [PATCH v3 4/4] arm64: dts: qcom: Fix pm4125 vbus regulator compatible and constraints Rakesh Kota
2026-07-06 13:08 ` Konrad Dybcio
2026-07-06 13:49 ` Bryan O'Donoghue
2026-07-06 14:30 ` Dmitry Baryshkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=477e95d5-ee3f-4a75-acef-a01f317f16c9@kernel.org \
--to=bod@kernel.org \
--cc=andersson@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jishnu.prakash@oss.qualcomm.com \
--cc=kamal.wadhwa@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_wcheng@quicinc.com \
--cc=rakesh.kota@oss.qualcomm.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox