clk-tegra30.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  1. /*
  2. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <linux/io.h>
  17. #include <linux/delay.h>
  18. #include <linux/clk-provider.h>
  19. #include <linux/clkdev.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/clk/tegra.h>
  23. #include <soc/tegra/pmc.h>
  24. #include <dt-bindings/clock/tegra30-car.h>
  25. #include "clk.h"
  26. #include "clk-id.h"
  27. #define OSC_CTRL 0x50
  28. #define OSC_CTRL_OSC_FREQ_MASK (0xF<<28)
  29. #define OSC_CTRL_OSC_FREQ_13MHZ (0X0<<28)
  30. #define OSC_CTRL_OSC_FREQ_19_2MHZ (0X4<<28)
  31. #define OSC_CTRL_OSC_FREQ_12MHZ (0X8<<28)
  32. #define OSC_CTRL_OSC_FREQ_26MHZ (0XC<<28)
  33. #define OSC_CTRL_OSC_FREQ_16_8MHZ (0X1<<28)
  34. #define OSC_CTRL_OSC_FREQ_38_4MHZ (0X5<<28)
  35. #define OSC_CTRL_OSC_FREQ_48MHZ (0X9<<28)
  36. #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
  37. #define OSC_CTRL_PLL_REF_DIV_MASK (3<<26)
  38. #define OSC_CTRL_PLL_REF_DIV_1 (0<<26)
  39. #define OSC_CTRL_PLL_REF_DIV_2 (1<<26)
  40. #define OSC_CTRL_PLL_REF_DIV_4 (2<<26)
  41. #define OSC_FREQ_DET 0x58
  42. #define OSC_FREQ_DET_TRIG BIT(31)
  43. #define OSC_FREQ_DET_STATUS 0x5c
  44. #define OSC_FREQ_DET_BUSY BIT(31)
  45. #define OSC_FREQ_DET_CNT_MASK 0xffff
  46. #define CCLKG_BURST_POLICY 0x368
  47. #define SUPER_CCLKG_DIVIDER 0x36c
  48. #define CCLKLP_BURST_POLICY 0x370
  49. #define SUPER_CCLKLP_DIVIDER 0x374
  50. #define SCLK_BURST_POLICY 0x028
  51. #define SUPER_SCLK_DIVIDER 0x02c
  52. #define SYSTEM_CLK_RATE 0x030
  53. #define TEGRA30_CLK_PERIPH_BANKS 5
  54. #define PLLC_BASE 0x80
  55. #define PLLC_MISC 0x8c
  56. #define PLLM_BASE 0x90
  57. #define PLLM_MISC 0x9c
  58. #define PLLP_BASE 0xa0
  59. #define PLLP_MISC 0xac
  60. #define PLLX_BASE 0xe0
  61. #define PLLX_MISC 0xe4
  62. #define PLLD_BASE 0xd0
  63. #define PLLD_MISC 0xdc
  64. #define PLLD2_BASE 0x4b8
  65. #define PLLD2_MISC 0x4bc
  66. #define PLLE_BASE 0xe8
  67. #define PLLE_MISC 0xec
  68. #define PLLA_BASE 0xb0
  69. #define PLLA_MISC 0xbc
  70. #define PLLU_BASE 0xc0
  71. #define PLLU_MISC 0xcc
  72. #define PLL_MISC_LOCK_ENABLE 18
  73. #define PLLDU_MISC_LOCK_ENABLE 22
  74. #define PLLE_MISC_LOCK_ENABLE 9
  75. #define PLL_BASE_LOCK BIT(27)
  76. #define PLLE_MISC_LOCK BIT(11)
  77. #define PLLE_AUX 0x48c
  78. #define PLLC_OUT 0x84
  79. #define PLLM_OUT 0x94
  80. #define PLLP_OUTA 0xa4
  81. #define PLLP_OUTB 0xa8
  82. #define PLLA_OUT 0xb4
  83. #define AUDIO_SYNC_CLK_I2S0 0x4a0
  84. #define AUDIO_SYNC_CLK_I2S1 0x4a4
  85. #define AUDIO_SYNC_CLK_I2S2 0x4a8
  86. #define AUDIO_SYNC_CLK_I2S3 0x4ac
  87. #define AUDIO_SYNC_CLK_I2S4 0x4b0
  88. #define AUDIO_SYNC_CLK_SPDIF 0x4b4
  89. #define CLK_SOURCE_SPDIF_OUT 0x108
  90. #define CLK_SOURCE_PWM 0x110
  91. #define CLK_SOURCE_D_AUDIO 0x3d0
  92. #define CLK_SOURCE_DAM0 0x3d8
  93. #define CLK_SOURCE_DAM1 0x3dc
  94. #define CLK_SOURCE_DAM2 0x3e0
  95. #define CLK_SOURCE_3D2 0x3b0
  96. #define CLK_SOURCE_2D 0x15c
  97. #define CLK_SOURCE_HDMI 0x18c
  98. #define CLK_SOURCE_DSIB 0xd0
  99. #define CLK_SOURCE_SE 0x42c
  100. #define CLK_SOURCE_EMC 0x19c
  101. #define AUDIO_SYNC_DOUBLER 0x49c
  102. #define UTMIP_PLL_CFG2 0x488
  103. #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xffff) << 6)
  104. #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18)
  105. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0)
  106. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2)
  107. #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4)
  108. #define UTMIP_PLL_CFG1 0x484
  109. #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 6)
  110. #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0)
  111. #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14)
  112. #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12)
  113. #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16)
  114. /* Tegra CPU clock and reset control regs */
  115. #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c
  116. #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340
  117. #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344
  118. #define TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR 0x34c
  119. #define TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470
  120. #define CPU_CLOCK(cpu) (0x1 << (8 + cpu))
  121. #define CPU_RESET(cpu) (0x1111ul << (cpu))
  122. #define CLK_RESET_CCLK_BURST 0x20
  123. #define CLK_RESET_CCLK_DIVIDER 0x24
  124. #define CLK_RESET_PLLX_BASE 0xe0
  125. #define CLK_RESET_PLLX_MISC 0xe4
  126. #define CLK_RESET_SOURCE_CSITE 0x1d4
  127. #define CLK_RESET_CCLK_BURST_POLICY_SHIFT 28
  128. #define CLK_RESET_CCLK_RUN_POLICY_SHIFT 4
  129. #define CLK_RESET_CCLK_IDLE_POLICY_SHIFT 0
  130. #define CLK_RESET_CCLK_IDLE_POLICY 1
  131. #define CLK_RESET_CCLK_RUN_POLICY 2
  132. #define CLK_RESET_CCLK_BURST_POLICY_PLLX 8
  133. /* PLLM override registers */
  134. #define PMC_PLLM_WB0_OVERRIDE 0x1dc
  135. #ifdef CONFIG_PM_SLEEP
  136. static struct cpu_clk_suspend_context {
  137. u32 pllx_misc;
  138. u32 pllx_base;
  139. u32 cpu_burst;
  140. u32 clk_csite_src;
  141. u32 cclk_divider;
  142. } tegra30_cpu_clk_sctx;
  143. #endif
  144. static void __iomem *clk_base;
  145. static void __iomem *pmc_base;
  146. static unsigned long input_freq;
  147. static DEFINE_SPINLOCK(cml_lock);
  148. static DEFINE_SPINLOCK(pll_d_lock);
  149. static DEFINE_SPINLOCK(emc_lock);
  150. #define TEGRA_INIT_DATA_MUX(_name, _parents, _offset, \
  151. _clk_num, _gate_flags, _clk_id) \
  152. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  153. 30, 2, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \
  154. _clk_num, _gate_flags, _clk_id)
  155. #define TEGRA_INIT_DATA_MUX8(_name, _parents, _offset, \
  156. _clk_num, _gate_flags, _clk_id) \
  157. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  158. 29, 3, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \
  159. _clk_num, _gate_flags, _clk_id)
  160. #define TEGRA_INIT_DATA_INT(_name, _parents, _offset, \
  161. _clk_num, _gate_flags, _clk_id) \
  162. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  163. 30, 2, 0, 0, 8, 1, TEGRA_DIVIDER_INT | \
  164. TEGRA_DIVIDER_ROUND_UP, _clk_num, \
  165. _gate_flags, _clk_id)
  166. #define TEGRA_INIT_DATA_NODIV(_name, _parents, _offset, \
  167. _mux_shift, _mux_width, _clk_num, \
  168. _gate_flags, _clk_id) \
  169. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  170. _mux_shift, _mux_width, 0, 0, 0, 0, 0,\
  171. _clk_num, _gate_flags, \
  172. _clk_id)
  173. static struct clk **clks;
  174. /*
  175. * Structure defining the fields for USB UTMI clocks Parameters.
  176. */
  177. struct utmi_clk_param {
  178. /* Oscillator Frequency in KHz */
  179. u32 osc_frequency;
  180. /* UTMIP PLL Enable Delay Count */
  181. u8 enable_delay_count;
  182. /* UTMIP PLL Stable count */
  183. u8 stable_count;
  184. /* UTMIP PLL Active delay count */
  185. u8 active_delay_count;
  186. /* UTMIP PLL Xtal frequency count */
  187. u8 xtal_freq_count;
  188. };
  189. static const struct utmi_clk_param utmi_parameters[] = {
  190. /* OSC_FREQUENCY, ENABLE_DLY, STABLE_CNT, ACTIVE_DLY, XTAL_FREQ_CNT */
  191. {13000000, 0x02, 0x33, 0x05, 0x7F},
  192. {19200000, 0x03, 0x4B, 0x06, 0xBB},
  193. {12000000, 0x02, 0x2F, 0x04, 0x76},
  194. {26000000, 0x04, 0x66, 0x09, 0xFE},
  195. {16800000, 0x03, 0x41, 0x0A, 0xA4},
  196. };
  197. static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
  198. { 12000000, 1040000000, 520, 6, 0, 8},
  199. { 13000000, 1040000000, 480, 6, 0, 8},
  200. { 16800000, 1040000000, 495, 8, 0, 8}, /* actual: 1039.5 MHz */
  201. { 19200000, 1040000000, 325, 6, 0, 6},
  202. { 26000000, 1040000000, 520, 13, 0, 8},
  203. { 12000000, 832000000, 416, 6, 0, 8},
  204. { 13000000, 832000000, 832, 13, 0, 8},
  205. { 16800000, 832000000, 396, 8, 0, 8}, /* actual: 831.6 MHz */
  206. { 19200000, 832000000, 260, 6, 0, 8},
  207. { 26000000, 832000000, 416, 13, 0, 8},
  208. { 12000000, 624000000, 624, 12, 0, 8},
  209. { 13000000, 624000000, 624, 13, 0, 8},
  210. { 16800000, 600000000, 520, 14, 0, 8},
  211. { 19200000, 624000000, 520, 16, 0, 8},
  212. { 26000000, 624000000, 624, 26, 0, 8},
  213. { 12000000, 600000000, 600, 12, 0, 8},
  214. { 13000000, 600000000, 600, 13, 0, 8},
  215. { 16800000, 600000000, 500, 14, 0, 8},
  216. { 19200000, 600000000, 375, 12, 0, 6},
  217. { 26000000, 600000000, 600, 26, 0, 8},
  218. { 12000000, 520000000, 520, 12, 0, 8},
  219. { 13000000, 520000000, 520, 13, 0, 8},
  220. { 16800000, 520000000, 495, 16, 0, 8}, /* actual: 519.75 MHz */
  221. { 19200000, 520000000, 325, 12, 0, 6},
  222. { 26000000, 520000000, 520, 26, 0, 8},
  223. { 12000000, 416000000, 416, 12, 0, 8},
  224. { 13000000, 416000000, 416, 13, 0, 8},
  225. { 16800000, 416000000, 396, 16, 0, 8}, /* actual: 415.8 MHz */
  226. { 19200000, 416000000, 260, 12, 0, 6},
  227. { 26000000, 416000000, 416, 26, 0, 8},
  228. { 0, 0, 0, 0, 0, 0 },
  229. };
  230. static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
  231. { 12000000, 666000000, 666, 12, 0, 8},
  232. { 13000000, 666000000, 666, 13, 0, 8},
  233. { 16800000, 666000000, 555, 14, 0, 8},
  234. { 19200000, 666000000, 555, 16, 0, 8},
  235. { 26000000, 666000000, 666, 26, 0, 8},
  236. { 12000000, 600000000, 600, 12, 0, 8},
  237. { 13000000, 600000000, 600, 13, 0, 8},
  238. { 16800000, 600000000, 500, 14, 0, 8},
  239. { 19200000, 600000000, 375, 12, 0, 6},
  240. { 26000000, 600000000, 600, 26, 0, 8},
  241. { 0, 0, 0, 0, 0, 0 },
  242. };
  243. static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
  244. { 12000000, 216000000, 432, 12, 1, 8},
  245. { 13000000, 216000000, 432, 13, 1, 8},
  246. { 16800000, 216000000, 360, 14, 1, 8},
  247. { 19200000, 216000000, 360, 16, 1, 8},
  248. { 26000000, 216000000, 432, 26, 1, 8},
  249. { 0, 0, 0, 0, 0, 0 },
  250. };
  251. static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
  252. { 9600000, 564480000, 294, 5, 0, 4},
  253. { 9600000, 552960000, 288, 5, 0, 4},
  254. { 9600000, 24000000, 5, 2, 0, 1},
  255. { 28800000, 56448000, 49, 25, 0, 1},
  256. { 28800000, 73728000, 64, 25, 0, 1},
  257. { 28800000, 24000000, 5, 6, 0, 1},
  258. { 0, 0, 0, 0, 0, 0 },
  259. };
  260. static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
  261. { 12000000, 216000000, 216, 12, 0, 4},
  262. { 13000000, 216000000, 216, 13, 0, 4},
  263. { 16800000, 216000000, 180, 14, 0, 4},
  264. { 19200000, 216000000, 180, 16, 0, 4},
  265. { 26000000, 216000000, 216, 26, 0, 4},
  266. { 12000000, 594000000, 594, 12, 0, 8},
  267. { 13000000, 594000000, 594, 13, 0, 8},
  268. { 16800000, 594000000, 495, 14, 0, 8},
  269. { 19200000, 594000000, 495, 16, 0, 8},
  270. { 26000000, 594000000, 594, 26, 0, 8},
  271. { 12000000, 1000000000, 1000, 12, 0, 12},
  272. { 13000000, 1000000000, 1000, 13, 0, 12},
  273. { 19200000, 1000000000, 625, 12, 0, 8},
  274. { 26000000, 1000000000, 1000, 26, 0, 12},
  275. { 0, 0, 0, 0, 0, 0 },
  276. };
  277. static struct pdiv_map pllu_p[] = {
  278. { .pdiv = 1, .hw_val = 1 },
  279. { .pdiv = 2, .hw_val = 0 },
  280. { .pdiv = 0, .hw_val = 0 },
  281. };
  282. static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
  283. { 12000000, 480000000, 960, 12, 2, 12 },
  284. { 13000000, 480000000, 960, 13, 2, 12 },
  285. { 16800000, 480000000, 400, 7, 2, 5 },
  286. { 19200000, 480000000, 200, 4, 2, 3 },
  287. { 26000000, 480000000, 960, 26, 2, 12 },
  288. { 0, 0, 0, 0, 0, 0 },
  289. };
  290. static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
  291. /* 1.7 GHz */
  292. { 12000000, 1700000000, 850, 6, 0, 8},
  293. { 13000000, 1700000000, 915, 7, 0, 8}, /* actual: 1699.2 MHz */
  294. { 16800000, 1700000000, 708, 7, 0, 8}, /* actual: 1699.2 MHz */
  295. { 19200000, 1700000000, 885, 10, 0, 8}, /* actual: 1699.2 MHz */
  296. { 26000000, 1700000000, 850, 13, 0, 8},
  297. /* 1.6 GHz */
  298. { 12000000, 1600000000, 800, 6, 0, 8},
  299. { 13000000, 1600000000, 738, 6, 0, 8}, /* actual: 1599.0 MHz */
  300. { 16800000, 1600000000, 857, 9, 0, 8}, /* actual: 1599.7 MHz */
  301. { 19200000, 1600000000, 500, 6, 0, 8},
  302. { 26000000, 1600000000, 800, 13, 0, 8},
  303. /* 1.5 GHz */
  304. { 12000000, 1500000000, 750, 6, 0, 8},
  305. { 13000000, 1500000000, 923, 8, 0, 8}, /* actual: 1499.8 MHz */
  306. { 16800000, 1500000000, 625, 7, 0, 8},
  307. { 19200000, 1500000000, 625, 8, 0, 8},
  308. { 26000000, 1500000000, 750, 13, 0, 8},
  309. /* 1.4 GHz */
  310. { 12000000, 1400000000, 700, 6, 0, 8},
  311. { 13000000, 1400000000, 969, 9, 0, 8}, /* actual: 1399.7 MHz */
  312. { 16800000, 1400000000, 1000, 12, 0, 8},
  313. { 19200000, 1400000000, 875, 12, 0, 8},
  314. { 26000000, 1400000000, 700, 13, 0, 8},
  315. /* 1.3 GHz */
  316. { 12000000, 1300000000, 975, 9, 0, 8},
  317. { 13000000, 1300000000, 1000, 10, 0, 8},
  318. { 16800000, 1300000000, 928, 12, 0, 8}, /* actual: 1299.2 MHz */
  319. { 19200000, 1300000000, 812, 12, 0, 8}, /* actual: 1299.2 MHz */
  320. { 26000000, 1300000000, 650, 13, 0, 8},
  321. /* 1.2 GHz */
  322. { 12000000, 1200000000, 1000, 10, 0, 8},
  323. { 13000000, 1200000000, 923, 10, 0, 8}, /* actual: 1199.9 MHz */
  324. { 16800000, 1200000000, 1000, 14, 0, 8},
  325. { 19200000, 1200000000, 1000, 16, 0, 8},
  326. { 26000000, 1200000000, 600, 13, 0, 8},
  327. /* 1.1 GHz */
  328. { 12000000, 1100000000, 825, 9, 0, 8},
  329. { 13000000, 1100000000, 846, 10, 0, 8}, /* actual: 1099.8 MHz */
  330. { 16800000, 1100000000, 982, 15, 0, 8}, /* actual: 1099.8 MHz */
  331. { 19200000, 1100000000, 859, 15, 0, 8}, /* actual: 1099.5 MHz */
  332. { 26000000, 1100000000, 550, 13, 0, 8},
  333. /* 1 GHz */
  334. { 12000000, 1000000000, 1000, 12, 0, 8},
  335. { 13000000, 1000000000, 1000, 13, 0, 8},
  336. { 16800000, 1000000000, 833, 14, 0, 8}, /* actual: 999.6 MHz */
  337. { 19200000, 1000000000, 625, 12, 0, 8},
  338. { 26000000, 1000000000, 1000, 26, 0, 8},
  339. { 0, 0, 0, 0, 0, 0 },
  340. };
  341. static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
  342. /* PLLE special case: use cpcon field to store cml divider value */
  343. { 12000000, 100000000, 150, 1, 18, 11},
  344. { 216000000, 100000000, 200, 18, 24, 13},
  345. { 0, 0, 0, 0, 0, 0 },
  346. };
  347. /* PLL parameters */
  348. static struct tegra_clk_pll_params pll_c_params = {
  349. .input_min = 2000000,
  350. .input_max = 31000000,
  351. .cf_min = 1000000,
  352. .cf_max = 6000000,
  353. .vco_min = 20000000,
  354. .vco_max = 1400000000,
  355. .base_reg = PLLC_BASE,
  356. .misc_reg = PLLC_MISC,
  357. .lock_mask = PLL_BASE_LOCK,
  358. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  359. .lock_delay = 300,
  360. .freq_table = pll_c_freq_table,
  361. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK,
  362. };
  363. static struct div_nmp pllm_nmp = {
  364. .divn_shift = 8,
  365. .divn_width = 10,
  366. .override_divn_shift = 5,
  367. .divm_shift = 0,
  368. .divm_width = 5,
  369. .override_divm_shift = 0,
  370. .divp_shift = 20,
  371. .divp_width = 3,
  372. .override_divp_shift = 15,
  373. };
  374. static struct tegra_clk_pll_params pll_m_params = {
  375. .input_min = 2000000,
  376. .input_max = 31000000,
  377. .cf_min = 1000000,
  378. .cf_max = 6000000,
  379. .vco_min = 20000000,
  380. .vco_max = 1200000000,
  381. .base_reg = PLLM_BASE,
  382. .misc_reg = PLLM_MISC,
  383. .lock_mask = PLL_BASE_LOCK,
  384. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  385. .lock_delay = 300,
  386. .div_nmp = &pllm_nmp,
  387. .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE,
  388. .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE,
  389. .freq_table = pll_m_freq_table,
  390. .flags = TEGRA_PLLM | TEGRA_PLL_HAS_CPCON |
  391. TEGRA_PLL_SET_DCCON | TEGRA_PLL_USE_LOCK,
  392. };
  393. static struct tegra_clk_pll_params pll_p_params = {
  394. .input_min = 2000000,
  395. .input_max = 31000000,
  396. .cf_min = 1000000,
  397. .cf_max = 6000000,
  398. .vco_min = 20000000,
  399. .vco_max = 1400000000,
  400. .base_reg = PLLP_BASE,
  401. .misc_reg = PLLP_MISC,
  402. .lock_mask = PLL_BASE_LOCK,
  403. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  404. .lock_delay = 300,
  405. .freq_table = pll_p_freq_table,
  406. .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK,
  407. .fixed_rate = 408000000,
  408. };
  409. static struct tegra_clk_pll_params pll_a_params = {
  410. .input_min = 2000000,
  411. .input_max = 31000000,
  412. .cf_min = 1000000,
  413. .cf_max = 6000000,
  414. .vco_min = 20000000,
  415. .vco_max = 1400000000,
  416. .base_reg = PLLA_BASE,
  417. .misc_reg = PLLA_MISC,
  418. .lock_mask = PLL_BASE_LOCK,
  419. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  420. .lock_delay = 300,
  421. .freq_table = pll_a_freq_table,
  422. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK,
  423. };
  424. static struct tegra_clk_pll_params pll_d_params = {
  425. .input_min = 2000000,
  426. .input_max = 40000000,
  427. .cf_min = 1000000,
  428. .cf_max = 6000000,
  429. .vco_min = 40000000,
  430. .vco_max = 1000000000,
  431. .base_reg = PLLD_BASE,
  432. .misc_reg = PLLD_MISC,
  433. .lock_mask = PLL_BASE_LOCK,
  434. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  435. .lock_delay = 1000,
  436. .freq_table = pll_d_freq_table,
  437. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
  438. TEGRA_PLL_USE_LOCK,
  439. };
  440. static struct tegra_clk_pll_params pll_d2_params = {
  441. .input_min = 2000000,
  442. .input_max = 40000000,
  443. .cf_min = 1000000,
  444. .cf_max = 6000000,
  445. .vco_min = 40000000,
  446. .vco_max = 1000000000,
  447. .base_reg = PLLD2_BASE,
  448. .misc_reg = PLLD2_MISC,
  449. .lock_mask = PLL_BASE_LOCK,
  450. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  451. .lock_delay = 1000,
  452. .freq_table = pll_d_freq_table,
  453. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
  454. TEGRA_PLL_USE_LOCK,
  455. };
  456. static struct tegra_clk_pll_params pll_u_params = {
  457. .input_min = 2000000,
  458. .input_max = 40000000,
  459. .cf_min = 1000000,
  460. .cf_max = 6000000,
  461. .vco_min = 48000000,
  462. .vco_max = 960000000,
  463. .base_reg = PLLU_BASE,
  464. .misc_reg = PLLU_MISC,
  465. .lock_mask = PLL_BASE_LOCK,
  466. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  467. .lock_delay = 1000,
  468. .pdiv_tohw = pllu_p,
  469. .freq_table = pll_u_freq_table,
  470. .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON,
  471. };
  472. static struct tegra_clk_pll_params pll_x_params = {
  473. .input_min = 2000000,
  474. .input_max = 31000000,
  475. .cf_min = 1000000,
  476. .cf_max = 6000000,
  477. .vco_min = 20000000,
  478. .vco_max = 1700000000,
  479. .base_reg = PLLX_BASE,
  480. .misc_reg = PLLX_MISC,
  481. .lock_mask = PLL_BASE_LOCK,
  482. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  483. .lock_delay = 300,
  484. .freq_table = pll_x_freq_table,
  485. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_DCCON |
  486. TEGRA_PLL_USE_LOCK,
  487. };
  488. static struct tegra_clk_pll_params pll_e_params = {
  489. .input_min = 12000000,
  490. .input_max = 216000000,
  491. .cf_min = 12000000,
  492. .cf_max = 12000000,
  493. .vco_min = 1200000000,
  494. .vco_max = 2400000000U,
  495. .base_reg = PLLE_BASE,
  496. .misc_reg = PLLE_MISC,
  497. .lock_mask = PLLE_MISC_LOCK,
  498. .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
  499. .lock_delay = 300,
  500. .freq_table = pll_e_freq_table,
  501. .flags = TEGRA_PLLE_CONFIGURE | TEGRA_PLL_FIXED,
  502. .fixed_rate = 100000000,
  503. };
  504. static unsigned long tegra30_input_freq[] = {
  505. [0] = 13000000,
  506. [1] = 16800000,
  507. [4] = 19200000,
  508. [5] = 38400000,
  509. [8] = 12000000,
  510. [9] = 48000000,
  511. [12] = 260000000,
  512. };
  513. static struct tegra_devclk devclks[] __initdata = {
  514. { .con_id = "pll_c", .dt_id = TEGRA30_CLK_PLL_C },
  515. { .con_id = "pll_c_out1", .dt_id = TEGRA30_CLK_PLL_C_OUT1 },
  516. { .con_id = "pll_p", .dt_id = TEGRA30_CLK_PLL_P },
  517. { .con_id = "pll_p_out1", .dt_id = TEGRA30_CLK_PLL_P_OUT1 },
  518. { .con_id = "pll_p_out2", .dt_id = TEGRA30_CLK_PLL_P_OUT2 },
  519. { .con_id = "pll_p_out3", .dt_id = TEGRA30_CLK_PLL_P_OUT3 },
  520. { .con_id = "pll_p_out4", .dt_id = TEGRA30_CLK_PLL_P_OUT4 },
  521. { .con_id = "pll_m", .dt_id = TEGRA30_CLK_PLL_M },
  522. { .con_id = "pll_m_out1", .dt_id = TEGRA30_CLK_PLL_M_OUT1 },
  523. { .con_id = "pll_x", .dt_id = TEGRA30_CLK_PLL_X },
  524. { .con_id = "pll_x_out0", .dt_id = TEGRA30_CLK_PLL_X_OUT0 },
  525. { .con_id = "pll_u", .dt_id = TEGRA30_CLK_PLL_U },
  526. { .con_id = "pll_d", .dt_id = TEGRA30_CLK_PLL_D },
  527. { .con_id = "pll_d_out0", .dt_id = TEGRA30_CLK_PLL_D_OUT0 },
  528. { .con_id = "pll_d2", .dt_id = TEGRA30_CLK_PLL_D2 },
  529. { .con_id = "pll_d2_out0", .dt_id = TEGRA30_CLK_PLL_D2_OUT0 },
  530. { .con_id = "pll_a", .dt_id = TEGRA30_CLK_PLL_A },
  531. { .con_id = "pll_a_out0", .dt_id = TEGRA30_CLK_PLL_A_OUT0 },
  532. { .con_id = "pll_e", .dt_id = TEGRA30_CLK_PLL_E },
  533. { .con_id = "spdif_in_sync", .dt_id = TEGRA30_CLK_SPDIF_IN_SYNC },
  534. { .con_id = "i2s0_sync", .dt_id = TEGRA30_CLK_I2S0_SYNC },
  535. { .con_id = "i2s1_sync", .dt_id = TEGRA30_CLK_I2S1_SYNC },
  536. { .con_id = "i2s2_sync", .dt_id = TEGRA30_CLK_I2S2_SYNC },
  537. { .con_id = "i2s3_sync", .dt_id = TEGRA30_CLK_I2S3_SYNC },
  538. { .con_id = "i2s4_sync", .dt_id = TEGRA30_CLK_I2S4_SYNC },
  539. { .con_id = "vimclk_sync", .dt_id = TEGRA30_CLK_VIMCLK_SYNC },
  540. { .con_id = "audio0", .dt_id = TEGRA30_CLK_AUDIO0 },
  541. { .con_id = "audio1", .dt_id = TEGRA30_CLK_AUDIO1 },
  542. { .con_id = "audio2", .dt_id = TEGRA30_CLK_AUDIO2 },
  543. { .con_id = "audio3", .dt_id = TEGRA30_CLK_AUDIO3 },
  544. { .con_id = "audio4", .dt_id = TEGRA30_CLK_AUDIO4 },
  545. { .con_id = "spdif", .dt_id = TEGRA30_CLK_SPDIF },
  546. { .con_id = "audio0_2x", .dt_id = TEGRA30_CLK_AUDIO0_2X },
  547. { .con_id = "audio1_2x", .dt_id = TEGRA30_CLK_AUDIO1_2X },
  548. { .con_id = "audio2_2x", .dt_id = TEGRA30_CLK_AUDIO2_2X },
  549. { .con_id = "audio3_2x", .dt_id = TEGRA30_CLK_AUDIO3_2X },
  550. { .con_id = "audio4_2x", .dt_id = TEGRA30_CLK_AUDIO4_2X },
  551. { .con_id = "spdif_2x", .dt_id = TEGRA30_CLK_SPDIF_2X },
  552. { .con_id = "extern1", .dev_id = "clk_out_1", .dt_id = TEGRA30_CLK_EXTERN1 },
  553. { .con_id = "extern2", .dev_id = "clk_out_2", .dt_id = TEGRA30_CLK_EXTERN2 },
  554. { .con_id = "extern3", .dev_id = "clk_out_3", .dt_id = TEGRA30_CLK_EXTERN3 },
  555. { .con_id = "blink", .dt_id = TEGRA30_CLK_BLINK },
  556. { .con_id = "cclk_g", .dt_id = TEGRA30_CLK_CCLK_G },
  557. { .con_id = "cclk_lp", .dt_id = TEGRA30_CLK_CCLK_LP },
  558. { .con_id = "sclk", .dt_id = TEGRA30_CLK_SCLK },
  559. { .con_id = "hclk", .dt_id = TEGRA30_CLK_HCLK },
  560. { .con_id = "pclk", .dt_id = TEGRA30_CLK_PCLK },
  561. { .con_id = "twd", .dt_id = TEGRA30_CLK_TWD },
  562. { .con_id = "emc", .dt_id = TEGRA30_CLK_EMC },
  563. { .con_id = "clk_32k", .dt_id = TEGRA30_CLK_CLK_32K },
  564. { .con_id = "clk_m_div2", .dt_id = TEGRA30_CLK_CLK_M_DIV2 },
  565. { .con_id = "clk_m_div4", .dt_id = TEGRA30_CLK_CLK_M_DIV4 },
  566. { .con_id = "cml0", .dt_id = TEGRA30_CLK_CML0 },
  567. { .con_id = "cml1", .dt_id = TEGRA30_CLK_CML1 },
  568. { .con_id = "clk_m", .dt_id = TEGRA30_CLK_CLK_M },
  569. { .con_id = "pll_ref", .dt_id = TEGRA30_CLK_PLL_REF },
  570. { .con_id = "csus", .dev_id = "tengra_camera", .dt_id = TEGRA30_CLK_CSUS },
  571. { .con_id = "vcp", .dev_id = "tegra-avp", .dt_id = TEGRA30_CLK_VCP },
  572. { .con_id = "bsea", .dev_id = "tegra-avp", .dt_id = TEGRA30_CLK_BSEA },
  573. { .con_id = "bsev", .dev_id = "tegra-aes", .dt_id = TEGRA30_CLK_BSEV },
  574. { .con_id = "dsia", .dev_id = "tegradc.0", .dt_id = TEGRA30_CLK_DSIA },
  575. { .con_id = "csi", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_CSI },
  576. { .con_id = "isp", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_ISP },
  577. { .con_id = "pcie", .dev_id = "tegra-pcie", .dt_id = TEGRA30_CLK_PCIE },
  578. { .con_id = "afi", .dev_id = "tegra-pcie", .dt_id = TEGRA30_CLK_AFI },
  579. { .con_id = "fuse", .dt_id = TEGRA30_CLK_FUSE },
  580. { .con_id = "fuse_burn", .dev_id = "fuse-tegra", .dt_id = TEGRA30_CLK_FUSE_BURN },
  581. { .con_id = "apbif", .dev_id = "tegra30-ahub", .dt_id = TEGRA30_CLK_APBIF },
  582. { .con_id = "hda2hdmi", .dev_id = "tegra30-hda", .dt_id = TEGRA30_CLK_HDA2HDMI },
  583. { .dev_id = "tegra-apbdma", .dt_id = TEGRA30_CLK_APBDMA },
  584. { .dev_id = "rtc-tegra", .dt_id = TEGRA30_CLK_RTC },
  585. { .dev_id = "timer", .dt_id = TEGRA30_CLK_TIMER },
  586. { .dev_id = "tegra-kbc", .dt_id = TEGRA30_CLK_KBC },
  587. { .dev_id = "fsl-tegra-udc", .dt_id = TEGRA30_CLK_USBD },
  588. { .dev_id = "tegra-ehci.1", .dt_id = TEGRA30_CLK_USB2 },
  589. { .dev_id = "tegra-ehci.2", .dt_id = TEGRA30_CLK_USB2 },
  590. { .dev_id = "kfuse-tegra", .dt_id = TEGRA30_CLK_KFUSE },
  591. { .dev_id = "tegra_sata_cold", .dt_id = TEGRA30_CLK_SATA_COLD },
  592. { .dev_id = "dtv", .dt_id = TEGRA30_CLK_DTV },
  593. { .dev_id = "tegra30-i2s.0", .dt_id = TEGRA30_CLK_I2S0 },
  594. { .dev_id = "tegra30-i2s.1", .dt_id = TEGRA30_CLK_I2S1 },
  595. { .dev_id = "tegra30-i2s.2", .dt_id = TEGRA30_CLK_I2S2 },
  596. { .dev_id = "tegra30-i2s.3", .dt_id = TEGRA30_CLK_I2S3 },
  597. { .dev_id = "tegra30-i2s.4", .dt_id = TEGRA30_CLK_I2S4 },
  598. { .con_id = "spdif_out", .dev_id = "tegra30-spdif", .dt_id = TEGRA30_CLK_SPDIF_OUT },
  599. { .con_id = "spdif_in", .dev_id = "tegra30-spdif", .dt_id = TEGRA30_CLK_SPDIF_IN },
  600. { .con_id = "d_audio", .dev_id = "tegra30-ahub", .dt_id = TEGRA30_CLK_D_AUDIO },
  601. { .dev_id = "tegra30-dam.0", .dt_id = TEGRA30_CLK_DAM0 },
  602. { .dev_id = "tegra30-dam.1", .dt_id = TEGRA30_CLK_DAM1 },
  603. { .dev_id = "tegra30-dam.2", .dt_id = TEGRA30_CLK_DAM2 },
  604. { .con_id = "hda", .dev_id = "tegra30-hda", .dt_id = TEGRA30_CLK_HDA },
  605. { .con_id = "hda2codec_2x", .dev_id = "tegra30-hda", .dt_id = TEGRA30_CLK_HDA2CODEC_2X },
  606. { .dev_id = "spi_tegra.0", .dt_id = TEGRA30_CLK_SBC1 },
  607. { .dev_id = "spi_tegra.1", .dt_id = TEGRA30_CLK_SBC2 },
  608. { .dev_id = "spi_tegra.2", .dt_id = TEGRA30_CLK_SBC3 },
  609. { .dev_id = "spi_tegra.3", .dt_id = TEGRA30_CLK_SBC4 },
  610. { .dev_id = "spi_tegra.4", .dt_id = TEGRA30_CLK_SBC5 },
  611. { .dev_id = "spi_tegra.5", .dt_id = TEGRA30_CLK_SBC6 },
  612. { .dev_id = "tegra_sata_oob", .dt_id = TEGRA30_CLK_SATA_OOB },
  613. { .dev_id = "tegra_sata", .dt_id = TEGRA30_CLK_SATA },
  614. { .dev_id = "tegra_nand", .dt_id = TEGRA30_CLK_NDFLASH },
  615. { .dev_id = "tegra_nand_speed", .dt_id = TEGRA30_CLK_NDSPEED },
  616. { .dev_id = "vfir", .dt_id = TEGRA30_CLK_VFIR },
  617. { .dev_id = "csite", .dt_id = TEGRA30_CLK_CSITE },
  618. { .dev_id = "la", .dt_id = TEGRA30_CLK_LA },
  619. { .dev_id = "tegra_w1", .dt_id = TEGRA30_CLK_OWR },
  620. { .dev_id = "mipi", .dt_id = TEGRA30_CLK_MIPI },
  621. { .dev_id = "tegra-tsensor", .dt_id = TEGRA30_CLK_TSENSOR },
  622. { .dev_id = "i2cslow", .dt_id = TEGRA30_CLK_I2CSLOW },
  623. { .dev_id = "vde", .dt_id = TEGRA30_CLK_VDE },
  624. { .con_id = "vi", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_VI },
  625. { .dev_id = "epp", .dt_id = TEGRA30_CLK_EPP },
  626. { .dev_id = "mpe", .dt_id = TEGRA30_CLK_MPE },
  627. { .dev_id = "host1x", .dt_id = TEGRA30_CLK_HOST1X },
  628. { .dev_id = "3d", .dt_id = TEGRA30_CLK_GR3D },
  629. { .dev_id = "3d2", .dt_id = TEGRA30_CLK_GR3D2 },
  630. { .dev_id = "2d", .dt_id = TEGRA30_CLK_GR2D },
  631. { .dev_id = "se", .dt_id = TEGRA30_CLK_SE },
  632. { .dev_id = "mselect", .dt_id = TEGRA30_CLK_MSELECT },
  633. { .dev_id = "tegra-nor", .dt_id = TEGRA30_CLK_NOR },
  634. { .dev_id = "sdhci-tegra.0", .dt_id = TEGRA30_CLK_SDMMC1 },
  635. { .dev_id = "sdhci-tegra.1", .dt_id = TEGRA30_CLK_SDMMC2 },
  636. { .dev_id = "sdhci-tegra.2", .dt_id = TEGRA30_CLK_SDMMC3 },
  637. { .dev_id = "sdhci-tegra.3", .dt_id = TEGRA30_CLK_SDMMC4 },
  638. { .dev_id = "cve", .dt_id = TEGRA30_CLK_CVE },
  639. { .dev_id = "tvo", .dt_id = TEGRA30_CLK_TVO },
  640. { .dev_id = "tvdac", .dt_id = TEGRA30_CLK_TVDAC },
  641. { .dev_id = "actmon", .dt_id = TEGRA30_CLK_ACTMON },
  642. { .con_id = "vi_sensor", .dev_id = "tegra_camera", .dt_id = TEGRA30_CLK_VI_SENSOR },
  643. { .con_id = "div-clk", .dev_id = "tegra-i2c.0", .dt_id = TEGRA30_CLK_I2C1 },
  644. { .con_id = "div-clk", .dev_id = "tegra-i2c.1", .dt_id = TEGRA30_CLK_I2C2 },
  645. { .con_id = "div-clk", .dev_id = "tegra-i2c.2", .dt_id = TEGRA30_CLK_I2C3 },
  646. { .con_id = "div-clk", .dev_id = "tegra-i2c.3", .dt_id = TEGRA30_CLK_I2C4 },
  647. { .con_id = "div-clk", .dev_id = "tegra-i2c.4", .dt_id = TEGRA30_CLK_I2C5 },
  648. { .dev_id = "tegra_uart.0", .dt_id = TEGRA30_CLK_UARTA },
  649. { .dev_id = "tegra_uart.1", .dt_id = TEGRA30_CLK_UARTB },
  650. { .dev_id = "tegra_uart.2", .dt_id = TEGRA30_CLK_UARTC },
  651. { .dev_id = "tegra_uart.3", .dt_id = TEGRA30_CLK_UARTD },
  652. { .dev_id = "tegra_uart.4", .dt_id = TEGRA30_CLK_UARTE },
  653. { .dev_id = "hdmi", .dt_id = TEGRA30_CLK_HDMI },
  654. { .dev_id = "extern1", .dt_id = TEGRA30_CLK_EXTERN1 },
  655. { .dev_id = "extern2", .dt_id = TEGRA30_CLK_EXTERN2 },
  656. { .dev_id = "extern3", .dt_id = TEGRA30_CLK_EXTERN3 },
  657. { .dev_id = "pwm", .dt_id = TEGRA30_CLK_PWM },
  658. { .dev_id = "tegradc.0", .dt_id = TEGRA30_CLK_DISP1 },
  659. { .dev_id = "tegradc.1", .dt_id = TEGRA30_CLK_DISP2 },
  660. { .dev_id = "tegradc.1", .dt_id = TEGRA30_CLK_DSIB },
  661. };
  662. static struct tegra_clk tegra30_clks[tegra_clk_max] __initdata = {
  663. [tegra_clk_clk_32k] = { .dt_id = TEGRA30_CLK_CLK_32K, .present = true },
  664. [tegra_clk_clk_m] = { .dt_id = TEGRA30_CLK_CLK_M, .present = true },
  665. [tegra_clk_clk_m_div2] = { .dt_id = TEGRA30_CLK_CLK_M_DIV2, .present = true },
  666. [tegra_clk_clk_m_div4] = { .dt_id = TEGRA30_CLK_CLK_M_DIV4, .present = true },
  667. [tegra_clk_pll_ref] = { .dt_id = TEGRA30_CLK_PLL_REF, .present = true },
  668. [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA30_CLK_SPDIF_IN_SYNC, .present = true },
  669. [tegra_clk_i2s0_sync] = { .dt_id = TEGRA30_CLK_I2S0_SYNC, .present = true },
  670. [tegra_clk_i2s1_sync] = { .dt_id = TEGRA30_CLK_I2S1_SYNC, .present = true },
  671. [tegra_clk_i2s2_sync] = { .dt_id = TEGRA30_CLK_I2S2_SYNC, .present = true },
  672. [tegra_clk_i2s3_sync] = { .dt_id = TEGRA30_CLK_I2S3_SYNC, .present = true },
  673. [tegra_clk_i2s4_sync] = { .dt_id = TEGRA30_CLK_I2S4_SYNC, .present = true },
  674. [tegra_clk_vimclk_sync] = { .dt_id = TEGRA30_CLK_VIMCLK_SYNC, .present = true },
  675. [tegra_clk_audio0] = { .dt_id = TEGRA30_CLK_AUDIO0, .present = true },
  676. [tegra_clk_audio1] = { .dt_id = TEGRA30_CLK_AUDIO1, .present = true },
  677. [tegra_clk_audio2] = { .dt_id = TEGRA30_CLK_AUDIO2, .present = true },
  678. [tegra_clk_audio3] = { .dt_id = TEGRA30_CLK_AUDIO3, .present = true },
  679. [tegra_clk_audio4] = { .dt_id = TEGRA30_CLK_AUDIO4, .present = true },
  680. [tegra_clk_spdif] = { .dt_id = TEGRA30_CLK_SPDIF, .present = true },
  681. [tegra_clk_audio0_mux] = { .dt_id = TEGRA30_CLK_AUDIO0_MUX, .present = true },
  682. [tegra_clk_audio1_mux] = { .dt_id = TEGRA30_CLK_AUDIO1_MUX, .present = true },
  683. [tegra_clk_audio2_mux] = { .dt_id = TEGRA30_CLK_AUDIO2_MUX, .present = true },
  684. [tegra_clk_audio3_mux] = { .dt_id = TEGRA30_CLK_AUDIO3_MUX, .present = true },
  685. [tegra_clk_audio4_mux] = { .dt_id = TEGRA30_CLK_AUDIO4_MUX, .present = true },
  686. [tegra_clk_spdif_mux] = { .dt_id = TEGRA30_CLK_SPDIF_MUX, .present = true },
  687. [tegra_clk_audio0_2x] = { .dt_id = TEGRA30_CLK_AUDIO0_2X, .present = true },
  688. [tegra_clk_audio1_2x] = { .dt_id = TEGRA30_CLK_AUDIO1_2X, .present = true },
  689. [tegra_clk_audio2_2x] = { .dt_id = TEGRA30_CLK_AUDIO2_2X, .present = true },
  690. [tegra_clk_audio3_2x] = { .dt_id = TEGRA30_CLK_AUDIO3_2X, .present = true },
  691. [tegra_clk_audio4_2x] = { .dt_id = TEGRA30_CLK_AUDIO4_2X, .present = true },
  692. [tegra_clk_spdif_2x] = { .dt_id = TEGRA30_CLK_SPDIF_2X, .present = true },
  693. [tegra_clk_clk_out_1] = { .dt_id = TEGRA30_CLK_CLK_OUT_1, .present = true },
  694. [tegra_clk_clk_out_2] = { .dt_id = TEGRA30_CLK_CLK_OUT_2, .present = true },
  695. [tegra_clk_clk_out_3] = { .dt_id = TEGRA30_CLK_CLK_OUT_3, .present = true },
  696. [tegra_clk_blink] = { .dt_id = TEGRA30_CLK_BLINK, .present = true },
  697. [tegra_clk_clk_out_1_mux] = { .dt_id = TEGRA30_CLK_CLK_OUT_1_MUX, .present = true },
  698. [tegra_clk_clk_out_2_mux] = { .dt_id = TEGRA30_CLK_CLK_OUT_2_MUX, .present = true },
  699. [tegra_clk_clk_out_3_mux] = { .dt_id = TEGRA30_CLK_CLK_OUT_3_MUX, .present = true },
  700. [tegra_clk_hclk] = { .dt_id = TEGRA30_CLK_HCLK, .present = true },
  701. [tegra_clk_pclk] = { .dt_id = TEGRA30_CLK_PCLK, .present = true },
  702. [tegra_clk_i2s0] = { .dt_id = TEGRA30_CLK_I2S0, .present = true },
  703. [tegra_clk_i2s1] = { .dt_id = TEGRA30_CLK_I2S1, .present = true },
  704. [tegra_clk_i2s2] = { .dt_id = TEGRA30_CLK_I2S2, .present = true },
  705. [tegra_clk_i2s3] = { .dt_id = TEGRA30_CLK_I2S3, .present = true },
  706. [tegra_clk_i2s4] = { .dt_id = TEGRA30_CLK_I2S4, .present = true },
  707. [tegra_clk_spdif_in] = { .dt_id = TEGRA30_CLK_SPDIF_IN, .present = true },
  708. [tegra_clk_hda] = { .dt_id = TEGRA30_CLK_HDA, .present = true },
  709. [tegra_clk_hda2codec_2x] = { .dt_id = TEGRA30_CLK_HDA2CODEC_2X, .present = true },
  710. [tegra_clk_sbc1] = { .dt_id = TEGRA30_CLK_SBC1, .present = true },
  711. [tegra_clk_sbc2] = { .dt_id = TEGRA30_CLK_SBC2, .present = true },
  712. [tegra_clk_sbc3] = { .dt_id = TEGRA30_CLK_SBC3, .present = true },
  713. [tegra_clk_sbc4] = { .dt_id = TEGRA30_CLK_SBC4, .present = true },
  714. [tegra_clk_sbc5] = { .dt_id = TEGRA30_CLK_SBC5, .present = true },
  715. [tegra_clk_sbc6] = { .dt_id = TEGRA30_CLK_SBC6, .present = true },
  716. [tegra_clk_ndflash] = { .dt_id = TEGRA30_CLK_NDFLASH, .present = true },
  717. [tegra_clk_ndspeed] = { .dt_id = TEGRA30_CLK_NDSPEED, .present = true },
  718. [tegra_clk_vfir] = { .dt_id = TEGRA30_CLK_VFIR, .present = true },
  719. [tegra_clk_la] = { .dt_id = TEGRA30_CLK_LA, .present = true },
  720. [tegra_clk_csite] = { .dt_id = TEGRA30_CLK_CSITE, .present = true },
  721. [tegra_clk_owr] = { .dt_id = TEGRA30_CLK_OWR, .present = true },
  722. [tegra_clk_mipi] = { .dt_id = TEGRA30_CLK_MIPI, .present = true },
  723. [tegra_clk_tsensor] = { .dt_id = TEGRA30_CLK_TSENSOR, .present = true },
  724. [tegra_clk_i2cslow] = { .dt_id = TEGRA30_CLK_I2CSLOW, .present = true },
  725. [tegra_clk_vde] = { .dt_id = TEGRA30_CLK_VDE, .present = true },
  726. [tegra_clk_vi] = { .dt_id = TEGRA30_CLK_VI, .present = true },
  727. [tegra_clk_epp] = { .dt_id = TEGRA30_CLK_EPP, .present = true },
  728. [tegra_clk_mpe] = { .dt_id = TEGRA30_CLK_MPE, .present = true },
  729. [tegra_clk_host1x] = { .dt_id = TEGRA30_CLK_HOST1X, .present = true },
  730. [tegra_clk_gr2d] = { .dt_id = TEGRA30_CLK_GR2D, .present = true },
  731. [tegra_clk_gr3d] = { .dt_id = TEGRA30_CLK_GR3D, .present = true },
  732. [tegra_clk_mselect] = { .dt_id = TEGRA30_CLK_MSELECT, .present = true },
  733. [tegra_clk_nor] = { .dt_id = TEGRA30_CLK_NOR, .present = true },
  734. [tegra_clk_sdmmc1] = { .dt_id = TEGRA30_CLK_SDMMC1, .present = true },
  735. [tegra_clk_sdmmc2] = { .dt_id = TEGRA30_CLK_SDMMC2, .present = true },
  736. [tegra_clk_sdmmc3] = { .dt_id = TEGRA30_CLK_SDMMC3, .present = true },
  737. [tegra_clk_sdmmc4] = { .dt_id = TEGRA30_CLK_SDMMC4, .present = true },
  738. [tegra_clk_cve] = { .dt_id = TEGRA30_CLK_CVE, .present = true },
  739. [tegra_clk_tvo] = { .dt_id = TEGRA30_CLK_TVO, .present = true },
  740. [tegra_clk_tvdac] = { .dt_id = TEGRA30_CLK_TVDAC, .present = true },
  741. [tegra_clk_actmon] = { .dt_id = TEGRA30_CLK_ACTMON, .present = true },
  742. [tegra_clk_vi_sensor] = { .dt_id = TEGRA30_CLK_VI_SENSOR, .present = true },
  743. [tegra_clk_i2c1] = { .dt_id = TEGRA30_CLK_I2C1, .present = true },
  744. [tegra_clk_i2c2] = { .dt_id = TEGRA30_CLK_I2C2, .present = true },
  745. [tegra_clk_i2c3] = { .dt_id = TEGRA30_CLK_I2C3, .present = true },
  746. [tegra_clk_i2c4] = { .dt_id = TEGRA30_CLK_I2C4, .present = true },
  747. [tegra_clk_i2c5] = { .dt_id = TEGRA30_CLK_I2C5, .present = true },
  748. [tegra_clk_uarta] = { .dt_id = TEGRA30_CLK_UARTA, .present = true },
  749. [tegra_clk_uartb] = { .dt_id = TEGRA30_CLK_UARTB, .present = true },
  750. [tegra_clk_uartc] = { .dt_id = TEGRA30_CLK_UARTC, .present = true },
  751. [tegra_clk_uartd] = { .dt_id = TEGRA30_CLK_UARTD, .present = true },
  752. [tegra_clk_uarte] = { .dt_id = TEGRA30_CLK_UARTE, .present = true },
  753. [tegra_clk_extern1] = { .dt_id = TEGRA30_CLK_EXTERN1, .present = true },
  754. [tegra_clk_extern2] = { .dt_id = TEGRA30_CLK_EXTERN2, .present = true },
  755. [tegra_clk_extern3] = { .dt_id = TEGRA30_CLK_EXTERN3, .present = true },
  756. [tegra_clk_disp1] = { .dt_id = TEGRA30_CLK_DISP1, .present = true },
  757. [tegra_clk_disp2] = { .dt_id = TEGRA30_CLK_DISP2, .present = true },
  758. [tegra_clk_apbdma] = { .dt_id = TEGRA30_CLK_APBDMA, .present = true },
  759. [tegra_clk_rtc] = { .dt_id = TEGRA30_CLK_RTC, .present = true },
  760. [tegra_clk_timer] = { .dt_id = TEGRA30_CLK_TIMER, .present = true },
  761. [tegra_clk_kbc] = { .dt_id = TEGRA30_CLK_KBC, .present = true },
  762. [tegra_clk_csus] = { .dt_id = TEGRA30_CLK_CSUS, .present = true },
  763. [tegra_clk_vcp] = { .dt_id = TEGRA30_CLK_VCP, .present = true },
  764. [tegra_clk_bsea] = { .dt_id = TEGRA30_CLK_BSEA, .present = true },
  765. [tegra_clk_bsev] = { .dt_id = TEGRA30_CLK_BSEV, .present = true },
  766. [tegra_clk_usbd] = { .dt_id = TEGRA30_CLK_USBD, .present = true },
  767. [tegra_clk_usb2] = { .dt_id = TEGRA30_CLK_USB2, .present = true },
  768. [tegra_clk_usb3] = { .dt_id = TEGRA30_CLK_USB3, .present = true },
  769. [tegra_clk_csi] = { .dt_id = TEGRA30_CLK_CSI, .present = true },
  770. [tegra_clk_isp] = { .dt_id = TEGRA30_CLK_ISP, .present = true },
  771. [tegra_clk_kfuse] = { .dt_id = TEGRA30_CLK_KFUSE, .present = true },
  772. [tegra_clk_fuse] = { .dt_id = TEGRA30_CLK_FUSE, .present = true },
  773. [tegra_clk_fuse_burn] = { .dt_id = TEGRA30_CLK_FUSE_BURN, .present = true },
  774. [tegra_clk_apbif] = { .dt_id = TEGRA30_CLK_APBIF, .present = true },
  775. [tegra_clk_hda2hdmi] = { .dt_id = TEGRA30_CLK_HDA2HDMI, .present = true },
  776. [tegra_clk_sata_cold] = { .dt_id = TEGRA30_CLK_SATA_COLD, .present = true },
  777. [tegra_clk_sata_oob] = { .dt_id = TEGRA30_CLK_SATA_OOB, .present = true },
  778. [tegra_clk_sata] = { .dt_id = TEGRA30_CLK_SATA, .present = true },
  779. [tegra_clk_dtv] = { .dt_id = TEGRA30_CLK_DTV, .present = true },
  780. [tegra_clk_pll_p] = { .dt_id = TEGRA30_CLK_PLL_P, .present = true },
  781. [tegra_clk_pll_p_out1] = { .dt_id = TEGRA30_CLK_PLL_P_OUT1, .present = true },
  782. [tegra_clk_pll_p_out2] = { .dt_id = TEGRA30_CLK_PLL_P_OUT2, .present = true },
  783. [tegra_clk_pll_p_out3] = { .dt_id = TEGRA30_CLK_PLL_P_OUT3, .present = true },
  784. [tegra_clk_pll_p_out4] = { .dt_id = TEGRA30_CLK_PLL_P_OUT4, .present = true },
  785. [tegra_clk_pll_a] = { .dt_id = TEGRA30_CLK_PLL_A, .present = true },
  786. [tegra_clk_pll_a_out0] = { .dt_id = TEGRA30_CLK_PLL_A_OUT0, .present = true },
  787. };
  788. static void tegra30_utmi_param_configure(void)
  789. {
  790. u32 reg;
  791. int i;
  792. for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) {
  793. if (input_freq == utmi_parameters[i].osc_frequency)
  794. break;
  795. }
  796. if (i >= ARRAY_SIZE(utmi_parameters)) {
  797. pr_err("%s: Unexpected input rate %lu\n", __func__, input_freq);
  798. return;
  799. }
  800. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2);
  801. /* Program UTMIP PLL stable and active counts */
  802. reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0);
  803. reg |= UTMIP_PLL_CFG2_STABLE_COUNT(
  804. utmi_parameters[i].stable_count);
  805. reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0);
  806. reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(
  807. utmi_parameters[i].active_delay_count);
  808. /* Remove power downs from UTMIP PLL control bits */
  809. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN;
  810. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN;
  811. reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN;
  812. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2);
  813. /* Program UTMIP PLL delay and oscillator frequency counts */
  814. reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1);
  815. reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0);
  816. reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(
  817. utmi_parameters[i].enable_delay_count);
  818. reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0);
  819. reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(
  820. utmi_parameters[i].xtal_freq_count);
  821. /* Remove power downs from UTMIP PLL control bits */
  822. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN;
  823. reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN;
  824. reg &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN;
  825. writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1);
  826. }
  827. static const char *pll_e_parents[] = {"pll_ref", "pll_p"};
  828. static void __init tegra30_pll_init(void)
  829. {
  830. struct clk *clk;
  831. /* PLLC */
  832. clk = tegra_clk_register_pll("pll_c", "pll_ref", clk_base, pmc_base, 0,
  833. &pll_c_params, NULL);
  834. clks[TEGRA30_CLK_PLL_C] = clk;
  835. /* PLLC_OUT1 */
  836. clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c",
  837. clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  838. 8, 8, 1, NULL);
  839. clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div",
  840. clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT,
  841. 0, NULL);
  842. clks[TEGRA30_CLK_PLL_C_OUT1] = clk;
  843. /* PLLM */
  844. clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, pmc_base,
  845. CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  846. &pll_m_params, NULL);
  847. clks[TEGRA30_CLK_PLL_M] = clk;
  848. /* PLLM_OUT1 */
  849. clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m",
  850. clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  851. 8, 8, 1, NULL);
  852. clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
  853. clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
  854. CLK_SET_RATE_PARENT, 0, NULL);
  855. clks[TEGRA30_CLK_PLL_M_OUT1] = clk;
  856. /* PLLX */
  857. clk = tegra_clk_register_pll("pll_x", "pll_ref", clk_base, pmc_base, 0,
  858. &pll_x_params, NULL);
  859. clks[TEGRA30_CLK_PLL_X] = clk;
  860. /* PLLX_OUT0 */
  861. clk = clk_register_fixed_factor(NULL, "pll_x_out0", "pll_x",
  862. CLK_SET_RATE_PARENT, 1, 2);
  863. clks[TEGRA30_CLK_PLL_X_OUT0] = clk;
  864. /* PLLU */
  865. clk = tegra_clk_register_pll("pll_u", "pll_ref", clk_base, pmc_base, 0,
  866. &pll_u_params, NULL);
  867. clks[TEGRA30_CLK_PLL_U] = clk;
  868. tegra30_utmi_param_configure();
  869. /* PLLD */
  870. clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc_base, 0,
  871. &pll_d_params, &pll_d_lock);
  872. clks[TEGRA30_CLK_PLL_D] = clk;
  873. /* PLLD_OUT0 */
  874. clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d",
  875. CLK_SET_RATE_PARENT, 1, 2);
  876. clks[TEGRA30_CLK_PLL_D_OUT0] = clk;
  877. /* PLLD2 */
  878. clk = tegra_clk_register_pll("pll_d2", "pll_ref", clk_base, pmc_base, 0,
  879. &pll_d2_params, NULL);
  880. clks[TEGRA30_CLK_PLL_D2] = clk;
  881. /* PLLD2_OUT0 */
  882. clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
  883. CLK_SET_RATE_PARENT, 1, 2);
  884. clks[TEGRA30_CLK_PLL_D2_OUT0] = clk;
  885. /* PLLE */
  886. clk = clk_register_mux(NULL, "pll_e_mux", pll_e_parents,
  887. ARRAY_SIZE(pll_e_parents),
  888. CLK_SET_RATE_NO_REPARENT,
  889. clk_base + PLLE_AUX, 2, 1, 0, NULL);
  890. clk = tegra_clk_register_plle("pll_e", "pll_e_mux", clk_base, pmc_base,
  891. CLK_GET_RATE_NOCACHE, &pll_e_params, NULL);
  892. clks[TEGRA30_CLK_PLL_E] = clk;
  893. }
  894. static const char *cclk_g_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m",
  895. "pll_p_cclkg", "pll_p_out4_cclkg",
  896. "pll_p_out3_cclkg", "unused", "pll_x" };
  897. static const char *cclk_lp_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m",
  898. "pll_p_cclklp", "pll_p_out4_cclklp",
  899. "pll_p_out3_cclklp", "unused", "pll_x",
  900. "pll_x_out0" };
  901. static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4",
  902. "pll_p_out3", "pll_p_out2", "unused",
  903. "clk_32k", "pll_m_out1" };
  904. static void __init tegra30_super_clk_init(void)
  905. {
  906. struct clk *clk;
  907. /*
  908. * Clock input to cclk_g divided from pll_p using
  909. * U71 divider of cclk_g.
  910. */
  911. clk = tegra_clk_register_divider("pll_p_cclkg", "pll_p",
  912. clk_base + SUPER_CCLKG_DIVIDER, 0,
  913. TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
  914. clk_register_clkdev(clk, "pll_p_cclkg", NULL);
  915. /*
  916. * Clock input to cclk_g divided from pll_p_out3 using
  917. * U71 divider of cclk_g.
  918. */
  919. clk = tegra_clk_register_divider("pll_p_out3_cclkg", "pll_p_out3",
  920. clk_base + SUPER_CCLKG_DIVIDER, 0,
  921. TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
  922. clk_register_clkdev(clk, "pll_p_out3_cclkg", NULL);
  923. /*
  924. * Clock input to cclk_g divided from pll_p_out4 using
  925. * U71 divider of cclk_g.
  926. */
  927. clk = tegra_clk_register_divider("pll_p_out4_cclkg", "pll_p_out4",
  928. clk_base + SUPER_CCLKG_DIVIDER, 0,
  929. TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
  930. clk_register_clkdev(clk, "pll_p_out4_cclkg", NULL);
  931. /* CCLKG */
  932. clk = tegra_clk_register_super_mux("cclk_g", cclk_g_parents,
  933. ARRAY_SIZE(cclk_g_parents),
  934. CLK_SET_RATE_PARENT,
  935. clk_base + CCLKG_BURST_POLICY,
  936. 0, 4, 0, 0, NULL);
  937. clks[TEGRA30_CLK_CCLK_G] = clk;
  938. /*
  939. * Clock input to cclk_lp divided from pll_p using
  940. * U71 divider of cclk_lp.
  941. */
  942. clk = tegra_clk_register_divider("pll_p_cclklp", "pll_p",
  943. clk_base + SUPER_CCLKLP_DIVIDER, 0,
  944. TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
  945. clk_register_clkdev(clk, "pll_p_cclklp", NULL);
  946. /*
  947. * Clock input to cclk_lp divided from pll_p_out3 using
  948. * U71 divider of cclk_lp.
  949. */
  950. clk = tegra_clk_register_divider("pll_p_out3_cclklp", "pll_p_out3",
  951. clk_base + SUPER_CCLKLP_DIVIDER, 0,
  952. TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
  953. clk_register_clkdev(clk, "pll_p_out3_cclklp", NULL);
  954. /*
  955. * Clock input to cclk_lp divided from pll_p_out4 using
  956. * U71 divider of cclk_lp.
  957. */
  958. clk = tegra_clk_register_divider("pll_p_out4_cclklp", "pll_p_out4",
  959. clk_base + SUPER_CCLKLP_DIVIDER, 0,
  960. TEGRA_DIVIDER_INT, 16, 8, 1, NULL);
  961. clk_register_clkdev(clk, "pll_p_out4_cclklp", NULL);
  962. /* CCLKLP */
  963. clk = tegra_clk_register_super_mux("cclk_lp", cclk_lp_parents,
  964. ARRAY_SIZE(cclk_lp_parents),
  965. CLK_SET_RATE_PARENT,
  966. clk_base + CCLKLP_BURST_POLICY,
  967. TEGRA_DIVIDER_2, 4, 8, 9,
  968. NULL);
  969. clks[TEGRA30_CLK_CCLK_LP] = clk;
  970. /* SCLK */
  971. clk = tegra_clk_register_super_mux("sclk", sclk_parents,
  972. ARRAY_SIZE(sclk_parents),
  973. CLK_SET_RATE_PARENT,
  974. clk_base + SCLK_BURST_POLICY,
  975. 0, 4, 0, 0, NULL);
  976. clks[TEGRA30_CLK_SCLK] = clk;
  977. /* twd */
  978. clk = clk_register_fixed_factor(NULL, "twd", "cclk_g",
  979. CLK_SET_RATE_PARENT, 1, 2);
  980. clks[TEGRA30_CLK_TWD] = clk;
  981. tegra_super_clk_gen4_init(clk_base, pmc_base, tegra30_clks, NULL);
  982. }
  983. static const char *mux_pllacp_clkm[] = { "pll_a_out0", "unused", "pll_p",
  984. "clk_m" };
  985. static const char *mux_pllpcm_clkm[] = { "pll_p", "pll_c", "pll_m", "clk_m" };
  986. static const char *mux_pllmcp_clkm[] = { "pll_m", "pll_c", "pll_p", "clk_m" };
  987. static const char *spdif_out_parents[] = { "pll_a_out0", "spdif_2x", "pll_p",
  988. "clk_m" };
  989. static const char *mux_pllmcpa[] = { "pll_m", "pll_c", "pll_p", "pll_a_out0" };
  990. static const char *mux_pllpmdacd2_clkm[] = { "pll_p", "pll_m", "pll_d_out0",
  991. "pll_a_out0", "pll_c",
  992. "pll_d2_out0", "clk_m" };
  993. static const char *mux_plld_out0_plld2_out0[] = { "pll_d_out0",
  994. "pll_d2_out0" };
  995. static const char *pwm_parents[] = { "pll_p", "pll_c", "clk_32k", "clk_m" };
  996. static struct tegra_periph_init_data tegra_periph_clk_list[] = {
  997. TEGRA_INIT_DATA_MUX("spdif_out", spdif_out_parents, CLK_SOURCE_SPDIF_OUT, 10, TEGRA_PERIPH_ON_APB, TEGRA30_CLK_SPDIF_OUT),
  998. TEGRA_INIT_DATA_MUX("d_audio", mux_pllacp_clkm, CLK_SOURCE_D_AUDIO, 106, 0, TEGRA30_CLK_D_AUDIO),
  999. TEGRA_INIT_DATA_MUX("dam0", mux_pllacp_clkm, CLK_SOURCE_DAM0, 108, 0, TEGRA30_CLK_DAM0),
  1000. TEGRA_INIT_DATA_MUX("dam1", mux_pllacp_clkm, CLK_SOURCE_DAM1, 109, 0, TEGRA30_CLK_DAM1),
  1001. TEGRA_INIT_DATA_MUX("dam2", mux_pllacp_clkm, CLK_SOURCE_DAM2, 110, 0, TEGRA30_CLK_DAM2),
  1002. TEGRA_INIT_DATA_INT("3d2", mux_pllmcpa, CLK_SOURCE_3D2, 98, TEGRA_PERIPH_MANUAL_RESET, TEGRA30_CLK_GR3D2),
  1003. TEGRA_INIT_DATA_INT("se", mux_pllpcm_clkm, CLK_SOURCE_SE, 127, 0, TEGRA30_CLK_SE),
  1004. TEGRA_INIT_DATA_MUX8("hdmi", mux_pllpmdacd2_clkm, CLK_SOURCE_HDMI, 51, 0, TEGRA30_CLK_HDMI),
  1005. TEGRA_INIT_DATA("pwm", NULL, NULL, pwm_parents, CLK_SOURCE_PWM, 28, 2, 0, 0, 8, 1, 0, 17, TEGRA_PERIPH_ON_APB, TEGRA30_CLK_PWM),
  1006. };
  1007. static struct tegra_periph_init_data tegra_periph_nodiv_clk_list[] = {
  1008. TEGRA_INIT_DATA_NODIV("dsib", mux_plld_out0_plld2_out0, CLK_SOURCE_DSIB, 25, 1, 82, 0, TEGRA30_CLK_DSIB),
  1009. };
  1010. static void __init tegra30_periph_clk_init(void)
  1011. {
  1012. struct tegra_periph_init_data *data;
  1013. struct clk *clk;
  1014. int i;
  1015. /* dsia */
  1016. clk = tegra_clk_register_periph_gate("dsia", "pll_d_out0", 0, clk_base,
  1017. 0, 48, periph_clk_enb_refcnt);
  1018. clks[TEGRA30_CLK_DSIA] = clk;
  1019. /* pcie */
  1020. clk = tegra_clk_register_periph_gate("pcie", "clk_m", 0, clk_base, 0,
  1021. 70, periph_clk_enb_refcnt);
  1022. clks[TEGRA30_CLK_PCIE] = clk;
  1023. /* afi */
  1024. clk = tegra_clk_register_periph_gate("afi", "clk_m", 0, clk_base, 0, 72,
  1025. periph_clk_enb_refcnt);
  1026. clks[TEGRA30_CLK_AFI] = clk;
  1027. /* emc */
  1028. clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
  1029. ARRAY_SIZE(mux_pllmcp_clkm),
  1030. CLK_SET_RATE_NO_REPARENT,
  1031. clk_base + CLK_SOURCE_EMC,
  1032. 30, 2, 0, &emc_lock);
  1033. clk = tegra_clk_register_periph_gate("emc", "emc_mux", 0, clk_base, 0,
  1034. 57, periph_clk_enb_refcnt);
  1035. clks[TEGRA30_CLK_EMC] = clk;
  1036. clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
  1037. &emc_lock);
  1038. clks[TEGRA30_CLK_MC] = clk;
  1039. /* cml0 */
  1040. clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX,
  1041. 0, 0, &cml_lock);
  1042. clks[TEGRA30_CLK_CML0] = clk;
  1043. /* cml1 */
  1044. clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX,
  1045. 1, 0, &cml_lock);
  1046. clks[TEGRA30_CLK_CML1] = clk;
  1047. for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) {
  1048. data = &tegra_periph_clk_list[i];
  1049. clk = tegra_clk_register_periph(data->name, data->p.parent_names,
  1050. data->num_parents, &data->periph,
  1051. clk_base, data->offset, data->flags);
  1052. clks[data->clk_id] = clk;
  1053. }
  1054. for (i = 0; i < ARRAY_SIZE(tegra_periph_nodiv_clk_list); i++) {
  1055. data = &tegra_periph_nodiv_clk_list[i];
  1056. clk = tegra_clk_register_periph_nodiv(data->name,
  1057. data->p.parent_names,
  1058. data->num_parents, &data->periph,
  1059. clk_base, data->offset);
  1060. clks[data->clk_id] = clk;
  1061. }
  1062. tegra_periph_clk_init(clk_base, pmc_base, tegra30_clks, &pll_p_params);
  1063. }
  1064. /* Tegra30 CPU clock and reset control functions */
  1065. static void tegra30_wait_cpu_in_reset(u32 cpu)
  1066. {
  1067. unsigned int reg;
  1068. do {
  1069. reg = readl(clk_base +
  1070. TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS);
  1071. cpu_relax();
  1072. } while (!(reg & (1 << cpu))); /* check CPU been reset or not */
  1073. return;
  1074. }
  1075. static void tegra30_put_cpu_in_reset(u32 cpu)
  1076. {
  1077. writel(CPU_RESET(cpu),
  1078. clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
  1079. dmb();
  1080. }
  1081. static void tegra30_cpu_out_of_reset(u32 cpu)
  1082. {
  1083. writel(CPU_RESET(cpu),
  1084. clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
  1085. wmb();
  1086. }
  1087. static void tegra30_enable_cpu_clock(u32 cpu)
  1088. {
  1089. unsigned int reg;
  1090. writel(CPU_CLOCK(cpu),
  1091. clk_base + TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR);
  1092. reg = readl(clk_base +
  1093. TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR);
  1094. }
  1095. static void tegra30_disable_cpu_clock(u32 cpu)
  1096. {
  1097. unsigned int reg;
  1098. reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  1099. writel(reg | CPU_CLOCK(cpu),
  1100. clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  1101. }
  1102. #ifdef CONFIG_PM_SLEEP
  1103. static bool tegra30_cpu_rail_off_ready(void)
  1104. {
  1105. unsigned int cpu_rst_status;
  1106. int cpu_pwr_status;
  1107. cpu_rst_status = readl(clk_base +
  1108. TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS);
  1109. cpu_pwr_status = tegra_powergate_is_powered(TEGRA_POWERGATE_CPU1) ||
  1110. tegra_powergate_is_powered(TEGRA_POWERGATE_CPU2) ||
  1111. tegra_powergate_is_powered(TEGRA_POWERGATE_CPU3);
  1112. if (((cpu_rst_status & 0xE) != 0xE) || cpu_pwr_status)
  1113. return false;
  1114. return true;
  1115. }
  1116. static void tegra30_cpu_clock_suspend(void)
  1117. {
  1118. /* switch coresite to clk_m, save off original source */
  1119. tegra30_cpu_clk_sctx.clk_csite_src =
  1120. readl(clk_base + CLK_RESET_SOURCE_CSITE);
  1121. writel(3<<30, clk_base + CLK_RESET_SOURCE_CSITE);
  1122. tegra30_cpu_clk_sctx.cpu_burst =
  1123. readl(clk_base + CLK_RESET_CCLK_BURST);
  1124. tegra30_cpu_clk_sctx.pllx_base =
  1125. readl(clk_base + CLK_RESET_PLLX_BASE);
  1126. tegra30_cpu_clk_sctx.pllx_misc =
  1127. readl(clk_base + CLK_RESET_PLLX_MISC);
  1128. tegra30_cpu_clk_sctx.cclk_divider =
  1129. readl(clk_base + CLK_RESET_CCLK_DIVIDER);
  1130. }
  1131. static void tegra30_cpu_clock_resume(void)
  1132. {
  1133. unsigned int reg, policy;
  1134. /* Is CPU complex already running on PLLX? */
  1135. reg = readl(clk_base + CLK_RESET_CCLK_BURST);
  1136. policy = (reg >> CLK_RESET_CCLK_BURST_POLICY_SHIFT) & 0xF;
  1137. if (policy == CLK_RESET_CCLK_IDLE_POLICY)
  1138. reg = (reg >> CLK_RESET_CCLK_IDLE_POLICY_SHIFT) & 0xF;
  1139. else if (policy == CLK_RESET_CCLK_RUN_POLICY)
  1140. reg = (reg >> CLK_RESET_CCLK_RUN_POLICY_SHIFT) & 0xF;
  1141. else
  1142. BUG();
  1143. if (reg != CLK_RESET_CCLK_BURST_POLICY_PLLX) {
  1144. /* restore PLLX settings if CPU is on different PLL */
  1145. writel(tegra30_cpu_clk_sctx.pllx_misc,
  1146. clk_base + CLK_RESET_PLLX_MISC);
  1147. writel(tegra30_cpu_clk_sctx.pllx_base,
  1148. clk_base + CLK_RESET_PLLX_BASE);
  1149. /* wait for PLL stabilization if PLLX was enabled */
  1150. if (tegra30_cpu_clk_sctx.pllx_base & (1 << 30))
  1151. udelay(300);
  1152. }
  1153. /*
  1154. * Restore original burst policy setting for calls resulting from CPU
  1155. * LP2 in idle or system suspend.
  1156. */
  1157. writel(tegra30_cpu_clk_sctx.cclk_divider,
  1158. clk_base + CLK_RESET_CCLK_DIVIDER);
  1159. writel(tegra30_cpu_clk_sctx.cpu_burst,
  1160. clk_base + CLK_RESET_CCLK_BURST);
  1161. writel(tegra30_cpu_clk_sctx.clk_csite_src,
  1162. clk_base + CLK_RESET_SOURCE_CSITE);
  1163. }
  1164. #endif
  1165. static struct tegra_cpu_car_ops tegra30_cpu_car_ops = {
  1166. .wait_for_reset = tegra30_wait_cpu_in_reset,
  1167. .put_in_reset = tegra30_put_cpu_in_reset,
  1168. .out_of_reset = tegra30_cpu_out_of_reset,
  1169. .enable_clock = tegra30_enable_cpu_clock,
  1170. .disable_clock = tegra30_disable_cpu_clock,
  1171. #ifdef CONFIG_PM_SLEEP
  1172. .rail_off_ready = tegra30_cpu_rail_off_ready,
  1173. .suspend = tegra30_cpu_clock_suspend,
  1174. .resume = tegra30_cpu_clock_resume,
  1175. #endif
  1176. };
  1177. static struct tegra_clk_init_table init_table[] __initdata = {
  1178. {TEGRA30_CLK_UARTA, TEGRA30_CLK_PLL_P, 408000000, 0},
  1179. {TEGRA30_CLK_UARTB, TEGRA30_CLK_PLL_P, 408000000, 0},
  1180. {TEGRA30_CLK_UARTC, TEGRA30_CLK_PLL_P, 408000000, 0},
  1181. {TEGRA30_CLK_UARTD, TEGRA30_CLK_PLL_P, 408000000, 0},
  1182. {TEGRA30_CLK_UARTE, TEGRA30_CLK_PLL_P, 408000000, 0},
  1183. {TEGRA30_CLK_PLL_A, TEGRA30_CLK_CLK_MAX, 564480000, 1},
  1184. {TEGRA30_CLK_PLL_A_OUT0, TEGRA30_CLK_CLK_MAX, 11289600, 1},
  1185. {TEGRA30_CLK_EXTERN1, TEGRA30_CLK_PLL_A_OUT0, 0, 1},
  1186. {TEGRA30_CLK_CLK_OUT_1_MUX, TEGRA30_CLK_EXTERN1, 0, 0},
  1187. {TEGRA30_CLK_CLK_OUT_1, TEGRA30_CLK_CLK_MAX, 0, 1},
  1188. {TEGRA30_CLK_BLINK, TEGRA30_CLK_CLK_MAX, 0, 1},
  1189. {TEGRA30_CLK_I2S0, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0},
  1190. {TEGRA30_CLK_I2S1, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0},
  1191. {TEGRA30_CLK_I2S2, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0},
  1192. {TEGRA30_CLK_I2S3, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0},
  1193. {TEGRA30_CLK_I2S4, TEGRA30_CLK_PLL_A_OUT0, 11289600, 0},
  1194. {TEGRA30_CLK_SDMMC1, TEGRA30_CLK_PLL_P, 48000000, 0},
  1195. {TEGRA30_CLK_SDMMC2, TEGRA30_CLK_PLL_P, 48000000, 0},
  1196. {TEGRA30_CLK_SDMMC3, TEGRA30_CLK_PLL_P, 48000000, 0},
  1197. {TEGRA30_CLK_PLL_M, TEGRA30_CLK_CLK_MAX, 0, 1},
  1198. {TEGRA30_CLK_PCLK, TEGRA30_CLK_CLK_MAX, 0, 1},
  1199. {TEGRA30_CLK_CSITE, TEGRA30_CLK_CLK_MAX, 0, 1},
  1200. {TEGRA30_CLK_EMC, TEGRA30_CLK_CLK_MAX, 0, 1},
  1201. {TEGRA30_CLK_MSELECT, TEGRA30_CLK_CLK_MAX, 0, 1},
  1202. {TEGRA30_CLK_SBC1, TEGRA30_CLK_PLL_P, 100000000, 0},
  1203. {TEGRA30_CLK_SBC2, TEGRA30_CLK_PLL_P, 100000000, 0},
  1204. {TEGRA30_CLK_SBC3, TEGRA30_CLK_PLL_P, 100000000, 0},
  1205. {TEGRA30_CLK_SBC4, TEGRA30_CLK_PLL_P, 100000000, 0},
  1206. {TEGRA30_CLK_SBC5, TEGRA30_CLK_PLL_P, 100000000, 0},
  1207. {TEGRA30_CLK_SBC6, TEGRA30_CLK_PLL_P, 100000000, 0},
  1208. {TEGRA30_CLK_HOST1X, TEGRA30_CLK_PLL_C, 150000000, 0},
  1209. {TEGRA30_CLK_DISP1, TEGRA30_CLK_PLL_P, 600000000, 0},
  1210. {TEGRA30_CLK_DISP2, TEGRA30_CLK_PLL_P, 600000000, 0},
  1211. {TEGRA30_CLK_TWD, TEGRA30_CLK_CLK_MAX, 0, 1},
  1212. {TEGRA30_CLK_GR2D, TEGRA30_CLK_PLL_C, 300000000, 0},
  1213. {TEGRA30_CLK_GR3D, TEGRA30_CLK_PLL_C, 300000000, 0},
  1214. {TEGRA30_CLK_GR3D2, TEGRA30_CLK_PLL_C, 300000000, 0},
  1215. { TEGRA30_CLK_PLL_U, TEGRA30_CLK_CLK_MAX, 480000000, 0 },
  1216. {TEGRA30_CLK_CLK_MAX, TEGRA30_CLK_CLK_MAX, 0, 0}, /* This MUST be the last entry. */
  1217. };
  1218. static void __init tegra30_clock_apply_init_table(void)
  1219. {
  1220. tegra_init_from_table(init_table, clks, TEGRA30_CLK_CLK_MAX);
  1221. }
  1222. /*
  1223. * Some clocks may be used by different drivers depending on the board
  1224. * configuration. List those here to register them twice in the clock lookup
  1225. * table under two names.
  1226. */
  1227. static struct tegra_clk_duplicate tegra_clk_duplicates[] = {
  1228. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_USBD, "utmip-pad", NULL),
  1229. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_USBD, "tegra-ehci.0", NULL),
  1230. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_USBD, "tegra-otg", NULL),
  1231. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEV, "tegra-avp", "bsev"),
  1232. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEV, "nvavp", "bsev"),
  1233. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_VDE, "tegra-aes", "vde"),
  1234. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEA, "tegra-aes", "bsea"),
  1235. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_BSEA, "nvavp", "bsea"),
  1236. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_CML1, "tegra_sata_cml", NULL),
  1237. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_CML0, "tegra_pcie", "cml"),
  1238. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_VCP, "nvavp", "vcp"),
  1239. TEGRA_CLK_DUPLICATE(TEGRA30_CLK_CLK_MAX, NULL, NULL), /* MUST be the last entry */
  1240. };
  1241. static const struct of_device_id pmc_match[] __initconst = {
  1242. { .compatible = "nvidia,tegra30-pmc" },
  1243. {},
  1244. };
  1245. static struct tegra_audio_clk_info tegra30_audio_plls[] = {
  1246. { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_p_out1" },
  1247. };
  1248. static void __init tegra30_clock_init(struct device_node *np)
  1249. {
  1250. struct device_node *node;
  1251. clk_base = of_iomap(np, 0);
  1252. if (!clk_base) {
  1253. pr_err("ioremap tegra30 CAR failed\n");
  1254. return;
  1255. }
  1256. node = of_find_matching_node(NULL, pmc_match);
  1257. if (!node) {
  1258. pr_err("Failed to find pmc node\n");
  1259. BUG();
  1260. }
  1261. pmc_base = of_iomap(node, 0);
  1262. if (!pmc_base) {
  1263. pr_err("Can't map pmc registers\n");
  1264. BUG();
  1265. }
  1266. clks = tegra_clk_init(clk_base, TEGRA30_CLK_CLK_MAX,
  1267. TEGRA30_CLK_PERIPH_BANKS);
  1268. if (!clks)
  1269. return;
  1270. if (tegra_osc_clk_init(clk_base, tegra30_clks, tegra30_input_freq,
  1271. ARRAY_SIZE(tegra30_input_freq), 1, &input_freq,
  1272. NULL) < 0)
  1273. return;
  1274. tegra_fixed_clk_init(tegra30_clks);
  1275. tegra30_pll_init();
  1276. tegra30_super_clk_init();
  1277. tegra30_periph_clk_init();
  1278. tegra_audio_clk_init(clk_base, pmc_base, tegra30_clks,
  1279. tegra30_audio_plls,
  1280. ARRAY_SIZE(tegra30_audio_plls));
  1281. tegra_pmc_clk_init(pmc_base, tegra30_clks);
  1282. tegra_init_dup_clks(tegra_clk_duplicates, clks, TEGRA30_CLK_CLK_MAX);
  1283. tegra_add_of_provider(np);
  1284. tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
  1285. tegra_clk_apply_init_table = tegra30_clock_apply_init_table;
  1286. tegra_cpu_car_ops = &tegra30_cpu_car_ops;
  1287. }
  1288. CLK_OF_DECLARE(tegra30, "nvidia,tegra30-car", tegra30_clock_init);