Tom Warren | e23bb6a | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010-2013, NVIDIA CORPORATION. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | /* Tegra114 Clock control functions */ |
| 18 | |
| 19 | #include <common.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/arch/clock.h> |
| 22 | #include <asm/arch/tegra.h> |
| 23 | #include <asm/arch-tegra/clk_rst.h> |
| 24 | #include <asm/arch-tegra/timer.h> |
| 25 | #include <div64.h> |
| 26 | #include <fdtdec.h> |
| 27 | |
| 28 | /* |
| 29 | * Clock types that we can use as a source. The Tegra114 has muxes for the |
| 30 | * peripheral clocks, and in most cases there are four options for the clock |
| 31 | * source. This gives us a clock 'type' and exploits what commonality exists |
| 32 | * in the device. |
| 33 | * |
| 34 | * Letters are obvious, except for T which means CLK_M, and S which means the |
| 35 | * clock derived from 32KHz. Beware that CLK_M (also called OSC in the |
| 36 | * datasheet) and PLL_M are different things. The former is the basic |
| 37 | * clock supplied to the SOC from an external oscillator. The latter is the |
| 38 | * memory clock PLL. |
| 39 | * |
| 40 | * See definitions in clock_id in the header file. |
| 41 | */ |
| 42 | enum clock_type_id { |
| 43 | CLOCK_TYPE_AXPT, /* PLL_A, PLL_X, PLL_P, CLK_M */ |
| 44 | CLOCK_TYPE_MCPA, /* and so on */ |
| 45 | CLOCK_TYPE_MCPT, |
| 46 | CLOCK_TYPE_PCM, |
| 47 | CLOCK_TYPE_PCMT, |
| 48 | CLOCK_TYPE_PCMT16, |
| 49 | CLOCK_TYPE_PDCT, |
| 50 | CLOCK_TYPE_ACPT, |
| 51 | CLOCK_TYPE_ASPTE, |
| 52 | CLOCK_TYPE_PMDACD2T, |
| 53 | CLOCK_TYPE_PCST, |
| 54 | |
| 55 | CLOCK_TYPE_COUNT, |
| 56 | CLOCK_TYPE_NONE = -1, /* invalid clock type */ |
| 57 | }; |
| 58 | |
| 59 | enum { |
| 60 | CLOCK_MAX_MUX = 8 /* number of source options for each clock */ |
| 61 | }; |
| 62 | |
| 63 | enum { |
| 64 | MASK_BITS_31_30 = 2, /* num of bits used to specify clock source */ |
| 65 | MASK_BITS_31_29, |
| 66 | MASK_BITS_29_28, |
| 67 | }; |
| 68 | |
| 69 | /* |
| 70 | * Clock source mux for each clock type. This just converts our enum into |
| 71 | * a list of mux sources for use by the code. |
| 72 | * |
| 73 | * Note: |
| 74 | * The extra column in each clock source array is used to store the mask |
| 75 | * bits in its register for the source. |
| 76 | */ |
| 77 | #define CLK(x) CLOCK_ID_ ## x |
| 78 | static enum clock_id clock_source[CLOCK_TYPE_COUNT][CLOCK_MAX_MUX+1] = { |
| 79 | { CLK(AUDIO), CLK(XCPU), CLK(PERIPH), CLK(OSC), |
| 80 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 81 | MASK_BITS_31_30}, |
| 82 | { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(AUDIO), |
| 83 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 84 | MASK_BITS_31_30}, |
| 85 | { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC), |
| 86 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 87 | MASK_BITS_31_30}, |
| 88 | { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(NONE), |
| 89 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 90 | MASK_BITS_31_30}, |
| 91 | { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC), |
| 92 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 93 | MASK_BITS_31_30}, |
| 94 | { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC), |
| 95 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 96 | MASK_BITS_31_30}, |
| 97 | { CLK(PERIPH), CLK(DISPLAY), CLK(CGENERAL), CLK(OSC), |
| 98 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 99 | MASK_BITS_31_30}, |
| 100 | { CLK(AUDIO), CLK(CGENERAL), CLK(PERIPH), CLK(OSC), |
| 101 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 102 | MASK_BITS_31_30}, |
| 103 | { CLK(AUDIO), CLK(SFROM32KHZ), CLK(PERIPH), CLK(OSC), |
| 104 | CLK(EPCI), CLK(NONE), CLK(NONE), CLK(NONE), |
| 105 | MASK_BITS_31_29}, |
| 106 | { CLK(PERIPH), CLK(MEMORY), CLK(DISPLAY), CLK(AUDIO), |
| 107 | CLK(CGENERAL), CLK(DISPLAY2), CLK(OSC), CLK(NONE), |
| 108 | MASK_BITS_31_29}, |
| 109 | { CLK(PERIPH), CLK(CGENERAL), CLK(SFROM32KHZ), CLK(OSC), |
| 110 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 111 | MASK_BITS_29_28} |
| 112 | }; |
| 113 | |
| 114 | /* |
| 115 | * Clock type for each peripheral clock source. We put the name in each |
| 116 | * record just so it is easy to match things up |
| 117 | */ |
| 118 | #define TYPE(name, type) type |
| 119 | static enum clock_type_id clock_periph_type[PERIPHC_COUNT] = { |
| 120 | /* 0x00 */ |
| 121 | TYPE(PERIPHC_I2S1, CLOCK_TYPE_AXPT), |
| 122 | TYPE(PERIPHC_I2S2, CLOCK_TYPE_AXPT), |
| 123 | TYPE(PERIPHC_SPDIF_OUT, CLOCK_TYPE_AXPT), |
| 124 | TYPE(PERIPHC_SPDIF_IN, CLOCK_TYPE_PCM), |
| 125 | TYPE(PERIPHC_PWM, CLOCK_TYPE_PCST), /* only PWM uses b29:28 */ |
| 126 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 127 | TYPE(PERIPHC_SBC2, CLOCK_TYPE_PCMT), |
| 128 | TYPE(PERIPHC_SBC3, CLOCK_TYPE_PCMT), |
| 129 | |
| 130 | /* 0x08 */ |
| 131 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 132 | TYPE(PERIPHC_I2C1, CLOCK_TYPE_PCMT16), |
| 133 | TYPE(PERIPHC_I2C5, CLOCK_TYPE_PCMT16), |
| 134 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 135 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 136 | TYPE(PERIPHC_SBC1, CLOCK_TYPE_PCMT), |
| 137 | TYPE(PERIPHC_DISP1, CLOCK_TYPE_PMDACD2T), |
| 138 | TYPE(PERIPHC_DISP2, CLOCK_TYPE_PMDACD2T), |
| 139 | |
| 140 | /* 0x10 */ |
| 141 | TYPE(PERIPHC_CVE, CLOCK_TYPE_PDCT), |
| 142 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 143 | TYPE(PERIPHC_VI, CLOCK_TYPE_MCPA), |
| 144 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 145 | TYPE(PERIPHC_SDMMC1, CLOCK_TYPE_PCMT), |
| 146 | TYPE(PERIPHC_SDMMC2, CLOCK_TYPE_PCMT), |
| 147 | TYPE(PERIPHC_G3D, CLOCK_TYPE_MCPA), |
| 148 | TYPE(PERIPHC_G2D, CLOCK_TYPE_MCPA), |
| 149 | |
| 150 | /* 0x18 */ |
| 151 | TYPE(PERIPHC_NDFLASH, CLOCK_TYPE_PCMT), |
| 152 | TYPE(PERIPHC_SDMMC4, CLOCK_TYPE_PCMT), |
| 153 | TYPE(PERIPHC_VFIR, CLOCK_TYPE_PCMT), |
| 154 | TYPE(PERIPHC_EPP, CLOCK_TYPE_MCPA), |
| 155 | TYPE(PERIPHC_MPE, CLOCK_TYPE_MCPA), |
| 156 | TYPE(PERIPHC_MIPI, CLOCK_TYPE_PCMT), /* MIPI base-band HSI */ |
| 157 | TYPE(PERIPHC_UART1, CLOCK_TYPE_PCMT), |
| 158 | TYPE(PERIPHC_UART2, CLOCK_TYPE_PCMT), |
| 159 | |
| 160 | /* 0x20 */ |
| 161 | TYPE(PERIPHC_HOST1X, CLOCK_TYPE_MCPA), |
| 162 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 163 | TYPE(PERIPHC_TVO, CLOCK_TYPE_PDCT), |
| 164 | TYPE(PERIPHC_HDMI, CLOCK_TYPE_PMDACD2T), |
| 165 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 166 | TYPE(PERIPHC_TVDAC, CLOCK_TYPE_PDCT), |
| 167 | TYPE(PERIPHC_I2C2, CLOCK_TYPE_PCMT16), |
| 168 | TYPE(PERIPHC_EMC, CLOCK_TYPE_MCPT), |
| 169 | |
| 170 | /* 0x28 */ |
| 171 | TYPE(PERIPHC_UART3, CLOCK_TYPE_PCMT), |
| 172 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 173 | TYPE(PERIPHC_VI, CLOCK_TYPE_MCPA), |
| 174 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 175 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 176 | TYPE(PERIPHC_SBC4, CLOCK_TYPE_PCMT), |
| 177 | TYPE(PERIPHC_I2C3, CLOCK_TYPE_PCMT16), |
| 178 | TYPE(PERIPHC_SDMMC3, CLOCK_TYPE_PCMT), |
| 179 | |
| 180 | /* 0x30 */ |
| 181 | TYPE(PERIPHC_UART4, CLOCK_TYPE_PCMT), |
| 182 | TYPE(PERIPHC_UART5, CLOCK_TYPE_PCMT), |
| 183 | TYPE(PERIPHC_VDE, CLOCK_TYPE_PCMT), |
| 184 | TYPE(PERIPHC_OWR, CLOCK_TYPE_PCMT), |
| 185 | TYPE(PERIPHC_NOR, CLOCK_TYPE_PCMT), |
| 186 | TYPE(PERIPHC_CSITE, CLOCK_TYPE_PCMT), |
| 187 | TYPE(PERIPHC_I2S0, CLOCK_TYPE_AXPT), |
| 188 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 189 | |
| 190 | /* 0x38h */ /* Jumps to reg offset 0x3B0h */ |
| 191 | TYPE(PERIPHC_G3D2, CLOCK_TYPE_MCPA), |
| 192 | TYPE(PERIPHC_MSELECT, CLOCK_TYPE_PCMT), |
| 193 | TYPE(PERIPHC_TSENSOR, CLOCK_TYPE_PCST), /* s/b PCTS */ |
| 194 | TYPE(PERIPHC_I2S3, CLOCK_TYPE_AXPT), |
| 195 | TYPE(PERIPHC_I2S4, CLOCK_TYPE_AXPT), |
| 196 | TYPE(PERIPHC_I2C4, CLOCK_TYPE_PCMT16), |
| 197 | TYPE(PERIPHC_SBC5, CLOCK_TYPE_PCMT), |
| 198 | TYPE(PERIPHC_SBC6, CLOCK_TYPE_PCMT), |
| 199 | |
| 200 | /* 0x40 */ |
| 201 | TYPE(PERIPHC_AUDIO, CLOCK_TYPE_ACPT), |
| 202 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 203 | TYPE(PERIPHC_DAM0, CLOCK_TYPE_ACPT), |
| 204 | TYPE(PERIPHC_DAM1, CLOCK_TYPE_ACPT), |
| 205 | TYPE(PERIPHC_DAM2, CLOCK_TYPE_ACPT), |
| 206 | TYPE(PERIPHC_HDA2CODEC2X, CLOCK_TYPE_PCMT), |
| 207 | TYPE(PERIPHC_ACTMON, CLOCK_TYPE_PCST), /* MASK 31:30 */ |
| 208 | TYPE(PERIPHC_EXTPERIPH1, CLOCK_TYPE_ASPTE), |
| 209 | |
| 210 | /* 0x48 */ |
| 211 | TYPE(PERIPHC_EXTPERIPH2, CLOCK_TYPE_ASPTE), |
| 212 | TYPE(PERIPHC_EXTPERIPH3, CLOCK_TYPE_ASPTE), |
| 213 | TYPE(PERIPHC_NANDSPEED, CLOCK_TYPE_PCMT), |
| 214 | TYPE(PERIPHC_I2CSLOW, CLOCK_TYPE_PCST), /* MASK 31:30 */ |
| 215 | TYPE(PERIPHC_SYS, CLOCK_TYPE_NONE), |
| 216 | TYPE(PERIPHC_SPEEDO, CLOCK_TYPE_PCMT), |
| 217 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 218 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 219 | |
| 220 | /* 0x50 */ |
| 221 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 222 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 223 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 224 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 225 | TYPE(PERIPHC_SATAOOB, CLOCK_TYPE_PCMT), /* offset 0x420h */ |
| 226 | TYPE(PERIPHC_SATA, CLOCK_TYPE_PCMT), |
| 227 | TYPE(PERIPHC_HDA, CLOCK_TYPE_PCMT), |
| 228 | }; |
| 229 | |
| 230 | /* |
| 231 | * This array translates a periph_id to a periphc_internal_id |
| 232 | * |
| 233 | * Not present/matched up: |
| 234 | * uint vi_sensor; _VI_SENSOR_0, 0x1A8 |
| 235 | * SPDIF - which is both 0x08 and 0x0c |
| 236 | * |
| 237 | */ |
| 238 | #define NONE(name) (-1) |
| 239 | #define OFFSET(name, value) PERIPHC_ ## name |
| 240 | static s8 periph_id_to_internal_id[PERIPH_ID_COUNT] = { |
| 241 | /* Low word: 31:0 */ |
| 242 | NONE(CPU), |
| 243 | NONE(COP), |
| 244 | NONE(TRIGSYS), |
| 245 | NONE(RESERVED3), |
| 246 | NONE(RTC), |
| 247 | NONE(TMR), |
| 248 | PERIPHC_UART1, |
| 249 | PERIPHC_UART2, /* and vfir 0x68 */ |
| 250 | |
| 251 | /* 8 */ |
| 252 | NONE(GPIO), |
| 253 | PERIPHC_SDMMC2, |
| 254 | NONE(SPDIF), /* 0x08 and 0x0c, unclear which to use */ |
| 255 | PERIPHC_I2S1, |
| 256 | PERIPHC_I2C1, |
| 257 | PERIPHC_NDFLASH, |
| 258 | PERIPHC_SDMMC1, |
| 259 | PERIPHC_SDMMC4, |
| 260 | |
| 261 | /* 16 */ |
| 262 | NONE(RESERVED16), |
| 263 | PERIPHC_PWM, |
| 264 | PERIPHC_I2S2, |
| 265 | PERIPHC_EPP, |
| 266 | PERIPHC_VI, |
| 267 | PERIPHC_G2D, |
| 268 | NONE(USBD), |
| 269 | NONE(ISP), |
| 270 | |
| 271 | /* 24 */ |
| 272 | PERIPHC_G3D, |
| 273 | NONE(RESERVED25), |
| 274 | PERIPHC_DISP2, |
| 275 | PERIPHC_DISP1, |
| 276 | PERIPHC_HOST1X, |
| 277 | NONE(VCP), |
| 278 | PERIPHC_I2S0, |
| 279 | NONE(CACHE2), |
| 280 | |
| 281 | /* Middle word: 63:32 */ |
| 282 | NONE(MEM), |
| 283 | NONE(AHBDMA), |
| 284 | NONE(APBDMA), |
| 285 | NONE(RESERVED35), |
| 286 | NONE(RESERVED36), |
| 287 | NONE(STAT_MON), |
| 288 | NONE(RESERVED38), |
| 289 | NONE(RESERVED39), |
| 290 | |
| 291 | /* 40 */ |
| 292 | NONE(KFUSE), |
| 293 | NONE(SBC1), /* SBC1, 0x34, is this SPI1? */ |
| 294 | PERIPHC_NOR, |
| 295 | NONE(RESERVED43), |
| 296 | PERIPHC_SBC2, |
| 297 | NONE(RESERVED45), |
| 298 | PERIPHC_SBC3, |
| 299 | PERIPHC_I2C5, |
| 300 | |
| 301 | /* 48 */ |
| 302 | NONE(DSI), |
| 303 | PERIPHC_TVO, /* also CVE 0x40 */ |
| 304 | PERIPHC_MIPI, |
| 305 | PERIPHC_HDMI, |
| 306 | NONE(CSI), |
| 307 | PERIPHC_TVDAC, |
| 308 | PERIPHC_I2C2, |
| 309 | PERIPHC_UART3, |
| 310 | |
| 311 | /* 56 */ |
| 312 | NONE(RESERVED56), |
| 313 | PERIPHC_EMC, |
| 314 | NONE(USB2), |
| 315 | NONE(USB3), |
| 316 | PERIPHC_MPE, |
| 317 | PERIPHC_VDE, |
| 318 | NONE(BSEA), |
| 319 | NONE(BSEV), |
| 320 | |
| 321 | /* Upper word 95:64 */ |
| 322 | PERIPHC_SPEEDO, |
| 323 | PERIPHC_UART4, |
| 324 | PERIPHC_UART5, |
| 325 | PERIPHC_I2C3, |
| 326 | PERIPHC_SBC4, |
| 327 | PERIPHC_SDMMC3, |
| 328 | NONE(PCIE), |
| 329 | PERIPHC_OWR, |
| 330 | |
| 331 | /* 72 */ |
| 332 | NONE(AFI), |
| 333 | PERIPHC_CSITE, |
| 334 | NONE(PCIEXCLK), |
| 335 | NONE(AVPUCQ), |
| 336 | NONE(RESERVED76), |
| 337 | NONE(RESERVED77), |
| 338 | NONE(RESERVED78), |
| 339 | NONE(DTV), |
| 340 | |
| 341 | /* 80 */ |
| 342 | PERIPHC_NANDSPEED, |
| 343 | PERIPHC_I2CSLOW, |
| 344 | NONE(DSIB), |
| 345 | NONE(RESERVED83), |
| 346 | NONE(IRAMA), |
| 347 | NONE(IRAMB), |
| 348 | NONE(IRAMC), |
| 349 | NONE(IRAMD), |
| 350 | |
| 351 | /* 88 */ |
| 352 | NONE(CRAM2), |
| 353 | NONE(RESERVED89), |
| 354 | NONE(MDOUBLER), |
| 355 | NONE(RESERVED91), |
| 356 | NONE(SUSOUT), |
| 357 | NONE(RESERVED93), |
| 358 | NONE(RESERVED94), |
| 359 | NONE(RESERVED95), |
| 360 | |
| 361 | /* V word: 31:0 */ |
| 362 | NONE(CPUG), |
| 363 | NONE(CPULP), |
| 364 | PERIPHC_G3D2, |
| 365 | PERIPHC_MSELECT, |
| 366 | PERIPHC_TSENSOR, |
| 367 | PERIPHC_I2S3, |
| 368 | PERIPHC_I2S4, |
| 369 | PERIPHC_I2C4, |
| 370 | |
| 371 | /* 08 */ |
| 372 | PERIPHC_SBC5, |
| 373 | PERIPHC_SBC6, |
| 374 | PERIPHC_AUDIO, |
| 375 | NONE(APBIF), |
| 376 | PERIPHC_DAM0, |
| 377 | PERIPHC_DAM1, |
| 378 | PERIPHC_DAM2, |
| 379 | PERIPHC_HDA2CODEC2X, |
| 380 | |
| 381 | /* 16 */ |
| 382 | NONE(ATOMICS), |
| 383 | NONE(RESERVED17), |
| 384 | NONE(RESERVED18), |
| 385 | NONE(RESERVED19), |
| 386 | NONE(RESERVED20), |
| 387 | NONE(RESERVED21), |
| 388 | NONE(RESERVED22), |
| 389 | PERIPHC_ACTMON, |
| 390 | |
| 391 | /* 24 */ |
| 392 | NONE(RESERVED24), |
| 393 | NONE(RESERVED25), |
| 394 | NONE(RESERVED26), |
| 395 | NONE(RESERVED27), |
| 396 | PERIPHC_SATA, |
| 397 | PERIPHC_HDA, |
| 398 | NONE(RESERVED30), |
| 399 | NONE(RESERVED31), |
| 400 | |
| 401 | /* W word: 31:0 */ |
| 402 | NONE(HDA2HDMICODEC), |
| 403 | NONE(RESERVED1_SATACOLD), |
| 404 | NONE(RESERVED2_PCIERX0), |
| 405 | NONE(RESERVED3_PCIERX1), |
| 406 | NONE(RESERVED4_PCIERX2), |
| 407 | NONE(RESERVED5_PCIERX3), |
| 408 | NONE(RESERVED6_PCIERX4), |
| 409 | NONE(RESERVED7_PCIERX5), |
| 410 | |
| 411 | /* 40 */ |
| 412 | NONE(CEC), |
| 413 | NONE(PCIE2_IOBIST), |
| 414 | NONE(EMC_IOBIST), |
| 415 | NONE(HDMI_IOBIST), |
| 416 | NONE(SATA_IOBIST), |
| 417 | NONE(MIPI_IOBIST), |
| 418 | NONE(EMC1_IOBIST), |
| 419 | NONE(XUSB), |
| 420 | |
| 421 | /* 48 */ |
| 422 | NONE(CILAB), |
| 423 | NONE(CILCD), |
| 424 | NONE(CILE), |
| 425 | NONE(DSIA_LP), |
| 426 | NONE(DSIB_LP), |
| 427 | NONE(RESERVED21_ENTROPY), |
| 428 | NONE(RESERVED22_W), |
| 429 | NONE(RESERVED23_W), |
| 430 | |
| 431 | /* 56 */ |
| 432 | NONE(RESERVED24_W), |
| 433 | NONE(AMX0), |
| 434 | NONE(ADX0), |
| 435 | NONE(DVFS), |
| 436 | NONE(XUSB_SS), |
| 437 | NONE(EMC_DLL), |
| 438 | NONE(MC1), |
| 439 | NONE(EMC1), |
| 440 | }; |
| 441 | |
| 442 | /* |
| 443 | * Get the oscillator frequency, from the corresponding hardware configuration |
| 444 | * field. Note that T30/T114 support 3 new higher freqs, but we map back |
| 445 | * to the old T20 freqs. Support for the higher oscillators is TBD. |
| 446 | */ |
| 447 | enum clock_osc_freq clock_get_osc_freq(void) |
| 448 | { |
| 449 | struct clk_rst_ctlr *clkrst = |
| 450 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 451 | u32 reg; |
| 452 | |
| 453 | reg = readl(&clkrst->crc_osc_ctrl); |
| 454 | reg = (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT; |
| 455 | |
| 456 | if (reg & 1) /* one of the newer freqs */ |
| 457 | printf("Warning: OSC_FREQ is unsupported! (%d)\n", reg); |
| 458 | |
| 459 | return reg >> 2; /* Map to most common (T20) freqs */ |
| 460 | } |
| 461 | |
| 462 | /* Returns a pointer to the clock source register for a peripheral */ |
| 463 | u32 *get_periph_source_reg(enum periph_id periph_id) |
| 464 | { |
| 465 | struct clk_rst_ctlr *clkrst = |
| 466 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 467 | enum periphc_internal_id internal_id; |
| 468 | |
| 469 | /* Coresight is a special case */ |
| 470 | if (periph_id == PERIPH_ID_CSI) |
| 471 | return &clkrst->crc_clk_src[PERIPH_ID_CSI+1]; |
| 472 | |
| 473 | assert(periph_id >= PERIPH_ID_FIRST && periph_id < PERIPH_ID_COUNT); |
| 474 | internal_id = periph_id_to_internal_id[periph_id]; |
| 475 | assert(internal_id != -1); |
| 476 | if (internal_id >= PERIPHC_VW_FIRST) { |
| 477 | internal_id -= PERIPHC_VW_FIRST; |
| 478 | return &clkrst->crc_clk_src_vw[internal_id]; |
| 479 | } else |
| 480 | return &clkrst->crc_clk_src[internal_id]; |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Given a peripheral ID and the required source clock, this returns which |
| 485 | * value should be programmed into the source mux for that peripheral. |
| 486 | * |
| 487 | * There is special code here to handle the one source type with 5 sources. |
| 488 | * |
| 489 | * @param periph_id peripheral to start |
| 490 | * @param source PLL id of required parent clock |
| 491 | * @param mux_bits Set to number of bits in mux register: 2 or 4 |
| 492 | * @param divider_bits Set to number of divider bits (8 or 16) |
| 493 | * @return mux value (0-4, or -1 if not found) |
| 494 | */ |
| 495 | int get_periph_clock_source(enum periph_id periph_id, |
| 496 | enum clock_id parent, int *mux_bits, int *divider_bits) |
| 497 | { |
| 498 | enum clock_type_id type; |
| 499 | enum periphc_internal_id internal_id; |
| 500 | int mux; |
| 501 | |
| 502 | assert(clock_periph_id_isvalid(periph_id)); |
| 503 | |
| 504 | internal_id = periph_id_to_internal_id[periph_id]; |
| 505 | assert(periphc_internal_id_isvalid(internal_id)); |
| 506 | |
| 507 | type = clock_periph_type[internal_id]; |
| 508 | assert(clock_type_id_isvalid(type)); |
| 509 | |
| 510 | *mux_bits = clock_source[type][CLOCK_MAX_MUX]; |
| 511 | |
| 512 | if (type == CLOCK_TYPE_PCMT16) |
| 513 | *divider_bits = 16; |
| 514 | else |
| 515 | *divider_bits = 8; |
| 516 | |
| 517 | for (mux = 0; mux < CLOCK_MAX_MUX; mux++) |
| 518 | if (clock_source[type][mux] == parent) |
| 519 | return mux; |
| 520 | |
| 521 | /* if we get here, either us or the caller has made a mistake */ |
| 522 | printf("Caller requested bad clock: periph=%d, parent=%d\n", periph_id, |
| 523 | parent); |
| 524 | return -1; |
| 525 | } |
| 526 | |
| 527 | void clock_set_enable(enum periph_id periph_id, int enable) |
| 528 | { |
| 529 | struct clk_rst_ctlr *clkrst = |
| 530 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 531 | u32 *clk; |
| 532 | u32 reg; |
| 533 | |
| 534 | /* Enable/disable the clock to this peripheral */ |
| 535 | assert(clock_periph_id_isvalid(periph_id)); |
| 536 | if ((int)periph_id < (int)PERIPH_ID_VW_FIRST) |
| 537 | clk = &clkrst->crc_clk_out_enb[PERIPH_REG(periph_id)]; |
| 538 | else |
| 539 | clk = &clkrst->crc_clk_out_enb_vw[PERIPH_REG(periph_id)]; |
| 540 | reg = readl(clk); |
| 541 | if (enable) |
| 542 | reg |= PERIPH_MASK(periph_id); |
| 543 | else |
| 544 | reg &= ~PERIPH_MASK(periph_id); |
| 545 | writel(reg, clk); |
| 546 | } |
| 547 | |
| 548 | void reset_set_enable(enum periph_id periph_id, int enable) |
| 549 | { |
| 550 | struct clk_rst_ctlr *clkrst = |
| 551 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 552 | u32 *reset; |
| 553 | u32 reg; |
| 554 | |
| 555 | /* Enable/disable reset to the peripheral */ |
| 556 | assert(clock_periph_id_isvalid(periph_id)); |
| 557 | if (periph_id < PERIPH_ID_VW_FIRST) |
| 558 | reset = &clkrst->crc_rst_dev[PERIPH_REG(periph_id)]; |
| 559 | else |
| 560 | reset = &clkrst->crc_rst_dev_vw[PERIPH_REG(periph_id)]; |
| 561 | reg = readl(reset); |
| 562 | if (enable) |
| 563 | reg |= PERIPH_MASK(periph_id); |
| 564 | else |
| 565 | reg &= ~PERIPH_MASK(periph_id); |
| 566 | writel(reg, reset); |
| 567 | } |
| 568 | |
| 569 | #ifdef CONFIG_OF_CONTROL |
| 570 | /* |
| 571 | * Convert a device tree clock ID to our peripheral ID. They are mostly |
| 572 | * the same but we are very cautious so we check that a valid clock ID is |
| 573 | * provided. |
| 574 | * |
| 575 | * @param clk_id Clock ID according to tegra114 device tree binding |
| 576 | * @return peripheral ID, or PERIPH_ID_NONE if the clock ID is invalid |
| 577 | */ |
| 578 | enum periph_id clk_id_to_periph_id(int clk_id) |
| 579 | { |
| 580 | if (clk_id > PERIPH_ID_COUNT) |
| 581 | return PERIPH_ID_NONE; |
| 582 | |
| 583 | switch (clk_id) { |
| 584 | case PERIPH_ID_RESERVED3: |
| 585 | case PERIPH_ID_RESERVED16: |
| 586 | case PERIPH_ID_RESERVED24: |
| 587 | case PERIPH_ID_RESERVED35: |
| 588 | case PERIPH_ID_RESERVED43: |
| 589 | case PERIPH_ID_RESERVED45: |
| 590 | case PERIPH_ID_RESERVED56: |
| 591 | case PERIPH_ID_RESERVED76: |
| 592 | case PERIPH_ID_RESERVED77: |
| 593 | case PERIPH_ID_RESERVED78: |
| 594 | case PERIPH_ID_RESERVED83: |
| 595 | case PERIPH_ID_RESERVED89: |
| 596 | case PERIPH_ID_RESERVED91: |
| 597 | case PERIPH_ID_RESERVED93: |
| 598 | case PERIPH_ID_RESERVED94: |
| 599 | case PERIPH_ID_RESERVED95: |
| 600 | return PERIPH_ID_NONE; |
| 601 | default: |
| 602 | return clk_id; |
| 603 | } |
| 604 | } |
| 605 | #endif /* CONFIG_OF_CONTROL */ |
| 606 | |
| 607 | void clock_early_init(void) |
| 608 | { |
| 609 | struct clk_rst_ctlr *clkrst = |
| 610 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 611 | |
| 612 | /* |
| 613 | * PLLP output frequency set to 408Mhz |
| 614 | * PLLC output frequency set to 600Mhz |
| 615 | * PLLD output frequency set to 925Mhz |
| 616 | */ |
| 617 | switch (clock_get_osc_freq()) { |
| 618 | case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */ |
| 619 | clock_set_rate(CLOCK_ID_PERIPH, 408, 12, 0, 8); |
| 620 | clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8); |
| 621 | clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12); |
| 622 | break; |
| 623 | |
| 624 | case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */ |
| 625 | clock_set_rate(CLOCK_ID_PERIPH, 408, 26, 0, 8); |
| 626 | clock_set_rate(CLOCK_ID_CGENERAL, 600, 26, 0, 8); |
| 627 | clock_set_rate(CLOCK_ID_DISPLAY, 925, 26, 0, 12); |
| 628 | break; |
| 629 | |
| 630 | case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */ |
| 631 | clock_set_rate(CLOCK_ID_PERIPH, 408, 13, 0, 8); |
| 632 | clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8); |
| 633 | clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12); |
| 634 | break; |
| 635 | case CLOCK_OSC_FREQ_19_2: |
| 636 | default: |
| 637 | /* |
| 638 | * These are not supported. It is too early to print a |
| 639 | * message and the UART likely won't work anyway due to the |
| 640 | * oscillator being wrong. |
| 641 | */ |
| 642 | break; |
| 643 | } |
| 644 | |
| 645 | /* PLLC_MISC2: Set dynramp_stepA/B. MISC2 maps to pll_out[1] */ |
| 646 | writel(0x00561600, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_out[1]); |
| 647 | |
| 648 | /* PLLC_MISC: Set LOCK_ENABLE */ |
| 649 | writel(0x01000000, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_misc); |
| 650 | udelay(2); |
| 651 | |
| 652 | /* PLLD_MISC: Set CLKENABLE, CPCON 12, LFCON 1 */ |
| 653 | writel(0x40000C10, &clkrst->crc_pll[CLOCK_ID_DISPLAY].pll_misc); |
| 654 | udelay(2); |
| 655 | } |