Skip to contentSkip to conversation

clk: qcom: clk-rcg2: Update logic to calculate D value for RCG

PATCH Superseded Taniya Das 2 participants 4 messages Feb 2, 2022 – Feb 17, 2022

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Taniya Das

author
#0 lore raw

PATCH v2 1/2 clk: qcom: clk-rcg2: Update logic to calculate D value for RCG

The current implementation does not check for D value is within the accepted range for a given M & N value. Update the logic to calculate the final D value based on the range.

Fixes 99cbd064b059f ("clk: qcom: Support display RCG clocks")

---
* Split the patch and update the Fixes tag.

 drivers/clk/qcom/clk-rcg2.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/clk/qcom/clk-rcg2.c +12 -2
index e1b1b426fae4..34251ec98def 100644
@@ -264,7 +264,7 @@ static int clk_rcg2_determine_floor_rate(struct clk_hw *hw,
 
 static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
 {
-	u32 cfg, mask;
+	u32 cfg, mask, d_val, not2d_val;
 	struct clk_hw *hw = &rcg->clkr.hw;
 	int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
 
@@ -283,8 +283,18 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
 		if (ret)
 			return ret;
 
+		/* Calculate 2d value */
+		d_val = f->n;
+
+		if (d_val > ((f->n - f->m) * 2))
+			d_val = (f->n - f->m) * 2;
+		else if (d_val < f->m)
+			d_val = f->m;
+
+		not2d_val = ~d_val & mask;
+
 		ret = regmap_update_bits(rcg->clkr.regmap,
-				RCG_D_OFFSET(rcg), mask, ~f->n);
+				RCG_D_OFFSET(rcg), mask, not2d_val);
 		if (ret)
 			return ret;
 	}

--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member of the Code Aurora Forum, hosted by the Linux Foundation.

author
#1 lore raw

PATCH v2 2/2 clk: qcom: clk-rcg2: Update the frac table for pixel clock

Support the new numerator and denominator for pixel clock.

Fixes 99cbd064b059f ("clk: qcom: Support display RCG clocks")
---
 drivers/clk/qcom/clk-rcg2.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/qcom/clk-rcg2.c +1 -0
index 34251ec98def..036c8071c07a 100644
@@ -730,6 +730,7 @@ static const struct frac_entry frac_table_pixel[] = {
 	{ 2, 9 },
 	{ 4, 9 },
 	{ 1, 1 },
+	{ 2, 3 },
 	{ }
 };
 

--
Qualcomm INDIA, on behalf of Qualcomm Innovation Center, Inc.is a member of the Code Aurora Forum, hosted by the Linux Foundation.

maintainer Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] clk: qcom: clk-rcg2: Update the frac table for pixel clock

Quoting Taniya Das (2022-02-02 09:25:40)

Quoted 4 lines

Support the new numerator and denominator for pixel clock.

Fixes 99cbd064b059f ("clk: qcom: Support display RCG clocks")

I guess the previous patch is to make this patch work? Please mention that in the first patches commit text.

Quoted 1 line

---

maintainer
#3 lore raw
In reply to Taniya Das

Quoting Taniya Das (2022-02-02 09:25:39)

Quoted 3 lines

The current implementation does not check for D value is within the accepted range for a given M & N value. Update the logic to calculate the final D value based on the range.

Is this fixing any SoC that's supported now? Or is it future work? This is important to know if this needs to be merged this week or next merge window.

Quoted 23 lines
Fixes 99cbd064b059f ("clk: qcom: Support display RCG clocks")

---
* Split the patch and update the Fixes tag.

 drivers/clk/qcom/clk-rcg2.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/clk/qcom/clk-rcg2.c +1 -1
index e1b1b426fae4..34251ec98def 100644
@@ -264,7 +264,7 @@ static int clk_rcg2_determine_floor_rate(struct clk_hw *hw,
 
 static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
 {
-       u32 cfg, mask;
+       u32 cfg, mask, d_val, not2d_val;
        struct clk_hw *hw = &rcg->clkr.hw;
        int ret, index = qcom_find_src_index(hw, rcg->parent_map, f->src);
 

drivers/clk/qcom/clk-rcg2.c static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f) · line 289

Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +4 -0
@@ -283,8 +283,18 @@ static int __clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)
                if (ret)
                        return ret;
 
+               /* Calculate 2d value */
+               d_val = f->n;
+
+               if (d_val > ((f->n - f->m) * 2))

Please make another local variable for (f->n - f->m) * 2

	u32 n_minus_m;

	...

	n_minus_m = f->n - f->m;
	n_minus_m *= 2;

	d_val = clamp(d_val, f->m, n_minus_m);
	not2d_val = ~d_val & mask;

would be better than if else logic because the types are all verified to be compatible.

Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c +7 -1
+                       d_val = (f->n - f->m) * 2;
+               else if (d_val < f->m)
+                       d_val = f->m;
+
+               not2d_val = ~d_val & mask;
+
                ret = regmap_update_bits(rcg->clkr.regmap,
-                               RCG_D_OFFSET(rcg), mask, ~f->n);
+                               RCG_D_OFFSET(rcg), mask, not2d_val);
                if (ret)
                        return ret;