Matt Wagantall | d1af38e | 2011-08-06 01:38:02 -0700 | [diff] [blame] | 1 | /* |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * MSM architecture clock driver |
| 3 | * |
| 4 | * Copyright (C) 2007 Google, Inc. |
| 5 | * Copyright (c) 2007-2011, Code Aurora Forum. All rights reserved. |
| 6 | * Author: San Mehat <san@android.com> |
| 7 | * |
| 8 | * This software is licensed under the terms of the GNU General Public |
| 9 | * License version 2, as published by the Free Software Foundation, and |
| 10 | * may be copied, distributed, and modified under those terms. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/version.h> |
| 20 | #include <linux/kernel.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/errno.h> |
| 23 | #include <linux/string.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/cpufreq.h> |
| 27 | #include <linux/mutex.h> |
| 28 | #include <linux/io.h> |
| 29 | #include <linux/sort.h> |
| 30 | #include <linux/remote_spinlock.h> |
| 31 | #include <mach/board.h> |
| 32 | #include <mach/msm_iomap.h> |
| 33 | #include <asm/mach-types.h> |
| 34 | #include <mach/socinfo.h> |
| 35 | |
| 36 | #include "proc_comm.h" |
| 37 | #include "smd_private.h" |
| 38 | #include "acpuclock.h" |
| 39 | |
| 40 | #define A11S_CLK_CNTL_ADDR (MSM_CSR_BASE + 0x100) |
| 41 | #define A11S_CLK_SEL_ADDR (MSM_CSR_BASE + 0x104) |
| 42 | #define A11S_VDD_SVS_PLEVEL_ADDR (MSM_CSR_BASE + 0x124) |
| 43 | #define PLLn_MODE(n) (MSM_CLK_CTL_BASE + 0x300 + 28 * (n)) |
| 44 | #define PLLn_L_VAL(n) (MSM_CLK_CTL_BASE + 0x304 + 28 * (n)) |
| 45 | |
| 46 | #define PLL4_MODE (MSM_CLK_CTL_BASE + 0x374) |
| 47 | #define PLL4_L_VAL (MSM_CLK_CTL_BASE + 0x378) |
| 48 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 49 | #define POWER_COLLAPSE_KHZ 19200 |
| 50 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | /* Max CPU frequency allowed by hardware while in standby waiting for an irq. */ |
| 52 | #define MAX_WAIT_FOR_IRQ_KHZ 128000 |
| 53 | |
| 54 | enum { |
| 55 | ACPU_PLL_TCXO = -1, |
| 56 | ACPU_PLL_0 = 0, |
| 57 | ACPU_PLL_1, |
| 58 | ACPU_PLL_2, |
| 59 | ACPU_PLL_3, |
| 60 | ACPU_PLL_4, |
| 61 | ACPU_PLL_END, |
| 62 | }; |
| 63 | |
| 64 | static const struct pll { |
| 65 | void __iomem *mod_reg; |
| 66 | const uint32_t l_val_mask; |
| 67 | } soc_pll[ACPU_PLL_END] = { |
| 68 | [ACPU_PLL_0] = {PLLn_MODE(ACPU_PLL_0), 0x3f}, |
| 69 | [ACPU_PLL_1] = {PLLn_MODE(ACPU_PLL_1), 0x3f}, |
| 70 | [ACPU_PLL_2] = {PLLn_MODE(ACPU_PLL_2), 0x3f}, |
| 71 | [ACPU_PLL_3] = {PLLn_MODE(ACPU_PLL_3), 0x3f}, |
| 72 | [ACPU_PLL_4] = {PLL4_MODE, 0x3ff}, |
| 73 | }; |
| 74 | |
| 75 | struct clock_state { |
| 76 | struct clkctl_acpu_speed *current_speed; |
| 77 | struct mutex lock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 78 | uint32_t max_speed_delta_khz; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 79 | unsigned long max_axi_khz; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 80 | struct clk *ebi1_clk; |
| 81 | }; |
| 82 | |
| 83 | #define PLL_BASE 7 |
| 84 | |
| 85 | struct shared_pll_control { |
| 86 | uint32_t version; |
| 87 | struct { |
| 88 | /* Denotes if the PLL is ON. Technically, this can be read |
| 89 | * directly from the PLL registers, but this feild is here, |
| 90 | * so let's use it. |
| 91 | */ |
| 92 | uint32_t on; |
| 93 | /* One bit for each processor core. The application processor |
| 94 | * is allocated bit position 1. All other bits should be |
| 95 | * considered as votes from other processors. |
| 96 | */ |
| 97 | uint32_t votes; |
| 98 | } pll[PLL_BASE + ACPU_PLL_END]; |
| 99 | }; |
| 100 | |
| 101 | struct clkctl_acpu_speed { |
| 102 | unsigned int use_for_scaling; |
| 103 | unsigned int a11clk_khz; |
| 104 | int pll; |
| 105 | unsigned int a11clk_src_sel; |
| 106 | unsigned int a11clk_src_div; |
| 107 | unsigned int ahbclk_khz; |
| 108 | unsigned int ahbclk_div; |
| 109 | int vdd; |
| 110 | unsigned int axiclk_khz; |
| 111 | unsigned long lpj; /* loops_per_jiffy */ |
| 112 | /* Pointers in acpu_freq_tbl[] for max up/down steppings. */ |
| 113 | struct clkctl_acpu_speed *down[ACPU_PLL_END]; |
| 114 | struct clkctl_acpu_speed *up[ACPU_PLL_END]; |
| 115 | }; |
| 116 | |
| 117 | static remote_spinlock_t pll_lock; |
| 118 | static struct shared_pll_control *pll_control; |
| 119 | static struct clock_state drv_state = { 0 }; |
| 120 | static struct clkctl_acpu_speed *acpu_freq_tbl; |
| 121 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 122 | /* |
| 123 | * ACPU freq tables used for different PLLs frequency combinations. The |
| 124 | * correct table is selected during init. |
| 125 | * |
| 126 | * Table stepping up/down entries are calculated during boot to choose the |
| 127 | * largest frequency jump that's less than max_speed_delta_khz on each PLL. |
| 128 | */ |
| 129 | |
| 130 | /* 7x01/7x25 normal with GSM capable modem */ |
| 131 | static struct clkctl_acpu_speed pll0_245_pll1_768_pll2_1056_pll4_0[] = { |
| 132 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 }, |
| 133 | { 1, 122880, ACPU_PLL_0, 4, 1, 61440, 1, 3, 61440 }, |
| 134 | { 0, 128000, ACPU_PLL_1, 1, 5, 64000, 1, 3, 61440 }, |
| 135 | { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 61440 }, |
| 136 | { 1, 245760, ACPU_PLL_0, 4, 0, 81920, 2, 4, 61440 }, |
| 137 | { 1, 256000, ACPU_PLL_1, 1, 2, 128000, 1, 5, 128000 }, |
| 138 | { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 128000 }, |
| 139 | { 1, 384000, ACPU_PLL_1, 1, 1, 128000, 2, 6, 128000 }, |
| 140 | { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 128000 }, |
| 141 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 142 | }; |
| 143 | |
| 144 | /* 7x01/7x25 normal with CDMA-only modem */ |
| 145 | static struct clkctl_acpu_speed pll0_196_pll1_768_pll2_1056_pll4_0[] = { |
| 146 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 }, |
| 147 | { 1, 98304, ACPU_PLL_0, 4, 1, 49152, 1, 3, 24576 }, |
| 148 | { 0, 128000, ACPU_PLL_1, 1, 5, 64000, 1, 3, 24576 }, |
| 149 | { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 24576 }, |
| 150 | { 1, 196608, ACPU_PLL_0, 4, 0, 65536, 2, 4, 24576 }, |
| 151 | { 1, 256000, ACPU_PLL_1, 1, 2, 128000, 1, 5, 128000 }, |
| 152 | { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 128000 }, |
| 153 | { 1, 384000, ACPU_PLL_1, 1, 1, 128000, 2, 6, 128000 }, |
| 154 | { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 128000 }, |
| 155 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 156 | }; |
| 157 | |
| 158 | /* 7x01/7x25 turbo with GSM capable modem */ |
| 159 | static struct clkctl_acpu_speed pll0_245_pll1_960_pll2_1056_pll4_0[] = { |
| 160 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 }, |
| 161 | { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 61440 }, |
| 162 | { 1, 122880, ACPU_PLL_0, 4, 1, 61440, 1, 3, 61440 }, |
| 163 | { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 61440 }, |
| 164 | { 1, 245760, ACPU_PLL_0, 4, 0, 81920, 2, 4, 61440 }, |
| 165 | { 1, 320000, ACPU_PLL_1, 1, 2, 107000, 2, 5, 120000 }, |
| 166 | { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 120000 }, |
| 167 | { 1, 480000, ACPU_PLL_1, 1, 1, 120000, 3, 6, 120000 }, |
| 168 | { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 122880 }, |
| 169 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 170 | }; |
| 171 | |
| 172 | /* 7x01/7x25 turbo with CDMA-only modem */ |
| 173 | static struct clkctl_acpu_speed pll0_196_pll1_960_pll2_1056_pll4_0[] = { |
| 174 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 }, |
| 175 | { 1, 98304, ACPU_PLL_0, 4, 1, 49152, 1, 3, 24576 }, |
| 176 | { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 24576 }, |
| 177 | { 0, 176000, ACPU_PLL_2, 2, 5, 88000, 1, 3, 24576 }, |
| 178 | { 1, 196608, ACPU_PLL_0, 4, 0, 65536, 2, 4, 24576 }, |
| 179 | { 1, 320000, ACPU_PLL_1, 1, 2, 107000, 2, 5, 120000 }, |
| 180 | { 0, 352000, ACPU_PLL_2, 2, 2, 88000, 3, 5, 120000 }, |
| 181 | { 1, 480000, ACPU_PLL_1, 1, 1, 120000, 3, 6, 120000 }, |
| 182 | { 1, 528000, ACPU_PLL_2, 2, 1, 132000, 3, 7, 120000 }, |
| 183 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 184 | }; |
| 185 | |
| 186 | /* 7x27 normal with GSM capable modem */ |
| 187 | static struct clkctl_acpu_speed pll0_245_pll1_960_pll2_1200_pll4_0[] = { |
| 188 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 }, |
| 189 | { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 61440 }, |
| 190 | { 1, 122880, ACPU_PLL_0, 4, 1, 61440, 1, 3, 61440 }, |
| 191 | { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 }, |
| 192 | { 1, 245760, ACPU_PLL_0, 4, 0, 122880, 1, 4, 61440 }, |
| 193 | { 1, 320000, ACPU_PLL_1, 1, 2, 160000, 1, 5, 122880 }, |
| 194 | { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 122880 }, |
| 195 | { 1, 480000, ACPU_PLL_1, 1, 1, 160000, 2, 6, 122880 }, |
| 196 | { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 122880 }, |
| 197 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 198 | }; |
| 199 | |
| 200 | /* 7x27 normal with CDMA-only modem */ |
| 201 | static struct clkctl_acpu_speed pll0_196_pll1_960_pll2_1200_pll4_0[] = { |
| 202 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 }, |
| 203 | { 1, 98304, ACPU_PLL_0, 4, 1, 98304, 0, 3, 49152 }, |
| 204 | { 0, 120000, ACPU_PLL_1, 1, 7, 60000, 1, 3, 49152 }, |
| 205 | { 1, 196608, ACPU_PLL_0, 4, 0, 65536, 2, 4, 98304 }, |
| 206 | { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 }, |
| 207 | { 1, 320000, ACPU_PLL_1, 1, 2, 160000, 1, 5, 120000 }, |
| 208 | { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 120000 }, |
| 209 | { 1, 480000, ACPU_PLL_1, 1, 1, 160000, 2, 6, 120000 }, |
| 210 | { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 120000 }, |
| 211 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 212 | }; |
| 213 | |
| 214 | /* 7x27 normal with GSM capable modem - PLL0 and PLL1 swapped */ |
| 215 | static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_0[] = { |
| 216 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 }, |
| 217 | { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 }, |
| 218 | { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 }, |
| 219 | { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 61440 }, |
| 220 | { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 }, |
| 221 | { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 122880 }, |
| 222 | { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 122880 }, |
| 223 | { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 122880 }, |
| 224 | { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 122880 }, |
| 225 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 226 | }; |
| 227 | |
| 228 | /* 7x27 normal with CDMA-only modem - PLL0 and PLL1 swapped */ |
| 229 | static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_0[] = { |
| 230 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 }, |
| 231 | { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 }, |
| 232 | { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 }, |
| 233 | { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 }, |
| 234 | { 0, 200000, ACPU_PLL_2, 2, 5, 66667, 2, 4, 98304 }, |
| 235 | { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 120000 }, |
| 236 | { 0, 400000, ACPU_PLL_2, 2, 2, 133333, 2, 5, 120000 }, |
| 237 | { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 120000 }, |
| 238 | { 1, 600000, ACPU_PLL_2, 2, 1, 200000, 2, 7, 120000 }, |
| 239 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 240 | }; |
| 241 | |
| 242 | /* 7x27 normal with GSM capable modem - PLL0 and PLL1 swapped and pll2 @ 800 */ |
| 243 | static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_800_pll4_0[] = { |
| 244 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 30720 }, |
| 245 | { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 61440 }, |
| 246 | { 1, 122880, ACPU_PLL_1, 1, 1, 61440, 1, 3, 61440 }, |
| 247 | { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 61440 }, |
| 248 | { 1, 245760, ACPU_PLL_1, 1, 0, 122880, 1, 4, 61440 }, |
| 249 | { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 122880 }, |
| 250 | { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 122880 }, |
| 251 | { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 122880 }, |
| 252 | { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 122880 }, |
| 253 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 254 | }; |
| 255 | |
| 256 | /* 7x27 normal with CDMA-only modem - PLL0 and PLL1 swapped and pll2 @ 800 */ |
| 257 | static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_800_pll4_0[] = { |
| 258 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 19200, 0, 0, 24576 }, |
| 259 | { 1, 98304, ACPU_PLL_1, 1, 1, 98304, 0, 3, 49152 }, |
| 260 | { 0, 120000, ACPU_PLL_0, 4, 7, 60000, 1, 3, 49152 }, |
| 261 | { 1, 196608, ACPU_PLL_1, 1, 0, 65536, 2, 4, 98304 }, |
| 262 | { 0, 200000, ACPU_PLL_2, 2, 3, 66667, 2, 4, 98304 }, |
| 263 | { 1, 320000, ACPU_PLL_0, 4, 2, 160000, 1, 5, 120000 }, |
| 264 | { 0, 400000, ACPU_PLL_2, 2, 1, 133333, 2, 5, 120000 }, |
| 265 | { 1, 480000, ACPU_PLL_0, 4, 1, 160000, 2, 6, 120000 }, |
| 266 | { 1, 800000, ACPU_PLL_2, 2, 0, 200000, 3, 7, 120000 }, |
| 267 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 268 | }; |
| 269 | |
| 270 | /* 7x27a pll2 at 1200mhz with GSM capable modem */ |
| 271 | static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800[] = { |
Trilok Soni | 7d6c865 | 2011-07-14 15:35:07 +0530 | [diff] [blame] | 272 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 }, |
| 273 | { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 }, |
| 274 | { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 }, |
| 275 | { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 }, |
| 276 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 277 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 278 | { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 }, |
| 279 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 280 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 281 | { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 282 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 283 | }; |
| 284 | |
| 285 | /* 7x27a pll2 at 1200mhz with CDMA only modem */ |
| 286 | static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_800[] = { |
Trilok Soni | 7d6c865 | 2011-07-14 15:35:07 +0530 | [diff] [blame] | 287 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 }, |
| 288 | { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 }, |
| 289 | { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 }, |
| 290 | { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 }, |
Trilok Soni | abb750b | 2011-07-13 16:47:18 +0530 | [diff] [blame] | 291 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 }, |
| 292 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 }, |
| 293 | { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 }, |
| 294 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 }, |
Trilok Soni | 7d6c865 | 2011-07-14 15:35:07 +0530 | [diff] [blame] | 295 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 296 | { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 }, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 297 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 298 | }; |
| 299 | |
Trilok Soni | f597e24 | 2011-06-06 12:37:16 +0530 | [diff] [blame] | 300 | /* 7x27aa pll4 at 1008mhz with GSM capable modem */ |
| 301 | static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_1008[] = { |
| 302 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 }, |
| 303 | { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 }, |
| 304 | { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 }, |
| 305 | { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 }, |
| 306 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 307 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 308 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 309 | { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 }, |
| 310 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 311 | { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000}, |
| 312 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 313 | }; |
| 314 | |
Trilok Soni | d7b05e5 | 2011-08-17 18:09:08 +0530 | [diff] [blame] | 315 | /* 7x27aa pll4 at 1008mhz with CDMA capable modem */ |
| 316 | static struct clkctl_acpu_speed pll0_960_pll1_196_pll2_1200_pll4_1008[] = { |
| 317 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 }, |
| 318 | { 0, 65536, ACPU_PLL_1, 1, 3, 8192, 3, 1, 49152 }, |
| 319 | { 1, 98304, ACPU_PLL_1, 1, 1, 12288, 3, 2, 49152 }, |
| 320 | { 1, 196608, ACPU_PLL_1, 1, 0, 24576, 3, 3, 98304 }, |
| 321 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 322 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 323 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 324 | { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 }, |
| 325 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 326 | { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000}, |
| 327 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 328 | }; |
| 329 | |
Trilok Soni | 54d35c4 | 2011-07-14 17:47:50 +0530 | [diff] [blame] | 330 | /* 7x25a pll2 at 1200mhz with GSM capable modem */ |
| 331 | static struct clkctl_acpu_speed pll0_960_pll1_245_pll2_1200_pll4_800_25a[] = { |
| 332 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 }, |
| 333 | { 0, 61440, ACPU_PLL_1, 1, 3, 7680, 3, 1, 61440 }, |
| 334 | { 1, 122880, ACPU_PLL_1, 1, 1, 15360, 3, 2, 61440 }, |
| 335 | { 1, 245760, ACPU_PLL_1, 1, 0, 30720, 3, 3, 61440 }, |
| 336 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 337 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 338 | { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 }, |
| 339 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 340 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 341 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 342 | }; |
| 343 | |
Trilok Soni | 9bb022c | 2011-10-31 18:25:19 +0530 | [diff] [blame^] | 344 | /* 7x27a pll2 at 1200mhz with GSM capable modem */ |
| 345 | static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800[] = { |
| 346 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 }, |
| 347 | { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 }, |
| 348 | { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 }, |
| 349 | { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 }, |
| 350 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 351 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 352 | { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 }, |
| 353 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 354 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 355 | { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 }, |
| 356 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 357 | }; |
| 358 | |
| 359 | /* 7x27a pll2 at 1200mhz with CDMA only modem */ |
| 360 | static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_800[] = { |
| 361 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 }, |
| 362 | { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 }, |
| 363 | { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 }, |
| 364 | { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 }, |
| 365 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 120000 }, |
| 366 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 120000 }, |
| 367 | { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 120000 }, |
| 368 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 120000 }, |
| 369 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 370 | { 1, 800000, ACPU_PLL_4, 6, 0, 100000, 3, 7, 200000 }, |
| 371 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 372 | }; |
| 373 | |
| 374 | /* 7x27aa pll4 at 1008mhz with GSM capable modem */ |
| 375 | static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_1008[] = { |
| 376 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 }, |
| 377 | { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 }, |
| 378 | { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 }, |
| 379 | { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 }, |
| 380 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 381 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 382 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 383 | { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 }, |
| 384 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 385 | { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000}, |
| 386 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 387 | }; |
| 388 | |
| 389 | /* 7x27aa pll4 at 1008mhz with CDMA capable modem */ |
| 390 | static struct clkctl_acpu_speed pll0_960_pll1_589_pll2_1200_pll4_1008[] = { |
| 391 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 24576 }, |
| 392 | { 0, 65536, ACPU_PLL_1, 1, 8, 8192, 3, 1, 49152 }, |
| 393 | { 1, 98304, ACPU_PLL_1, 1, 5, 12288, 3, 2, 49152 }, |
| 394 | { 1, 196608, ACPU_PLL_1, 1, 2, 24576, 3, 3, 98304 }, |
| 395 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 396 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 397 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 398 | { 0, 504000, ACPU_PLL_4, 6, 1, 63000, 3, 6, 200000 }, |
| 399 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 400 | { 1, 1008000, ACPU_PLL_4, 6, 0, 126000, 3, 7, 200000}, |
| 401 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 402 | }; |
| 403 | |
| 404 | /* 7x25a pll2 at 1200mhz with GSM capable modem */ |
| 405 | static struct clkctl_acpu_speed pll0_960_pll1_737_pll2_1200_pll4_800_25a[] = { |
| 406 | { 0, 19200, ACPU_PLL_TCXO, 0, 0, 2400, 3, 0, 30720 }, |
| 407 | { 0, 61440, ACPU_PLL_1, 1, 11, 7680, 3, 1, 61440 }, |
| 408 | { 1, 122880, ACPU_PLL_1, 1, 5, 15360, 3, 2, 61440 }, |
| 409 | { 1, 245760, ACPU_PLL_1, 1, 2, 30720, 3, 3, 61440 }, |
| 410 | { 0, 300000, ACPU_PLL_2, 2, 3, 37500, 3, 4, 150000 }, |
| 411 | { 1, 320000, ACPU_PLL_0, 4, 2, 40000, 3, 4, 122880 }, |
| 412 | { 0, 400000, ACPU_PLL_4, 6, 1, 50000, 3, 4, 122880 }, |
| 413 | { 1, 480000, ACPU_PLL_0, 4, 1, 60000, 3, 5, 122880 }, |
| 414 | { 1, 600000, ACPU_PLL_2, 2, 1, 75000, 3, 6, 200000 }, |
| 415 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, {0, 0, 0, 0} } |
| 416 | }; |
| 417 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 418 | #define PLL_0_MHZ 0 |
| 419 | #define PLL_196_MHZ 10 |
| 420 | #define PLL_245_MHZ 12 |
| 421 | #define PLL_491_MHZ 25 |
Trilok Soni | 9bb022c | 2011-10-31 18:25:19 +0530 | [diff] [blame^] | 422 | #define PLL_589_MHZ 30 |
| 423 | #define PLL_737_MHZ 38 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 424 | #define PLL_768_MHZ 40 |
| 425 | #define PLL_800_MHZ 41 |
| 426 | #define PLL_960_MHZ 50 |
Trilok Soni | f597e24 | 2011-06-06 12:37:16 +0530 | [diff] [blame] | 427 | #define PLL_1008_MHZ 52 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 428 | #define PLL_1056_MHZ 55 |
| 429 | #define PLL_1200_MHZ 62 |
| 430 | |
| 431 | #define PLL_CONFIG(m0, m1, m2, m4) { \ |
| 432 | PLL_##m0##_MHZ, PLL_##m1##_MHZ, PLL_##m2##_MHZ, PLL_##m4##_MHZ, \ |
| 433 | pll0_##m0##_pll1_##m1##_pll2_##m2##_pll4_##m4 \ |
| 434 | } |
| 435 | |
| 436 | struct pll_freq_tbl_map { |
| 437 | unsigned int pll0_l; |
| 438 | unsigned int pll1_l; |
| 439 | unsigned int pll2_l; |
| 440 | unsigned int pll4_l; |
| 441 | struct clkctl_acpu_speed *tbl; |
| 442 | }; |
| 443 | |
| 444 | static struct pll_freq_tbl_map acpu_freq_tbl_list[] = { |
| 445 | PLL_CONFIG(196, 768, 1056, 0), |
| 446 | PLL_CONFIG(245, 768, 1056, 0), |
| 447 | PLL_CONFIG(196, 960, 1056, 0), |
| 448 | PLL_CONFIG(245, 960, 1056, 0), |
| 449 | PLL_CONFIG(196, 960, 1200, 0), |
| 450 | PLL_CONFIG(245, 960, 1200, 0), |
| 451 | PLL_CONFIG(960, 196, 1200, 0), |
| 452 | PLL_CONFIG(960, 245, 1200, 0), |
| 453 | PLL_CONFIG(960, 196, 800, 0), |
| 454 | PLL_CONFIG(960, 245, 800, 0), |
| 455 | PLL_CONFIG(960, 245, 1200, 800), |
| 456 | PLL_CONFIG(960, 196, 1200, 800), |
Trilok Soni | f597e24 | 2011-06-06 12:37:16 +0530 | [diff] [blame] | 457 | PLL_CONFIG(960, 245, 1200, 1008), |
Trilok Soni | d7b05e5 | 2011-08-17 18:09:08 +0530 | [diff] [blame] | 458 | PLL_CONFIG(960, 196, 1200, 1008), |
Trilok Soni | 9bb022c | 2011-10-31 18:25:19 +0530 | [diff] [blame^] | 459 | PLL_CONFIG(960, 737, 1200, 800), |
| 460 | PLL_CONFIG(960, 589, 1200, 800), |
| 461 | PLL_CONFIG(960, 737, 1200, 1008), |
| 462 | PLL_CONFIG(960, 589, 1200, 1008), |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 463 | { 0, 0, 0, 0, 0 } |
| 464 | }; |
| 465 | |
| 466 | #ifdef CONFIG_CPU_FREQ_MSM |
| 467 | static struct cpufreq_frequency_table freq_table[20]; |
| 468 | |
| 469 | static void __init cpufreq_table_init(void) |
| 470 | { |
| 471 | unsigned int i; |
| 472 | unsigned int freq_cnt = 0; |
| 473 | |
| 474 | /* Construct the freq_table table from acpu_freq_tbl since the |
| 475 | * freq_table values need to match frequencies specified in |
| 476 | * acpu_freq_tbl and acpu_freq_tbl needs to be fixed up during init. |
| 477 | */ |
| 478 | for (i = 0; acpu_freq_tbl[i].a11clk_khz != 0 |
| 479 | && freq_cnt < ARRAY_SIZE(freq_table)-1; i++) { |
| 480 | if (acpu_freq_tbl[i].use_for_scaling) { |
| 481 | freq_table[freq_cnt].index = freq_cnt; |
| 482 | freq_table[freq_cnt].frequency |
| 483 | = acpu_freq_tbl[i].a11clk_khz; |
| 484 | freq_cnt++; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /* freq_table not big enough to store all usable freqs. */ |
| 489 | BUG_ON(acpu_freq_tbl[i].a11clk_khz != 0); |
| 490 | |
| 491 | freq_table[freq_cnt].index = freq_cnt; |
| 492 | freq_table[freq_cnt].frequency = CPUFREQ_TABLE_END; |
| 493 | |
| 494 | pr_info("%d scaling frequencies supported.\n", freq_cnt); |
| 495 | } |
| 496 | #endif |
| 497 | |
| 498 | static void pll_enable(void __iomem *addr, unsigned on) |
| 499 | { |
| 500 | if (on) { |
| 501 | writel_relaxed(2, addr); |
| 502 | mb(); |
| 503 | udelay(5); |
| 504 | writel_relaxed(6, addr); |
| 505 | mb(); |
| 506 | udelay(50); |
| 507 | writel_relaxed(7, addr); |
| 508 | } else { |
| 509 | writel_relaxed(0, addr); |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | static int pc_pll_request(unsigned id, unsigned on) |
| 514 | { |
| 515 | int res = 0; |
| 516 | on = !!on; |
| 517 | |
| 518 | if (on) |
| 519 | pr_debug("Enabling PLL %d\n", id); |
| 520 | else |
| 521 | pr_debug("Disabling PLL %d\n", id); |
| 522 | |
| 523 | if (id >= ACPU_PLL_END) |
| 524 | return -EINVAL; |
| 525 | |
| 526 | if (pll_control) { |
| 527 | remote_spin_lock(&pll_lock); |
| 528 | if (on) { |
| 529 | pll_control->pll[PLL_BASE + id].votes |= 2; |
| 530 | if (!pll_control->pll[PLL_BASE + id].on) { |
| 531 | pll_enable(soc_pll[id].mod_reg, 1); |
| 532 | pll_control->pll[PLL_BASE + id].on = 1; |
| 533 | } |
| 534 | } else { |
| 535 | pll_control->pll[PLL_BASE + id].votes &= ~2; |
| 536 | if (pll_control->pll[PLL_BASE + id].on |
| 537 | && !pll_control->pll[PLL_BASE + id].votes) { |
| 538 | pll_enable(soc_pll[id].mod_reg, 0); |
| 539 | pll_control->pll[PLL_BASE + id].on = 0; |
| 540 | } |
| 541 | } |
| 542 | remote_spin_unlock(&pll_lock); |
| 543 | } else { |
| 544 | res = msm_proc_comm(PCOM_CLKCTL_RPC_PLL_REQUEST, &id, &on); |
| 545 | if (res < 0) |
| 546 | return res; |
| 547 | else if ((int) id < 0) |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
| 551 | if (on) |
| 552 | pr_debug("PLL enabled\n"); |
| 553 | else |
| 554 | pr_debug("PLL disabled\n"); |
| 555 | |
| 556 | return res; |
| 557 | } |
| 558 | |
| 559 | |
| 560 | /*---------------------------------------------------------------------------- |
| 561 | * ARM11 'owned' clock control |
| 562 | *---------------------------------------------------------------------------*/ |
| 563 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 564 | static int acpuclk_set_vdd_level(int vdd) |
| 565 | { |
| 566 | uint32_t current_vdd; |
| 567 | |
| 568 | /* |
| 569 | * NOTE: v1.0 of 7x27a/7x25a chip doesn't have working |
| 570 | * VDD switching support. |
| 571 | */ |
| 572 | if ((cpu_is_msm7x27a() || cpu_is_msm7x25a()) && |
| 573 | (SOCINFO_VERSION_MINOR(socinfo_get_version()) < 1)) |
| 574 | return 0; |
| 575 | |
| 576 | current_vdd = readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x07; |
| 577 | |
| 578 | pr_debug("Switching VDD from %u mV -> %d mV\n", |
| 579 | current_vdd, vdd); |
| 580 | |
| 581 | writel_relaxed((1 << 7) | (vdd << 3), A11S_VDD_SVS_PLEVEL_ADDR); |
| 582 | mb(); |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 583 | udelay(62); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 584 | if ((readl_relaxed(A11S_VDD_SVS_PLEVEL_ADDR) & 0x7) != vdd) { |
| 585 | pr_err("VDD set failed\n"); |
| 586 | return -EIO; |
| 587 | } |
| 588 | |
| 589 | pr_debug("VDD switched\n"); |
| 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | /* Set proper dividers for the given clock speed. */ |
| 595 | static void acpuclk_set_div(const struct clkctl_acpu_speed *hunt_s) |
| 596 | { |
| 597 | uint32_t reg_clkctl, reg_clksel, clk_div, src_sel; |
| 598 | |
| 599 | reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR); |
| 600 | |
| 601 | /* AHB_CLK_DIV */ |
| 602 | clk_div = (reg_clksel >> 1) & 0x03; |
| 603 | /* CLK_SEL_SRC1NO */ |
| 604 | src_sel = reg_clksel & 1; |
| 605 | |
| 606 | /* |
| 607 | * If the new clock divider is higher than the previous, then |
| 608 | * program the divider before switching the clock |
| 609 | */ |
| 610 | if (hunt_s->ahbclk_div > clk_div) { |
| 611 | reg_clksel &= ~(0x3 << 1); |
| 612 | reg_clksel |= (hunt_s->ahbclk_div << 1); |
| 613 | writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR); |
| 614 | } |
| 615 | |
| 616 | /* Program clock source and divider */ |
| 617 | reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR); |
| 618 | reg_clkctl &= ~(0xFF << (8 * src_sel)); |
| 619 | reg_clkctl |= hunt_s->a11clk_src_sel << (4 + 8 * src_sel); |
| 620 | reg_clkctl |= hunt_s->a11clk_src_div << (0 + 8 * src_sel); |
| 621 | writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR); |
| 622 | |
| 623 | /* Program clock source selection */ |
| 624 | reg_clksel ^= 1; |
| 625 | writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR); |
| 626 | |
| 627 | /* |
| 628 | * If the new clock divider is lower than the previous, then |
| 629 | * program the divider after switching the clock |
| 630 | */ |
| 631 | if (hunt_s->ahbclk_div < clk_div) { |
| 632 | reg_clksel &= ~(0x3 << 1); |
| 633 | reg_clksel |= (hunt_s->ahbclk_div << 1); |
| 634 | writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR); |
| 635 | } |
| 636 | } |
| 637 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 638 | static int acpuclk_7201_set_rate(int cpu, unsigned long rate, |
| 639 | enum setrate_reason reason) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 640 | { |
| 641 | uint32_t reg_clkctl; |
| 642 | struct clkctl_acpu_speed *cur_s, *tgt_s, *strt_s; |
| 643 | int res, rc = 0; |
| 644 | unsigned int plls_enabled = 0, pll; |
| 645 | |
| 646 | if (reason == SETRATE_CPUFREQ) |
| 647 | mutex_lock(&drv_state.lock); |
| 648 | |
| 649 | strt_s = cur_s = drv_state.current_speed; |
| 650 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 651 | WARN_ONCE(cur_s == NULL, "%s: not initialized\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 652 | if (cur_s == NULL) { |
| 653 | rc = -ENOENT; |
| 654 | goto out; |
| 655 | } |
| 656 | |
| 657 | if (rate == cur_s->a11clk_khz) |
| 658 | goto out; |
| 659 | |
| 660 | for (tgt_s = acpu_freq_tbl; tgt_s->a11clk_khz != 0; tgt_s++) { |
| 661 | if (tgt_s->a11clk_khz == rate) |
| 662 | break; |
| 663 | } |
| 664 | |
| 665 | if (tgt_s->a11clk_khz == 0) { |
| 666 | rc = -EINVAL; |
| 667 | goto out; |
| 668 | } |
| 669 | |
| 670 | /* Choose the highest speed at or below 'rate' with same PLL. */ |
| 671 | if (reason != SETRATE_CPUFREQ |
| 672 | && tgt_s->a11clk_khz < cur_s->a11clk_khz) { |
| 673 | while (tgt_s->pll != ACPU_PLL_TCXO && tgt_s->pll != cur_s->pll) |
| 674 | tgt_s--; |
| 675 | } |
| 676 | |
| 677 | if (strt_s->pll != ACPU_PLL_TCXO) |
| 678 | plls_enabled |= 1 << strt_s->pll; |
| 679 | |
| 680 | if (reason == SETRATE_CPUFREQ) { |
| 681 | if (strt_s->pll != tgt_s->pll && tgt_s->pll != ACPU_PLL_TCXO) { |
| 682 | rc = pc_pll_request(tgt_s->pll, 1); |
| 683 | if (rc < 0) { |
| 684 | pr_err("PLL%d enable failed (%d)\n", |
| 685 | tgt_s->pll, rc); |
| 686 | goto out; |
| 687 | } |
| 688 | plls_enabled |= 1 << tgt_s->pll; |
| 689 | } |
| 690 | } |
| 691 | /* Need to do this when coming out of power collapse since some modem |
| 692 | * firmwares reset the VDD when the application processor enters power |
| 693 | * collapse. */ |
| 694 | if (reason == SETRATE_CPUFREQ || reason == SETRATE_PC) { |
| 695 | /* Increase VDD if needed. */ |
| 696 | if (tgt_s->vdd > cur_s->vdd) { |
| 697 | rc = acpuclk_set_vdd_level(tgt_s->vdd); |
| 698 | if (rc < 0) { |
| 699 | pr_err("Unable to switch ACPU vdd (%d)\n", rc); |
| 700 | goto out; |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /* Set wait states for CPU inbetween frequency changes */ |
| 706 | reg_clkctl = readl_relaxed(A11S_CLK_CNTL_ADDR); |
| 707 | reg_clkctl |= (100 << 16); /* set WT_ST_CNT */ |
| 708 | writel_relaxed(reg_clkctl, A11S_CLK_CNTL_ADDR); |
| 709 | |
| 710 | pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n", |
| 711 | strt_s->a11clk_khz, tgt_s->a11clk_khz); |
| 712 | |
| 713 | while (cur_s != tgt_s) { |
| 714 | /* |
| 715 | * Always jump to target freq if within 256mhz, regulardless of |
| 716 | * PLL. If differnece is greater, use the predefinied |
| 717 | * steppings in the table. |
| 718 | */ |
| 719 | int d = abs((int)(cur_s->a11clk_khz - tgt_s->a11clk_khz)); |
| 720 | if (d > drv_state.max_speed_delta_khz) { |
| 721 | |
| 722 | if (tgt_s->a11clk_khz > cur_s->a11clk_khz) { |
| 723 | /* Step up: jump to target PLL as early as |
| 724 | * possible so indexing using TCXO (up[-1]) |
| 725 | * never occurs. */ |
| 726 | if (likely(cur_s->up[tgt_s->pll])) |
| 727 | cur_s = cur_s->up[tgt_s->pll]; |
| 728 | else |
| 729 | cur_s = cur_s->up[cur_s->pll]; |
| 730 | } else { |
| 731 | /* Step down: stay on current PLL as long as |
| 732 | * possible so indexing using TCXO (down[-1]) |
| 733 | * never occurs. */ |
| 734 | if (likely(cur_s->down[cur_s->pll])) |
| 735 | cur_s = cur_s->down[cur_s->pll]; |
| 736 | else |
| 737 | cur_s = cur_s->down[tgt_s->pll]; |
| 738 | } |
| 739 | |
| 740 | if (cur_s == NULL) { /* This should not happen. */ |
| 741 | pr_err("No stepping frequencies found. " |
| 742 | "strt_s:%u tgt_s:%u\n", |
| 743 | strt_s->a11clk_khz, tgt_s->a11clk_khz); |
| 744 | rc = -EINVAL; |
| 745 | goto out; |
| 746 | } |
| 747 | |
| 748 | } else { |
| 749 | cur_s = tgt_s; |
| 750 | } |
| 751 | |
| 752 | pr_debug("STEP khz = %u, pll = %d\n", |
| 753 | cur_s->a11clk_khz, cur_s->pll); |
| 754 | |
| 755 | if (cur_s->pll != ACPU_PLL_TCXO |
| 756 | && !(plls_enabled & (1 << cur_s->pll))) { |
| 757 | rc = pc_pll_request(cur_s->pll, 1); |
| 758 | if (rc < 0) { |
| 759 | pr_err("PLL%d enable failed (%d)\n", |
| 760 | cur_s->pll, rc); |
| 761 | goto out; |
| 762 | } |
| 763 | plls_enabled |= 1 << cur_s->pll; |
| 764 | } |
| 765 | |
| 766 | acpuclk_set_div(cur_s); |
| 767 | drv_state.current_speed = cur_s; |
| 768 | /* Re-adjust lpj for the new clock speed. */ |
| 769 | loops_per_jiffy = cur_s->lpj; |
| 770 | mb(); |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 771 | udelay(50); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* Nothing else to do for SWFI. */ |
| 775 | if (reason == SETRATE_SWFI) |
| 776 | goto out; |
| 777 | |
| 778 | /* Change the AXI bus frequency if we can. */ |
| 779 | if (strt_s->axiclk_khz != tgt_s->axiclk_khz) { |
| 780 | res = clk_set_rate(drv_state.ebi1_clk, |
| 781 | tgt_s->axiclk_khz * 1000); |
| 782 | if (res < 0) |
| 783 | pr_warning("Setting AXI min rate failed (%d)\n", res); |
| 784 | } |
| 785 | |
| 786 | /* Disable PLLs we are not using anymore. */ |
| 787 | if (tgt_s->pll != ACPU_PLL_TCXO) |
| 788 | plls_enabled &= ~(1 << tgt_s->pll); |
| 789 | for (pll = ACPU_PLL_0; pll < ACPU_PLL_END; pll++) |
| 790 | if (plls_enabled & (1 << pll)) { |
| 791 | res = pc_pll_request(pll, 0); |
| 792 | if (res < 0) |
| 793 | pr_warning("PLL%d disable failed (%d)\n", |
| 794 | pll, res); |
| 795 | } |
| 796 | |
| 797 | /* Nothing else to do for power collapse. */ |
| 798 | if (reason == SETRATE_PC) |
| 799 | goto out; |
| 800 | |
| 801 | /* Drop VDD level if we can. */ |
| 802 | if (tgt_s->vdd < strt_s->vdd) { |
| 803 | res = acpuclk_set_vdd_level(tgt_s->vdd); |
| 804 | if (res < 0) |
| 805 | pr_warning("Unable to drop ACPU vdd (%d)\n", res); |
| 806 | } |
| 807 | |
| 808 | pr_debug("ACPU speed change complete\n"); |
| 809 | out: |
| 810 | if (reason == SETRATE_CPUFREQ) |
| 811 | mutex_unlock(&drv_state.lock); |
| 812 | return rc; |
| 813 | } |
| 814 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 815 | static void __init acpuclk_hw_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 816 | { |
| 817 | struct clkctl_acpu_speed *speed; |
Trilok Soni | 7d6c865 | 2011-07-14 15:35:07 +0530 | [diff] [blame] | 818 | uint32_t div, sel, reg_clksel; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 819 | int res; |
| 820 | |
| 821 | /* |
| 822 | * Determine the rate of ACPU clock |
| 823 | */ |
| 824 | |
| 825 | if (!(readl_relaxed(A11S_CLK_SEL_ADDR) & 0x01)) { /* CLK_SEL_SRC1N0 */ |
| 826 | /* CLK_SRC0_SEL */ |
| 827 | sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 12) & 0x7; |
| 828 | /* CLK_SRC0_DIV */ |
| 829 | div = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 8) & 0x0f; |
| 830 | } else { |
| 831 | /* CLK_SRC1_SEL */ |
| 832 | sel = (readl_relaxed(A11S_CLK_CNTL_ADDR) >> 4) & 0x07; |
| 833 | /* CLK_SRC1_DIV */ |
| 834 | div = readl_relaxed(A11S_CLK_CNTL_ADDR) & 0x0f; |
| 835 | } |
| 836 | |
| 837 | /* Accomodate bootloaders that might not be implementing the |
| 838 | * workaround for the h/w bug in 7x25. */ |
| 839 | if (cpu_is_msm7x25() && sel == 2) |
| 840 | sel = 3; |
| 841 | |
| 842 | for (speed = acpu_freq_tbl; speed->a11clk_khz != 0; speed++) { |
| 843 | if (speed->a11clk_src_sel == sel |
| 844 | && (speed->a11clk_src_div == div)) |
| 845 | break; |
| 846 | } |
| 847 | if (speed->a11clk_khz == 0) { |
| 848 | pr_err("Error - ACPU clock reports invalid speed\n"); |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | drv_state.current_speed = speed; |
| 853 | if (speed->pll != ACPU_PLL_TCXO) |
| 854 | if (pc_pll_request(speed->pll, 1)) |
| 855 | pr_warning("Failed to vote for boot PLL\n"); |
| 856 | |
Trilok Soni | 7d6c865 | 2011-07-14 15:35:07 +0530 | [diff] [blame] | 857 | /* Fix div2 to 2 for 7x27/5a(aa) targets */ |
| 858 | if (!cpu_is_msm7x27()) { |
| 859 | reg_clksel = readl_relaxed(A11S_CLK_SEL_ADDR); |
| 860 | reg_clksel &= ~(0x3 << 14); |
| 861 | reg_clksel |= (0x1 << 14); |
| 862 | writel_relaxed(reg_clksel, A11S_CLK_SEL_ADDR); |
| 863 | } |
| 864 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 865 | res = clk_set_rate(drv_state.ebi1_clk, speed->axiclk_khz * 1000); |
| 866 | if (res < 0) |
| 867 | pr_warning("Setting AXI min rate failed (%d)\n", res); |
| 868 | res = clk_enable(drv_state.ebi1_clk); |
| 869 | if (res < 0) |
| 870 | pr_warning("Enabling AXI clock failed (%d)\n", res); |
| 871 | |
| 872 | pr_info("ACPU running at %d KHz\n", speed->a11clk_khz); |
| 873 | } |
| 874 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 875 | static unsigned long acpuclk_7201_get_rate(int cpu) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 876 | { |
| 877 | WARN_ONCE(drv_state.current_speed == NULL, |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 878 | "%s: not initialized\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 879 | if (drv_state.current_speed) |
| 880 | return drv_state.current_speed->a11clk_khz; |
| 881 | else |
| 882 | return 0; |
| 883 | } |
| 884 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 885 | /*---------------------------------------------------------------------------- |
| 886 | * Clock driver initialization |
| 887 | *---------------------------------------------------------------------------*/ |
| 888 | |
| 889 | #define DIV2REG(n) ((n)-1) |
| 890 | #define REG2DIV(n) ((n)+1) |
| 891 | #define SLOWER_BY(div, factor) div = DIV2REG(REG2DIV(div) * factor) |
| 892 | |
| 893 | static void __init acpu_freq_tbl_fixup(void) |
| 894 | { |
| 895 | unsigned long pll0_l, pll1_l, pll2_l, pll4_l; |
| 896 | int axi_160mhz = 0, axi_200mhz = 0; |
| 897 | struct pll_freq_tbl_map *lst; |
| 898 | struct clkctl_acpu_speed *t; |
| 899 | unsigned int pll0_needs_fixup = 0; |
| 900 | |
| 901 | /* Wait for the PLLs to be initialized and then read their frequency. |
| 902 | */ |
| 903 | do { |
| 904 | pll0_l = readl_relaxed(PLLn_L_VAL(0)) & |
| 905 | soc_pll[ACPU_PLL_0].l_val_mask; |
| 906 | cpu_relax(); |
| 907 | udelay(50); |
| 908 | } while (pll0_l == 0); |
| 909 | do { |
| 910 | pll1_l = readl_relaxed(PLLn_L_VAL(1)) & |
| 911 | soc_pll[ACPU_PLL_1].l_val_mask; |
| 912 | cpu_relax(); |
| 913 | udelay(50); |
| 914 | } while (pll1_l == 0); |
| 915 | do { |
| 916 | pll2_l = readl_relaxed(PLLn_L_VAL(2)) & |
| 917 | soc_pll[ACPU_PLL_2].l_val_mask; |
| 918 | cpu_relax(); |
| 919 | udelay(50); |
| 920 | } while (pll2_l == 0); |
| 921 | |
| 922 | pr_info("L val: PLL0: %d, PLL1: %d, PLL2: %d\n", |
| 923 | (int)pll0_l, (int)pll1_l, (int)pll2_l); |
| 924 | |
| 925 | if (!cpu_is_msm7x27() && !cpu_is_msm7x25a()) { |
| 926 | do { |
| 927 | pll4_l = readl_relaxed(PLL4_L_VAL) & |
| 928 | soc_pll[ACPU_PLL_4].l_val_mask; |
| 929 | cpu_relax(); |
| 930 | udelay(50); |
| 931 | } while (pll4_l == 0); |
| 932 | pr_info("L val: PLL4: %d\n", (int)pll4_l); |
| 933 | } else { |
| 934 | pll4_l = 0; |
| 935 | } |
| 936 | |
| 937 | /* Some configurations run PLL0 twice as fast. Instead of having |
| 938 | * separate tables for this case, we simply fix up the ACPU clock |
| 939 | * source divider since it's a simple fix up. |
| 940 | */ |
| 941 | if (pll0_l == PLL_491_MHZ) { |
| 942 | pll0_l = PLL_245_MHZ; |
| 943 | pll0_needs_fixup = 1; |
| 944 | } |
| 945 | |
Trilok Soni | 54d35c4 | 2011-07-14 17:47:50 +0530 | [diff] [blame] | 946 | /* Fix the tables for 7x25a variant to not conflict with 7x27 ones */ |
| 947 | if (cpu_is_msm7x25a()) { |
| 948 | if (pll1_l == PLL_245_MHZ) { |
| 949 | acpu_freq_tbl = |
| 950 | pll0_960_pll1_245_pll2_1200_pll4_800_25a; |
Trilok Soni | 9bb022c | 2011-10-31 18:25:19 +0530 | [diff] [blame^] | 951 | } else if (pll1_l == PLL_737_MHZ) { |
| 952 | acpu_freq_tbl = |
| 953 | pll0_960_pll1_737_pll2_1200_pll4_800_25a; |
Trilok Soni | 54d35c4 | 2011-07-14 17:47:50 +0530 | [diff] [blame] | 954 | } |
| 955 | } else { |
| 956 | /* Select the right table to use. */ |
| 957 | for (lst = acpu_freq_tbl_list; lst->tbl != 0; lst++) { |
| 958 | if (lst->pll0_l == pll0_l && lst->pll1_l == pll1_l |
| 959 | && lst->pll2_l == pll2_l |
| 960 | && lst->pll4_l == pll4_l) { |
| 961 | acpu_freq_tbl = lst->tbl; |
| 962 | break; |
| 963 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
| 967 | if (acpu_freq_tbl == NULL) { |
| 968 | pr_crit("Unknown PLL configuration!\n"); |
| 969 | BUG(); |
| 970 | } |
| 971 | |
| 972 | /* Fix up PLL0 source divider if necessary. Also, fix up the AXI to |
| 973 | * the max that's supported by the board (RAM used in board). |
| 974 | */ |
| 975 | axi_160mhz = (pll0_l == PLL_960_MHZ || pll1_l == PLL_960_MHZ); |
| 976 | axi_200mhz = (pll2_l == PLL_1200_MHZ || pll2_l == PLL_800_MHZ); |
| 977 | for (t = &acpu_freq_tbl[0]; t->a11clk_khz != 0; t++) { |
| 978 | |
| 979 | if (pll0_needs_fixup && t->pll == ACPU_PLL_0) |
| 980 | SLOWER_BY(t->a11clk_src_div, 2); |
| 981 | if (axi_160mhz && drv_state.max_axi_khz >= 160000 |
| 982 | && t->ahbclk_khz > 128000) |
| 983 | t->axiclk_khz = 160000; |
| 984 | if (axi_200mhz && drv_state.max_axi_khz >= 200000 |
| 985 | && t->ahbclk_khz > 160000) |
| 986 | t->axiclk_khz = 200000; |
| 987 | } |
| 988 | |
| 989 | t--; |
| 990 | drv_state.max_axi_khz = t->axiclk_khz; |
| 991 | |
| 992 | /* The default 7x27 ACPU clock plan supports running the AXI bus at |
| 993 | * 200 MHz. So we don't classify it as Turbo mode. |
| 994 | */ |
| 995 | if (cpu_is_msm7x27()) |
| 996 | return; |
| 997 | |
| 998 | if (!axi_160mhz) |
| 999 | pr_info("Turbo mode not supported.\n"); |
| 1000 | else if (t->axiclk_khz == 160000) |
| 1001 | pr_info("Turbo mode supported and enabled.\n"); |
| 1002 | else |
| 1003 | pr_info("Turbo mode supported but not enabled.\n"); |
| 1004 | } |
| 1005 | |
| 1006 | /* |
| 1007 | * Hardware requires the CPU to be dropped to less than MAX_WAIT_FOR_IRQ_KHZ |
| 1008 | * before entering a wait for irq low-power mode. Find a suitable rate. |
| 1009 | */ |
| 1010 | static unsigned long __init find_wait_for_irq_khz(void) |
| 1011 | { |
| 1012 | unsigned long found_khz = 0; |
| 1013 | int i; |
| 1014 | |
| 1015 | for (i = 0; acpu_freq_tbl[i].a11clk_khz && |
| 1016 | acpu_freq_tbl[i].a11clk_khz <= MAX_WAIT_FOR_IRQ_KHZ; i++) |
| 1017 | found_khz = acpu_freq_tbl[i].a11clk_khz; |
| 1018 | |
| 1019 | return found_khz; |
| 1020 | } |
| 1021 | |
| 1022 | /* Initalize the lpj field in the acpu_freq_tbl. */ |
| 1023 | static void __init lpj_init(void) |
| 1024 | { |
| 1025 | int i; |
| 1026 | const struct clkctl_acpu_speed *base_clk = drv_state.current_speed; |
| 1027 | for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) { |
| 1028 | acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy, |
| 1029 | base_clk->a11clk_khz, |
| 1030 | acpu_freq_tbl[i].a11clk_khz); |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | static void __init precompute_stepping(void) |
| 1035 | { |
| 1036 | int i, step_idx; |
| 1037 | |
| 1038 | #define cur_freq acpu_freq_tbl[i].a11clk_khz |
| 1039 | #define step_freq acpu_freq_tbl[step_idx].a11clk_khz |
| 1040 | #define cur_pll acpu_freq_tbl[i].pll |
| 1041 | #define step_pll acpu_freq_tbl[step_idx].pll |
| 1042 | |
| 1043 | for (i = 0; acpu_freq_tbl[i].a11clk_khz; i++) { |
| 1044 | |
| 1045 | /* Calculate max "up" step for each destination PLL */ |
| 1046 | step_idx = i + 1; |
| 1047 | while (step_freq && (step_freq - cur_freq) |
| 1048 | <= drv_state.max_speed_delta_khz) { |
| 1049 | acpu_freq_tbl[i].up[step_pll] = |
| 1050 | &acpu_freq_tbl[step_idx]; |
| 1051 | step_idx++; |
| 1052 | } |
| 1053 | if (step_idx == (i + 1) && step_freq) { |
| 1054 | pr_crit("Delta between freqs %u KHz and %u KHz is" |
| 1055 | " too high!\n", cur_freq, step_freq); |
| 1056 | BUG(); |
| 1057 | } |
| 1058 | |
| 1059 | /* Calculate max "down" step for each destination PLL */ |
| 1060 | step_idx = i - 1; |
| 1061 | while (step_idx >= 0 && (cur_freq - step_freq) |
| 1062 | <= drv_state.max_speed_delta_khz) { |
| 1063 | acpu_freq_tbl[i].down[step_pll] = |
| 1064 | &acpu_freq_tbl[step_idx]; |
| 1065 | step_idx--; |
| 1066 | } |
| 1067 | if (step_idx == (i - 1) && i > 0) { |
| 1068 | pr_crit("Delta between freqs %u KHz and %u KHz is" |
| 1069 | " too high!\n", cur_freq, step_freq); |
| 1070 | BUG(); |
| 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | static void __init print_acpu_freq_tbl(void) |
| 1076 | { |
| 1077 | struct clkctl_acpu_speed *t; |
| 1078 | short down_idx[ACPU_PLL_END]; |
| 1079 | short up_idx[ACPU_PLL_END]; |
| 1080 | int i, j; |
| 1081 | |
| 1082 | #define FREQ_IDX(freq_ptr) (freq_ptr - acpu_freq_tbl) |
| 1083 | pr_info("Id CPU-KHz PLL DIV AHB-KHz ADIV AXI-KHz " |
| 1084 | "D0 D1 D2 D4 U0 U1 U2 U4\n"); |
| 1085 | |
| 1086 | t = &acpu_freq_tbl[0]; |
| 1087 | for (i = 0; t->a11clk_khz != 0; i++) { |
| 1088 | |
| 1089 | for (j = 0; j < ACPU_PLL_END; j++) { |
| 1090 | down_idx[j] = t->down[j] ? FREQ_IDX(t->down[j]) : -1; |
| 1091 | up_idx[j] = t->up[j] ? FREQ_IDX(t->up[j]) : -1; |
| 1092 | } |
| 1093 | |
| 1094 | pr_info("%2d %7d %3d %3d %7d %4d %7d " |
| 1095 | "%2d %2d %2d %2d %2d %2d %2d %2d\n", |
| 1096 | i, t->a11clk_khz, t->pll, t->a11clk_src_div + 1, |
| 1097 | t->ahbclk_khz, t->ahbclk_div + 1, t->axiclk_khz, |
| 1098 | down_idx[0], down_idx[1], down_idx[2], down_idx[4], |
| 1099 | up_idx[0], up_idx[1], up_idx[2], up_idx[4]); |
| 1100 | |
| 1101 | t++; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | static void msm7x25_acpu_pll_hw_bug_fix(void) |
| 1106 | { |
| 1107 | unsigned int n; |
| 1108 | |
| 1109 | /* The 7625 has a hardware bug and in order to select PLL2 we |
| 1110 | * must program PLL3. Use the same table, and just fix up the |
| 1111 | * numbers on this target. */ |
| 1112 | for (n = 0; acpu_freq_tbl[n].a11clk_khz != 0; n++) |
| 1113 | if (acpu_freq_tbl[n].pll == ACPU_PLL_2) |
| 1114 | acpu_freq_tbl[n].a11clk_src_sel = 3; |
| 1115 | } |
| 1116 | |
| 1117 | static void shared_pll_control_init(void) |
| 1118 | { |
| 1119 | #define PLL_REMOTE_SPINLOCK_ID "S:7" |
| 1120 | unsigned smem_size; |
| 1121 | remote_spin_lock_init(&pll_lock, PLL_REMOTE_SPINLOCK_ID); |
| 1122 | pll_control = smem_get_entry(SMEM_CLKREGIM_SOURCES, &smem_size); |
| 1123 | |
| 1124 | if (!pll_control) |
| 1125 | pr_warning("Can't find shared PLL control data structure!\n"); |
| 1126 | /* There might be more PLLs than what the application processor knows |
| 1127 | * about. But the index used for each PLL is guaranteed to remain the |
| 1128 | * same. */ |
| 1129 | else if (smem_size < sizeof(struct shared_pll_control)) |
| 1130 | pr_warning("Shared PLL control data structure too small!\n"); |
| 1131 | else if (pll_control->version != 0xCCEE0001) |
| 1132 | pr_warning("Shared PLL control version mismatch!\n"); |
| 1133 | else { |
| 1134 | pr_info("Shared PLL control available.\n"); |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | pll_control = NULL; |
| 1139 | pr_warning("Falling back to proc_comm PLL control.\n"); |
| 1140 | } |
| 1141 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1142 | static struct acpuclk_data acpuclk_7201_data = { |
| 1143 | .set_rate = acpuclk_7201_set_rate, |
| 1144 | .get_rate = acpuclk_7201_get_rate, |
| 1145 | .power_collapse_khz = POWER_COLLAPSE_KHZ, |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 1146 | .switch_time_us = 50, |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1147 | }; |
| 1148 | |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 1149 | static int __init acpuclk_7201_init(struct acpuclk_soc_data *soc_data) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1150 | { |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1151 | pr_info("%s()\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1152 | |
| 1153 | drv_state.ebi1_clk = clk_get(NULL, "ebi1_acpu_clk"); |
| 1154 | BUG_ON(IS_ERR(drv_state.ebi1_clk)); |
| 1155 | |
| 1156 | mutex_init(&drv_state.lock); |
| 1157 | shared_pll_control_init(); |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 1158 | drv_state.max_speed_delta_khz = soc_data->max_speed_delta_khz; |
| 1159 | drv_state.max_axi_khz = soc_data->max_axi_khz; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1160 | acpu_freq_tbl_fixup(); |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1161 | acpuclk_7201_data.wait_for_irq_khz = find_wait_for_irq_khz(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1162 | precompute_stepping(); |
| 1163 | if (cpu_is_msm7x25()) |
| 1164 | msm7x25_acpu_pll_hw_bug_fix(); |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1165 | acpuclk_hw_init(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1166 | lpj_init(); |
| 1167 | print_acpu_freq_tbl(); |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1168 | acpuclk_register(&acpuclk_7201_data); |
| 1169 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1170 | #ifdef CONFIG_CPU_FREQ_MSM |
| 1171 | cpufreq_table_init(); |
| 1172 | cpufreq_frequency_table_get_attr(freq_table, smp_processor_id()); |
| 1173 | #endif |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 1174 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1175 | } |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 1176 | |
| 1177 | struct acpuclk_soc_data acpuclk_7201_soc_data __initdata = { |
| 1178 | .max_speed_delta_khz = 400000, |
| 1179 | .max_axi_khz = 160000, |
| 1180 | .init = acpuclk_7201_init, |
| 1181 | }; |
| 1182 | |
| 1183 | struct acpuclk_soc_data acpuclk_7x27_soc_data __initdata = { |
| 1184 | .max_speed_delta_khz = 400000, |
| 1185 | .max_axi_khz = 200000, |
| 1186 | .init = acpuclk_7201_init, |
| 1187 | }; |
| 1188 | |
| 1189 | struct acpuclk_soc_data acpuclk_7x27a_soc_data __initdata = { |
| 1190 | .max_speed_delta_khz = 400000, |
| 1191 | .max_axi_khz = 200000, |
| 1192 | .init = acpuclk_7201_init, |
| 1193 | }; |
| 1194 | |
| 1195 | struct acpuclk_soc_data acpuclk_7x27aa_soc_data __initdata = { |
| 1196 | .max_speed_delta_khz = 504000, |
| 1197 | .max_axi_khz = 200000, |
| 1198 | .init = acpuclk_7201_init, |
| 1199 | }; |