Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 by Sascha Hauer, Pengutronix |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version 2 |
| 7 | * of the License, or (at your option) any later version. |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program; if not, write to the Free Software |
| 15 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 16 | * MA 02110-1301, USA. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/list.h> |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/io.h> |
Jean-Christop PLAGNIOL-VILLARD | 6d803ba | 2010-11-17 10:04:33 +0100 | [diff] [blame] | 24 | #include <linux/clkdev.h> |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 25 | |
| 26 | #include <mach/clock.h> |
| 27 | #include <mach/hardware.h> |
| 28 | #include <mach/common.h> |
| 29 | |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 30 | #include "crmregs-imx3.h" |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 31 | |
| 32 | #ifdef HAVE_SET_RATE_SUPPORT |
| 33 | static void calc_dividers(u32 div, u32 *pre, u32 *post, u32 maxpost) |
| 34 | { |
| 35 | u32 min_pre, temp_pre, old_err, err; |
| 36 | |
| 37 | min_pre = (div - 1) / maxpost + 1; |
| 38 | old_err = 8; |
| 39 | |
| 40 | for (temp_pre = 8; temp_pre >= min_pre; temp_pre--) { |
| 41 | if (div > (temp_pre * maxpost)) |
| 42 | break; |
| 43 | |
| 44 | if (div < (temp_pre * temp_pre)) |
| 45 | continue; |
| 46 | |
| 47 | err = div % temp_pre; |
| 48 | |
| 49 | if (err == 0) { |
| 50 | *pre = temp_pre; |
| 51 | break; |
| 52 | } |
| 53 | |
| 54 | err = temp_pre - err; |
| 55 | |
| 56 | if (err < old_err) { |
| 57 | old_err = err; |
| 58 | *pre = temp_pre; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | *post = (div + *pre - 1) / *pre; |
| 63 | } |
| 64 | |
| 65 | /* get the best values for a 3-bit divider combined with a 6-bit divider */ |
| 66 | static void calc_dividers_3_6(u32 div, u32 *pre, u32 *post) |
| 67 | { |
| 68 | if (div >= 512) { |
| 69 | *pre = 8; |
| 70 | *post = 64; |
| 71 | } else if (div >= 64) { |
| 72 | calc_dividers(div, pre, post, 64); |
| 73 | } else if (div <= 8) { |
| 74 | *pre = div; |
| 75 | *post = 1; |
| 76 | } else { |
| 77 | *pre = 1; |
| 78 | *post = div; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /* get the best values for two cascaded 3-bit dividers */ |
| 83 | static void calc_dividers_3_3(u32 div, u32 *pre, u32 *post) |
| 84 | { |
| 85 | if (div >= 64) { |
| 86 | *pre = *post = 8; |
| 87 | } else if (div > 8) { |
| 88 | calc_dividers(div, pre, post, 8); |
| 89 | } else { |
| 90 | *pre = 1; |
| 91 | *post = div; |
| 92 | } |
| 93 | } |
| 94 | #endif |
| 95 | |
| 96 | static unsigned long get_rate_mpll(void) |
| 97 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 98 | ulong mpctl = __raw_readl(MX35_CCM_MPCTL); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 99 | |
| 100 | return mxc_decode_pll(mpctl, 24000000); |
| 101 | } |
| 102 | |
| 103 | static unsigned long get_rate_ppll(void) |
| 104 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 105 | ulong ppctl = __raw_readl(MX35_CCM_PPCTL); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 106 | |
| 107 | return mxc_decode_pll(ppctl, 24000000); |
| 108 | } |
| 109 | |
| 110 | struct arm_ahb_div { |
| 111 | unsigned char arm, ahb, sel; |
| 112 | }; |
| 113 | |
| 114 | static struct arm_ahb_div clk_consumer[] = { |
| 115 | { .arm = 1, .ahb = 4, .sel = 0}, |
| 116 | { .arm = 1, .ahb = 3, .sel = 1}, |
| 117 | { .arm = 2, .ahb = 2, .sel = 0}, |
| 118 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 119 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 120 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 121 | { .arm = 4, .ahb = 1, .sel = 0}, |
| 122 | { .arm = 1, .ahb = 5, .sel = 0}, |
| 123 | { .arm = 1, .ahb = 8, .sel = 0}, |
| 124 | { .arm = 1, .ahb = 6, .sel = 1}, |
| 125 | { .arm = 2, .ahb = 4, .sel = 0}, |
| 126 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 127 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 128 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 129 | { .arm = 4, .ahb = 2, .sel = 0}, |
| 130 | { .arm = 0, .ahb = 0, .sel = 0}, |
| 131 | }; |
| 132 | |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 133 | static unsigned long get_rate_arm(void) |
| 134 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 135 | unsigned long pdr0 = __raw_readl(MXC_CCM_PDR0); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 136 | struct arm_ahb_div *aad; |
| 137 | unsigned long fref = get_rate_mpll(); |
| 138 | |
Sascha Hauer | d16caf6 | 2009-03-23 10:07:48 +0100 | [diff] [blame] | 139 | aad = &clk_consumer[(pdr0 >> 16) & 0xf]; |
| 140 | if (aad->sel) |
Marc Kleine-Budde | c56702d | 2010-08-16 15:54:06 +0200 | [diff] [blame] | 141 | fref = fref * 3 / 4; |
Sascha Hauer | d16caf6 | 2009-03-23 10:07:48 +0100 | [diff] [blame] | 142 | |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 143 | return fref / aad->arm; |
| 144 | } |
| 145 | |
| 146 | static unsigned long get_rate_ahb(struct clk *clk) |
| 147 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 148 | unsigned long pdr0 = __raw_readl(MXC_CCM_PDR0); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 149 | struct arm_ahb_div *aad; |
Marc Kleine-Budde | c56702d | 2010-08-16 15:54:06 +0200 | [diff] [blame] | 150 | unsigned long fref = get_rate_arm(); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 151 | |
Sascha Hauer | d16caf6 | 2009-03-23 10:07:48 +0100 | [diff] [blame] | 152 | aad = &clk_consumer[(pdr0 >> 16) & 0xf]; |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 153 | |
| 154 | return fref / aad->ahb; |
| 155 | } |
| 156 | |
| 157 | static unsigned long get_rate_ipg(struct clk *clk) |
| 158 | { |
| 159 | return get_rate_ahb(NULL) >> 1; |
| 160 | } |
| 161 | |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 162 | static unsigned long get_rate_uart(struct clk *clk) |
| 163 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 164 | unsigned long pdr3 = __raw_readl(MX35_CCM_PDR3); |
| 165 | unsigned long pdr4 = __raw_readl(MX35_CCM_PDR4); |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 166 | unsigned long div = ((pdr4 >> 10) & 0x3f) + 1; |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 167 | |
| 168 | if (pdr3 & (1 << 14)) |
| 169 | return get_rate_arm() / div; |
| 170 | else |
| 171 | return get_rate_ppll() / div; |
| 172 | } |
| 173 | |
| 174 | static unsigned long get_rate_sdhc(struct clk *clk) |
| 175 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 176 | unsigned long pdr3 = __raw_readl(MX35_CCM_PDR3); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 177 | unsigned long div, rate; |
| 178 | |
| 179 | if (pdr3 & (1 << 6)) |
| 180 | rate = get_rate_arm(); |
| 181 | else |
| 182 | rate = get_rate_ppll(); |
| 183 | |
| 184 | switch (clk->id) { |
| 185 | default: |
| 186 | case 0: |
| 187 | div = pdr3 & 0x3f; |
| 188 | break; |
| 189 | case 1: |
| 190 | div = (pdr3 >> 8) & 0x3f; |
| 191 | break; |
| 192 | case 2: |
| 193 | div = (pdr3 >> 16) & 0x3f; |
| 194 | break; |
| 195 | } |
| 196 | |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 197 | return rate / (div + 1); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | static unsigned long get_rate_mshc(struct clk *clk) |
| 201 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 202 | unsigned long pdr1 = __raw_readl(MXC_CCM_PDR1); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 203 | unsigned long div1, div2, rate; |
| 204 | |
| 205 | if (pdr1 & (1 << 7)) |
| 206 | rate = get_rate_arm(); |
| 207 | else |
| 208 | rate = get_rate_ppll(); |
| 209 | |
| 210 | div1 = (pdr1 >> 29) & 0x7; |
| 211 | div2 = (pdr1 >> 22) & 0x3f; |
| 212 | |
| 213 | return rate / ((div1 + 1) * (div2 + 1)); |
| 214 | } |
| 215 | |
| 216 | static unsigned long get_rate_ssi(struct clk *clk) |
| 217 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 218 | unsigned long pdr2 = __raw_readl(MX35_CCM_PDR2); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 219 | unsigned long div1, div2, rate; |
| 220 | |
| 221 | if (pdr2 & (1 << 6)) |
| 222 | rate = get_rate_arm(); |
| 223 | else |
| 224 | rate = get_rate_ppll(); |
| 225 | |
| 226 | switch (clk->id) { |
| 227 | default: |
| 228 | case 0: |
| 229 | div1 = pdr2 & 0x3f; |
| 230 | div2 = (pdr2 >> 24) & 0x7; |
| 231 | break; |
| 232 | case 1: |
| 233 | div1 = (pdr2 >> 8) & 0x3f; |
| 234 | div2 = (pdr2 >> 27) & 0x7; |
| 235 | break; |
| 236 | } |
| 237 | |
| 238 | return rate / ((div1 + 1) * (div2 + 1)); |
| 239 | } |
| 240 | |
| 241 | static unsigned long get_rate_csi(struct clk *clk) |
| 242 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 243 | unsigned long pdr2 = __raw_readl(MX35_CCM_PDR2); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 244 | unsigned long rate; |
| 245 | |
| 246 | if (pdr2 & (1 << 7)) |
| 247 | rate = get_rate_arm(); |
| 248 | else |
| 249 | rate = get_rate_ppll(); |
| 250 | |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 251 | return rate / (((pdr2 >> 16) & 0x3f) + 1); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 252 | } |
| 253 | |
Sascha Hauer | 547270a | 2009-03-17 15:43:54 +0100 | [diff] [blame] | 254 | static unsigned long get_rate_otg(struct clk *clk) |
| 255 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 256 | unsigned long pdr4 = __raw_readl(MX35_CCM_PDR4); |
Sascha Hauer | 547270a | 2009-03-17 15:43:54 +0100 | [diff] [blame] | 257 | unsigned long rate; |
| 258 | |
| 259 | if (pdr4 & (1 << 9)) |
| 260 | rate = get_rate_arm(); |
| 261 | else |
| 262 | rate = get_rate_ppll(); |
| 263 | |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 264 | return rate / (((pdr4 >> 22) & 0x3f) + 1); |
Sascha Hauer | 547270a | 2009-03-17 15:43:54 +0100 | [diff] [blame] | 265 | } |
| 266 | |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 267 | static unsigned long get_rate_ipg_per(struct clk *clk) |
| 268 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 269 | unsigned long pdr0 = __raw_readl(MXC_CCM_PDR0); |
| 270 | unsigned long pdr4 = __raw_readl(MX35_CCM_PDR4); |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 271 | unsigned long div; |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 272 | |
| 273 | if (pdr0 & (1 << 26)) { |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 274 | div = (pdr4 >> 16) & 0x3f; |
| 275 | return get_rate_arm() / (div + 1); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 276 | } else { |
Sascha Hauer | 9a6f17f | 2010-04-22 12:37:13 +0200 | [diff] [blame] | 277 | div = (pdr0 >> 12) & 0x7; |
Marc Kleine-Budde | c96c1e3 | 2010-08-16 15:54:05 +0200 | [diff] [blame] | 278 | return get_rate_ahb(NULL) / (div + 1); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Juergen Beisert | c735c40 | 2010-08-16 15:54:07 +0200 | [diff] [blame] | 282 | static unsigned long get_rate_hsp(struct clk *clk) |
| 283 | { |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 284 | unsigned long hsp_podf = (__raw_readl(MXC_CCM_PDR0) >> 20) & 0x03; |
Juergen Beisert | c735c40 | 2010-08-16 15:54:07 +0200 | [diff] [blame] | 285 | unsigned long fref = get_rate_mpll(); |
| 286 | |
| 287 | if (fref > 400 * 1000 * 1000) { |
| 288 | switch (hsp_podf) { |
| 289 | case 0: |
| 290 | return fref >> 2; |
| 291 | case 1: |
| 292 | return fref >> 3; |
| 293 | case 2: |
| 294 | return fref / 3; |
| 295 | } |
| 296 | } else { |
| 297 | switch (hsp_podf) { |
| 298 | case 0: |
| 299 | case 2: |
| 300 | return fref / 3; |
| 301 | case 1: |
| 302 | return fref / 6; |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | return 0; |
| 307 | } |
| 308 | |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 309 | static int clk_cgr_enable(struct clk *clk) |
| 310 | { |
| 311 | u32 reg; |
| 312 | |
| 313 | reg = __raw_readl(clk->enable_reg); |
| 314 | reg |= 3 << clk->enable_shift; |
| 315 | __raw_writel(reg, clk->enable_reg); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | static void clk_cgr_disable(struct clk *clk) |
| 321 | { |
| 322 | u32 reg; |
| 323 | |
| 324 | reg = __raw_readl(clk->enable_reg); |
| 325 | reg &= ~(3 << clk->enable_shift); |
| 326 | __raw_writel(reg, clk->enable_reg); |
| 327 | } |
| 328 | |
| 329 | #define DEFINE_CLOCK(name, i, er, es, gr, sr) \ |
| 330 | static struct clk name = { \ |
| 331 | .id = i, \ |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 332 | .enable_reg = er, \ |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 333 | .enable_shift = es, \ |
| 334 | .get_rate = gr, \ |
| 335 | .set_rate = sr, \ |
| 336 | .enable = clk_cgr_enable, \ |
| 337 | .disable = clk_cgr_disable, \ |
| 338 | } |
| 339 | |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 340 | DEFINE_CLOCK(asrc_clk, 0, MX35_CCM_CGR0, 0, NULL, NULL); |
| 341 | DEFINE_CLOCK(pata_clk, 0, MX35_CCM_CGR0, 2, get_rate_ipg, NULL); |
| 342 | /* DEFINE_CLOCK(audmux_clk, 0, MX35_CCM_CGR0, 4, NULL, NULL); */ |
| 343 | DEFINE_CLOCK(can1_clk, 0, MX35_CCM_CGR0, 6, get_rate_ipg, NULL); |
| 344 | DEFINE_CLOCK(can2_clk, 1, MX35_CCM_CGR0, 8, get_rate_ipg, NULL); |
| 345 | DEFINE_CLOCK(cspi1_clk, 0, MX35_CCM_CGR0, 10, get_rate_ipg, NULL); |
| 346 | DEFINE_CLOCK(cspi2_clk, 1, MX35_CCM_CGR0, 12, get_rate_ipg, NULL); |
| 347 | DEFINE_CLOCK(ect_clk, 0, MX35_CCM_CGR0, 14, get_rate_ipg, NULL); |
| 348 | DEFINE_CLOCK(edio_clk, 0, MX35_CCM_CGR0, 16, NULL, NULL); |
| 349 | DEFINE_CLOCK(emi_clk, 0, MX35_CCM_CGR0, 18, get_rate_ipg, NULL); |
| 350 | DEFINE_CLOCK(epit1_clk, 0, MX35_CCM_CGR0, 20, get_rate_ipg, NULL); |
| 351 | DEFINE_CLOCK(epit2_clk, 1, MX35_CCM_CGR0, 22, get_rate_ipg, NULL); |
| 352 | DEFINE_CLOCK(esai_clk, 0, MX35_CCM_CGR0, 24, NULL, NULL); |
| 353 | DEFINE_CLOCK(esdhc1_clk, 0, MX35_CCM_CGR0, 26, get_rate_sdhc, NULL); |
| 354 | DEFINE_CLOCK(esdhc2_clk, 1, MX35_CCM_CGR0, 28, get_rate_sdhc, NULL); |
| 355 | DEFINE_CLOCK(esdhc3_clk, 2, MX35_CCM_CGR0, 30, get_rate_sdhc, NULL); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 356 | |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 357 | DEFINE_CLOCK(fec_clk, 0, MX35_CCM_CGR1, 0, get_rate_ipg, NULL); |
| 358 | DEFINE_CLOCK(gpio1_clk, 0, MX35_CCM_CGR1, 2, NULL, NULL); |
| 359 | DEFINE_CLOCK(gpio2_clk, 1, MX35_CCM_CGR1, 4, NULL, NULL); |
| 360 | DEFINE_CLOCK(gpio3_clk, 2, MX35_CCM_CGR1, 6, NULL, NULL); |
| 361 | DEFINE_CLOCK(gpt_clk, 0, MX35_CCM_CGR1, 8, get_rate_ipg, NULL); |
| 362 | DEFINE_CLOCK(i2c1_clk, 0, MX35_CCM_CGR1, 10, get_rate_ipg_per, NULL); |
| 363 | DEFINE_CLOCK(i2c2_clk, 1, MX35_CCM_CGR1, 12, get_rate_ipg_per, NULL); |
| 364 | DEFINE_CLOCK(i2c3_clk, 2, MX35_CCM_CGR1, 14, get_rate_ipg_per, NULL); |
| 365 | DEFINE_CLOCK(iomuxc_clk, 0, MX35_CCM_CGR1, 16, NULL, NULL); |
| 366 | DEFINE_CLOCK(ipu_clk, 0, MX35_CCM_CGR1, 18, get_rate_hsp, NULL); |
| 367 | DEFINE_CLOCK(kpp_clk, 0, MX35_CCM_CGR1, 20, get_rate_ipg, NULL); |
| 368 | DEFINE_CLOCK(mlb_clk, 0, MX35_CCM_CGR1, 22, get_rate_ahb, NULL); |
| 369 | DEFINE_CLOCK(mshc_clk, 0, MX35_CCM_CGR1, 24, get_rate_mshc, NULL); |
| 370 | DEFINE_CLOCK(owire_clk, 0, MX35_CCM_CGR1, 26, get_rate_ipg_per, NULL); |
| 371 | DEFINE_CLOCK(pwm_clk, 0, MX35_CCM_CGR1, 28, get_rate_ipg_per, NULL); |
| 372 | DEFINE_CLOCK(rngc_clk, 0, MX35_CCM_CGR1, 30, get_rate_ipg, NULL); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 373 | |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 374 | DEFINE_CLOCK(rtc_clk, 0, MX35_CCM_CGR2, 0, get_rate_ipg, NULL); |
| 375 | DEFINE_CLOCK(rtic_clk, 0, MX35_CCM_CGR2, 2, get_rate_ahb, NULL); |
| 376 | DEFINE_CLOCK(scc_clk, 0, MX35_CCM_CGR2, 4, get_rate_ipg, NULL); |
| 377 | DEFINE_CLOCK(sdma_clk, 0, MX35_CCM_CGR2, 6, NULL, NULL); |
| 378 | DEFINE_CLOCK(spba_clk, 0, MX35_CCM_CGR2, 8, get_rate_ipg, NULL); |
| 379 | DEFINE_CLOCK(spdif_clk, 0, MX35_CCM_CGR2, 10, NULL, NULL); |
| 380 | DEFINE_CLOCK(ssi1_clk, 0, MX35_CCM_CGR2, 12, get_rate_ssi, NULL); |
| 381 | DEFINE_CLOCK(ssi2_clk, 1, MX35_CCM_CGR2, 14, get_rate_ssi, NULL); |
| 382 | DEFINE_CLOCK(uart1_clk, 0, MX35_CCM_CGR2, 16, get_rate_uart, NULL); |
| 383 | DEFINE_CLOCK(uart2_clk, 1, MX35_CCM_CGR2, 18, get_rate_uart, NULL); |
| 384 | DEFINE_CLOCK(uart3_clk, 2, MX35_CCM_CGR2, 20, get_rate_uart, NULL); |
| 385 | DEFINE_CLOCK(usbotg_clk, 0, MX35_CCM_CGR2, 22, get_rate_otg, NULL); |
| 386 | DEFINE_CLOCK(wdog_clk, 0, MX35_CCM_CGR2, 24, NULL, NULL); |
| 387 | DEFINE_CLOCK(max_clk, 0, MX35_CCM_CGR2, 26, NULL, NULL); |
| 388 | DEFINE_CLOCK(audmux_clk, 0, MX35_CCM_CGR2, 30, NULL, NULL); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 389 | |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 390 | DEFINE_CLOCK(csi_clk, 0, MX35_CCM_CGR3, 0, get_rate_csi, NULL); |
| 391 | DEFINE_CLOCK(iim_clk, 0, MX35_CCM_CGR3, 2, NULL, NULL); |
| 392 | DEFINE_CLOCK(gpu2d_clk, 0, MX35_CCM_CGR3, 4, NULL, NULL); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 393 | |
Harro Haan | 3e9a23d | 2009-11-27 11:44:35 +0100 | [diff] [blame] | 394 | DEFINE_CLOCK(usbahb_clk, 0, 0, 0, get_rate_ahb, NULL); |
| 395 | |
Juergen Beisert | 9e0afdf | 2009-10-02 11:24:49 +0200 | [diff] [blame] | 396 | static int clk_dummy_enable(struct clk *clk) |
| 397 | { |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static void clk_dummy_disable(struct clk *clk) |
| 402 | { |
| 403 | } |
| 404 | |
| 405 | static unsigned long get_rate_nfc(struct clk *clk) |
| 406 | { |
| 407 | unsigned long div1; |
| 408 | |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 409 | div1 = (__raw_readl(MX35_CCM_PDR4) >> 28) + 1; |
Juergen Beisert | 9e0afdf | 2009-10-02 11:24:49 +0200 | [diff] [blame] | 410 | |
| 411 | return get_rate_ahb(NULL) / div1; |
| 412 | } |
| 413 | |
| 414 | /* NAND Controller: It seems it can't be disabled */ |
| 415 | static struct clk nfc_clk = { |
| 416 | .id = 0, |
| 417 | .enable_reg = 0, |
| 418 | .enable_shift = 0, |
| 419 | .get_rate = get_rate_nfc, |
| 420 | .set_rate = NULL, /* set_rate_nfc, */ |
| 421 | .enable = clk_dummy_enable, |
| 422 | .disable = clk_dummy_disable |
| 423 | }; |
| 424 | |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 425 | #define _REGISTER_CLOCK(d, n, c) \ |
| 426 | { \ |
| 427 | .dev_id = d, \ |
| 428 | .con_id = n, \ |
| 429 | .clk = &c, \ |
| 430 | }, |
| 431 | |
Rabin Vincent | 6b4bfb8 | 2009-05-26 22:31:46 +0530 | [diff] [blame] | 432 | static struct clk_lookup lookups[] = { |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 433 | _REGISTER_CLOCK(NULL, "asrc", asrc_clk) |
Fabio Estevam | 03b20b0 | 2011-08-23 17:18:07 -0300 | [diff] [blame] | 434 | _REGISTER_CLOCK("pata_imx", NULL, pata_clk) |
Marc Kleine-Budde | 757e1e4 | 2010-04-30 01:19:35 +0200 | [diff] [blame] | 435 | _REGISTER_CLOCK("flexcan.0", NULL, can1_clk) |
| 436 | _REGISTER_CLOCK("flexcan.1", NULL, can2_clk) |
Uwe Kleine-König | ab56050 | 2010-09-09 21:02:02 +0200 | [diff] [blame] | 437 | _REGISTER_CLOCK("imx35-cspi.0", NULL, cspi1_clk) |
| 438 | _REGISTER_CLOCK("imx35-cspi.1", NULL, cspi2_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 439 | _REGISTER_CLOCK(NULL, "ect", ect_clk) |
| 440 | _REGISTER_CLOCK(NULL, "edio", edio_clk) |
| 441 | _REGISTER_CLOCK(NULL, "emi", emi_clk) |
Sascha Hauer | bd45140 | 2010-08-19 14:08:05 +0200 | [diff] [blame] | 442 | _REGISTER_CLOCK("imx-epit.0", NULL, epit1_clk) |
| 443 | _REGISTER_CLOCK("imx-epit.1", NULL, epit2_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 444 | _REGISTER_CLOCK(NULL, "esai", esai_clk) |
Shawn Guo | 57ed331 | 2011-06-30 09:24:26 +0800 | [diff] [blame] | 445 | _REGISTER_CLOCK("sdhci-esdhc-imx35.0", NULL, esdhc1_clk) |
| 446 | _REGISTER_CLOCK("sdhci-esdhc-imx35.1", NULL, esdhc2_clk) |
| 447 | _REGISTER_CLOCK("sdhci-esdhc-imx35.2", NULL, esdhc3_clk) |
Shawn Guo | 0ca1e29 | 2011-07-01 18:11:22 +0800 | [diff] [blame] | 448 | /* i.mx35 has the i.mx27 type fec */ |
| 449 | _REGISTER_CLOCK("imx27-fec.0", NULL, fec_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 450 | _REGISTER_CLOCK(NULL, "gpio", gpio1_clk) |
| 451 | _REGISTER_CLOCK(NULL, "gpio", gpio2_clk) |
| 452 | _REGISTER_CLOCK(NULL, "gpio", gpio3_clk) |
| 453 | _REGISTER_CLOCK("gpt.0", NULL, gpt_clk) |
| 454 | _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk) |
| 455 | _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk) |
| 456 | _REGISTER_CLOCK("imx-i2c.2", NULL, i2c3_clk) |
| 457 | _REGISTER_CLOCK(NULL, "iomuxc", iomuxc_clk) |
Sascha Hauer | 76b6ea0 | 2009-04-01 10:09:18 +0200 | [diff] [blame] | 458 | _REGISTER_CLOCK("ipu-core", NULL, ipu_clk) |
| 459 | _REGISTER_CLOCK("mx3_sdc_fb", NULL, ipu_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 460 | _REGISTER_CLOCK(NULL, "kpp", kpp_clk) |
| 461 | _REGISTER_CLOCK(NULL, "mlb", mlb_clk) |
| 462 | _REGISTER_CLOCK(NULL, "mshc", mshc_clk) |
| 463 | _REGISTER_CLOCK("mxc_w1", NULL, owire_clk) |
| 464 | _REGISTER_CLOCK(NULL, "pwm", pwm_clk) |
| 465 | _REGISTER_CLOCK(NULL, "rngc", rngc_clk) |
| 466 | _REGISTER_CLOCK(NULL, "rtc", rtc_clk) |
| 467 | _REGISTER_CLOCK(NULL, "rtic", rtic_clk) |
| 468 | _REGISTER_CLOCK(NULL, "scc", scc_clk) |
Shawn Guo | 62550cd | 2011-07-13 21:33:17 +0800 | [diff] [blame] | 469 | _REGISTER_CLOCK("imx35-sdma", NULL, sdma_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 470 | _REGISTER_CLOCK(NULL, "spba", spba_clk) |
| 471 | _REGISTER_CLOCK(NULL, "spdif", spdif_clk) |
Sascha Hauer | d8d982b | 2009-10-29 17:17:42 +0100 | [diff] [blame] | 472 | _REGISTER_CLOCK("imx-ssi.0", NULL, ssi1_clk) |
| 473 | _REGISTER_CLOCK("imx-ssi.1", NULL, ssi2_clk) |
Shawn Guo | fe6b540 | 2011-06-25 02:04:33 +0800 | [diff] [blame] | 474 | /* i.mx35 has the i.mx21 type uart */ |
| 475 | _REGISTER_CLOCK("imx21-uart.0", NULL, uart1_clk) |
| 476 | _REGISTER_CLOCK("imx21-uart.1", NULL, uart2_clk) |
| 477 | _REGISTER_CLOCK("imx21-uart.2", NULL, uart3_clk) |
Sascha Hauer | 547270a | 2009-03-17 15:43:54 +0100 | [diff] [blame] | 478 | _REGISTER_CLOCK("mxc-ehci.0", "usb", usbotg_clk) |
| 479 | _REGISTER_CLOCK("mxc-ehci.1", "usb", usbotg_clk) |
| 480 | _REGISTER_CLOCK("mxc-ehci.2", "usb", usbotg_clk) |
| 481 | _REGISTER_CLOCK("fsl-usb2-udc", "usb", usbotg_clk) |
Harro Haan | 3e9a23d | 2009-11-27 11:44:35 +0100 | [diff] [blame] | 482 | _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", usbahb_clk) |
Fabio Estevam | 2c1f467 | 2010-12-07 14:16:04 -0200 | [diff] [blame] | 483 | _REGISTER_CLOCK("imx2-wdt.0", NULL, wdog_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 484 | _REGISTER_CLOCK(NULL, "max", max_clk) |
Sascha Hauer | 4dc7be7 | 2009-11-02 09:49:41 +0100 | [diff] [blame] | 485 | _REGISTER_CLOCK(NULL, "audmux", audmux_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 486 | _REGISTER_CLOCK(NULL, "csi", csi_clk) |
| 487 | _REGISTER_CLOCK(NULL, "iim", iim_clk) |
| 488 | _REGISTER_CLOCK(NULL, "gpu2d", gpu2d_clk) |
Juergen Beisert | 9e0afdf | 2009-10-02 11:24:49 +0200 | [diff] [blame] | 489 | _REGISTER_CLOCK("mxc_nand.0", NULL, nfc_clk) |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 490 | }; |
| 491 | |
| 492 | int __init mx35_clocks_init() |
| 493 | { |
Eric Bénard | 9cd39fb | 2011-12-13 15:13:19 +0100 | [diff] [blame] | 494 | unsigned int cgr2 = 3 << 26; |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 495 | |
Uwe Kleine-König | 97adeda | 2009-11-12 22:56:29 +0100 | [diff] [blame] | 496 | #if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_ICEDCC) |
Hans J. Koch | 3d6e614 | 2010-08-12 15:10:53 +0200 | [diff] [blame] | 497 | cgr2 |= 3 << 16; |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 498 | #endif |
| 499 | |
Russell King | 0a0300d | 2010-01-12 12:28:00 +0000 | [diff] [blame] | 500 | clkdev_add_table(lookups, ARRAY_SIZE(lookups)); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 501 | |
| 502 | /* Turn off all clocks except the ones we need to survive, namely: |
| 503 | * EMI, GPIO1/2/3, GPT, IOMUX, MAX and eventually uart |
| 504 | */ |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 505 | __raw_writel((3 << 18), MX35_CCM_CGR0); |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 506 | __raw_writel((3 << 2) | (3 << 4) | (3 << 6) | (3 << 8) | (3 << 16), |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 507 | MX35_CCM_CGR1); |
| 508 | __raw_writel(cgr2, MX35_CCM_CGR2); |
| 509 | __raw_writel(0, MX35_CCM_CGR3); |
Eric Bénard | 9cd39fb | 2011-12-13 15:13:19 +0100 | [diff] [blame] | 510 | |
| 511 | clk_enable(&iim_clk); |
| 512 | imx_print_silicon_rev("i.MX35", mx35_revision()); |
| 513 | clk_disable(&iim_clk); |
Hans J. Koch | 3d6e614 | 2010-08-12 15:10:53 +0200 | [diff] [blame] | 514 | |
| 515 | /* |
| 516 | * Check if we came up in internal boot mode. If yes, we need some |
| 517 | * extra clocks turned on, otherwise the MX35 boot ROM code will |
| 518 | * hang after a watchdog reset. |
| 519 | */ |
Fabio Estevam | 29781fa | 2012-01-20 16:43:09 -0200 | [diff] [blame^] | 520 | if (!(__raw_readl(MX35_CCM_RCSR) & (3 << 10))) { |
Hans J. Koch | 3d6e614 | 2010-08-12 15:10:53 +0200 | [diff] [blame] | 521 | /* Additionally turn on UART1, SCC, and IIM clocks */ |
Eric Bénard | 9cd39fb | 2011-12-13 15:13:19 +0100 | [diff] [blame] | 522 | clk_enable(&iim_clk); |
| 523 | clk_enable(&uart1_clk); |
| 524 | clk_enable(&scc_clk); |
Hans J. Koch | 3d6e614 | 2010-08-12 15:10:53 +0200 | [diff] [blame] | 525 | } |
| 526 | |
Sascha Hauer | bd45140 | 2010-08-19 14:08:05 +0200 | [diff] [blame] | 527 | #ifdef CONFIG_MXC_USE_EPIT |
| 528 | epit_timer_init(&epit1_clk, |
| 529 | MX35_IO_ADDRESS(MX35_EPIT1_BASE_ADDR), MX35_INT_EPIT1); |
| 530 | #else |
Uwe Kleine-König | 6ef9af6 | 2009-12-16 19:07:20 +0100 | [diff] [blame] | 531 | mxc_timer_init(&gpt_clk, |
| 532 | MX35_IO_ADDRESS(MX35_GPT1_BASE_ADDR), MX35_INT_GPT); |
Sascha Hauer | bd45140 | 2010-08-19 14:08:05 +0200 | [diff] [blame] | 533 | #endif |
Sascha Hauer | 2cb536d | 2009-02-06 17:48:59 +0100 | [diff] [blame] | 534 | |
| 535 | return 0; |
| 536 | } |