Misc patches to support clocks for SDM845
v5 cover Misc patches to support clocks for SDM845
Changes in v5:
1. Adressed review comments for v3 and v4 version of GCC driver for SDM845
https://lkml.org/lkml/2018/4/16/1129
2. Removed bi_tcxo clock being modelled from the GCC driver, as RPMH clock driver would provide the same. https://lkml.org/lkml/2018/4/13/685
3. The GCC clock driver(patch 2) depends upon the below patches related to GDSC operation and RPMh clock driver, which are under review.
https://lkml.org/lkml/2018/4/2/143
https://lkml.org/lkml/2018/4/13/685
Changes in v4:
1. Adressed review comments for v2 version of GCC driver for SDM845
https://lkml.org/lkml/2018/4/9/55.
2. The GCC clock driver(patch 3) depends upon the below patches related to GDSC operation and are under review.
https://lkml.org/lkml/2018/4/2/142
Changes in v3:
1. Adressed review comments given for v2 series.
2. The GCC clock driver(patch 3) depends upon the below patches related to GDSC operation and are under review.
https://lkml.org/lkml/2018/4/2/142
Changes in v2:
Fixup for recalc_rate ops for clk_rcg2_shared_ops:
There could be few scenarios where shared clocks are configured at rate other than CXO by boot. In those cases there would be a mismatch between the rate calculated by the recalc shared ops and the actual HW register configuration. Fix the same by adding an additional check to read current src from CFG register and make a decision based on that.
Changes in v1:
https://lkml.org/lkml/2018/1/31/209
This patch series does the miscellaneous changes to support clock nodes for SDM845. Below are the major changes for which the existing code does not have support.
1. Clear hardware clock control bit of RCGs where HW clock control bit is set by default so that software can control those root clocks.
2. Introduces clk_rcg2_shared_ops to support clock controller drivers for SDM845. With new shared ops, RCGs with shared branches will be configured to a safe source in disable path and actual RCG update configuration will be done in enable path instead of doing config update in set_rate. In set_rate(), just cache the rate instead of doing actual configuration update. Also each RCG in clock controller driver will have their own safe configuration frequency table to switch to safe frequency.
3. Add support for controlling Fabia PLL for which the support is not available in existing alpha PLL code.
4. Add Global Clock controller (GCC) driver for SDM845. This should allow most non-multimedia device drivers to probe and control their clocks.
[v1] : https://lkml.org/lkml/2018/1/31/209
[v2] : https://lkml.org/lkml/2018/3/8/495
[v3] : https://www.spinics.net/lists/linux-arm-msm/msg35009.html
[v4] : https://lkml.org/lkml/2018/4/9/79
Amit Nischal (1):
clk: qcom: Configure the RCGs to a safe source as needed
Taniya Das (1):
clk: qcom: Add Global Clock controller (GCC) driver for SDM845
.../devicetree/bindings/clock/qcom,gcc.txt | 1 + drivers/clk/qcom/Kconfig | 9 + drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/clk-rcg.h | 7 +- drivers/clk/qcom/clk-rcg2.c | 173 +- drivers/clk/qcom/gcc-sdm845.c | 3456 ++++++++++++++++++++ include/dt-bindings/clock/qcom,gcc-sdm845.h | 237 ++ 7 files changed, 3882 insertions(+), 2 deletions(-) create mode 100644 drivers/clk/qcom/gcc-sdm845.c create mode 100644 include/dt-bindings/clock/qcom,gcc-sdm845.h
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v5 1/2 clk: qcom: Configure the RCGs to a safe source as needed
For some root clock generators, there could be child branches which are controlled by an entity other than application processor subsystem. For such RCGs, as per application processor subsystem clock driver, all of its downstream clocks are disabled and RCG is in disabled state but in reality downstream clocks can be left enabled before.
So in this scenario, when RCG is disabled as per clock driver's point of view and when rate scaling request comes before downstream clock enable request, then RCG fails to update its configuration because in reality RCG is on and it expects its new source to alredy be in enable state but in reality new source is off. In order to avoid having the RCG to go into an invalid state, add support to cache the rate of RCG during set_rate(), defer actual RCG configuration update to be done during clk_enable() as at this point of time, both its new parent and safe source will be already enabled and RCG can safely switch to new parent.
During clk_disable() request, configure it to safe source as both its parents, safe source and current parent will be enabled and RCG can safely execute a switch. Also add support to have safe configuration frequency table structure for each shared RCG.
--- drivers/clk/qcom/clk-rcg.h | 7 +- drivers/clk/qcom/clk-rcg2.c | 173 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 178 insertions(+), 2 deletions(-)
drivers/clk/qcom/clk-rcg.h +6 -1
@@ -1,5 +1,5 @@/* -* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and
@@ -144,8 +144,10 @@ struct clk_dyn_rcg {* @cmd_rcgr: corresponds to *_CMD_RCGR * @mnd_width: number of bits in m/n/d values * @hid_width: number of bits in half integer divider +* @safe_src_index: safe src index value * @parent_map: map from software's parent index to hardware's src_sel field * @freq_tbl: frequency table +* @current_freq: last cached frequency when using branches with shared RCGs * @clkr: regmap clock handle * */
@@ -153,8 +155,10 @@ struct clk_rcg2 {u32 cmd_rcgr;u8 mnd_width;u8 hid_width; +const u8 safe_src_index;const struct parent_map *parent_map;const struct freq_tbl *freq_tbl; +unsigned long current_freq;struct clk_regmap clkr; };
@@ -167,5 +171,6 @@ struct clk_rcg2 {extern const struct clk_ops clk_byte2_ops;extern const struct clk_ops clk_pixel_ops;extern const struct clk_ops clk_gfx3d_ops; +extern const struct clk_ops clk_rcg2_shared_ops;#endif
drivers/clk/qcom/clk-rcg2.c +172 -1
180 lines not on this page · raw message
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v5 2/2 clk: qcom: Add Global Clock controller (GCC) driver for SDM845
In reply to Amit NischalFrom: Taniya Das <[email protected]>
Add support for the global clock controller found on SDM845 based devices. This should allow most non-multimedia device drivers to probe and control their clocks.
--- .../devicetree/bindings/clock/qcom,gcc.txt | 1 + drivers/clk/qcom/Kconfig | 9 + drivers/clk/qcom/Makefile | 1 + drivers/clk/qcom/gcc-sdm845.c | 3456 ++++++++++++++++++++ include/dt-bindings/clock/qcom,gcc-sdm845.h | 237 ++ 5 files changed, 3704 insertions(+) create mode 100644 drivers/clk/qcom/gcc-sdm845.c create mode 100644 include/dt-bindings/clock/qcom,gcc-sdm845.h
Documentation/devicetree/bindings/clock/qcom,gcc.txt +1 -0
@@ -18,6 +18,7 @@ Required properties : "qcom,gcc-msm8994" "qcom,gcc-msm8996" "qcom,gcc-mdm9615" + "qcom,gcc-sdm845" - reg : shall contain base register location and length - #clock-cells : shall contain 1
drivers/clk/qcom/Kconfig +9 -0
@@ -218,6 +218,15 @@ config MSM_MMCC_8996 Say Y if you want to support multimedia devices such as display, graphics, video encode/decode, camera, etc. +config SDM_GCC_845 + tristate "SDM845 Global Clock Controller" + depends on COMMON_CLK_QCOM + help + Support for the global clock controller on Qualcomm Technologies, Inc + sdm845 devices. + Say Y if you want to use peripheral devices such as UART, SPI, + I2C, USB, UFS, SDDC, PCIe, etc. + config SPMI_PMIC_CLKDIV tristate "SPMI PMIC clkdiv Support" depends on (COMMON_CLK_QCOM && SPMI) || COMPILE_TEST
drivers/clk/qcom/Makefile +1 -0
@@ -37,4 +37,5 @@ obj-$(CONFIG_QCOM_A53PLL) += a53-pll.o obj-$(CONFIG_QCOM_CLK_APCS_MSM8916) += apcs-msm8916.o obj-$(CONFIG_QCOM_CLK_RPM) += clk-rpm.o obj-$(CONFIG_QCOM_CLK_SMD_RPM) += clk-smd-rpm.o +obj-$(CONFIG_SDM_GCC_845) += gcc-sdm845.o obj-$(CONFIG_SPMI_PMIC_CLKDIV) += clk-spmi-pmic-div.o
drivers/clk/qcom/gcc-sdm845.c new file +3456 -0
2,973 lines not on this page · raw message
include/dt-bindings/clock/qcom,gcc-sdm845.h new file +237 -0
237 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Part of the diff is not shown here. View the raw message.
Stephen Boyd
maintainerRe: [PATCH v5 1/2] clk: qcom: Configure the RCGs to a safe source as needed
In reply to Amit NischalQuoting Amit Nischal (2018-04-18 06:34:32)
drivers/clk/qcom/clk-rcg.h struct clk_rcg2 { · line 158
Quoted 9 lines
drivers/clk/qcom/clk-rcg.h +1
-0@@ -153,8 +155,10 @@ struct clk_rcg2 {u32 cmd_rcgr;u8 mnd_width;u8 hid_width; +const u8 safe_src_index;
Please drop const.
Quoted 13 lines
drivers/clk/qcom/clk-rcg.h +1
-0const struct parent_map *parent_map;const struct freq_tbl *freq_tbl; +unsigned long current_freq;struct clk_regmap clkr; };drivers/clk/qcom/clk-rcg2.c +3
-0+ +static int clk_rcg2_shared_set_rate (struct clk_hw *hw,unsigned long rate, +unsigned long parent_rate)
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 857
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +int ret; + +/* +* Return if the RCG is currently disabled. This configuration +* update will happen as part of the RCG enable sequence. +*/ +if (!__clk_is_enabled (hw->clk)) { + rcg->current_freq = rate;
We should probably check that 'rate' can be achieved during clk_set_rate() though. So I imagine we would need to do all the rounding, etc. and then cache the frequency at that point. Or cross fingers that this set rate op is never called without the round_rate op being called on it too.
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 866
Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c +9
-0+return 0 ; + } + + ret =clk_rcg2_shared_force_enable_clear (hw, rate); +if (ret) +return ret; + +/* Update current frequency with the requested frequency. */ + rcg->current_freq = rate;
Is this even needed? recalc_rate() would be called shortly after and do this too.
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 874
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +8
-0+ +return ret; +} + +static int clk_rcg2_shared_set_rate_and_parent (struct clk_hw *hw, +unsigned long rate,unsigned long parent_rate,u8 index) +{ +return clk_rcg2_shared_set_rate (hw, rate, parent_rate);
We lost index. I guess that's OK...
Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+} +
[...]
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 893
Quoted 7 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+ +static unsigned long clk_rcg2_get_safe_src_rate (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +int index; + + index =qcom_find_src_index (hw, rcg->parent_map, rcg->safe_src_index);
Why are we finding it though? Can't we just set the bit to be what it's supposed to be all the time at compile time instead of going through the parent map to find the register value?
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 897
Quoted 4 lines
drivers/clk/qcom/clk-rcg2.c +4
-0+if (index <0 ) + index =0 ; + +return clk_hw_get_rate (clk_hw_get_parent_by_index (hw, index));
I'm still failing to see why the 'rate' is so important for the safe source.
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 907
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+} + +static int clk_rcg2_shared_enable (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +struct freq_tbl safe_src_freq_tbl = {0 }; + + safe_src_freq_tbl.freq =clk_rcg2_get_safe_src_rate (hw); + +if (rcg->current_freq == safe_src_freq_tbl.freq) {
I'd prefer this became a bool condition like rcg->on_safe_src or something like that, instead of calculating the safe src frequency and comparing that to whatever recalc_rate saw.
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 913
Quoted 6 lines
drivers/clk/qcom/clk-rcg2.c +6
-0+ safe_src_freq_tbl.src = rcg->safe_src_index; +/* +* Reconfigure the RCG - Incase if any other sub system updates +* the div or src without the knowledge of application processor +* subsystem and RCG could run at different rate other than +* software cached rate.
This happens? But then if we force enable RCG and the src was changed by another subsystem and that src isn't enabled anymore we're going to get a stuck rcg switch. So they really shouldn't be switching it over to a non-safe src before handing it off to us. I can believe div, so ok we may need to update div, but then either the 'current_freq' is in the table that matches the safe src speed, and then we can call clk_rcg2_shared_force_enable_clear() or the frequency doesn't match safe src speed and we can still call clk_rcg2_shared_force_enable_clear() because it's in the freq table. I thought these three lines below in this if condition were purely there because the frequency table didn't hold the entry for safe src speed, sometimes.
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 916
Quoted 3 lines
drivers/clk/qcom/clk-rcg2.c +3
-0+*/ +clk_rcg2_set_force_enable (hw); +clk_rcg2_configure (rcg, &safe_src_freq_tbl);
This could be a few more lines to regmap_write() the cfg reg with the proper index then leave the mnd registers empty, and then call update_config()? Instead of doing index gymnastics.
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 929
Quoted 13 lines
drivers/clk/qcom/clk-rcg2.c +13
-0+clk_rcg2_clear_force_enable (hw); + +return 0 ; + } + +/* +* Switch from safe source to the stashed mux selection. The current +* parent has already been prepared and enabled at this point, and +* the safe source is always on while application processor subsystem +* is online. Therefore, the RCG can safely switch its source. +*/ + +return clk_rcg2_shared_force_enable_clear (hw, rcg->current_freq);
Ok maybe it's because we may boot up, rate is safe src speed in hardware, that entry is not in the freq table, recalc_rate() is called and that finds safe src speed and assigns it into current_freq. I can believe that. So in this case, the above if condition is going to catch it and allow enable to be called before clk_set_rate().
How about changing 'current_freq' to literally a struct freq_table member, that stores a copy of the frequency table entry to use or constructs the entry on the fly when the frequency doesn't exist in the plan? At boot time, that could be populated with the value we read from hardware, and then otherwise when we call disable() it would just copy it over into the member and on enable() it would slam it into the hardware and do update_config().
Or we could even just read the M, N, D, and CFG registers and save them off at driver probe time or during disable and then restore them on enable. Make a pointer in clk_rcg2 to some regcache structure and then assign those statically in the SoC driver to avoid wasting space for each RCG out there. The recalc_rate() function could fill in the cache too if there's some special bit set indicating it needs to load it initially, and then a new recalc_rate() function could be written to operate on the mini-cache of register values for these clks. We could even go a step further and have the clk_set_rate() path write into the cache when the clk is disabled to update the mnd and cfg and bypass the cache when the clk is enabled.
It would be super nice if regmap could handle all of this too, so we could enable caching for a few registers, regmap write into them and skip the update_config() step when clk disabled, and then flush the cache when we enable, update_config(), and disable caching for the registers. recalc_rate() would work unchanged then because it would always hit in the cache when caching is on, or read the hardware when caching was off. We would need something that lets us bypass the cache though and write directly when we force the safe src. There's already some regmap caching code, so it might work with some more APIs added. Or we could go the custom cache route and see how bad it is.
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+} + +static void clk_rcg2_shared_disable (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +struct freq_tbl safe_src_freq_tbl = {0 }; + + safe_src_freq_tbl.src = rcg->safe_src_index; + safe_src_freq_tbl.freq =clk_rcg2_get_safe_src_rate (hw); +
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 949
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+/* +* Park the RCG at a safe configuration - sourced off from safe source. +* Force enable and disable the RCG while configuring it to safeguard +* against any update signal coming from the downstream clock. +* The current parent is still prepared and enabled at this point, and +* the safe source is always on while application processor subsystem +* is online. Therefore, the RCG can safely switch its parent. +*/ +clk_rcg2_set_force_enable (hw); +clk_rcg2_configure (rcg, &safe_src_freq_tbl);
Again, slam in index and call update_config() directly.
Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+clk_rcg2_clear_force_enable (hw); +}
Re: [PATCH v5 1/2] clk: qcom: Configure the RCGs to a safe source as needed
Quoted 12 lines · Stephen Boyd
Quoting Amit Nischal (2018-04-18 06:34:32)
drivers/clk/qcom/clk-rcg.h struct clk_rcg2 { · line 158
Quoted 9 lines
drivers/clk/qcom/clk-rcg.h +1
-0@@ -153,8 +155,10 @@ struct clk_rcg2 {u32 cmd_rcgr;u8 mnd_width;u8 hid_width; +const u8 safe_src_index;Please drop const.
Thanks for the review. Will remove the const.
Quoted 23 lines
Quoted 23 lines
drivers/clk/qcom/clk-rcg.h +1
-0const struct parent_map *parent_map;const struct freq_tbl *freq_tbl; +unsigned long current_freq;struct clk_regmap clkr; };drivers/clk/qcom/clk-rcg2.c +2
-0+ +static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned longrate,
drivers/clk/qcom/clk-rcg2.c +9
-0+ unsigned long parent_rate) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +int ret; + +/* +* Return if the RCG is currently disabled. This configuration +* update will happen as part of the RCG enable sequence. +*/
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c
Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+if (!__clk_is_enabled (hw->clk)) { + rcg->current_freq = rate;We should probably check that 'rate' can be achieved during
clk_set_rate()though. So I imagine we would need to do all the rounding, etc. and then cache the frequency at that point. Or cross fingers that this set rate op is never called without theround_rateop being called on it too.
Yes set_rate() op would not be called without round_rate/determine_rate().
Quoted 13 lines
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 866
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +9
-0+return 0 ; + } + + ret =clk_rcg2_shared_force_enable_clear (hw, rate); +if (ret) +return ret; + +/* Update current frequency with the requested frequency. */ + rcg->current_freq = rate;Is this even needed?
recalc_rate()would be called shortly after and do this too.
Here updating of current_freq with the new requested rate is required as recalc_rate() op is using the current_freq and returning the cached rate (current_freq) when the clock is in disabled state.
Quoted 16 lines
drivers/clk/qcom/clk-rcg2.c
Quoted 10 lines
drivers/clk/qcom/clk-rcg2.c +6
-0+ +return ret; +} + +static int clk_rcg2_shared_set_rate_and_parent (struct clk_hw *hw, + unsigned long rate, unsigned long parent_rate, u8index)
drivers/clk/qcom/clk-rcg2.c +2
-0+{ +return clk_rcg2_shared_set_rate (hw, rate, parent_rate);We lost index. I guess that's OK...
Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+} +[...]
Quoted 12 lines
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+ +static unsigned long clk_rcg2_get_safe_src_rate (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +int index; + + index = qcom_find_src_index(hw, rcg->parent_map,
rcg->safe_src_index);Why are we finding it though? Can't we just set the bit to be what it's supposed to be all the time at compile time instead of going through the parent map to find the register value?
This is to find the safe source rate from the safe_src_index value. As suggested in v2 series, we are constructing the safe source frequency table on the fly from the safe_src_index value.
Quoted 8 lines
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 897
Quoted 5 lines
drivers/clk/qcom/clk-rcg2.c +4
-0+if (index <0 ) + index =0 ; + +return clk_hw_get_rate (clk_hw_get_parent_by_index (hw, index));I'm still failing to see why the 'rate' is so important for the safe source.
Safe source's rate is getting used in the clk_rcg2_shared_enable() op. Please have a look at next comment which explains about the need of safe source's rate.
Quoted 26 lines
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 907
Quoted 11 lines
drivers/clk/qcom/clk-rcg2.c +10
-0+} + +static int clk_rcg2_shared_enable (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +struct freq_tbl safe_src_freq_tbl = {0 }; + + safe_src_freq_tbl.freq =clk_rcg2_get_safe_src_rate (hw); + +if (rcg->current_freq == safe_src_freq_tbl.freq) {I'd prefer this became a bool condition like
rcg->on_safe_srcor something like that, instead of calculating the safe src frequency and comparing that to whateverrecalc_ratesaw.Quoted 9 lines
drivers/clk/qcom/clk-rcg2.c +3
-0+ safe_src_freq_tbl.src = rcg->safe_src_index; +/* +* Reconfigure the RCG - Incase if any other sub system updates
+ * the div or src without the knowledge of application
processor
+ * subsystem and RCG could run at different rate other
than
+ * software cached rate.
Quoted 11 lines
This happens? But then if we force enable RCG and the src was changed by another subsystem and that src isn't enabled anymore we're going to get a stuck rcg switch. So they really shouldn't be switching it over to a non-safe src before handing it off to us. I can believe div, so ok we may need to update div, but then either the '
current_freq' is in the table that matches the safe src speed, and then we can callclk_rcg2_shared_force_enable_clear()or the frequency doesn't match safe src speed and we can still callclk_rcg2_shared_force_enable_clear()because it's in the freq table. I thought these three lines below in this if condition were purely there because the frequency table didn't hold the entry for safe src speed, sometimes.
Yes, your understanding is right. Above lines are there to catch the below:
1. When pre-boot entity configures the clock to run from safe_src.
2. RCG frequency table does not hold the entry for safe_src speed.
3. The clock_enable() gets call without the set_rate().
If all the above three conditions will be true then, enable op would configure the RCG at safe_src speed otherwise, enable() would configure the RCG with the first frequency entry in the frequency table and RCG will get enable at a rate which BOOT has not configured and the old configuration will be lost.
Quoted 53 lines
drivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 916
Quoted 4 lines
drivers/clk/qcom/clk-rcg2.c +3
-0+*/ +clk_rcg2_set_force_enable (hw); +clk_rcg2_configure (rcg, &safe_src_freq_tbl);This could be a few more lines to
regmap_write()the cfg reg with the proper index then leave the mnd registers empty, and then callupdate_config()? Instead of doing index gymnastics.Quoted 16 lines
drivers/clk/qcom/clk-rcg2.c +7
-0+clk_rcg2_clear_force_enable (hw); + +return 0 ; + } + +/* +* Switch from safe source to the stashed mux selection. The current
+ * parent has already been prepared and enabled at this point,
and
+ * the safe source is always on while application processor
subsystemdrivers/clk/qcom/clk-rcg2.c +4
-0+* is online. Therefore, the RCG can safely switch its source. +*/ + + return clk_rcg2_shared_force_enable_clear(hw,Quoted 1 line
rcg->current_freq);Ok maybe it's because we may boot up, rate is safe src speed in hardware, that entry is not in the freq table,
recalc_rate()is called and that finds safe src speed and assigns it intocurrent_freq. I can believe that. So in this case, the above if condition is going to catch it and allow enable to be called beforeclk_set_rate().How about changing '
current_freq' to literally a structfreq_tablemember, that stores a copy of the frequency table entry to use or constructs the entry on the fly when the frequency doesn't exist in the plan? At boot time, that could be populated with the value we read from hardware, and then otherwise when we calldisable()it would just copy it over into the member and onenable()it would slam it into the hardware and doupdate_config().Or we could even just read the M, N, D, and CFG registers and save them off at driver probe time or during disable and then restore them on enable. Make a pointer in
clk_rcg2to some regcache structure and then assign those statically in the SoC driver to avoid wasting space for each RCG out there. Therecalc_rate()function could fill in the cache too if there's some special bit set indicating it needs to load it initially, and then a newrecalc_rate()function could be written to operate on the mini-cache of register values for these clks. We could even go a step further and have theclk_set_rate()path write into the cache when the clk is disabled to update the mnd and cfg and bypass the cache when the clk is enabled.
Quoted 10 lines
It would be super nice if regmap could handle all of this too, so we could enable caching for a few registers, regmap write into them and skip the
update_config()step when clk disabled, and then flush the cache when we enable,update_config(), and disable caching for the registers.recalc_rate()would work unchanged then because it would always hit in the cache when caching is on, or read the hardware when caching was off. We would need something that lets us bypass the cache though and write directly when we force the safe src. There's already some regmap caching code, so it might work with some more APIs added. Or we could go the custom cache route and see how bad it is.
Thanks for your valuable suggestions. We would like to revisit this feature to construct a frequency table entry on the fly when boot configures the RCG to a different frequency which is not present in the freq_tbl at a later point of time.
As of now, it's expected that any pre-boot entity should follow the frequency plan and configure the RCG accordingly.
The main intention of this patch is to switch the RCG to the safe source(XO) in disable path and switch back to stashed mux source from the safe source(XO) in enable path.
Quoted 30 lines
Quoted 21 lines
drivers/clk/qcom/clk-rcg2.c +12
-0+} + +static void clk_rcg2_shared_disable (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); +struct freq_tbl safe_src_freq_tbl = {0 }; + + safe_src_freq_tbl.src = rcg->safe_src_index; + safe_src_freq_tbl.freq =clk_rcg2_get_safe_src_rate (hw); + +/* +* Park the RCG at a safe configuration - sourced off from safe source.
+ * Force enable and disable the RCG while configuring it to
safeguarddrivers/clk/qcom/clk-rcg2.c +2
-0+* against any update signal coming from the downstream clock. +* The current parent is still prepared and enabled at this point, and
+ * the safe source is always on while application processor
subsystemdrivers/clk/qcom/clk-rcg2.c static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, · line 949
Quoted 4 lines
drivers/clk/qcom/clk-rcg2.c +4
-0+* is online. Therefore, the RCG can safely switch its parent. +*/ +clk_rcg2_set_force_enable (hw); +clk_rcg2_configure (rcg, &safe_src_freq_tbl);Again, slam in index and call
update_config()directly.Quoted 2 lines
drivers/clk/qcom/clk-rcg2.c +2
-0+clk_rcg2_clear_force_enable (hw); +}