lcc-ipq806x.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2014, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/bitops.h>
  7. #include <linux/err.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/clk-provider.h>
  12. #include <linux/regmap.h>
  13. #include <dt-bindings/clock/qcom,lcc-ipq806x.h>
  14. #include "common.h"
  15. #include "clk-regmap.h"
  16. #include "clk-pll.h"
  17. #include "clk-rcg.h"
  18. #include "clk-branch.h"
  19. #include "clk-regmap-divider.h"
  20. #include "clk-regmap-mux.h"
  21. #include "reset.h"
  22. static struct clk_pll pll4 = {
  23. .l_reg = 0x4,
  24. .m_reg = 0x8,
  25. .n_reg = 0xc,
  26. .config_reg = 0x14,
  27. .mode_reg = 0x0,
  28. .status_reg = 0x18,
  29. .status_bit = 16,
  30. .clkr.hw.init = &(struct clk_init_data){
  31. .name = "pll4",
  32. .parent_data = &(const struct clk_parent_data) {
  33. .fw_name = "pxo", .name = "pxo_board",
  34. },
  35. .num_parents = 1,
  36. .ops = &clk_pll_ops,
  37. },
  38. };
  39. static const struct pll_config pll4_config = {
  40. .l = 0xf,
  41. .m = 0x91,
  42. .n = 0xc7,
  43. .vco_val = 0x0,
  44. .vco_mask = BIT(17) | BIT(16),
  45. .pre_div_val = 0x0,
  46. .pre_div_mask = BIT(19),
  47. .post_div_val = 0x0,
  48. .post_div_mask = BIT(21) | BIT(20),
  49. .mn_ena_mask = BIT(22),
  50. .main_output_mask = BIT(23),
  51. };
  52. enum {
  53. P_PXO,
  54. P_PLL4,
  55. };
  56. static const struct parent_map lcc_pxo_pll4_map[] = {
  57. { P_PXO, 0 },
  58. { P_PLL4, 2 }
  59. };
  60. static const struct clk_parent_data lcc_pxo_pll4[] = {
  61. { .fw_name = "pxo", .name = "pxo_board" },
  62. { .fw_name = "pll4_vote", .name = "pll4_vote" },
  63. };
  64. static const struct freq_tbl clk_tbl_aif_mi2s[] = {
  65. { 1024000, P_PLL4, 4, 1, 96 },
  66. { 1411200, P_PLL4, 4, 2, 139 },
  67. { 1536000, P_PLL4, 4, 1, 64 },
  68. { 2048000, P_PLL4, 4, 1, 48 },
  69. { 2116800, P_PLL4, 4, 2, 93 },
  70. { 2304000, P_PLL4, 4, 2, 85 },
  71. { 2822400, P_PLL4, 4, 6, 209 },
  72. { 3072000, P_PLL4, 4, 1, 32 },
  73. { 3175200, P_PLL4, 4, 1, 31 },
  74. { 4096000, P_PLL4, 4, 1, 24 },
  75. { 4233600, P_PLL4, 4, 9, 209 },
  76. { 4608000, P_PLL4, 4, 3, 64 },
  77. { 5644800, P_PLL4, 4, 12, 209 },
  78. { 6144000, P_PLL4, 4, 1, 16 },
  79. { 6350400, P_PLL4, 4, 2, 31 },
  80. { 8192000, P_PLL4, 4, 1, 12 },
  81. { 8467200, P_PLL4, 4, 18, 209 },
  82. { 9216000, P_PLL4, 4, 3, 32 },
  83. { 11289600, P_PLL4, 4, 24, 209 },
  84. { 12288000, P_PLL4, 4, 1, 8 },
  85. { 12700800, P_PLL4, 4, 27, 209 },
  86. { 13824000, P_PLL4, 4, 9, 64 },
  87. { 16384000, P_PLL4, 4, 1, 6 },
  88. { 16934400, P_PLL4, 4, 41, 238 },
  89. { 18432000, P_PLL4, 4, 3, 16 },
  90. { 22579200, P_PLL4, 2, 24, 209 },
  91. { 24576000, P_PLL4, 4, 1, 4 },
  92. { 27648000, P_PLL4, 4, 9, 32 },
  93. { 33868800, P_PLL4, 4, 41, 119 },
  94. { 36864000, P_PLL4, 4, 3, 8 },
  95. { 45158400, P_PLL4, 1, 24, 209 },
  96. { 49152000, P_PLL4, 4, 1, 2 },
  97. { 50803200, P_PLL4, 1, 27, 209 },
  98. { }
  99. };
  100. static struct clk_rcg mi2s_osr_src = {
  101. .ns_reg = 0x48,
  102. .md_reg = 0x4c,
  103. .mn = {
  104. .mnctr_en_bit = 8,
  105. .mnctr_reset_bit = 7,
  106. .mnctr_mode_shift = 5,
  107. .n_val_shift = 24,
  108. .m_val_shift = 8,
  109. .width = 8,
  110. },
  111. .p = {
  112. .pre_div_shift = 3,
  113. .pre_div_width = 2,
  114. },
  115. .s = {
  116. .src_sel_shift = 0,
  117. .parent_map = lcc_pxo_pll4_map,
  118. },
  119. .freq_tbl = clk_tbl_aif_mi2s,
  120. .clkr = {
  121. .enable_reg = 0x48,
  122. .enable_mask = BIT(9),
  123. .hw.init = &(struct clk_init_data){
  124. .name = "mi2s_osr_src",
  125. .parent_data = lcc_pxo_pll4,
  126. .num_parents = ARRAY_SIZE(lcc_pxo_pll4),
  127. .ops = &clk_rcg_ops,
  128. .flags = CLK_SET_RATE_GATE,
  129. },
  130. },
  131. };
  132. static struct clk_branch mi2s_osr_clk = {
  133. .halt_reg = 0x50,
  134. .halt_bit = 1,
  135. .halt_check = BRANCH_HALT_ENABLE,
  136. .clkr = {
  137. .enable_reg = 0x48,
  138. .enable_mask = BIT(17),
  139. .hw.init = &(struct clk_init_data){
  140. .name = "mi2s_osr_clk",
  141. .parent_hws = (const struct clk_hw*[]) {
  142. &mi2s_osr_src.clkr.hw,
  143. },
  144. .num_parents = 1,
  145. .ops = &clk_branch_ops,
  146. .flags = CLK_SET_RATE_PARENT,
  147. },
  148. },
  149. };
  150. static struct clk_regmap_div mi2s_div_clk = {
  151. .reg = 0x48,
  152. .shift = 10,
  153. .width = 4,
  154. .clkr = {
  155. .hw.init = &(struct clk_init_data){
  156. .name = "mi2s_div_clk",
  157. .parent_hws = (const struct clk_hw*[]) {
  158. &mi2s_osr_src.clkr.hw,
  159. },
  160. .num_parents = 1,
  161. .ops = &clk_regmap_div_ops,
  162. },
  163. },
  164. };
  165. static struct clk_branch mi2s_bit_div_clk = {
  166. .halt_reg = 0x50,
  167. .halt_bit = 0,
  168. .halt_check = BRANCH_HALT_ENABLE,
  169. .clkr = {
  170. .enable_reg = 0x48,
  171. .enable_mask = BIT(15),
  172. .hw.init = &(struct clk_init_data){
  173. .name = "mi2s_bit_div_clk",
  174. .parent_hws = (const struct clk_hw*[]) {
  175. &mi2s_div_clk.clkr.hw,
  176. },
  177. .num_parents = 1,
  178. .ops = &clk_branch_ops,
  179. .flags = CLK_SET_RATE_PARENT,
  180. },
  181. },
  182. };
  183. static const struct clk_parent_data lcc_mi2s_bit_div_codec_clk[] = {
  184. { .hw = &mi2s_bit_div_clk.clkr.hw, },
  185. { .fw_name = "mi2s_codec", .name = "mi2s_codec_clk" },
  186. };
  187. static struct clk_regmap_mux mi2s_bit_clk = {
  188. .reg = 0x48,
  189. .shift = 14,
  190. .width = 1,
  191. .clkr = {
  192. .hw.init = &(struct clk_init_data){
  193. .name = "mi2s_bit_clk",
  194. .parent_data = lcc_mi2s_bit_div_codec_clk,
  195. .num_parents = ARRAY_SIZE(lcc_mi2s_bit_div_codec_clk),
  196. .ops = &clk_regmap_mux_closest_ops,
  197. .flags = CLK_SET_RATE_PARENT,
  198. },
  199. },
  200. };
  201. static const struct freq_tbl clk_tbl_pcm[] = {
  202. { 64000, P_PLL4, 4, 1, 1536 },
  203. { 128000, P_PLL4, 4, 1, 768 },
  204. { 256000, P_PLL4, 4, 1, 384 },
  205. { 512000, P_PLL4, 4, 1, 192 },
  206. { 1024000, P_PLL4, 4, 1, 96 },
  207. { 2048000, P_PLL4, 4, 1, 48 },
  208. { },
  209. };
  210. static struct clk_rcg pcm_src = {
  211. .ns_reg = 0x54,
  212. .md_reg = 0x58,
  213. .mn = {
  214. .mnctr_en_bit = 8,
  215. .mnctr_reset_bit = 7,
  216. .mnctr_mode_shift = 5,
  217. .n_val_shift = 16,
  218. .m_val_shift = 16,
  219. .width = 16,
  220. },
  221. .p = {
  222. .pre_div_shift = 3,
  223. .pre_div_width = 2,
  224. },
  225. .s = {
  226. .src_sel_shift = 0,
  227. .parent_map = lcc_pxo_pll4_map,
  228. },
  229. .freq_tbl = clk_tbl_pcm,
  230. .clkr = {
  231. .enable_reg = 0x54,
  232. .enable_mask = BIT(9),
  233. .hw.init = &(struct clk_init_data){
  234. .name = "pcm_src",
  235. .parent_data = lcc_pxo_pll4,
  236. .num_parents = ARRAY_SIZE(lcc_pxo_pll4),
  237. .ops = &clk_rcg_ops,
  238. .flags = CLK_SET_RATE_GATE,
  239. },
  240. },
  241. };
  242. static struct clk_branch pcm_clk_out = {
  243. .halt_reg = 0x5c,
  244. .halt_bit = 0,
  245. .halt_check = BRANCH_HALT_ENABLE,
  246. .clkr = {
  247. .enable_reg = 0x54,
  248. .enable_mask = BIT(11),
  249. .hw.init = &(struct clk_init_data){
  250. .name = "pcm_clk_out",
  251. .parent_hws = (const struct clk_hw*[]) {
  252. &pcm_src.clkr.hw,
  253. },
  254. .num_parents = 1,
  255. .ops = &clk_branch_ops,
  256. .flags = CLK_SET_RATE_PARENT,
  257. },
  258. },
  259. };
  260. static const struct clk_parent_data lcc_pcm_clk_out_codec_clk[] = {
  261. { .hw = &pcm_clk_out.clkr.hw, },
  262. { .fw_name = "pcm_codec_clk", .name = "pcm_codec_clk" },
  263. };
  264. static struct clk_regmap_mux pcm_clk = {
  265. .reg = 0x54,
  266. .shift = 10,
  267. .width = 1,
  268. .clkr = {
  269. .hw.init = &(struct clk_init_data){
  270. .name = "pcm_clk",
  271. .parent_data = lcc_pcm_clk_out_codec_clk,
  272. .num_parents = ARRAY_SIZE(lcc_pcm_clk_out_codec_clk),
  273. .ops = &clk_regmap_mux_closest_ops,
  274. .flags = CLK_SET_RATE_PARENT,
  275. },
  276. },
  277. };
  278. static const struct freq_tbl clk_tbl_aif_osr[] = {
  279. { 2822400, P_PLL4, 1, 147, 20480 },
  280. { 4096000, P_PLL4, 1, 1, 96 },
  281. { 5644800, P_PLL4, 1, 147, 10240 },
  282. { 6144000, P_PLL4, 1, 1, 64 },
  283. { 11289600, P_PLL4, 1, 147, 5120 },
  284. { 12288000, P_PLL4, 1, 1, 32 },
  285. { 22579200, P_PLL4, 1, 147, 2560 },
  286. { 24576000, P_PLL4, 1, 1, 16 },
  287. { },
  288. };
  289. static struct clk_rcg spdif_src = {
  290. .ns_reg = 0xcc,
  291. .md_reg = 0xd0,
  292. .mn = {
  293. .mnctr_en_bit = 8,
  294. .mnctr_reset_bit = 7,
  295. .mnctr_mode_shift = 5,
  296. .n_val_shift = 16,
  297. .m_val_shift = 16,
  298. .width = 8,
  299. },
  300. .p = {
  301. .pre_div_shift = 3,
  302. .pre_div_width = 2,
  303. },
  304. .s = {
  305. .src_sel_shift = 0,
  306. .parent_map = lcc_pxo_pll4_map,
  307. },
  308. .freq_tbl = clk_tbl_aif_osr,
  309. .clkr = {
  310. .enable_reg = 0xcc,
  311. .enable_mask = BIT(9),
  312. .hw.init = &(struct clk_init_data){
  313. .name = "spdif_src",
  314. .parent_data = lcc_pxo_pll4,
  315. .num_parents = ARRAY_SIZE(lcc_pxo_pll4),
  316. .ops = &clk_rcg_ops,
  317. .flags = CLK_SET_RATE_GATE,
  318. },
  319. },
  320. };
  321. static struct clk_branch spdif_clk = {
  322. .halt_reg = 0xd4,
  323. .halt_bit = 1,
  324. .halt_check = BRANCH_HALT_ENABLE,
  325. .clkr = {
  326. .enable_reg = 0xcc,
  327. .enable_mask = BIT(12),
  328. .hw.init = &(struct clk_init_data){
  329. .name = "spdif_clk",
  330. .parent_hws = (const struct clk_hw*[]) {
  331. &spdif_src.clkr.hw,
  332. },
  333. .num_parents = 1,
  334. .ops = &clk_branch_ops,
  335. .flags = CLK_SET_RATE_PARENT,
  336. },
  337. },
  338. };
  339. static const struct freq_tbl clk_tbl_ahbix[] = {
  340. { 131072000, P_PLL4, 1, 1, 3 },
  341. { },
  342. };
  343. static struct clk_rcg ahbix_clk = {
  344. .ns_reg = 0x38,
  345. .md_reg = 0x3c,
  346. .mn = {
  347. .mnctr_en_bit = 8,
  348. .mnctr_reset_bit = 7,
  349. .mnctr_mode_shift = 5,
  350. .n_val_shift = 24,
  351. .m_val_shift = 8,
  352. .width = 8,
  353. },
  354. .p = {
  355. .pre_div_shift = 3,
  356. .pre_div_width = 2,
  357. },
  358. .s = {
  359. .src_sel_shift = 0,
  360. .parent_map = lcc_pxo_pll4_map,
  361. },
  362. .freq_tbl = clk_tbl_ahbix,
  363. .clkr = {
  364. .enable_reg = 0x38,
  365. .enable_mask = BIT(11),
  366. .hw.init = &(struct clk_init_data){
  367. .name = "ahbix",
  368. .parent_data = lcc_pxo_pll4,
  369. .num_parents = ARRAY_SIZE(lcc_pxo_pll4),
  370. .ops = &clk_rcg_lcc_ops,
  371. },
  372. },
  373. };
  374. static struct clk_regmap *lcc_ipq806x_clks[] = {
  375. [PLL4] = &pll4.clkr,
  376. [MI2S_OSR_SRC] = &mi2s_osr_src.clkr,
  377. [MI2S_OSR_CLK] = &mi2s_osr_clk.clkr,
  378. [MI2S_DIV_CLK] = &mi2s_div_clk.clkr,
  379. [MI2S_BIT_DIV_CLK] = &mi2s_bit_div_clk.clkr,
  380. [MI2S_BIT_CLK] = &mi2s_bit_clk.clkr,
  381. [PCM_SRC] = &pcm_src.clkr,
  382. [PCM_CLK_OUT] = &pcm_clk_out.clkr,
  383. [PCM_CLK] = &pcm_clk.clkr,
  384. [SPDIF_SRC] = &spdif_src.clkr,
  385. [SPDIF_CLK] = &spdif_clk.clkr,
  386. [AHBIX_CLK] = &ahbix_clk.clkr,
  387. };
  388. static const struct qcom_reset_map lcc_ipq806x_resets[] = {
  389. [LCC_PCM_RESET] = { 0x54, 13 },
  390. };
  391. static const struct regmap_config lcc_ipq806x_regmap_config = {
  392. .reg_bits = 32,
  393. .reg_stride = 4,
  394. .val_bits = 32,
  395. .max_register = 0xfc,
  396. .fast_io = true,
  397. };
  398. static const struct qcom_cc_desc lcc_ipq806x_desc = {
  399. .config = &lcc_ipq806x_regmap_config,
  400. .clks = lcc_ipq806x_clks,
  401. .num_clks = ARRAY_SIZE(lcc_ipq806x_clks),
  402. .resets = lcc_ipq806x_resets,
  403. .num_resets = ARRAY_SIZE(lcc_ipq806x_resets),
  404. };
  405. static const struct of_device_id lcc_ipq806x_match_table[] = {
  406. { .compatible = "qcom,lcc-ipq8064" },
  407. { }
  408. };
  409. MODULE_DEVICE_TABLE(of, lcc_ipq806x_match_table);
  410. static int lcc_ipq806x_probe(struct platform_device *pdev)
  411. {
  412. u32 val;
  413. struct regmap *regmap;
  414. regmap = qcom_cc_map(pdev, &lcc_ipq806x_desc);
  415. if (IS_ERR(regmap))
  416. return PTR_ERR(regmap);
  417. /* Configure the rate of PLL4 if the bootloader hasn't already */
  418. regmap_read(regmap, 0x0, &val);
  419. if (!val)
  420. clk_pll_configure_sr(&pll4, regmap, &pll4_config, true);
  421. /* Enable PLL4 source on the LPASS Primary PLL Mux */
  422. regmap_write(regmap, 0xc4, 0x1);
  423. return qcom_cc_really_probe(&pdev->dev, &lcc_ipq806x_desc, regmap);
  424. }
  425. static struct platform_driver lcc_ipq806x_driver = {
  426. .probe = lcc_ipq806x_probe,
  427. .driver = {
  428. .name = "lcc-ipq806x",
  429. .of_match_table = lcc_ipq806x_match_table,
  430. },
  431. };
  432. module_platform_driver(lcc_ipq806x_driver);
  433. MODULE_DESCRIPTION("QCOM LCC IPQ806x Driver");
  434. MODULE_LICENSE("GPL v2");
  435. MODULE_ALIAS("platform:lcc-ipq806x");