Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * OMAP3-specific clock framework functions |
| 3 | * |
Paul Walmsley | 542313c | 2008-07-03 12:24:45 +0300 | [diff] [blame] | 4 | * Copyright (C) 2007-2008 Texas Instruments, Inc. |
Paul Walmsley | 3c82e22 | 2009-07-24 19:44:06 -0600 | [diff] [blame] | 5 | * Copyright (C) 2007-2009 Nokia Corporation |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 6 | * |
| 7 | * Written by Paul Walmsley |
Paul Walmsley | 542313c | 2008-07-03 12:24:45 +0300 | [diff] [blame] | 8 | * Testing and integration fixes by Jouni Högander |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 9 | * |
| 10 | * Parts of this code are based on code written by |
| 11 | * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | #undef DEBUG |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/errno.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/io.h> |
Paul Walmsley | 542313c | 2008-07-03 12:24:45 +0300 | [diff] [blame] | 27 | #include <linux/limits.h> |
Russell King | fbd3bdb | 2008-09-06 12:13:59 +0100 | [diff] [blame] | 28 | #include <linux/bitops.h> |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 29 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 30 | #include <plat/cpu.h> |
| 31 | #include <plat/clock.h> |
| 32 | #include <plat/sram.h> |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 33 | #include <plat/sdrc.h> |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 34 | #include <asm/div64.h> |
Russell King | 44dc9d0 | 2009-01-19 15:51:11 +0000 | [diff] [blame] | 35 | #include <asm/clkdev.h> |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 36 | |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 37 | #include "clock.h" |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 38 | #include "clock34xx.h" |
| 39 | #include "sdrc.h" |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 40 | #include "prm.h" |
| 41 | #include "prm-regbits-34xx.h" |
| 42 | #include "cm.h" |
| 43 | #include "cm-regbits-34xx.h" |
| 44 | |
Rajendra Nayak | 7a66a39 | 2009-10-05 13:31:44 -0700 | [diff] [blame] | 45 | /* |
| 46 | * DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks |
| 47 | * that are sourced by DPLL5, and both of these require this clock |
| 48 | * to be at 120 MHz for proper operation. |
| 49 | */ |
| 50 | #define DPLL5_FREQ_FOR_USBHOST 120000000 |
| 51 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 52 | /* needed by omap3_core_dpll_m2_set_rate() */ |
| 53 | struct clk *sdrc_ick_p, *arm_fck_p; |
| 54 | |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 55 | /** |
Paul Walmsley | 3c82e22 | 2009-07-24 19:44:06 -0600 | [diff] [blame] | 56 | * omap3430es2_clk_ssi_find_idlest - return CM_IDLEST info for SSI |
| 57 | * @clk: struct clk * being enabled |
| 58 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
| 59 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
| 60 | * |
| 61 | * The OMAP3430ES2 SSI target CM_IDLEST bit is at a different shift |
| 62 | * from the CM_{I,F}CLKEN bit. Pass back the correct info via |
| 63 | * @idlest_reg and @idlest_bit. No return value. |
| 64 | */ |
| 65 | static void omap3430es2_clk_ssi_find_idlest(struct clk *clk, |
| 66 | void __iomem **idlest_reg, |
| 67 | u8 *idlest_bit) |
| 68 | { |
| 69 | u32 r; |
| 70 | |
| 71 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
| 72 | *idlest_reg = (__force void __iomem *)r; |
| 73 | *idlest_bit = OMAP3430ES2_ST_SSI_IDLE_SHIFT; |
| 74 | } |
| 75 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 76 | const struct clkops clkops_omap3430es2_ssi_wait = { |
| 77 | .enable = omap2_dflt_clk_enable, |
| 78 | .disable = omap2_dflt_clk_disable, |
| 79 | .find_idlest = omap3430es2_clk_ssi_find_idlest, |
| 80 | .find_companion = omap2_clk_dflt_find_companion, |
| 81 | }; |
| 82 | |
Paul Walmsley | 3c82e22 | 2009-07-24 19:44:06 -0600 | [diff] [blame] | 83 | /** |
| 84 | * omap3430es2_clk_dss_usbhost_find_idlest - CM_IDLEST info for DSS, USBHOST |
| 85 | * @clk: struct clk * being enabled |
| 86 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
| 87 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
| 88 | * |
| 89 | * Some OMAP modules on OMAP3 ES2+ chips have both initiator and |
| 90 | * target IDLEST bits. For our purposes, we are concerned with the |
| 91 | * target IDLEST bits, which exist at a different bit position than |
| 92 | * the *CLKEN bit position for these modules (DSS and USBHOST) (The |
| 93 | * default find_idlest code assumes that they are at the same |
| 94 | * position.) No return value. |
| 95 | */ |
| 96 | static void omap3430es2_clk_dss_usbhost_find_idlest(struct clk *clk, |
| 97 | void __iomem **idlest_reg, |
| 98 | u8 *idlest_bit) |
| 99 | { |
| 100 | u32 r; |
| 101 | |
| 102 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
| 103 | *idlest_reg = (__force void __iomem *)r; |
| 104 | /* USBHOST_IDLE has same shift */ |
| 105 | *idlest_bit = OMAP3430ES2_ST_DSS_IDLE_SHIFT; |
| 106 | } |
| 107 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 108 | const struct clkops clkops_omap3430es2_dss_usbhost_wait = { |
| 109 | .enable = omap2_dflt_clk_enable, |
| 110 | .disable = omap2_dflt_clk_disable, |
| 111 | .find_idlest = omap3430es2_clk_dss_usbhost_find_idlest, |
| 112 | .find_companion = omap2_clk_dflt_find_companion, |
| 113 | }; |
| 114 | |
Paul Walmsley | 3c82e22 | 2009-07-24 19:44:06 -0600 | [diff] [blame] | 115 | /** |
| 116 | * omap3430es2_clk_hsotgusb_find_idlest - return CM_IDLEST info for HSOTGUSB |
| 117 | * @clk: struct clk * being enabled |
| 118 | * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into |
| 119 | * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into |
| 120 | * |
| 121 | * The OMAP3430ES2 HSOTGUSB target CM_IDLEST bit is at a different |
| 122 | * shift from the CM_{I,F}CLKEN bit. Pass back the correct info via |
| 123 | * @idlest_reg and @idlest_bit. No return value. |
| 124 | */ |
| 125 | static void omap3430es2_clk_hsotgusb_find_idlest(struct clk *clk, |
| 126 | void __iomem **idlest_reg, |
| 127 | u8 *idlest_bit) |
| 128 | { |
| 129 | u32 r; |
| 130 | |
| 131 | r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20); |
| 132 | *idlest_reg = (__force void __iomem *)r; |
| 133 | *idlest_bit = OMAP3430ES2_ST_HSOTGUSB_IDLE_SHIFT; |
| 134 | } |
| 135 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 136 | const struct clkops clkops_omap3430es2_hsotgusb_wait = { |
| 137 | .enable = omap2_dflt_clk_enable, |
| 138 | .disable = omap2_dflt_clk_disable, |
| 139 | .find_idlest = omap3430es2_clk_hsotgusb_find_idlest, |
| 140 | .find_companion = omap2_clk_dflt_find_companion, |
| 141 | }; |
| 142 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 143 | const struct clkops clkops_noncore_dpll_ops = { |
| 144 | .enable = omap3_noncore_dpll_enable, |
| 145 | .disable = omap3_noncore_dpll_disable, |
| 146 | }; |
Paul Walmsley | 16c90f0 | 2009-01-27 19:12:47 -0700 | [diff] [blame] | 147 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 148 | int omap3_dpll4_set_rate(struct clk *clk, unsigned long rate) |
Paul Walmsley | 16c90f0 | 2009-01-27 19:12:47 -0700 | [diff] [blame] | 149 | { |
| 150 | /* |
| 151 | * According to the 12-5 CDP code from TI, "Limitation 2.5" |
| 152 | * on 3430ES1 prevents us from changing DPLL multipliers or dividers |
| 153 | * on DPLL4. |
| 154 | */ |
| 155 | if (omap_rev() == OMAP3430_REV_ES1_0) { |
| 156 | printk(KERN_ERR "clock: DPLL4 cannot change rate due to " |
| 157 | "silicon 'Limitation 2.5' on 3430ES1.\n"); |
| 158 | return -EINVAL; |
| 159 | } |
| 160 | return omap3_noncore_dpll_set_rate(clk, rate); |
| 161 | } |
| 162 | |
Paul Walmsley | 542313c | 2008-07-03 12:24:45 +0300 | [diff] [blame] | 163 | /* Common clock code */ |
| 164 | |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 165 | /* |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 166 | * Set clocks for bypass mode for reboot to work. |
| 167 | */ |
| 168 | void omap2_clk_prepare_for_reboot(void) |
| 169 | { |
| 170 | /* REVISIT: Not ready for 343x */ |
| 171 | #if 0 |
| 172 | u32 rate; |
| 173 | |
| 174 | if (vclk == NULL || sclk == NULL) |
| 175 | return; |
| 176 | |
| 177 | rate = clk_get_rate(sclk); |
| 178 | clk_set_rate(vclk, rate); |
| 179 | #endif |
| 180 | } |
| 181 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 182 | void omap3_clk_lock_dpll5(void) |
Rajendra Nayak | 7a66a39 | 2009-10-05 13:31:44 -0700 | [diff] [blame] | 183 | { |
| 184 | struct clk *dpll5_clk; |
| 185 | struct clk *dpll5_m2_clk; |
| 186 | |
| 187 | dpll5_clk = clk_get(NULL, "dpll5_ck"); |
| 188 | clk_set_rate(dpll5_clk, DPLL5_FREQ_FOR_USBHOST); |
| 189 | clk_enable(dpll5_clk); |
| 190 | |
| 191 | /* Enable autoidle to allow it to enter low power bypass */ |
| 192 | omap3_dpll_allow_idle(dpll5_clk); |
| 193 | |
| 194 | /* Program dpll5_m2_clk divider for no division */ |
| 195 | dpll5_m2_clk = clk_get(NULL, "dpll5_m2_ck"); |
| 196 | clk_enable(dpll5_m2_clk); |
| 197 | clk_set_rate(dpll5_m2_clk, DPLL5_FREQ_FOR_USBHOST); |
| 198 | |
| 199 | clk_disable(dpll5_m2_clk); |
| 200 | clk_disable(dpll5_clk); |
| 201 | return; |
| 202 | } |
| 203 | |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 204 | /* REVISIT: Move this init stuff out into clock.c */ |
| 205 | |
| 206 | /* |
| 207 | * Switch the MPU rate if specified on cmdline. |
| 208 | * We cannot do this early until cmdline is parsed. |
| 209 | */ |
Paul Walmsley | 4680c29 | 2010-01-26 20:13:09 -0700 | [diff] [blame^] | 210 | static int __init omap3xxx_clk_arch_init(void) |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 211 | { |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 212 | struct clk *osc_sys_ck, *dpll1_ck, *arm_fck, *core_ck; |
| 213 | unsigned long osc_sys_rate; |
| 214 | |
Paul Walmsley | 4680c29 | 2010-01-26 20:13:09 -0700 | [diff] [blame^] | 215 | if (!cpu_is_omap34xx()) |
| 216 | return 0; |
| 217 | |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 218 | if (!mpurate) |
| 219 | return -EINVAL; |
| 220 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 221 | /* XXX test these for success */ |
| 222 | dpll1_ck = clk_get(NULL, "dpll1_ck"); |
| 223 | arm_fck = clk_get(NULL, "arm_fck"); |
| 224 | core_ck = clk_get(NULL, "core_ck"); |
| 225 | osc_sys_ck = clk_get(NULL, "osc_sys_ck"); |
| 226 | |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 227 | /* REVISIT: not yet ready for 343x */ |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 228 | if (clk_set_rate(dpll1_ck, mpurate)) |
Sanjeev Premi | 11b6638 | 2009-09-03 20:13:58 +0300 | [diff] [blame] | 229 | printk(KERN_ERR "*** Unable to set MPU rate\n"); |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 230 | |
| 231 | recalculate_root_clocks(); |
| 232 | |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 233 | osc_sys_rate = clk_get_rate(osc_sys_ck); |
| 234 | |
| 235 | pr_info("Switched to new clocking rate (Crystal/Core/MPU): " |
| 236 | "%ld.%01ld/%ld/%ld MHz\n", |
| 237 | (osc_sys_rate / 1000000), |
| 238 | ((osc_sys_rate / 100000) % 10), |
| 239 | (clk_get_rate(core_ck) / 1000000), |
| 240 | (clk_get_rate(arm_fck) / 1000000)); |
Sanjeev Premi | 11b6638 | 2009-09-03 20:13:58 +0300 | [diff] [blame] | 241 | |
| 242 | calibrate_delay(); |
Paul Walmsley | 02e19a9 | 2008-03-18 15:09:51 +0200 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
Paul Walmsley | 4680c29 | 2010-01-26 20:13:09 -0700 | [diff] [blame^] | 246 | arch_initcall(omap3xxx_clk_arch_init); |
Paul Walmsley | 82e9bd5 | 2009-12-08 16:18:47 -0700 | [diff] [blame] | 247 | |
| 248 | |