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

Merge branches 'clk-semicolon', 'clk-axi-clkgen', 'clk-qoriq', 'clk-baikal', 'clk-const' and 'clk-mmp2' into clk-next

* clk-semicolon:
clk: meson: use semicolons rather than commas to separate statements
clk: mvebu: ap80x-cpu: use semicolons rather than commas to separate statements
clk: uniphier: use semicolons rather than commas to separate statements

* clk-axi-clkgen:
clk: axi-clkgen: Set power bits for fractional mode
clk: axi-clkgen: Add support for fractional dividers

* clk-qoriq:
clk: qoriq: modify MAX_PLL_DIV to 32

* clk-baikal:
clk: baikal-t1: Mark Ethernet PLL as critical

* clk-const:
clk: pxa: Constify static struct clk_ops

* clk-mmp2:
clk: mmp2: Fix the display clock divider base

+156 -69
+8 -6
drivers/clk/baikal-t1/clk-ccu-pll.c
··· 51 51 }; 52 52 53 53 /* 54 - * Mark as critical all PLLs except Ethernet one. CPU and DDR PLLs are sources 55 - * of CPU cores and DDR controller reference clocks, due to which they 56 - * obviously shouldn't be ever gated. SATA and PCIe PLLs are the parents of 57 - * APB-bus and DDR controller AXI-bus clocks. If they are gated the system will 58 - * be unusable. 54 + * Alas we have to mark all PLLs as critical. CPU and DDR PLLs are sources of 55 + * CPU cores and DDR controller reference clocks, due to which they obviously 56 + * shouldn't be ever gated. SATA and PCIe PLLs are the parents of APB-bus and 57 + * DDR controller AXI-bus clocks. If they are gated the system will be 58 + * unusable. Moreover disabling SATA and Ethernet PLLs causes automatic reset 59 + * of the corresponding subsystems. So until we aren't ready to re-initialize 60 + * all the devices consuming those PLLs, they will be marked as critical too. 59 61 */ 60 62 static const struct ccu_pll_info pll_info[] = { 61 63 CCU_PLL_INFO(CCU_CPU_PLL, "cpu_pll", "ref_clk", CCU_CPU_PLL_BASE, ··· 69 67 CCU_PLL_INFO(CCU_PCIE_PLL, "pcie_pll", "ref_clk", CCU_PCIE_PLL_BASE, 70 68 CLK_IS_CRITICAL), 71 69 CCU_PLL_INFO(CCU_ETH_PLL, "eth_pll", "ref_clk", CCU_ETH_PLL_BASE, 72 - CLK_SET_RATE_GATE) 70 + CLK_IS_CRITICAL | CLK_SET_RATE_GATE) 73 71 }; 74 72 75 73 struct ccu_pll_data {
+137 -52
drivers/clk/clk-axi-clkgen.c
··· 27 27 28 28 #define AXI_CLKGEN_V2_DRP_STATUS_BUSY BIT(16) 29 29 30 + #define MMCM_REG_CLKOUT5_2 0x07 30 31 #define MMCM_REG_CLKOUT0_1 0x08 31 32 #define MMCM_REG_CLKOUT0_2 0x09 33 + #define MMCM_REG_CLKOUT6_2 0x13 32 34 #define MMCM_REG_CLK_FB1 0x14 33 35 #define MMCM_REG_CLK_FB2 0x15 34 36 #define MMCM_REG_CLK_DIV 0x16 35 37 #define MMCM_REG_LOCK1 0x18 36 38 #define MMCM_REG_LOCK2 0x19 37 39 #define MMCM_REG_LOCK3 0x1a 40 + #define MMCM_REG_POWER 0x28 38 41 #define MMCM_REG_FILTER1 0x4e 39 42 #define MMCM_REG_FILTER2 0x4f 40 43 41 44 #define MMCM_CLKOUT_NOCOUNT BIT(6) 42 45 46 + #define MMCM_CLK_DIV_DIVIDE BIT(11) 43 47 #define MMCM_CLK_DIV_NOCOUNT BIT(12) 44 48 45 49 struct axi_clkgen { ··· 111 107 unsigned long d, d_min, d_max, _d_min, _d_max; 112 108 unsigned long m, m_min, m_max; 113 109 unsigned long f, dout, best_f, fvco; 110 + unsigned long fract_shift = 0; 111 + unsigned long fvco_min_fract, fvco_max_fract; 114 112 115 113 fin /= 1000; 116 114 fout /= 1000; ··· 125 119 d_min = max_t(unsigned long, DIV_ROUND_UP(fin, fpfd_max), 1); 126 120 d_max = min_t(unsigned long, fin / fpfd_min, 80); 127 121 128 - m_min = max_t(unsigned long, DIV_ROUND_UP(fvco_min, fin) * d_min, 1); 129 - m_max = min_t(unsigned long, fvco_max * d_max / fin, 64); 122 + again: 123 + fvco_min_fract = fvco_min << fract_shift; 124 + fvco_max_fract = fvco_max << fract_shift; 125 + 126 + m_min = max_t(unsigned long, DIV_ROUND_UP(fvco_min_fract, fin) * d_min, 1); 127 + m_max = min_t(unsigned long, fvco_max_fract * d_max / fin, 64 << fract_shift); 130 128 131 129 for (m = m_min; m <= m_max; m++) { 132 - _d_min = max(d_min, DIV_ROUND_UP(fin * m, fvco_max)); 133 - _d_max = min(d_max, fin * m / fvco_min); 130 + _d_min = max(d_min, DIV_ROUND_UP(fin * m, fvco_max_fract)); 131 + _d_max = min(d_max, fin * m / fvco_min_fract); 134 132 135 133 for (d = _d_min; d <= _d_max; d++) { 136 134 fvco = fin * m / d; 137 135 138 136 dout = DIV_ROUND_CLOSEST(fvco, fout); 139 - dout = clamp_t(unsigned long, dout, 1, 128); 137 + dout = clamp_t(unsigned long, dout, 1, 128 << fract_shift); 140 138 f = fvco / dout; 141 139 if (abs(f - fout) < abs(best_f - fout)) { 142 140 best_f = f; 143 141 *best_d = d; 144 - *best_m = m; 145 - *best_dout = dout; 142 + *best_m = m << (3 - fract_shift); 143 + *best_dout = dout << (3 - fract_shift); 146 144 if (best_f == fout) 147 145 return; 148 146 } 149 147 } 150 148 } 149 + 150 + /* Lets see if we find a better setting in fractional mode */ 151 + if (fract_shift == 0) { 152 + fract_shift = 3; 153 + goto again; 154 + } 151 155 } 152 156 153 - static void axi_clkgen_calc_clk_params(unsigned int divider, unsigned int *low, 154 - unsigned int *high, unsigned int *edge, unsigned int *nocount) 155 - { 156 - if (divider == 1) 157 - *nocount = 1; 158 - else 159 - *nocount = 0; 157 + struct axi_clkgen_div_params { 158 + unsigned int low; 159 + unsigned int high; 160 + unsigned int edge; 161 + unsigned int nocount; 162 + unsigned int frac_en; 163 + unsigned int frac; 164 + unsigned int frac_wf_f; 165 + unsigned int frac_wf_r; 166 + unsigned int frac_phase; 167 + }; 160 168 161 - *high = divider / 2; 162 - *edge = divider % 2; 163 - *low = divider - *high; 169 + static void axi_clkgen_calc_clk_params(unsigned int divider, 170 + unsigned int frac_divider, struct axi_clkgen_div_params *params) 171 + { 172 + 173 + memset(params, 0x0, sizeof(*params)); 174 + 175 + if (divider == 1) { 176 + params->nocount = 1; 177 + return; 178 + } 179 + 180 + if (frac_divider == 0) { 181 + params->high = divider / 2; 182 + params->edge = divider % 2; 183 + params->low = divider - params->high; 184 + } else { 185 + params->frac_en = 1; 186 + params->frac = frac_divider; 187 + 188 + params->high = divider / 2; 189 + params->edge = divider % 2; 190 + params->low = params->high; 191 + 192 + if (params->edge == 0) { 193 + params->high--; 194 + params->frac_wf_r = 1; 195 + } 196 + 197 + if (params->edge == 0 || frac_divider == 1) 198 + params->low--; 199 + if (((params->edge == 0) ^ (frac_divider == 1)) || 200 + (divider == 2 && frac_divider == 1)) 201 + params->frac_wf_f = 1; 202 + 203 + params->frac_phase = params->edge * 4 + frac_divider / 2; 204 + } 164 205 } 165 206 166 207 static void axi_clkgen_write(struct axi_clkgen *axi_clkgen, ··· 299 246 return container_of(clk_hw, struct axi_clkgen, clk_hw); 300 247 } 301 248 249 + static void axi_clkgen_set_div(struct axi_clkgen *axi_clkgen, 250 + unsigned int reg1, unsigned int reg2, unsigned int reg3, 251 + struct axi_clkgen_div_params *params) 252 + { 253 + axi_clkgen_mmcm_write(axi_clkgen, reg1, 254 + (params->high << 6) | params->low, 0xefff); 255 + axi_clkgen_mmcm_write(axi_clkgen, reg2, 256 + (params->frac << 12) | (params->frac_en << 11) | 257 + (params->frac_wf_r << 10) | (params->edge << 7) | 258 + (params->nocount << 6), 0x7fff); 259 + if (reg3 != 0) { 260 + axi_clkgen_mmcm_write(axi_clkgen, reg3, 261 + (params->frac_phase << 11) | (params->frac_wf_f << 10), 0x3c00); 262 + } 263 + } 264 + 302 265 static int axi_clkgen_set_rate(struct clk_hw *clk_hw, 303 266 unsigned long rate, unsigned long parent_rate) 304 267 { 305 268 struct axi_clkgen *axi_clkgen = clk_hw_to_axi_clkgen(clk_hw); 306 269 unsigned int d, m, dout; 307 - unsigned int nocount; 308 - unsigned int high; 309 - unsigned int edge; 310 - unsigned int low; 270 + struct axi_clkgen_div_params params; 271 + uint32_t power = 0; 311 272 uint32_t filter; 312 273 uint32_t lock; 313 274 ··· 333 266 if (d == 0 || dout == 0 || m == 0) 334 267 return -EINVAL; 335 268 269 + if ((dout & 0x7) != 0 || (m & 0x7) != 0) 270 + power |= 0x9800; 271 + 272 + axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_POWER, power, 0x9800); 273 + 336 274 filter = axi_clkgen_lookup_filter(m - 1); 337 275 lock = axi_clkgen_lookup_lock(m - 1); 338 276 339 - axi_clkgen_calc_clk_params(dout, &low, &high, &edge, &nocount); 340 - axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_CLKOUT0_1, 341 - (high << 6) | low, 0xefff); 342 - axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_CLKOUT0_2, 343 - (edge << 7) | (nocount << 6), 0x03ff); 277 + axi_clkgen_calc_clk_params(dout >> 3, dout & 0x7, &params); 278 + axi_clkgen_set_div(axi_clkgen, MMCM_REG_CLKOUT0_1, MMCM_REG_CLKOUT0_2, 279 + MMCM_REG_CLKOUT5_2, &params); 344 280 345 - axi_clkgen_calc_clk_params(d, &low, &high, &edge, &nocount); 281 + axi_clkgen_calc_clk_params(d, 0, &params); 346 282 axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_CLK_DIV, 347 - (edge << 13) | (nocount << 12) | (high << 6) | low, 0x3fff); 283 + (params.edge << 13) | (params.nocount << 12) | 284 + (params.high << 6) | params.low, 0x3fff); 348 285 349 - axi_clkgen_calc_clk_params(m, &low, &high, &edge, &nocount); 350 - axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_CLK_FB1, 351 - (high << 6) | low, 0xefff); 352 - axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_CLK_FB2, 353 - (edge << 7) | (nocount << 6), 0x03ff); 286 + axi_clkgen_calc_clk_params(m >> 3, m & 0x7, &params); 287 + axi_clkgen_set_div(axi_clkgen, MMCM_REG_CLK_FB1, MMCM_REG_CLK_FB2, 288 + MMCM_REG_CLKOUT6_2, &params); 354 289 355 290 axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_LOCK1, lock & 0x3ff, 0x3ff); 356 291 axi_clkgen_mmcm_write(axi_clkgen, MMCM_REG_LOCK2, ··· 382 313 return min_t(unsigned long long, tmp, LONG_MAX); 383 314 } 384 315 316 + static unsigned int axi_clkgen_get_div(struct axi_clkgen *axi_clkgen, 317 + unsigned int reg1, unsigned int reg2) 318 + { 319 + unsigned int val1, val2; 320 + unsigned int div; 321 + 322 + axi_clkgen_mmcm_read(axi_clkgen, reg2, &val2); 323 + if (val2 & MMCM_CLKOUT_NOCOUNT) 324 + return 8; 325 + 326 + axi_clkgen_mmcm_read(axi_clkgen, reg1, &val1); 327 + 328 + div = (val1 & 0x3f) + ((val1 >> 6) & 0x3f); 329 + div <<= 3; 330 + 331 + if (val2 & MMCM_CLK_DIV_DIVIDE) { 332 + if ((val2 & BIT(7)) && (val2 & 0x7000) != 0x1000) 333 + div += 8; 334 + else 335 + div += 16; 336 + 337 + div += (val2 >> 12) & 0x7; 338 + } 339 + 340 + return div; 341 + } 342 + 385 343 static unsigned long axi_clkgen_recalc_rate(struct clk_hw *clk_hw, 386 344 unsigned long parent_rate) 387 345 { 388 346 struct axi_clkgen *axi_clkgen = clk_hw_to_axi_clkgen(clk_hw); 389 347 unsigned int d, m, dout; 390 - unsigned int reg; 391 348 unsigned long long tmp; 349 + unsigned int val; 392 350 393 - axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLKOUT0_2, &reg); 394 - if (reg & MMCM_CLKOUT_NOCOUNT) { 395 - dout = 1; 396 - } else { 397 - axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLKOUT0_1, &reg); 398 - dout = (reg & 0x3f) + ((reg >> 6) & 0x3f); 399 - } 351 + dout = axi_clkgen_get_div(axi_clkgen, MMCM_REG_CLKOUT0_1, 352 + MMCM_REG_CLKOUT0_2); 353 + m = axi_clkgen_get_div(axi_clkgen, MMCM_REG_CLK_FB1, 354 + MMCM_REG_CLK_FB2); 400 355 401 - axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_DIV, &reg); 402 - if (reg & MMCM_CLK_DIV_NOCOUNT) 356 + axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_DIV, &val); 357 + if (val & MMCM_CLK_DIV_NOCOUNT) 403 358 d = 1; 404 359 else 405 - d = (reg & 0x3f) + ((reg >> 6) & 0x3f); 406 - 407 - axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_FB2, &reg); 408 - if (reg & MMCM_CLKOUT_NOCOUNT) { 409 - m = 1; 410 - } else { 411 - axi_clkgen_mmcm_read(axi_clkgen, MMCM_REG_CLK_FB1, &reg); 412 - m = (reg & 0x3f) + ((reg >> 6) & 0x3f); 413 - } 360 + d = (val & 0x3f) + ((val >> 6) & 0x3f); 414 361 415 362 if (d == 0 || dout == 0) 416 363 return 0;
+1 -1
drivers/clk/clk-qoriq.c
··· 31 31 #define CGA_PLL4 4 /* only on clockgen-1.0, which lacks CGB */ 32 32 #define CGB_PLL1 4 33 33 #define CGB_PLL2 5 34 - #define MAX_PLL_DIV 16 34 + #define MAX_PLL_DIV 32 35 35 36 36 struct clockgen_pll_div { 37 37 struct clk *clk;
+1 -1
drivers/clk/meson/meson-aoclk.c
··· 57 57 rstc->data = data; 58 58 rstc->regmap = regmap; 59 59 rstc->reset.ops = &meson_aoclk_reset_ops; 60 - rstc->reset.nr_resets = data->num_reset, 60 + rstc->reset.nr_resets = data->num_reset; 61 61 rstc->reset.of_node = dev->of_node; 62 62 ret = devm_reset_controller_register(dev, &rstc->reset); 63 63 if (ret) {
+2 -2
drivers/clk/mmp/clk-of-mmp2.c
··· 347 347 }; 348 348 349 349 static struct mmp_param_div_clk apmu_div_clks[] = { 350 - {0, "disp0_div", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 8, 4, 0, &disp0_lock}, 350 + {0, "disp0_div", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 8, 4, CLK_DIVIDER_ONE_BASED, &disp0_lock}, 351 351 {0, "disp0_sphy_div", "disp0_mux", CLK_SET_RATE_PARENT, APMU_DISP0, 15, 5, 0, &disp0_lock}, 352 - {0, "disp1_div", "disp1_mux", CLK_SET_RATE_PARENT, APMU_DISP1, 8, 4, 0, &disp1_lock}, 352 + {0, "disp1_div", "disp1_mux", CLK_SET_RATE_PARENT, APMU_DISP1, 8, 4, CLK_DIVIDER_ONE_BASED, &disp1_lock}, 353 353 {0, "ccic0_sphy_div", "ccic0_mix_clk", CLK_SET_RATE_PARENT, APMU_CCIC0, 10, 5, 0, &ccic0_lock}, 354 354 {0, "ccic1_sphy_div", "ccic1_mix_clk", CLK_SET_RATE_PARENT, APMU_CCIC1, 10, 5, 0, &ccic1_lock}, 355 355 };
+1 -1
drivers/clk/mvebu/ap-cpu-clk.c
··· 197 197 198 198 stable_bit = BIT(clk->pll_regs->ratio_state_offset + 199 199 clk->cluster * 200 - clk->pll_regs->ratio_state_cluster_offset), 200 + clk->pll_regs->ratio_state_cluster_offset); 201 201 ret = regmap_read_poll_timeout(clk->pll_cr_base, 202 202 clk->pll_regs->ratio_state_reg, reg, 203 203 reg & stable_bit, STATUS_POLL_PERIOD_US,
+4 -4
drivers/clk/pxa/clk-pxa.h
··· 19 19 #define MUX_RO_RATE_RO_OPS(name, clk_name) \ 20 20 static struct clk_hw name ## _mux_hw; \ 21 21 static struct clk_hw name ## _rate_hw; \ 22 - static struct clk_ops name ## _mux_ops = { \ 22 + static const struct clk_ops name ## _mux_ops = { \ 23 23 .get_parent = name ## _get_parent, \ 24 24 .set_parent = dummy_clk_set_parent, \ 25 25 }; \ 26 - static struct clk_ops name ## _rate_ops = { \ 26 + static const struct clk_ops name ## _rate_ops = { \ 27 27 .recalc_rate = name ## _get_rate, \ 28 28 }; \ 29 29 static struct clk * __init clk_register_ ## name(void) \ ··· 38 38 39 39 #define RATE_RO_OPS(name, clk_name) \ 40 40 static struct clk_hw name ## _rate_hw; \ 41 - static const struct clk_ops name ## _rate_ops = { \ 41 + static const struct clk_ops name ## _rate_ops = { \ 42 42 .recalc_rate = name ## _get_rate, \ 43 43 }; \ 44 44 static struct clk * __init clk_register_ ## name(void) \ ··· 53 53 54 54 #define RATE_OPS(name, clk_name) \ 55 55 static struct clk_hw name ## _rate_hw; \ 56 - static struct clk_ops name ## _rate_ops = { \ 56 + static const struct clk_ops name ## _rate_ops = { \ 57 57 .recalc_rate = name ## _get_rate, \ 58 58 .set_rate = name ## _set_rate, \ 59 59 .determine_rate = name ## _determine_rate, \
+1 -1
drivers/clk/uniphier/clk-uniphier-cpugear.c
··· 90 90 init.ops = &uniphier_clk_cpugear_ops; 91 91 init.flags = CLK_SET_RATE_PARENT; 92 92 init.parent_names = data->parent_names; 93 - init.num_parents = data->num_parents, 93 + init.num_parents = data->num_parents; 94 94 95 95 gear->regmap = regmap; 96 96 gear->regbase = data->regbase;
+1 -1
drivers/clk/uniphier/clk-uniphier-mux.c
··· 70 70 init.ops = &uniphier_clk_mux_ops; 71 71 init.flags = CLK_SET_RATE_PARENT; 72 72 init.parent_names = data->parent_names; 73 - init.num_parents = data->num_parents, 73 + init.num_parents = data->num_parents; 74 74 75 75 mux->regmap = regmap; 76 76 mux->reg = data->reg;