clk-tegra20.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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/clk.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 <linux/delay.h>
  24. #include <dt-bindings/clock/tegra20-car.h>
  25. #include "clk.h"
  26. #include "clk-id.h"
  27. #define OSC_CTRL 0x50
  28. #define OSC_CTRL_OSC_FREQ_MASK (3<<30)
  29. #define OSC_CTRL_OSC_FREQ_13MHZ (0<<30)
  30. #define OSC_CTRL_OSC_FREQ_19_2MHZ (1<<30)
  31. #define OSC_CTRL_OSC_FREQ_12MHZ (2<<30)
  32. #define OSC_CTRL_OSC_FREQ_26MHZ (3<<30)
  33. #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK)
  34. #define OSC_CTRL_PLL_REF_DIV_MASK (3<<28)
  35. #define OSC_CTRL_PLL_REF_DIV_1 (0<<28)
  36. #define OSC_CTRL_PLL_REF_DIV_2 (1<<28)
  37. #define OSC_CTRL_PLL_REF_DIV_4 (2<<28)
  38. #define OSC_FREQ_DET 0x58
  39. #define OSC_FREQ_DET_TRIG (1<<31)
  40. #define OSC_FREQ_DET_STATUS 0x5c
  41. #define OSC_FREQ_DET_BUSY (1<<31)
  42. #define OSC_FREQ_DET_CNT_MASK 0xFFFF
  43. #define TEGRA20_CLK_PERIPH_BANKS 3
  44. #define PLLS_BASE 0xf0
  45. #define PLLS_MISC 0xf4
  46. #define PLLC_BASE 0x80
  47. #define PLLC_MISC 0x8c
  48. #define PLLM_BASE 0x90
  49. #define PLLM_MISC 0x9c
  50. #define PLLP_BASE 0xa0
  51. #define PLLP_MISC 0xac
  52. #define PLLA_BASE 0xb0
  53. #define PLLA_MISC 0xbc
  54. #define PLLU_BASE 0xc0
  55. #define PLLU_MISC 0xcc
  56. #define PLLD_BASE 0xd0
  57. #define PLLD_MISC 0xdc
  58. #define PLLX_BASE 0xe0
  59. #define PLLX_MISC 0xe4
  60. #define PLLE_BASE 0xe8
  61. #define PLLE_MISC 0xec
  62. #define PLL_BASE_LOCK BIT(27)
  63. #define PLLE_MISC_LOCK BIT(11)
  64. #define PLL_MISC_LOCK_ENABLE 18
  65. #define PLLDU_MISC_LOCK_ENABLE 22
  66. #define PLLE_MISC_LOCK_ENABLE 9
  67. #define PLLC_OUT 0x84
  68. #define PLLM_OUT 0x94
  69. #define PLLP_OUTA 0xa4
  70. #define PLLP_OUTB 0xa8
  71. #define PLLA_OUT 0xb4
  72. #define CCLK_BURST_POLICY 0x20
  73. #define SUPER_CCLK_DIVIDER 0x24
  74. #define SCLK_BURST_POLICY 0x28
  75. #define SUPER_SCLK_DIVIDER 0x2c
  76. #define CLK_SYSTEM_RATE 0x30
  77. #define CCLK_BURST_POLICY_SHIFT 28
  78. #define CCLK_RUN_POLICY_SHIFT 4
  79. #define CCLK_IDLE_POLICY_SHIFT 0
  80. #define CCLK_IDLE_POLICY 1
  81. #define CCLK_RUN_POLICY 2
  82. #define CCLK_BURST_POLICY_PLLX 8
  83. #define CLK_SOURCE_I2S1 0x100
  84. #define CLK_SOURCE_I2S2 0x104
  85. #define CLK_SOURCE_PWM 0x110
  86. #define CLK_SOURCE_SPI 0x114
  87. #define CLK_SOURCE_XIO 0x120
  88. #define CLK_SOURCE_TWC 0x12c
  89. #define CLK_SOURCE_IDE 0x144
  90. #define CLK_SOURCE_HDMI 0x18c
  91. #define CLK_SOURCE_DISP1 0x138
  92. #define CLK_SOURCE_DISP2 0x13c
  93. #define CLK_SOURCE_CSITE 0x1d4
  94. #define CLK_SOURCE_I2C1 0x124
  95. #define CLK_SOURCE_I2C2 0x198
  96. #define CLK_SOURCE_I2C3 0x1b8
  97. #define CLK_SOURCE_DVC 0x128
  98. #define CLK_SOURCE_UARTA 0x178
  99. #define CLK_SOURCE_UARTB 0x17c
  100. #define CLK_SOURCE_UARTC 0x1a0
  101. #define CLK_SOURCE_UARTD 0x1c0
  102. #define CLK_SOURCE_UARTE 0x1c4
  103. #define CLK_SOURCE_EMC 0x19c
  104. #define AUDIO_SYNC_CLK 0x38
  105. /* Tegra CPU clock and reset control regs */
  106. #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c
  107. #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340
  108. #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344
  109. #define CPU_CLOCK(cpu) (0x1 << (8 + cpu))
  110. #define CPU_RESET(cpu) (0x1111ul << (cpu))
  111. #ifdef CONFIG_PM_SLEEP
  112. static struct cpu_clk_suspend_context {
  113. u32 pllx_misc;
  114. u32 pllx_base;
  115. u32 cpu_burst;
  116. u32 clk_csite_src;
  117. u32 cclk_divider;
  118. } tegra20_cpu_clk_sctx;
  119. #endif
  120. static void __iomem *clk_base;
  121. static void __iomem *pmc_base;
  122. #define TEGRA_INIT_DATA_MUX(_name, _parents, _offset, \
  123. _clk_num, _gate_flags, _clk_id) \
  124. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  125. 30, 2, 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, \
  126. _clk_num, \
  127. _gate_flags, _clk_id)
  128. #define TEGRA_INIT_DATA_DIV16(_name, _parents, _offset, \
  129. _clk_num, _gate_flags, _clk_id) \
  130. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  131. 30, 2, 0, 0, 16, 0, TEGRA_DIVIDER_ROUND_UP, \
  132. _clk_num, _gate_flags, \
  133. _clk_id)
  134. #define TEGRA_INIT_DATA_NODIV(_name, _parents, _offset, \
  135. _mux_shift, _mux_width, _clk_num, \
  136. _gate_flags, _clk_id) \
  137. TEGRA_INIT_DATA(_name, NULL, NULL, _parents, _offset, \
  138. _mux_shift, _mux_width, 0, 0, 0, 0, 0, \
  139. _clk_num, _gate_flags, \
  140. _clk_id)
  141. static struct clk **clks;
  142. static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
  143. { 12000000, 600000000, 600, 12, 0, 8 },
  144. { 13000000, 600000000, 600, 13, 0, 8 },
  145. { 19200000, 600000000, 500, 16, 0, 6 },
  146. { 26000000, 600000000, 600, 26, 0, 8 },
  147. { 0, 0, 0, 0, 0, 0 },
  148. };
  149. static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
  150. { 12000000, 666000000, 666, 12, 0, 8},
  151. { 13000000, 666000000, 666, 13, 0, 8},
  152. { 19200000, 666000000, 555, 16, 0, 8},
  153. { 26000000, 666000000, 666, 26, 0, 8},
  154. { 12000000, 600000000, 600, 12, 0, 8},
  155. { 13000000, 600000000, 600, 13, 0, 8},
  156. { 19200000, 600000000, 375, 12, 0, 6},
  157. { 26000000, 600000000, 600, 26, 0, 8},
  158. { 0, 0, 0, 0, 0, 0 },
  159. };
  160. static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
  161. { 12000000, 216000000, 432, 12, 1, 8},
  162. { 13000000, 216000000, 432, 13, 1, 8},
  163. { 19200000, 216000000, 90, 4, 1, 1},
  164. { 26000000, 216000000, 432, 26, 1, 8},
  165. { 12000000, 432000000, 432, 12, 0, 8},
  166. { 13000000, 432000000, 432, 13, 0, 8},
  167. { 19200000, 432000000, 90, 4, 0, 1},
  168. { 26000000, 432000000, 432, 26, 0, 8},
  169. { 0, 0, 0, 0, 0, 0 },
  170. };
  171. static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
  172. { 28800000, 56448000, 49, 25, 0, 1},
  173. { 28800000, 73728000, 64, 25, 0, 1},
  174. { 28800000, 24000000, 5, 6, 0, 1},
  175. { 0, 0, 0, 0, 0, 0 },
  176. };
  177. static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
  178. { 12000000, 216000000, 216, 12, 0, 4},
  179. { 13000000, 216000000, 216, 13, 0, 4},
  180. { 19200000, 216000000, 135, 12, 0, 3},
  181. { 26000000, 216000000, 216, 26, 0, 4},
  182. { 12000000, 594000000, 594, 12, 0, 8},
  183. { 13000000, 594000000, 594, 13, 0, 8},
  184. { 19200000, 594000000, 495, 16, 0, 8},
  185. { 26000000, 594000000, 594, 26, 0, 8},
  186. { 12000000, 1000000000, 1000, 12, 0, 12},
  187. { 13000000, 1000000000, 1000, 13, 0, 12},
  188. { 19200000, 1000000000, 625, 12, 0, 8},
  189. { 26000000, 1000000000, 1000, 26, 0, 12},
  190. { 0, 0, 0, 0, 0, 0 },
  191. };
  192. static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
  193. { 12000000, 480000000, 960, 12, 0, 0},
  194. { 13000000, 480000000, 960, 13, 0, 0},
  195. { 19200000, 480000000, 200, 4, 0, 0},
  196. { 26000000, 480000000, 960, 26, 0, 0},
  197. { 0, 0, 0, 0, 0, 0 },
  198. };
  199. static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
  200. /* 1 GHz */
  201. { 12000000, 1000000000, 1000, 12, 0, 12},
  202. { 13000000, 1000000000, 1000, 13, 0, 12},
  203. { 19200000, 1000000000, 625, 12, 0, 8},
  204. { 26000000, 1000000000, 1000, 26, 0, 12},
  205. /* 912 MHz */
  206. { 12000000, 912000000, 912, 12, 0, 12},
  207. { 13000000, 912000000, 912, 13, 0, 12},
  208. { 19200000, 912000000, 760, 16, 0, 8},
  209. { 26000000, 912000000, 912, 26, 0, 12},
  210. /* 816 MHz */
  211. { 12000000, 816000000, 816, 12, 0, 12},
  212. { 13000000, 816000000, 816, 13, 0, 12},
  213. { 19200000, 816000000, 680, 16, 0, 8},
  214. { 26000000, 816000000, 816, 26, 0, 12},
  215. /* 760 MHz */
  216. { 12000000, 760000000, 760, 12, 0, 12},
  217. { 13000000, 760000000, 760, 13, 0, 12},
  218. { 19200000, 760000000, 950, 24, 0, 8},
  219. { 26000000, 760000000, 760, 26, 0, 12},
  220. /* 750 MHz */
  221. { 12000000, 750000000, 750, 12, 0, 12},
  222. { 13000000, 750000000, 750, 13, 0, 12},
  223. { 19200000, 750000000, 625, 16, 0, 8},
  224. { 26000000, 750000000, 750, 26, 0, 12},
  225. /* 608 MHz */
  226. { 12000000, 608000000, 608, 12, 0, 12},
  227. { 13000000, 608000000, 608, 13, 0, 12},
  228. { 19200000, 608000000, 380, 12, 0, 8},
  229. { 26000000, 608000000, 608, 26, 0, 12},
  230. /* 456 MHz */
  231. { 12000000, 456000000, 456, 12, 0, 12},
  232. { 13000000, 456000000, 456, 13, 0, 12},
  233. { 19200000, 456000000, 380, 16, 0, 8},
  234. { 26000000, 456000000, 456, 26, 0, 12},
  235. /* 312 MHz */
  236. { 12000000, 312000000, 312, 12, 0, 12},
  237. { 13000000, 312000000, 312, 13, 0, 12},
  238. { 19200000, 312000000, 260, 16, 0, 8},
  239. { 26000000, 312000000, 312, 26, 0, 12},
  240. { 0, 0, 0, 0, 0, 0 },
  241. };
  242. static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
  243. { 12000000, 100000000, 200, 24, 0, 0 },
  244. { 0, 0, 0, 0, 0, 0 },
  245. };
  246. /* PLL parameters */
  247. static struct tegra_clk_pll_params pll_c_params = {
  248. .input_min = 2000000,
  249. .input_max = 31000000,
  250. .cf_min = 1000000,
  251. .cf_max = 6000000,
  252. .vco_min = 20000000,
  253. .vco_max = 1400000000,
  254. .base_reg = PLLC_BASE,
  255. .misc_reg = PLLC_MISC,
  256. .lock_mask = PLL_BASE_LOCK,
  257. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  258. .lock_delay = 300,
  259. .freq_table = pll_c_freq_table,
  260. .flags = TEGRA_PLL_HAS_CPCON,
  261. };
  262. static struct tegra_clk_pll_params pll_m_params = {
  263. .input_min = 2000000,
  264. .input_max = 31000000,
  265. .cf_min = 1000000,
  266. .cf_max = 6000000,
  267. .vco_min = 20000000,
  268. .vco_max = 1200000000,
  269. .base_reg = PLLM_BASE,
  270. .misc_reg = PLLM_MISC,
  271. .lock_mask = PLL_BASE_LOCK,
  272. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  273. .lock_delay = 300,
  274. .freq_table = pll_m_freq_table,
  275. .flags = TEGRA_PLL_HAS_CPCON,
  276. };
  277. static struct tegra_clk_pll_params pll_p_params = {
  278. .input_min = 2000000,
  279. .input_max = 31000000,
  280. .cf_min = 1000000,
  281. .cf_max = 6000000,
  282. .vco_min = 20000000,
  283. .vco_max = 1400000000,
  284. .base_reg = PLLP_BASE,
  285. .misc_reg = PLLP_MISC,
  286. .lock_mask = PLL_BASE_LOCK,
  287. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  288. .lock_delay = 300,
  289. .freq_table = pll_p_freq_table,
  290. .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_CPCON,
  291. .fixed_rate = 216000000,
  292. };
  293. static struct tegra_clk_pll_params pll_a_params = {
  294. .input_min = 2000000,
  295. .input_max = 31000000,
  296. .cf_min = 1000000,
  297. .cf_max = 6000000,
  298. .vco_min = 20000000,
  299. .vco_max = 1400000000,
  300. .base_reg = PLLA_BASE,
  301. .misc_reg = PLLA_MISC,
  302. .lock_mask = PLL_BASE_LOCK,
  303. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  304. .lock_delay = 300,
  305. .freq_table = pll_a_freq_table,
  306. .flags = TEGRA_PLL_HAS_CPCON,
  307. };
  308. static struct tegra_clk_pll_params pll_d_params = {
  309. .input_min = 2000000,
  310. .input_max = 40000000,
  311. .cf_min = 1000000,
  312. .cf_max = 6000000,
  313. .vco_min = 40000000,
  314. .vco_max = 1000000000,
  315. .base_reg = PLLD_BASE,
  316. .misc_reg = PLLD_MISC,
  317. .lock_mask = PLL_BASE_LOCK,
  318. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  319. .lock_delay = 1000,
  320. .freq_table = pll_d_freq_table,
  321. .flags = TEGRA_PLL_HAS_CPCON,
  322. };
  323. static struct pdiv_map pllu_p[] = {
  324. { .pdiv = 1, .hw_val = 1 },
  325. { .pdiv = 2, .hw_val = 0 },
  326. { .pdiv = 0, .hw_val = 0 },
  327. };
  328. static struct tegra_clk_pll_params pll_u_params = {
  329. .input_min = 2000000,
  330. .input_max = 40000000,
  331. .cf_min = 1000000,
  332. .cf_max = 6000000,
  333. .vco_min = 48000000,
  334. .vco_max = 960000000,
  335. .base_reg = PLLU_BASE,
  336. .misc_reg = PLLU_MISC,
  337. .lock_mask = PLL_BASE_LOCK,
  338. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  339. .lock_delay = 1000,
  340. .pdiv_tohw = pllu_p,
  341. .freq_table = pll_u_freq_table,
  342. .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON,
  343. };
  344. static struct tegra_clk_pll_params pll_x_params = {
  345. .input_min = 2000000,
  346. .input_max = 31000000,
  347. .cf_min = 1000000,
  348. .cf_max = 6000000,
  349. .vco_min = 20000000,
  350. .vco_max = 1200000000,
  351. .base_reg = PLLX_BASE,
  352. .misc_reg = PLLX_MISC,
  353. .lock_mask = PLL_BASE_LOCK,
  354. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  355. .lock_delay = 300,
  356. .freq_table = pll_x_freq_table,
  357. .flags = TEGRA_PLL_HAS_CPCON,
  358. };
  359. static struct tegra_clk_pll_params pll_e_params = {
  360. .input_min = 12000000,
  361. .input_max = 12000000,
  362. .cf_min = 0,
  363. .cf_max = 0,
  364. .vco_min = 0,
  365. .vco_max = 0,
  366. .base_reg = PLLE_BASE,
  367. .misc_reg = PLLE_MISC,
  368. .lock_mask = PLLE_MISC_LOCK,
  369. .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
  370. .lock_delay = 0,
  371. .freq_table = pll_e_freq_table,
  372. .flags = TEGRA_PLL_FIXED,
  373. .fixed_rate = 100000000,
  374. };
  375. static struct tegra_devclk devclks[] __initdata = {
  376. { .con_id = "pll_c", .dt_id = TEGRA20_CLK_PLL_C },
  377. { .con_id = "pll_c_out1", .dt_id = TEGRA20_CLK_PLL_C_OUT1 },
  378. { .con_id = "pll_p", .dt_id = TEGRA20_CLK_PLL_P },
  379. { .con_id = "pll_p_out1", .dt_id = TEGRA20_CLK_PLL_P_OUT1 },
  380. { .con_id = "pll_p_out2", .dt_id = TEGRA20_CLK_PLL_P_OUT2 },
  381. { .con_id = "pll_p_out3", .dt_id = TEGRA20_CLK_PLL_P_OUT3 },
  382. { .con_id = "pll_p_out4", .dt_id = TEGRA20_CLK_PLL_P_OUT4 },
  383. { .con_id = "pll_m", .dt_id = TEGRA20_CLK_PLL_M },
  384. { .con_id = "pll_m_out1", .dt_id = TEGRA20_CLK_PLL_M_OUT1 },
  385. { .con_id = "pll_x", .dt_id = TEGRA20_CLK_PLL_X },
  386. { .con_id = "pll_u", .dt_id = TEGRA20_CLK_PLL_U },
  387. { .con_id = "pll_d", .dt_id = TEGRA20_CLK_PLL_D },
  388. { .con_id = "pll_d_out0", .dt_id = TEGRA20_CLK_PLL_D_OUT0 },
  389. { .con_id = "pll_a", .dt_id = TEGRA20_CLK_PLL_A },
  390. { .con_id = "pll_a_out0", .dt_id = TEGRA20_CLK_PLL_A_OUT0 },
  391. { .con_id = "pll_e", .dt_id = TEGRA20_CLK_PLL_E },
  392. { .con_id = "cclk", .dt_id = TEGRA20_CLK_CCLK },
  393. { .con_id = "sclk", .dt_id = TEGRA20_CLK_SCLK },
  394. { .con_id = "hclk", .dt_id = TEGRA20_CLK_HCLK },
  395. { .con_id = "pclk", .dt_id = TEGRA20_CLK_PCLK },
  396. { .con_id = "fuse", .dt_id = TEGRA20_CLK_FUSE },
  397. { .con_id = "twd", .dt_id = TEGRA20_CLK_TWD },
  398. { .con_id = "audio", .dt_id = TEGRA20_CLK_AUDIO },
  399. { .con_id = "audio_2x", .dt_id = TEGRA20_CLK_AUDIO_2X },
  400. { .dev_id = "tegra20-ac97", .dt_id = TEGRA20_CLK_AC97 },
  401. { .dev_id = "tegra-apbdma", .dt_id = TEGRA20_CLK_APBDMA },
  402. { .dev_id = "rtc-tegra", .dt_id = TEGRA20_CLK_RTC },
  403. { .dev_id = "timer", .dt_id = TEGRA20_CLK_TIMER },
  404. { .dev_id = "tegra-kbc", .dt_id = TEGRA20_CLK_KBC },
  405. { .con_id = "csus", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_CSUS },
  406. { .con_id = "vcp", .dev_id = "tegra-avp", .dt_id = TEGRA20_CLK_VCP },
  407. { .con_id = "bsea", .dev_id = "tegra-avp", .dt_id = TEGRA20_CLK_BSEA },
  408. { .con_id = "bsev", .dev_id = "tegra-aes", .dt_id = TEGRA20_CLK_BSEV },
  409. { .con_id = "emc", .dt_id = TEGRA20_CLK_EMC },
  410. { .dev_id = "fsl-tegra-udc", .dt_id = TEGRA20_CLK_USBD },
  411. { .dev_id = "tegra-ehci.1", .dt_id = TEGRA20_CLK_USB2 },
  412. { .dev_id = "tegra-ehci.2", .dt_id = TEGRA20_CLK_USB3 },
  413. { .dev_id = "dsi", .dt_id = TEGRA20_CLK_DSI },
  414. { .con_id = "csi", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_CSI },
  415. { .con_id = "isp", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_ISP },
  416. { .con_id = "pex", .dt_id = TEGRA20_CLK_PEX },
  417. { .con_id = "afi", .dt_id = TEGRA20_CLK_AFI },
  418. { .con_id = "cdev1", .dt_id = TEGRA20_CLK_CDEV1 },
  419. { .con_id = "cdev2", .dt_id = TEGRA20_CLK_CDEV2 },
  420. { .con_id = "clk_32k", .dt_id = TEGRA20_CLK_CLK_32K },
  421. { .con_id = "blink", .dt_id = TEGRA20_CLK_BLINK },
  422. { .con_id = "clk_m", .dt_id = TEGRA20_CLK_CLK_M },
  423. { .con_id = "pll_ref", .dt_id = TEGRA20_CLK_PLL_REF },
  424. { .dev_id = "tegra20-i2s.0", .dt_id = TEGRA20_CLK_I2S1 },
  425. { .dev_id = "tegra20-i2s.1", .dt_id = TEGRA20_CLK_I2S2 },
  426. { .con_id = "spdif_out", .dev_id = "tegra20-spdif", .dt_id = TEGRA20_CLK_SPDIF_OUT },
  427. { .con_id = "spdif_in", .dev_id = "tegra20-spdif", .dt_id = TEGRA20_CLK_SPDIF_IN },
  428. { .dev_id = "spi_tegra.0", .dt_id = TEGRA20_CLK_SBC1 },
  429. { .dev_id = "spi_tegra.1", .dt_id = TEGRA20_CLK_SBC2 },
  430. { .dev_id = "spi_tegra.2", .dt_id = TEGRA20_CLK_SBC3 },
  431. { .dev_id = "spi_tegra.3", .dt_id = TEGRA20_CLK_SBC4 },
  432. { .dev_id = "spi", .dt_id = TEGRA20_CLK_SPI },
  433. { .dev_id = "xio", .dt_id = TEGRA20_CLK_XIO },
  434. { .dev_id = "twc", .dt_id = TEGRA20_CLK_TWC },
  435. { .dev_id = "ide", .dt_id = TEGRA20_CLK_IDE },
  436. { .dev_id = "tegra_nand", .dt_id = TEGRA20_CLK_NDFLASH },
  437. { .dev_id = "vfir", .dt_id = TEGRA20_CLK_VFIR },
  438. { .dev_id = "csite", .dt_id = TEGRA20_CLK_CSITE },
  439. { .dev_id = "la", .dt_id = TEGRA20_CLK_LA },
  440. { .dev_id = "tegra_w1", .dt_id = TEGRA20_CLK_OWR },
  441. { .dev_id = "mipi", .dt_id = TEGRA20_CLK_MIPI },
  442. { .dev_id = "vde", .dt_id = TEGRA20_CLK_VDE },
  443. { .con_id = "vi", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_VI },
  444. { .dev_id = "epp", .dt_id = TEGRA20_CLK_EPP },
  445. { .dev_id = "mpe", .dt_id = TEGRA20_CLK_MPE },
  446. { .dev_id = "host1x", .dt_id = TEGRA20_CLK_HOST1X },
  447. { .dev_id = "3d", .dt_id = TEGRA20_CLK_GR3D },
  448. { .dev_id = "2d", .dt_id = TEGRA20_CLK_GR2D },
  449. { .dev_id = "tegra-nor", .dt_id = TEGRA20_CLK_NOR },
  450. { .dev_id = "sdhci-tegra.0", .dt_id = TEGRA20_CLK_SDMMC1 },
  451. { .dev_id = "sdhci-tegra.1", .dt_id = TEGRA20_CLK_SDMMC2 },
  452. { .dev_id = "sdhci-tegra.2", .dt_id = TEGRA20_CLK_SDMMC3 },
  453. { .dev_id = "sdhci-tegra.3", .dt_id = TEGRA20_CLK_SDMMC4 },
  454. { .dev_id = "cve", .dt_id = TEGRA20_CLK_CVE },
  455. { .dev_id = "tvo", .dt_id = TEGRA20_CLK_TVO },
  456. { .dev_id = "tvdac", .dt_id = TEGRA20_CLK_TVDAC },
  457. { .con_id = "vi_sensor", .dev_id = "tegra_camera", .dt_id = TEGRA20_CLK_VI_SENSOR },
  458. { .dev_id = "hdmi", .dt_id = TEGRA20_CLK_HDMI },
  459. { .con_id = "div-clk", .dev_id = "tegra-i2c.0", .dt_id = TEGRA20_CLK_I2C1 },
  460. { .con_id = "div-clk", .dev_id = "tegra-i2c.1", .dt_id = TEGRA20_CLK_I2C2 },
  461. { .con_id = "div-clk", .dev_id = "tegra-i2c.2", .dt_id = TEGRA20_CLK_I2C3 },
  462. { .con_id = "div-clk", .dev_id = "tegra-i2c.3", .dt_id = TEGRA20_CLK_DVC },
  463. { .dev_id = "tegra-pwm", .dt_id = TEGRA20_CLK_PWM },
  464. { .dev_id = "tegra_uart.0", .dt_id = TEGRA20_CLK_UARTA },
  465. { .dev_id = "tegra_uart.1", .dt_id = TEGRA20_CLK_UARTB },
  466. { .dev_id = "tegra_uart.2", .dt_id = TEGRA20_CLK_UARTC },
  467. { .dev_id = "tegra_uart.3", .dt_id = TEGRA20_CLK_UARTD },
  468. { .dev_id = "tegra_uart.4", .dt_id = TEGRA20_CLK_UARTE },
  469. { .dev_id = "tegradc.0", .dt_id = TEGRA20_CLK_DISP1 },
  470. { .dev_id = "tegradc.1", .dt_id = TEGRA20_CLK_DISP2 },
  471. };
  472. static struct tegra_clk tegra20_clks[tegra_clk_max] __initdata = {
  473. [tegra_clk_spdif_out] = { .dt_id = TEGRA20_CLK_SPDIF_OUT, .present = true },
  474. [tegra_clk_spdif_in] = { .dt_id = TEGRA20_CLK_SPDIF_IN, .present = true },
  475. [tegra_clk_sdmmc1] = { .dt_id = TEGRA20_CLK_SDMMC1, .present = true },
  476. [tegra_clk_sdmmc2] = { .dt_id = TEGRA20_CLK_SDMMC2, .present = true },
  477. [tegra_clk_sdmmc3] = { .dt_id = TEGRA20_CLK_SDMMC3, .present = true },
  478. [tegra_clk_sdmmc4] = { .dt_id = TEGRA20_CLK_SDMMC4, .present = true },
  479. [tegra_clk_la] = { .dt_id = TEGRA20_CLK_LA, .present = true },
  480. [tegra_clk_csite] = { .dt_id = TEGRA20_CLK_CSITE, .present = true },
  481. [tegra_clk_vfir] = { .dt_id = TEGRA20_CLK_VFIR, .present = true },
  482. [tegra_clk_mipi] = { .dt_id = TEGRA20_CLK_MIPI, .present = true },
  483. [tegra_clk_nor] = { .dt_id = TEGRA20_CLK_NOR, .present = true },
  484. [tegra_clk_rtc] = { .dt_id = TEGRA20_CLK_RTC, .present = true },
  485. [tegra_clk_timer] = { .dt_id = TEGRA20_CLK_TIMER, .present = true },
  486. [tegra_clk_kbc] = { .dt_id = TEGRA20_CLK_KBC, .present = true },
  487. [tegra_clk_csus] = { .dt_id = TEGRA20_CLK_CSUS, .present = true },
  488. [tegra_clk_vcp] = { .dt_id = TEGRA20_CLK_VCP, .present = true },
  489. [tegra_clk_bsea] = { .dt_id = TEGRA20_CLK_BSEA, .present = true },
  490. [tegra_clk_bsev] = { .dt_id = TEGRA20_CLK_BSEV, .present = true },
  491. [tegra_clk_usbd] = { .dt_id = TEGRA20_CLK_USBD, .present = true },
  492. [tegra_clk_usb2] = { .dt_id = TEGRA20_CLK_USB2, .present = true },
  493. [tegra_clk_usb3] = { .dt_id = TEGRA20_CLK_USB3, .present = true },
  494. [tegra_clk_csi] = { .dt_id = TEGRA20_CLK_CSI, .present = true },
  495. [tegra_clk_isp] = { .dt_id = TEGRA20_CLK_ISP, .present = true },
  496. [tegra_clk_clk_32k] = { .dt_id = TEGRA20_CLK_CLK_32K, .present = true },
  497. [tegra_clk_blink] = { .dt_id = TEGRA20_CLK_BLINK, .present = true },
  498. [tegra_clk_hclk] = { .dt_id = TEGRA20_CLK_HCLK, .present = true },
  499. [tegra_clk_pclk] = { .dt_id = TEGRA20_CLK_PCLK, .present = true },
  500. [tegra_clk_pll_p_out1] = { .dt_id = TEGRA20_CLK_PLL_P_OUT1, .present = true },
  501. [tegra_clk_pll_p_out2] = { .dt_id = TEGRA20_CLK_PLL_P_OUT2, .present = true },
  502. [tegra_clk_pll_p_out3] = { .dt_id = TEGRA20_CLK_PLL_P_OUT3, .present = true },
  503. [tegra_clk_pll_p_out4] = { .dt_id = TEGRA20_CLK_PLL_P_OUT4, .present = true },
  504. [tegra_clk_pll_p] = { .dt_id = TEGRA20_CLK_PLL_P, .present = true },
  505. [tegra_clk_owr] = { .dt_id = TEGRA20_CLK_OWR, .present = true },
  506. [tegra_clk_sbc1] = { .dt_id = TEGRA20_CLK_SBC1, .present = true },
  507. [tegra_clk_sbc2] = { .dt_id = TEGRA20_CLK_SBC2, .present = true },
  508. [tegra_clk_sbc3] = { .dt_id = TEGRA20_CLK_SBC3, .present = true },
  509. [tegra_clk_sbc4] = { .dt_id = TEGRA20_CLK_SBC4, .present = true },
  510. [tegra_clk_vde] = { .dt_id = TEGRA20_CLK_VDE, .present = true },
  511. [tegra_clk_vi] = { .dt_id = TEGRA20_CLK_VI, .present = true },
  512. [tegra_clk_epp] = { .dt_id = TEGRA20_CLK_EPP, .present = true },
  513. [tegra_clk_mpe] = { .dt_id = TEGRA20_CLK_MPE, .present = true },
  514. [tegra_clk_host1x] = { .dt_id = TEGRA20_CLK_HOST1X, .present = true },
  515. [tegra_clk_gr2d] = { .dt_id = TEGRA20_CLK_GR2D, .present = true },
  516. [tegra_clk_gr3d] = { .dt_id = TEGRA20_CLK_GR3D, .present = true },
  517. [tegra_clk_ndflash] = { .dt_id = TEGRA20_CLK_NDFLASH, .present = true },
  518. [tegra_clk_cve] = { .dt_id = TEGRA20_CLK_CVE, .present = true },
  519. [tegra_clk_tvo] = { .dt_id = TEGRA20_CLK_TVO, .present = true },
  520. [tegra_clk_tvdac] = { .dt_id = TEGRA20_CLK_TVDAC, .present = true },
  521. [tegra_clk_vi_sensor] = { .dt_id = TEGRA20_CLK_VI_SENSOR, .present = true },
  522. [tegra_clk_afi] = { .dt_id = TEGRA20_CLK_AFI, .present = true },
  523. [tegra_clk_fuse] = { .dt_id = TEGRA20_CLK_FUSE, .present = true },
  524. [tegra_clk_kfuse] = { .dt_id = TEGRA20_CLK_KFUSE, .present = true },
  525. };
  526. static unsigned long tegra20_clk_measure_input_freq(void)
  527. {
  528. u32 osc_ctrl = readl_relaxed(clk_base + OSC_CTRL);
  529. u32 auto_clk_control = osc_ctrl & OSC_CTRL_OSC_FREQ_MASK;
  530. u32 pll_ref_div = osc_ctrl & OSC_CTRL_PLL_REF_DIV_MASK;
  531. unsigned long input_freq;
  532. switch (auto_clk_control) {
  533. case OSC_CTRL_OSC_FREQ_12MHZ:
  534. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  535. input_freq = 12000000;
  536. break;
  537. case OSC_CTRL_OSC_FREQ_13MHZ:
  538. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  539. input_freq = 13000000;
  540. break;
  541. case OSC_CTRL_OSC_FREQ_19_2MHZ:
  542. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  543. input_freq = 19200000;
  544. break;
  545. case OSC_CTRL_OSC_FREQ_26MHZ:
  546. BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1);
  547. input_freq = 26000000;
  548. break;
  549. default:
  550. pr_err("Unexpected clock autodetect value %d",
  551. auto_clk_control);
  552. BUG();
  553. return 0;
  554. }
  555. return input_freq;
  556. }
  557. static unsigned int tegra20_get_pll_ref_div(void)
  558. {
  559. u32 pll_ref_div = readl_relaxed(clk_base + OSC_CTRL) &
  560. OSC_CTRL_PLL_REF_DIV_MASK;
  561. switch (pll_ref_div) {
  562. case OSC_CTRL_PLL_REF_DIV_1:
  563. return 1;
  564. case OSC_CTRL_PLL_REF_DIV_2:
  565. return 2;
  566. case OSC_CTRL_PLL_REF_DIV_4:
  567. return 4;
  568. default:
  569. pr_err("Invalied pll ref divider %d\n", pll_ref_div);
  570. BUG();
  571. }
  572. return 0;
  573. }
  574. static void tegra20_pll_init(void)
  575. {
  576. struct clk *clk;
  577. /* PLLC */
  578. clk = tegra_clk_register_pll("pll_c", "pll_ref", clk_base, NULL, 0,
  579. &pll_c_params, NULL);
  580. clks[TEGRA20_CLK_PLL_C] = clk;
  581. /* PLLC_OUT1 */
  582. clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c",
  583. clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  584. 8, 8, 1, NULL);
  585. clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div",
  586. clk_base + PLLC_OUT, 1, 0, CLK_SET_RATE_PARENT,
  587. 0, NULL);
  588. clks[TEGRA20_CLK_PLL_C_OUT1] = clk;
  589. /* PLLM */
  590. clk = tegra_clk_register_pll("pll_m", "pll_ref", clk_base, NULL,
  591. CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  592. &pll_m_params, NULL);
  593. clks[TEGRA20_CLK_PLL_M] = clk;
  594. /* PLLM_OUT1 */
  595. clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m",
  596. clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  597. 8, 8, 1, NULL);
  598. clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
  599. clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
  600. CLK_SET_RATE_PARENT, 0, NULL);
  601. clks[TEGRA20_CLK_PLL_M_OUT1] = clk;
  602. /* PLLX */
  603. clk = tegra_clk_register_pll("pll_x", "pll_ref", clk_base, NULL, 0,
  604. &pll_x_params, NULL);
  605. clks[TEGRA20_CLK_PLL_X] = clk;
  606. /* PLLU */
  607. clk = tegra_clk_register_pll("pll_u", "pll_ref", clk_base, NULL, 0,
  608. &pll_u_params, NULL);
  609. clks[TEGRA20_CLK_PLL_U] = clk;
  610. /* PLLD */
  611. clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, NULL, 0,
  612. &pll_d_params, NULL);
  613. clks[TEGRA20_CLK_PLL_D] = clk;
  614. /* PLLD_OUT0 */
  615. clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d",
  616. CLK_SET_RATE_PARENT, 1, 2);
  617. clks[TEGRA20_CLK_PLL_D_OUT0] = clk;
  618. /* PLLA */
  619. clk = tegra_clk_register_pll("pll_a", "pll_p_out1", clk_base, NULL, 0,
  620. &pll_a_params, NULL);
  621. clks[TEGRA20_CLK_PLL_A] = clk;
  622. /* PLLA_OUT0 */
  623. clk = tegra_clk_register_divider("pll_a_out0_div", "pll_a",
  624. clk_base + PLLA_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  625. 8, 8, 1, NULL);
  626. clk = tegra_clk_register_pll_out("pll_a_out0", "pll_a_out0_div",
  627. clk_base + PLLA_OUT, 1, 0, CLK_IGNORE_UNUSED |
  628. CLK_SET_RATE_PARENT, 0, NULL);
  629. clks[TEGRA20_CLK_PLL_A_OUT0] = clk;
  630. /* PLLE */
  631. clk = tegra_clk_register_plle("pll_e", "pll_ref", clk_base, pmc_base,
  632. 0, &pll_e_params, NULL);
  633. clks[TEGRA20_CLK_PLL_E] = clk;
  634. }
  635. static const char *cclk_parents[] = { "clk_m", "pll_c", "clk_32k", "pll_m",
  636. "pll_p", "pll_p_out4",
  637. "pll_p_out3", "clk_d", "pll_x" };
  638. static const char *sclk_parents[] = { "clk_m", "pll_c_out1", "pll_p_out4",
  639. "pll_p_out3", "pll_p_out2", "clk_d",
  640. "clk_32k", "pll_m_out1" };
  641. static void tegra20_super_clk_init(void)
  642. {
  643. struct clk *clk;
  644. /* CCLK */
  645. clk = tegra_clk_register_super_mux("cclk", cclk_parents,
  646. ARRAY_SIZE(cclk_parents), CLK_SET_RATE_PARENT,
  647. clk_base + CCLK_BURST_POLICY, 0, 4, 0, 0, NULL);
  648. clks[TEGRA20_CLK_CCLK] = clk;
  649. /* SCLK */
  650. clk = tegra_clk_register_super_mux("sclk", sclk_parents,
  651. ARRAY_SIZE(sclk_parents), CLK_SET_RATE_PARENT,
  652. clk_base + SCLK_BURST_POLICY, 0, 4, 0, 0, NULL);
  653. clks[TEGRA20_CLK_SCLK] = clk;
  654. /* twd */
  655. clk = clk_register_fixed_factor(NULL, "twd", "cclk", 0, 1, 4);
  656. clks[TEGRA20_CLK_TWD] = clk;
  657. }
  658. static const char *audio_parents[] = {"spdif_in", "i2s1", "i2s2", "unused",
  659. "pll_a_out0", "unused", "unused",
  660. "unused"};
  661. static void __init tegra20_audio_clk_init(void)
  662. {
  663. struct clk *clk;
  664. /* audio */
  665. clk = clk_register_mux(NULL, "audio_mux", audio_parents,
  666. ARRAY_SIZE(audio_parents),
  667. CLK_SET_RATE_NO_REPARENT,
  668. clk_base + AUDIO_SYNC_CLK, 0, 3, 0, NULL);
  669. clk = clk_register_gate(NULL, "audio", "audio_mux", 0,
  670. clk_base + AUDIO_SYNC_CLK, 4,
  671. CLK_GATE_SET_TO_DISABLE, NULL);
  672. clks[TEGRA20_CLK_AUDIO] = clk;
  673. /* audio_2x */
  674. clk = clk_register_fixed_factor(NULL, "audio_doubler", "audio",
  675. CLK_SET_RATE_PARENT, 2, 1);
  676. clk = tegra_clk_register_periph_gate("audio_2x", "audio_doubler",
  677. TEGRA_PERIPH_NO_RESET, clk_base,
  678. CLK_SET_RATE_PARENT, 89,
  679. periph_clk_enb_refcnt);
  680. clks[TEGRA20_CLK_AUDIO_2X] = clk;
  681. }
  682. static const char *i2s1_parents[] = {"pll_a_out0", "audio_2x", "pll_p",
  683. "clk_m"};
  684. static const char *i2s2_parents[] = {"pll_a_out0", "audio_2x", "pll_p",
  685. "clk_m"};
  686. static const char *pwm_parents[] = {"pll_p", "pll_c", "audio", "clk_m",
  687. "clk_32k"};
  688. static const char *mux_pllpcm_clkm[] = {"pll_p", "pll_c", "pll_m", "clk_m"};
  689. static const char *mux_pllpdc_clkm[] = {"pll_p", "pll_d_out0", "pll_c",
  690. "clk_m"};
  691. static const char *mux_pllmcp_clkm[] = {"pll_m", "pll_c", "pll_p", "clk_m"};
  692. static struct tegra_periph_init_data tegra_periph_clk_list[] = {
  693. TEGRA_INIT_DATA_MUX("i2s1", i2s1_parents, CLK_SOURCE_I2S1, 11, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2S1),
  694. TEGRA_INIT_DATA_MUX("i2s2", i2s2_parents, CLK_SOURCE_I2S2, 18, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2S2),
  695. TEGRA_INIT_DATA_MUX("spi", mux_pllpcm_clkm, CLK_SOURCE_SPI, 43, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_SPI),
  696. TEGRA_INIT_DATA_MUX("xio", mux_pllpcm_clkm, CLK_SOURCE_XIO, 45, 0, TEGRA20_CLK_XIO),
  697. TEGRA_INIT_DATA_MUX("twc", mux_pllpcm_clkm, CLK_SOURCE_TWC, 16, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_TWC),
  698. TEGRA_INIT_DATA_MUX("ide", mux_pllpcm_clkm, CLK_SOURCE_XIO, 25, 0, TEGRA20_CLK_IDE),
  699. TEGRA_INIT_DATA_DIV16("dvc", mux_pllpcm_clkm, CLK_SOURCE_DVC, 47, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_DVC),
  700. TEGRA_INIT_DATA_DIV16("i2c1", mux_pllpcm_clkm, CLK_SOURCE_I2C1, 12, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2C1),
  701. TEGRA_INIT_DATA_DIV16("i2c2", mux_pllpcm_clkm, CLK_SOURCE_I2C2, 54, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2C2),
  702. TEGRA_INIT_DATA_DIV16("i2c3", mux_pllpcm_clkm, CLK_SOURCE_I2C3, 67, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_I2C3),
  703. TEGRA_INIT_DATA_MUX("hdmi", mux_pllpdc_clkm, CLK_SOURCE_HDMI, 51, 0, TEGRA20_CLK_HDMI),
  704. TEGRA_INIT_DATA("pwm", NULL, NULL, pwm_parents, CLK_SOURCE_PWM, 28, 3, 0, 0, 8, 1, 0, 17, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_PWM),
  705. };
  706. static struct tegra_periph_init_data tegra_periph_nodiv_clk_list[] = {
  707. TEGRA_INIT_DATA_NODIV("uarta", mux_pllpcm_clkm, CLK_SOURCE_UARTA, 30, 2, 6, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTA),
  708. TEGRA_INIT_DATA_NODIV("uartb", mux_pllpcm_clkm, CLK_SOURCE_UARTB, 30, 2, 7, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTB),
  709. TEGRA_INIT_DATA_NODIV("uartc", mux_pllpcm_clkm, CLK_SOURCE_UARTC, 30, 2, 55, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTC),
  710. TEGRA_INIT_DATA_NODIV("uartd", mux_pllpcm_clkm, CLK_SOURCE_UARTD, 30, 2, 65, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTD),
  711. TEGRA_INIT_DATA_NODIV("uarte", mux_pllpcm_clkm, CLK_SOURCE_UARTE, 30, 2, 66, TEGRA_PERIPH_ON_APB, TEGRA20_CLK_UARTE),
  712. TEGRA_INIT_DATA_NODIV("disp1", mux_pllpdc_clkm, CLK_SOURCE_DISP1, 30, 2, 27, 0, TEGRA20_CLK_DISP1),
  713. TEGRA_INIT_DATA_NODIV("disp2", mux_pllpdc_clkm, CLK_SOURCE_DISP2, 30, 2, 26, 0, TEGRA20_CLK_DISP2),
  714. };
  715. static void __init tegra20_periph_clk_init(void)
  716. {
  717. struct tegra_periph_init_data *data;
  718. struct clk *clk;
  719. int i;
  720. /* ac97 */
  721. clk = tegra_clk_register_periph_gate("ac97", "pll_a_out0",
  722. TEGRA_PERIPH_ON_APB,
  723. clk_base, 0, 3, periph_clk_enb_refcnt);
  724. clks[TEGRA20_CLK_AC97] = clk;
  725. /* apbdma */
  726. clk = tegra_clk_register_periph_gate("apbdma", "pclk", 0, clk_base,
  727. 0, 34, periph_clk_enb_refcnt);
  728. clks[TEGRA20_CLK_APBDMA] = clk;
  729. /* emc */
  730. clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
  731. ARRAY_SIZE(mux_pllmcp_clkm),
  732. CLK_SET_RATE_NO_REPARENT,
  733. clk_base + CLK_SOURCE_EMC,
  734. 30, 2, 0, NULL);
  735. clk = tegra_clk_register_periph_gate("emc", "emc_mux", 0, clk_base, 0,
  736. 57, periph_clk_enb_refcnt);
  737. clks[TEGRA20_CLK_EMC] = clk;
  738. /* dsi */
  739. clk = tegra_clk_register_periph_gate("dsi", "pll_d", 0, clk_base, 0,
  740. 48, periph_clk_enb_refcnt);
  741. clk_register_clkdev(clk, NULL, "dsi");
  742. clks[TEGRA20_CLK_DSI] = clk;
  743. /* pex */
  744. clk = tegra_clk_register_periph_gate("pex", "clk_m", 0, clk_base, 0, 70,
  745. periph_clk_enb_refcnt);
  746. clks[TEGRA20_CLK_PEX] = clk;
  747. /* cdev1 */
  748. clk = clk_register_fixed_rate(NULL, "cdev1_fixed", NULL, CLK_IS_ROOT,
  749. 26000000);
  750. clk = tegra_clk_register_periph_gate("cdev1", "cdev1_fixed", 0,
  751. clk_base, 0, 94, periph_clk_enb_refcnt);
  752. clks[TEGRA20_CLK_CDEV1] = clk;
  753. /* cdev2 */
  754. clk = clk_register_fixed_rate(NULL, "cdev2_fixed", NULL, CLK_IS_ROOT,
  755. 26000000);
  756. clk = tegra_clk_register_periph_gate("cdev2", "cdev2_fixed", 0,
  757. clk_base, 0, 93, periph_clk_enb_refcnt);
  758. clks[TEGRA20_CLK_CDEV2] = clk;
  759. for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) {
  760. data = &tegra_periph_clk_list[i];
  761. clk = tegra_clk_register_periph(data->name, data->p.parent_names,
  762. data->num_parents, &data->periph,
  763. clk_base, data->offset, data->flags);
  764. clks[data->clk_id] = clk;
  765. }
  766. for (i = 0; i < ARRAY_SIZE(tegra_periph_nodiv_clk_list); i++) {
  767. data = &tegra_periph_nodiv_clk_list[i];
  768. clk = tegra_clk_register_periph_nodiv(data->name,
  769. data->p.parent_names,
  770. data->num_parents, &data->periph,
  771. clk_base, data->offset);
  772. clks[data->clk_id] = clk;
  773. }
  774. tegra_periph_clk_init(clk_base, pmc_base, tegra20_clks, &pll_p_params);
  775. }
  776. static void __init tegra20_osc_clk_init(void)
  777. {
  778. struct clk *clk;
  779. unsigned long input_freq;
  780. unsigned int pll_ref_div;
  781. input_freq = tegra20_clk_measure_input_freq();
  782. /* clk_m */
  783. clk = clk_register_fixed_rate(NULL, "clk_m", NULL, CLK_IS_ROOT |
  784. CLK_IGNORE_UNUSED, input_freq);
  785. clks[TEGRA20_CLK_CLK_M] = clk;
  786. /* pll_ref */
  787. pll_ref_div = tegra20_get_pll_ref_div();
  788. clk = clk_register_fixed_factor(NULL, "pll_ref", "clk_m",
  789. CLK_SET_RATE_PARENT, 1, pll_ref_div);
  790. clks[TEGRA20_CLK_PLL_REF] = clk;
  791. }
  792. /* Tegra20 CPU clock and reset control functions */
  793. static void tegra20_wait_cpu_in_reset(u32 cpu)
  794. {
  795. unsigned int reg;
  796. do {
  797. reg = readl(clk_base +
  798. TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
  799. cpu_relax();
  800. } while (!(reg & (1 << cpu))); /* check CPU been reset or not */
  801. return;
  802. }
  803. static void tegra20_put_cpu_in_reset(u32 cpu)
  804. {
  805. writel(CPU_RESET(cpu),
  806. clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
  807. dmb();
  808. }
  809. static void tegra20_cpu_out_of_reset(u32 cpu)
  810. {
  811. writel(CPU_RESET(cpu),
  812. clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
  813. wmb();
  814. }
  815. static void tegra20_enable_cpu_clock(u32 cpu)
  816. {
  817. unsigned int reg;
  818. reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  819. writel(reg & ~CPU_CLOCK(cpu),
  820. clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  821. barrier();
  822. reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  823. }
  824. static void tegra20_disable_cpu_clock(u32 cpu)
  825. {
  826. unsigned int reg;
  827. reg = readl(clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  828. writel(reg | CPU_CLOCK(cpu),
  829. clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  830. }
  831. #ifdef CONFIG_PM_SLEEP
  832. static bool tegra20_cpu_rail_off_ready(void)
  833. {
  834. unsigned int cpu_rst_status;
  835. cpu_rst_status = readl(clk_base +
  836. TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
  837. return !!(cpu_rst_status & 0x2);
  838. }
  839. static void tegra20_cpu_clock_suspend(void)
  840. {
  841. /* switch coresite to clk_m, save off original source */
  842. tegra20_cpu_clk_sctx.clk_csite_src =
  843. readl(clk_base + CLK_SOURCE_CSITE);
  844. writel(3<<30, clk_base + CLK_SOURCE_CSITE);
  845. tegra20_cpu_clk_sctx.cpu_burst =
  846. readl(clk_base + CCLK_BURST_POLICY);
  847. tegra20_cpu_clk_sctx.pllx_base =
  848. readl(clk_base + PLLX_BASE);
  849. tegra20_cpu_clk_sctx.pllx_misc =
  850. readl(clk_base + PLLX_MISC);
  851. tegra20_cpu_clk_sctx.cclk_divider =
  852. readl(clk_base + SUPER_CCLK_DIVIDER);
  853. }
  854. static void tegra20_cpu_clock_resume(void)
  855. {
  856. unsigned int reg, policy;
  857. /* Is CPU complex already running on PLLX? */
  858. reg = readl(clk_base + CCLK_BURST_POLICY);
  859. policy = (reg >> CCLK_BURST_POLICY_SHIFT) & 0xF;
  860. if (policy == CCLK_IDLE_POLICY)
  861. reg = (reg >> CCLK_IDLE_POLICY_SHIFT) & 0xF;
  862. else if (policy == CCLK_RUN_POLICY)
  863. reg = (reg >> CCLK_RUN_POLICY_SHIFT) & 0xF;
  864. else
  865. BUG();
  866. if (reg != CCLK_BURST_POLICY_PLLX) {
  867. /* restore PLLX settings if CPU is on different PLL */
  868. writel(tegra20_cpu_clk_sctx.pllx_misc,
  869. clk_base + PLLX_MISC);
  870. writel(tegra20_cpu_clk_sctx.pllx_base,
  871. clk_base + PLLX_BASE);
  872. /* wait for PLL stabilization if PLLX was enabled */
  873. if (tegra20_cpu_clk_sctx.pllx_base & (1 << 30))
  874. udelay(300);
  875. }
  876. /*
  877. * Restore original burst policy setting for calls resulting from CPU
  878. * LP2 in idle or system suspend.
  879. */
  880. writel(tegra20_cpu_clk_sctx.cclk_divider,
  881. clk_base + SUPER_CCLK_DIVIDER);
  882. writel(tegra20_cpu_clk_sctx.cpu_burst,
  883. clk_base + CCLK_BURST_POLICY);
  884. writel(tegra20_cpu_clk_sctx.clk_csite_src,
  885. clk_base + CLK_SOURCE_CSITE);
  886. }
  887. #endif
  888. static struct tegra_cpu_car_ops tegra20_cpu_car_ops = {
  889. .wait_for_reset = tegra20_wait_cpu_in_reset,
  890. .put_in_reset = tegra20_put_cpu_in_reset,
  891. .out_of_reset = tegra20_cpu_out_of_reset,
  892. .enable_clock = tegra20_enable_cpu_clock,
  893. .disable_clock = tegra20_disable_cpu_clock,
  894. #ifdef CONFIG_PM_SLEEP
  895. .rail_off_ready = tegra20_cpu_rail_off_ready,
  896. .suspend = tegra20_cpu_clock_suspend,
  897. .resume = tegra20_cpu_clock_resume,
  898. #endif
  899. };
  900. static struct tegra_clk_init_table init_table[] __initdata = {
  901. {TEGRA20_CLK_PLL_P, TEGRA20_CLK_CLK_MAX, 216000000, 1},
  902. {TEGRA20_CLK_PLL_P_OUT1, TEGRA20_CLK_CLK_MAX, 28800000, 1},
  903. {TEGRA20_CLK_PLL_P_OUT2, TEGRA20_CLK_CLK_MAX, 48000000, 1},
  904. {TEGRA20_CLK_PLL_P_OUT3, TEGRA20_CLK_CLK_MAX, 72000000, 1},
  905. {TEGRA20_CLK_PLL_P_OUT4, TEGRA20_CLK_CLK_MAX, 24000000, 1},
  906. {TEGRA20_CLK_PLL_C, TEGRA20_CLK_CLK_MAX, 600000000, 1},
  907. {TEGRA20_CLK_PLL_C_OUT1, TEGRA20_CLK_CLK_MAX, 120000000, 1},
  908. {TEGRA20_CLK_SCLK, TEGRA20_CLK_PLL_C_OUT1, 0, 1},
  909. {TEGRA20_CLK_HCLK, TEGRA20_CLK_CLK_MAX, 0, 1},
  910. {TEGRA20_CLK_PCLK, TEGRA20_CLK_CLK_MAX, 60000000, 1},
  911. {TEGRA20_CLK_CSITE, TEGRA20_CLK_CLK_MAX, 0, 1},
  912. {TEGRA20_CLK_EMC, TEGRA20_CLK_CLK_MAX, 0, 1},
  913. {TEGRA20_CLK_CCLK, TEGRA20_CLK_CLK_MAX, 0, 1},
  914. {TEGRA20_CLK_UARTA, TEGRA20_CLK_PLL_P, 0, 0},
  915. {TEGRA20_CLK_UARTB, TEGRA20_CLK_PLL_P, 0, 0},
  916. {TEGRA20_CLK_UARTC, TEGRA20_CLK_PLL_P, 0, 0},
  917. {TEGRA20_CLK_UARTD, TEGRA20_CLK_PLL_P, 0, 0},
  918. {TEGRA20_CLK_UARTE, TEGRA20_CLK_PLL_P, 0, 0},
  919. {TEGRA20_CLK_PLL_A, TEGRA20_CLK_CLK_MAX, 56448000, 1},
  920. {TEGRA20_CLK_PLL_A_OUT0, TEGRA20_CLK_CLK_MAX, 11289600, 1},
  921. {TEGRA20_CLK_CDEV1, TEGRA20_CLK_CLK_MAX, 0, 1},
  922. {TEGRA20_CLK_BLINK, TEGRA20_CLK_CLK_MAX, 32768, 1},
  923. {TEGRA20_CLK_I2S1, TEGRA20_CLK_PLL_A_OUT0, 11289600, 0},
  924. {TEGRA20_CLK_I2S2, TEGRA20_CLK_PLL_A_OUT0, 11289600, 0},
  925. {TEGRA20_CLK_SDMMC1, TEGRA20_CLK_PLL_P, 48000000, 0},
  926. {TEGRA20_CLK_SDMMC3, TEGRA20_CLK_PLL_P, 48000000, 0},
  927. {TEGRA20_CLK_SDMMC4, TEGRA20_CLK_PLL_P, 48000000, 0},
  928. {TEGRA20_CLK_SPI, TEGRA20_CLK_PLL_P, 20000000, 0},
  929. {TEGRA20_CLK_SBC1, TEGRA20_CLK_PLL_P, 100000000, 0},
  930. {TEGRA20_CLK_SBC2, TEGRA20_CLK_PLL_P, 100000000, 0},
  931. {TEGRA20_CLK_SBC3, TEGRA20_CLK_PLL_P, 100000000, 0},
  932. {TEGRA20_CLK_SBC4, TEGRA20_CLK_PLL_P, 100000000, 0},
  933. {TEGRA20_CLK_HOST1X, TEGRA20_CLK_PLL_C, 150000000, 0},
  934. {TEGRA20_CLK_DISP1, TEGRA20_CLK_PLL_P, 600000000, 0},
  935. {TEGRA20_CLK_DISP2, TEGRA20_CLK_PLL_P, 600000000, 0},
  936. {TEGRA20_CLK_GR2D, TEGRA20_CLK_PLL_C, 300000000, 0},
  937. {TEGRA20_CLK_GR3D, TEGRA20_CLK_PLL_C, 300000000, 0},
  938. {TEGRA20_CLK_CLK_MAX, TEGRA20_CLK_CLK_MAX, 0, 0}, /* This MUST be the last entry */
  939. };
  940. static void __init tegra20_clock_apply_init_table(void)
  941. {
  942. tegra_init_from_table(init_table, clks, TEGRA20_CLK_CLK_MAX);
  943. }
  944. /*
  945. * Some clocks may be used by different drivers depending on the board
  946. * configuration. List those here to register them twice in the clock lookup
  947. * table under two names.
  948. */
  949. static struct tegra_clk_duplicate tegra_clk_duplicates[] = {
  950. TEGRA_CLK_DUPLICATE(TEGRA20_CLK_USBD, "utmip-pad", NULL),
  951. TEGRA_CLK_DUPLICATE(TEGRA20_CLK_USBD, "tegra-ehci.0", NULL),
  952. TEGRA_CLK_DUPLICATE(TEGRA20_CLK_USBD, "tegra-otg", NULL),
  953. TEGRA_CLK_DUPLICATE(TEGRA20_CLK_CCLK, NULL, "cpu"),
  954. TEGRA_CLK_DUPLICATE(TEGRA20_CLK_CLK_MAX, NULL, NULL), /* Must be the last entry */
  955. };
  956. static const struct of_device_id pmc_match[] __initconst = {
  957. { .compatible = "nvidia,tegra20-pmc" },
  958. {},
  959. };
  960. static void __init tegra20_clock_init(struct device_node *np)
  961. {
  962. struct device_node *node;
  963. clk_base = of_iomap(np, 0);
  964. if (!clk_base) {
  965. pr_err("Can't map CAR registers\n");
  966. BUG();
  967. }
  968. node = of_find_matching_node(NULL, pmc_match);
  969. if (!node) {
  970. pr_err("Failed to find pmc node\n");
  971. BUG();
  972. }
  973. pmc_base = of_iomap(node, 0);
  974. if (!pmc_base) {
  975. pr_err("Can't map pmc registers\n");
  976. BUG();
  977. }
  978. clks = tegra_clk_init(clk_base, TEGRA20_CLK_CLK_MAX,
  979. TEGRA20_CLK_PERIPH_BANKS);
  980. if (!clks)
  981. return;
  982. tegra20_osc_clk_init();
  983. tegra_fixed_clk_init(tegra20_clks);
  984. tegra20_pll_init();
  985. tegra20_super_clk_init();
  986. tegra_super_clk_gen4_init(clk_base, pmc_base, tegra20_clks, NULL);
  987. tegra20_periph_clk_init();
  988. tegra20_audio_clk_init();
  989. tegra_pmc_clk_init(pmc_base, tegra20_clks);
  990. tegra_init_dup_clks(tegra_clk_duplicates, clks, TEGRA20_CLK_CLK_MAX);
  991. tegra_add_of_provider(np);
  992. tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
  993. tegra_clk_apply_init_table = tegra20_clock_apply_init_table;
  994. tegra_cpu_car_ops = &tegra20_cpu_car_ops;
  995. }
  996. CLK_OF_DECLARE(tegra20, "nvidia,tegra20-car", tegra20_clock_init);