Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 2 | /* |
Tom Warren | a8480ef | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 3 | * (C) Copyright 2010-2015 |
| 4 | * NVIDIA Corporation <www.nvidia.com> |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* Tegra114 Clock control functions */ |
| 8 | |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 9 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/clock.h> |
Tom Warren | fbef355 | 2013-04-01 15:48:54 -0700 | [diff] [blame] | 13 | #include <asm/arch/sysctr.h> |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 14 | #include <asm/arch/tegra.h> |
| 15 | #include <asm/arch-tegra/clk_rst.h> |
| 16 | #include <asm/arch-tegra/timer.h> |
| 17 | #include <div64.h> |
| 18 | #include <fdtdec.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 19 | #include <linux/delay.h> |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 20 | |
Svyatoslav Ryhel | 19a5b03 | 2023-02-14 19:35:25 +0200 | [diff] [blame] | 21 | #include <dt-bindings/clock/tegra114-car.h> |
| 22 | |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 23 | /* |
| 24 | * Clock types that we can use as a source. The Tegra114 has muxes for the |
| 25 | * peripheral clocks, and in most cases there are four options for the clock |
| 26 | * source. This gives us a clock 'type' and exploits what commonality exists |
| 27 | * in the device. |
| 28 | * |
| 29 | * Letters are obvious, except for T which means CLK_M, and S which means the |
| 30 | * clock derived from 32KHz. Beware that CLK_M (also called OSC in the |
| 31 | * datasheet) and PLL_M are different things. The former is the basic |
| 32 | * clock supplied to the SOC from an external oscillator. The latter is the |
| 33 | * memory clock PLL. |
| 34 | * |
| 35 | * See definitions in clock_id in the header file. |
| 36 | */ |
| 37 | enum clock_type_id { |
| 38 | CLOCK_TYPE_AXPT, /* PLL_A, PLL_X, PLL_P, CLK_M */ |
| 39 | CLOCK_TYPE_MCPA, /* and so on */ |
| 40 | CLOCK_TYPE_MCPT, |
| 41 | CLOCK_TYPE_PCM, |
| 42 | CLOCK_TYPE_PCMT, |
| 43 | CLOCK_TYPE_PCMT16, |
| 44 | CLOCK_TYPE_PDCT, |
| 45 | CLOCK_TYPE_ACPT, |
| 46 | CLOCK_TYPE_ASPTE, |
| 47 | CLOCK_TYPE_PMDACD2T, |
| 48 | CLOCK_TYPE_PCST, |
| 49 | |
| 50 | CLOCK_TYPE_COUNT, |
| 51 | CLOCK_TYPE_NONE = -1, /* invalid clock type */ |
| 52 | }; |
| 53 | |
| 54 | enum { |
| 55 | CLOCK_MAX_MUX = 8 /* number of source options for each clock */ |
| 56 | }; |
| 57 | |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 58 | /* |
| 59 | * Clock source mux for each clock type. This just converts our enum into |
| 60 | * a list of mux sources for use by the code. |
| 61 | * |
| 62 | * Note: |
| 63 | * The extra column in each clock source array is used to store the mask |
| 64 | * bits in its register for the source. |
| 65 | */ |
| 66 | #define CLK(x) CLOCK_ID_ ## x |
| 67 | static enum clock_id clock_source[CLOCK_TYPE_COUNT][CLOCK_MAX_MUX+1] = { |
| 68 | { CLK(AUDIO), CLK(XCPU), CLK(PERIPH), CLK(OSC), |
| 69 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 70 | MASK_BITS_31_30}, |
| 71 | { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(AUDIO), |
| 72 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 73 | MASK_BITS_31_30}, |
| 74 | { CLK(MEMORY), CLK(CGENERAL), CLK(PERIPH), CLK(OSC), |
| 75 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 76 | MASK_BITS_31_30}, |
| 77 | { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(NONE), |
| 78 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 79 | MASK_BITS_31_30}, |
| 80 | { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC), |
| 81 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 82 | MASK_BITS_31_30}, |
| 83 | { CLK(PERIPH), CLK(CGENERAL), CLK(MEMORY), CLK(OSC), |
| 84 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 85 | MASK_BITS_31_30}, |
| 86 | { CLK(PERIPH), CLK(DISPLAY), CLK(CGENERAL), CLK(OSC), |
| 87 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 88 | MASK_BITS_31_30}, |
| 89 | { CLK(AUDIO), CLK(CGENERAL), CLK(PERIPH), CLK(OSC), |
| 90 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
| 91 | MASK_BITS_31_30}, |
| 92 | { CLK(AUDIO), CLK(SFROM32KHZ), CLK(PERIPH), CLK(OSC), |
| 93 | CLK(EPCI), CLK(NONE), CLK(NONE), CLK(NONE), |
| 94 | MASK_BITS_31_29}, |
| 95 | { CLK(PERIPH), CLK(MEMORY), CLK(DISPLAY), CLK(AUDIO), |
| 96 | CLK(CGENERAL), CLK(DISPLAY2), CLK(OSC), CLK(NONE), |
| 97 | MASK_BITS_31_29}, |
| 98 | { CLK(PERIPH), CLK(CGENERAL), CLK(SFROM32KHZ), CLK(OSC), |
| 99 | CLK(NONE), CLK(NONE), CLK(NONE), CLK(NONE), |
Stephen Warren | 510c0ae | 2014-01-24 10:16:18 -0700 | [diff] [blame] | 100 | MASK_BITS_31_28} |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | /* |
| 104 | * Clock type for each peripheral clock source. We put the name in each |
| 105 | * record just so it is easy to match things up |
| 106 | */ |
| 107 | #define TYPE(name, type) type |
| 108 | static enum clock_type_id clock_periph_type[PERIPHC_COUNT] = { |
| 109 | /* 0x00 */ |
| 110 | TYPE(PERIPHC_I2S1, CLOCK_TYPE_AXPT), |
| 111 | TYPE(PERIPHC_I2S2, CLOCK_TYPE_AXPT), |
| 112 | TYPE(PERIPHC_SPDIF_OUT, CLOCK_TYPE_AXPT), |
| 113 | TYPE(PERIPHC_SPDIF_IN, CLOCK_TYPE_PCM), |
| 114 | TYPE(PERIPHC_PWM, CLOCK_TYPE_PCST), /* only PWM uses b29:28 */ |
| 115 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 116 | TYPE(PERIPHC_SBC2, CLOCK_TYPE_PCMT), |
| 117 | TYPE(PERIPHC_SBC3, CLOCK_TYPE_PCMT), |
| 118 | |
| 119 | /* 0x08 */ |
| 120 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 121 | TYPE(PERIPHC_I2C1, CLOCK_TYPE_PCMT16), |
| 122 | TYPE(PERIPHC_I2C5, CLOCK_TYPE_PCMT16), |
| 123 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 124 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 125 | TYPE(PERIPHC_SBC1, CLOCK_TYPE_PCMT), |
| 126 | TYPE(PERIPHC_DISP1, CLOCK_TYPE_PMDACD2T), |
| 127 | TYPE(PERIPHC_DISP2, CLOCK_TYPE_PMDACD2T), |
| 128 | |
| 129 | /* 0x10 */ |
| 130 | TYPE(PERIPHC_CVE, CLOCK_TYPE_PDCT), |
| 131 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 132 | TYPE(PERIPHC_VI, CLOCK_TYPE_MCPA), |
| 133 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 134 | TYPE(PERIPHC_SDMMC1, CLOCK_TYPE_PCMT), |
| 135 | TYPE(PERIPHC_SDMMC2, CLOCK_TYPE_PCMT), |
| 136 | TYPE(PERIPHC_G3D, CLOCK_TYPE_MCPA), |
| 137 | TYPE(PERIPHC_G2D, CLOCK_TYPE_MCPA), |
| 138 | |
| 139 | /* 0x18 */ |
| 140 | TYPE(PERIPHC_NDFLASH, CLOCK_TYPE_PCMT), |
| 141 | TYPE(PERIPHC_SDMMC4, CLOCK_TYPE_PCMT), |
| 142 | TYPE(PERIPHC_VFIR, CLOCK_TYPE_PCMT), |
| 143 | TYPE(PERIPHC_EPP, CLOCK_TYPE_MCPA), |
| 144 | TYPE(PERIPHC_MPE, CLOCK_TYPE_MCPA), |
| 145 | TYPE(PERIPHC_MIPI, CLOCK_TYPE_PCMT), /* MIPI base-band HSI */ |
| 146 | TYPE(PERIPHC_UART1, CLOCK_TYPE_PCMT), |
| 147 | TYPE(PERIPHC_UART2, CLOCK_TYPE_PCMT), |
| 148 | |
| 149 | /* 0x20 */ |
| 150 | TYPE(PERIPHC_HOST1X, CLOCK_TYPE_MCPA), |
| 151 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 152 | TYPE(PERIPHC_TVO, CLOCK_TYPE_PDCT), |
| 153 | TYPE(PERIPHC_HDMI, CLOCK_TYPE_PMDACD2T), |
| 154 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 155 | TYPE(PERIPHC_TVDAC, CLOCK_TYPE_PDCT), |
| 156 | TYPE(PERIPHC_I2C2, CLOCK_TYPE_PCMT16), |
| 157 | TYPE(PERIPHC_EMC, CLOCK_TYPE_MCPT), |
| 158 | |
| 159 | /* 0x28 */ |
| 160 | TYPE(PERIPHC_UART3, CLOCK_TYPE_PCMT), |
| 161 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 162 | TYPE(PERIPHC_VI, CLOCK_TYPE_MCPA), |
| 163 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 164 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 165 | TYPE(PERIPHC_SBC4, CLOCK_TYPE_PCMT), |
| 166 | TYPE(PERIPHC_I2C3, CLOCK_TYPE_PCMT16), |
| 167 | TYPE(PERIPHC_SDMMC3, CLOCK_TYPE_PCMT), |
| 168 | |
| 169 | /* 0x30 */ |
| 170 | TYPE(PERIPHC_UART4, CLOCK_TYPE_PCMT), |
| 171 | TYPE(PERIPHC_UART5, CLOCK_TYPE_PCMT), |
| 172 | TYPE(PERIPHC_VDE, CLOCK_TYPE_PCMT), |
| 173 | TYPE(PERIPHC_OWR, CLOCK_TYPE_PCMT), |
| 174 | TYPE(PERIPHC_NOR, CLOCK_TYPE_PCMT), |
| 175 | TYPE(PERIPHC_CSITE, CLOCK_TYPE_PCMT), |
| 176 | TYPE(PERIPHC_I2S0, CLOCK_TYPE_AXPT), |
| 177 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 178 | |
| 179 | /* 0x38h */ /* Jumps to reg offset 0x3B0h */ |
| 180 | TYPE(PERIPHC_G3D2, CLOCK_TYPE_MCPA), |
| 181 | TYPE(PERIPHC_MSELECT, CLOCK_TYPE_PCMT), |
| 182 | TYPE(PERIPHC_TSENSOR, CLOCK_TYPE_PCST), /* s/b PCTS */ |
| 183 | TYPE(PERIPHC_I2S3, CLOCK_TYPE_AXPT), |
| 184 | TYPE(PERIPHC_I2S4, CLOCK_TYPE_AXPT), |
| 185 | TYPE(PERIPHC_I2C4, CLOCK_TYPE_PCMT16), |
| 186 | TYPE(PERIPHC_SBC5, CLOCK_TYPE_PCMT), |
| 187 | TYPE(PERIPHC_SBC6, CLOCK_TYPE_PCMT), |
| 188 | |
| 189 | /* 0x40 */ |
| 190 | TYPE(PERIPHC_AUDIO, CLOCK_TYPE_ACPT), |
| 191 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 192 | TYPE(PERIPHC_DAM0, CLOCK_TYPE_ACPT), |
| 193 | TYPE(PERIPHC_DAM1, CLOCK_TYPE_ACPT), |
| 194 | TYPE(PERIPHC_DAM2, CLOCK_TYPE_ACPT), |
| 195 | TYPE(PERIPHC_HDA2CODEC2X, CLOCK_TYPE_PCMT), |
| 196 | TYPE(PERIPHC_ACTMON, CLOCK_TYPE_PCST), /* MASK 31:30 */ |
| 197 | TYPE(PERIPHC_EXTPERIPH1, CLOCK_TYPE_ASPTE), |
| 198 | |
| 199 | /* 0x48 */ |
| 200 | TYPE(PERIPHC_EXTPERIPH2, CLOCK_TYPE_ASPTE), |
| 201 | TYPE(PERIPHC_EXTPERIPH3, CLOCK_TYPE_ASPTE), |
| 202 | TYPE(PERIPHC_NANDSPEED, CLOCK_TYPE_PCMT), |
| 203 | TYPE(PERIPHC_I2CSLOW, CLOCK_TYPE_PCST), /* MASK 31:30 */ |
| 204 | TYPE(PERIPHC_SYS, CLOCK_TYPE_NONE), |
| 205 | TYPE(PERIPHC_SPEEDO, CLOCK_TYPE_PCMT), |
| 206 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 207 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 208 | |
| 209 | /* 0x50 */ |
| 210 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 211 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 212 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 213 | TYPE(PERIPHC_NONE, CLOCK_TYPE_NONE), |
| 214 | TYPE(PERIPHC_SATAOOB, CLOCK_TYPE_PCMT), /* offset 0x420h */ |
| 215 | TYPE(PERIPHC_SATA, CLOCK_TYPE_PCMT), |
| 216 | TYPE(PERIPHC_HDA, CLOCK_TYPE_PCMT), |
| 217 | }; |
| 218 | |
| 219 | /* |
| 220 | * This array translates a periph_id to a periphc_internal_id |
| 221 | * |
| 222 | * Not present/matched up: |
| 223 | * uint vi_sensor; _VI_SENSOR_0, 0x1A8 |
| 224 | * SPDIF - which is both 0x08 and 0x0c |
| 225 | * |
| 226 | */ |
| 227 | #define NONE(name) (-1) |
| 228 | #define OFFSET(name, value) PERIPHC_ ## name |
| 229 | static s8 periph_id_to_internal_id[PERIPH_ID_COUNT] = { |
| 230 | /* Low word: 31:0 */ |
| 231 | NONE(CPU), |
| 232 | NONE(COP), |
| 233 | NONE(TRIGSYS), |
| 234 | NONE(RESERVED3), |
| 235 | NONE(RTC), |
| 236 | NONE(TMR), |
| 237 | PERIPHC_UART1, |
| 238 | PERIPHC_UART2, /* and vfir 0x68 */ |
| 239 | |
| 240 | /* 8 */ |
| 241 | NONE(GPIO), |
| 242 | PERIPHC_SDMMC2, |
| 243 | NONE(SPDIF), /* 0x08 and 0x0c, unclear which to use */ |
| 244 | PERIPHC_I2S1, |
| 245 | PERIPHC_I2C1, |
| 246 | PERIPHC_NDFLASH, |
| 247 | PERIPHC_SDMMC1, |
| 248 | PERIPHC_SDMMC4, |
| 249 | |
| 250 | /* 16 */ |
| 251 | NONE(RESERVED16), |
| 252 | PERIPHC_PWM, |
| 253 | PERIPHC_I2S2, |
| 254 | PERIPHC_EPP, |
| 255 | PERIPHC_VI, |
| 256 | PERIPHC_G2D, |
| 257 | NONE(USBD), |
| 258 | NONE(ISP), |
| 259 | |
| 260 | /* 24 */ |
| 261 | PERIPHC_G3D, |
| 262 | NONE(RESERVED25), |
| 263 | PERIPHC_DISP2, |
| 264 | PERIPHC_DISP1, |
| 265 | PERIPHC_HOST1X, |
| 266 | NONE(VCP), |
| 267 | PERIPHC_I2S0, |
| 268 | NONE(CACHE2), |
| 269 | |
| 270 | /* Middle word: 63:32 */ |
| 271 | NONE(MEM), |
| 272 | NONE(AHBDMA), |
| 273 | NONE(APBDMA), |
| 274 | NONE(RESERVED35), |
| 275 | NONE(RESERVED36), |
| 276 | NONE(STAT_MON), |
| 277 | NONE(RESERVED38), |
| 278 | NONE(RESERVED39), |
| 279 | |
| 280 | /* 40 */ |
| 281 | NONE(KFUSE), |
| 282 | NONE(SBC1), /* SBC1, 0x34, is this SPI1? */ |
| 283 | PERIPHC_NOR, |
| 284 | NONE(RESERVED43), |
| 285 | PERIPHC_SBC2, |
| 286 | NONE(RESERVED45), |
| 287 | PERIPHC_SBC3, |
| 288 | PERIPHC_I2C5, |
| 289 | |
| 290 | /* 48 */ |
| 291 | NONE(DSI), |
| 292 | PERIPHC_TVO, /* also CVE 0x40 */ |
| 293 | PERIPHC_MIPI, |
| 294 | PERIPHC_HDMI, |
| 295 | NONE(CSI), |
| 296 | PERIPHC_TVDAC, |
| 297 | PERIPHC_I2C2, |
| 298 | PERIPHC_UART3, |
| 299 | |
| 300 | /* 56 */ |
Svyatoslav Ryhel | 46988e9 | 2023-12-25 17:30:37 +0200 | [diff] [blame] | 301 | NONE(MIPI_CAL), |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 302 | PERIPHC_EMC, |
| 303 | NONE(USB2), |
| 304 | NONE(USB3), |
| 305 | PERIPHC_MPE, |
| 306 | PERIPHC_VDE, |
| 307 | NONE(BSEA), |
| 308 | NONE(BSEV), |
| 309 | |
| 310 | /* Upper word 95:64 */ |
| 311 | PERIPHC_SPEEDO, |
| 312 | PERIPHC_UART4, |
| 313 | PERIPHC_UART5, |
| 314 | PERIPHC_I2C3, |
| 315 | PERIPHC_SBC4, |
| 316 | PERIPHC_SDMMC3, |
| 317 | NONE(PCIE), |
| 318 | PERIPHC_OWR, |
| 319 | |
| 320 | /* 72 */ |
| 321 | NONE(AFI), |
| 322 | PERIPHC_CSITE, |
| 323 | NONE(PCIEXCLK), |
| 324 | NONE(AVPUCQ), |
| 325 | NONE(RESERVED76), |
| 326 | NONE(RESERVED77), |
| 327 | NONE(RESERVED78), |
| 328 | NONE(DTV), |
| 329 | |
| 330 | /* 80 */ |
| 331 | PERIPHC_NANDSPEED, |
| 332 | PERIPHC_I2CSLOW, |
| 333 | NONE(DSIB), |
| 334 | NONE(RESERVED83), |
| 335 | NONE(IRAMA), |
| 336 | NONE(IRAMB), |
| 337 | NONE(IRAMC), |
| 338 | NONE(IRAMD), |
| 339 | |
| 340 | /* 88 */ |
| 341 | NONE(CRAM2), |
| 342 | NONE(RESERVED89), |
| 343 | NONE(MDOUBLER), |
| 344 | NONE(RESERVED91), |
| 345 | NONE(SUSOUT), |
| 346 | NONE(RESERVED93), |
| 347 | NONE(RESERVED94), |
| 348 | NONE(RESERVED95), |
| 349 | |
| 350 | /* V word: 31:0 */ |
| 351 | NONE(CPUG), |
| 352 | NONE(CPULP), |
| 353 | PERIPHC_G3D2, |
| 354 | PERIPHC_MSELECT, |
| 355 | PERIPHC_TSENSOR, |
| 356 | PERIPHC_I2S3, |
| 357 | PERIPHC_I2S4, |
| 358 | PERIPHC_I2C4, |
| 359 | |
| 360 | /* 08 */ |
| 361 | PERIPHC_SBC5, |
| 362 | PERIPHC_SBC6, |
| 363 | PERIPHC_AUDIO, |
| 364 | NONE(APBIF), |
| 365 | PERIPHC_DAM0, |
| 366 | PERIPHC_DAM1, |
| 367 | PERIPHC_DAM2, |
| 368 | PERIPHC_HDA2CODEC2X, |
| 369 | |
| 370 | /* 16 */ |
| 371 | NONE(ATOMICS), |
| 372 | NONE(RESERVED17), |
| 373 | NONE(RESERVED18), |
| 374 | NONE(RESERVED19), |
| 375 | NONE(RESERVED20), |
| 376 | NONE(RESERVED21), |
| 377 | NONE(RESERVED22), |
| 378 | PERIPHC_ACTMON, |
| 379 | |
| 380 | /* 24 */ |
| 381 | NONE(RESERVED24), |
| 382 | NONE(RESERVED25), |
| 383 | NONE(RESERVED26), |
| 384 | NONE(RESERVED27), |
| 385 | PERIPHC_SATA, |
| 386 | PERIPHC_HDA, |
| 387 | NONE(RESERVED30), |
| 388 | NONE(RESERVED31), |
| 389 | |
| 390 | /* W word: 31:0 */ |
| 391 | NONE(HDA2HDMICODEC), |
| 392 | NONE(RESERVED1_SATACOLD), |
| 393 | NONE(RESERVED2_PCIERX0), |
| 394 | NONE(RESERVED3_PCIERX1), |
| 395 | NONE(RESERVED4_PCIERX2), |
| 396 | NONE(RESERVED5_PCIERX3), |
| 397 | NONE(RESERVED6_PCIERX4), |
| 398 | NONE(RESERVED7_PCIERX5), |
| 399 | |
| 400 | /* 40 */ |
| 401 | NONE(CEC), |
| 402 | NONE(PCIE2_IOBIST), |
| 403 | NONE(EMC_IOBIST), |
| 404 | NONE(HDMI_IOBIST), |
| 405 | NONE(SATA_IOBIST), |
| 406 | NONE(MIPI_IOBIST), |
| 407 | NONE(EMC1_IOBIST), |
| 408 | NONE(XUSB), |
| 409 | |
| 410 | /* 48 */ |
| 411 | NONE(CILAB), |
| 412 | NONE(CILCD), |
| 413 | NONE(CILE), |
| 414 | NONE(DSIA_LP), |
| 415 | NONE(DSIB_LP), |
| 416 | NONE(RESERVED21_ENTROPY), |
| 417 | NONE(RESERVED22_W), |
| 418 | NONE(RESERVED23_W), |
| 419 | |
| 420 | /* 56 */ |
| 421 | NONE(RESERVED24_W), |
| 422 | NONE(AMX0), |
| 423 | NONE(ADX0), |
| 424 | NONE(DVFS), |
| 425 | NONE(XUSB_SS), |
| 426 | NONE(EMC_DLL), |
| 427 | NONE(MC1), |
| 428 | NONE(EMC1), |
| 429 | }; |
| 430 | |
| 431 | /* |
Tom Warren | a8480ef | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 432 | * PLL divider shift/mask tables for all PLL IDs. |
| 433 | */ |
| 434 | struct clk_pll_info tegra_pll_info_table[CLOCK_ID_PLL_COUNT] = { |
| 435 | /* |
| 436 | * T114: some deviations from T2x/T30. |
| 437 | * NOTE: If kcp_mask/kvco_mask == 0, they're not used in that PLL (PLLX, etc.) |
| 438 | * If lock_ena or lock_det are >31, they're not used in that PLL. |
| 439 | */ |
| 440 | |
| 441 | { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x0F, |
| 442 | .lock_ena = 24, .lock_det = 27, .kcp_shift = 28, .kcp_mask = 3, .kvco_shift = 27, .kvco_mask = 1 }, /* PLLC */ |
| 443 | { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 0, .p_mask = 0, |
| 444 | .lock_ena = 0, .lock_det = 27, .kcp_shift = 1, .kcp_mask = 3, .kvco_shift = 0, .kvco_mask = 1 }, /* PLLM */ |
| 445 | { .m_shift = 0, .m_mask = 0x1F, .n_shift = 8, .n_mask = 0x3FF, .p_shift = 20, .p_mask = 0x07, |
| 446 | .lock_ena = 18, .lock_det = 27, .kcp_shift = 8, .kcp_mask = 0xF, .kvco_shift = 4, .kvco_mask = 0xF }, /* PLLP */ |
| 447 | { .m_shift = 0, .m_mask = 0x1F, .n_shift = 8, .n_mask = 0x3FF, .p_shift = 20, .p_mask = 0x07, |
| 448 | .lock_ena = 18, .lock_det = 27, .kcp_shift = 8, .kcp_mask = 0xF, .kvco_shift = 4, .kvco_mask = 0xF }, /* PLLA */ |
| 449 | { .m_shift = 0, .m_mask = 0x1F, .n_shift = 8, .n_mask = 0x3FF, .p_shift = 20, .p_mask = 0x01, |
| 450 | .lock_ena = 22, .lock_det = 27, .kcp_shift = 8, .kcp_mask = 0xF, .kvco_shift = 4, .kvco_mask = 0xF }, /* PLLU */ |
| 451 | { .m_shift = 0, .m_mask = 0x1F, .n_shift = 8, .n_mask = 0x3FF, .p_shift = 20, .p_mask = 0x07, |
| 452 | .lock_ena = 22, .lock_det = 27, .kcp_shift = 8, .kcp_mask = 0xF, .kvco_shift = 4, .kvco_mask = 0xF }, /* PLLD */ |
| 453 | { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 20, .p_mask = 0x0F, |
| 454 | .lock_ena = 18, .lock_det = 27, .kcp_shift = 0, .kcp_mask = 0, .kvco_shift = 0, .kvco_mask = 0 }, /* PLLX */ |
| 455 | { .m_shift = 0, .m_mask = 0xFF, .n_shift = 8, .n_mask = 0xFF, .p_shift = 0, .p_mask = 0, |
| 456 | .lock_ena = 9, .lock_det = 11, .kcp_shift = 6, .kcp_mask = 3, .kvco_shift = 0, .kvco_mask = 1 }, /* PLLE */ |
| 457 | { .m_shift = 0, .m_mask = 0x0F, .n_shift = 8, .n_mask = 0x3FF, .p_shift = 20, .p_mask = 0x07, |
| 458 | .lock_ena = 18, .lock_det = 27, .kcp_shift = 8, .kcp_mask = 0xF, .kvco_shift = 4, .kvco_mask = 0xF }, /* PLLS (RESERVED) */ |
Svyatoslav Ryhel | b06e8fa | 2023-11-16 09:35:26 +0200 | [diff] [blame] | 459 | { .m_shift = 0, .m_mask = 0x1F, .n_shift = 8, .n_mask = 0x3FF, .p_shift = 20, .p_mask = 0x07, |
| 460 | .lock_ena = 22, .lock_det = 27, .kcp_shift = 8, .kcp_mask = 0xF, .kvco_shift = 4, .kvco_mask = 0xF }, /* PLLD2 */ |
Tom Warren | a8480ef | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 461 | }; |
| 462 | |
| 463 | /* |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 464 | * Get the oscillator frequency, from the corresponding hardware configuration |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 465 | * field. Note that T30+ supports 3 new higher freqs. |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 466 | */ |
| 467 | enum clock_osc_freq clock_get_osc_freq(void) |
| 468 | { |
| 469 | struct clk_rst_ctlr *clkrst = |
| 470 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 471 | u32 reg; |
| 472 | |
| 473 | reg = readl(&clkrst->crc_osc_ctrl); |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 474 | return (reg & OSC_FREQ_MASK) >> OSC_FREQ_SHIFT; |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | /* Returns a pointer to the clock source register for a peripheral */ |
| 478 | u32 *get_periph_source_reg(enum periph_id periph_id) |
| 479 | { |
| 480 | struct clk_rst_ctlr *clkrst = |
| 481 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 482 | enum periphc_internal_id internal_id; |
| 483 | |
| 484 | /* Coresight is a special case */ |
| 485 | if (periph_id == PERIPH_ID_CSI) |
| 486 | return &clkrst->crc_clk_src[PERIPH_ID_CSI+1]; |
| 487 | |
| 488 | assert(periph_id >= PERIPH_ID_FIRST && periph_id < PERIPH_ID_COUNT); |
| 489 | internal_id = periph_id_to_internal_id[periph_id]; |
| 490 | assert(internal_id != -1); |
| 491 | if (internal_id >= PERIPHC_VW_FIRST) { |
| 492 | internal_id -= PERIPHC_VW_FIRST; |
| 493 | return &clkrst->crc_clk_src_vw[internal_id]; |
| 494 | } else |
| 495 | return &clkrst->crc_clk_src[internal_id]; |
| 496 | } |
| 497 | |
Stephen Warren | 532543c | 2016-09-13 10:45:56 -0600 | [diff] [blame] | 498 | int get_periph_clock_info(enum periph_id periph_id, int *mux_bits, |
| 499 | int *divider_bits, int *type) |
| 500 | { |
| 501 | enum periphc_internal_id internal_id; |
| 502 | |
| 503 | if (!clock_periph_id_isvalid(periph_id)) |
| 504 | return -1; |
| 505 | |
| 506 | internal_id = periph_id_to_internal_id[periph_id]; |
| 507 | if (!periphc_internal_id_isvalid(internal_id)) |
| 508 | return -1; |
| 509 | |
| 510 | *type = clock_periph_type[internal_id]; |
| 511 | if (!clock_type_id_isvalid(*type)) |
| 512 | return -1; |
| 513 | |
| 514 | *mux_bits = clock_source[*type][CLOCK_MAX_MUX]; |
| 515 | |
| 516 | if (*type == CLOCK_TYPE_PCMT16) |
| 517 | *divider_bits = 16; |
| 518 | else |
| 519 | *divider_bits = 8; |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | enum clock_id get_periph_clock_id(enum periph_id periph_id, int source) |
| 525 | { |
| 526 | enum periphc_internal_id internal_id; |
| 527 | int type; |
| 528 | |
| 529 | if (!clock_periph_id_isvalid(periph_id)) |
| 530 | return CLOCK_ID_NONE; |
| 531 | |
| 532 | internal_id = periph_id_to_internal_id[periph_id]; |
| 533 | if (!periphc_internal_id_isvalid(internal_id)) |
| 534 | return CLOCK_ID_NONE; |
| 535 | |
| 536 | type = clock_periph_type[internal_id]; |
| 537 | if (!clock_type_id_isvalid(type)) |
| 538 | return CLOCK_ID_NONE; |
| 539 | |
| 540 | return clock_source[type][source]; |
| 541 | } |
| 542 | |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 543 | /** |
| 544 | * Given a peripheral ID and the required source clock, this returns which |
| 545 | * value should be programmed into the source mux for that peripheral. |
| 546 | * |
| 547 | * There is special code here to handle the one source type with 5 sources. |
| 548 | * |
| 549 | * @param periph_id peripheral to start |
| 550 | * @param source PLL id of required parent clock |
| 551 | * @param mux_bits Set to number of bits in mux register: 2 or 4 |
| 552 | * @param divider_bits Set to number of divider bits (8 or 16) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 553 | * Return: mux value (0-4, or -1 if not found) |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 554 | */ |
| 555 | int get_periph_clock_source(enum periph_id periph_id, |
| 556 | enum clock_id parent, int *mux_bits, int *divider_bits) |
| 557 | { |
| 558 | enum clock_type_id type; |
Stephen Warren | 532543c | 2016-09-13 10:45:56 -0600 | [diff] [blame] | 559 | int mux, err; |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 560 | |
Stephen Warren | 532543c | 2016-09-13 10:45:56 -0600 | [diff] [blame] | 561 | err = get_periph_clock_info(periph_id, mux_bits, divider_bits, &type); |
| 562 | assert(!err); |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 563 | |
| 564 | for (mux = 0; mux < CLOCK_MAX_MUX; mux++) |
| 565 | if (clock_source[type][mux] == parent) |
| 566 | return mux; |
| 567 | |
| 568 | /* if we get here, either us or the caller has made a mistake */ |
| 569 | printf("Caller requested bad clock: periph=%d, parent=%d\n", periph_id, |
| 570 | parent); |
| 571 | return -1; |
| 572 | } |
| 573 | |
| 574 | void clock_set_enable(enum periph_id periph_id, int enable) |
| 575 | { |
| 576 | struct clk_rst_ctlr *clkrst = |
| 577 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 578 | u32 *clk; |
| 579 | u32 reg; |
| 580 | |
| 581 | /* Enable/disable the clock to this peripheral */ |
| 582 | assert(clock_periph_id_isvalid(periph_id)); |
| 583 | if ((int)periph_id < (int)PERIPH_ID_VW_FIRST) |
| 584 | clk = &clkrst->crc_clk_out_enb[PERIPH_REG(periph_id)]; |
| 585 | else |
| 586 | clk = &clkrst->crc_clk_out_enb_vw[PERIPH_REG(periph_id)]; |
| 587 | reg = readl(clk); |
| 588 | if (enable) |
| 589 | reg |= PERIPH_MASK(periph_id); |
| 590 | else |
| 591 | reg &= ~PERIPH_MASK(periph_id); |
| 592 | writel(reg, clk); |
| 593 | } |
| 594 | |
| 595 | void reset_set_enable(enum periph_id periph_id, int enable) |
| 596 | { |
| 597 | struct clk_rst_ctlr *clkrst = |
| 598 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 599 | u32 *reset; |
| 600 | u32 reg; |
| 601 | |
| 602 | /* Enable/disable reset to the peripheral */ |
| 603 | assert(clock_periph_id_isvalid(periph_id)); |
| 604 | if (periph_id < PERIPH_ID_VW_FIRST) |
| 605 | reset = &clkrst->crc_rst_dev[PERIPH_REG(periph_id)]; |
| 606 | else |
| 607 | reset = &clkrst->crc_rst_dev_vw[PERIPH_REG(periph_id)]; |
| 608 | reg = readl(reset); |
| 609 | if (enable) |
| 610 | reg |= PERIPH_MASK(periph_id); |
| 611 | else |
| 612 | reg &= ~PERIPH_MASK(periph_id); |
| 613 | writel(reg, reset); |
| 614 | } |
| 615 | |
Masahiro Yamada | 366b24f | 2015-08-12 07:31:55 +0900 | [diff] [blame] | 616 | #if CONFIG_IS_ENABLED(OF_CONTROL) |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 617 | /* |
| 618 | * Convert a device tree clock ID to our peripheral ID. They are mostly |
| 619 | * the same but we are very cautious so we check that a valid clock ID is |
| 620 | * provided. |
| 621 | * |
| 622 | * @param clk_id Clock ID according to tegra114 device tree binding |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 623 | * Return: peripheral ID, or PERIPH_ID_NONE if the clock ID is invalid |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 624 | */ |
| 625 | enum periph_id clk_id_to_periph_id(int clk_id) |
| 626 | { |
| 627 | if (clk_id > PERIPH_ID_COUNT) |
| 628 | return PERIPH_ID_NONE; |
| 629 | |
| 630 | switch (clk_id) { |
| 631 | case PERIPH_ID_RESERVED3: |
| 632 | case PERIPH_ID_RESERVED16: |
| 633 | case PERIPH_ID_RESERVED24: |
| 634 | case PERIPH_ID_RESERVED35: |
| 635 | case PERIPH_ID_RESERVED43: |
| 636 | case PERIPH_ID_RESERVED45: |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 637 | case PERIPH_ID_RESERVED76: |
| 638 | case PERIPH_ID_RESERVED77: |
| 639 | case PERIPH_ID_RESERVED78: |
| 640 | case PERIPH_ID_RESERVED83: |
| 641 | case PERIPH_ID_RESERVED89: |
| 642 | case PERIPH_ID_RESERVED91: |
| 643 | case PERIPH_ID_RESERVED93: |
| 644 | case PERIPH_ID_RESERVED94: |
| 645 | case PERIPH_ID_RESERVED95: |
| 646 | return PERIPH_ID_NONE; |
| 647 | default: |
| 648 | return clk_id; |
| 649 | } |
| 650 | } |
Svyatoslav Ryhel | 19a5b03 | 2023-02-14 19:35:25 +0200 | [diff] [blame] | 651 | |
| 652 | /* |
| 653 | * Convert a device tree clock ID to our PLL ID. |
| 654 | * |
| 655 | * @param clk_id Clock ID according to tegra114 device tree binding |
| 656 | * Return: clock ID, or CLOCK_ID_NONE if the clock ID is invalid |
| 657 | */ |
| 658 | enum clock_id clk_id_to_pll_id(int clk_id) |
| 659 | { |
| 660 | switch (clk_id) { |
| 661 | case TEGRA114_CLK_PLL_C: |
| 662 | return CLOCK_ID_CGENERAL; |
| 663 | case TEGRA114_CLK_PLL_M: |
| 664 | return CLOCK_ID_MEMORY; |
| 665 | case TEGRA114_CLK_PLL_P: |
| 666 | return CLOCK_ID_PERIPH; |
| 667 | case TEGRA114_CLK_PLL_A: |
| 668 | return CLOCK_ID_AUDIO; |
| 669 | case TEGRA114_CLK_PLL_U: |
| 670 | return CLOCK_ID_USB; |
| 671 | case TEGRA114_CLK_PLL_D: |
| 672 | case TEGRA114_CLK_PLL_D_OUT0: |
| 673 | return CLOCK_ID_DISPLAY; |
Svyatoslav Ryhel | b06e8fa | 2023-11-16 09:35:26 +0200 | [diff] [blame] | 674 | case TEGRA114_CLK_PLL_D2: |
| 675 | case TEGRA114_CLK_PLL_D2_OUT0: |
| 676 | return CLOCK_ID_DISPLAY2; |
Svyatoslav Ryhel | 19a5b03 | 2023-02-14 19:35:25 +0200 | [diff] [blame] | 677 | case TEGRA114_CLK_PLL_X: |
| 678 | return CLOCK_ID_XCPU; |
| 679 | case TEGRA114_CLK_PLL_E_OUT0: |
| 680 | return CLOCK_ID_EPCI; |
| 681 | case TEGRA114_CLK_CLK_32K: |
| 682 | return CLOCK_ID_32KHZ; |
| 683 | case TEGRA114_CLK_CLK_M: |
| 684 | return CLOCK_ID_CLK_M; |
| 685 | default: |
| 686 | return CLOCK_ID_NONE; |
| 687 | } |
| 688 | } |
Masahiro Yamada | 366b24f | 2015-08-12 07:31:55 +0900 | [diff] [blame] | 689 | #endif /* CONFIG_IS_ENABLED(OF_CONTROL) */ |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 690 | |
| 691 | void clock_early_init(void) |
| 692 | { |
| 693 | struct clk_rst_ctlr *clkrst = |
| 694 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
Tom Warren | a8480ef | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 695 | struct clk_pll_info *pllinfo; |
| 696 | u32 data; |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 697 | |
Jimmy Zhang | 2a544db | 2014-01-24 10:37:36 -0700 | [diff] [blame] | 698 | tegra30_set_up_pllp(); |
| 699 | |
Thierry Reding | 0fca329 | 2015-09-08 11:38:04 +0200 | [diff] [blame] | 700 | /* clear IDDQ before accessing any other PLLC registers */ |
| 701 | pllinfo = &tegra_pll_info_table[CLOCK_ID_CGENERAL]; |
| 702 | clrbits_le32(&clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_misc, PLLC_IDDQ); |
| 703 | udelay(2); |
| 704 | |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 705 | /* |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 706 | * PLLC output frequency set to 600Mhz |
| 707 | * PLLD output frequency set to 925Mhz |
| 708 | */ |
| 709 | switch (clock_get_osc_freq()) { |
| 710 | case CLOCK_OSC_FREQ_12_0: /* OSC is 12Mhz */ |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 711 | case CLOCK_OSC_FREQ_48_0: /* OSC is 48Mhz */ |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 712 | clock_set_rate(CLOCK_ID_CGENERAL, 600, 12, 0, 8); |
| 713 | clock_set_rate(CLOCK_ID_DISPLAY, 925, 12, 0, 12); |
| 714 | break; |
| 715 | |
| 716 | case CLOCK_OSC_FREQ_26_0: /* OSC is 26Mhz */ |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 717 | clock_set_rate(CLOCK_ID_CGENERAL, 600, 26, 0, 8); |
| 718 | clock_set_rate(CLOCK_ID_DISPLAY, 925, 26, 0, 12); |
| 719 | break; |
| 720 | |
| 721 | case CLOCK_OSC_FREQ_13_0: /* OSC is 13Mhz */ |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 722 | case CLOCK_OSC_FREQ_16_8: /* OSC is 16.8Mhz */ |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 723 | clock_set_rate(CLOCK_ID_CGENERAL, 600, 13, 0, 8); |
| 724 | clock_set_rate(CLOCK_ID_DISPLAY, 925, 13, 0, 12); |
| 725 | break; |
| 726 | case CLOCK_OSC_FREQ_19_2: |
Svyatoslav Ryhel | 7f4ab33 | 2023-02-01 10:53:01 +0200 | [diff] [blame] | 727 | case CLOCK_OSC_FREQ_38_4: |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 728 | default: |
| 729 | /* |
| 730 | * These are not supported. It is too early to print a |
| 731 | * message and the UART likely won't work anyway due to the |
| 732 | * oscillator being wrong. |
| 733 | */ |
| 734 | break; |
| 735 | } |
| 736 | |
| 737 | /* PLLC_MISC2: Set dynramp_stepA/B. MISC2 maps to pll_out[1] */ |
| 738 | writel(0x00561600, &clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_out[1]); |
| 739 | |
| 740 | /* PLLC_MISC: Set LOCK_ENABLE */ |
Tom Warren | a8480ef | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 741 | pllinfo = &tegra_pll_info_table[CLOCK_ID_CGENERAL]; |
| 742 | setbits_le32(&clkrst->crc_pll[CLOCK_ID_CGENERAL].pll_misc, (1 << pllinfo->lock_ena)); |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 743 | udelay(2); |
| 744 | |
Tom Warren | a8480ef | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 745 | /* PLLD_MISC: Set CLKENABLE, CPCON 12, LFCON 1, and enable lock */ |
| 746 | pllinfo = &tegra_pll_info_table[CLOCK_ID_DISPLAY]; |
| 747 | data = (12 << pllinfo->kcp_shift) | (1 << pllinfo->kvco_shift); |
| 748 | data |= (1 << PLLD_CLKENABLE) | (1 << pllinfo->lock_ena); |
| 749 | writel(data, &clkrst->crc_pll[CLOCK_ID_DISPLAY].pll_misc); |
Tom Warren | e3d95bc | 2013-01-28 13:32:10 +0000 | [diff] [blame] | 750 | udelay(2); |
| 751 | } |
Tom Warren | fbef355 | 2013-04-01 15:48:54 -0700 | [diff] [blame] | 752 | |
| 753 | void arch_timer_init(void) |
| 754 | { |
| 755 | struct sysctr_ctlr *sysctr = (struct sysctr_ctlr *)NV_PA_TSC_BASE; |
| 756 | u32 freq, val; |
| 757 | |
Thierry Reding | 4c3aaa7 | 2015-08-20 11:42:20 +0200 | [diff] [blame] | 758 | freq = clock_get_rate(CLOCK_ID_CLK_M); |
| 759 | debug("%s: clk_m freq is %dHz [0x%08X]\n", __func__, freq, freq); |
Tom Warren | fbef355 | 2013-04-01 15:48:54 -0700 | [diff] [blame] | 760 | |
| 761 | /* ARM CNTFRQ */ |
| 762 | asm("mcr p15, 0, %0, c14, c0, 0\n" : : "r" (freq)); |
| 763 | |
| 764 | /* Only T114 has the System Counter regs */ |
| 765 | debug("%s: setting CNTFID0 to 0x%08X\n", __func__, freq); |
| 766 | writel(freq, &sysctr->cntfid0); |
| 767 | |
| 768 | val = readl(&sysctr->cntcr); |
| 769 | val |= TSC_CNTCR_ENABLE | TSC_CNTCR_HDBG; |
| 770 | writel(val, &sysctr->cntcr); |
| 771 | debug("%s: TSC CNTCR = 0x%08X\n", __func__, val); |
| 772 | } |
Stephen Warren | 1453d10 | 2016-09-13 10:45:55 -0600 | [diff] [blame] | 773 | |
Svyatoslav Ryhel | c93b518 | 2023-07-03 18:06:54 +0300 | [diff] [blame] | 774 | struct clk_pll_simple *clock_get_simple_pll(enum clock_id clkid) |
| 775 | { |
| 776 | struct clk_rst_ctlr *clkrst = |
| 777 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 778 | |
| 779 | switch (clkid) { |
| 780 | case CLOCK_ID_XCPU: |
| 781 | case CLOCK_ID_EPCI: |
| 782 | case CLOCK_ID_SFROM32KHZ: |
| 783 | return &clkrst->crc_pll_simple[clkid - CLOCK_ID_FIRST_SIMPLE]; |
Svyatoslav Ryhel | b06e8fa | 2023-11-16 09:35:26 +0200 | [diff] [blame] | 784 | case CLOCK_ID_DISPLAY2: |
| 785 | return &clkrst->plld2; |
Svyatoslav Ryhel | c93b518 | 2023-07-03 18:06:54 +0300 | [diff] [blame] | 786 | default: |
| 787 | return NULL; |
| 788 | } |
| 789 | } |
| 790 | |
Stephen Warren | 1453d10 | 2016-09-13 10:45:55 -0600 | [diff] [blame] | 791 | struct periph_clk_init periph_clk_init_table[] = { |
| 792 | { PERIPH_ID_SBC1, CLOCK_ID_PERIPH }, |
| 793 | { PERIPH_ID_SBC2, CLOCK_ID_PERIPH }, |
| 794 | { PERIPH_ID_SBC3, CLOCK_ID_PERIPH }, |
| 795 | { PERIPH_ID_SBC4, CLOCK_ID_PERIPH }, |
| 796 | { PERIPH_ID_SBC5, CLOCK_ID_PERIPH }, |
| 797 | { PERIPH_ID_SBC6, CLOCK_ID_PERIPH }, |
| 798 | { PERIPH_ID_HOST1X, CLOCK_ID_PERIPH }, |
| 799 | { PERIPH_ID_DISP1, CLOCK_ID_CGENERAL }, |
| 800 | { PERIPH_ID_NDFLASH, CLOCK_ID_PERIPH }, |
| 801 | { PERIPH_ID_SDMMC1, CLOCK_ID_PERIPH }, |
| 802 | { PERIPH_ID_SDMMC2, CLOCK_ID_PERIPH }, |
| 803 | { PERIPH_ID_SDMMC3, CLOCK_ID_PERIPH }, |
| 804 | { PERIPH_ID_SDMMC4, CLOCK_ID_PERIPH }, |
Svyatoslav Ryhel | c226fc7 | 2023-02-14 19:35:28 +0200 | [diff] [blame] | 805 | { PERIPH_ID_PWM, CLOCK_ID_PERIPH }, |
Stephen Warren | 1453d10 | 2016-09-13 10:45:55 -0600 | [diff] [blame] | 806 | { PERIPH_ID_I2C1, CLOCK_ID_PERIPH }, |
| 807 | { PERIPH_ID_I2C2, CLOCK_ID_PERIPH }, |
| 808 | { PERIPH_ID_I2C3, CLOCK_ID_PERIPH }, |
| 809 | { PERIPH_ID_I2C4, CLOCK_ID_PERIPH }, |
| 810 | { PERIPH_ID_I2C5, CLOCK_ID_PERIPH }, |
| 811 | { -1, }, |
| 812 | }; |