diff mbox series

[1/2] media: qcom: camss: add management of supply regulators to CSIPHY

Message ID 20240926211957.4108692-2-vladimir.zapolskiy@linaro.org
State New
Headers show
Series media: qcom: camss: manage supply regulators as CSIPHY resources | expand

Commit Message

Vladimir Zapolskiy Sept. 26, 2024, 9:19 p.m. UTC
This change allows to properly assign and manage supply regulator
resources by CSIPHY subdevices of CAMSS, this is needed to fine tune
description of supply regulators on newer platforms, conversion of
old platforms to the new scheme is also anticipated.

Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
---
 .../media/platform/qcom/camss/camss-csiphy.c  | 35 ++++++++++++++++++-
 .../media/platform/qcom/camss/camss-csiphy.h  |  2 ++
 2 files changed, 36 insertions(+), 1 deletion(-)

Comments

Depeng Shao Oct. 8, 2024, 4 p.m. UTC | #1
Hi Vladimir,

On 9/27/2024 5:19 AM, Vladimir Zapolskiy wrote:
> This change allows to properly assign and manage supply regulator
> resources by CSIPHY subdevices of CAMSS, this is needed to fine tune
> description of supply regulators on newer platforms, conversion of
> old platforms to the new scheme is also anticipated.
> 
> Signed-off-by: Vladimir Zapolskiy <vladimir.zapolskiy@linaro.org>
> ---
>   .../media/platform/qcom/camss/camss-csiphy.c  | 35 ++++++++++++++++++-
>   .../media/platform/qcom/camss/camss-csiphy.h  |  2 ++
>   2 files changed, 36 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c
> index 2f7361dfd461..68a3ea1ba2a5 100644
> --- a/drivers/media/platform/qcom/camss/camss-csiphy.c
> +++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
> @@ -212,14 +212,25 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on)
>   		if (ret < 0)
>   			return ret;
>   
> +		ret = regulator_bulk_enable(csiphy->num_supplies,
> +					    csiphy->supplies);
> +		if (ret < 0) {
> +			pm_runtime_put_sync(dev);
> +			return ret;
> +		}
> +
>   		ret = csiphy_set_clock_rates(csiphy);
>   		if (ret < 0) {
> +			regulator_bulk_disable(csiphy->num_supplies,
> +					       csiphy->supplies);
>   			pm_runtime_put_sync(dev);
>   			return ret;
>   		}
>   
>   		ret = camss_enable_clocks(csiphy->nclocks, csiphy->clock, dev);
>   		if (ret < 0) {
> +			regulator_bulk_disable(csiphy->num_supplies,
> +					       csiphy->supplies);
>   			pm_runtime_put_sync(dev);
>   			return ret;
>   		}
> @@ -234,6 +245,8 @@ static int csiphy_set_power(struct v4l2_subdev *sd, int on)
>   
>   		camss_disable_clocks(csiphy->nclocks, csiphy->clock);
>   
> +		regulator_bulk_disable(csiphy->num_supplies, csiphy->supplies);
> +
>   		pm_runtime_put_sync(dev);
>   	}
>   
> @@ -676,7 +689,27 @@ int msm_csiphy_subdev_init(struct camss *camss,
>   		}
>   	}
>   
> -	return 0;
> +	/* CSIPHY supplies */
> +	for (i = 0; i < ARRAY_SIZE(res->regulators); i++) {
> +		if (res->regulators[i])
> +			csiphy->num_supplies++;
> +	}
> +
> +	if (csiphy->num_supplies) {
> +		csiphy->supplies = devm_kmalloc_array(camss->dev,
> +						      csiphy->num_supplies,
> +						      sizeof(*csiphy->supplies),
> +						      GFP_KERNEL);
> +		if (!csiphy->supplies)
> +			return -ENOMEM;
> +	}
> +
> +	for (i = 0; i < csiphy->num_supplies; i++)
> +		csiphy->supplies[i].supply = res->regulators[i];
> +
> +	ret = devm_regulator_bulk_get(camss->dev, csiphy->num_supplies,
> +				      csiphy->supplies);
> +	return ret;
>   }
>   
>   /*
> diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/media/platform/qcom/camss/camss-csiphy.h
> index 47f0b6b09eba..eebc1ff1cfab 100644
> --- a/drivers/media/platform/qcom/camss/camss-csiphy.h
> +++ b/drivers/media/platform/qcom/camss/camss-csiphy.h
> @@ -91,6 +91,8 @@ struct csiphy_device {
>   	bool *rate_set;
>   	int nclocks;
>   	u32 timer_clk_rate;
> +	struct regulator_bulk_data *supplies;
> +	int num_supplies;
>   	struct csiphy_config cfg;
>   	struct v4l2_mbus_framefmt fmt[MSM_CSIPHY_PADS_NUM];
>   	const struct csiphy_subdev_resources *res;

I have verified this change on SM8550 board.

Tested-by: Depeng Shao <quic_depengs@quicinc.com> # SM8550

Thanks,
Depeng
diff mbox series

Patch

diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.c b/drivers/media/platform/qcom/camss/camss-csiphy.c
index 2f7361dfd461..68a3ea1ba2a5 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.c
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.c
@@ -212,14 +212,25 @@  static int csiphy_set_power(struct v4l2_subdev *sd, int on)
 		if (ret < 0)
 			return ret;
 
+		ret = regulator_bulk_enable(csiphy->num_supplies,
+					    csiphy->supplies);
+		if (ret < 0) {
+			pm_runtime_put_sync(dev);
+			return ret;
+		}
+
 		ret = csiphy_set_clock_rates(csiphy);
 		if (ret < 0) {
+			regulator_bulk_disable(csiphy->num_supplies,
+					       csiphy->supplies);
 			pm_runtime_put_sync(dev);
 			return ret;
 		}
 
 		ret = camss_enable_clocks(csiphy->nclocks, csiphy->clock, dev);
 		if (ret < 0) {
+			regulator_bulk_disable(csiphy->num_supplies,
+					       csiphy->supplies);
 			pm_runtime_put_sync(dev);
 			return ret;
 		}
@@ -234,6 +245,8 @@  static int csiphy_set_power(struct v4l2_subdev *sd, int on)
 
 		camss_disable_clocks(csiphy->nclocks, csiphy->clock);
 
+		regulator_bulk_disable(csiphy->num_supplies, csiphy->supplies);
+
 		pm_runtime_put_sync(dev);
 	}
 
@@ -676,7 +689,27 @@  int msm_csiphy_subdev_init(struct camss *camss,
 		}
 	}
 
-	return 0;
+	/* CSIPHY supplies */
+	for (i = 0; i < ARRAY_SIZE(res->regulators); i++) {
+		if (res->regulators[i])
+			csiphy->num_supplies++;
+	}
+
+	if (csiphy->num_supplies) {
+		csiphy->supplies = devm_kmalloc_array(camss->dev,
+						      csiphy->num_supplies,
+						      sizeof(*csiphy->supplies),
+						      GFP_KERNEL);
+		if (!csiphy->supplies)
+			return -ENOMEM;
+	}
+
+	for (i = 0; i < csiphy->num_supplies; i++)
+		csiphy->supplies[i].supply = res->regulators[i];
+
+	ret = devm_regulator_bulk_get(camss->dev, csiphy->num_supplies,
+				      csiphy->supplies);
+	return ret;
 }
 
 /*
diff --git a/drivers/media/platform/qcom/camss/camss-csiphy.h b/drivers/media/platform/qcom/camss/camss-csiphy.h
index 47f0b6b09eba..eebc1ff1cfab 100644
--- a/drivers/media/platform/qcom/camss/camss-csiphy.h
+++ b/drivers/media/platform/qcom/camss/camss-csiphy.h
@@ -91,6 +91,8 @@  struct csiphy_device {
 	bool *rate_set;
 	int nclocks;
 	u32 timer_clk_rate;
+	struct regulator_bulk_data *supplies;
+	int num_supplies;
 	struct csiphy_config cfg;
 	struct v4l2_mbus_framefmt fmt[MSM_CSIPHY_PADS_NUM];
 	const struct csiphy_subdev_resources *res;