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