Merge tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux

Pull clock framework fixes from Michael Turquette:
"The clk fixes for 4.0-rc4 comprise three themes.

First are the usual driver fixes for new regressions since v3.19.

Second are fixes to the common clock divider type caused by recent
changes to how we round clock rates. This affects many clock drivers
that use this common code.

Finally there are fixes for drivers that improperly compared struct
clk pointers (drivers must not deref these pointers). While some of
these drivers have done this for a long time, this did not cause a
problem until we started generating unique struct clk pointers for
every consumer. A new function, clk_is_match was introduced to get
these drivers working again and they are fixed up to no longer deref
the pointers themselves"

* tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux:
ASoC: kirkwood: fix struct clk pointer comparing
ASoC: fsl_spdif: fix struct clk pointer comparing
ARM: imx: fix struct clk pointer comparing
clk: introduce clk_is_match
clk: don't export static symbol
clk: divider: fix calculation of initial best divider when rounding to closest
clk: divider: fix selection of divider when rounding to closest
clk: divider: fix calculation of maximal parent rate for a given divider
clk: divider: return real rate instead of divider value
clk: qcom: fix platform_no_drv_owner.cocci warnings
clk: qcom: fix platform_no_drv_owner.cocci warnings
clk: qcom: Add PLL4 vote clock
clk: qcom: lcc-msm8960: Fix PLL rate detection
clk: qcom: Fix slimbus n and m val offsets
clk: ti: Fix FAPLL parent enable bit handling

Changed files
+83 -29
arch
arm
mach-imx
drivers
include
linux
sound
soc
+3 -2
arch/arm/mach-imx/mach-imx6q.c
··· 211 211 * set bit IOMUXC_GPR1[21]. Or the PTP clock must be from pad 212 212 * (external OSC), and we need to clear the bit. 213 213 */ 214 - clksel = ptp_clk == enet_ref ? IMX6Q_GPR1_ENET_CLK_SEL_ANATOP : 215 - IMX6Q_GPR1_ENET_CLK_SEL_PAD; 214 + clksel = clk_is_match(ptp_clk, enet_ref) ? 215 + IMX6Q_GPR1_ENET_CLK_SEL_ANATOP : 216 + IMX6Q_GPR1_ENET_CLK_SEL_PAD; 216 217 gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr"); 217 218 if (!IS_ERR(gpr)) 218 219 regmap_update_bits(gpr, IOMUXC_GPR1,
+14 -15
drivers/clk/clk-divider.c
··· 144 144 divider->flags); 145 145 } 146 146 147 - /* 148 - * The reverse of DIV_ROUND_UP: The maximum number which 149 - * divided by m is r 150 - */ 151 - #define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1) 152 - 153 147 static bool _is_valid_table_div(const struct clk_div_table *table, 154 148 unsigned int div) 155 149 { ··· 219 225 unsigned long parent_rate, unsigned long rate, 220 226 unsigned long flags) 221 227 { 222 - int up, down, div; 228 + int up, down; 229 + unsigned long up_rate, down_rate; 223 230 224 - up = down = div = DIV_ROUND_CLOSEST(parent_rate, rate); 231 + up = DIV_ROUND_UP(parent_rate, rate); 232 + down = parent_rate / rate; 225 233 226 234 if (flags & CLK_DIVIDER_POWER_OF_TWO) { 227 - up = __roundup_pow_of_two(div); 228 - down = __rounddown_pow_of_two(div); 235 + up = __roundup_pow_of_two(up); 236 + down = __rounddown_pow_of_two(down); 229 237 } else if (table) { 230 - up = _round_up_table(table, div); 231 - down = _round_down_table(table, div); 238 + up = _round_up_table(table, up); 239 + down = _round_down_table(table, down); 232 240 } 233 241 234 - return (up - div) <= (div - down) ? up : down; 242 + up_rate = DIV_ROUND_UP(parent_rate, up); 243 + down_rate = DIV_ROUND_UP(parent_rate, down); 244 + 245 + return (rate - up_rate) <= (down_rate - rate) ? up : down; 235 246 } 236 247 237 248 static int _div_round(const struct clk_div_table *table, ··· 312 313 return i; 313 314 } 314 315 parent_rate = __clk_round_rate(__clk_get_parent(hw->clk), 315 - MULT_ROUND_UP(rate, i)); 316 + rate * i); 316 317 now = DIV_ROUND_UP(parent_rate, i); 317 318 if (_is_best_div(rate, now, best, flags)) { 318 319 bestdiv = i; ··· 352 353 bestdiv = readl(divider->reg) >> divider->shift; 353 354 bestdiv &= div_mask(divider->width); 354 355 bestdiv = _get_div(divider->table, bestdiv, divider->flags); 355 - return bestdiv; 356 + return DIV_ROUND_UP(*prate, bestdiv); 356 357 } 357 358 358 359 return divider_round_rate(hw, rate, prate, divider->table,
+26 -1
drivers/clk/clk.c
··· 1350 1350 1351 1351 return rate; 1352 1352 } 1353 - EXPORT_SYMBOL_GPL(clk_core_get_rate); 1354 1353 1355 1354 /** 1356 1355 * clk_get_rate - return the rate of clk ··· 2168 2169 2169 2170 return clk_core_get_phase(clk->core); 2170 2171 } 2172 + 2173 + /** 2174 + * clk_is_match - check if two clk's point to the same hardware clock 2175 + * @p: clk compared against q 2176 + * @q: clk compared against p 2177 + * 2178 + * Returns true if the two struct clk pointers both point to the same hardware 2179 + * clock node. Put differently, returns true if struct clk *p and struct clk *q 2180 + * share the same struct clk_core object. 2181 + * 2182 + * Returns false otherwise. Note that two NULL clks are treated as matching. 2183 + */ 2184 + bool clk_is_match(const struct clk *p, const struct clk *q) 2185 + { 2186 + /* trivial case: identical struct clk's or both NULL */ 2187 + if (p == q) 2188 + return true; 2189 + 2190 + /* true if clk->core pointers match. Avoid derefing garbage */ 2191 + if (!IS_ERR_OR_NULL(p) && !IS_ERR_OR_NULL(q)) 2192 + if (p->core == q->core) 2193 + return true; 2194 + 2195 + return false; 2196 + } 2197 + EXPORT_SYMBOL_GPL(clk_is_match); 2171 2198 2172 2199 /** 2173 2200 * __clk_init - initialize the data structures in a struct clk
+13
drivers/clk/qcom/gcc-msm8960.c
··· 48 48 }, 49 49 }; 50 50 51 + static struct clk_regmap pll4_vote = { 52 + .enable_reg = 0x34c0, 53 + .enable_mask = BIT(4), 54 + .hw.init = &(struct clk_init_data){ 55 + .name = "pll4_vote", 56 + .parent_names = (const char *[]){ "pll4" }, 57 + .num_parents = 1, 58 + .ops = &clk_pll_vote_ops, 59 + }, 60 + }; 61 + 51 62 static struct clk_pll pll8 = { 52 63 .l_reg = 0x3144, 53 64 .m_reg = 0x3148, ··· 3034 3023 3035 3024 static struct clk_regmap *gcc_msm8960_clks[] = { 3036 3025 [PLL3] = &pll3.clkr, 3026 + [PLL4_VOTE] = &pll4_vote, 3037 3027 [PLL8] = &pll8.clkr, 3038 3028 [PLL8_VOTE] = &pll8_vote, 3039 3029 [PLL14] = &pll14.clkr, ··· 3259 3247 3260 3248 static struct clk_regmap *gcc_apq8064_clks[] = { 3261 3249 [PLL3] = &pll3.clkr, 3250 + [PLL4_VOTE] = &pll4_vote, 3262 3251 [PLL8] = &pll8.clkr, 3263 3252 [PLL8_VOTE] = &pll8_vote, 3264 3253 [PLL14] = &pll14.clkr,
-1
drivers/clk/qcom/lcc-ipq806x.c
··· 462 462 .remove = lcc_ipq806x_remove, 463 463 .driver = { 464 464 .name = "lcc-ipq806x", 465 - .owner = THIS_MODULE, 466 465 .of_match_table = lcc_ipq806x_match_table, 467 466 }, 468 467 };
+3 -4
drivers/clk/qcom/lcc-msm8960.c
··· 417 417 .mnctr_en_bit = 8, 418 418 .mnctr_reset_bit = 7, 419 419 .mnctr_mode_shift = 5, 420 - .n_val_shift = 16, 421 - .m_val_shift = 16, 420 + .n_val_shift = 24, 421 + .m_val_shift = 8, 422 422 .width = 8, 423 423 }, 424 424 .p = { ··· 547 547 return PTR_ERR(regmap); 548 548 549 549 /* Use the correct frequency plan depending on speed of PLL4 */ 550 - val = regmap_read(regmap, 0x4, &val); 550 + regmap_read(regmap, 0x4, &val); 551 551 if (val == 0x12) { 552 552 slimbus_src.freq_tbl = clk_tbl_aif_osr_492; 553 553 mi2s_osr_src.freq_tbl = clk_tbl_aif_osr_492; ··· 574 574 .remove = lcc_msm8960_remove, 575 575 .driver = { 576 576 .name = "lcc-msm8960", 577 - .owner = THIS_MODULE, 578 577 .of_match_table = lcc_msm8960_match_table, 579 578 }, 580 579 };
+3 -3
drivers/clk/ti/fapll.c
··· 84 84 struct fapll_data *fd = to_fapll(hw); 85 85 u32 v = readl_relaxed(fd->base); 86 86 87 - v |= (1 << FAPLL_MAIN_PLLEN); 87 + v |= FAPLL_MAIN_PLLEN; 88 88 writel_relaxed(v, fd->base); 89 89 90 90 return 0; ··· 95 95 struct fapll_data *fd = to_fapll(hw); 96 96 u32 v = readl_relaxed(fd->base); 97 97 98 - v &= ~(1 << FAPLL_MAIN_PLLEN); 98 + v &= ~FAPLL_MAIN_PLLEN; 99 99 writel_relaxed(v, fd->base); 100 100 } 101 101 ··· 104 104 struct fapll_data *fd = to_fapll(hw); 105 105 u32 v = readl_relaxed(fd->base); 106 106 107 - return v & (1 << FAPLL_MAIN_PLLEN); 107 + return v & FAPLL_MAIN_PLLEN; 108 108 } 109 109 110 110 static unsigned long ti_fapll_recalc_rate(struct clk_hw *hw,
+18
include/linux/clk.h
··· 125 125 */ 126 126 int clk_get_phase(struct clk *clk); 127 127 128 + /** 129 + * clk_is_match - check if two clk's point to the same hardware clock 130 + * @p: clk compared against q 131 + * @q: clk compared against p 132 + * 133 + * Returns true if the two struct clk pointers both point to the same hardware 134 + * clock node. Put differently, returns true if struct clk *p and struct clk *q 135 + * share the same struct clk_core object. 136 + * 137 + * Returns false otherwise. Note that two NULL clks are treated as matching. 138 + */ 139 + bool clk_is_match(const struct clk *p, const struct clk *q); 140 + 128 141 #else 129 142 130 143 static inline long clk_get_accuracy(struct clk *clk) ··· 153 140 static inline long clk_get_phase(struct clk *clk) 154 141 { 155 142 return -ENOTSUPP; 143 + } 144 + 145 + static inline bool clk_is_match(const struct clk *p, const struct clk *q) 146 + { 147 + return p == q; 156 148 } 157 149 158 150 #endif
+2 -2
sound/soc/fsl/fsl_spdif.c
··· 1049 1049 enum spdif_txrate index, bool round) 1050 1050 { 1051 1051 const u32 rate[] = { 32000, 44100, 48000, 96000, 192000 }; 1052 - bool is_sysclk = clk == spdif_priv->sysclk; 1052 + bool is_sysclk = clk_is_match(clk, spdif_priv->sysclk); 1053 1053 u64 rate_ideal, rate_actual, sub; 1054 1054 u32 sysclk_dfmin, sysclk_dfmax; 1055 1055 u32 txclk_df, sysclk_df, arate; ··· 1143 1143 spdif_priv->txclk_src[index], rate[index]); 1144 1144 dev_dbg(&pdev->dev, "use txclk df %d for %dHz sample rate\n", 1145 1145 spdif_priv->txclk_df[index], rate[index]); 1146 - if (spdif_priv->txclk[index] == spdif_priv->sysclk) 1146 + if (clk_is_match(spdif_priv->txclk[index], spdif_priv->sysclk)) 1147 1147 dev_dbg(&pdev->dev, "use sysclk df %d for %dHz sample rate\n", 1148 1148 spdif_priv->sysclk_df[index], rate[index]); 1149 1149 dev_dbg(&pdev->dev, "the best rate for %dHz sample rate is %dHz\n",
+1 -1
sound/soc/kirkwood/kirkwood-i2s.c
··· 579 579 if (PTR_ERR(priv->extclk) == -EPROBE_DEFER) 580 580 return -EPROBE_DEFER; 581 581 } else { 582 - if (priv->extclk == priv->clk) { 582 + if (clk_is_match(priv->extclk, priv->clk)) { 583 583 devm_clk_put(&pdev->dev, priv->extclk); 584 584 priv->extclk = ERR_PTR(-EINVAL); 585 585 } else {