clk: qcom: clk-rcg2: introduce support for multiple conf for same freq
Subsystems (3)
v3 cover clk: qcom: clk-rcg2: introduce support for multiple conf for same freq
This small series fix a current problem with ipq8074 where the 2 uniphy port doesn't work in some corner case with some clk configuration. The port to correctly work require a specific frequency, using the wrong one results in the port not transmitting data.
With the current code with a requested freq of 125MHz, the frequency is set to 105MHz. This is caused by the fact that there are 2 different configuration to set 125MHz and it's always selected the first one that results in 105MHz.
In the original QSDK code, the frequency configuration selection is different and the CEIL FLOOR logic is not present. Instead it's used a BEST approach where the frequency table is checked and then it's checked if there are duplicate entry.
This proposed implementation is more specific and keep the CEIL FLOOR logic while maitaining the possibility to provide multiple configuration.
The first 2 patch drop redundant F entry redefinition.
The 3rd and 4th one try to align rcg2 set rate to what clock core suggest by using just what determine_clock pass to clk core.
The 5th one implement the change with also some macro description on how this new implementation works. On determine the old v2 logic is used but for set the requested parent is used instead of researching.
The 6th one migrate the gcc-ipq8074 driver to this new implementation.
Changes v3:
- Add qcom_find_freq_exact
- Drop re-search on rcg2_set_rate
- Rework multiple conf patch to follow new implementation Changes v2:
- Out of RFC
- Fix compile warning from buildbot related to F redefinition
Christian Marangi (6):
clk: qcom: gcc-ipq6018: drop redundant F define
clk: qcom: gcc-sdm660: drop redundant F define
clk: qcom: common: add qcom_find_freq_exact
clk: qcom: clk-rcg2: don't re-search config on rcg2_set_rate
clk: qcom: clk-rcg2: introduce support for multiple conf for same freq
clk: qcom: gcc-ipq8074: rework nss_port5/6 clock to multiple conf
drivers/clk/qcom/clk-rcg.h | 14 +++- drivers/clk/qcom/clk-rcg2.c | 140 +++++++++++++++++++++++++++------ drivers/clk/qcom/common.c | 17 ++++ drivers/clk/qcom/common.h | 2 + drivers/clk/qcom/gcc-ipq6018.c | 2 - drivers/clk/qcom/gcc-ipq8074.c | 64 +++++++++++---- drivers/clk/qcom/gcc-sdm660.c | 2 - 7 files changed, 196 insertions(+), 45 deletions(-)
Signature · 1 line
2.38.1
PATCH v3 1/6 clk: qcom: gcc-ipq6018: drop redundant F define
The same exact F frequency table entry is defined in clk-rcg.h Drop the redundant define to cleanup code.
--- drivers/clk/qcom/gcc-ipq6018.c | 2 -- 1 file changed, 2 deletions(-)
drivers/clk/qcom/gcc-ipq6018.c +0 -2
@@ -26,8 +26,6 @@#include "clk-regmap-mux.h" #include "reset.h" -#define F (f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) } -enum {P_XO ,P_BIAS_PLL ,
Signature · 1 line
2.38.1
PATCH v3 2/6 clk: qcom: gcc-sdm660: drop redundant F define
In reply to Christian MarangiThe same exact F frequency table entry is defined in clk-rcg.h Drop the redundant define to cleanup code.
--- drivers/clk/qcom/gcc-sdm660.c | 2 -- 1 file changed, 2 deletions(-)
drivers/clk/qcom/gcc-sdm660.c +0 -2
@@ -25,8 +25,6 @@#include "reset.h" #include "gdsc.h" -#define F (f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) } -enum {P_XO ,P_SLEEP_CLK ,
Signature · 1 line
2.38.1
PATCH v3 3/6 clk: qcom: common: add qcom_find_freq_exact
In reply to Christian MarangiCurrently qcom_find_freq will always find a freq following a CEIL logic but we may need to find the exact requesting frequency or return NULL.
Add qcom_find_freq_exact to perform a search of the exact requested frequency.
--- drivers/clk/qcom/common.c | 17 +++++++++++++++++ drivers/clk/qcom/common.h | 2 ++ 2 files changed, 19 insertions(+)
drivers/clk/qcom/common.c +17 -0
@@ -57,6 +57,23 @@ const struct freq_tbl *qcom_find_freq_floor(const struct freq_tbl *f, }EXPORT_SYMBOL_GPL (qcom_find_freq_floor); +const +struct freq_tbl *qcom_find_freq_exact (const struct freq_tbl *f,unsigned long rate) +{ +if (!f) +return NULL ; + +if (!f->freq) +return f; + +for (; f->freq; f++) +if (rate == f->freq) +return f; + +return NULL ; +} +EXPORT_SYMBOL_GPL (qcom_find_freq_exact); +int qcom_find_src_index (struct clk_hw *hw,const struct parent_map *map,u8 src) {int i, num_parents =clk_hw_get_num_parents (hw);
drivers/clk/qcom/common.h +2 -0
@@ -45,6 +45,8 @@ extern const struct freq_tbl *qcom_find_freq(const struct freq_tbl *f, unsigned long rate);extern const struct freq_tbl *qcom_find_freq_floor (const struct freq_tbl *f,unsigned long rate); +extern const struct freq_tbl *qcom_find_freq_exact (const struct freq_tbl *f, +unsigned long rate);extern void qcom_pll_set_fsm_mode (struct regmap *m,u32 reg,u8 bias_count,u8 lock_count); extern int qcom_find_src_index(struct clk_hw *hw, const struct parent_map *map,
Signature · 1 line
2.38.1
PATCH v3 4/6 clk: qcom: clk-rcg2: don't re-search config on rcg2_set_rate
In reply to Christian MarangiCurrently the rcg2 driver search the rate to apply 2 times.
- In _freq_tbl_determine_rate for the determine_rate function used by core clk to understand the best rate to set with set_rate
- In rcg2_set_rate where the suggested rate is not trusted and searched another time using a CEIL or FLOOR policy.
This is fundamentally wrong as we are ignoring what core clock is deciding and just setting whatever clock configuration we want for the suggested clock. The problem is in the fact that the correct clock should have already be searched and selected with the determine_rate function and set_rate should just apply whatever clock was provided.
Rework the function using the find_req_exact and by trusting whatever core clk is asking to set.
--- drivers/clk/qcom/clk-rcg2.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/clk/qcom/clk-rcg2.c +6 -17
@@ -352,23 +352,12 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f)return update_config (rcg); } -static int __clk_rcg2_set_rate (struct clk_hw *hw,unsigned long rate, -enum freq_policy policy) +static int __clk_rcg2_set_rate (struct clk_hw *hw,unsigned long rate) {struct clk_rcg2 *rcg =to_clk_rcg2 (hw);const struct freq_tbl *f; -switch (policy) { -case FLOOR : - f =qcom_find_freq_floor (rcg->freq_tbl, rate); -break ; -case CEIL : - f =qcom_find_freq (rcg->freq_tbl, rate); -break ; -default : -return -EINVAL ; - } - + f =qcom_find_freq_exact (rcg->freq_tbl, rate);if (!f)return -EINVAL ;
@@ -378,25 +367,25 @@ static int __clk_rcg2_set_rate(struct clk_hw *hw, unsigned long rate,static int clk_rcg2_set_rate (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate) { -return __clk_rcg2_set_rate (hw, rate,CEIL ); +return __clk_rcg2_set_rate (hw, rate); }static int clk_rcg2_set_floor_rate (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate) { -return __clk_rcg2_set_rate (hw, rate,FLOOR ); +return __clk_rcg2_set_rate (hw, rate); }static int clk_rcg2_set_rate_and_parent (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate,u8 index) { -return __clk_rcg2_set_rate (hw, rate,CEIL ); +return __clk_rcg2_set_rate (hw, rate); }static int clk_rcg2_set_floor_rate_and_parent (struct clk_hw *hw,unsigned long rate,unsigned long parent_rate,u8 index) { -return __clk_rcg2_set_rate (hw, rate,FLOOR ); +return __clk_rcg2_set_rate (hw, rate); }static int clk_rcg2_get_duty_cycle (struct clk_hw *hw,struct clk_duty *duty)
Signature · 1 line
2.38.1
Stephen Boyd
maintainerRe: [PATCH v3 4/6] clk: qcom: clk-rcg2: don't re-search config on rcg2_set_rate
Quoting Christian Marangi (2023-01-17 05:54:57)
Quoted 11 lines
Currently the rcg2 driver search the rate to apply 2 times.
- In_freq_tbl_determine_ratefor thedetermine_ratefunction used by core clk to understand the best rate to set withset_rate
- Inrcg2_set_ratewhere the suggested rate is not trusted and searched another time using a CEIL or FLOOR policy.This is fundamentally wrong as we are ignoring what core clock is deciding and just setting whatever clock configuration we want for the suggested clock. The problem is in the fact that the correct clock should have already be searched and selected with the
determine_ratefunction andset_rateshould just apply whatever clock was provided.
It sounds like you're assuming the rate coming into the set_rate clk_op is rounded? Don't make that assumption. The set_rate clk_op should round the rate again. The parent rate could have changed.
Re: [PATCH v3 4/6] clk: qcom: clk-rcg2: don't re-search config on rcg2_set_rate
Quoted 13 lines · Stephen Boyd
Quoting Christian Marangi (2023-01-17 05:54:57)
Quoted 11 lines
Currently the rcg2 driver search the rate to apply 2 times.
- In_freq_tbl_determine_ratefor thedetermine_ratefunction used by core clk to understand the best rate to set withset_rate
- Inrcg2_set_ratewhere the suggested rate is not trusted and searched another time using a CEIL or FLOOR policy.This is fundamentally wrong as we are ignoring what core clock is deciding and just setting whatever clock configuration we want for the suggested clock. The problem is in the fact that the correct clock should have already be searched and selected with the
determine_ratefunction andset_rateshould just apply whatever clock was provided.
Quoted 3 lines
It sounds like you're assuming the rate coming into the
set_rateclk_opis rounded? Don't make that assumption. Theset_rateclk_opshould round the rate again. The parent rate could have changed.
My fault, I suggested this some time ago on the basis that... "CCF switching the parent rate during the clk_set_rate() call. Then the second lookup might end up selecting different parent/mnd configuration."
Signature · 2 lines
With best wishes Dmitry
PATCH v3 5/6 clk: qcom: clk-rcg2: introduce support for multiple conf for same freq
In reply to Christian MarangiSome RCG frequency can be reached by multiple configuration.
We currently declare multiple configuration for the same frequency but that is not supported and always the first configuration will be taken.
These multiple configuration are needed as based on the current parent configuration, it may be needed to use a different configuration to reach the same frequency.
To handle this introduce 2 new macro, FM and C.
- FM is used to declare an empty freq_tbl with just the frequency and an array of confs to insert all the config for the provided frequency.
- C is used to declare a freq_conf where src, pre_div, m and n are provided.
The driver is changed to handle this special freq_tbl and select the correct config by calculating the final rate and deciding based on the one that is less different than the requested one.
Function set_rate(_and_parent) will then select the config based on the current or the requested parent for the set_rate_and_parent variant.
--- drivers/clk/qcom/clk-rcg.h | 14 +++- drivers/clk/qcom/clk-rcg2.c | 129 ++++++++++++++++++++++++++++++++---- 2 files changed, 129 insertions(+), 14 deletions(-)
drivers/clk/qcom/clk-rcg.h +13 -1
@@ -7,7 +7,17 @@#include <linux/clk-provider.h> #include "clk-regmap.h" -#define F (f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n) } +#define F (f, s, h, m, n) { (f), (s), (2 * (h) - 1), (m), (n), 0, NULL } + +#define FM (_f, _confs) { .freq = (_f), .confs_num = ARRAY_SIZE(_confs), .confs = (_confs) } +#define C (s, h, m, n) { (s), (2 * (h) - 1), (m), (n) } + +struct freq_conf { +u8 src; +u8 pre_div; +u16 m; +u16 n; +};struct freq_tbl {unsigned long freq;
@@ -15,6 +25,8 @@ struct freq_tbl {u8 pre_div;u16 m;u16 n; +int confs_num; +const struct freq_conf *confs; };/**
drivers/clk/qcom/clk-rcg2.c +116 -13
199 lines not on this page · raw message
Signature · 1 line
2.38.1
Stephen Boyd
maintainerQuoting Christian Marangi (2023-01-17 05:54:58)
drivers/clk/qcom/clk-rcg.h struct freq_tbl { · line 29
Quoted 10 lines
drivers/clk/qcom/clk-rcg.h +2
-0@@ -15,6 +25,8 @@ struct freq_tbl {u8 pre_div;u16 m;u16 n; +int confs_num; +const struct freq_conf *confs;
This design is uncommon. I suggest you have a different clk_ops structure and/or entire clk_rcg (clk_rcg_fm?) that does things differently. Then we don't have to worry that all the other rcg2 clks (of which there are many) could be broken by this patch.
PATCH v3 6/6 clk: qcom: gcc-ipq8074: rework nss_port5/6 clock to multiple conf
In reply to Christian MarangiRework nss_port5/6 to use the new multiple configuration implementation and correctly fix the clocks for these port under some corner case.
This is particularly relevant for device that have 2.5G or 10G port connected to port5 or port 6 on ipq8074. As the parent are shared across multiple port it may be required to select the correct configuration to accomplish the desired clock. Without this patch such port doesn't work in some specific ethernet speed as the clock will be set to the wrong frequency as we just select the first configuration for the related frequency instead of selecting the best one.
--- drivers/clk/qcom/gcc-ipq8074.c | 64 +++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 16 deletions(-)
drivers/clk/qcom/gcc-ipq8074.c +48 -16
@@ -1787,13 +1787,21 @@ static struct clk_regmap_div nss_port4_tx_div_clk_src = { }, }; +static const struct freq_conf ftbl_nss_port5_rx_clk_src_25[] = { +C (P_UNIPHY1_RX ,12.5 ,0 ,0 ), +C (P_UNIPHY0_RX ,5 ,0 ,0 ), +}; + +static const struct freq_conf ftbl_nss_port5_rx_clk_src_125[] = { +C (P_UNIPHY1_RX ,2.5 ,0 ,0 ), +C (P_UNIPHY0_RX ,1 ,0 ,0 ), +}; +static const struct freq_tbl ftbl_nss_port5_rx_clk_src[] = {F (19200000 ,P_XO ,1 ,0 ,0 ), -F (25000000 ,P_UNIPHY1_RX ,12.5 ,0 ,0 ), -F (25000000 ,P_UNIPHY0_RX ,5 ,0 ,0 ), +FM (25000000 , ftbl_nss_port5_rx_clk_src_25),F (78125000 ,P_UNIPHY1_RX ,4 ,0 ,0 ), -F (125000000 ,P_UNIPHY1_RX ,2.5 ,0 ,0 ), -F (125000000 ,P_UNIPHY0_RX ,1 ,0 ,0 ), +FM (125000000 , ftbl_nss_port5_rx_clk_src_125),F (156250000 ,P_UNIPHY1_RX ,2 ,0 ,0 ),F (312500000 ,P_UNIPHY1_RX ,1 ,0 ,0 ), { }
@@ -1829,13 +1837,21 @@ static struct clk_regmap_div nss_port5_rx_div_clk_src = { }, }; +static struct freq_conf ftbl_nss_port5_tx_clk_src_25[] = { +C (P_UNIPHY1_TX ,12.5 ,0 ,0 ), +C (P_UNIPHY0_TX ,5 ,0 ,0 ), +}; + +static struct freq_conf ftbl_nss_port5_tx_clk_src_125[] = { +C (P_UNIPHY1_TX ,2.5 ,0 ,0 ), +C (P_UNIPHY0_TX ,1 ,0 ,0 ), +}; +static const struct freq_tbl ftbl_nss_port5_tx_clk_src[] = {F (19200000 ,P_XO ,1 ,0 ,0 ), -F (25000000 ,P_UNIPHY1_TX ,12.5 ,0 ,0 ), -F (25000000 ,P_UNIPHY0_TX ,5 ,0 ,0 ), +FM (25000000 , ftbl_nss_port5_tx_clk_src_25),F (78125000 ,P_UNIPHY1_TX ,4 ,0 ,0 ), -F (125000000 ,P_UNIPHY1_TX ,2.5 ,0 ,0 ), -F (125000000 ,P_UNIPHY0_TX ,1 ,0 ,0 ), +FM (125000000 , ftbl_nss_port5_tx_clk_src_125),F (156250000 ,P_UNIPHY1_TX ,2 ,0 ,0 ),F (312500000 ,P_UNIPHY1_TX ,1 ,0 ,0 ), { }
@@ -1871,13 +1887,21 @@ static struct clk_regmap_div nss_port5_tx_div_clk_src = { }, }; +static struct freq_conf ftbl_nss_port6_rx_clk_src_25[] = { +C (P_UNIPHY2_RX ,5 ,0 ,0 ), +C (P_UNIPHY2_RX ,12.5 ,0 ,0 ), +}; + +static struct freq_conf ftbl_nss_port6_rx_clk_src_125[] = { +C (P_UNIPHY2_RX ,1 ,0 ,0 ), +C (P_UNIPHY2_RX ,2.5 ,0 ,0 ), +}; +static const struct freq_tbl ftbl_nss_port6_rx_clk_src[] = {F (19200000 ,P_XO ,1 ,0 ,0 ), -F (25000000 ,P_UNIPHY2_RX ,5 ,0 ,0 ), -F (25000000 ,P_UNIPHY2_RX ,12.5 ,0 ,0 ), +FM (25000000 , ftbl_nss_port6_rx_clk_src_25),F (78125000 ,P_UNIPHY2_RX ,4 ,0 ,0 ), -F (125000000 ,P_UNIPHY2_RX ,1 ,0 ,0 ), -F (125000000 ,P_UNIPHY2_RX ,2.5 ,0 ,0 ), +FM (125000000 , ftbl_nss_port6_rx_clk_src_125),F (156250000 ,P_UNIPHY2_RX ,2 ,0 ,0 ),F (312500000 ,P_UNIPHY2_RX ,1 ,0 ,0 ), { }
@@ -1913,13 +1937,21 @@ static struct clk_regmap_div nss_port6_rx_div_clk_src = { }, }; +static struct freq_conf ftbl_nss_port6_tx_clk_src_25[] = { +C (P_UNIPHY2_TX ,5 ,0 ,0 ), +C (P_UNIPHY2_TX ,12.5 ,0 ,0 ), +}; + +static struct freq_conf ftbl_nss_port6_tx_clk_src_125[] = { +C (P_UNIPHY2_TX ,1 ,0 ,0 ), +C (P_UNIPHY2_TX ,2.5 ,0 ,0 ), +}; +static const struct freq_tbl ftbl_nss_port6_tx_clk_src[] = {F (19200000 ,P_XO ,1 ,0 ,0 ), -F (25000000 ,P_UNIPHY2_TX ,5 ,0 ,0 ), -F (25000000 ,P_UNIPHY2_TX ,12.5 ,0 ,0 ), +FM (25000000 , ftbl_nss_port6_tx_clk_src_25),F (78125000 ,P_UNIPHY2_TX ,4 ,0 ,0 ), -F (125000000 ,P_UNIPHY2_TX ,1 ,0 ,0 ), -F (125000000 ,P_UNIPHY2_TX ,2.5 ,0 ,0 ), +FM (125000000 , ftbl_nss_port6_tx_clk_src_125),F (156250000 ,P_UNIPHY2_TX ,2 ,0 ,0 ),F (312500000 ,P_UNIPHY2_TX ,1 ,0 ,0 ), { }
Signature · 1 line
2.38.1