Add divisor computation feature for sdm845 gp clocks
Subsystems (3)
v5 cover Add divisor computation feature for sdm845 gp clocks
SDM845 has "General Purpose" clocks that can be muxed to SoC pins to clock various external devices.
Those clocks may be used as e.g. PWM sources for external peripherals.
GPCLK can in theory have arbitrary value depending on the use case, so the concept of frequency tables, used in rcg2 clock driver, is not efficient, because it allows only defined frequencies.
Introduce clk_rcg2_gp_ops, which automatically calculate clock mnd values for arbitrary clock rate. The calculation done as follows:
- upon determine rate request, we calculate m/n/pre_div as follows:
- find parent(from our client's assigned-clock-parent) rate
- find scaled rates by dividing rates on its greatest common divisor
- assign requested scaled rate to m
- factorize scaled parent rate, put multipliers to n till max value (determined by mnd_width)
- validate calculated values with *_width:
- if doesn't fit, delete divisor and multiplier by 2 until fit
- return determined rate
Limitations:
- The driver doesn't select a parent clock (it may be selected by client in device tree with assigned-clocks, assigned-clock-parents properties)
---
Changes in v5:
- Split patchset per subsystem
- Link to v4: https://lore.kernel.org/r/20240913-starqltechn_integration_upstream-v4-0-2d2efd5c5877@gmail.com
Changes in v4:
- Replace gcc-845 freq_tbl frequencies patch with new approach,
based on automatic m/n/pre_div value generation
- Link to v3: https://lore.kernel.org/r/20240618-starqltechn_integration_upstream-v3-0-e3f6662017ac@gmail.com
---
Dzmitry Sankouski (2):
clk: qcom: clk-rcg2: document calc_rate function
gcc-sdm845: Add general purpose clock ops
drivers/clk/qcom/clk-rcg.h | 1 + drivers/clk/qcom/clk-rcg2.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- drivers/clk/qcom/gcc-sdm845.c | 11 ++---- 3 files changed, 198 insertions(+), 15 deletions(-)
---
base-commit: 92fc9636d1471b7f68bfee70c776f7f77e747b97
change-id: 20240617-starqltechn_integration_upstream-bc86850b2fe3
Best regards,
Signature · 1 line
Dzmitry Sankouski <[email protected]>
PATCH v5 1/2 clk: qcom: clk-rcg2: document calc_rate function
Update calc_rate docs to reflect, that pre_div
is not pure divisor, but a register value, and requires conversion.
--- drivers/clk/qcom/clk-rcg2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/clk/qcom/clk-rcg2.c +8 -1
@@ -153,7 +153,14 @@ static int clk_rcg2_set_parent(struct clk_hw *hw, u8 index)* * parent_rate m * rate = ----------- x --- -* hid_div n +* pre_div n +* +* @param rate - Parent rate. +* @param m - Multiplier. +* @param n - Divisor. +* @param mode - Use zero to ignore m/n calculation. +* @param hid_div - Pre divisor register value. Pre divisor value +* relates to hid_div as pre_div = (hid_div + 1) / 2 */ static unsigned long calc_rate (unsigned long rate,u32 m,u32 n,u32 mode,u32 hid_div)
Signature · 1 line
2.39.2
PATCH v5 2/2 gcc-sdm845: Add general purpose clock ops
In reply to Dzmitry SankouskiSDM845 has "General Purpose" clocks that can be muxed to SoC pins to clock various external devices.
Those clocks may be used as e.g. PWM sources for external peripherals.
GPCLK can in theory have arbitrary value depending on the use case, so the concept of frequency tables, used in rcg2 clock driver, is not efficient, because it allows only defined frequencies.
Introduce clk_rcg2_gp_ops, which automatically calculate clock mnd values for arbitrary clock rate. The calculation done as follows:
- upon determine rate request, we calculate m/n/pre_div as follows:
- find parent(from our client's assigned-clock-parent) rate
- find scaled rates by dividing rates on its greatest common divisor
- assign requested scaled rate to m
- factorize scaled parent rate, put multipliers to n till max value (determined by mnd_width)
- validate calculated values with *_width:
- if doesn't fit, delete divisor and multiplier by 2 until fit
- return determined rate
Limitations:
- The driver doesn't select a parent clock (it may be selected by client in device tree with assigned-clocks, assigned-clock-parents properties)
---
Changes in v5:
- replace '/' to div64_u64 to fix 32 bit gcc error
- fix empty scalar initializer
--- drivers/clk/qcom/clk-rcg.h | 1 + drivers/clk/qcom/clk-rcg2.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- drivers/clk/qcom/gcc-sdm845.c | 11 ++---- 3 files changed, 190 insertions(+), 14 deletions(-)
drivers/clk/qcom/clk-rcg.h +1 -0
@@ -189,6 +189,7 @@ struct clk_rcg2_gfx3d { container_of(to_clk_rcg2(_hw), struct clk_rcg2_gfx3d, rcg)extern const struct clk_ops clk_rcg2_ops; +extern const struct clk_ops clk_rcg2_gp_ops;extern const struct clk_ops clk_rcg2_floor_ops;extern const struct clk_ops clk_rcg2_fm_ops;extern const struct clk_ops clk_rcg2_mux_closest_ops;
drivers/clk/qcom/clk-rcg2.c +186 -6
258 lines not on this page · raw message
drivers/clk/qcom/gcc-sdm845.c +3 -8
@@ -284,11 +284,6 @@ static struct clk_rcg2 gcc_sdm670_cpuss_rbcpr_clk_src = { };static const struct freq_tbl ftbl_gcc_gp1_clk_src[] = { -F (19200000 ,P_BI_TCXO ,1 ,0 ,0 ), -F (25000000 ,P_GPLL0_OUT_EVEN ,12 ,0 ,0 ), -F (50000000 ,P_GPLL0_OUT_EVEN ,6 ,0 ,0 ), -F (100000000 ,P_GPLL0_OUT_MAIN ,6 ,0 ,0 ), -F (200000000 ,P_GPLL0_OUT_MAIN ,3 ,0 ,0 ), { } };
@@ -302,7 +297,7 @@ static struct clk_rcg2 gcc_gp1_clk_src = { .name = "gcc_gp1_clk_src", .parent_data = gcc_parent_data_1, .num_parents = ARRAY_SIZE(gcc_parent_data_1), - .ops = &clk_rcg2_ops, + .ops = &clk_rcg2_gp_ops, }, };
@@ -316,7 +311,7 @@ static struct clk_rcg2 gcc_gp2_clk_src = { .name = "gcc_gp2_clk_src", .parent_data = gcc_parent_data_1, .num_parents = ARRAY_SIZE(gcc_parent_data_1), - .ops = &clk_rcg2_ops, + .ops = &clk_rcg2_gp_ops, }, };
@@ -330,7 +325,7 @@ static struct clk_rcg2 gcc_gp3_clk_src = { .name = "gcc_gp3_clk_src", .parent_data = gcc_parent_data_1, .num_parents = ARRAY_SIZE(gcc_parent_data_1), - .ops = &clk_rcg2_ops, + .ops = &clk_rcg2_gp_ops, }, };
Signature · 1 line
2.39.2
kernel test robot
build botRe: [PATCH v5 2/2] gcc-sdm845: Add general purpose clock ops
kernel test robot noticed the following build warnings:
Hi Dzmitry,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 92fc9636d1471b7f68bfee70c776f7f77e747b97]
url: https://github.com/intel-lab-lkp/linux/commits/Dzmitry-Sankouski/clk-qcom-clk-rcg2-document-calc_rate-function/20240926-184051 base: 92fc9636d1471b7f68bfee70c776f7f77e747b97 patch link: https://lore.kernel.org/r/20240617-starqltechn_integration_upstream-v5-2-761795ea5084%40gmail.com patch subject: [PATCH v5 2/2] gcc-sdm845: Add general purpose clock ops config: i386-buildonly-randconfig-006-20240929 (https://download.01.org/0day-ci/archive/20240929/[email protected]/config) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240929/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/clk/qcom/clk-rcg2.c:431:13: warning: variable 'count' set but not used [-Wunused-but-set-variable]
431 | int i = 2, count = 0;
| ^1 warning generated.
vim +/count +431 drivers/clk/qcom/clk-rcg2.c
427
428 static void clk_rcg2_calc_mnd(u64 parent_rate, u64 rate, struct freq_tbl *f,
429 unsigned int mnd_max, unsigned int pre_div_max)
430 {
> 431 int i = 2, count = 0;
432 unsigned int pre_div = 1;
433 unsigned long rates_gcd, scaled_parent_rate;
434 u16 m, n = 1, n_candidate = 1, n_max;
435
436 rates_gcd = gcd(parent_rate, rate);
437 m = div64_u64(rate, rates_gcd);
438 scaled_parent_rate = div64_u64(parent_rate, rates_gcd);
439 while (scaled_parent_rate > (mnd_max + m) * pre_div_max) {
440 // we're exceeding divisor's range, trying lower scale.
441 if (m > 1) {
442 m--;
443 scaled_parent_rate = mult_frac(scaled_parent_rate, m, (m + 1));
444 } else {
445 f->n = mnd_max + m;
446 f->pre_div = pre_div_max;
447 f->m = m;
448 }
449 }
450
451 n_max = m + mnd_max;
452
453 while (scaled_parent_rate > 1) {
454 while (scaled_parent_rate % i == 0) {
455 n_candidate *= i;
456 if (n_candidate < n_max)
457 n = n_candidate;
458 else if (pre_div * i < pre_div_max)
459 pre_div *= i;
460 else
461 clk_rcg2_split_div(i, &pre_div, &n, pre_div_max);
462
463 scaled_parent_rate /= i;
464 }
465 i++;
466 count++;
467 }
468
469 f->m = m;
470 f->n = n;
471 f->pre_div = pre_div > 1 ? pre_div : 0;
472 }
473
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki