Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: qcom: clk-alpha-pll: Add support for Fabia PLL calibration

In the cases where the PLL is not calibrated the PLL could fail to lock.
Add support for prepare ops which would take care of the same.

Fabia PLL user/test control registers might required to be configured, so
add support for configuring them.

Signed-off-by: Taniya Das <tdas@codeaurora.org>
Link: https://lkml.kernel.org/r/1573812304-24074-3-git-send-email-tdas@codeaurora.org
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Taniya Das and committed by
Stephen Boyd
691865ba 1dc36983

+80
+76
drivers/clk/qcom/clk-alpha-pll.c
··· 1032 1032 regmap_write(regmap, PLL_CONFIG_CTL(pll), 1033 1033 config->config_ctl_val); 1034 1034 1035 + if (config->config_ctl_hi_val) 1036 + regmap_write(regmap, PLL_CONFIG_CTL_U(pll), 1037 + config->config_ctl_hi_val); 1038 + 1039 + if (config->user_ctl_val) 1040 + regmap_write(regmap, PLL_USER_CTL(pll), config->user_ctl_val); 1041 + 1042 + if (config->user_ctl_hi_val) 1043 + regmap_write(regmap, PLL_USER_CTL_U(pll), 1044 + config->user_ctl_hi_val); 1045 + 1046 + if (config->test_ctl_val) 1047 + regmap_write(regmap, PLL_TEST_CTL(pll), 1048 + config->test_ctl_val); 1049 + 1050 + if (config->test_ctl_hi_val) 1051 + regmap_write(regmap, PLL_TEST_CTL_U(pll), 1052 + config->test_ctl_hi_val); 1053 + 1035 1054 if (config->post_div_mask) { 1036 1055 mask = config->post_div_mask; 1037 1056 val = config->post_div_val; ··· 1189 1170 return __clk_alpha_pll_update_latch(pll); 1190 1171 } 1191 1172 1173 + static int alpha_pll_fabia_prepare(struct clk_hw *hw) 1174 + { 1175 + struct clk_alpha_pll *pll = to_clk_alpha_pll(hw); 1176 + const struct pll_vco *vco; 1177 + struct clk_hw *parent_hw; 1178 + unsigned long cal_freq, rrate; 1179 + u32 cal_l, val, alpha_width = pll_alpha_width(pll); 1180 + u64 a; 1181 + int ret; 1182 + 1183 + /* Check if calibration needs to be done i.e. PLL is in reset */ 1184 + ret = regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val); 1185 + if (ret) 1186 + return ret; 1187 + 1188 + /* Return early if calibration is not needed. */ 1189 + if (val & PLL_RESET_N) 1190 + return 0; 1191 + 1192 + vco = alpha_pll_find_vco(pll, clk_hw_get_rate(hw)); 1193 + if (!vco) { 1194 + pr_err("alpha pll: not in a valid vco range\n"); 1195 + return -EINVAL; 1196 + } 1197 + 1198 + cal_freq = DIV_ROUND_CLOSEST((pll->vco_table[0].min_freq + 1199 + pll->vco_table[0].max_freq) * 54, 100); 1200 + 1201 + parent_hw = clk_hw_get_parent(hw); 1202 + if (!parent_hw) 1203 + return -EINVAL; 1204 + 1205 + rrate = alpha_pll_round_rate(cal_freq, clk_hw_get_rate(parent_hw), 1206 + &cal_l, &a, alpha_width); 1207 + /* 1208 + * Due to a limited number of bits for fractional rate programming, the 1209 + * rounded up rate could be marginally higher than the requested rate. 1210 + */ 1211 + if (rrate > (cal_freq + FABIA_PLL_RATE_MARGIN) || rrate < cal_freq) 1212 + return -EINVAL; 1213 + 1214 + /* Setup PLL for calibration frequency */ 1215 + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), cal_l); 1216 + 1217 + /* Bringup the PLL at calibration frequency */ 1218 + ret = clk_alpha_pll_enable(hw); 1219 + if (ret) { 1220 + pr_err("alpha pll calibration failed\n"); 1221 + return ret; 1222 + } 1223 + 1224 + clk_alpha_pll_disable(hw); 1225 + 1226 + return 0; 1227 + } 1228 + 1192 1229 const struct clk_ops clk_alpha_pll_fabia_ops = { 1230 + .prepare = alpha_pll_fabia_prepare, 1193 1231 .enable = alpha_pll_fabia_enable, 1194 1232 .disable = alpha_pll_fabia_disable, 1195 1233 .is_enabled = clk_alpha_pll_is_enabled,
+4
drivers/clk/qcom/clk-alpha-pll.h
··· 94 94 u32 alpha_hi; 95 95 u32 config_ctl_val; 96 96 u32 config_ctl_hi_val; 97 + u32 user_ctl_val; 98 + u32 user_ctl_hi_val; 99 + u32 test_ctl_val; 100 + u32 test_ctl_hi_val; 97 101 u32 main_output_mask; 98 102 u32 aux_output_mask; 99 103 u32 aux2_output_mask;