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

Merge branch 'clock' into HEAD

This is a major overhaul of the clk-qoriq driver, which I'm merging
via PPC with Stephen Boyd's ack in order to apply subsequent PPC patches
that depend on it.

+1228 -273
+50 -11
Documentation/devicetree/bindings/clock/qoriq-clock.txt
··· 1 1 * Clock Block on Freescale QorIQ Platforms 2 2 3 - Freescale qoriq chips take primary clocking input from the external 3 + Freescale QorIQ chips take primary clocking input from the external 4 4 SYSCLK signal. The SYSCLK input (frequency) is multiplied using 5 5 multiple phase locked loops (PLL) to create a variety of frequencies 6 6 which can then be passed to a variety of internal logic, including ··· 13 13 Chassis Version Example Chips 14 14 --------------- ------------- 15 15 1.0 p4080, p5020, p5040 16 - 2.0 t4240, b4860, t1040 16 + 2.0 t4240, b4860 17 17 18 18 1. Clock Block Binding 19 19 20 20 Required properties: 21 - - compatible: Should contain a specific clock block compatible string 22 - and a single chassis clock compatible string. 23 - Clock block strings include, but not limited to, one of the: 21 + - compatible: Should contain a chip-specific clock block compatible 22 + string and (if applicable) may contain a chassis-version clock 23 + compatible string. 24 + 25 + Chip-specific strings are of the form "fsl,<chip>-clockgen", such as: 24 26 * "fsl,p2041-clockgen" 25 27 * "fsl,p3041-clockgen" 26 28 * "fsl,p4080-clockgen" ··· 32 30 * "fsl,b4420-clockgen" 33 31 * "fsl,b4860-clockgen" 34 32 * "fsl,ls1021a-clockgen" 35 - Chassis clock strings include: 33 + Chassis-version clock strings include: 36 34 * "fsl,qoriq-clockgen-1.0": for chassis 1.0 clocks 37 35 * "fsl,qoriq-clockgen-2.0": for chassis 2.0 clocks 38 36 - reg: Describes the address of the device's resources within the 39 37 address space defined by its parent bus, and resource zero 40 38 represents the clock register set 41 - - clock-frequency: Input system clock frequency 42 39 43 - Recommended properties: 40 + Optional properties: 44 41 - ranges: Allows valid translation between child's address space and 45 42 parent's. Must be present if the device has sub-nodes. 46 43 - #address-cells: Specifies the number of cells used to represent ··· 48 47 - #size-cells: Specifies the number of cells used to represent 49 48 the size of an address. Must be present if the device has 50 49 sub-nodes and set to 1 if present 50 + - clock-frequency: Input system clock frequency (SYSCLK) 51 + - clocks: If clock-frequency is not specified, sysclk may be provided 52 + as an input clock. Either clock-frequency or clocks must be 53 + provided. 51 54 52 - 2. Clock Provider/Consumer Binding 55 + 2. Clock Provider 56 + 57 + The clockgen node should act as a clock provider, though in older device 58 + trees the children of the clockgen node are the clock providers. 59 + 60 + When the clockgen node is a clock provider, #clock-cells = <2>. 61 + The first cell of the clock specifier is the clock type, and the 62 + second cell is the clock index for the specified type. 63 + 64 + Type# Name Index Cell 65 + 0 sysclk must be 0 66 + 1 cmux index (n in CLKCnCSR) 67 + 2 hwaccel index (n in CLKCGnHWACSR) 68 + 3 fman 0 for fm1, 1 for fm2 69 + 4 platform pll 0=pll, 1=pll/2, 2=pll/3, 3=pll/4 70 + 71 + 3. Example 72 + 73 + clockgen: global-utilities@e1000 { 74 + compatible = "fsl,p5020-clockgen", "fsl,qoriq-clockgen-1.0"; 75 + clock-frequency = <133333333>; 76 + reg = <0xe1000 0x1000>; 77 + #clock-cells = <2>; 78 + }; 79 + 80 + fman@400000 { 81 + ... 82 + clocks = <&clockgen 3 0>; 83 + ... 84 + }; 85 + } 86 + 4. Legacy Child Nodes 87 + 88 + NOTE: These nodes are deprecated. Kernels should continue to support 89 + device trees with these nodes, but new device trees should not use them. 53 90 54 91 Most of the bindings are from the common clock binding[1]. 55 92 [1] Documentation/devicetree/bindings/clock/clock-bindings.txt ··· 121 82 - reg: Should be the offset and length of clock block base address. 122 83 The length should be 4. 123 84 124 - Example for clock block and clock provider: 85 + Legacy Example: 125 86 / { 126 87 clockgen: global-utilities@e1000 { 127 88 compatible = "fsl,p5020-clockgen", "fsl,qoriq-clockgen-1.0"; ··· 181 142 }; 182 143 }; 183 144 184 - Example for clock consumer: 145 + Example for legacy clock consumer: 185 146 186 147 / { 187 148 cpu0: PowerPC,e5500@0 {
+4 -4
arch/powerpc/include/asm/fsl_guts.h include/linux/fsl/guts.h
··· 12 12 * option) any later version. 13 13 */ 14 14 15 - #ifndef __ASM_POWERPC_FSL_GUTS_H__ 16 - #define __ASM_POWERPC_FSL_GUTS_H__ 17 - #ifdef __KERNEL__ 15 + #ifndef __FSL_GUTS_H__ 16 + #define __FSL_GUTS_H__ 17 + 18 + #include <linux/types.h> 18 19 19 20 /** 20 21 * Global Utility Registers. ··· 189 188 190 189 #endif 191 190 192 - #endif 193 191 #endif
+1 -1
arch/powerpc/platforms/85xx/mpc85xx_mds.c
··· 34 34 #include <linux/of_device.h> 35 35 #include <linux/phy.h> 36 36 #include <linux/memblock.h> 37 + #include <linux/fsl/guts.h> 37 38 38 39 #include <linux/atomic.h> 39 40 #include <asm/time.h> ··· 52 51 #include <asm/qe_ic.h> 53 52 #include <asm/mpic.h> 54 53 #include <asm/swiotlb.h> 55 - #include <asm/fsl_guts.h> 56 54 #include "smp.h" 57 55 58 56 #include "mpc85xx.h"
+1 -1
arch/powerpc/platforms/85xx/mpc85xx_rdb.c
··· 17 17 #include <linux/seq_file.h> 18 18 #include <linux/interrupt.h> 19 19 #include <linux/of_platform.h> 20 + #include <linux/fsl/guts.h> 20 21 21 22 #include <asm/time.h> 22 23 #include <asm/machdep.h> ··· 28 27 #include <asm/mpic.h> 29 28 #include <asm/qe.h> 30 29 #include <asm/qe_ic.h> 31 - #include <asm/fsl_guts.h> 32 30 33 31 #include <sysdev/fsl_soc.h> 34 32 #include <sysdev/fsl_pci.h>
+1 -1
arch/powerpc/platforms/85xx/p1022_ds.c
··· 16 16 * kind, whether express or implied. 17 17 */ 18 18 19 + #include <linux/fsl/guts.h> 19 20 #include <linux/pci.h> 20 21 #include <linux/of_platform.h> 21 22 #include <asm/div64.h> ··· 26 25 #include <sysdev/fsl_soc.h> 27 26 #include <sysdev/fsl_pci.h> 28 27 #include <asm/udbg.h> 29 - #include <asm/fsl_guts.h> 30 28 #include <asm/fsl_lbc.h> 31 29 #include "smp.h" 32 30
+1 -1
arch/powerpc/platforms/85xx/p1022_rdk.c
··· 12 12 * kind, whether express or implied. 13 13 */ 14 14 15 + #include <linux/fsl/guts.h> 15 16 #include <linux/pci.h> 16 17 #include <linux/of_platform.h> 17 18 #include <asm/div64.h> ··· 22 21 #include <sysdev/fsl_soc.h> 23 22 #include <sysdev/fsl_pci.h> 24 23 #include <asm/udbg.h> 25 - #include <asm/fsl_guts.h> 26 24 #include "smp.h" 27 25 28 26 #include "mpc85xx.h"
+1 -1
arch/powerpc/platforms/85xx/smp.c
··· 19 19 #include <linux/kexec.h> 20 20 #include <linux/highmem.h> 21 21 #include <linux/cpu.h> 22 + #include <linux/fsl/guts.h> 22 23 23 24 #include <asm/machdep.h> 24 25 #include <asm/pgtable.h> ··· 27 26 #include <asm/mpic.h> 28 27 #include <asm/cacheflush.h> 29 28 #include <asm/dbell.h> 30 - #include <asm/fsl_guts.h> 31 29 #include <asm/code-patching.h> 32 30 #include <asm/cputhreads.h> 33 31
+1 -1
arch/powerpc/platforms/85xx/twr_p102x.c
··· 15 15 #include <linux/kernel.h> 16 16 #include <linux/init.h> 17 17 #include <linux/errno.h> 18 + #include <linux/fsl/guts.h> 18 19 #include <linux/pci.h> 19 20 #include <linux/of_platform.h> 20 21 ··· 24 23 #include <asm/mpic.h> 25 24 #include <asm/qe.h> 26 25 #include <asm/qe_ic.h> 27 - #include <asm/fsl_guts.h> 28 26 29 27 #include <sysdev/fsl_soc.h> 30 28 #include <sysdev/fsl_pci.h>
+1 -1
arch/powerpc/platforms/86xx/mpc8610_hpcd.c
··· 24 24 #include <linux/delay.h> 25 25 #include <linux/seq_file.h> 26 26 #include <linux/of.h> 27 + #include <linux/fsl/guts.h> 27 28 28 29 #include <asm/time.h> 29 30 #include <asm/machdep.h> ··· 39 38 #include <sysdev/fsl_pci.h> 40 39 #include <sysdev/fsl_soc.h> 41 40 #include <sysdev/simple_gpio.h> 42 - #include <asm/fsl_guts.h> 43 41 44 42 #include "mpc86xx.h" 45 43
+1 -1
drivers/clk/Kconfig
··· 121 121 122 122 config CLK_QORIQ 123 123 bool "Clock driver for Freescale QorIQ platforms" 124 - depends on (PPC_E500MC || ARM) && OF 124 + depends on (PPC_E500MC || ARM || ARM64) && OF 125 125 ---help--- 126 126 This adds the clock driver support for Freescale QorIQ platforms 127 127 using common clock framework.
+1162 -246
drivers/clk/clk-qoriq.c
··· 10 10 11 11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 12 12 13 + #include <linux/clk.h> 13 14 #include <linux/clk-provider.h> 15 + #include <linux/fsl/guts.h> 14 16 #include <linux/io.h> 15 17 #include <linux/kernel.h> 16 18 #include <linux/module.h> ··· 21 19 #include <linux/of.h> 22 20 #include <linux/slab.h> 23 21 24 - struct cmux_clk { 25 - struct clk_hw hw; 26 - void __iomem *reg; 27 - unsigned int clk_per_pll; 28 - u32 flags; 22 + #define PLL_DIV1 0 23 + #define PLL_DIV2 1 24 + #define PLL_DIV3 2 25 + #define PLL_DIV4 3 26 + 27 + #define PLATFORM_PLL 0 28 + #define CGA_PLL1 1 29 + #define CGA_PLL2 2 30 + #define CGA_PLL3 3 31 + #define CGA_PLL4 4 /* only on clockgen-1.0, which lacks CGB */ 32 + #define CGB_PLL1 4 33 + #define CGB_PLL2 5 34 + 35 + struct clockgen_pll_div { 36 + struct clk *clk; 37 + char name[32]; 29 38 }; 30 39 31 - #define PLL_KILL BIT(31) 32 - #define CLKSEL_SHIFT 27 33 - #define CLKSEL_ADJUST BIT(0) 34 - #define to_cmux_clk(p) container_of(p, struct cmux_clk, hw) 40 + struct clockgen_pll { 41 + struct clockgen_pll_div div[4]; 42 + }; 35 43 36 - static int cmux_set_parent(struct clk_hw *hw, u8 idx) 44 + #define CLKSEL_VALID 1 45 + #define CLKSEL_80PCT 2 /* Only allowed if PLL <= 80% of max cpu freq */ 46 + 47 + struct clockgen_sourceinfo { 48 + u32 flags; /* CLKSEL_xxx */ 49 + int pll; /* CGx_PLLn */ 50 + int div; /* PLL_DIVn */ 51 + }; 52 + 53 + #define NUM_MUX_PARENTS 16 54 + 55 + struct clockgen_muxinfo { 56 + struct clockgen_sourceinfo clksel[NUM_MUX_PARENTS]; 57 + }; 58 + 59 + #define NUM_HWACCEL 5 60 + #define NUM_CMUX 8 61 + 62 + struct clockgen; 63 + 64 + /* 65 + * cmux freq must be >= platform pll. 66 + * If not set, cmux freq must be >= platform pll/2 67 + */ 68 + #define CG_CMUX_GE_PLAT 1 69 + 70 + #define CG_PLL_8BIT 2 /* PLLCnGSR[CFG] is 8 bits, not 6 */ 71 + #define CG_VER3 4 /* version 3 cg: reg layout different */ 72 + #define CG_LITTLE_ENDIAN 8 73 + 74 + struct clockgen_chipinfo { 75 + const char *compat, *guts_compat; 76 + const struct clockgen_muxinfo *cmux_groups[2]; 77 + const struct clockgen_muxinfo *hwaccel[NUM_HWACCEL]; 78 + void (*init_periph)(struct clockgen *cg); 79 + int cmux_to_group[NUM_CMUX]; /* -1 terminates if fewer than NUM_CMUX */ 80 + u32 pll_mask; /* 1 << n bit set if PLL n is valid */ 81 + u32 flags; /* CG_xxx */ 82 + }; 83 + 84 + struct clockgen { 85 + struct device_node *node; 86 + void __iomem *regs; 87 + struct clockgen_chipinfo info; /* mutable copy */ 88 + struct clk *sysclk; 89 + struct clockgen_pll pll[6]; 90 + struct clk *cmux[NUM_CMUX]; 91 + struct clk *hwaccel[NUM_HWACCEL]; 92 + struct clk *fman[2]; 93 + struct ccsr_guts __iomem *guts; 94 + }; 95 + 96 + static struct clockgen clockgen; 97 + 98 + static void cg_out(struct clockgen *cg, u32 val, u32 __iomem *reg) 37 99 { 38 - struct cmux_clk *clk = to_cmux_clk(hw); 100 + if (cg->info.flags & CG_LITTLE_ENDIAN) 101 + iowrite32(val, reg); 102 + else 103 + iowrite32be(val, reg); 104 + } 105 + 106 + static u32 cg_in(struct clockgen *cg, u32 __iomem *reg) 107 + { 108 + u32 val; 109 + 110 + if (cg->info.flags & CG_LITTLE_ENDIAN) 111 + val = ioread32(reg); 112 + else 113 + val = ioread32be(reg); 114 + 115 + return val; 116 + } 117 + 118 + static const struct clockgen_muxinfo p2041_cmux_grp1 = { 119 + { 120 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 121 + [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 122 + [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 123 + } 124 + }; 125 + 126 + static const struct clockgen_muxinfo p2041_cmux_grp2 = { 127 + { 128 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 129 + [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 130 + [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 131 + } 132 + }; 133 + 134 + static const struct clockgen_muxinfo p5020_cmux_grp1 = { 135 + { 136 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 137 + [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 138 + [4] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL2, PLL_DIV1 }, 139 + } 140 + }; 141 + 142 + static const struct clockgen_muxinfo p5020_cmux_grp2 = { 143 + { 144 + [0] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV1 }, 145 + [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 146 + [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 147 + } 148 + }; 149 + 150 + static const struct clockgen_muxinfo p5040_cmux_grp1 = { 151 + { 152 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 153 + [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 154 + [4] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL2, PLL_DIV1 }, 155 + [5] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL2, PLL_DIV2 }, 156 + } 157 + }; 158 + 159 + static const struct clockgen_muxinfo p5040_cmux_grp2 = { 160 + { 161 + [0] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV1 }, 162 + [1] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV2 }, 163 + [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 164 + [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 165 + } 166 + }; 167 + 168 + static const struct clockgen_muxinfo p4080_cmux_grp1 = { 169 + { 170 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 171 + [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 172 + [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 173 + [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 174 + [8] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL3, PLL_DIV1 }, 175 + } 176 + }; 177 + 178 + static const struct clockgen_muxinfo p4080_cmux_grp2 = { 179 + { 180 + [0] = { CLKSEL_VALID | CLKSEL_80PCT, CGA_PLL1, PLL_DIV1 }, 181 + [8] = { CLKSEL_VALID, CGA_PLL3, PLL_DIV1 }, 182 + [9] = { CLKSEL_VALID, CGA_PLL3, PLL_DIV2 }, 183 + [12] = { CLKSEL_VALID, CGA_PLL4, PLL_DIV1 }, 184 + [13] = { CLKSEL_VALID, CGA_PLL4, PLL_DIV2 }, 185 + } 186 + }; 187 + 188 + static const struct clockgen_muxinfo t1023_cmux = { 189 + { 190 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 191 + [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 192 + } 193 + }; 194 + 195 + static const struct clockgen_muxinfo t1040_cmux = { 196 + { 197 + [0] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 198 + [1] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 199 + [4] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 200 + [5] = { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 201 + } 202 + }; 203 + 204 + 205 + static const struct clockgen_muxinfo clockgen2_cmux_cga = { 206 + { 207 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 208 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 209 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 }, 210 + {}, 211 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 212 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 213 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 }, 214 + {}, 215 + { CLKSEL_VALID, CGA_PLL3, PLL_DIV1 }, 216 + { CLKSEL_VALID, CGA_PLL3, PLL_DIV2 }, 217 + { CLKSEL_VALID, CGA_PLL3, PLL_DIV4 }, 218 + }, 219 + }; 220 + 221 + static const struct clockgen_muxinfo clockgen2_cmux_cga12 = { 222 + { 223 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 224 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 225 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 }, 226 + {}, 227 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 228 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 229 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 }, 230 + }, 231 + }; 232 + 233 + static const struct clockgen_muxinfo clockgen2_cmux_cgb = { 234 + { 235 + { CLKSEL_VALID, CGB_PLL1, PLL_DIV1 }, 236 + { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 }, 237 + { CLKSEL_VALID, CGB_PLL1, PLL_DIV4 }, 238 + {}, 239 + { CLKSEL_VALID, CGB_PLL2, PLL_DIV1 }, 240 + { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 }, 241 + { CLKSEL_VALID, CGB_PLL2, PLL_DIV4 }, 242 + }, 243 + }; 244 + 245 + static const struct clockgen_muxinfo ls1043a_hwa1 = { 246 + { 247 + {}, 248 + {}, 249 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 250 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 }, 251 + {}, 252 + {}, 253 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 254 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 }, 255 + }, 256 + }; 257 + 258 + static const struct clockgen_muxinfo ls1043a_hwa2 = { 259 + { 260 + {}, 261 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 262 + {}, 263 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 }, 264 + }, 265 + }; 266 + 267 + static const struct clockgen_muxinfo t1023_hwa1 = { 268 + { 269 + {}, 270 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 271 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 272 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 }, 273 + }, 274 + }; 275 + 276 + static const struct clockgen_muxinfo t1023_hwa2 = { 277 + { 278 + [6] = { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 279 + }, 280 + }; 281 + 282 + static const struct clockgen_muxinfo t2080_hwa1 = { 283 + { 284 + {}, 285 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 286 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 287 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 }, 288 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 }, 289 + { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 }, 290 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 291 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 }, 292 + }, 293 + }; 294 + 295 + static const struct clockgen_muxinfo t2080_hwa2 = { 296 + { 297 + {}, 298 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV1 }, 299 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 300 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 }, 301 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV4 }, 302 + { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 }, 303 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 304 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 }, 305 + }, 306 + }; 307 + 308 + static const struct clockgen_muxinfo t4240_hwa1 = { 309 + { 310 + { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV2 }, 311 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV1 }, 312 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV2 }, 313 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV3 }, 314 + { CLKSEL_VALID, CGA_PLL1, PLL_DIV4 }, 315 + {}, 316 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV2 }, 317 + { CLKSEL_VALID, CGA_PLL2, PLL_DIV3 }, 318 + }, 319 + }; 320 + 321 + static const struct clockgen_muxinfo t4240_hwa4 = { 322 + { 323 + [2] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 }, 324 + [3] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV3 }, 325 + [4] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV4 }, 326 + [5] = { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 }, 327 + [6] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 }, 328 + }, 329 + }; 330 + 331 + static const struct clockgen_muxinfo t4240_hwa5 = { 332 + { 333 + [2] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV2 }, 334 + [3] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV3 }, 335 + [4] = { CLKSEL_VALID, CGB_PLL2, PLL_DIV4 }, 336 + [5] = { CLKSEL_VALID, PLATFORM_PLL, PLL_DIV1 }, 337 + [6] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV2 }, 338 + [7] = { CLKSEL_VALID, CGB_PLL1, PLL_DIV3 }, 339 + }, 340 + }; 341 + 342 + #define RCWSR7_FM1_CLK_SEL 0x40000000 343 + #define RCWSR7_FM2_CLK_SEL 0x20000000 344 + #define RCWSR7_HWA_ASYNC_DIV 0x04000000 345 + 346 + static void __init p2041_init_periph(struct clockgen *cg) 347 + { 348 + u32 reg; 349 + 350 + reg = ioread32be(&cg->guts->rcwsr[7]); 351 + 352 + if (reg & RCWSR7_FM1_CLK_SEL) 353 + cg->fman[0] = cg->pll[CGA_PLL2].div[PLL_DIV2].clk; 354 + else 355 + cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk; 356 + } 357 + 358 + static void __init p4080_init_periph(struct clockgen *cg) 359 + { 360 + u32 reg; 361 + 362 + reg = ioread32be(&cg->guts->rcwsr[7]); 363 + 364 + if (reg & RCWSR7_FM1_CLK_SEL) 365 + cg->fman[0] = cg->pll[CGA_PLL3].div[PLL_DIV2].clk; 366 + else 367 + cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk; 368 + 369 + if (reg & RCWSR7_FM2_CLK_SEL) 370 + cg->fman[1] = cg->pll[CGA_PLL3].div[PLL_DIV2].clk; 371 + else 372 + cg->fman[1] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk; 373 + } 374 + 375 + static void __init p5020_init_periph(struct clockgen *cg) 376 + { 377 + u32 reg; 378 + int div = PLL_DIV2; 379 + 380 + reg = ioread32be(&cg->guts->rcwsr[7]); 381 + if (reg & RCWSR7_HWA_ASYNC_DIV) 382 + div = PLL_DIV4; 383 + 384 + if (reg & RCWSR7_FM1_CLK_SEL) 385 + cg->fman[0] = cg->pll[CGA_PLL2].div[div].clk; 386 + else 387 + cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk; 388 + } 389 + 390 + static void __init p5040_init_periph(struct clockgen *cg) 391 + { 392 + u32 reg; 393 + int div = PLL_DIV2; 394 + 395 + reg = ioread32be(&cg->guts->rcwsr[7]); 396 + if (reg & RCWSR7_HWA_ASYNC_DIV) 397 + div = PLL_DIV4; 398 + 399 + if (reg & RCWSR7_FM1_CLK_SEL) 400 + cg->fman[0] = cg->pll[CGA_PLL3].div[div].clk; 401 + else 402 + cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk; 403 + 404 + if (reg & RCWSR7_FM2_CLK_SEL) 405 + cg->fman[1] = cg->pll[CGA_PLL3].div[div].clk; 406 + else 407 + cg->fman[1] = cg->pll[PLATFORM_PLL].div[PLL_DIV2].clk; 408 + } 409 + 410 + static void __init t1023_init_periph(struct clockgen *cg) 411 + { 412 + cg->fman[0] = cg->hwaccel[1]; 413 + } 414 + 415 + static void __init t1040_init_periph(struct clockgen *cg) 416 + { 417 + cg->fman[0] = cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk; 418 + } 419 + 420 + static void __init t2080_init_periph(struct clockgen *cg) 421 + { 422 + cg->fman[0] = cg->hwaccel[0]; 423 + } 424 + 425 + static void __init t4240_init_periph(struct clockgen *cg) 426 + { 427 + cg->fman[0] = cg->hwaccel[3]; 428 + cg->fman[1] = cg->hwaccel[4]; 429 + } 430 + 431 + static const struct clockgen_chipinfo chipinfo[] = { 432 + { 433 + .compat = "fsl,b4420-clockgen", 434 + .guts_compat = "fsl,b4860-device-config", 435 + .init_periph = t2080_init_periph, 436 + .cmux_groups = { 437 + &clockgen2_cmux_cga12, &clockgen2_cmux_cgb 438 + }, 439 + .hwaccel = { 440 + &t2080_hwa1 441 + }, 442 + .cmux_to_group = { 443 + 0, 1, 1, 1, -1 444 + }, 445 + .pll_mask = 0x3f, 446 + .flags = CG_PLL_8BIT, 447 + }, 448 + { 449 + .compat = "fsl,b4860-clockgen", 450 + .guts_compat = "fsl,b4860-device-config", 451 + .init_periph = t2080_init_periph, 452 + .cmux_groups = { 453 + &clockgen2_cmux_cga12, &clockgen2_cmux_cgb 454 + }, 455 + .hwaccel = { 456 + &t2080_hwa1 457 + }, 458 + .cmux_to_group = { 459 + 0, 1, 1, 1, -1 460 + }, 461 + .pll_mask = 0x3f, 462 + .flags = CG_PLL_8BIT, 463 + }, 464 + { 465 + .compat = "fsl,ls1021a-clockgen", 466 + .cmux_groups = { 467 + &t1023_cmux 468 + }, 469 + .cmux_to_group = { 470 + 0, -1 471 + }, 472 + .pll_mask = 0x03, 473 + }, 474 + { 475 + .compat = "fsl,ls1043a-clockgen", 476 + .init_periph = t2080_init_periph, 477 + .cmux_groups = { 478 + &t1040_cmux 479 + }, 480 + .hwaccel = { 481 + &ls1043a_hwa1, &ls1043a_hwa2 482 + }, 483 + .cmux_to_group = { 484 + 0, -1 485 + }, 486 + .pll_mask = 0x07, 487 + .flags = CG_PLL_8BIT, 488 + }, 489 + { 490 + .compat = "fsl,ls2080a-clockgen", 491 + .cmux_groups = { 492 + &clockgen2_cmux_cga12, &clockgen2_cmux_cgb 493 + }, 494 + .cmux_to_group = { 495 + 0, 0, 1, 1, -1 496 + }, 497 + .pll_mask = 0x37, 498 + .flags = CG_VER3 | CG_LITTLE_ENDIAN, 499 + }, 500 + { 501 + .compat = "fsl,p2041-clockgen", 502 + .guts_compat = "fsl,qoriq-device-config-1.0", 503 + .init_periph = p2041_init_periph, 504 + .cmux_groups = { 505 + &p2041_cmux_grp1, &p2041_cmux_grp2 506 + }, 507 + .cmux_to_group = { 508 + 0, 0, 1, 1, -1 509 + }, 510 + .pll_mask = 0x07, 511 + }, 512 + { 513 + .compat = "fsl,p3041-clockgen", 514 + .guts_compat = "fsl,qoriq-device-config-1.0", 515 + .init_periph = p2041_init_periph, 516 + .cmux_groups = { 517 + &p2041_cmux_grp1, &p2041_cmux_grp2 518 + }, 519 + .cmux_to_group = { 520 + 0, 0, 1, 1, -1 521 + }, 522 + .pll_mask = 0x07, 523 + }, 524 + { 525 + .compat = "fsl,p4080-clockgen", 526 + .guts_compat = "fsl,qoriq-device-config-1.0", 527 + .init_periph = p4080_init_periph, 528 + .cmux_groups = { 529 + &p4080_cmux_grp1, &p4080_cmux_grp2 530 + }, 531 + .cmux_to_group = { 532 + 0, 0, 0, 0, 1, 1, 1, 1 533 + }, 534 + .pll_mask = 0x1f, 535 + }, 536 + { 537 + .compat = "fsl,p5020-clockgen", 538 + .guts_compat = "fsl,qoriq-device-config-1.0", 539 + .init_periph = p5020_init_periph, 540 + .cmux_groups = { 541 + &p2041_cmux_grp1, &p2041_cmux_grp2 542 + }, 543 + .cmux_to_group = { 544 + 0, 1, -1 545 + }, 546 + .pll_mask = 0x07, 547 + }, 548 + { 549 + .compat = "fsl,p5040-clockgen", 550 + .guts_compat = "fsl,p5040-device-config", 551 + .init_periph = p5040_init_periph, 552 + .cmux_groups = { 553 + &p5040_cmux_grp1, &p5040_cmux_grp2 554 + }, 555 + .cmux_to_group = { 556 + 0, 0, 1, 1, -1 557 + }, 558 + .pll_mask = 0x0f, 559 + }, 560 + { 561 + .compat = "fsl,t1023-clockgen", 562 + .guts_compat = "fsl,t1023-device-config", 563 + .init_periph = t1023_init_periph, 564 + .cmux_groups = { 565 + &t1023_cmux 566 + }, 567 + .hwaccel = { 568 + &t1023_hwa1, &t1023_hwa2 569 + }, 570 + .cmux_to_group = { 571 + 0, 0, -1 572 + }, 573 + .pll_mask = 0x03, 574 + .flags = CG_PLL_8BIT, 575 + }, 576 + { 577 + .compat = "fsl,t1040-clockgen", 578 + .guts_compat = "fsl,t1040-device-config", 579 + .init_periph = t1040_init_periph, 580 + .cmux_groups = { 581 + &t1040_cmux 582 + }, 583 + .cmux_to_group = { 584 + 0, 0, 0, 0, -1 585 + }, 586 + .pll_mask = 0x07, 587 + .flags = CG_PLL_8BIT, 588 + }, 589 + { 590 + .compat = "fsl,t2080-clockgen", 591 + .guts_compat = "fsl,t2080-device-config", 592 + .init_periph = t2080_init_periph, 593 + .cmux_groups = { 594 + &clockgen2_cmux_cga12 595 + }, 596 + .hwaccel = { 597 + &t2080_hwa1, &t2080_hwa2 598 + }, 599 + .cmux_to_group = { 600 + 0, -1 601 + }, 602 + .pll_mask = 0x07, 603 + .flags = CG_PLL_8BIT, 604 + }, 605 + { 606 + .compat = "fsl,t4240-clockgen", 607 + .guts_compat = "fsl,t4240-device-config", 608 + .init_periph = t4240_init_periph, 609 + .cmux_groups = { 610 + &clockgen2_cmux_cga, &clockgen2_cmux_cgb 611 + }, 612 + .hwaccel = { 613 + &t4240_hwa1, NULL, NULL, &t4240_hwa4, &t4240_hwa5 614 + }, 615 + .cmux_to_group = { 616 + 0, 0, 1, -1 617 + }, 618 + .pll_mask = 0x3f, 619 + .flags = CG_PLL_8BIT, 620 + }, 621 + {}, 622 + }; 623 + 624 + struct mux_hwclock { 625 + struct clk_hw hw; 626 + struct clockgen *cg; 627 + const struct clockgen_muxinfo *info; 628 + u32 __iomem *reg; 629 + u8 parent_to_clksel[NUM_MUX_PARENTS]; 630 + s8 clksel_to_parent[NUM_MUX_PARENTS]; 631 + int num_parents; 632 + }; 633 + 634 + #define to_mux_hwclock(p) container_of(p, struct mux_hwclock, hw) 635 + #define CLKSEL_MASK 0x78000000 636 + #define CLKSEL_SHIFT 27 637 + 638 + static int mux_set_parent(struct clk_hw *hw, u8 idx) 639 + { 640 + struct mux_hwclock *hwc = to_mux_hwclock(hw); 39 641 u32 clksel; 40 642 41 - clksel = ((idx / clk->clk_per_pll) << 2) + idx % clk->clk_per_pll; 42 - if (clk->flags & CLKSEL_ADJUST) 43 - clksel += 8; 44 - clksel = (clksel & 0xf) << CLKSEL_SHIFT; 45 - iowrite32be(clksel, clk->reg); 643 + if (idx >= hwc->num_parents) 644 + return -EINVAL; 645 + 646 + clksel = hwc->parent_to_clksel[idx]; 647 + cg_out(hwc->cg, (clksel << CLKSEL_SHIFT) & CLKSEL_MASK, hwc->reg); 46 648 47 649 return 0; 48 650 } 49 651 50 - static u8 cmux_get_parent(struct clk_hw *hw) 652 + static u8 mux_get_parent(struct clk_hw *hw) 51 653 { 52 - struct cmux_clk *clk = to_cmux_clk(hw); 654 + struct mux_hwclock *hwc = to_mux_hwclock(hw); 53 655 u32 clksel; 656 + s8 ret; 54 657 55 - clksel = ioread32be(clk->reg); 56 - clksel = (clksel >> CLKSEL_SHIFT) & 0xf; 57 - if (clk->flags & CLKSEL_ADJUST) 58 - clksel -= 8; 59 - clksel = (clksel >> 2) * clk->clk_per_pll + clksel % 4; 658 + clksel = (cg_in(hwc->cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT; 60 659 61 - return clksel; 660 + ret = hwc->clksel_to_parent[clksel]; 661 + if (ret < 0) { 662 + pr_err("%s: mux at %p has bad clksel\n", __func__, hwc->reg); 663 + return 0; 664 + } 665 + 666 + return ret; 62 667 } 63 668 64 669 static const struct clk_ops cmux_ops = { 65 - .get_parent = cmux_get_parent, 66 - .set_parent = cmux_set_parent, 670 + .get_parent = mux_get_parent, 671 + .set_parent = mux_set_parent, 67 672 }; 68 673 674 + /* 675 + * Don't allow setting for now, as the clock options haven't been 676 + * sanitized for additional restrictions. 677 + */ 678 + static const struct clk_ops hwaccel_ops = { 679 + .get_parent = mux_get_parent, 680 + }; 681 + 682 + static const struct clockgen_pll_div *get_pll_div(struct clockgen *cg, 683 + struct mux_hwclock *hwc, 684 + int idx) 685 + { 686 + int pll, div; 687 + 688 + if (!(hwc->info->clksel[idx].flags & CLKSEL_VALID)) 689 + return NULL; 690 + 691 + pll = hwc->info->clksel[idx].pll; 692 + div = hwc->info->clksel[idx].div; 693 + 694 + return &cg->pll[pll].div[div]; 695 + } 696 + 697 + static struct clk * __init create_mux_common(struct clockgen *cg, 698 + struct mux_hwclock *hwc, 699 + const struct clk_ops *ops, 700 + unsigned long min_rate, 701 + unsigned long pct80_rate, 702 + const char *fmt, int idx) 703 + { 704 + struct clk_init_data init = {}; 705 + struct clk *clk; 706 + const struct clockgen_pll_div *div; 707 + const char *parent_names[NUM_MUX_PARENTS]; 708 + char name[32]; 709 + int i, j; 710 + 711 + snprintf(name, sizeof(name), fmt, idx); 712 + 713 + for (i = 0, j = 0; i < NUM_MUX_PARENTS; i++) { 714 + unsigned long rate; 715 + 716 + hwc->clksel_to_parent[i] = -1; 717 + 718 + div = get_pll_div(cg, hwc, i); 719 + if (!div) 720 + continue; 721 + 722 + rate = clk_get_rate(div->clk); 723 + 724 + if (hwc->info->clksel[i].flags & CLKSEL_80PCT && 725 + rate > pct80_rate) 726 + continue; 727 + if (rate < min_rate) 728 + continue; 729 + 730 + parent_names[j] = div->name; 731 + hwc->parent_to_clksel[j] = i; 732 + hwc->clksel_to_parent[i] = j; 733 + j++; 734 + } 735 + 736 + init.name = name; 737 + init.ops = ops; 738 + init.parent_names = parent_names; 739 + init.num_parents = hwc->num_parents = j; 740 + init.flags = 0; 741 + hwc->hw.init = &init; 742 + hwc->cg = cg; 743 + 744 + clk = clk_register(NULL, &hwc->hw); 745 + if (IS_ERR(clk)) { 746 + pr_err("%s: Couldn't register %s: %ld\n", __func__, name, 747 + PTR_ERR(clk)); 748 + kfree(hwc); 749 + return NULL; 750 + } 751 + 752 + return clk; 753 + } 754 + 755 + static struct clk * __init create_one_cmux(struct clockgen *cg, int idx) 756 + { 757 + struct mux_hwclock *hwc; 758 + const struct clockgen_pll_div *div; 759 + unsigned long plat_rate, min_rate; 760 + u64 pct80_rate; 761 + u32 clksel; 762 + 763 + hwc = kzalloc(sizeof(*hwc), GFP_KERNEL); 764 + if (!hwc) 765 + return NULL; 766 + 767 + hwc->reg = cg->regs + 0x20 * idx; 768 + hwc->info = cg->info.cmux_groups[cg->info.cmux_to_group[idx]]; 769 + 770 + /* 771 + * Find the rate for the default clksel, and treat it as the 772 + * maximum rated core frequency. If this is an incorrect 773 + * assumption, certain clock options (possibly including the 774 + * default clksel) may be inappropriately excluded on certain 775 + * chips. 776 + */ 777 + clksel = (cg_in(cg, hwc->reg) & CLKSEL_MASK) >> CLKSEL_SHIFT; 778 + div = get_pll_div(cg, hwc, clksel); 779 + if (!div) 780 + return NULL; 781 + 782 + pct80_rate = clk_get_rate(div->clk); 783 + pct80_rate *= 8; 784 + do_div(pct80_rate, 10); 785 + 786 + plat_rate = clk_get_rate(cg->pll[PLATFORM_PLL].div[PLL_DIV1].clk); 787 + 788 + if (cg->info.flags & CG_CMUX_GE_PLAT) 789 + min_rate = plat_rate; 790 + else 791 + min_rate = plat_rate / 2; 792 + 793 + return create_mux_common(cg, hwc, &cmux_ops, min_rate, 794 + pct80_rate, "cg-cmux%d", idx); 795 + } 796 + 797 + static struct clk * __init create_one_hwaccel(struct clockgen *cg, int idx) 798 + { 799 + struct mux_hwclock *hwc; 800 + 801 + hwc = kzalloc(sizeof(*hwc), GFP_KERNEL); 802 + if (!hwc) 803 + return NULL; 804 + 805 + hwc->reg = cg->regs + 0x20 * idx + 0x10; 806 + hwc->info = cg->info.hwaccel[idx]; 807 + 808 + return create_mux_common(cg, hwc, &hwaccel_ops, 0, 0, 809 + "cg-hwaccel%d", idx); 810 + } 811 + 812 + static void __init create_muxes(struct clockgen *cg) 813 + { 814 + int i; 815 + 816 + for (i = 0; i < ARRAY_SIZE(cg->cmux); i++) { 817 + if (cg->info.cmux_to_group[i] < 0) 818 + break; 819 + if (cg->info.cmux_to_group[i] >= 820 + ARRAY_SIZE(cg->info.cmux_groups)) { 821 + WARN_ON_ONCE(1); 822 + continue; 823 + } 824 + 825 + cg->cmux[i] = create_one_cmux(cg, i); 826 + } 827 + 828 + for (i = 0; i < ARRAY_SIZE(cg->hwaccel); i++) { 829 + if (!cg->info.hwaccel[i]) 830 + continue; 831 + 832 + cg->hwaccel[i] = create_one_hwaccel(cg, i); 833 + } 834 + } 835 + 836 + static void __init clockgen_init(struct device_node *np); 837 + 838 + /* Legacy nodes may get probed before the parent clockgen node */ 839 + static void __init legacy_init_clockgen(struct device_node *np) 840 + { 841 + if (!clockgen.node) 842 + clockgen_init(of_get_parent(np)); 843 + } 844 + 845 + /* Legacy node */ 69 846 static void __init core_mux_init(struct device_node *np) 70 847 { 71 848 struct clk *clk; 72 - struct clk_init_data init; 73 - struct cmux_clk *cmux_clk; 74 - struct device_node *node; 75 - int rc, count, i; 76 - u32 offset; 77 - const char *clk_name; 78 - const char **parent_names; 79 - struct of_phandle_args clkspec; 849 + struct resource res; 850 + int idx, rc; 80 851 81 - rc = of_property_read_u32(np, "reg", &offset); 82 - if (rc) { 83 - pr_err("%s: could not get reg property\n", np->name); 84 - return; 85 - } 852 + legacy_init_clockgen(np); 86 853 87 - /* get the input clock source count */ 88 - count = of_property_count_strings(np, "clock-names"); 89 - if (count < 0) { 90 - pr_err("%s: get clock count error\n", np->name); 91 - return; 92 - } 93 - parent_names = kcalloc(count, sizeof(char *), GFP_KERNEL); 94 - if (!parent_names) 854 + if (of_address_to_resource(np, 0, &res)) 95 855 return; 96 856 97 - for (i = 0; i < count; i++) 98 - parent_names[i] = of_clk_get_parent_name(np, i); 99 - 100 - cmux_clk = kzalloc(sizeof(*cmux_clk), GFP_KERNEL); 101 - if (!cmux_clk) 102 - goto err_name; 103 - 104 - cmux_clk->reg = of_iomap(np, 0); 105 - if (!cmux_clk->reg) { 106 - pr_err("%s: could not map register\n", __func__); 107 - goto err_clk; 108 - } 109 - 110 - rc = of_parse_phandle_with_args(np, "clocks", "#clock-cells", 0, 111 - &clkspec); 112 - if (rc) { 113 - pr_err("%s: parse clock node error\n", __func__); 114 - goto err_clk; 115 - } 116 - 117 - cmux_clk->clk_per_pll = of_property_count_strings(clkspec.np, 118 - "clock-output-names"); 119 - of_node_put(clkspec.np); 120 - 121 - node = of_find_compatible_node(NULL, NULL, "fsl,p4080-clockgen"); 122 - if (node && (offset >= 0x80)) 123 - cmux_clk->flags = CLKSEL_ADJUST; 124 - 125 - rc = of_property_read_string_index(np, "clock-output-names", 126 - 0, &clk_name); 127 - if (rc) { 128 - pr_err("%s: read clock names error\n", np->name); 129 - goto err_clk; 130 - } 131 - 132 - init.name = clk_name; 133 - init.ops = &cmux_ops; 134 - init.parent_names = parent_names; 135 - init.num_parents = count; 136 - init.flags = 0; 137 - cmux_clk->hw.init = &init; 138 - 139 - clk = clk_register(NULL, &cmux_clk->hw); 140 - if (IS_ERR(clk)) { 141 - pr_err("%s: could not register clock\n", clk_name); 142 - goto err_clk; 143 - } 857 + idx = (res.start & 0xf0) >> 5; 858 + clk = clockgen.cmux[idx]; 144 859 145 860 rc = of_clk_add_provider(np, of_clk_src_simple_get, clk); 146 861 if (rc) { 147 - pr_err("Could not register clock provider for node:%s\n", 148 - np->name); 149 - goto err_clk; 862 + pr_err("%s: Couldn't register clk provider for node %s: %d\n", 863 + __func__, np->name, rc); 864 + return; 150 865 } 151 - goto err_name; 152 - 153 - err_clk: 154 - kfree(cmux_clk); 155 - err_name: 156 - /* free *_names because they are reallocated when registered */ 157 - kfree(parent_names); 158 866 } 159 867 160 - static void __init core_pll_init(struct device_node *np) 868 + static struct clk *sysclk_from_fixed(struct device_node *node, const char *name) 161 869 { 162 - u32 mult; 163 - int i, rc, count; 164 - const char *clk_name, *parent_name; 165 - struct clk_onecell_data *onecell_data; 166 - struct clk **subclks; 167 - void __iomem *base; 870 + u32 rate; 168 871 169 - base = of_iomap(np, 0); 170 - if (!base) { 171 - pr_err("iomap error\n"); 872 + if (of_property_read_u32(node, "clock-frequency", &rate)) 873 + return ERR_PTR(-ENODEV); 874 + 875 + return clk_register_fixed_rate(NULL, name, NULL, CLK_IS_ROOT, rate); 876 + } 877 + 878 + static struct clk *sysclk_from_parent(const char *name) 879 + { 880 + struct clk *clk; 881 + const char *parent_name; 882 + 883 + clk = of_clk_get(clockgen.node, 0); 884 + if (IS_ERR(clk)) 885 + return clk; 886 + 887 + /* Register the input clock under the desired name. */ 888 + parent_name = __clk_get_name(clk); 889 + clk = clk_register_fixed_factor(NULL, name, parent_name, 890 + 0, 1, 1); 891 + if (IS_ERR(clk)) 892 + pr_err("%s: Couldn't register %s: %ld\n", __func__, name, 893 + PTR_ERR(clk)); 894 + 895 + return clk; 896 + } 897 + 898 + static struct clk * __init create_sysclk(const char *name) 899 + { 900 + struct device_node *sysclk; 901 + struct clk *clk; 902 + 903 + clk = sysclk_from_fixed(clockgen.node, name); 904 + if (!IS_ERR(clk)) 905 + return clk; 906 + 907 + clk = sysclk_from_parent(name); 908 + if (!IS_ERR(clk)) 909 + return clk; 910 + 911 + sysclk = of_get_child_by_name(clockgen.node, "sysclk"); 912 + if (sysclk) { 913 + clk = sysclk_from_fixed(sysclk, name); 914 + if (!IS_ERR(clk)) 915 + return clk; 916 + } 917 + 918 + pr_err("%s: No input clock\n", __func__); 919 + return NULL; 920 + } 921 + 922 + /* Legacy node */ 923 + static void __init sysclk_init(struct device_node *node) 924 + { 925 + struct clk *clk; 926 + 927 + legacy_init_clockgen(node); 928 + 929 + clk = clockgen.sysclk; 930 + if (clk) 931 + of_clk_add_provider(node, of_clk_src_simple_get, clk); 932 + } 933 + 934 + #define PLL_KILL BIT(31) 935 + 936 + static void __init create_one_pll(struct clockgen *cg, int idx) 937 + { 938 + u32 __iomem *reg; 939 + u32 mult; 940 + struct clockgen_pll *pll = &cg->pll[idx]; 941 + int i; 942 + 943 + if (!(cg->info.pll_mask & (1 << idx))) 944 + return; 945 + 946 + if (cg->info.flags & CG_VER3) { 947 + switch (idx) { 948 + case PLATFORM_PLL: 949 + reg = cg->regs + 0x60080; 950 + break; 951 + case CGA_PLL1: 952 + reg = cg->regs + 0x80; 953 + break; 954 + case CGA_PLL2: 955 + reg = cg->regs + 0xa0; 956 + break; 957 + case CGB_PLL1: 958 + reg = cg->regs + 0x10080; 959 + break; 960 + case CGB_PLL2: 961 + reg = cg->regs + 0x100a0; 962 + break; 963 + default: 964 + WARN_ONCE(1, "index %d\n", idx); 965 + return; 966 + } 967 + } else { 968 + if (idx == PLATFORM_PLL) 969 + reg = cg->regs + 0xc00; 970 + else 971 + reg = cg->regs + 0x800 + 0x20 * (idx - 1); 972 + } 973 + 974 + /* Get the multiple of PLL */ 975 + mult = cg_in(cg, reg); 976 + 977 + /* Check if this PLL is disabled */ 978 + if (mult & PLL_KILL) { 979 + pr_debug("%s(): pll %p disabled\n", __func__, reg); 172 980 return; 173 981 } 174 982 175 - /* get the multiple of PLL */ 176 - mult = ioread32be(base); 983 + if ((cg->info.flags & CG_VER3) || 984 + ((cg->info.flags & CG_PLL_8BIT) && idx != PLATFORM_PLL)) 985 + mult = (mult & GENMASK(8, 1)) >> 1; 986 + else 987 + mult = (mult & GENMASK(6, 1)) >> 1; 177 988 178 - /* check if this PLL is disabled */ 179 - if (mult & PLL_KILL) { 180 - pr_debug("PLL:%s is disabled\n", np->name); 181 - goto err_map; 989 + for (i = 0; i < ARRAY_SIZE(pll->div); i++) { 990 + struct clk *clk; 991 + 992 + snprintf(pll->div[i].name, sizeof(pll->div[i].name), 993 + "cg-pll%d-div%d", idx, i + 1); 994 + 995 + clk = clk_register_fixed_factor(NULL, 996 + pll->div[i].name, "cg-sysclk", 0, mult, i + 1); 997 + if (IS_ERR(clk)) { 998 + pr_err("%s: %s: register failed %ld\n", 999 + __func__, pll->div[i].name, PTR_ERR(clk)); 1000 + continue; 1001 + } 1002 + 1003 + pll->div[i].clk = clk; 182 1004 } 183 - mult = (mult >> 1) & 0x3f; 1005 + } 184 1006 185 - parent_name = of_clk_get_parent_name(np, 0); 186 - if (!parent_name) { 187 - pr_err("PLL: %s must have a parent\n", np->name); 188 - goto err_map; 189 - } 1007 + static void __init create_plls(struct clockgen *cg) 1008 + { 1009 + int i; 190 1010 1011 + for (i = 0; i < ARRAY_SIZE(cg->pll); i++) 1012 + create_one_pll(cg, i); 1013 + } 1014 + 1015 + static void __init legacy_pll_init(struct device_node *np, int idx) 1016 + { 1017 + struct clockgen_pll *pll; 1018 + struct clk_onecell_data *onecell_data; 1019 + struct clk **subclks; 1020 + int count, rc; 1021 + 1022 + legacy_init_clockgen(np); 1023 + 1024 + pll = &clockgen.pll[idx]; 191 1025 count = of_property_count_strings(np, "clock-output-names"); 192 - if (count < 0 || count > 4) { 193 - pr_err("%s: clock is not supported\n", np->name); 194 - goto err_map; 195 - } 196 1026 197 - subclks = kcalloc(count, sizeof(struct clk *), GFP_KERNEL); 1027 + BUILD_BUG_ON(ARRAY_SIZE(pll->div) < 4); 1028 + subclks = kcalloc(4, sizeof(struct clk *), GFP_KERNEL); 198 1029 if (!subclks) 199 - goto err_map; 1030 + return; 200 1031 201 1032 onecell_data = kmalloc(sizeof(*onecell_data), GFP_KERNEL); 202 1033 if (!onecell_data) 203 1034 goto err_clks; 204 1035 205 - for (i = 0; i < count; i++) { 206 - rc = of_property_read_string_index(np, "clock-output-names", 207 - i, &clk_name); 208 - if (rc) { 209 - pr_err("%s: could not get clock names\n", np->name); 210 - goto err_cell; 211 - } 212 - 213 - /* 214 - * when count == 4, there are 4 output clocks: 215 - * /1, /2, /3, /4 respectively 216 - * when count < 4, there are at least 2 output clocks: 217 - * /1, /2, (/4, if count == 3) respectively. 218 - */ 219 - if (count == 4) 220 - subclks[i] = clk_register_fixed_factor(NULL, clk_name, 221 - parent_name, 0, mult, 1 + i); 222 - else 223 - 224 - subclks[i] = clk_register_fixed_factor(NULL, clk_name, 225 - parent_name, 0, mult, 1 << i); 226 - 227 - if (IS_ERR(subclks[i])) { 228 - pr_err("%s: could not register clock\n", clk_name); 229 - goto err_cell; 230 - } 1036 + if (count <= 3) { 1037 + subclks[0] = pll->div[0].clk; 1038 + subclks[1] = pll->div[1].clk; 1039 + subclks[2] = pll->div[3].clk; 1040 + } else { 1041 + subclks[0] = pll->div[0].clk; 1042 + subclks[1] = pll->div[1].clk; 1043 + subclks[2] = pll->div[2].clk; 1044 + subclks[3] = pll->div[3].clk; 231 1045 } 232 1046 233 1047 onecell_data->clks = subclks; ··· 1051 233 1052 234 rc = of_clk_add_provider(np, of_clk_src_onecell_get, onecell_data); 1053 235 if (rc) { 1054 - pr_err("Could not register clk provider for node:%s\n", 1055 - np->name); 236 + pr_err("%s: Couldn't register clk provider for node %s: %d\n", 237 + __func__, np->name, rc); 1056 238 goto err_cell; 1057 239 } 1058 240 1059 - iounmap(base); 1060 241 return; 1061 242 err_cell: 1062 243 kfree(onecell_data); 1063 244 err_clks: 1064 245 kfree(subclks); 1065 - err_map: 1066 - iounmap(base); 1067 246 } 1068 247 1069 - static void __init sysclk_init(struct device_node *node) 1070 - { 1071 - struct clk *clk; 1072 - const char *clk_name = node->name; 1073 - struct device_node *np = of_get_parent(node); 1074 - u32 rate; 1075 - 1076 - if (!np) { 1077 - pr_err("could not get parent node\n"); 1078 - return; 1079 - } 1080 - 1081 - if (of_property_read_u32(np, "clock-frequency", &rate)) { 1082 - of_node_put(node); 1083 - return; 1084 - } 1085 - 1086 - of_property_read_string(np, "clock-output-names", &clk_name); 1087 - 1088 - clk = clk_register_fixed_rate(NULL, clk_name, NULL, CLK_IS_ROOT, rate); 1089 - if (!IS_ERR(clk)) 1090 - of_clk_add_provider(np, of_clk_src_simple_get, clk); 1091 - } 1092 - 248 + /* Legacy node */ 1093 249 static void __init pltfrm_pll_init(struct device_node *np) 1094 250 { 1095 - void __iomem *base; 1096 - uint32_t mult; 1097 - const char *parent_name, *clk_name; 1098 - int i, _errno; 1099 - struct clk_onecell_data *cod; 251 + legacy_pll_init(np, PLATFORM_PLL); 252 + } 1100 253 1101 - base = of_iomap(np, 0); 1102 - if (!base) { 254 + /* Legacy node */ 255 + static void __init core_pll_init(struct device_node *np) 256 + { 257 + struct resource res; 258 + int idx; 259 + 260 + if (of_address_to_resource(np, 0, &res)) 261 + return; 262 + 263 + if ((res.start & 0xfff) == 0xc00) { 264 + /* 265 + * ls1021a devtree labels the platform PLL 266 + * with the core PLL compatible 267 + */ 268 + pltfrm_pll_init(np); 269 + } else { 270 + idx = (res.start & 0xf0) >> 5; 271 + legacy_pll_init(np, CGA_PLL1 + idx); 272 + } 273 + } 274 + 275 + static struct clk *clockgen_clk_get(struct of_phandle_args *clkspec, void *data) 276 + { 277 + struct clockgen *cg = data; 278 + struct clk *clk; 279 + struct clockgen_pll *pll; 280 + u32 type, idx; 281 + 282 + if (clkspec->args_count < 2) { 283 + pr_err("%s: insufficient phandle args\n", __func__); 284 + return ERR_PTR(-EINVAL); 285 + } 286 + 287 + type = clkspec->args[0]; 288 + idx = clkspec->args[1]; 289 + 290 + switch (type) { 291 + case 0: 292 + if (idx != 0) 293 + goto bad_args; 294 + clk = cg->sysclk; 295 + break; 296 + case 1: 297 + if (idx >= ARRAY_SIZE(cg->cmux)) 298 + goto bad_args; 299 + clk = cg->cmux[idx]; 300 + break; 301 + case 2: 302 + if (idx >= ARRAY_SIZE(cg->hwaccel)) 303 + goto bad_args; 304 + clk = cg->hwaccel[idx]; 305 + break; 306 + case 3: 307 + if (idx >= ARRAY_SIZE(cg->fman)) 308 + goto bad_args; 309 + clk = cg->fman[idx]; 310 + break; 311 + case 4: 312 + pll = &cg->pll[PLATFORM_PLL]; 313 + if (idx >= ARRAY_SIZE(pll->div)) 314 + goto bad_args; 315 + clk = pll->div[idx].clk; 316 + break; 317 + default: 318 + goto bad_args; 319 + } 320 + 321 + if (!clk) 322 + return ERR_PTR(-ENOENT); 323 + return clk; 324 + 325 + bad_args: 326 + pr_err("%s: Bad phandle args %u %u\n", __func__, type, idx); 327 + return ERR_PTR(-EINVAL); 328 + } 329 + 330 + #ifdef CONFIG_PPC 331 + #include <asm/mpc85xx.h> 332 + 333 + static const u32 a4510_svrs[] __initconst = { 334 + (SVR_P2040 << 8) | 0x10, /* P2040 1.0 */ 335 + (SVR_P2040 << 8) | 0x11, /* P2040 1.1 */ 336 + (SVR_P2041 << 8) | 0x10, /* P2041 1.0 */ 337 + (SVR_P2041 << 8) | 0x11, /* P2041 1.1 */ 338 + (SVR_P3041 << 8) | 0x10, /* P3041 1.0 */ 339 + (SVR_P3041 << 8) | 0x11, /* P3041 1.1 */ 340 + (SVR_P4040 << 8) | 0x20, /* P4040 2.0 */ 341 + (SVR_P4080 << 8) | 0x20, /* P4080 2.0 */ 342 + (SVR_P5010 << 8) | 0x10, /* P5010 1.0 */ 343 + (SVR_P5010 << 8) | 0x20, /* P5010 2.0 */ 344 + (SVR_P5020 << 8) | 0x10, /* P5020 1.0 */ 345 + (SVR_P5021 << 8) | 0x10, /* P5021 1.0 */ 346 + (SVR_P5040 << 8) | 0x10, /* P5040 1.0 */ 347 + }; 348 + 349 + #define SVR_SECURITY 0x80000 /* The Security (E) bit */ 350 + 351 + static bool __init has_erratum_a4510(void) 352 + { 353 + u32 svr = mfspr(SPRN_SVR); 354 + int i; 355 + 356 + svr &= ~SVR_SECURITY; 357 + 358 + for (i = 0; i < ARRAY_SIZE(a4510_svrs); i++) { 359 + if (svr == a4510_svrs[i]) 360 + return true; 361 + } 362 + 363 + return false; 364 + } 365 + #else 366 + static bool __init has_erratum_a4510(void) 367 + { 368 + return false; 369 + } 370 + #endif 371 + 372 + static void __init clockgen_init(struct device_node *np) 373 + { 374 + int i, ret; 375 + bool is_old_ls1021a = false; 376 + 377 + /* May have already been called by a legacy probe */ 378 + if (clockgen.node) 379 + return; 380 + 381 + clockgen.node = np; 382 + clockgen.regs = of_iomap(np, 0); 383 + if (!clockgen.regs && 384 + of_device_is_compatible(of_root, "fsl,ls1021a")) { 385 + /* Compatibility hack for old, broken device trees */ 386 + clockgen.regs = ioremap(0x1ee1000, 0x1000); 387 + is_old_ls1021a = true; 388 + } 389 + if (!clockgen.regs) { 1103 390 pr_err("%s(): %s: of_iomap() failed\n", __func__, np->name); 1104 391 return; 1105 392 } 1106 393 1107 - /* Get the multiple of PLL */ 1108 - mult = ioread32be(base); 1109 - 1110 - iounmap(base); 1111 - 1112 - /* Check if this PLL is disabled */ 1113 - if (mult & PLL_KILL) { 1114 - pr_debug("%s(): %s: Disabled\n", __func__, np->name); 1115 - return; 1116 - } 1117 - mult = (mult & GENMASK(6, 1)) >> 1; 1118 - 1119 - parent_name = of_clk_get_parent_name(np, 0); 1120 - if (!parent_name) { 1121 - pr_err("%s(): %s: of_clk_get_parent_name() failed\n", 1122 - __func__, np->name); 1123 - return; 394 + for (i = 0; i < ARRAY_SIZE(chipinfo); i++) { 395 + if (of_device_is_compatible(np, chipinfo[i].compat)) 396 + break; 397 + if (is_old_ls1021a && 398 + !strcmp(chipinfo[i].compat, "fsl,ls1021a-clockgen")) 399 + break; 1124 400 } 1125 401 1126 - i = of_property_count_strings(np, "clock-output-names"); 1127 - if (i < 0) { 1128 - pr_err("%s(): %s: of_property_count_strings(clock-output-names) = %d\n", 1129 - __func__, np->name, i); 1130 - return; 402 + if (i == ARRAY_SIZE(chipinfo)) { 403 + pr_err("%s: unknown clockgen node %s\n", __func__, 404 + np->full_name); 405 + goto err; 1131 406 } 407 + clockgen.info = chipinfo[i]; 1132 408 1133 - cod = kmalloc(sizeof(*cod) + i * sizeof(struct clk *), GFP_KERNEL); 1134 - if (!cod) 1135 - return; 1136 - cod->clks = (struct clk **)(cod + 1); 1137 - cod->clk_num = i; 409 + if (clockgen.info.guts_compat) { 410 + struct device_node *guts; 1138 411 1139 - for (i = 0; i < cod->clk_num; i++) { 1140 - _errno = of_property_read_string_index(np, "clock-output-names", 1141 - i, &clk_name); 1142 - if (_errno < 0) { 1143 - pr_err("%s(): %s: of_property_read_string_index(clock-output-names) = %d\n", 1144 - __func__, np->name, _errno); 1145 - goto return_clk_unregister; 412 + guts = of_find_compatible_node(NULL, NULL, 413 + clockgen.info.guts_compat); 414 + if (guts) { 415 + clockgen.guts = of_iomap(guts, 0); 416 + if (!clockgen.guts) { 417 + pr_err("%s: Couldn't map %s regs\n", __func__, 418 + guts->full_name); 419 + } 1146 420 } 1147 421 1148 - cod->clks[i] = clk_register_fixed_factor(NULL, clk_name, 1149 - parent_name, 0, mult, 1 + i); 1150 - if (IS_ERR(cod->clks[i])) { 1151 - pr_err("%s(): %s: clk_register_fixed_factor(%s) = %ld\n", 1152 - __func__, np->name, 1153 - clk_name, PTR_ERR(cod->clks[i])); 1154 - goto return_clk_unregister; 1155 - } 1156 422 } 1157 423 1158 - _errno = of_clk_add_provider(np, of_clk_src_onecell_get, cod); 1159 - if (_errno < 0) { 1160 - pr_err("%s(): %s: of_clk_add_provider() = %d\n", 1161 - __func__, np->name, _errno); 1162 - goto return_clk_unregister; 424 + if (has_erratum_a4510()) 425 + clockgen.info.flags |= CG_CMUX_GE_PLAT; 426 + 427 + clockgen.sysclk = create_sysclk("cg-sysclk"); 428 + create_plls(&clockgen); 429 + create_muxes(&clockgen); 430 + 431 + if (clockgen.info.init_periph) 432 + clockgen.info.init_periph(&clockgen); 433 + 434 + ret = of_clk_add_provider(np, clockgen_clk_get, &clockgen); 435 + if (ret) { 436 + pr_err("%s: Couldn't register clk provider for node %s: %d\n", 437 + __func__, np->name, ret); 1163 438 } 1164 439 1165 440 return; 1166 - 1167 - return_clk_unregister: 1168 - while (--i >= 0) 1169 - clk_unregister(cod->clks[i]); 1170 - kfree(cod); 441 + err: 442 + iounmap(clockgen.regs); 443 + clockgen.regs = NULL; 1171 444 } 1172 445 446 + CLK_OF_DECLARE(qoriq_clockgen_1, "fsl,qoriq-clockgen-1.0", clockgen_init); 447 + CLK_OF_DECLARE(qoriq_clockgen_2, "fsl,qoriq-clockgen-2.0", clockgen_init); 448 + CLK_OF_DECLARE(qoriq_clockgen_ls1021a, "fsl,ls1021a-clockgen", clockgen_init); 449 + CLK_OF_DECLARE(qoriq_clockgen_ls1043a, "fsl,ls1043a-clockgen", clockgen_init); 450 + CLK_OF_DECLARE(qoriq_clockgen_ls2080a, "fsl,ls2080a-clockgen", clockgen_init); 451 + 452 + /* Legacy nodes */ 1173 453 CLK_OF_DECLARE(qoriq_sysclk_1, "fsl,qoriq-sysclk-1.0", sysclk_init); 1174 454 CLK_OF_DECLARE(qoriq_sysclk_2, "fsl,qoriq-sysclk-2.0", sysclk_init); 1175 455 CLK_OF_DECLARE(qoriq_core_pll_1, "fsl,qoriq-core-pll-1.0", core_pll_init);
+1 -1
drivers/iommu/fsl_pamu.c
··· 20 20 21 21 #include "fsl_pamu.h" 22 22 23 + #include <linux/fsl/guts.h> 23 24 #include <linux/interrupt.h> 24 25 #include <linux/genalloc.h> 25 26 26 27 #include <asm/mpc85xx.h> 27 - #include <asm/fsl_guts.h> 28 28 29 29 /* define indexes for each operation mapping scenario */ 30 30 #define OMI_QMAN 0x00
+1 -1
sound/soc/fsl/mpc8610_hpcd.c
··· 12 12 13 13 #include <linux/module.h> 14 14 #include <linux/interrupt.h> 15 + #include <linux/fsl/guts.h> 15 16 #include <linux/of_address.h> 16 17 #include <linux/of_device.h> 17 18 #include <linux/slab.h> 18 19 #include <sound/soc.h> 19 - #include <asm/fsl_guts.h> 20 20 21 21 #include "fsl_dma.h" 22 22 #include "fsl_ssi.h"
+1 -1
sound/soc/fsl/p1022_ds.c
··· 11 11 */ 12 12 13 13 #include <linux/module.h> 14 + #include <linux/fsl/guts.h> 14 15 #include <linux/interrupt.h> 15 16 #include <linux/of_address.h> 16 17 #include <linux/of_device.h> 17 18 #include <linux/slab.h> 18 19 #include <sound/soc.h> 19 - #include <asm/fsl_guts.h> 20 20 21 21 #include "fsl_dma.h" 22 22 #include "fsl_ssi.h"
+1 -1
sound/soc/fsl/p1022_rdk.c
··· 18 18 */ 19 19 20 20 #include <linux/module.h> 21 + #include <linux/fsl/guts.h> 21 22 #include <linux/interrupt.h> 22 23 #include <linux/of_address.h> 23 24 #include <linux/of_device.h> 24 25 #include <linux/slab.h> 25 26 #include <sound/soc.h> 26 - #include <asm/fsl_guts.h> 27 27 28 28 #include "fsl_dma.h" 29 29 #include "fsl_ssi.h"