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

clk: let init callback return an error code

If the init callback is allowed to request resources, it needs a return
value to report the outcome of such a request.

Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
Link: https://lkml.kernel.org/r/20190924123954.31561-3-jbrunet@baylibre.com
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Jerome Brunet and committed by
Stephen Boyd
89d079dc f6fa75ca

+72 -35
+11 -6
drivers/clk/clk.c
··· 3316 3316 * optional platform-specific magic 3317 3317 * 3318 3318 * The .init callback is not used by any of the basic clock types, but 3319 - * exists for weird hardware that must perform initialization magic. 3320 - * Please consider other ways of solving initialization problems before 3321 - * using this callback, as its use is discouraged. 3319 + * exists for weird hardware that must perform initialization magic for 3320 + * CCF to get an accurate view of clock for any other callbacks. It may 3321 + * also be used needs to perform dynamic allocations. Such allocation 3322 + * must be freed in the terminate() callback. 3323 + * This callback shall not be used to initialize the parameters state, 3324 + * such as rate, parent, etc ... 3322 3325 * 3323 3326 * If it exist, this callback should called before any other callback of 3324 3327 * the clock 3325 3328 */ 3326 - if (core->ops->init) 3327 - core->ops->init(core->hw); 3328 - 3329 + if (core->ops->init) { 3330 + ret = core->ops->init(core->hw); 3331 + if (ret) 3332 + goto out; 3333 + } 3329 3334 3330 3335 core->parent = __clk_init_parent(core); 3331 3336
+3 -1
drivers/clk/meson/clk-mpll.c
··· 129 129 return 0; 130 130 } 131 131 132 - static void mpll_init(struct clk_hw *hw) 132 + static int mpll_init(struct clk_hw *hw) 133 133 { 134 134 struct clk_regmap *clk = to_clk_regmap(hw); 135 135 struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk); ··· 151 151 /* Set the magic misc bit if required */ 152 152 if (MESON_PARM_APPLICABLE(&mpll->misc)) 153 153 meson_parm_write(clk->map, &mpll->misc, 1); 154 + 155 + return 0; 154 156 } 155 157 156 158 const struct clk_ops meson_clk_mpll_ro_ops = {
+3 -1
drivers/clk/meson/clk-phase.c
··· 78 78 return (struct meson_clk_triphase_data *)clk->data; 79 79 } 80 80 81 - static void meson_clk_triphase_sync(struct clk_hw *hw) 81 + static int meson_clk_triphase_sync(struct clk_hw *hw) 82 82 { 83 83 struct clk_regmap *clk = to_clk_regmap(hw); 84 84 struct meson_clk_triphase_data *tph = meson_clk_triphase_data(clk); ··· 88 88 val = meson_parm_read(clk->map, &tph->ph0); 89 89 meson_parm_write(clk->map, &tph->ph1, val); 90 90 meson_parm_write(clk->map, &tph->ph2, val); 91 + 92 + return 0; 91 93 } 92 94 93 95 static int meson_clk_triphase_get_phase(struct clk_hw *hw)
+3 -1
drivers/clk/meson/clk-pll.c
··· 277 277 return -ETIMEDOUT; 278 278 } 279 279 280 - static void meson_clk_pll_init(struct clk_hw *hw) 280 + static int meson_clk_pll_init(struct clk_hw *hw) 281 281 { 282 282 struct clk_regmap *clk = to_clk_regmap(hw); 283 283 struct meson_clk_pll_data *pll = meson_clk_pll_data(clk); ··· 288 288 pll->init_count); 289 289 meson_parm_write(clk->map, &pll->rst, 0); 290 290 } 291 + 292 + return 0; 291 293 } 292 294 293 295 static int meson_clk_pll_is_enabled(struct clk_hw *hw)
+3 -1
drivers/clk/meson/sclk-div.c
··· 216 216 return 0; 217 217 } 218 218 219 - static void sclk_div_init(struct clk_hw *hw) 219 + static int sclk_div_init(struct clk_hw *hw) 220 220 { 221 221 struct clk_regmap *clk = to_clk_regmap(hw); 222 222 struct meson_sclk_div_data *sclk = meson_sclk_div_data(clk); ··· 231 231 sclk->cached_div = val + 1; 232 232 233 233 sclk_div_get_duty_cycle(hw, &sclk->cached_duty); 234 + 235 + return 0; 234 236 } 235 237 236 238 const struct clk_ops meson_sclk_div_ops = {
+6 -2
drivers/clk/microchip/clk-core.c
··· 266 266 writel(REFO_ON | REFO_OE, PIC32_CLR(refo->ctrl_reg)); 267 267 } 268 268 269 - static void roclk_init(struct clk_hw *hw) 269 + static int roclk_init(struct clk_hw *hw) 270 270 { 271 271 /* initialize clock in disabled state */ 272 272 roclk_disable(hw); 273 + 274 + return 0; 273 275 } 274 276 275 277 static u8 roclk_get_parent(struct clk_hw *hw) ··· 882 880 return err; 883 881 } 884 882 885 - static void sclk_init(struct clk_hw *hw) 883 + static int sclk_init(struct clk_hw *hw) 886 884 { 887 885 struct pic32_sys_clk *sclk = clkhw_to_sys_clk(hw); 888 886 unsigned long flags; ··· 901 899 writel(v, sclk->slew_reg); 902 900 spin_unlock_irqrestore(&sclk->core->reg_lock, flags); 903 901 } 902 + 903 + return 0; 904 904 } 905 905 906 906 /* sclk with post-divider */
+3 -1
drivers/clk/mmp/clk-frac.c
··· 109 109 return 0; 110 110 } 111 111 112 - static void clk_factor_init(struct clk_hw *hw) 112 + static int clk_factor_init(struct clk_hw *hw) 113 113 { 114 114 struct mmp_clk_factor *factor = to_clk_factor(hw); 115 115 struct mmp_clk_factor_masks *masks = factor->masks; ··· 146 146 147 147 if (factor->lock) 148 148 spin_unlock_irqrestore(factor->lock, flags); 149 + 150 + return 0; 149 151 } 150 152 151 153 static const struct clk_ops clk_factor_ops = {
+3 -1
drivers/clk/mmp/clk-mix.c
··· 419 419 } 420 420 } 421 421 422 - static void mmp_clk_mix_init(struct clk_hw *hw) 422 + static int mmp_clk_mix_init(struct clk_hw *hw) 423 423 { 424 424 struct mmp_clk_mix *mix = to_clk_mix(hw); 425 425 426 426 if (mix->table) 427 427 _filter_clk_table(mix, mix->table, mix->table_size); 428 + 429 + return 0; 428 430 } 429 431 430 432 const struct clk_ops mmp_clk_mix_ops = {
+4 -2
drivers/clk/qcom/clk-hfpll.c
··· 196 196 return l_val * parent_rate; 197 197 } 198 198 199 - static void clk_hfpll_init(struct clk_hw *hw) 199 + static int clk_hfpll_init(struct clk_hw *hw) 200 200 { 201 201 struct clk_hfpll *h = to_clk_hfpll(hw); 202 202 struct hfpll_data const *hd = h->d; ··· 206 206 regmap_read(regmap, hd->mode_reg, &mode); 207 207 if (mode != (PLL_BYPASSNL | PLL_RESET_N | PLL_OUTCTRL)) { 208 208 __clk_hfpll_init_once(hw); 209 - return; 209 + return 0; 210 210 } 211 211 212 212 if (hd->status_reg) { ··· 218 218 __clk_hfpll_init_once(hw); 219 219 } 220 220 } 221 + 222 + return 0; 221 223 } 222 224 223 225 static int hfpll_is_enabled(struct clk_hw *hw)
+17 -11
drivers/clk/rockchip/clk-pll.c
··· 282 282 return !(pllcon & RK3036_PLLCON1_PWRDOWN); 283 283 } 284 284 285 - static void rockchip_rk3036_pll_init(struct clk_hw *hw) 285 + static int rockchip_rk3036_pll_init(struct clk_hw *hw) 286 286 { 287 287 struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw); 288 288 const struct rockchip_pll_rate_table *rate; ··· 290 290 unsigned long drate; 291 291 292 292 if (!(pll->flags & ROCKCHIP_PLL_SYNC_RATE)) 293 - return; 293 + return 0; 294 294 295 295 drate = clk_hw_get_rate(hw); 296 296 rate = rockchip_get_pll_settings(pll, drate); 297 297 298 298 /* when no rate setting for the current rate, rely on clk_set_rate */ 299 299 if (!rate) 300 - return; 300 + return 0; 301 301 302 302 rockchip_rk3036_pll_get_params(pll, &cur); 303 303 ··· 319 319 if (!parent) { 320 320 pr_warn("%s: parent of %s not available\n", 321 321 __func__, __clk_get_name(hw->clk)); 322 - return; 322 + return 0; 323 323 } 324 324 325 325 pr_debug("%s: pll %s: rate params do not match rate table, adjusting\n", 326 326 __func__, __clk_get_name(hw->clk)); 327 327 rockchip_rk3036_pll_set_params(pll, rate); 328 328 } 329 + 330 + return 0; 329 331 } 330 332 331 333 static const struct clk_ops rockchip_rk3036_pll_clk_norate_ops = { ··· 517 515 return !(pllcon & RK3066_PLLCON3_PWRDOWN); 518 516 } 519 517 520 - static void rockchip_rk3066_pll_init(struct clk_hw *hw) 518 + static int rockchip_rk3066_pll_init(struct clk_hw *hw) 521 519 { 522 520 struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw); 523 521 const struct rockchip_pll_rate_table *rate; ··· 525 523 unsigned long drate; 526 524 527 525 if (!(pll->flags & ROCKCHIP_PLL_SYNC_RATE)) 528 - return; 526 + return 0; 529 527 530 528 drate = clk_hw_get_rate(hw); 531 529 rate = rockchip_get_pll_settings(pll, drate); 532 530 533 531 /* when no rate setting for the current rate, rely on clk_set_rate */ 534 532 if (!rate) 535 - return; 533 + return 0; 536 534 537 535 rockchip_rk3066_pll_get_params(pll, &cur); 538 536 ··· 545 543 __func__, clk_hw_get_name(hw)); 546 544 rockchip_rk3066_pll_set_params(pll, rate); 547 545 } 546 + 547 + return 0; 548 548 } 549 549 550 550 static const struct clk_ops rockchip_rk3066_pll_clk_norate_ops = { ··· 765 761 return !(pllcon & RK3399_PLLCON3_PWRDOWN); 766 762 } 767 763 768 - static void rockchip_rk3399_pll_init(struct clk_hw *hw) 764 + static int rockchip_rk3399_pll_init(struct clk_hw *hw) 769 765 { 770 766 struct rockchip_clk_pll *pll = to_rockchip_clk_pll(hw); 771 767 const struct rockchip_pll_rate_table *rate; ··· 773 769 unsigned long drate; 774 770 775 771 if (!(pll->flags & ROCKCHIP_PLL_SYNC_RATE)) 776 - return; 772 + return 0; 777 773 778 774 drate = clk_hw_get_rate(hw); 779 775 rate = rockchip_get_pll_settings(pll, drate); 780 776 781 777 /* when no rate setting for the current rate, rely on clk_set_rate */ 782 778 if (!rate) 783 - return; 779 + return 0; 784 780 785 781 rockchip_rk3399_pll_get_params(pll, &cur); 786 782 ··· 802 798 if (!parent) { 803 799 pr_warn("%s: parent of %s not available\n", 804 800 __func__, __clk_get_name(hw->clk)); 805 - return; 801 + return 0; 806 802 } 807 803 808 804 pr_debug("%s: pll %s: rate params do not match rate table, adjusting\n", 809 805 __func__, __clk_get_name(hw->clk)); 810 806 rockchip_rk3399_pll_set_params(pll, rate); 811 807 } 808 + 809 + return 0; 812 810 } 813 811 814 812 static const struct clk_ops rockchip_rk3399_pll_clk_norate_ops = {
+1 -1
drivers/clk/ti/clock.h
··· 253 253 254 254 extern struct ti_clk_features ti_clk_features; 255 255 256 - void omap2_init_clk_clkdm(struct clk_hw *hw); 256 + int omap2_init_clk_clkdm(struct clk_hw *hw); 257 257 int omap2_clkops_enable_clkdm(struct clk_hw *hw); 258 258 void omap2_clkops_disable_clkdm(struct clk_hw *hw); 259 259
+5 -3
drivers/clk/ti/clockdomain.c
··· 101 101 * 102 102 * Convert a clockdomain name stored in a struct clk 'clk' into a 103 103 * clockdomain pointer, and save it into the struct clk. Intended to be 104 - * called during clk_register(). No return value. 104 + * called during clk_register(). Returns 0 on success, -EERROR otherwise. 105 105 */ 106 - void omap2_init_clk_clkdm(struct clk_hw *hw) 106 + int omap2_init_clk_clkdm(struct clk_hw *hw) 107 107 { 108 108 struct clk_hw_omap *clk = to_clk_hw_omap(hw); 109 109 struct clockdomain *clkdm; 110 110 const char *clk_name; 111 111 112 112 if (!clk->clkdm_name) 113 - return; 113 + return 0; 114 114 115 115 clk_name = __clk_get_name(hw->clk); 116 116 ··· 123 123 pr_debug("clock: could not associate clk %s to clkdm %s\n", 124 124 clk_name, clk->clkdm_name); 125 125 } 126 + 127 + return 0; 126 128 } 127 129 128 130 static void __init of_ti_clockdomain_setup(struct device_node *node)
+3 -1
drivers/net/phy/mdio-mux-meson-g12a.c
··· 123 123 return (val & PLL_CTL0_LOCK_DIG) ? 1 : 0; 124 124 } 125 125 126 - static void g12a_ephy_pll_init(struct clk_hw *hw) 126 + static int g12a_ephy_pll_init(struct clk_hw *hw) 127 127 { 128 128 struct g12a_ephy_pll *pll = g12a_ephy_pll_to_dev(hw); 129 129 ··· 136 136 writel(0x20200000, pll->base + ETH_PLL_CTL5); 137 137 writel(0x0000c002, pll->base + ETH_PLL_CTL6); 138 138 writel(0x00000023, pll->base + ETH_PLL_CTL7); 139 + 140 + return 0; 139 141 } 140 142 141 143 static const struct clk_ops g12a_ephy_pll_ops = {
+7 -3
include/linux/clk-provider.h
··· 190 190 * 191 191 * @init: Perform platform-specific initialization magic. 192 192 * This is not not used by any of the basic clock types. 193 - * Please consider other ways of solving initialization problems 194 - * before using this callback, as its use is discouraged. 193 + * This callback exist for HW which needs to perform some 194 + * initialisation magic for CCF to get an accurate view of the 195 + * clock. It may also be used dynamic resource allocation is 196 + * required. It shall not used to deal with clock parameters, 197 + * such as rate or parents. 198 + * Returns 0 on success, -EERROR otherwise. 195 199 * 196 200 * @debug_init: Set up type-specific debugfs entries for this clock. This 197 201 * is called once, after the debugfs directory entry for this ··· 247 243 struct clk_duty *duty); 248 244 int (*set_duty_cycle)(struct clk_hw *hw, 249 245 struct clk_duty *duty); 250 - void (*init)(struct clk_hw *hw); 246 + int (*init)(struct clk_hw *hw); 251 247 void (*debug_init)(struct clk_hw *hw, struct dentry *dentry); 252 248 }; 253 249