clk: qcom: MISC RCG changes for SDM845
Subsystems (3)
v2 cover clk: qcom: MISC RCG changes for SDM845
Changes in v2:
* Changed usage of clk_hw_is_prepared() to __clk_is_enabled() in clk_rcg2_shared_ops to fix build test error.
Changes in v1:
This patch series does the miscellaneous changes for RCGs used in SDM845.
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.
Amit Nischal (2):
clk: qcom: Clear hardware clock control bit of RCG
clk: qcom: Configure the RCGs to a safe source as needed
drivers/clk/qcom/clk-rcg.h | 8 ++- drivers/clk/qcom/clk-rcg2.c | 154 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 159 insertions(+), 3 deletions(-)
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 1/2 clk: qcom: Clear hardware clock control bit of RCG
For upcoming targets like sdm845, POR value of the hardware clock control bit is set for most of root clocks which needs to be cleared for software to be able to control. For older targets like MSM8996, this bit is reserved bit and having POR value as 0 so this patch will work for the older targets too. So update the configuration mask to take care of the same to clear hardware clock control bit.
--- drivers/clk/qcom/clk-rcg2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/clk-rcg2.c +3 -2
@@ -1,5 +1,5 @@/* -* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* Copyright (c) 2013, 2017, 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
@@ -42,6 +42,7 @@#define CFG_MODE_SHIFT 12#define CFG_MODE_MASK (0x3 << CFG_MODE_SHIFT)#define CFG_MODE_DUAL_EDGE (0x2 << CFG_MODE_SHIFT) +#define CFG_HW_CLK_CTRL_MASK BIT(20)#define M_REG 0x8#define N_REG 0xc
@@ -276,7 +277,7 @@ static int clk_rcg2_configure(struct clk_rcg2 *rcg, const struct freq_tbl *f) } mask =BIT (rcg->hid_width) -1 ; - mask |=CFG_SRC_SEL_MASK |CFG_MODE_MASK ; + mask |=CFG_SRC_SEL_MASK |CFG_MODE_MASK |CFG_HW_CLK_CTRL_MASK ; cfg = f->pre_div <<CFG_SRC_DIV_SHIFT ; cfg |= rcg->parent_map[index].cfg <<CFG_SRC_SEL_SHIFT ;if (rcg->mnd_width && f->n && (f->m != f->n))
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
PATCH v2 2/2 clk: qcom: Configure the RCGs to a safe source as needed
In reply to Amit NischalFor 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 actual 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 actual RCG is on and it expects its new source to alredy in enable state but in reality new source is in off state. In order to avoid letting the RCG to go into an invalid state, add support to just 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 | 8 ++- drivers/clk/qcom/clk-rcg2.c | 149 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-)
drivers/clk/qcom/clk-rcg.h +7 -1
@@ -1,5 +1,5 @@/* -* Copyright (c) 2013, The Linux Foundation. All rights reserved. +* Copyright (c) 2013, 2017, 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
@@ -156,6 +156,9 @@ struct clk_dyn_rcg {* @hid_width: number of bits in half integer divider * @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 +* @safe_src_freq_tbl : frequency table of safe source when using branches +* with shared RCGs * @clkr: regmap clock handle * */
@@ -165,6 +168,8 @@ struct clk_rcg2 {u8 hid_width;const struct parent_map *parent_map;const struct freq_tbl *freq_tbl; +unsigned long current_freq; +const struct freq_tbl *safe_src_freq_tbl;struct clk_regmap clkr; };
@@ -177,5 +182,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 +149 -0
152 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
Quoted 3 lines · Amit Nischal
Changes in v2:
* Changed usage ofclk_hw_is_prepared()to__clk_is_enabled()inclk_rcg2_shared_opsto fix build test error.
Please change it to read the hardware directly and not use __clk_is_enabled() or clk_hw_is_prepared().
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Quoted 7 lines · Stephen Boyd
Quoted 3 lines · Amit Nischal
Changes in v2:
* Changed usage ofclk_hw_is_prepared()to__clk_is_enabled()inclk_rcg2_shared_opsto fix build test error.Please change it to read the hardware directly and not use
__clk_is_enabled()orclk_hw_is_prepared().
Hi Stephen,
Thanks for the review the change.
Here intention is to know the software status of the RCG instead of HW status and we have intentionally not defined the 'is_enabled' ops for clk_rcg2_shared_ops. This clk_rcg2_shared_ops are only applicable for the RCGs with shared branches across different subsystems. Reason for using the same is mentioned below.
When RCG gets enabled by other subsystem (outside the Application processor subsystem):
In this case when RCG gets enabled by branch clock managed by other subsystem(outside the Application processor subsystem) and if we check HW statusof RCG in clk_rcg2_shared_set_rate() instead of checking its software statusthen it will give the status as ENABLED without overlying software knowingits status and during source switch, update configuration will get fail as newparent will be indisabled state.
In above scenario, clock framework will not enable the new parent beforeconfiguration update as enable and prepare counts are zero for RCG clockand clk_set_rate() will follow below path.
clk_rcg2_shared_set_rate()
__clk_set_parent_before()-->New parent will be disabled as prepare count = 0 clk_change_rate()
clk_set_rate()
So solution of this problem is as follows and same is explained in the commit text of https://patchwork.kernel.org/patch/10139985/
1. If software status of the RCG is disabled(enable/prepare counts are 0) then just cache or store the rate in current_freq variable and if softwarestatus is enabled then follow the normal update procedure.
2. Set the rate and switch to new source onlyin clk_rcg2_shared_enable() i.e. during RCG enable sequence. This will make surethat required parents are already in enable state before configuration updateand RCG switch will happen successfully every time.
In past, We have encountered similar RCG update configuration failure issues for somedisplay RCGs, where there are two branch clocks, one is controlled by application processor subsystem and another one controlled by othersubsystem. So to handle such cases, we need clk_rcg2_shared_ops.
Quoted 7 lines · Stephen Boyd
Quoted 3 lines · Amit Nischal
Changes in v2:
* Changed usage ofclk_hw_is_prepared()to__clk_is_enabled()inclk_rcg2_shared_opsto fix build test error.Please change it to read the hardware directly and not use
__clk_is_enabled()orclk_hw_is_prepared().
Hi Stephen,
Thanks for the review the change.
Here intention is to know the software status of the RCG instead of HW status and we have intentionally not defined the 'is_enabled' ops for clk_rcg2_shared_ops. This clk_rcg2_shared_ops are only applicable for the RCGs with shared branches across different subsystems. Reason for using the same is mentioned below.
When RCG gets enabled by other subsystem (outside the Application processor subsystem):
In this case when RCG gets enabled by branch clock managed by other subsystem (outside the Application processor subsystem) and if we check HW status of RCG in clk_rcg2_shared_set_rate() instead of checking its software status then it will give the status as ENABLED without overlying software knowing its status and during source switch, update configuration will get fail as new parent will be in disabled state.
In above scenario, clock framework will not enable the new parent before configuration update as enable and prepare counts are zero for RCG clock and clk_set_rate() will follow below path.
clk_rcg2_shared_set_rate() __clk_set_parent_before()-->New parent will be disabled as prepare
count = 0
clk_change_rate()
clk_set_rate()
So solution of this problem is as follows and same is explained in the commit text of https://patchwork.kernel.org/patch/10139985/
1. If software status of the RCG is disabled(enable/prepare counts are 0) then just cache or store the rate in current_freq variable and if software status is enabled then follow the normal update procedure.
2. Set the rate and switch to new source only in clk_rcg2_shared_enable() i.e. during RCG enable sequence. This will make sure that required parents are already in enable state before configuration update and RCG switch will happen successfully every time.
In past, We have encountered similar RCG update configuration failure issues for some display RCGs, where there are two branch clocks, one is controlled by application processor subsystem and another one controlled by other subsystem. So to handle such cases, we need clk_rcg2_shared_ops.