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