clk-tegra114.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. /*
  2. * Copyright (c) 2012, 2013, 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-provider.h>
  18. #include <linux/of.h>
  19. #include <linux/of_address.h>
  20. #include <linux/delay.h>
  21. #include <linux/export.h>
  22. #include <linux/clk/tegra.h>
  23. #include <dt-bindings/clock/tegra114-car.h>
  24. #include "clk.h"
  25. #include "clk-id.h"
  26. #define RST_DFLL_DVCO 0x2F4
  27. #define CPU_FINETRIM_SELECT 0x4d4 /* override default prop dlys */
  28. #define CPU_FINETRIM_DR 0x4d8 /* rise->rise prop dly A */
  29. #define CPU_FINETRIM_R 0x4e4 /* rise->rise prop dly inc A */
  30. /* RST_DFLL_DVCO bitfields */
  31. #define DVFS_DFLL_RESET_SHIFT 0
  32. /* CPU_FINETRIM_SELECT and CPU_FINETRIM_DR bitfields */
  33. #define CPU_FINETRIM_1_FCPU_1 BIT(0) /* fcpu0 */
  34. #define CPU_FINETRIM_1_FCPU_2 BIT(1) /* fcpu1 */
  35. #define CPU_FINETRIM_1_FCPU_3 BIT(2) /* fcpu2 */
  36. #define CPU_FINETRIM_1_FCPU_4 BIT(3) /* fcpu3 */
  37. #define CPU_FINETRIM_1_FCPU_5 BIT(4) /* fl2 */
  38. #define CPU_FINETRIM_1_FCPU_6 BIT(5) /* ftop */
  39. /* CPU_FINETRIM_R bitfields */
  40. #define CPU_FINETRIM_R_FCPU_1_SHIFT 0 /* fcpu0 */
  41. #define CPU_FINETRIM_R_FCPU_1_MASK (0x3 << CPU_FINETRIM_R_FCPU_1_SHIFT)
  42. #define CPU_FINETRIM_R_FCPU_2_SHIFT 2 /* fcpu1 */
  43. #define CPU_FINETRIM_R_FCPU_2_MASK (0x3 << CPU_FINETRIM_R_FCPU_2_SHIFT)
  44. #define CPU_FINETRIM_R_FCPU_3_SHIFT 4 /* fcpu2 */
  45. #define CPU_FINETRIM_R_FCPU_3_MASK (0x3 << CPU_FINETRIM_R_FCPU_3_SHIFT)
  46. #define CPU_FINETRIM_R_FCPU_4_SHIFT 6 /* fcpu3 */
  47. #define CPU_FINETRIM_R_FCPU_4_MASK (0x3 << CPU_FINETRIM_R_FCPU_4_SHIFT)
  48. #define CPU_FINETRIM_R_FCPU_5_SHIFT 8 /* fl2 */
  49. #define CPU_FINETRIM_R_FCPU_5_MASK (0x3 << CPU_FINETRIM_R_FCPU_5_SHIFT)
  50. #define CPU_FINETRIM_R_FCPU_6_SHIFT 10 /* ftop */
  51. #define CPU_FINETRIM_R_FCPU_6_MASK (0x3 << CPU_FINETRIM_R_FCPU_6_SHIFT)
  52. #define TEGRA114_CLK_PERIPH_BANKS 5
  53. #define PLLC_BASE 0x80
  54. #define PLLC_MISC2 0x88
  55. #define PLLC_MISC 0x8c
  56. #define PLLC2_BASE 0x4e8
  57. #define PLLC2_MISC 0x4ec
  58. #define PLLC3_BASE 0x4fc
  59. #define PLLC3_MISC 0x500
  60. #define PLLM_BASE 0x90
  61. #define PLLM_MISC 0x9c
  62. #define PLLP_BASE 0xa0
  63. #define PLLP_MISC 0xac
  64. #define PLLX_BASE 0xe0
  65. #define PLLX_MISC 0xe4
  66. #define PLLX_MISC2 0x514
  67. #define PLLX_MISC3 0x518
  68. #define PLLD_BASE 0xd0
  69. #define PLLD_MISC 0xdc
  70. #define PLLD2_BASE 0x4b8
  71. #define PLLD2_MISC 0x4bc
  72. #define PLLE_BASE 0xe8
  73. #define PLLE_MISC 0xec
  74. #define PLLA_BASE 0xb0
  75. #define PLLA_MISC 0xbc
  76. #define PLLU_BASE 0xc0
  77. #define PLLU_MISC 0xcc
  78. #define PLLRE_BASE 0x4c4
  79. #define PLLRE_MISC 0x4c8
  80. #define PLL_MISC_LOCK_ENABLE 18
  81. #define PLLC_MISC_LOCK_ENABLE 24
  82. #define PLLDU_MISC_LOCK_ENABLE 22
  83. #define PLLE_MISC_LOCK_ENABLE 9
  84. #define PLLRE_MISC_LOCK_ENABLE 30
  85. #define PLLC_IDDQ_BIT 26
  86. #define PLLX_IDDQ_BIT 3
  87. #define PLLRE_IDDQ_BIT 16
  88. #define PLL_BASE_LOCK BIT(27)
  89. #define PLLE_MISC_LOCK BIT(11)
  90. #define PLLRE_MISC_LOCK BIT(24)
  91. #define PLLCX_BASE_LOCK (BIT(26)|BIT(27))
  92. #define PLLE_AUX 0x48c
  93. #define PLLC_OUT 0x84
  94. #define PLLM_OUT 0x94
  95. #define OSC_CTRL 0x50
  96. #define OSC_CTRL_OSC_FREQ_SHIFT 28
  97. #define OSC_CTRL_PLL_REF_DIV_SHIFT 26
  98. #define PLLXC_SW_MAX_P 6
  99. #define CCLKG_BURST_POLICY 0x368
  100. #define CLK_SOURCE_CSITE 0x1d4
  101. #define CLK_SOURCE_EMC 0x19c
  102. /* PLLM override registers */
  103. #define PMC_PLLM_WB0_OVERRIDE 0x1dc
  104. #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0
  105. /* Tegra CPU clock and reset control regs */
  106. #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470
  107. #define MUX8(_name, _parents, _offset, \
  108. _clk_num, _gate_flags, _clk_id) \
  109. TEGRA_INIT_DATA_TABLE(_name, NULL, NULL, _parents, _offset,\
  110. 29, MASK(3), 0, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP,\
  111. _clk_num, _gate_flags, _clk_id, _parents##_idx, 0,\
  112. NULL)
  113. #ifdef CONFIG_PM_SLEEP
  114. static struct cpu_clk_suspend_context {
  115. u32 clk_csite_src;
  116. u32 cclkg_burst;
  117. u32 cclkg_divider;
  118. } tegra114_cpu_clk_sctx;
  119. #endif
  120. static void __iomem *clk_base;
  121. static void __iomem *pmc_base;
  122. static DEFINE_SPINLOCK(pll_d_lock);
  123. static DEFINE_SPINLOCK(pll_d2_lock);
  124. static DEFINE_SPINLOCK(pll_u_lock);
  125. static DEFINE_SPINLOCK(pll_re_lock);
  126. static DEFINE_SPINLOCK(emc_lock);
  127. static struct div_nmp pllxc_nmp = {
  128. .divm_shift = 0,
  129. .divm_width = 8,
  130. .divn_shift = 8,
  131. .divn_width = 8,
  132. .divp_shift = 20,
  133. .divp_width = 4,
  134. };
  135. static const struct pdiv_map pllxc_p[] = {
  136. { .pdiv = 1, .hw_val = 0 },
  137. { .pdiv = 2, .hw_val = 1 },
  138. { .pdiv = 3, .hw_val = 2 },
  139. { .pdiv = 4, .hw_val = 3 },
  140. { .pdiv = 5, .hw_val = 4 },
  141. { .pdiv = 6, .hw_val = 5 },
  142. { .pdiv = 8, .hw_val = 6 },
  143. { .pdiv = 10, .hw_val = 7 },
  144. { .pdiv = 12, .hw_val = 8 },
  145. { .pdiv = 16, .hw_val = 9 },
  146. { .pdiv = 12, .hw_val = 10 },
  147. { .pdiv = 16, .hw_val = 11 },
  148. { .pdiv = 20, .hw_val = 12 },
  149. { .pdiv = 24, .hw_val = 13 },
  150. { .pdiv = 32, .hw_val = 14 },
  151. { .pdiv = 0, .hw_val = 0 },
  152. };
  153. static struct tegra_clk_pll_freq_table pll_c_freq_table[] = {
  154. { 12000000, 624000000, 104, 1, 2, 0 },
  155. { 12000000, 600000000, 100, 1, 2, 0 },
  156. { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */
  157. { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */
  158. { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */
  159. { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */
  160. { 0, 0, 0, 0, 0, 0 },
  161. };
  162. static struct tegra_clk_pll_params pll_c_params = {
  163. .input_min = 12000000,
  164. .input_max = 800000000,
  165. .cf_min = 12000000,
  166. .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */
  167. .vco_min = 600000000,
  168. .vco_max = 1400000000,
  169. .base_reg = PLLC_BASE,
  170. .misc_reg = PLLC_MISC,
  171. .lock_mask = PLL_BASE_LOCK,
  172. .lock_enable_bit_idx = PLLC_MISC_LOCK_ENABLE,
  173. .lock_delay = 300,
  174. .iddq_reg = PLLC_MISC,
  175. .iddq_bit_idx = PLLC_IDDQ_BIT,
  176. .max_p = PLLXC_SW_MAX_P,
  177. .dyn_ramp_reg = PLLC_MISC2,
  178. .stepa_shift = 17,
  179. .stepb_shift = 9,
  180. .pdiv_tohw = pllxc_p,
  181. .div_nmp = &pllxc_nmp,
  182. .freq_table = pll_c_freq_table,
  183. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
  184. };
  185. static struct div_nmp pllcx_nmp = {
  186. .divm_shift = 0,
  187. .divm_width = 2,
  188. .divn_shift = 8,
  189. .divn_width = 8,
  190. .divp_shift = 20,
  191. .divp_width = 3,
  192. };
  193. static const struct pdiv_map pllc_p[] = {
  194. { .pdiv = 1, .hw_val = 0 },
  195. { .pdiv = 2, .hw_val = 1 },
  196. { .pdiv = 4, .hw_val = 3 },
  197. { .pdiv = 8, .hw_val = 5 },
  198. { .pdiv = 16, .hw_val = 7 },
  199. { .pdiv = 0, .hw_val = 0 },
  200. };
  201. static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = {
  202. { 12000000, 600000000, 100, 1, 2, 0 },
  203. { 13000000, 600000000, 92, 1, 2, 0 }, /* actual: 598.0 MHz */
  204. { 16800000, 600000000, 71, 1, 2, 0 }, /* actual: 596.4 MHz */
  205. { 19200000, 600000000, 62, 1, 2, 0 }, /* actual: 595.2 MHz */
  206. { 26000000, 600000000, 92, 2, 2, 0 }, /* actual: 598.0 MHz */
  207. { 0, 0, 0, 0, 0, 0 },
  208. };
  209. static struct tegra_clk_pll_params pll_c2_params = {
  210. .input_min = 12000000,
  211. .input_max = 48000000,
  212. .cf_min = 12000000,
  213. .cf_max = 19200000,
  214. .vco_min = 600000000,
  215. .vco_max = 1200000000,
  216. .base_reg = PLLC2_BASE,
  217. .misc_reg = PLLC2_MISC,
  218. .lock_mask = PLL_BASE_LOCK,
  219. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  220. .lock_delay = 300,
  221. .pdiv_tohw = pllc_p,
  222. .div_nmp = &pllcx_nmp,
  223. .max_p = 7,
  224. .ext_misc_reg[0] = 0x4f0,
  225. .ext_misc_reg[1] = 0x4f4,
  226. .ext_misc_reg[2] = 0x4f8,
  227. .freq_table = pll_cx_freq_table,
  228. .flags = TEGRA_PLL_USE_LOCK,
  229. };
  230. static struct tegra_clk_pll_params pll_c3_params = {
  231. .input_min = 12000000,
  232. .input_max = 48000000,
  233. .cf_min = 12000000,
  234. .cf_max = 19200000,
  235. .vco_min = 600000000,
  236. .vco_max = 1200000000,
  237. .base_reg = PLLC3_BASE,
  238. .misc_reg = PLLC3_MISC,
  239. .lock_mask = PLL_BASE_LOCK,
  240. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  241. .lock_delay = 300,
  242. .pdiv_tohw = pllc_p,
  243. .div_nmp = &pllcx_nmp,
  244. .max_p = 7,
  245. .ext_misc_reg[0] = 0x504,
  246. .ext_misc_reg[1] = 0x508,
  247. .ext_misc_reg[2] = 0x50c,
  248. .freq_table = pll_cx_freq_table,
  249. .flags = TEGRA_PLL_USE_LOCK,
  250. };
  251. static struct div_nmp pllm_nmp = {
  252. .divm_shift = 0,
  253. .divm_width = 8,
  254. .override_divm_shift = 0,
  255. .divn_shift = 8,
  256. .divn_width = 8,
  257. .override_divn_shift = 8,
  258. .divp_shift = 20,
  259. .divp_width = 1,
  260. .override_divp_shift = 27,
  261. };
  262. static const struct pdiv_map pllm_p[] = {
  263. { .pdiv = 1, .hw_val = 0 },
  264. { .pdiv = 2, .hw_val = 1 },
  265. { .pdiv = 0, .hw_val = 0 },
  266. };
  267. static struct tegra_clk_pll_freq_table pll_m_freq_table[] = {
  268. { 12000000, 800000000, 66, 1, 1, 0 }, /* actual: 792.0 MHz */
  269. { 13000000, 800000000, 61, 1, 1, 0 }, /* actual: 793.0 MHz */
  270. { 16800000, 800000000, 47, 1, 1, 0 }, /* actual: 789.6 MHz */
  271. { 19200000, 800000000, 41, 1, 1, 0 }, /* actual: 787.2 MHz */
  272. { 26000000, 800000000, 61, 2, 1, 0 }, /* actual: 793.0 MHz */
  273. { 0, 0, 0, 0, 0, 0 },
  274. };
  275. static struct tegra_clk_pll_params pll_m_params = {
  276. .input_min = 12000000,
  277. .input_max = 500000000,
  278. .cf_min = 12000000,
  279. .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */
  280. .vco_min = 400000000,
  281. .vco_max = 1066000000,
  282. .base_reg = PLLM_BASE,
  283. .misc_reg = PLLM_MISC,
  284. .lock_mask = PLL_BASE_LOCK,
  285. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  286. .lock_delay = 300,
  287. .max_p = 2,
  288. .pdiv_tohw = pllm_p,
  289. .div_nmp = &pllm_nmp,
  290. .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE,
  291. .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2,
  292. .freq_table = pll_m_freq_table,
  293. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE |
  294. TEGRA_PLL_FIXED,
  295. };
  296. static struct div_nmp pllp_nmp = {
  297. .divm_shift = 0,
  298. .divm_width = 5,
  299. .divn_shift = 8,
  300. .divn_width = 10,
  301. .divp_shift = 20,
  302. .divp_width = 3,
  303. };
  304. static struct tegra_clk_pll_freq_table pll_p_freq_table[] = {
  305. { 12000000, 216000000, 432, 12, 2, 8 },
  306. { 13000000, 216000000, 432, 13, 2, 8 },
  307. { 16800000, 216000000, 360, 14, 2, 8 },
  308. { 19200000, 216000000, 360, 16, 2, 8 },
  309. { 26000000, 216000000, 432, 26, 2, 8 },
  310. { 0, 0, 0, 0, 0, 0 },
  311. };
  312. static struct tegra_clk_pll_params pll_p_params = {
  313. .input_min = 2000000,
  314. .input_max = 31000000,
  315. .cf_min = 1000000,
  316. .cf_max = 6000000,
  317. .vco_min = 200000000,
  318. .vco_max = 700000000,
  319. .base_reg = PLLP_BASE,
  320. .misc_reg = PLLP_MISC,
  321. .lock_mask = PLL_BASE_LOCK,
  322. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  323. .lock_delay = 300,
  324. .div_nmp = &pllp_nmp,
  325. .freq_table = pll_p_freq_table,
  326. .flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK |
  327. TEGRA_PLL_HAS_LOCK_ENABLE,
  328. .fixed_rate = 408000000,
  329. };
  330. static struct tegra_clk_pll_freq_table pll_a_freq_table[] = {
  331. { 9600000, 282240000, 147, 5, 1, 4 },
  332. { 9600000, 368640000, 192, 5, 1, 4 },
  333. { 9600000, 240000000, 200, 8, 1, 8 },
  334. { 28800000, 282240000, 245, 25, 1, 8 },
  335. { 28800000, 368640000, 320, 25, 1, 8 },
  336. { 28800000, 240000000, 200, 24, 1, 8 },
  337. { 0, 0, 0, 0, 0, 0 },
  338. };
  339. static struct tegra_clk_pll_params pll_a_params = {
  340. .input_min = 2000000,
  341. .input_max = 31000000,
  342. .cf_min = 1000000,
  343. .cf_max = 6000000,
  344. .vco_min = 200000000,
  345. .vco_max = 700000000,
  346. .base_reg = PLLA_BASE,
  347. .misc_reg = PLLA_MISC,
  348. .lock_mask = PLL_BASE_LOCK,
  349. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  350. .lock_delay = 300,
  351. .div_nmp = &pllp_nmp,
  352. .freq_table = pll_a_freq_table,
  353. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_USE_LOCK |
  354. TEGRA_PLL_HAS_LOCK_ENABLE,
  355. };
  356. static struct tegra_clk_pll_freq_table pll_d_freq_table[] = {
  357. { 12000000, 216000000, 864, 12, 4, 12 },
  358. { 13000000, 216000000, 864, 13, 4, 12 },
  359. { 16800000, 216000000, 720, 14, 4, 12 },
  360. { 19200000, 216000000, 720, 16, 4, 12 },
  361. { 26000000, 216000000, 864, 26, 4, 12 },
  362. { 12000000, 594000000, 594, 12, 1, 12 },
  363. { 13000000, 594000000, 594, 13, 1, 12 },
  364. { 16800000, 594000000, 495, 14, 1, 12 },
  365. { 19200000, 594000000, 495, 16, 1, 12 },
  366. { 26000000, 594000000, 594, 26, 1, 12 },
  367. { 12000000, 1000000000, 1000, 12, 1, 12 },
  368. { 13000000, 1000000000, 1000, 13, 1, 12 },
  369. { 19200000, 1000000000, 625, 12, 1, 12 },
  370. { 26000000, 1000000000, 1000, 26, 1, 12 },
  371. { 0, 0, 0, 0, 0, 0 },
  372. };
  373. static struct tegra_clk_pll_params pll_d_params = {
  374. .input_min = 2000000,
  375. .input_max = 40000000,
  376. .cf_min = 1000000,
  377. .cf_max = 6000000,
  378. .vco_min = 500000000,
  379. .vco_max = 1000000000,
  380. .base_reg = PLLD_BASE,
  381. .misc_reg = PLLD_MISC,
  382. .lock_mask = PLL_BASE_LOCK,
  383. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  384. .lock_delay = 1000,
  385. .div_nmp = &pllp_nmp,
  386. .freq_table = pll_d_freq_table,
  387. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
  388. TEGRA_PLL_HAS_LOCK_ENABLE,
  389. };
  390. static struct tegra_clk_pll_params pll_d2_params = {
  391. .input_min = 2000000,
  392. .input_max = 40000000,
  393. .cf_min = 1000000,
  394. .cf_max = 6000000,
  395. .vco_min = 500000000,
  396. .vco_max = 1000000000,
  397. .base_reg = PLLD2_BASE,
  398. .misc_reg = PLLD2_MISC,
  399. .lock_mask = PLL_BASE_LOCK,
  400. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  401. .lock_delay = 1000,
  402. .div_nmp = &pllp_nmp,
  403. .freq_table = pll_d_freq_table,
  404. .flags = TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
  405. TEGRA_PLL_HAS_LOCK_ENABLE,
  406. };
  407. static const struct pdiv_map pllu_p[] = {
  408. { .pdiv = 1, .hw_val = 1 },
  409. { .pdiv = 2, .hw_val = 0 },
  410. { .pdiv = 0, .hw_val = 0 },
  411. };
  412. static struct div_nmp pllu_nmp = {
  413. .divm_shift = 0,
  414. .divm_width = 5,
  415. .divn_shift = 8,
  416. .divn_width = 10,
  417. .divp_shift = 20,
  418. .divp_width = 1,
  419. };
  420. static struct tegra_clk_pll_freq_table pll_u_freq_table[] = {
  421. { 12000000, 480000000, 960, 12, 2, 12 },
  422. { 13000000, 480000000, 960, 13, 2, 12 },
  423. { 16800000, 480000000, 400, 7, 2, 5 },
  424. { 19200000, 480000000, 200, 4, 2, 3 },
  425. { 26000000, 480000000, 960, 26, 2, 12 },
  426. { 0, 0, 0, 0, 0, 0 },
  427. };
  428. static struct tegra_clk_pll_params pll_u_params = {
  429. .input_min = 2000000,
  430. .input_max = 40000000,
  431. .cf_min = 1000000,
  432. .cf_max = 6000000,
  433. .vco_min = 480000000,
  434. .vco_max = 960000000,
  435. .base_reg = PLLU_BASE,
  436. .misc_reg = PLLU_MISC,
  437. .lock_mask = PLL_BASE_LOCK,
  438. .lock_enable_bit_idx = PLLDU_MISC_LOCK_ENABLE,
  439. .lock_delay = 1000,
  440. .pdiv_tohw = pllu_p,
  441. .div_nmp = &pllu_nmp,
  442. .freq_table = pll_u_freq_table,
  443. .flags = TEGRA_PLLU | TEGRA_PLL_HAS_CPCON | TEGRA_PLL_SET_LFCON |
  444. TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
  445. };
  446. static struct tegra_clk_pll_freq_table pll_x_freq_table[] = {
  447. /* 1 GHz */
  448. { 12000000, 1000000000, 83, 1, 1, 0 }, /* actual: 996.0 MHz */
  449. { 13000000, 1000000000, 76, 1, 1, 0 }, /* actual: 988.0 MHz */
  450. { 16800000, 1000000000, 59, 1, 1, 0 }, /* actual: 991.2 MHz */
  451. { 19200000, 1000000000, 52, 1, 1, 0 }, /* actual: 998.4 MHz */
  452. { 26000000, 1000000000, 76, 2, 1, 0 }, /* actual: 988.0 MHz */
  453. { 0, 0, 0, 0, 0, 0 },
  454. };
  455. static struct tegra_clk_pll_params pll_x_params = {
  456. .input_min = 12000000,
  457. .input_max = 800000000,
  458. .cf_min = 12000000,
  459. .cf_max = 19200000, /* s/w policy, h/w capability 50 MHz */
  460. .vco_min = 700000000,
  461. .vco_max = 2400000000U,
  462. .base_reg = PLLX_BASE,
  463. .misc_reg = PLLX_MISC,
  464. .lock_mask = PLL_BASE_LOCK,
  465. .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE,
  466. .lock_delay = 300,
  467. .iddq_reg = PLLX_MISC3,
  468. .iddq_bit_idx = PLLX_IDDQ_BIT,
  469. .max_p = PLLXC_SW_MAX_P,
  470. .dyn_ramp_reg = PLLX_MISC2,
  471. .stepa_shift = 16,
  472. .stepb_shift = 24,
  473. .pdiv_tohw = pllxc_p,
  474. .div_nmp = &pllxc_nmp,
  475. .freq_table = pll_x_freq_table,
  476. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE,
  477. };
  478. static struct tegra_clk_pll_freq_table pll_e_freq_table[] = {
  479. /* PLLE special case: use cpcon field to store cml divider value */
  480. { 336000000, 100000000, 100, 21, 16, 11 },
  481. { 312000000, 100000000, 200, 26, 24, 13 },
  482. { 12000000, 100000000, 200, 1, 24, 13 },
  483. { 0, 0, 0, 0, 0, 0 },
  484. };
  485. static const struct pdiv_map plle_p[] = {
  486. { .pdiv = 1, .hw_val = 0 },
  487. { .pdiv = 2, .hw_val = 1 },
  488. { .pdiv = 3, .hw_val = 2 },
  489. { .pdiv = 4, .hw_val = 3 },
  490. { .pdiv = 5, .hw_val = 4 },
  491. { .pdiv = 6, .hw_val = 5 },
  492. { .pdiv = 8, .hw_val = 6 },
  493. { .pdiv = 10, .hw_val = 7 },
  494. { .pdiv = 12, .hw_val = 8 },
  495. { .pdiv = 16, .hw_val = 9 },
  496. { .pdiv = 12, .hw_val = 10 },
  497. { .pdiv = 16, .hw_val = 11 },
  498. { .pdiv = 20, .hw_val = 12 },
  499. { .pdiv = 24, .hw_val = 13 },
  500. { .pdiv = 32, .hw_val = 14 },
  501. { .pdiv = 0, .hw_val = 0 }
  502. };
  503. static struct div_nmp plle_nmp = {
  504. .divm_shift = 0,
  505. .divm_width = 8,
  506. .divn_shift = 8,
  507. .divn_width = 8,
  508. .divp_shift = 24,
  509. .divp_width = 4,
  510. };
  511. static struct tegra_clk_pll_params pll_e_params = {
  512. .input_min = 12000000,
  513. .input_max = 1000000000,
  514. .cf_min = 12000000,
  515. .cf_max = 75000000,
  516. .vco_min = 1600000000,
  517. .vco_max = 2400000000U,
  518. .base_reg = PLLE_BASE,
  519. .misc_reg = PLLE_MISC,
  520. .aux_reg = PLLE_AUX,
  521. .lock_mask = PLLE_MISC_LOCK,
  522. .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE,
  523. .lock_delay = 300,
  524. .pdiv_tohw = plle_p,
  525. .div_nmp = &plle_nmp,
  526. .freq_table = pll_e_freq_table,
  527. .flags = TEGRA_PLL_FIXED | TEGRA_PLL_HAS_LOCK_ENABLE,
  528. .fixed_rate = 100000000,
  529. };
  530. static struct div_nmp pllre_nmp = {
  531. .divm_shift = 0,
  532. .divm_width = 8,
  533. .divn_shift = 8,
  534. .divn_width = 8,
  535. .divp_shift = 16,
  536. .divp_width = 4,
  537. };
  538. static struct tegra_clk_pll_params pll_re_vco_params = {
  539. .input_min = 12000000,
  540. .input_max = 1000000000,
  541. .cf_min = 12000000,
  542. .cf_max = 19200000, /* s/w policy, h/w capability 38 MHz */
  543. .vco_min = 300000000,
  544. .vco_max = 600000000,
  545. .base_reg = PLLRE_BASE,
  546. .misc_reg = PLLRE_MISC,
  547. .lock_mask = PLLRE_MISC_LOCK,
  548. .lock_enable_bit_idx = PLLRE_MISC_LOCK_ENABLE,
  549. .lock_delay = 300,
  550. .iddq_reg = PLLRE_MISC,
  551. .iddq_bit_idx = PLLRE_IDDQ_BIT,
  552. .div_nmp = &pllre_nmp,
  553. .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE |
  554. TEGRA_PLL_LOCK_MISC,
  555. };
  556. /* possible OSC frequencies in Hz */
  557. static unsigned long tegra114_input_freq[] = {
  558. [ 0] = 13000000,
  559. [ 1] = 16800000,
  560. [ 4] = 19200000,
  561. [ 5] = 38400000,
  562. [ 8] = 12000000,
  563. [ 9] = 48000000,
  564. [12] = 26000000,
  565. };
  566. #define MASK(x) (BIT(x) - 1)
  567. /* peripheral mux definitions */
  568. static const char *mux_plld_out0_plld2_out0[] = {
  569. "pll_d_out0", "pll_d2_out0",
  570. };
  571. #define mux_plld_out0_plld2_out0_idx NULL
  572. static const char *mux_pllmcp_clkm[] = {
  573. "pll_m_out0", "pll_c_out0", "pll_p_out0", "clk_m", "pll_m_ud",
  574. };
  575. static const struct clk_div_table pll_re_div_table[] = {
  576. { .val = 0, .div = 1 },
  577. { .val = 1, .div = 2 },
  578. { .val = 2, .div = 3 },
  579. { .val = 3, .div = 4 },
  580. { .val = 4, .div = 5 },
  581. { .val = 5, .div = 6 },
  582. { .val = 0, .div = 0 },
  583. };
  584. static struct tegra_clk tegra114_clks[tegra_clk_max] __initdata = {
  585. [tegra_clk_rtc] = { .dt_id = TEGRA114_CLK_RTC, .present = true },
  586. [tegra_clk_timer] = { .dt_id = TEGRA114_CLK_TIMER, .present = true },
  587. [tegra_clk_uarta] = { .dt_id = TEGRA114_CLK_UARTA, .present = true },
  588. [tegra_clk_uartd] = { .dt_id = TEGRA114_CLK_UARTD, .present = true },
  589. [tegra_clk_sdmmc2_8] = { .dt_id = TEGRA114_CLK_SDMMC2, .present = true },
  590. [tegra_clk_i2s1] = { .dt_id = TEGRA114_CLK_I2S1, .present = true },
  591. [tegra_clk_i2c1] = { .dt_id = TEGRA114_CLK_I2C1, .present = true },
  592. [tegra_clk_ndflash] = { .dt_id = TEGRA114_CLK_NDFLASH, .present = true },
  593. [tegra_clk_sdmmc1_8] = { .dt_id = TEGRA114_CLK_SDMMC1, .present = true },
  594. [tegra_clk_sdmmc4_8] = { .dt_id = TEGRA114_CLK_SDMMC4, .present = true },
  595. [tegra_clk_pwm] = { .dt_id = TEGRA114_CLK_PWM, .present = true },
  596. [tegra_clk_i2s0] = { .dt_id = TEGRA114_CLK_I2S0, .present = true },
  597. [tegra_clk_i2s2] = { .dt_id = TEGRA114_CLK_I2S2, .present = true },
  598. [tegra_clk_epp_8] = { .dt_id = TEGRA114_CLK_EPP, .present = true },
  599. [tegra_clk_gr2d_8] = { .dt_id = TEGRA114_CLK_GR2D, .present = true },
  600. [tegra_clk_usbd] = { .dt_id = TEGRA114_CLK_USBD, .present = true },
  601. [tegra_clk_isp] = { .dt_id = TEGRA114_CLK_ISP, .present = true },
  602. [tegra_clk_gr3d_8] = { .dt_id = TEGRA114_CLK_GR3D, .present = true },
  603. [tegra_clk_disp2] = { .dt_id = TEGRA114_CLK_DISP2, .present = true },
  604. [tegra_clk_disp1] = { .dt_id = TEGRA114_CLK_DISP1, .present = true },
  605. [tegra_clk_host1x_8] = { .dt_id = TEGRA114_CLK_HOST1X, .present = true },
  606. [tegra_clk_vcp] = { .dt_id = TEGRA114_CLK_VCP, .present = true },
  607. [tegra_clk_apbdma] = { .dt_id = TEGRA114_CLK_APBDMA, .present = true },
  608. [tegra_clk_kbc] = { .dt_id = TEGRA114_CLK_KBC, .present = true },
  609. [tegra_clk_kfuse] = { .dt_id = TEGRA114_CLK_KFUSE, .present = true },
  610. [tegra_clk_sbc1_8] = { .dt_id = TEGRA114_CLK_SBC1, .present = true },
  611. [tegra_clk_nor] = { .dt_id = TEGRA114_CLK_NOR, .present = true },
  612. [tegra_clk_sbc2_8] = { .dt_id = TEGRA114_CLK_SBC2, .present = true },
  613. [tegra_clk_sbc3_8] = { .dt_id = TEGRA114_CLK_SBC3, .present = true },
  614. [tegra_clk_i2c5] = { .dt_id = TEGRA114_CLK_I2C5, .present = true },
  615. [tegra_clk_mipi] = { .dt_id = TEGRA114_CLK_MIPI, .present = true },
  616. [tegra_clk_hdmi] = { .dt_id = TEGRA114_CLK_HDMI, .present = true },
  617. [tegra_clk_csi] = { .dt_id = TEGRA114_CLK_CSI, .present = true },
  618. [tegra_clk_i2c2] = { .dt_id = TEGRA114_CLK_I2C2, .present = true },
  619. [tegra_clk_uartc] = { .dt_id = TEGRA114_CLK_UARTC, .present = true },
  620. [tegra_clk_emc] = { .dt_id = TEGRA114_CLK_EMC, .present = true },
  621. [tegra_clk_usb2] = { .dt_id = TEGRA114_CLK_USB2, .present = true },
  622. [tegra_clk_usb3] = { .dt_id = TEGRA114_CLK_USB3, .present = true },
  623. [tegra_clk_vde_8] = { .dt_id = TEGRA114_CLK_VDE, .present = true },
  624. [tegra_clk_bsea] = { .dt_id = TEGRA114_CLK_BSEA, .present = true },
  625. [tegra_clk_bsev] = { .dt_id = TEGRA114_CLK_BSEV, .present = true },
  626. [tegra_clk_i2c3] = { .dt_id = TEGRA114_CLK_I2C3, .present = true },
  627. [tegra_clk_sbc4_8] = { .dt_id = TEGRA114_CLK_SBC4, .present = true },
  628. [tegra_clk_sdmmc3_8] = { .dt_id = TEGRA114_CLK_SDMMC3, .present = true },
  629. [tegra_clk_owr] = { .dt_id = TEGRA114_CLK_OWR, .present = true },
  630. [tegra_clk_csite] = { .dt_id = TEGRA114_CLK_CSITE, .present = true },
  631. [tegra_clk_la] = { .dt_id = TEGRA114_CLK_LA, .present = true },
  632. [tegra_clk_trace] = { .dt_id = TEGRA114_CLK_TRACE, .present = true },
  633. [tegra_clk_soc_therm] = { .dt_id = TEGRA114_CLK_SOC_THERM, .present = true },
  634. [tegra_clk_dtv] = { .dt_id = TEGRA114_CLK_DTV, .present = true },
  635. [tegra_clk_ndspeed] = { .dt_id = TEGRA114_CLK_NDSPEED, .present = true },
  636. [tegra_clk_i2cslow] = { .dt_id = TEGRA114_CLK_I2CSLOW, .present = true },
  637. [tegra_clk_tsec] = { .dt_id = TEGRA114_CLK_TSEC, .present = true },
  638. [tegra_clk_xusb_host] = { .dt_id = TEGRA114_CLK_XUSB_HOST, .present = true },
  639. [tegra_clk_msenc] = { .dt_id = TEGRA114_CLK_MSENC, .present = true },
  640. [tegra_clk_csus] = { .dt_id = TEGRA114_CLK_CSUS, .present = true },
  641. [tegra_clk_mselect] = { .dt_id = TEGRA114_CLK_MSELECT, .present = true },
  642. [tegra_clk_tsensor] = { .dt_id = TEGRA114_CLK_TSENSOR, .present = true },
  643. [tegra_clk_i2s3] = { .dt_id = TEGRA114_CLK_I2S3, .present = true },
  644. [tegra_clk_i2s4] = { .dt_id = TEGRA114_CLK_I2S4, .present = true },
  645. [tegra_clk_i2c4] = { .dt_id = TEGRA114_CLK_I2C4, .present = true },
  646. [tegra_clk_sbc5_8] = { .dt_id = TEGRA114_CLK_SBC5, .present = true },
  647. [tegra_clk_sbc6_8] = { .dt_id = TEGRA114_CLK_SBC6, .present = true },
  648. [tegra_clk_d_audio] = { .dt_id = TEGRA114_CLK_D_AUDIO, .present = true },
  649. [tegra_clk_apbif] = { .dt_id = TEGRA114_CLK_APBIF, .present = true },
  650. [tegra_clk_dam0] = { .dt_id = TEGRA114_CLK_DAM0, .present = true },
  651. [tegra_clk_dam1] = { .dt_id = TEGRA114_CLK_DAM1, .present = true },
  652. [tegra_clk_dam2] = { .dt_id = TEGRA114_CLK_DAM2, .present = true },
  653. [tegra_clk_hda2codec_2x] = { .dt_id = TEGRA114_CLK_HDA2CODEC_2X, .present = true },
  654. [tegra_clk_audio0_2x] = { .dt_id = TEGRA114_CLK_AUDIO0_2X, .present = true },
  655. [tegra_clk_audio1_2x] = { .dt_id = TEGRA114_CLK_AUDIO1_2X, .present = true },
  656. [tegra_clk_audio2_2x] = { .dt_id = TEGRA114_CLK_AUDIO2_2X, .present = true },
  657. [tegra_clk_audio3_2x] = { .dt_id = TEGRA114_CLK_AUDIO3_2X, .present = true },
  658. [tegra_clk_audio4_2x] = { .dt_id = TEGRA114_CLK_AUDIO4_2X, .present = true },
  659. [tegra_clk_spdif_2x] = { .dt_id = TEGRA114_CLK_SPDIF_2X, .present = true },
  660. [tegra_clk_actmon] = { .dt_id = TEGRA114_CLK_ACTMON, .present = true },
  661. [tegra_clk_extern1] = { .dt_id = TEGRA114_CLK_EXTERN1, .present = true },
  662. [tegra_clk_extern2] = { .dt_id = TEGRA114_CLK_EXTERN2, .present = true },
  663. [tegra_clk_extern3] = { .dt_id = TEGRA114_CLK_EXTERN3, .present = true },
  664. [tegra_clk_hda] = { .dt_id = TEGRA114_CLK_HDA, .present = true },
  665. [tegra_clk_se] = { .dt_id = TEGRA114_CLK_SE, .present = true },
  666. [tegra_clk_hda2hdmi] = { .dt_id = TEGRA114_CLK_HDA2HDMI, .present = true },
  667. [tegra_clk_cilab] = { .dt_id = TEGRA114_CLK_CILAB, .present = true },
  668. [tegra_clk_cilcd] = { .dt_id = TEGRA114_CLK_CILCD, .present = true },
  669. [tegra_clk_cile] = { .dt_id = TEGRA114_CLK_CILE, .present = true },
  670. [tegra_clk_dsialp] = { .dt_id = TEGRA114_CLK_DSIALP, .present = true },
  671. [tegra_clk_dsiblp] = { .dt_id = TEGRA114_CLK_DSIBLP, .present = true },
  672. [tegra_clk_dds] = { .dt_id = TEGRA114_CLK_DDS, .present = true },
  673. [tegra_clk_dp2] = { .dt_id = TEGRA114_CLK_DP2, .present = true },
  674. [tegra_clk_amx] = { .dt_id = TEGRA114_CLK_AMX, .present = true },
  675. [tegra_clk_adx] = { .dt_id = TEGRA114_CLK_ADX, .present = true },
  676. [tegra_clk_xusb_ss] = { .dt_id = TEGRA114_CLK_XUSB_SS, .present = true },
  677. [tegra_clk_uartb] = { .dt_id = TEGRA114_CLK_UARTB, .present = true },
  678. [tegra_clk_vfir] = { .dt_id = TEGRA114_CLK_VFIR, .present = true },
  679. [tegra_clk_spdif_in] = { .dt_id = TEGRA114_CLK_SPDIF_IN, .present = true },
  680. [tegra_clk_spdif_out] = { .dt_id = TEGRA114_CLK_SPDIF_OUT, .present = true },
  681. [tegra_clk_vi_8] = { .dt_id = TEGRA114_CLK_VI, .present = true },
  682. [tegra_clk_fuse] = { .dt_id = TEGRA114_CLK_FUSE, .present = true },
  683. [tegra_clk_fuse_burn] = { .dt_id = TEGRA114_CLK_FUSE_BURN, .present = true },
  684. [tegra_clk_clk_32k] = { .dt_id = TEGRA114_CLK_CLK_32K, .present = true },
  685. [tegra_clk_clk_m] = { .dt_id = TEGRA114_CLK_CLK_M, .present = true },
  686. [tegra_clk_clk_m_div2] = { .dt_id = TEGRA114_CLK_CLK_M_DIV2, .present = true },
  687. [tegra_clk_clk_m_div4] = { .dt_id = TEGRA114_CLK_CLK_M_DIV4, .present = true },
  688. [tegra_clk_pll_ref] = { .dt_id = TEGRA114_CLK_PLL_REF, .present = true },
  689. [tegra_clk_pll_c] = { .dt_id = TEGRA114_CLK_PLL_C, .present = true },
  690. [tegra_clk_pll_c_out1] = { .dt_id = TEGRA114_CLK_PLL_C_OUT1, .present = true },
  691. [tegra_clk_pll_c2] = { .dt_id = TEGRA114_CLK_PLL_C2, .present = true },
  692. [tegra_clk_pll_c3] = { .dt_id = TEGRA114_CLK_PLL_C3, .present = true },
  693. [tegra_clk_pll_m] = { .dt_id = TEGRA114_CLK_PLL_M, .present = true },
  694. [tegra_clk_pll_m_out1] = { .dt_id = TEGRA114_CLK_PLL_M_OUT1, .present = true },
  695. [tegra_clk_pll_p] = { .dt_id = TEGRA114_CLK_PLL_P, .present = true },
  696. [tegra_clk_pll_p_out1] = { .dt_id = TEGRA114_CLK_PLL_P_OUT1, .present = true },
  697. [tegra_clk_pll_p_out2_int] = { .dt_id = TEGRA114_CLK_PLL_P_OUT2, .present = true },
  698. [tegra_clk_pll_p_out3] = { .dt_id = TEGRA114_CLK_PLL_P_OUT3, .present = true },
  699. [tegra_clk_pll_p_out4] = { .dt_id = TEGRA114_CLK_PLL_P_OUT4, .present = true },
  700. [tegra_clk_pll_a] = { .dt_id = TEGRA114_CLK_PLL_A, .present = true },
  701. [tegra_clk_pll_a_out0] = { .dt_id = TEGRA114_CLK_PLL_A_OUT0, .present = true },
  702. [tegra_clk_pll_d] = { .dt_id = TEGRA114_CLK_PLL_D, .present = true },
  703. [tegra_clk_pll_d_out0] = { .dt_id = TEGRA114_CLK_PLL_D_OUT0, .present = true },
  704. [tegra_clk_pll_d2] = { .dt_id = TEGRA114_CLK_PLL_D2, .present = true },
  705. [tegra_clk_pll_d2_out0] = { .dt_id = TEGRA114_CLK_PLL_D2_OUT0, .present = true },
  706. [tegra_clk_pll_u] = { .dt_id = TEGRA114_CLK_PLL_U, .present = true },
  707. [tegra_clk_pll_u_480m] = { .dt_id = TEGRA114_CLK_PLL_U_480M, .present = true },
  708. [tegra_clk_pll_u_60m] = { .dt_id = TEGRA114_CLK_PLL_U_60M, .present = true },
  709. [tegra_clk_pll_u_48m] = { .dt_id = TEGRA114_CLK_PLL_U_48M, .present = true },
  710. [tegra_clk_pll_u_12m] = { .dt_id = TEGRA114_CLK_PLL_U_12M, .present = true },
  711. [tegra_clk_pll_x] = { .dt_id = TEGRA114_CLK_PLL_X, .present = true },
  712. [tegra_clk_pll_x_out0] = { .dt_id = TEGRA114_CLK_PLL_X_OUT0, .present = true },
  713. [tegra_clk_pll_re_vco] = { .dt_id = TEGRA114_CLK_PLL_RE_VCO, .present = true },
  714. [tegra_clk_pll_re_out] = { .dt_id = TEGRA114_CLK_PLL_RE_OUT, .present = true },
  715. [tegra_clk_pll_e_out0] = { .dt_id = TEGRA114_CLK_PLL_E_OUT0, .present = true },
  716. [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA114_CLK_SPDIF_IN_SYNC, .present = true },
  717. [tegra_clk_i2s0_sync] = { .dt_id = TEGRA114_CLK_I2S0_SYNC, .present = true },
  718. [tegra_clk_i2s1_sync] = { .dt_id = TEGRA114_CLK_I2S1_SYNC, .present = true },
  719. [tegra_clk_i2s2_sync] = { .dt_id = TEGRA114_CLK_I2S2_SYNC, .present = true },
  720. [tegra_clk_i2s3_sync] = { .dt_id = TEGRA114_CLK_I2S3_SYNC, .present = true },
  721. [tegra_clk_i2s4_sync] = { .dt_id = TEGRA114_CLK_I2S4_SYNC, .present = true },
  722. [tegra_clk_vimclk_sync] = { .dt_id = TEGRA114_CLK_VIMCLK_SYNC, .present = true },
  723. [tegra_clk_audio0] = { .dt_id = TEGRA114_CLK_AUDIO0, .present = true },
  724. [tegra_clk_audio1] = { .dt_id = TEGRA114_CLK_AUDIO1, .present = true },
  725. [tegra_clk_audio2] = { .dt_id = TEGRA114_CLK_AUDIO2, .present = true },
  726. [tegra_clk_audio3] = { .dt_id = TEGRA114_CLK_AUDIO3, .present = true },
  727. [tegra_clk_audio4] = { .dt_id = TEGRA114_CLK_AUDIO4, .present = true },
  728. [tegra_clk_spdif] = { .dt_id = TEGRA114_CLK_SPDIF, .present = true },
  729. [tegra_clk_clk_out_1] = { .dt_id = TEGRA114_CLK_CLK_OUT_1, .present = true },
  730. [tegra_clk_clk_out_2] = { .dt_id = TEGRA114_CLK_CLK_OUT_2, .present = true },
  731. [tegra_clk_clk_out_3] = { .dt_id = TEGRA114_CLK_CLK_OUT_3, .present = true },
  732. [tegra_clk_blink] = { .dt_id = TEGRA114_CLK_BLINK, .present = true },
  733. [tegra_clk_xusb_host_src] = { .dt_id = TEGRA114_CLK_XUSB_HOST_SRC, .present = true },
  734. [tegra_clk_xusb_falcon_src] = { .dt_id = TEGRA114_CLK_XUSB_FALCON_SRC, .present = true },
  735. [tegra_clk_xusb_fs_src] = { .dt_id = TEGRA114_CLK_XUSB_FS_SRC, .present = true },
  736. [tegra_clk_xusb_ss_src] = { .dt_id = TEGRA114_CLK_XUSB_SS_SRC, .present = true },
  737. [tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA114_CLK_XUSB_SS_DIV2, .present = true},
  738. [tegra_clk_xusb_dev_src] = { .dt_id = TEGRA114_CLK_XUSB_DEV_SRC, .present = true },
  739. [tegra_clk_xusb_dev] = { .dt_id = TEGRA114_CLK_XUSB_DEV, .present = true },
  740. [tegra_clk_xusb_hs_src] = { .dt_id = TEGRA114_CLK_XUSB_HS_SRC, .present = true },
  741. [tegra_clk_sclk] = { .dt_id = TEGRA114_CLK_SCLK, .present = true },
  742. [tegra_clk_hclk] = { .dt_id = TEGRA114_CLK_HCLK, .present = true },
  743. [tegra_clk_pclk] = { .dt_id = TEGRA114_CLK_PCLK, .present = true },
  744. [tegra_clk_cclk_g] = { .dt_id = TEGRA114_CLK_CCLK_G, .present = true },
  745. [tegra_clk_cclk_lp] = { .dt_id = TEGRA114_CLK_CCLK_LP, .present = true },
  746. [tegra_clk_dfll_ref] = { .dt_id = TEGRA114_CLK_DFLL_REF, .present = true },
  747. [tegra_clk_dfll_soc] = { .dt_id = TEGRA114_CLK_DFLL_SOC, .present = true },
  748. [tegra_clk_audio0_mux] = { .dt_id = TEGRA114_CLK_AUDIO0_MUX, .present = true },
  749. [tegra_clk_audio1_mux] = { .dt_id = TEGRA114_CLK_AUDIO1_MUX, .present = true },
  750. [tegra_clk_audio2_mux] = { .dt_id = TEGRA114_CLK_AUDIO2_MUX, .present = true },
  751. [tegra_clk_audio3_mux] = { .dt_id = TEGRA114_CLK_AUDIO3_MUX, .present = true },
  752. [tegra_clk_audio4_mux] = { .dt_id = TEGRA114_CLK_AUDIO4_MUX, .present = true },
  753. [tegra_clk_spdif_mux] = { .dt_id = TEGRA114_CLK_SPDIF_MUX, .present = true },
  754. [tegra_clk_clk_out_1_mux] = { .dt_id = TEGRA114_CLK_CLK_OUT_1_MUX, .present = true },
  755. [tegra_clk_clk_out_2_mux] = { .dt_id = TEGRA114_CLK_CLK_OUT_2_MUX, .present = true },
  756. [tegra_clk_clk_out_3_mux] = { .dt_id = TEGRA114_CLK_CLK_OUT_3_MUX, .present = true },
  757. [tegra_clk_dsia_mux] = { .dt_id = TEGRA114_CLK_DSIA_MUX, .present = true },
  758. [tegra_clk_dsib_mux] = { .dt_id = TEGRA114_CLK_DSIB_MUX, .present = true },
  759. [tegra_clk_cec] = { .dt_id = TEGRA114_CLK_CEC, .present = true },
  760. };
  761. static struct tegra_devclk devclks[] __initdata = {
  762. { .con_id = "clk_m", .dt_id = TEGRA114_CLK_CLK_M },
  763. { .con_id = "pll_ref", .dt_id = TEGRA114_CLK_PLL_REF },
  764. { .con_id = "clk_32k", .dt_id = TEGRA114_CLK_CLK_32K },
  765. { .con_id = "clk_m_div2", .dt_id = TEGRA114_CLK_CLK_M_DIV2 },
  766. { .con_id = "clk_m_div4", .dt_id = TEGRA114_CLK_CLK_M_DIV4 },
  767. { .con_id = "pll_c", .dt_id = TEGRA114_CLK_PLL_C },
  768. { .con_id = "pll_c_out1", .dt_id = TEGRA114_CLK_PLL_C_OUT1 },
  769. { .con_id = "pll_c2", .dt_id = TEGRA114_CLK_PLL_C2 },
  770. { .con_id = "pll_c3", .dt_id = TEGRA114_CLK_PLL_C3 },
  771. { .con_id = "pll_p", .dt_id = TEGRA114_CLK_PLL_P },
  772. { .con_id = "pll_p_out1", .dt_id = TEGRA114_CLK_PLL_P_OUT1 },
  773. { .con_id = "pll_p_out2", .dt_id = TEGRA114_CLK_PLL_P_OUT2 },
  774. { .con_id = "pll_p_out3", .dt_id = TEGRA114_CLK_PLL_P_OUT3 },
  775. { .con_id = "pll_p_out4", .dt_id = TEGRA114_CLK_PLL_P_OUT4 },
  776. { .con_id = "pll_m", .dt_id = TEGRA114_CLK_PLL_M },
  777. { .con_id = "pll_m_out1", .dt_id = TEGRA114_CLK_PLL_M_OUT1 },
  778. { .con_id = "pll_x", .dt_id = TEGRA114_CLK_PLL_X },
  779. { .con_id = "pll_x_out0", .dt_id = TEGRA114_CLK_PLL_X_OUT0 },
  780. { .con_id = "pll_u", .dt_id = TEGRA114_CLK_PLL_U },
  781. { .con_id = "pll_u_480M", .dt_id = TEGRA114_CLK_PLL_U_480M },
  782. { .con_id = "pll_u_60M", .dt_id = TEGRA114_CLK_PLL_U_60M },
  783. { .con_id = "pll_u_48M", .dt_id = TEGRA114_CLK_PLL_U_48M },
  784. { .con_id = "pll_u_12M", .dt_id = TEGRA114_CLK_PLL_U_12M },
  785. { .con_id = "pll_d", .dt_id = TEGRA114_CLK_PLL_D },
  786. { .con_id = "pll_d_out0", .dt_id = TEGRA114_CLK_PLL_D_OUT0 },
  787. { .con_id = "pll_d2", .dt_id = TEGRA114_CLK_PLL_D2 },
  788. { .con_id = "pll_d2_out0", .dt_id = TEGRA114_CLK_PLL_D2_OUT0 },
  789. { .con_id = "pll_a", .dt_id = TEGRA114_CLK_PLL_A },
  790. { .con_id = "pll_a_out0", .dt_id = TEGRA114_CLK_PLL_A_OUT0 },
  791. { .con_id = "pll_re_vco", .dt_id = TEGRA114_CLK_PLL_RE_VCO },
  792. { .con_id = "pll_re_out", .dt_id = TEGRA114_CLK_PLL_RE_OUT },
  793. { .con_id = "pll_e_out0", .dt_id = TEGRA114_CLK_PLL_E_OUT0 },
  794. { .con_id = "spdif_in_sync", .dt_id = TEGRA114_CLK_SPDIF_IN_SYNC },
  795. { .con_id = "i2s0_sync", .dt_id = TEGRA114_CLK_I2S0_SYNC },
  796. { .con_id = "i2s1_sync", .dt_id = TEGRA114_CLK_I2S1_SYNC },
  797. { .con_id = "i2s2_sync", .dt_id = TEGRA114_CLK_I2S2_SYNC },
  798. { .con_id = "i2s3_sync", .dt_id = TEGRA114_CLK_I2S3_SYNC },
  799. { .con_id = "i2s4_sync", .dt_id = TEGRA114_CLK_I2S4_SYNC },
  800. { .con_id = "vimclk_sync", .dt_id = TEGRA114_CLK_VIMCLK_SYNC },
  801. { .con_id = "audio0", .dt_id = TEGRA114_CLK_AUDIO0 },
  802. { .con_id = "audio1", .dt_id = TEGRA114_CLK_AUDIO1 },
  803. { .con_id = "audio2", .dt_id = TEGRA114_CLK_AUDIO2 },
  804. { .con_id = "audio3", .dt_id = TEGRA114_CLK_AUDIO3 },
  805. { .con_id = "audio4", .dt_id = TEGRA114_CLK_AUDIO4 },
  806. { .con_id = "spdif", .dt_id = TEGRA114_CLK_SPDIF },
  807. { .con_id = "audio0_2x", .dt_id = TEGRA114_CLK_AUDIO0_2X },
  808. { .con_id = "audio1_2x", .dt_id = TEGRA114_CLK_AUDIO1_2X },
  809. { .con_id = "audio2_2x", .dt_id = TEGRA114_CLK_AUDIO2_2X },
  810. { .con_id = "audio3_2x", .dt_id = TEGRA114_CLK_AUDIO3_2X },
  811. { .con_id = "audio4_2x", .dt_id = TEGRA114_CLK_AUDIO4_2X },
  812. { .con_id = "spdif_2x", .dt_id = TEGRA114_CLK_SPDIF_2X },
  813. { .con_id = "extern1", .dev_id = "clk_out_1", .dt_id = TEGRA114_CLK_EXTERN1 },
  814. { .con_id = "extern2", .dev_id = "clk_out_2", .dt_id = TEGRA114_CLK_EXTERN2 },
  815. { .con_id = "extern3", .dev_id = "clk_out_3", .dt_id = TEGRA114_CLK_EXTERN3 },
  816. { .con_id = "blink", .dt_id = TEGRA114_CLK_BLINK },
  817. { .con_id = "cclk_g", .dt_id = TEGRA114_CLK_CCLK_G },
  818. { .con_id = "cclk_lp", .dt_id = TEGRA114_CLK_CCLK_LP },
  819. { .con_id = "sclk", .dt_id = TEGRA114_CLK_SCLK },
  820. { .con_id = "hclk", .dt_id = TEGRA114_CLK_HCLK },
  821. { .con_id = "pclk", .dt_id = TEGRA114_CLK_PCLK },
  822. { .con_id = "fuse", .dt_id = TEGRA114_CLK_FUSE },
  823. { .dev_id = "rtc-tegra", .dt_id = TEGRA114_CLK_RTC },
  824. { .dev_id = "timer", .dt_id = TEGRA114_CLK_TIMER },
  825. };
  826. static const char *mux_pllm_pllc2_c_c3_pllp_plla[] = {
  827. "pll_m", "pll_c2", "pll_c", "pll_c3", "pll_p", "pll_a_out0"
  828. };
  829. static u32 mux_pllm_pllc2_c_c3_pllp_plla_idx[] = {
  830. [0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 6,
  831. };
  832. static struct tegra_audio_clk_info tegra114_audio_plls[] = {
  833. { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_p_out1" },
  834. };
  835. static struct clk **clks;
  836. static unsigned long osc_freq;
  837. static unsigned long pll_ref_freq;
  838. static void __init tegra114_fixed_clk_init(void __iomem *clk_base)
  839. {
  840. struct clk *clk;
  841. /* clk_32k */
  842. clk = clk_register_fixed_rate(NULL, "clk_32k", NULL, 0, 32768);
  843. clks[TEGRA114_CLK_CLK_32K] = clk;
  844. /* clk_m_div2 */
  845. clk = clk_register_fixed_factor(NULL, "clk_m_div2", "clk_m",
  846. CLK_SET_RATE_PARENT, 1, 2);
  847. clks[TEGRA114_CLK_CLK_M_DIV2] = clk;
  848. /* clk_m_div4 */
  849. clk = clk_register_fixed_factor(NULL, "clk_m_div4", "clk_m",
  850. CLK_SET_RATE_PARENT, 1, 4);
  851. clks[TEGRA114_CLK_CLK_M_DIV4] = clk;
  852. }
  853. static void __init tegra114_pll_init(void __iomem *clk_base,
  854. void __iomem *pmc)
  855. {
  856. struct clk *clk;
  857. /* PLLC */
  858. clk = tegra_clk_register_pllxc("pll_c", "pll_ref", clk_base,
  859. pmc, 0, &pll_c_params, NULL);
  860. clks[TEGRA114_CLK_PLL_C] = clk;
  861. /* PLLC_OUT1 */
  862. clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c",
  863. clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  864. 8, 8, 1, NULL);
  865. clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div",
  866. clk_base + PLLC_OUT, 1, 0,
  867. CLK_SET_RATE_PARENT, 0, NULL);
  868. clks[TEGRA114_CLK_PLL_C_OUT1] = clk;
  869. /* PLLC2 */
  870. clk = tegra_clk_register_pllc("pll_c2", "pll_ref", clk_base, pmc, 0,
  871. &pll_c2_params, NULL);
  872. clks[TEGRA114_CLK_PLL_C2] = clk;
  873. /* PLLC3 */
  874. clk = tegra_clk_register_pllc("pll_c3", "pll_ref", clk_base, pmc, 0,
  875. &pll_c3_params, NULL);
  876. clks[TEGRA114_CLK_PLL_C3] = clk;
  877. /* PLLM */
  878. clk = tegra_clk_register_pllm("pll_m", "pll_ref", clk_base, pmc,
  879. CLK_IGNORE_UNUSED | CLK_SET_RATE_GATE,
  880. &pll_m_params, NULL);
  881. clks[TEGRA114_CLK_PLL_M] = clk;
  882. /* PLLM_OUT1 */
  883. clk = tegra_clk_register_divider("pll_m_out1_div", "pll_m",
  884. clk_base + PLLM_OUT, 0, TEGRA_DIVIDER_ROUND_UP,
  885. 8, 8, 1, NULL);
  886. clk = tegra_clk_register_pll_out("pll_m_out1", "pll_m_out1_div",
  887. clk_base + PLLM_OUT, 1, 0, CLK_IGNORE_UNUSED |
  888. CLK_SET_RATE_PARENT, 0, NULL);
  889. clks[TEGRA114_CLK_PLL_M_OUT1] = clk;
  890. /* PLLM_UD */
  891. clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m",
  892. CLK_SET_RATE_PARENT, 1, 1);
  893. /* PLLU */
  894. clk = tegra_clk_register_pllu_tegra114("pll_u", "pll_ref", clk_base, 0,
  895. &pll_u_params, &pll_u_lock);
  896. clks[TEGRA114_CLK_PLL_U] = clk;
  897. /* PLLU_480M */
  898. clk = clk_register_gate(NULL, "pll_u_480M", "pll_u",
  899. CLK_SET_RATE_PARENT, clk_base + PLLU_BASE,
  900. 22, 0, &pll_u_lock);
  901. clks[TEGRA114_CLK_PLL_U_480M] = clk;
  902. /* PLLU_60M */
  903. clk = clk_register_fixed_factor(NULL, "pll_u_60M", "pll_u",
  904. CLK_SET_RATE_PARENT, 1, 8);
  905. clks[TEGRA114_CLK_PLL_U_60M] = clk;
  906. /* PLLU_48M */
  907. clk = clk_register_fixed_factor(NULL, "pll_u_48M", "pll_u",
  908. CLK_SET_RATE_PARENT, 1, 10);
  909. clks[TEGRA114_CLK_PLL_U_48M] = clk;
  910. /* PLLU_12M */
  911. clk = clk_register_fixed_factor(NULL, "pll_u_12M", "pll_u",
  912. CLK_SET_RATE_PARENT, 1, 40);
  913. clks[TEGRA114_CLK_PLL_U_12M] = clk;
  914. /* PLLD */
  915. clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0,
  916. &pll_d_params, &pll_d_lock);
  917. clks[TEGRA114_CLK_PLL_D] = clk;
  918. /* PLLD_OUT0 */
  919. clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d",
  920. CLK_SET_RATE_PARENT, 1, 2);
  921. clks[TEGRA114_CLK_PLL_D_OUT0] = clk;
  922. /* PLLD2 */
  923. clk = tegra_clk_register_pll("pll_d2", "pll_ref", clk_base, pmc, 0,
  924. &pll_d2_params, &pll_d2_lock);
  925. clks[TEGRA114_CLK_PLL_D2] = clk;
  926. /* PLLD2_OUT0 */
  927. clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2",
  928. CLK_SET_RATE_PARENT, 1, 2);
  929. clks[TEGRA114_CLK_PLL_D2_OUT0] = clk;
  930. /* PLLRE */
  931. clk = tegra_clk_register_pllre("pll_re_vco", "pll_ref", clk_base, pmc,
  932. 0, &pll_re_vco_params, &pll_re_lock, pll_ref_freq);
  933. clks[TEGRA114_CLK_PLL_RE_VCO] = clk;
  934. clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0,
  935. clk_base + PLLRE_BASE, 16, 4, 0,
  936. pll_re_div_table, &pll_re_lock);
  937. clks[TEGRA114_CLK_PLL_RE_OUT] = clk;
  938. /* PLLE */
  939. clk = tegra_clk_register_plle_tegra114("pll_e_out0", "pll_ref",
  940. clk_base, 0, &pll_e_params, NULL);
  941. clks[TEGRA114_CLK_PLL_E_OUT0] = clk;
  942. }
  943. #define CLK_SOURCE_VI_SENSOR 0x1a8
  944. static struct tegra_periph_init_data tegra_periph_clk_list[] = {
  945. MUX8("vi_sensor", mux_pllm_pllc2_c_c3_pllp_plla, CLK_SOURCE_VI_SENSOR, 20, TEGRA_PERIPH_NO_RESET, TEGRA114_CLK_VI_SENSOR),
  946. };
  947. static __init void tegra114_periph_clk_init(void __iomem *clk_base,
  948. void __iomem *pmc_base)
  949. {
  950. struct clk *clk;
  951. struct tegra_periph_init_data *data;
  952. unsigned int i;
  953. /* xusb_ss_div2 */
  954. clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0,
  955. 1, 2);
  956. clks[TEGRA114_CLK_XUSB_SS_DIV2] = clk;
  957. /* dsia mux */
  958. clk = clk_register_mux(NULL, "dsia_mux", mux_plld_out0_plld2_out0,
  959. ARRAY_SIZE(mux_plld_out0_plld2_out0),
  960. CLK_SET_RATE_NO_REPARENT,
  961. clk_base + PLLD_BASE, 25, 1, 0, &pll_d_lock);
  962. clks[TEGRA114_CLK_DSIA_MUX] = clk;
  963. /* dsib mux */
  964. clk = clk_register_mux(NULL, "dsib_mux", mux_plld_out0_plld2_out0,
  965. ARRAY_SIZE(mux_plld_out0_plld2_out0),
  966. CLK_SET_RATE_NO_REPARENT,
  967. clk_base + PLLD2_BASE, 25, 1, 0, &pll_d2_lock);
  968. clks[TEGRA114_CLK_DSIB_MUX] = clk;
  969. clk = tegra_clk_register_periph_gate("dsia", "dsia_mux", 0, clk_base,
  970. 0, 48, periph_clk_enb_refcnt);
  971. clks[TEGRA114_CLK_DSIA] = clk;
  972. clk = tegra_clk_register_periph_gate("dsib", "dsib_mux", 0, clk_base,
  973. 0, 82, periph_clk_enb_refcnt);
  974. clks[TEGRA114_CLK_DSIB] = clk;
  975. /* emc mux */
  976. clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
  977. ARRAY_SIZE(mux_pllmcp_clkm),
  978. CLK_SET_RATE_NO_REPARENT,
  979. clk_base + CLK_SOURCE_EMC,
  980. 29, 3, 0, &emc_lock);
  981. clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
  982. &emc_lock);
  983. clks[TEGRA114_CLK_MC] = clk;
  984. clk = tegra_clk_register_periph_gate("mipi-cal", "clk_m", 0, clk_base,
  985. CLK_SET_RATE_PARENT, 56,
  986. periph_clk_enb_refcnt);
  987. clks[TEGRA114_CLK_MIPI_CAL] = clk;
  988. for (i = 0; i < ARRAY_SIZE(tegra_periph_clk_list); i++) {
  989. data = &tegra_periph_clk_list[i];
  990. clk = tegra_clk_register_periph(data->name,
  991. data->p.parent_names, data->num_parents,
  992. &data->periph, clk_base, data->offset, data->flags);
  993. clks[data->clk_id] = clk;
  994. }
  995. tegra_periph_clk_init(clk_base, pmc_base, tegra114_clks,
  996. &pll_p_params);
  997. }
  998. /* Tegra114 CPU clock and reset control functions */
  999. static void tegra114_wait_cpu_in_reset(u32 cpu)
  1000. {
  1001. unsigned int reg;
  1002. do {
  1003. reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS);
  1004. cpu_relax();
  1005. } while (!(reg & (1 << cpu))); /* check CPU been reset or not */
  1006. }
  1007. static void tegra114_disable_cpu_clock(u32 cpu)
  1008. {
  1009. /* flow controller would take care in the power sequence. */
  1010. }
  1011. #ifdef CONFIG_PM_SLEEP
  1012. static void tegra114_cpu_clock_suspend(void)
  1013. {
  1014. /* switch coresite to clk_m, save off original source */
  1015. tegra114_cpu_clk_sctx.clk_csite_src =
  1016. readl(clk_base + CLK_SOURCE_CSITE);
  1017. writel(3 << 30, clk_base + CLK_SOURCE_CSITE);
  1018. tegra114_cpu_clk_sctx.cclkg_burst =
  1019. readl(clk_base + CCLKG_BURST_POLICY);
  1020. tegra114_cpu_clk_sctx.cclkg_divider =
  1021. readl(clk_base + CCLKG_BURST_POLICY + 4);
  1022. }
  1023. static void tegra114_cpu_clock_resume(void)
  1024. {
  1025. writel(tegra114_cpu_clk_sctx.clk_csite_src,
  1026. clk_base + CLK_SOURCE_CSITE);
  1027. writel(tegra114_cpu_clk_sctx.cclkg_burst,
  1028. clk_base + CCLKG_BURST_POLICY);
  1029. writel(tegra114_cpu_clk_sctx.cclkg_divider,
  1030. clk_base + CCLKG_BURST_POLICY + 4);
  1031. }
  1032. #endif
  1033. static struct tegra_cpu_car_ops tegra114_cpu_car_ops = {
  1034. .wait_for_reset = tegra114_wait_cpu_in_reset,
  1035. .disable_clock = tegra114_disable_cpu_clock,
  1036. #ifdef CONFIG_PM_SLEEP
  1037. .suspend = tegra114_cpu_clock_suspend,
  1038. .resume = tegra114_cpu_clock_resume,
  1039. #endif
  1040. };
  1041. static const struct of_device_id pmc_match[] __initconst = {
  1042. { .compatible = "nvidia,tegra114-pmc" },
  1043. { },
  1044. };
  1045. /*
  1046. * dfll_soc/dfll_ref apparently must be kept enabled, otherwise I2C5
  1047. * breaks
  1048. */
  1049. static struct tegra_clk_init_table init_table[] __initdata = {
  1050. { TEGRA114_CLK_UARTA, TEGRA114_CLK_PLL_P, 408000000, 0 },
  1051. { TEGRA114_CLK_UARTB, TEGRA114_CLK_PLL_P, 408000000, 0 },
  1052. { TEGRA114_CLK_UARTC, TEGRA114_CLK_PLL_P, 408000000, 0 },
  1053. { TEGRA114_CLK_UARTD, TEGRA114_CLK_PLL_P, 408000000, 0 },
  1054. { TEGRA114_CLK_PLL_A, TEGRA114_CLK_CLK_MAX, 564480000, 1 },
  1055. { TEGRA114_CLK_PLL_A_OUT0, TEGRA114_CLK_CLK_MAX, 11289600, 1 },
  1056. { TEGRA114_CLK_EXTERN1, TEGRA114_CLK_PLL_A_OUT0, 0, 1 },
  1057. { TEGRA114_CLK_CLK_OUT_1_MUX, TEGRA114_CLK_EXTERN1, 0, 1 },
  1058. { TEGRA114_CLK_CLK_OUT_1, TEGRA114_CLK_CLK_MAX, 0, 1 },
  1059. { TEGRA114_CLK_I2S0, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 },
  1060. { TEGRA114_CLK_I2S1, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 },
  1061. { TEGRA114_CLK_I2S2, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 },
  1062. { TEGRA114_CLK_I2S3, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 },
  1063. { TEGRA114_CLK_I2S4, TEGRA114_CLK_PLL_A_OUT0, 11289600, 0 },
  1064. { TEGRA114_CLK_HOST1X, TEGRA114_CLK_PLL_P, 136000000, 0 },
  1065. { TEGRA114_CLK_DFLL_SOC, TEGRA114_CLK_PLL_P, 51000000, 1 },
  1066. { TEGRA114_CLK_DFLL_REF, TEGRA114_CLK_PLL_P, 51000000, 1 },
  1067. { TEGRA114_CLK_DISP1, TEGRA114_CLK_PLL_P, 0, 0 },
  1068. { TEGRA114_CLK_DISP2, TEGRA114_CLK_PLL_P, 0, 0 },
  1069. { TEGRA114_CLK_GR2D, TEGRA114_CLK_PLL_C2, 300000000, 0 },
  1070. { TEGRA114_CLK_GR3D, TEGRA114_CLK_PLL_C2, 300000000, 0 },
  1071. { TEGRA114_CLK_DSIALP, TEGRA114_CLK_PLL_P, 68000000, 0 },
  1072. { TEGRA114_CLK_DSIBLP, TEGRA114_CLK_PLL_P, 68000000, 0 },
  1073. { TEGRA114_CLK_PLL_RE_VCO, TEGRA114_CLK_CLK_MAX, 612000000, 0 },
  1074. { TEGRA114_CLK_XUSB_SS_SRC, TEGRA114_CLK_PLL_RE_OUT, 122400000, 0 },
  1075. { TEGRA114_CLK_XUSB_FS_SRC, TEGRA114_CLK_PLL_U_48M, 48000000, 0 },
  1076. { TEGRA114_CLK_XUSB_HS_SRC, TEGRA114_CLK_XUSB_SS_DIV2, 61200000, 0 },
  1077. { TEGRA114_CLK_XUSB_FALCON_SRC, TEGRA114_CLK_PLL_P, 204000000, 0 },
  1078. { TEGRA114_CLK_XUSB_HOST_SRC, TEGRA114_CLK_PLL_P, 102000000, 0 },
  1079. /* must be the last entry */
  1080. { TEGRA114_CLK_CLK_MAX, TEGRA114_CLK_CLK_MAX, 0, 0 },
  1081. };
  1082. static void __init tegra114_clock_apply_init_table(void)
  1083. {
  1084. tegra_init_from_table(init_table, clks, TEGRA114_CLK_CLK_MAX);
  1085. }
  1086. /**
  1087. * tegra114_car_barrier - wait for pending writes to the CAR to complete
  1088. *
  1089. * Wait for any outstanding writes to the CAR MMIO space from this CPU
  1090. * to complete before continuing execution. No return value.
  1091. */
  1092. static void tegra114_car_barrier(void)
  1093. {
  1094. wmb(); /* probably unnecessary */
  1095. readl_relaxed(clk_base + CPU_FINETRIM_SELECT);
  1096. }
  1097. /**
  1098. * tegra114_clock_tune_cpu_trimmers_high - use high-voltage propagation delays
  1099. *
  1100. * When the CPU rail voltage is in the high-voltage range, use the
  1101. * built-in hardwired clock propagation delays in the CPU clock
  1102. * shaper. No return value.
  1103. */
  1104. void tegra114_clock_tune_cpu_trimmers_high(void)
  1105. {
  1106. u32 select = 0;
  1107. /* Use hardwired rise->rise & fall->fall clock propagation delays */
  1108. select |= ~(CPU_FINETRIM_1_FCPU_1 | CPU_FINETRIM_1_FCPU_2 |
  1109. CPU_FINETRIM_1_FCPU_3 | CPU_FINETRIM_1_FCPU_4 |
  1110. CPU_FINETRIM_1_FCPU_5 | CPU_FINETRIM_1_FCPU_6);
  1111. writel_relaxed(select, clk_base + CPU_FINETRIM_SELECT);
  1112. tegra114_car_barrier();
  1113. }
  1114. EXPORT_SYMBOL(tegra114_clock_tune_cpu_trimmers_high);
  1115. /**
  1116. * tegra114_clock_tune_cpu_trimmers_low - use low-voltage propagation delays
  1117. *
  1118. * When the CPU rail voltage is in the low-voltage range, use the
  1119. * extended clock propagation delays set by
  1120. * tegra114_clock_tune_cpu_trimmers_init(). The intention is to
  1121. * maintain the input clock duty cycle that the FCPU subsystem
  1122. * expects. No return value.
  1123. */
  1124. void tegra114_clock_tune_cpu_trimmers_low(void)
  1125. {
  1126. u32 select = 0;
  1127. /*
  1128. * Use software-specified rise->rise & fall->fall clock
  1129. * propagation delays (from
  1130. * tegra114_clock_tune_cpu_trimmers_init()
  1131. */
  1132. select |= (CPU_FINETRIM_1_FCPU_1 | CPU_FINETRIM_1_FCPU_2 |
  1133. CPU_FINETRIM_1_FCPU_3 | CPU_FINETRIM_1_FCPU_4 |
  1134. CPU_FINETRIM_1_FCPU_5 | CPU_FINETRIM_1_FCPU_6);
  1135. writel_relaxed(select, clk_base + CPU_FINETRIM_SELECT);
  1136. tegra114_car_barrier();
  1137. }
  1138. EXPORT_SYMBOL(tegra114_clock_tune_cpu_trimmers_low);
  1139. /**
  1140. * tegra114_clock_tune_cpu_trimmers_init - set up and enable clk prop delays
  1141. *
  1142. * Program extended clock propagation delays into the FCPU clock
  1143. * shaper and enable them. XXX Define the purpose - peak current
  1144. * reduction? No return value.
  1145. */
  1146. /* XXX Initial voltage rail state assumption issues? */
  1147. void tegra114_clock_tune_cpu_trimmers_init(void)
  1148. {
  1149. u32 dr = 0, r = 0;
  1150. /* Increment the rise->rise clock delay by four steps */
  1151. r |= (CPU_FINETRIM_R_FCPU_1_MASK | CPU_FINETRIM_R_FCPU_2_MASK |
  1152. CPU_FINETRIM_R_FCPU_3_MASK | CPU_FINETRIM_R_FCPU_4_MASK |
  1153. CPU_FINETRIM_R_FCPU_5_MASK | CPU_FINETRIM_R_FCPU_6_MASK);
  1154. writel_relaxed(r, clk_base + CPU_FINETRIM_R);
  1155. /*
  1156. * Use the rise->rise clock propagation delay specified in the
  1157. * r field
  1158. */
  1159. dr |= (CPU_FINETRIM_1_FCPU_1 | CPU_FINETRIM_1_FCPU_2 |
  1160. CPU_FINETRIM_1_FCPU_3 | CPU_FINETRIM_1_FCPU_4 |
  1161. CPU_FINETRIM_1_FCPU_5 | CPU_FINETRIM_1_FCPU_6);
  1162. writel_relaxed(dr, clk_base + CPU_FINETRIM_DR);
  1163. tegra114_clock_tune_cpu_trimmers_low();
  1164. }
  1165. EXPORT_SYMBOL(tegra114_clock_tune_cpu_trimmers_init);
  1166. /**
  1167. * tegra114_clock_assert_dfll_dvco_reset - assert the DFLL's DVCO reset
  1168. *
  1169. * Assert the reset line of the DFLL's DVCO. No return value.
  1170. */
  1171. void tegra114_clock_assert_dfll_dvco_reset(void)
  1172. {
  1173. u32 v;
  1174. v = readl_relaxed(clk_base + RST_DFLL_DVCO);
  1175. v |= (1 << DVFS_DFLL_RESET_SHIFT);
  1176. writel_relaxed(v, clk_base + RST_DFLL_DVCO);
  1177. tegra114_car_barrier();
  1178. }
  1179. EXPORT_SYMBOL(tegra114_clock_assert_dfll_dvco_reset);
  1180. /**
  1181. * tegra114_clock_deassert_dfll_dvco_reset - deassert the DFLL's DVCO reset
  1182. *
  1183. * Deassert the reset line of the DFLL's DVCO, allowing the DVCO to
  1184. * operate. No return value.
  1185. */
  1186. void tegra114_clock_deassert_dfll_dvco_reset(void)
  1187. {
  1188. u32 v;
  1189. v = readl_relaxed(clk_base + RST_DFLL_DVCO);
  1190. v &= ~(1 << DVFS_DFLL_RESET_SHIFT);
  1191. writel_relaxed(v, clk_base + RST_DFLL_DVCO);
  1192. tegra114_car_barrier();
  1193. }
  1194. EXPORT_SYMBOL(tegra114_clock_deassert_dfll_dvco_reset);
  1195. static void __init tegra114_clock_init(struct device_node *np)
  1196. {
  1197. struct device_node *node;
  1198. clk_base = of_iomap(np, 0);
  1199. if (!clk_base) {
  1200. pr_err("ioremap tegra114 CAR failed\n");
  1201. return;
  1202. }
  1203. node = of_find_matching_node(NULL, pmc_match);
  1204. if (!node) {
  1205. pr_err("Failed to find pmc node\n");
  1206. WARN_ON(1);
  1207. return;
  1208. }
  1209. pmc_base = of_iomap(node, 0);
  1210. if (!pmc_base) {
  1211. pr_err("Can't map pmc registers\n");
  1212. WARN_ON(1);
  1213. return;
  1214. }
  1215. clks = tegra_clk_init(clk_base, TEGRA114_CLK_CLK_MAX,
  1216. TEGRA114_CLK_PERIPH_BANKS);
  1217. if (!clks)
  1218. return;
  1219. if (tegra_osc_clk_init(clk_base, tegra114_clks, tegra114_input_freq,
  1220. ARRAY_SIZE(tegra114_input_freq), 1, &osc_freq,
  1221. &pll_ref_freq) < 0)
  1222. return;
  1223. tegra114_fixed_clk_init(clk_base);
  1224. tegra114_pll_init(clk_base, pmc_base);
  1225. tegra114_periph_clk_init(clk_base, pmc_base);
  1226. tegra_audio_clk_init(clk_base, pmc_base, tegra114_clks,
  1227. tegra114_audio_plls,
  1228. ARRAY_SIZE(tegra114_audio_plls));
  1229. tegra_pmc_clk_init(pmc_base, tegra114_clks);
  1230. tegra_super_clk_gen4_init(clk_base, pmc_base, tegra114_clks,
  1231. &pll_x_params);
  1232. tegra_add_of_provider(np);
  1233. tegra_register_devclks(devclks, ARRAY_SIZE(devclks));
  1234. tegra_clk_apply_init_table = tegra114_clock_apply_init_table;
  1235. tegra_cpu_car_ops = &tegra114_cpu_car_ops;
  1236. }
  1237. CLK_OF_DECLARE(tegra114, "nvidia,tegra114-car", tegra114_clock_init);