lcc-ipq806x.c 10 KB

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