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

Pull clk fixes from Stephen Boyd"

- one stm32f4 fix for a change that introduced the PLL_I2S and PLL_SAI
boards

- two Allwinner clk driver build fixes

- two Allwinner CPU clk driver fixes where we see random CPUFreq
crashes because the CPU's PLL locks up sometimes when we change the
rate

* tag 'clk-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/clk/linux:
clk: sunxi-ng: a33: gate then ungate PLL CPU clk after rate change
clk: sunxi-ng: Add clk notifier to gate then ungate PLL clocks
clk: sunxi-ng: fix build failure in ccu-sun9i-a80 driver
clk: sunxi-ng: fix build error without CONFIG_RESET_CONTROLLER
clk: stm32f4: fix: exclude values 0 and 1 for PLLQ

Changed files
+84 -3
drivers
+10 -3
drivers/clk/clk-stm32f4.c
··· 429 429 { 0, 2 }, { 1, 4 }, { 2, 6 }, { 3, 8 }, { 0 } 430 430 }; 431 431 432 + static const struct clk_div_table pll_divq_table[] = { 433 + { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, 434 + { 8, 8 }, { 9, 9 }, { 10, 10 }, { 11, 11 }, { 12, 12 }, { 13, 13 }, 435 + { 14, 14 }, { 15, 15 }, 436 + { 0 } 437 + }; 438 + 432 439 static const struct clk_div_table pll_divr_table[] = { 433 440 { 2, 2 }, { 3, 3 }, { 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 }, { 0 } 434 441 }; ··· 503 496 504 497 #define MAX_PLL_DIV 3 505 498 static const struct stm32f4_div_data div_data[MAX_PLL_DIV] = { 506 - { 16, 2, 0, pll_divp_table }, 507 - { 24, 4, CLK_DIVIDER_ONE_BASED, NULL }, 508 - { 28, 3, 0, pll_divr_table }, 499 + { 16, 2, 0, pll_divp_table }, 500 + { 24, 4, 0, pll_divq_table }, 501 + { 28, 3, 0, pll_divr_table }, 509 502 }; 510 503 511 504 struct stm32f4_pll_data {
+2
drivers/clk/sunxi-ng/Kconfig
··· 1 1 config SUNXI_CCU 2 2 bool "Clock support for Allwinner SoCs" 3 3 depends on ARCH_SUNXI || COMPILE_TEST 4 + select RESET_CONTROLLER 4 5 default ARCH_SUNXI 5 6 6 7 if SUNXI_CCU ··· 136 135 config SUN9I_A80_CCU 137 136 bool "Support for the Allwinner A80 CCU" 138 137 select SUNXI_CCU_DIV 138 + select SUNXI_CCU_MULT 139 139 select SUNXI_CCU_GATE 140 140 select SUNXI_CCU_NKMP 141 141 select SUNXI_CCU_NM
+11
drivers/clk/sunxi-ng/ccu-sun8i-a33.c
··· 752 752 .num_resets = ARRAY_SIZE(sun8i_a33_ccu_resets), 753 753 }; 754 754 755 + static struct ccu_pll_nb sun8i_a33_pll_cpu_nb = { 756 + .common = &pll_cpux_clk.common, 757 + /* copy from pll_cpux_clk */ 758 + .enable = BIT(31), 759 + .lock = BIT(28), 760 + }; 761 + 755 762 static struct ccu_mux_nb sun8i_a33_cpu_nb = { 756 763 .common = &cpux_clk.common, 757 764 .cm = &cpux_clk.mux, ··· 790 783 791 784 sunxi_ccu_probe(node, reg, &sun8i_a33_ccu_desc); 792 785 786 + /* Gate then ungate PLL CPU after any rate changes */ 787 + ccu_pll_notifier_register(&sun8i_a33_pll_cpu_nb); 788 + 789 + /* Reparent CPU during PLL CPU rate changes */ 793 790 ccu_mux_notifier_register(pll_cpux_clk.common.hw.clk, 794 791 &sun8i_a33_cpu_nb); 795 792 }
+49
drivers/clk/sunxi-ng/ccu_common.c
··· 14 14 * GNU General Public License for more details. 15 15 */ 16 16 17 + #include <linux/clk.h> 17 18 #include <linux/clk-provider.h> 18 19 #include <linux/iopoll.h> 19 20 #include <linux/slab.h> 20 21 21 22 #include "ccu_common.h" 23 + #include "ccu_gate.h" 22 24 #include "ccu_reset.h" 23 25 24 26 static DEFINE_SPINLOCK(ccu_lock); ··· 39 37 addr = common->base + common->reg; 40 38 41 39 WARN_ON(readl_relaxed_poll_timeout(addr, reg, reg & lock, 100, 70000)); 40 + } 41 + 42 + /* 43 + * This clock notifier is called when the frequency of a PLL clock is 44 + * changed. In common PLL designs, changes to the dividers take effect 45 + * almost immediately, while changes to the multipliers (implemented 46 + * as dividers in the feedback loop) take a few cycles to work into 47 + * the feedback loop for the PLL to stablize. 48 + * 49 + * Sometimes when the PLL clock rate is changed, the decrease in the 50 + * divider is too much for the decrease in the multiplier to catch up. 51 + * The PLL clock rate will spike, and in some cases, might lock up 52 + * completely. 53 + * 54 + * This notifier callback will gate and then ungate the clock, 55 + * effectively resetting it, so it proceeds to work. Care must be 56 + * taken to reparent consumers to other temporary clocks during the 57 + * rate change, and that this notifier callback must be the first 58 + * to be registered. 59 + */ 60 + static int ccu_pll_notifier_cb(struct notifier_block *nb, 61 + unsigned long event, void *data) 62 + { 63 + struct ccu_pll_nb *pll = to_ccu_pll_nb(nb); 64 + int ret = 0; 65 + 66 + if (event != POST_RATE_CHANGE) 67 + goto out; 68 + 69 + ccu_gate_helper_disable(pll->common, pll->enable); 70 + 71 + ret = ccu_gate_helper_enable(pll->common, pll->enable); 72 + if (ret) 73 + goto out; 74 + 75 + ccu_helper_wait_for_lock(pll->common, pll->lock); 76 + 77 + out: 78 + return notifier_from_errno(ret); 79 + } 80 + 81 + int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb) 82 + { 83 + pll_nb->clk_nb.notifier_call = ccu_pll_notifier_cb; 84 + 85 + return clk_notifier_register(pll_nb->common->hw.clk, 86 + &pll_nb->clk_nb); 42 87 } 43 88 44 89 int sunxi_ccu_probe(struct device_node *node, void __iomem *reg,
+12
drivers/clk/sunxi-ng/ccu_common.h
··· 83 83 84 84 void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock); 85 85 86 + struct ccu_pll_nb { 87 + struct notifier_block clk_nb; 88 + struct ccu_common *common; 89 + 90 + u32 enable; 91 + u32 lock; 92 + }; 93 + 94 + #define to_ccu_pll_nb(_nb) container_of(_nb, struct ccu_pll_nb, clk_nb) 95 + 96 + int ccu_pll_notifier_register(struct ccu_pll_nb *pll_nb); 97 + 86 98 int sunxi_ccu_probe(struct device_node *node, void __iomem *reg, 87 99 const struct sunxi_ccu_desc *desc); 88 100