diff mbox series

[04/10] soc: qcom: icc-bwmon: store reference to varian data in container

Message ID 20220720192807.130098-5-krzysztof.kozlowski@linaro.org (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series soc/arm64: qcom: Add LLCC BWMON on SDM845 | expand

Commit Message

Krzysztof Kozlowski July 20, 2022, 7:28 p.m. UTC
Instead of copying pieces of variant-specific data (struct
icc_bwmon_data) into the state container (struct icc_bwmon), just store
a pointer to it.

This simplifies a bit the code and allows later to grow easily the
variant-specific data for new BWMON v5.

Cc: Rajendra Nayak <quic_rjendra@quicinc.com>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
---
 drivers/soc/qcom/icc-bwmon.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Sibi Sankar July 26, 2022, 11:28 a.m. UTC | #1
On 7/21/22 12:58 AM, Krzysztof Kozlowski wrote:
> Instead of copying pieces of variant-specific data (struct
> icc_bwmon_data) into the state container (struct icc_bwmon), just store
> a pointer to it.
> 
> This simplifies a bit the code and allows later to grow easily the
> variant-specific data for new BWMON v5.
> 
> Cc: Rajendra Nayak <quic_rjendra@quicinc.com>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Patch subject has a typo s/varian/variant

Reviewed-by: Sibi Sankar <quic_sibis@quicinc.com>
> ---
>   drivers/soc/qcom/icc-bwmon.c | 20 ++++++++------------
>   1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/soc/qcom/icc-bwmon.c b/drivers/soc/qcom/icc-bwmon.c
> index b76a59d9002c..93c3cec84721 100644
> --- a/drivers/soc/qcom/icc-bwmon.c
> +++ b/drivers/soc/qcom/icc-bwmon.c
> @@ -118,11 +118,10 @@ struct icc_bwmon_data {
>   
>   struct icc_bwmon {
>   	struct device *dev;
> +	const struct icc_bwmon_data *data;
>   	void __iomem *base;
>   	int irq;
>   
> -	unsigned int default_lowbw_kbps;
> -	unsigned int sample_ms;
>   	unsigned int max_bw_kbps;
>   	unsigned int min_bw_kbps;
>   	unsigned int target_kbps;
> @@ -199,20 +198,20 @@ static void bwmon_set_threshold(struct icc_bwmon *bwmon, unsigned int reg,
>   {
>   	unsigned int thres;
>   
> -	thres = mult_frac(bwmon_kbps_to_count(kbps), bwmon->sample_ms,
> +	thres = mult_frac(bwmon_kbps_to_count(kbps), bwmon->data->sample_ms,
>   			  MSEC_PER_SEC);
>   	writel_relaxed(thres, bwmon->base + reg);
>   }
>   
> -static void bwmon_start(struct icc_bwmon *bwmon,
> -			const struct icc_bwmon_data *data)
> +static void bwmon_start(struct icc_bwmon *bwmon)
>   {
> +	const struct icc_bwmon_data *data = bwmon->data;
>   	unsigned int thres_count;
>   	int window;
>   
>   	bwmon_clear_counters(bwmon);
>   
> -	window = mult_frac(bwmon->sample_ms, HW_TIMER_HZ, MSEC_PER_SEC);
> +	window = mult_frac(bwmon->data->sample_ms, HW_TIMER_HZ, MSEC_PER_SEC);
>   	/* Maximum sampling window: 0xfffff */
>   	writel_relaxed(window, bwmon->base + BWMON_SAMPLE_WINDOW);
>   
> @@ -267,7 +266,7 @@ static irqreturn_t bwmon_intr(int irq, void *dev_id)
>   	 */
>   	max = readl(bwmon->base + BWMON_ZONE_MAX(zone)) + 1;
>   	max *= BWMON_COUNT_UNIT_KB;
> -	bwmon->target_kbps = mult_frac(max, MSEC_PER_SEC, bwmon->sample_ms);
> +	bwmon->target_kbps = mult_frac(max, MSEC_PER_SEC, bwmon->data->sample_ms);
>   
>   	return IRQ_WAKE_THREAD;
>   }
> @@ -329,14 +328,13 @@ static int bwmon_probe(struct platform_device *pdev)
>   	struct device *dev = &pdev->dev;
>   	struct dev_pm_opp *opp;
>   	struct icc_bwmon *bwmon;
> -	const struct icc_bwmon_data *data;
>   	int ret;
>   
>   	bwmon = devm_kzalloc(dev, sizeof(*bwmon), GFP_KERNEL);
>   	if (!bwmon)
>   		return -ENOMEM;
>   
> -	data = of_device_get_match_data(dev);
> +	bwmon->data = of_device_get_match_data(dev);
>   
>   	bwmon->base = devm_platform_ioremap_resource(pdev, 0);
>   	if (IS_ERR(bwmon->base)) {
> @@ -364,8 +362,6 @@ static int bwmon_probe(struct platform_device *pdev)
>   	if (IS_ERR(opp))
>   		return dev_err_probe(dev, ret, "failed to find min peak bandwidth\n");
>   
> -	bwmon->sample_ms = data->sample_ms;
> -	bwmon->default_lowbw_kbps = data->default_lowbw_kbps;
>   	bwmon->dev = dev;
>   
>   	bwmon_disable(bwmon);
> @@ -376,7 +372,7 @@ static int bwmon_probe(struct platform_device *pdev)
>   		return dev_err_probe(dev, ret, "failed to request IRQ\n");
>   
>   	platform_set_drvdata(pdev, bwmon);
> -	bwmon_start(bwmon, data);
> +	bwmon_start(bwmon);
>   
>   	return 0;
>   }
>
diff mbox series

Patch

diff --git a/drivers/soc/qcom/icc-bwmon.c b/drivers/soc/qcom/icc-bwmon.c
index b76a59d9002c..93c3cec84721 100644
--- a/drivers/soc/qcom/icc-bwmon.c
+++ b/drivers/soc/qcom/icc-bwmon.c
@@ -118,11 +118,10 @@  struct icc_bwmon_data {
 
 struct icc_bwmon {
 	struct device *dev;
+	const struct icc_bwmon_data *data;
 	void __iomem *base;
 	int irq;
 
-	unsigned int default_lowbw_kbps;
-	unsigned int sample_ms;
 	unsigned int max_bw_kbps;
 	unsigned int min_bw_kbps;
 	unsigned int target_kbps;
@@ -199,20 +198,20 @@  static void bwmon_set_threshold(struct icc_bwmon *bwmon, unsigned int reg,
 {
 	unsigned int thres;
 
-	thres = mult_frac(bwmon_kbps_to_count(kbps), bwmon->sample_ms,
+	thres = mult_frac(bwmon_kbps_to_count(kbps), bwmon->data->sample_ms,
 			  MSEC_PER_SEC);
 	writel_relaxed(thres, bwmon->base + reg);
 }
 
-static void bwmon_start(struct icc_bwmon *bwmon,
-			const struct icc_bwmon_data *data)
+static void bwmon_start(struct icc_bwmon *bwmon)
 {
+	const struct icc_bwmon_data *data = bwmon->data;
 	unsigned int thres_count;
 	int window;
 
 	bwmon_clear_counters(bwmon);
 
-	window = mult_frac(bwmon->sample_ms, HW_TIMER_HZ, MSEC_PER_SEC);
+	window = mult_frac(bwmon->data->sample_ms, HW_TIMER_HZ, MSEC_PER_SEC);
 	/* Maximum sampling window: 0xfffff */
 	writel_relaxed(window, bwmon->base + BWMON_SAMPLE_WINDOW);
 
@@ -267,7 +266,7 @@  static irqreturn_t bwmon_intr(int irq, void *dev_id)
 	 */
 	max = readl(bwmon->base + BWMON_ZONE_MAX(zone)) + 1;
 	max *= BWMON_COUNT_UNIT_KB;
-	bwmon->target_kbps = mult_frac(max, MSEC_PER_SEC, bwmon->sample_ms);
+	bwmon->target_kbps = mult_frac(max, MSEC_PER_SEC, bwmon->data->sample_ms);
 
 	return IRQ_WAKE_THREAD;
 }
@@ -329,14 +328,13 @@  static int bwmon_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct dev_pm_opp *opp;
 	struct icc_bwmon *bwmon;
-	const struct icc_bwmon_data *data;
 	int ret;
 
 	bwmon = devm_kzalloc(dev, sizeof(*bwmon), GFP_KERNEL);
 	if (!bwmon)
 		return -ENOMEM;
 
-	data = of_device_get_match_data(dev);
+	bwmon->data = of_device_get_match_data(dev);
 
 	bwmon->base = devm_platform_ioremap_resource(pdev, 0);
 	if (IS_ERR(bwmon->base)) {
@@ -364,8 +362,6 @@  static int bwmon_probe(struct platform_device *pdev)
 	if (IS_ERR(opp))
 		return dev_err_probe(dev, ret, "failed to find min peak bandwidth\n");
 
-	bwmon->sample_ms = data->sample_ms;
-	bwmon->default_lowbw_kbps = data->default_lowbw_kbps;
 	bwmon->dev = dev;
 
 	bwmon_disable(bwmon);
@@ -376,7 +372,7 @@  static int bwmon_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, ret, "failed to request IRQ\n");
 
 	platform_set_drvdata(pdev, bwmon);
-	bwmon_start(bwmon, data);
+	bwmon_start(bwmon);
 
 	return 0;
 }