diff mbox series

[v11,2/3] phy: qcom-qmp: add regulator_set_load to dp phy

Message ID 1653082028-10211-3-git-send-email-quic_khsieh@quicinc.com (mailing list archive)
State Superseded
Headers show
Series eDP/DP Phy vdda realted function | expand

Commit Message

Kuogee Hsieh May 20, 2022, 9:27 p.m. UTC
This patch add regulator_set_load() before enable regulator at
DP phy driver.

Signed-off-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/phy/qualcomm/phy-qcom-qmp.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Doug Anderson May 25, 2022, 12:17 a.m. UTC | #1
Hi,

On Fri, May 20, 2022 at 2:27 PM Kuogee Hsieh <quic_khsieh@quicinc.com> wrote:
>
> This patch add regulator_set_load() before enable regulator at
> DP phy driver.
>
> Signed-off-by: Kuogee Hsieh <quic_khsieh@quicinc.com>
> Reviewed-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  drivers/phy/qualcomm/phy-qcom-qmp.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c
> index b144ae1..a93e153 100644
> --- a/drivers/phy/qualcomm/phy-qcom-qmp.c
> +++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
> @@ -3130,6 +3130,7 @@ struct qmp_phy_cfg {
>         int num_resets;
>         /* regulators to be requested */
>         const char * const *vreg_list;
> +       const unsigned int *vreg_enable_load;
>         int num_vregs;
>
>         /* array of registers with different offsets */
> @@ -3346,6 +3347,10 @@ static const char * const qmp_phy_vreg_l[] = {
>         "vdda-phy", "vdda-pll",
>  };
>
> +static const unsigned int qmp_phy_vreg_enable_load[] = {
> +       21800, 36000
> +};

I'm a little confused. Why make a new parallel structure? Don't you
want to set a load for everyone who's using "qmp_phy_vreg_l"? It seems
like it would be better to do something like this:

struct qmp_regulator_data {
  const char *name;
  unsigned int load;
};

struct qmp_regulator_data qmp_phy_vreg_l[] = {
  { .name = "vdda-phy", .load = 21800 },
  { .name = "vdda-pll", .load = 36000 },
};

Right now some random smattering of devices are setting the load but
not others...

>  static const struct qmp_phy_cfg ipq8074_usb3phy_cfg = {
>         .type                   = PHY_TYPE_USB3,
>         .nlanes                 = 1,
> @@ -3711,6 +3716,7 @@ static const struct qmp_phy_cfg sc7180_usb3phy_cfg = {
>         .reset_list             = sc7180_usb3phy_reset_l,
>         .num_resets             = ARRAY_SIZE(sc7180_usb3phy_reset_l),
>         .vreg_list              = qmp_phy_vreg_l,
> +       .vreg_enable_load       = qmp_phy_vreg_enable_load,
>         .num_vregs              = ARRAY_SIZE(qmp_phy_vreg_l),

One downside of the parallel structures is that there's nothing
enforcing that ARRAY_SIZE(qmp_phy_vreg_l) ==
ARRAY_SIZE(qmp_phy_vreg_enable_load), though the code below relies on
it.


> @@ -6175,6 +6186,18 @@ static int qcom_qmp_phy_probe(struct platform_device *pdev)
>                 return ret;
>         }
>
> +       if (cfg->vreg_enable_load) {
> +               for (i = 0; i < cfg->num_vregs; i++) {
> +                       ret = regulator_set_load(qmp->vregs[i].consumer,
> +                                               cfg->vreg_enable_load[i]);
> +                       if (ret) {
> +                               dev_err(dev, "failed to set load at %s\n",
> +                                               qmp->vregs[i].supply);

nit: indentation of the 2nd line seems a bit off?

> +                               return ret;
> +                       }
> +               }
> +       }

Feels like the above snippet belongs in qcom_qmp_phy_vreg_init() ?
diff mbox series

Patch

diff --git a/drivers/phy/qualcomm/phy-qcom-qmp.c b/drivers/phy/qualcomm/phy-qcom-qmp.c
index b144ae1..a93e153 100644
--- a/drivers/phy/qualcomm/phy-qcom-qmp.c
+++ b/drivers/phy/qualcomm/phy-qcom-qmp.c
@@ -3130,6 +3130,7 @@  struct qmp_phy_cfg {
 	int num_resets;
 	/* regulators to be requested */
 	const char * const *vreg_list;
+	const unsigned int *vreg_enable_load;
 	int num_vregs;
 
 	/* array of registers with different offsets */
@@ -3346,6 +3347,10 @@  static const char * const qmp_phy_vreg_l[] = {
 	"vdda-phy", "vdda-pll",
 };
 
+static const unsigned int qmp_phy_vreg_enable_load[] = {
+	21800, 36000
+};
+
 static const struct qmp_phy_cfg ipq8074_usb3phy_cfg = {
 	.type			= PHY_TYPE_USB3,
 	.nlanes			= 1,
@@ -3711,6 +3716,7 @@  static const struct qmp_phy_cfg sc7180_usb3phy_cfg = {
 	.reset_list		= sc7180_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(sc7180_usb3phy_reset_l),
 	.vreg_list		= qmp_phy_vreg_l,
+	.vreg_enable_load	= qmp_phy_vreg_enable_load,
 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
 	.regs			= qmp_v3_usb3phy_regs_layout,
 
@@ -3749,6 +3755,7 @@  static const struct qmp_phy_cfg sc7180_dpphy_cfg = {
 	.reset_list		= sc7180_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(sc7180_usb3phy_reset_l),
 	.vreg_list		= qmp_phy_vreg_l,
+	.vreg_enable_load	= qmp_phy_vreg_enable_load,
 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
 	.regs			= qmp_v3_usb3phy_regs_layout,
 
@@ -3940,6 +3947,7 @@  static const struct qmp_phy_cfg sm8150_usb3phy_cfg = {
 	.reset_list		= msm8996_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(msm8996_usb3phy_reset_l),
 	.vreg_list		= qmp_phy_vreg_l,
+	.vreg_enable_load	= qmp_phy_vreg_enable_load,
 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
 	.regs			= qmp_v4_usb3phy_regs_layout,
 
@@ -4009,6 +4017,7 @@  static const struct qmp_phy_cfg sc8180x_dpphy_cfg = {
 	.reset_list		= sc7180_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(sc7180_usb3phy_reset_l),
 	.vreg_list		= qmp_phy_vreg_l,
+	.vreg_enable_load	= qmp_phy_vreg_enable_load,
 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
 	.regs			= qmp_v3_usb3phy_regs_layout,
 
@@ -4072,6 +4081,7 @@  static const struct qmp_phy_cfg sm8250_usb3phy_cfg = {
 	.reset_list		= msm8996_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(msm8996_usb3phy_reset_l),
 	.vreg_list		= qmp_phy_vreg_l,
+	.vreg_enable_load	= qmp_phy_vreg_enable_load,
 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
 	.regs			= qmp_v4_usb3phy_regs_layout,
 
@@ -4139,6 +4149,7 @@  static const struct qmp_phy_cfg sm8250_dpphy_cfg = {
 	.reset_list		= msm8996_usb3phy_reset_l,
 	.num_resets		= ARRAY_SIZE(msm8996_usb3phy_reset_l),
 	.vreg_list		= qmp_phy_vreg_l,
+	.vreg_enable_load	= qmp_phy_vreg_enable_load,
 	.num_vregs		= ARRAY_SIZE(qmp_phy_vreg_l),
 	.regs			= qmp_v4_usb3phy_regs_layout,
 
@@ -6107,7 +6118,7 @@  static int qcom_qmp_phy_probe(struct platform_device *pdev)
 	const struct qmp_phy_cfg *usb_cfg = NULL;
 	const struct qmp_phy_cfg *dp_cfg = NULL;
 	int num, id, expected_phys;
-	int ret;
+	int ret, i;
 
 	qmp = devm_kzalloc(dev, sizeof(*qmp), GFP_KERNEL);
 	if (!qmp)
@@ -6175,6 +6186,18 @@  static int qcom_qmp_phy_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	if (cfg->vreg_enable_load) {
+		for (i = 0; i < cfg->num_vregs; i++) {
+			ret = regulator_set_load(qmp->vregs[i].consumer,
+						cfg->vreg_enable_load[i]);
+			if (ret) {
+				dev_err(dev, "failed to set load at %s\n",
+						qmp->vregs[i].supply);
+				return ret;
+			}
+		}
+	}
+
 	num = of_get_available_child_count(dev->of_node);
 	/* do we have a rogue child node ? */
 	if (num > expected_phys)