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

ARM: Kirkwood: Replace clock gating

Add a varient of the basic clk-gate code. This variant calls a
function before gating the clock off. This function is used to disable
the SATA or PCIe PHY.

Now that all the drivers prepare and enable there clk as needed, there
is no need for the common code to keep track of which clocks need
gating on. Let the common clock framework turn off clocks which are
not used.

Buy using the added clk varient, when the clk framework turns off SATA
or PCIe clocks, we also disabled SATA and PCIe PHYs which were not
needed.

The function kirkwood_pcie_id() can now be called outside of __init
code, so remove this property for it, and functions it calls.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Tested-by: Jamie Lentin <jm@lentin.co.uk>
Signed-off-by: Mike Turquette <mturquette@linaro.org>

authored by

Andrew Lunn and committed by
Mike Turquette
98d9986c e919c716

+129 -92
+126 -86
arch/arm/mach-kirkwood/common.c
··· 63 63 iotable_init(kirkwood_io_desc, ARRAY_SIZE(kirkwood_io_desc)); 64 64 } 65 65 66 - /* 67 - * Default clock control bits. Any bit _not_ set in this variable 68 - * will be cleared from the hardware after platform devices have been 69 - * registered. Some reserved bits must be set to 1. 70 - */ 71 - unsigned int kirkwood_clk_ctrl = CGC_DUNIT | CGC_RESERVED; 72 - 73 - 74 66 /***************************************************************************** 75 67 * CLK tree 76 68 ****************************************************************************/ 69 + 70 + static void disable_sata0(void) 71 + { 72 + /* Disable PLL and IVREF */ 73 + writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2); 74 + /* Disable PHY */ 75 + writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL); 76 + } 77 + 78 + static void disable_sata1(void) 79 + { 80 + /* Disable PLL and IVREF */ 81 + writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2); 82 + /* Disable PHY */ 83 + writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL); 84 + } 85 + 86 + static void disable_pcie0(void) 87 + { 88 + writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL); 89 + while (1) 90 + if (readl(PCIE_STATUS) & 0x1) 91 + break; 92 + writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL); 93 + } 94 + 95 + static void disable_pcie1(void) 96 + { 97 + u32 dev, rev; 98 + 99 + kirkwood_pcie_id(&dev, &rev); 100 + 101 + if (dev == MV88F6282_DEV_ID) { 102 + writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL); 103 + while (1) 104 + if (readl(PCIE1_STATUS) & 0x1) 105 + break; 106 + writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL); 107 + } 108 + } 109 + 110 + /* An extended version of the gated clk. This calls fn() before 111 + * disabling the clock. We use this to turn off PHYs etc. */ 112 + struct clk_gate_fn { 113 + struct clk_gate gate; 114 + void (*fn)(void); 115 + }; 116 + 117 + #define to_clk_gate_fn(_gate) container_of(_gate, struct clk_gate_fn, gate) 118 + #define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw) 119 + 120 + static void clk_gate_fn_disable(struct clk_hw *hw) 121 + { 122 + struct clk_gate *gate = to_clk_gate(hw); 123 + struct clk_gate_fn *gate_fn = to_clk_gate_fn(gate); 124 + 125 + if (gate_fn->fn) 126 + gate_fn->fn(); 127 + 128 + clk_gate_ops.disable(hw); 129 + } 130 + 131 + static struct clk_ops clk_gate_fn_ops; 132 + 133 + static struct clk __init *clk_register_gate_fn(struct device *dev, 134 + const char *name, 135 + const char *parent_name, unsigned long flags, 136 + void __iomem *reg, u8 bit_idx, 137 + u8 clk_gate_flags, spinlock_t *lock, 138 + void (*fn)(void)) 139 + { 140 + struct clk_gate_fn *gate_fn; 141 + struct clk *clk; 142 + struct clk_init_data init; 143 + 144 + gate_fn = kzalloc(sizeof(struct clk_gate_fn), GFP_KERNEL); 145 + if (!gate_fn) { 146 + pr_err("%s: could not allocate gated clk\n", __func__); 147 + return ERR_PTR(-ENOMEM); 148 + } 149 + 150 + init.name = name; 151 + init.ops = &clk_gate_fn_ops; 152 + init.flags = flags; 153 + init.parent_names = (parent_name ? &parent_name : NULL); 154 + init.num_parents = (parent_name ? 1 : 0); 155 + 156 + /* struct clk_gate assignments */ 157 + gate_fn->gate.reg = reg; 158 + gate_fn->gate.bit_idx = bit_idx; 159 + gate_fn->gate.flags = clk_gate_flags; 160 + gate_fn->gate.lock = lock; 161 + gate_fn->gate.hw.init = &init; 162 + 163 + /* ops is the gate ops, but with our disable function */ 164 + if (clk_gate_fn_ops.disable != clk_gate_fn_disable) { 165 + clk_gate_fn_ops = clk_gate_ops; 166 + clk_gate_fn_ops.disable = clk_gate_fn_disable; 167 + } 168 + 169 + clk = clk_register(dev, &gate_fn->gate.hw); 170 + 171 + if (IS_ERR(clk)) 172 + kfree(gate_fn); 173 + 174 + return clk; 175 + } 176 + 77 177 static DEFINE_SPINLOCK(gating_lock); 78 178 static struct clk *tclk; 79 179 80 180 static struct clk __init *kirkwood_register_gate(const char *name, u8 bit_idx) 81 181 { 82 - return clk_register_gate(NULL, name, "tclk", CLK_IGNORE_UNUSED, 182 + return clk_register_gate(NULL, name, "tclk", 0, 83 183 (void __iomem *)CLOCK_GATING_CTRL, 84 184 bit_idx, 0, &gating_lock); 185 + } 186 + 187 + static struct clk __init *kirkwood_register_gate_fn(const char *name, 188 + u8 bit_idx, 189 + void (*fn)(void)) 190 + { 191 + return clk_register_gate_fn(NULL, name, "tclk", 0, 192 + (void __iomem *)CLOCK_GATING_CTRL, 193 + bit_idx, 0, &gating_lock, fn); 85 194 } 86 195 87 196 void __init kirkwood_clk_init(void) ··· 204 95 runit = kirkwood_register_gate("runit", CGC_BIT_RUNIT); 205 96 ge0 = kirkwood_register_gate("ge0", CGC_BIT_GE0); 206 97 ge1 = kirkwood_register_gate("ge1", CGC_BIT_GE1); 207 - sata0 = kirkwood_register_gate("sata0", CGC_BIT_SATA0); 208 - sata1 = kirkwood_register_gate("sata1", CGC_BIT_SATA1); 98 + sata0 = kirkwood_register_gate_fn("sata0", CGC_BIT_SATA0, 99 + disable_sata0); 100 + sata1 = kirkwood_register_gate_fn("sata1", CGC_BIT_SATA1, 101 + disable_sata1); 209 102 usb0 = kirkwood_register_gate("usb0", CGC_BIT_USB0); 210 103 sdio = kirkwood_register_gate("sdio", CGC_BIT_SDIO); 211 104 crypto = kirkwood_register_gate("crypto", CGC_BIT_CRYPTO); 212 105 xor0 = kirkwood_register_gate("xor0", CGC_BIT_XOR0); 213 106 xor1 = kirkwood_register_gate("xor1", CGC_BIT_XOR1); 214 - pex0 = kirkwood_register_gate("pex0", CGC_BIT_PEX0); 215 - pex1 = kirkwood_register_gate("pex1", CGC_BIT_PEX1); 107 + pex0 = kirkwood_register_gate_fn("pex0", CGC_BIT_PEX0, 108 + disable_pcie0); 109 + pex1 = kirkwood_register_gate_fn("pex1", CGC_BIT_PEX1, 110 + disable_pcie1); 216 111 audio = kirkwood_register_gate("audio", CGC_BIT_AUDIO); 217 112 kirkwood_register_gate("tdm", CGC_BIT_TDM); 218 113 kirkwood_register_gate("tsu", CGC_BIT_TSU); ··· 245 132 ****************************************************************************/ 246 133 void __init kirkwood_ehci_init(void) 247 134 { 248 - kirkwood_clk_ctrl |= CGC_USB0; 249 135 orion_ehci_init(USB_PHYS_BASE, IRQ_KIRKWOOD_USB, EHCI_PHY_NA); 250 136 } 251 137 ··· 254 142 ****************************************************************************/ 255 143 void __init kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data) 256 144 { 257 - kirkwood_clk_ctrl |= CGC_GE0; 258 - 259 145 orion_ge00_init(eth_data, 260 146 GE00_PHYS_BASE, IRQ_KIRKWOOD_GE00_SUM, 261 147 IRQ_KIRKWOOD_GE00_ERR); ··· 265 155 ****************************************************************************/ 266 156 void __init kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data) 267 157 { 268 - 269 - kirkwood_clk_ctrl |= CGC_GE1; 270 - 271 158 orion_ge01_init(eth_data, 272 159 GE01_PHYS_BASE, IRQ_KIRKWOOD_GE01_SUM, 273 160 IRQ_KIRKWOOD_GE01_ERR); ··· 309 202 void __init kirkwood_nand_init(struct mtd_partition *parts, int nr_parts, 310 203 int chip_delay) 311 204 { 312 - kirkwood_clk_ctrl |= CGC_RUNIT; 313 205 kirkwood_nand_data.parts = parts; 314 206 kirkwood_nand_data.nr_parts = nr_parts; 315 207 kirkwood_nand_data.chip_delay = chip_delay; ··· 318 212 void __init kirkwood_nand_init_rnb(struct mtd_partition *parts, int nr_parts, 319 213 int (*dev_ready)(struct mtd_info *)) 320 214 { 321 - kirkwood_clk_ctrl |= CGC_RUNIT; 322 215 kirkwood_nand_data.parts = parts; 323 216 kirkwood_nand_data.nr_parts = nr_parts; 324 217 kirkwood_nand_data.dev_ready = dev_ready; ··· 338 233 ****************************************************************************/ 339 234 void __init kirkwood_sata_init(struct mv_sata_platform_data *sata_data) 340 235 { 341 - kirkwood_clk_ctrl |= CGC_SATA0; 342 - if (sata_data->n_ports > 1) 343 - kirkwood_clk_ctrl |= CGC_SATA1; 344 - 345 236 orion_sata_init(sata_data, SATA_PHYS_BASE, IRQ_KIRKWOOD_SATA); 346 237 } 347 238 ··· 380 279 mvsdio_data->clock = 100000000; 381 280 else 382 281 mvsdio_data->clock = 200000000; 383 - kirkwood_clk_ctrl |= CGC_SDIO; 384 282 kirkwood_sdio.dev.platform_data = mvsdio_data; 385 283 platform_device_register(&kirkwood_sdio); 386 284 } ··· 390 290 ****************************************************************************/ 391 291 void __init kirkwood_spi_init() 392 292 { 393 - kirkwood_clk_ctrl |= CGC_RUNIT; 394 293 orion_spi_init(SPI_PHYS_BASE); 395 294 } 396 295 ··· 428 329 ****************************************************************************/ 429 330 void __init kirkwood_crypto_init(void) 430 331 { 431 - kirkwood_clk_ctrl |= CGC_CRYPTO; 432 332 orion_crypto_init(CRYPTO_PHYS_BASE, KIRKWOOD_SRAM_PHYS_BASE, 433 333 KIRKWOOD_SRAM_SIZE, IRQ_KIRKWOOD_CRYPTO); 434 334 } ··· 438 340 ****************************************************************************/ 439 341 void __init kirkwood_xor0_init(void) 440 342 { 441 - kirkwood_clk_ctrl |= CGC_XOR0; 442 343 orion_xor0_init(XOR0_PHYS_BASE, XOR0_HIGH_PHYS_BASE, 443 344 IRQ_KIRKWOOD_XOR_00, IRQ_KIRKWOOD_XOR_01); 444 345 } ··· 448 351 ****************************************************************************/ 449 352 void __init kirkwood_xor1_init(void) 450 353 { 451 - kirkwood_clk_ctrl |= CGC_XOR1; 452 354 orion_xor1_init(XOR1_PHYS_BASE, XOR1_HIGH_PHYS_BASE, 453 355 IRQ_KIRKWOOD_XOR_10, IRQ_KIRKWOOD_XOR_11); 454 356 } ··· 534 438 535 439 void __init kirkwood_audio_init(void) 536 440 { 537 - kirkwood_clk_ctrl |= CGC_AUDIO; 538 441 platform_device_register(&kirkwood_i2s_device); 539 442 platform_device_register(&kirkwood_pcm_device); 540 443 } ··· 631 536 kexec_reinit = kirkwood_enable_pcie; 632 537 #endif 633 538 } 634 - 635 - static int __init kirkwood_clock_gate(void) 636 - { 637 - unsigned int curr = readl(CLOCK_GATING_CTRL); 638 - u32 dev, rev; 639 - 640 - kirkwood_pcie_id(&dev, &rev); 641 - printk(KERN_DEBUG "Gating clock of unused units\n"); 642 - printk(KERN_DEBUG "before: 0x%08x\n", curr); 643 - 644 - /* Make sure those units are accessible */ 645 - writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL); 646 - 647 - /* For SATA: first shutdown the phy */ 648 - if (!(kirkwood_clk_ctrl & CGC_SATA0)) { 649 - /* Disable PLL and IVREF */ 650 - writel(readl(SATA0_PHY_MODE_2) & ~0xf, SATA0_PHY_MODE_2); 651 - /* Disable PHY */ 652 - writel(readl(SATA0_IF_CTRL) | 0x200, SATA0_IF_CTRL); 653 - } 654 - if (!(kirkwood_clk_ctrl & CGC_SATA1)) { 655 - /* Disable PLL and IVREF */ 656 - writel(readl(SATA1_PHY_MODE_2) & ~0xf, SATA1_PHY_MODE_2); 657 - /* Disable PHY */ 658 - writel(readl(SATA1_IF_CTRL) | 0x200, SATA1_IF_CTRL); 659 - } 660 - 661 - /* For PCIe: first shutdown the phy */ 662 - if (!(kirkwood_clk_ctrl & CGC_PEX0)) { 663 - writel(readl(PCIE_LINK_CTRL) | 0x10, PCIE_LINK_CTRL); 664 - while (1) 665 - if (readl(PCIE_STATUS) & 0x1) 666 - break; 667 - writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL); 668 - } 669 - 670 - /* For PCIe 1: first shutdown the phy */ 671 - if (dev == MV88F6282_DEV_ID) { 672 - if (!(kirkwood_clk_ctrl & CGC_PEX1)) { 673 - writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL); 674 - while (1) 675 - if (readl(PCIE1_STATUS) & 0x1) 676 - break; 677 - writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL); 678 - } 679 - } else /* keep this bit set for devices that don't have PCIe1 */ 680 - kirkwood_clk_ctrl |= CGC_PEX1; 681 - 682 - /* Now gate clock the required units */ 683 - writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL); 684 - printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL)); 685 - 686 - return 0; 687 - } 688 - late_initcall(kirkwood_clock_gate); 689 539 690 540 void kirkwood_restart(char mode, const char *cmd) 691 541 {
+1 -4
arch/arm/mach-kirkwood/pcie.c
··· 44 44 writel(curr | CGC_PEX0, CLOCK_GATING_CTRL); 45 45 } 46 46 47 - void __init kirkwood_pcie_id(u32 *dev, u32 *rev) 47 + void kirkwood_pcie_id(u32 *dev, u32 *rev) 48 48 { 49 49 kirkwood_enable_pcie(); 50 50 *dev = orion_pcie_dev_id((void __iomem *)PCIE_VIRT_BASE); ··· 181 181 182 182 static int __init kirkwood_pcie_setup(int nr, struct pci_sys_data *sys) 183 183 { 184 - extern unsigned int kirkwood_clk_ctrl; 185 184 struct pcie_port *pp; 186 185 int index; 187 186 ··· 199 200 200 201 switch (index) { 201 202 case 0: 202 - kirkwood_clk_ctrl |= CGC_PEX0; 203 203 kirkwood_enable_pcie_clk("0"); 204 204 pcie0_ioresources_init(pp); 205 205 break; 206 206 case 1: 207 - kirkwood_clk_ctrl |= CGC_PEX1; 208 207 kirkwood_enable_pcie_clk("1"); 209 208 pcie1_ioresources_init(pp); 210 209 break;
+2 -2
arch/arm/plat-orion/pcie.c
··· 52 52 #define PCIE_DEBUG_SOFT_RESET (1<<20) 53 53 54 54 55 - u32 __init orion_pcie_dev_id(void __iomem *base) 55 + u32 orion_pcie_dev_id(void __iomem *base) 56 56 { 57 57 return readl(base + PCIE_DEV_ID_OFF) >> 16; 58 58 } 59 59 60 - u32 __init orion_pcie_rev(void __iomem *base) 60 + u32 orion_pcie_rev(void __iomem *base) 61 61 { 62 62 return readl(base + PCIE_DEV_REV_OFF) & 0xff; 63 63 }