lpassaudiocc-sc7280.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/clk-provider.h>
  6. #include <linux/err.h>
  7. #include <linux/kernel.h>
  8. #include <linux/module.h>
  9. #include <linux/of.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/pm_clock.h>
  12. #include <linux/pm_runtime.h>
  13. #include <linux/regmap.h>
  14. #include <dt-bindings/clock/qcom,lpass-sc7280.h>
  15. #include <dt-bindings/clock/qcom,lpassaudiocc-sc7280.h>
  16. #include "clk-alpha-pll.h"
  17. #include "clk-branch.h"
  18. #include "clk-rcg.h"
  19. #include "clk-regmap.h"
  20. #include "clk-regmap-divider.h"
  21. #include "clk-regmap-mux.h"
  22. #include "common.h"
  23. #include "gdsc.h"
  24. #include "reset.h"
  25. enum {
  26. P_BI_TCXO,
  27. P_LPASS_AON_CC_PLL_OUT_EVEN,
  28. P_LPASS_AON_CC_PLL_OUT_MAIN,
  29. P_LPASS_AON_CC_PLL_OUT_MAIN_CDIV_DIV_CLK_SRC,
  30. P_LPASS_AON_CC_PLL_OUT_ODD,
  31. P_LPASS_AUDIO_CC_PLL_OUT_AUX,
  32. P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC,
  33. P_LPASS_AUDIO_CC_PLL_MAIN_DIV_CLK,
  34. };
  35. static const struct pll_vco zonda_vco[] = {
  36. { 595200000UL, 3600000000UL, 0 },
  37. };
  38. static struct clk_branch lpass_q6ss_ahbm_clk = {
  39. .halt_reg = 0x901c,
  40. .halt_check = BRANCH_HALT,
  41. .clkr = {
  42. .enable_reg = 0x901c,
  43. .enable_mask = BIT(0),
  44. .hw.init = &(struct clk_init_data){
  45. .name = "lpass_q6ss_ahbm_clk",
  46. .ops = &clk_branch2_ops,
  47. },
  48. },
  49. };
  50. static struct clk_branch lpass_q6ss_ahbs_clk = {
  51. .halt_reg = 0x9020,
  52. .halt_check = BRANCH_HALT_VOTED,
  53. .clkr = {
  54. .enable_reg = 0x9020,
  55. .enable_mask = BIT(0),
  56. .hw.init = &(struct clk_init_data){
  57. .name = "lpass_q6ss_ahbs_clk",
  58. .ops = &clk_branch2_ops,
  59. },
  60. },
  61. };
  62. /* 1128.96MHz configuration */
  63. static const struct alpha_pll_config lpass_audio_cc_pll_config = {
  64. .l = 0x3a,
  65. .alpha = 0xcccc,
  66. .config_ctl_val = 0x08200920,
  67. .config_ctl_hi_val = 0x05002001,
  68. .config_ctl_hi1_val = 0x00000000,
  69. .user_ctl_val = 0x03000101,
  70. };
  71. static struct clk_alpha_pll lpass_audio_cc_pll = {
  72. .offset = 0x0,
  73. .vco_table = zonda_vco,
  74. .num_vco = ARRAY_SIZE(zonda_vco),
  75. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_ZONDA],
  76. .clkr = {
  77. .hw.init = &(const struct clk_init_data){
  78. .name = "lpass_audio_cc_pll",
  79. .parent_data = &(const struct clk_parent_data){
  80. .index = 0,
  81. },
  82. .num_parents = 1,
  83. .ops = &clk_alpha_pll_zonda_ops,
  84. },
  85. },
  86. };
  87. static const struct clk_div_table post_div_table_lpass_audio_cc_pll_out_aux2[] = {
  88. { 0x1, 2 },
  89. { }
  90. };
  91. static struct clk_alpha_pll_postdiv lpass_audio_cc_pll_out_aux2 = {
  92. .offset = 0x0,
  93. .post_div_shift = 8,
  94. .post_div_table = post_div_table_lpass_audio_cc_pll_out_aux2,
  95. .num_post_div = ARRAY_SIZE(post_div_table_lpass_audio_cc_pll_out_aux2),
  96. .width = 2,
  97. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_ZONDA],
  98. .clkr.hw.init = &(const struct clk_init_data){
  99. .name = "lpass_audio_cc_pll_out_aux2",
  100. .parent_hws = (const struct clk_hw*[]){
  101. &lpass_audio_cc_pll.clkr.hw,
  102. },
  103. .num_parents = 1,
  104. .ops = &clk_alpha_pll_postdiv_zonda_ops,
  105. },
  106. };
  107. static const struct pll_vco lucid_vco[] = {
  108. { 249600000, 2000000000, 0 },
  109. };
  110. /* 614.4 MHz configuration */
  111. static const struct alpha_pll_config lpass_aon_cc_pll_config = {
  112. .l = 0x20,
  113. .alpha = 0x0,
  114. .config_ctl_val = 0x20485699,
  115. .config_ctl_hi_val = 0x00002261,
  116. .config_ctl_hi1_val = 0x329A299C,
  117. .user_ctl_val = 0x00005100,
  118. .user_ctl_hi_val = 0x00000805,
  119. .user_ctl_hi1_val = 0x00000000,
  120. };
  121. static struct clk_alpha_pll lpass_aon_cc_pll = {
  122. .offset = 0x0,
  123. .vco_table = lucid_vco,
  124. .num_vco = ARRAY_SIZE(lucid_vco),
  125. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  126. .clkr = {
  127. .hw.init = &(const struct clk_init_data){
  128. .name = "lpass_aon_cc_pll",
  129. .parent_data = &(const struct clk_parent_data){
  130. .index = 0,
  131. },
  132. .num_parents = 1,
  133. .ops = &clk_alpha_pll_lucid_ops,
  134. },
  135. },
  136. };
  137. static const struct clk_div_table post_div_table_lpass_aon_cc_pll_out_even[] = {
  138. { 0x1, 2 },
  139. { }
  140. };
  141. static struct clk_alpha_pll_postdiv lpass_aon_cc_pll_out_even = {
  142. .offset = 0x0,
  143. .post_div_shift = 8,
  144. .post_div_table = post_div_table_lpass_aon_cc_pll_out_even,
  145. .num_post_div = ARRAY_SIZE(post_div_table_lpass_aon_cc_pll_out_even),
  146. .width = 4,
  147. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  148. .clkr.hw.init = &(const struct clk_init_data){
  149. .name = "lpass_aon_cc_pll_out_even",
  150. .parent_hws = (const struct clk_hw*[]){
  151. &lpass_aon_cc_pll.clkr.hw,
  152. },
  153. .num_parents = 1,
  154. .ops = &clk_alpha_pll_postdiv_lucid_ops,
  155. },
  156. };
  157. static const struct clk_div_table post_div_table_lpass_aon_cc_pll_out_odd[] = {
  158. { 0x5, 5 },
  159. { }
  160. };
  161. static struct clk_alpha_pll_postdiv lpass_aon_cc_pll_out_odd = {
  162. .offset = 0x0,
  163. .post_div_shift = 12,
  164. .post_div_table = post_div_table_lpass_aon_cc_pll_out_odd,
  165. .num_post_div = ARRAY_SIZE(post_div_table_lpass_aon_cc_pll_out_odd),
  166. .width = 4,
  167. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID],
  168. .clkr.hw.init = &(const struct clk_init_data){
  169. .name = "lpass_aon_cc_pll_out_odd",
  170. .parent_hws = (const struct clk_hw*[]){
  171. &lpass_aon_cc_pll.clkr.hw,
  172. },
  173. .num_parents = 1,
  174. .ops = &clk_alpha_pll_postdiv_lucid_ops,
  175. },
  176. };
  177. static const struct parent_map lpass_audio_cc_parent_map_0[] = {
  178. { P_BI_TCXO, 0 },
  179. { P_LPASS_AUDIO_CC_PLL_OUT_AUX, 3 },
  180. { P_LPASS_AON_CC_PLL_OUT_ODD, 5 },
  181. { P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 6 },
  182. };
  183. static struct clk_regmap_div lpass_audio_cc_pll_out_aux2_div_clk_src;
  184. static struct clk_regmap_div lpass_audio_cc_pll_out_main_div_clk_src;
  185. static const struct clk_parent_data lpass_audio_cc_parent_data_0[] = {
  186. { .index = 0 },
  187. { .hw = &lpass_audio_cc_pll.clkr.hw },
  188. { .hw = &lpass_aon_cc_pll_out_odd.clkr.hw },
  189. { .hw = &lpass_audio_cc_pll_out_aux2_div_clk_src.clkr.hw },
  190. };
  191. static const struct parent_map lpass_aon_cc_parent_map_0[] = {
  192. { P_BI_TCXO, 0 },
  193. { P_LPASS_AON_CC_PLL_OUT_EVEN, 4 },
  194. };
  195. static const struct clk_parent_data lpass_aon_cc_parent_data_0[] = {
  196. { .index = 0 },
  197. { .hw = &lpass_aon_cc_pll_out_even.clkr.hw },
  198. };
  199. static const struct parent_map lpass_aon_cc_parent_map_1[] = {
  200. { P_BI_TCXO, 0 },
  201. { P_LPASS_AON_CC_PLL_OUT_ODD, 1 },
  202. { P_LPASS_AUDIO_CC_PLL_MAIN_DIV_CLK, 6 },
  203. };
  204. static const struct clk_parent_data lpass_aon_cc_parent_data_1[] = {
  205. { .index = 0 },
  206. { .hw = &lpass_aon_cc_pll_out_odd.clkr.hw },
  207. { .hw = &lpass_audio_cc_pll_out_main_div_clk_src.clkr.hw },
  208. };
  209. static const struct freq_tbl ftbl_lpass_aon_cc_main_rcg_clk_src[] = {
  210. F(38400000, P_LPASS_AON_CC_PLL_OUT_EVEN, 8, 0, 0),
  211. F(76800000, P_LPASS_AON_CC_PLL_OUT_EVEN, 4, 0, 0),
  212. F(153600000, P_LPASS_AON_CC_PLL_OUT_EVEN, 2, 0, 0),
  213. { }
  214. };
  215. static struct clk_rcg2 lpass_aon_cc_main_rcg_clk_src = {
  216. .cmd_rcgr = 0x1000,
  217. .mnd_width = 0,
  218. .hid_width = 5,
  219. .parent_map = lpass_aon_cc_parent_map_0,
  220. .freq_tbl = ftbl_lpass_aon_cc_main_rcg_clk_src,
  221. .clkr.hw.init = &(const struct clk_init_data){
  222. .name = "lpass_aon_cc_main_rcg_clk_src",
  223. .parent_data = lpass_aon_cc_parent_data_0,
  224. .num_parents = ARRAY_SIZE(lpass_aon_cc_parent_data_0),
  225. .flags = CLK_OPS_PARENT_ENABLE,
  226. .ops = &clk_rcg2_shared_ops,
  227. },
  228. };
  229. static const struct freq_tbl ftbl_lpass_aon_cc_tx_mclk_rcg_clk_src[] = {
  230. F(19200000, P_BI_TCXO, 1, 0, 0),
  231. F(24576000, P_LPASS_AON_CC_PLL_OUT_ODD, 5, 0, 0),
  232. { }
  233. };
  234. static struct clk_rcg2 lpass_aon_cc_tx_mclk_rcg_clk_src = {
  235. .cmd_rcgr = 0x13004,
  236. .mnd_width = 0,
  237. .hid_width = 5,
  238. .parent_map = lpass_aon_cc_parent_map_1,
  239. .freq_tbl = ftbl_lpass_aon_cc_tx_mclk_rcg_clk_src,
  240. .clkr.hw.init = &(const struct clk_init_data){
  241. .name = "lpass_aon_cc_tx_mclk_rcg_clk_src",
  242. .parent_data = lpass_aon_cc_parent_data_1,
  243. .num_parents = ARRAY_SIZE(lpass_aon_cc_parent_data_1),
  244. .ops = &clk_rcg2_ops,
  245. },
  246. };
  247. static struct clk_regmap_div lpass_audio_cc_pll_out_aux2_div_clk_src = {
  248. .reg = 0x48,
  249. .shift = 0,
  250. .width = 4,
  251. .clkr.hw.init = &(const struct clk_init_data) {
  252. .name = "lpass_audio_cc_pll_out_aux2_div_clk_src",
  253. .parent_hws = (const struct clk_hw*[]){
  254. &lpass_audio_cc_pll_out_aux2.clkr.hw,
  255. },
  256. .num_parents = 1,
  257. .flags = CLK_SET_RATE_PARENT,
  258. .ops = &clk_regmap_div_ro_ops,
  259. },
  260. };
  261. static struct clk_regmap_div lpass_audio_cc_pll_out_main_div_clk_src = {
  262. .reg = 0x3c,
  263. .shift = 0,
  264. .width = 4,
  265. .clkr.hw.init = &(const struct clk_init_data) {
  266. .name = "lpass_audio_cc_pll_out_main_div_clk_src",
  267. .parent_hws = (const struct clk_hw*[]){
  268. &lpass_audio_cc_pll.clkr.hw,
  269. },
  270. .num_parents = 1,
  271. .flags = CLK_SET_RATE_PARENT,
  272. .ops = &clk_regmap_div_ro_ops,
  273. },
  274. };
  275. static struct clk_regmap_div lpass_aon_cc_cdiv_tx_mclk_div_clk_src = {
  276. .reg = 0x13010,
  277. .shift = 0,
  278. .width = 4,
  279. .clkr.hw.init = &(const struct clk_init_data) {
  280. .name = "lpass_aon_cc_cdiv_tx_mclk_div_clk_src",
  281. .parent_hws = (const struct clk_hw*[]){
  282. &lpass_aon_cc_tx_mclk_rcg_clk_src.clkr.hw,
  283. },
  284. .num_parents = 1,
  285. .flags = CLK_SET_RATE_PARENT,
  286. .ops = &clk_regmap_div_ro_ops,
  287. },
  288. };
  289. static struct clk_regmap_div lpass_aon_cc_pll_out_main_cdiv_div_clk_src = {
  290. .reg = 0x80,
  291. .shift = 0,
  292. .width = 4,
  293. .clkr.hw.init = &(const struct clk_init_data) {
  294. .name = "lpass_aon_cc_pll_out_main_cdiv_div_clk_src",
  295. .parent_hws = (const struct clk_hw*[]){
  296. &lpass_aon_cc_pll.clkr.hw,
  297. },
  298. .num_parents = 1,
  299. .flags = CLK_SET_RATE_PARENT,
  300. .ops = &clk_regmap_div_ro_ops,
  301. },
  302. };
  303. static const struct freq_tbl ftbl_lpass_audio_cc_ext_mclk0_clk_src[] = {
  304. F(256000, P_LPASS_AON_CC_PLL_OUT_ODD, 15, 1, 32),
  305. F(352800, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 10, 1, 32),
  306. F(512000, P_LPASS_AON_CC_PLL_OUT_ODD, 15, 1, 16),
  307. F(705600, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 10, 1, 16),
  308. F(768000, P_LPASS_AON_CC_PLL_OUT_ODD, 10, 1, 16),
  309. F(1024000, P_LPASS_AON_CC_PLL_OUT_ODD, 15, 1, 8),
  310. F(1411200, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 10, 1, 8),
  311. F(1536000, P_LPASS_AON_CC_PLL_OUT_ODD, 10, 1, 8),
  312. F(2048000, P_LPASS_AON_CC_PLL_OUT_ODD, 15, 1, 4),
  313. F(2822400, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 10, 1, 4),
  314. F(3072000, P_LPASS_AON_CC_PLL_OUT_ODD, 10, 1, 4),
  315. F(4096000, P_LPASS_AON_CC_PLL_OUT_ODD, 15, 1, 2),
  316. F(5644800, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 10, 1, 2),
  317. F(6144000, P_LPASS_AON_CC_PLL_OUT_ODD, 10, 1, 2),
  318. F(8192000, P_LPASS_AON_CC_PLL_OUT_ODD, 15, 0, 0),
  319. F(9600000, P_BI_TCXO, 2, 0, 0),
  320. F(11289600, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 10, 0, 0),
  321. F(12288000, P_LPASS_AON_CC_PLL_OUT_ODD, 10, 0, 0),
  322. F(19200000, P_BI_TCXO, 1, 0, 0),
  323. F(22579200, P_LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC, 5, 0, 0),
  324. F(24576000, P_LPASS_AON_CC_PLL_OUT_ODD, 5, 0, 0),
  325. { }
  326. };
  327. static struct clk_rcg2 lpass_audio_cc_ext_mclk0_clk_src = {
  328. .cmd_rcgr = 0x20004,
  329. .mnd_width = 8,
  330. .hid_width = 5,
  331. .parent_map = lpass_audio_cc_parent_map_0,
  332. .freq_tbl = ftbl_lpass_audio_cc_ext_mclk0_clk_src,
  333. .clkr.hw.init = &(const struct clk_init_data){
  334. .name = "lpass_audio_cc_ext_mclk0_clk_src",
  335. .parent_data = lpass_audio_cc_parent_data_0,
  336. .num_parents = ARRAY_SIZE(lpass_audio_cc_parent_data_0),
  337. .ops = &clk_rcg2_ops,
  338. },
  339. };
  340. static struct clk_rcg2 lpass_audio_cc_ext_mclk1_clk_src = {
  341. .cmd_rcgr = 0x21004,
  342. .mnd_width = 8,
  343. .hid_width = 5,
  344. .parent_map = lpass_audio_cc_parent_map_0,
  345. .freq_tbl = ftbl_lpass_audio_cc_ext_mclk0_clk_src,
  346. .clkr.hw.init = &(const struct clk_init_data){
  347. .name = "lpass_audio_cc_ext_mclk1_clk_src",
  348. .parent_data = lpass_audio_cc_parent_data_0,
  349. .num_parents = ARRAY_SIZE(lpass_audio_cc_parent_data_0),
  350. .ops = &clk_rcg2_ops,
  351. },
  352. };
  353. static struct clk_rcg2 lpass_audio_cc_rx_mclk_clk_src = {
  354. .cmd_rcgr = 0x24004,
  355. .mnd_width = 8,
  356. .hid_width = 5,
  357. .parent_map = lpass_audio_cc_parent_map_0,
  358. .freq_tbl = ftbl_lpass_audio_cc_ext_mclk0_clk_src,
  359. .clkr.hw.init = &(const struct clk_init_data){
  360. .name = "lpass_audio_cc_rx_mclk_clk_src",
  361. .parent_data = lpass_audio_cc_parent_data_0,
  362. .num_parents = ARRAY_SIZE(lpass_audio_cc_parent_data_0),
  363. .ops = &clk_rcg2_ops,
  364. },
  365. };
  366. static struct clk_regmap_div lpass_audio_cc_cdiv_rx_mclk_div_clk_src = {
  367. .reg = 0x240d0,
  368. .shift = 0,
  369. .width = 4,
  370. .clkr.hw.init = &(const struct clk_init_data) {
  371. .name = "lpass_audio_cc_cdiv_rx_mclk_div_clk_src",
  372. .parent_hws = (const struct clk_hw*[]){
  373. &lpass_audio_cc_rx_mclk_clk_src.clkr.hw,
  374. },
  375. .num_parents = 1,
  376. .flags = CLK_SET_RATE_PARENT,
  377. .ops = &clk_regmap_div_ro_ops,
  378. },
  379. };
  380. static struct clk_branch lpass_aon_cc_audio_hm_h_clk;
  381. static struct clk_branch lpass_audio_cc_codec_mem0_clk = {
  382. .halt_reg = 0x1e004,
  383. .halt_check = BRANCH_HALT,
  384. .clkr = {
  385. .enable_reg = 0x1e004,
  386. .enable_mask = BIT(0),
  387. .hw.init = &(const struct clk_init_data){
  388. .name = "lpass_audio_cc_codec_mem0_clk",
  389. .parent_hws = (const struct clk_hw*[]){
  390. &lpass_aon_cc_audio_hm_h_clk.clkr.hw,
  391. },
  392. .num_parents = 1,
  393. .flags = CLK_SET_RATE_PARENT,
  394. .ops = &clk_branch2_ops,
  395. },
  396. },
  397. };
  398. static struct clk_branch lpass_audio_cc_codec_mem1_clk = {
  399. .halt_reg = 0x1e008,
  400. .halt_check = BRANCH_HALT,
  401. .clkr = {
  402. .enable_reg = 0x1e008,
  403. .enable_mask = BIT(0),
  404. .hw.init = &(const struct clk_init_data){
  405. .name = "lpass_audio_cc_codec_mem1_clk",
  406. .parent_hws = (const struct clk_hw*[]){
  407. &lpass_aon_cc_audio_hm_h_clk.clkr.hw,
  408. },
  409. .num_parents = 1,
  410. .flags = CLK_SET_RATE_PARENT,
  411. .ops = &clk_branch2_ops,
  412. },
  413. },
  414. };
  415. static struct clk_branch lpass_audio_cc_codec_mem2_clk = {
  416. .halt_reg = 0x1e00c,
  417. .halt_check = BRANCH_HALT,
  418. .clkr = {
  419. .enable_reg = 0x1e00c,
  420. .enable_mask = BIT(0),
  421. .hw.init = &(const struct clk_init_data){
  422. .name = "lpass_audio_cc_codec_mem2_clk",
  423. .parent_hws = (const struct clk_hw*[]){
  424. &lpass_aon_cc_audio_hm_h_clk.clkr.hw,
  425. },
  426. .num_parents = 1,
  427. .flags = CLK_SET_RATE_PARENT,
  428. .ops = &clk_branch2_ops,
  429. },
  430. },
  431. };
  432. static struct clk_branch lpass_audio_cc_codec_mem_clk = {
  433. .halt_reg = 0x1e000,
  434. .halt_check = BRANCH_HALT,
  435. .clkr = {
  436. .enable_reg = 0x1e000,
  437. .enable_mask = BIT(0),
  438. .hw.init = &(const struct clk_init_data){
  439. .name = "lpass_audio_cc_codec_mem_clk",
  440. .parent_hws = (const struct clk_hw*[]){
  441. &lpass_aon_cc_audio_hm_h_clk.clkr.hw,
  442. },
  443. .num_parents = 1,
  444. .flags = CLK_SET_RATE_PARENT,
  445. .ops = &clk_branch2_ops,
  446. },
  447. },
  448. };
  449. static struct clk_branch lpass_audio_cc_ext_mclk0_clk = {
  450. .halt_reg = 0x20018,
  451. .halt_check = BRANCH_HALT,
  452. .clkr = {
  453. .enable_reg = 0x20018,
  454. .enable_mask = BIT(0),
  455. .hw.init = &(const struct clk_init_data){
  456. .name = "lpass_audio_cc_ext_mclk0_clk",
  457. .parent_hws = (const struct clk_hw*[]){
  458. &lpass_audio_cc_ext_mclk0_clk_src.clkr.hw,
  459. },
  460. .num_parents = 1,
  461. .flags = CLK_SET_RATE_PARENT,
  462. .ops = &clk_branch2_ops,
  463. },
  464. },
  465. };
  466. static struct clk_branch lpass_audio_cc_ext_mclk1_clk = {
  467. .halt_reg = 0x21018,
  468. .halt_check = BRANCH_HALT,
  469. .clkr = {
  470. .enable_reg = 0x21018,
  471. .enable_mask = BIT(0),
  472. .hw.init = &(const struct clk_init_data){
  473. .name = "lpass_audio_cc_ext_mclk1_clk",
  474. .parent_hws = (const struct clk_hw*[]){
  475. &lpass_audio_cc_ext_mclk1_clk_src.clkr.hw,
  476. },
  477. .num_parents = 1,
  478. .flags = CLK_SET_RATE_PARENT,
  479. .ops = &clk_branch2_ops,
  480. },
  481. },
  482. };
  483. static struct clk_branch lpass_audio_cc_rx_mclk_2x_clk = {
  484. .halt_reg = 0x240cc,
  485. .halt_check = BRANCH_HALT,
  486. .clkr = {
  487. .enable_reg = 0x240cc,
  488. .enable_mask = BIT(0),
  489. .hw.init = &(const struct clk_init_data){
  490. .name = "lpass_audio_cc_rx_mclk_2x_clk",
  491. .parent_hws = (const struct clk_hw*[]){
  492. &lpass_audio_cc_rx_mclk_clk_src.clkr.hw,
  493. },
  494. .num_parents = 1,
  495. .flags = CLK_SET_RATE_PARENT,
  496. .ops = &clk_branch2_ops,
  497. },
  498. },
  499. };
  500. static struct clk_branch lpass_audio_cc_rx_mclk_clk = {
  501. .halt_reg = 0x240d4,
  502. .halt_check = BRANCH_HALT,
  503. .clkr = {
  504. .enable_reg = 0x240d4,
  505. .enable_mask = BIT(0),
  506. .hw.init = &(const struct clk_init_data){
  507. .name = "lpass_audio_cc_rx_mclk_clk",
  508. .parent_hws = (const struct clk_hw*[]){
  509. &lpass_audio_cc_cdiv_rx_mclk_div_clk_src.clkr.hw,
  510. },
  511. .num_parents = 1,
  512. .flags = CLK_SET_RATE_PARENT,
  513. .ops = &clk_branch2_ops,
  514. },
  515. },
  516. };
  517. static struct clk_branch lpass_aon_cc_audio_hm_h_clk = {
  518. .halt_reg = 0x9014,
  519. .halt_check = BRANCH_HALT,
  520. .clkr = {
  521. .enable_reg = 0x9014,
  522. .enable_mask = BIT(0),
  523. .hw.init = &(const struct clk_init_data){
  524. .name = "lpass_aon_cc_audio_hm_h_clk",
  525. .parent_hws = (const struct clk_hw*[]){
  526. &lpass_aon_cc_main_rcg_clk_src.clkr.hw,
  527. },
  528. .num_parents = 1,
  529. .flags = CLK_SET_RATE_PARENT,
  530. .ops = &clk_branch2_aon_ops,
  531. },
  532. },
  533. };
  534. static struct clk_branch lpass_aon_cc_va_mem0_clk = {
  535. .halt_reg = 0x9028,
  536. .halt_check = BRANCH_HALT,
  537. .clkr = {
  538. .enable_reg = 0x9028,
  539. .enable_mask = BIT(0),
  540. .hw.init = &(const struct clk_init_data){
  541. .name = "lpass_aon_cc_va_mem0_clk",
  542. .parent_hws = (const struct clk_hw*[]){
  543. &lpass_aon_cc_main_rcg_clk_src.clkr.hw,
  544. },
  545. .num_parents = 1,
  546. .flags = CLK_SET_RATE_PARENT,
  547. .ops = &clk_branch2_ops,
  548. },
  549. },
  550. };
  551. static struct clk_branch lpass_aon_cc_tx_mclk_2x_clk = {
  552. .halt_reg = 0x1300c,
  553. .halt_check = BRANCH_HALT,
  554. .clkr = {
  555. .enable_reg = 0x1300c,
  556. .enable_mask = BIT(0),
  557. .hw.init = &(const struct clk_init_data){
  558. .name = "lpass_aon_cc_tx_mclk_2x_clk",
  559. .parent_hws = (const struct clk_hw*[]){
  560. &lpass_aon_cc_tx_mclk_rcg_clk_src.clkr.hw,
  561. },
  562. .num_parents = 1,
  563. .flags = CLK_SET_RATE_PARENT,
  564. .ops = &clk_branch2_ops,
  565. },
  566. },
  567. };
  568. static struct clk_branch lpass_aon_cc_tx_mclk_clk = {
  569. .halt_reg = 0x13014,
  570. .halt_check = BRANCH_HALT,
  571. .clkr = {
  572. .enable_reg = 0x13014,
  573. .enable_mask = BIT(0),
  574. .hw.init = &(const struct clk_init_data){
  575. .name = "lpass_aon_cc_tx_mclk_clk",
  576. .parent_hws = (const struct clk_hw*[]){
  577. &lpass_aon_cc_cdiv_tx_mclk_div_clk_src.clkr.hw,
  578. },
  579. .num_parents = 1,
  580. .flags = CLK_SET_RATE_PARENT,
  581. .ops = &clk_branch2_ops,
  582. },
  583. },
  584. };
  585. static struct gdsc lpass_aon_cc_lpass_audio_hm_gdsc = {
  586. .gdscr = 0x9090,
  587. .pd = {
  588. .name = "lpass_aon_cc_lpass_audio_hm_gdsc",
  589. },
  590. .pwrsts = PWRSTS_OFF_ON,
  591. .flags = RETAIN_FF_ENABLE,
  592. };
  593. static struct clk_regmap *lpass_cc_sc7280_clocks[] = {
  594. [LPASS_Q6SS_AHBM_CLK] = &lpass_q6ss_ahbm_clk.clkr,
  595. [LPASS_Q6SS_AHBS_CLK] = &lpass_q6ss_ahbs_clk.clkr,
  596. };
  597. static struct clk_regmap *lpass_aon_cc_sc7280_clocks[] = {
  598. [LPASS_AON_CC_AUDIO_HM_H_CLK] = &lpass_aon_cc_audio_hm_h_clk.clkr,
  599. [LPASS_AON_CC_VA_MEM0_CLK] = &lpass_aon_cc_va_mem0_clk.clkr,
  600. [LPASS_AON_CC_CDIV_TX_MCLK_DIV_CLK_SRC] = &lpass_aon_cc_cdiv_tx_mclk_div_clk_src.clkr,
  601. [LPASS_AON_CC_MAIN_RCG_CLK_SRC] = &lpass_aon_cc_main_rcg_clk_src.clkr,
  602. [LPASS_AON_CC_PLL] = &lpass_aon_cc_pll.clkr,
  603. [LPASS_AON_CC_PLL_OUT_EVEN] = &lpass_aon_cc_pll_out_even.clkr,
  604. [LPASS_AON_CC_PLL_OUT_MAIN_CDIV_DIV_CLK_SRC] =
  605. &lpass_aon_cc_pll_out_main_cdiv_div_clk_src.clkr,
  606. [LPASS_AON_CC_PLL_OUT_ODD] = &lpass_aon_cc_pll_out_odd.clkr,
  607. [LPASS_AON_CC_TX_MCLK_2X_CLK] = &lpass_aon_cc_tx_mclk_2x_clk.clkr,
  608. [LPASS_AON_CC_TX_MCLK_CLK] = &lpass_aon_cc_tx_mclk_clk.clkr,
  609. [LPASS_AON_CC_TX_MCLK_RCG_CLK_SRC] = &lpass_aon_cc_tx_mclk_rcg_clk_src.clkr,
  610. };
  611. static struct gdsc *lpass_aon_cc_sc7280_gdscs[] = {
  612. [LPASS_AON_CC_LPASS_AUDIO_HM_GDSC] = &lpass_aon_cc_lpass_audio_hm_gdsc,
  613. };
  614. static struct clk_regmap *lpass_audio_cc_sc7280_clocks[] = {
  615. [LPASS_AUDIO_CC_CDIV_RX_MCLK_DIV_CLK_SRC] = &lpass_audio_cc_cdiv_rx_mclk_div_clk_src.clkr,
  616. [LPASS_AUDIO_CC_CODEC_MEM0_CLK] = &lpass_audio_cc_codec_mem0_clk.clkr,
  617. [LPASS_AUDIO_CC_CODEC_MEM1_CLK] = &lpass_audio_cc_codec_mem1_clk.clkr,
  618. [LPASS_AUDIO_CC_CODEC_MEM2_CLK] = &lpass_audio_cc_codec_mem2_clk.clkr,
  619. [LPASS_AUDIO_CC_CODEC_MEM_CLK] = &lpass_audio_cc_codec_mem_clk.clkr,
  620. [LPASS_AUDIO_CC_EXT_MCLK0_CLK] = &lpass_audio_cc_ext_mclk0_clk.clkr,
  621. [LPASS_AUDIO_CC_EXT_MCLK0_CLK_SRC] = &lpass_audio_cc_ext_mclk0_clk_src.clkr,
  622. [LPASS_AUDIO_CC_EXT_MCLK1_CLK] = &lpass_audio_cc_ext_mclk1_clk.clkr,
  623. [LPASS_AUDIO_CC_EXT_MCLK1_CLK_SRC] = &lpass_audio_cc_ext_mclk1_clk_src.clkr,
  624. [LPASS_AUDIO_CC_PLL] = &lpass_audio_cc_pll.clkr,
  625. [LPASS_AUDIO_CC_PLL_OUT_AUX2] = &lpass_audio_cc_pll_out_aux2.clkr,
  626. [LPASS_AUDIO_CC_PLL_OUT_AUX2_DIV_CLK_SRC] = &lpass_audio_cc_pll_out_aux2_div_clk_src.clkr,
  627. [LPASS_AUDIO_CC_PLL_OUT_MAIN_DIV_CLK_SRC] = &lpass_audio_cc_pll_out_main_div_clk_src.clkr,
  628. [LPASS_AUDIO_CC_RX_MCLK_2X_CLK] = &lpass_audio_cc_rx_mclk_2x_clk.clkr,
  629. [LPASS_AUDIO_CC_RX_MCLK_CLK] = &lpass_audio_cc_rx_mclk_clk.clkr,
  630. [LPASS_AUDIO_CC_RX_MCLK_CLK_SRC] = &lpass_audio_cc_rx_mclk_clk_src.clkr,
  631. };
  632. static struct regmap_config lpass_audio_cc_sc7280_regmap_config = {
  633. .reg_bits = 32,
  634. .reg_stride = 4,
  635. .val_bits = 32,
  636. .fast_io = true,
  637. };
  638. static const struct qcom_cc_desc lpass_cc_sc7280_desc = {
  639. .config = &lpass_audio_cc_sc7280_regmap_config,
  640. .clks = lpass_cc_sc7280_clocks,
  641. .num_clks = ARRAY_SIZE(lpass_cc_sc7280_clocks),
  642. .gdscs = lpass_aon_cc_sc7280_gdscs,
  643. .num_gdscs = ARRAY_SIZE(lpass_aon_cc_sc7280_gdscs),
  644. };
  645. static const struct qcom_cc_desc lpass_audio_cc_sc7280_desc = {
  646. .config = &lpass_audio_cc_sc7280_regmap_config,
  647. .clks = lpass_audio_cc_sc7280_clocks,
  648. .num_clks = ARRAY_SIZE(lpass_audio_cc_sc7280_clocks),
  649. };
  650. static const struct qcom_reset_map lpass_audio_cc_sc7280_resets[] = {
  651. [LPASS_AUDIO_SWR_RX_CGCR] = { 0xa0, 1 },
  652. [LPASS_AUDIO_SWR_TX_CGCR] = { 0xa8, 1 },
  653. [LPASS_AUDIO_SWR_WSA_CGCR] = { 0xb0, 1 },
  654. };
  655. static const struct qcom_cc_desc lpass_audio_cc_reset_sc7280_desc = {
  656. .config = &lpass_audio_cc_sc7280_regmap_config,
  657. .resets = lpass_audio_cc_sc7280_resets,
  658. .num_resets = ARRAY_SIZE(lpass_audio_cc_sc7280_resets),
  659. };
  660. static const struct of_device_id lpass_audio_cc_sc7280_match_table[] = {
  661. { .compatible = "qcom,sc7280-lpassaudiocc" },
  662. { }
  663. };
  664. MODULE_DEVICE_TABLE(of, lpass_audio_cc_sc7280_match_table);
  665. static int lpass_audio_setup_runtime_pm(struct platform_device *pdev)
  666. {
  667. int ret;
  668. pm_runtime_use_autosuspend(&pdev->dev);
  669. pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
  670. ret = devm_pm_runtime_enable(&pdev->dev);
  671. if (ret)
  672. return ret;
  673. ret = devm_pm_clk_create(&pdev->dev);
  674. if (ret)
  675. return ret;
  676. ret = pm_clk_add(&pdev->dev, "iface");
  677. if (ret < 0)
  678. dev_err(&pdev->dev, "failed to acquire iface clock\n");
  679. return pm_runtime_resume_and_get(&pdev->dev);
  680. }
  681. static int lpass_audio_cc_sc7280_probe(struct platform_device *pdev)
  682. {
  683. const struct qcom_cc_desc *desc;
  684. struct regmap *regmap;
  685. int ret;
  686. ret = lpass_audio_setup_runtime_pm(pdev);
  687. if (ret)
  688. return ret;
  689. lpass_audio_cc_sc7280_regmap_config.name = "lpassaudio_cc";
  690. lpass_audio_cc_sc7280_regmap_config.max_register = 0x2f000;
  691. desc = &lpass_audio_cc_sc7280_desc;
  692. regmap = qcom_cc_map(pdev, desc);
  693. if (IS_ERR(regmap)) {
  694. ret = PTR_ERR(regmap);
  695. goto exit;
  696. }
  697. clk_zonda_pll_configure(&lpass_audio_cc_pll, regmap, &lpass_audio_cc_pll_config);
  698. /* PLL settings */
  699. regmap_write(regmap, 0x4, 0x3b);
  700. regmap_write(regmap, 0x8, 0xff05);
  701. ret = qcom_cc_really_probe(&pdev->dev, &lpass_audio_cc_sc7280_desc, regmap);
  702. if (ret) {
  703. dev_err(&pdev->dev, "Failed to register LPASS AUDIO CC clocks\n");
  704. goto exit;
  705. }
  706. ret = qcom_cc_probe_by_index(pdev, 1, &lpass_audio_cc_reset_sc7280_desc);
  707. if (ret) {
  708. dev_err(&pdev->dev, "Failed to register LPASS AUDIO CC Resets\n");
  709. goto exit;
  710. }
  711. pm_runtime_mark_last_busy(&pdev->dev);
  712. exit:
  713. pm_runtime_put_autosuspend(&pdev->dev);
  714. return ret;
  715. }
  716. static const struct dev_pm_ops lpass_audio_cc_pm_ops = {
  717. SET_RUNTIME_PM_OPS(pm_clk_suspend, pm_clk_resume, NULL)
  718. };
  719. static struct platform_driver lpass_audio_cc_sc7280_driver = {
  720. .probe = lpass_audio_cc_sc7280_probe,
  721. .driver = {
  722. .name = "lpass_audio_cc-sc7280",
  723. .of_match_table = lpass_audio_cc_sc7280_match_table,
  724. .pm = &lpass_audio_cc_pm_ops,
  725. },
  726. };
  727. static const struct qcom_cc_desc lpass_aon_cc_sc7280_desc = {
  728. .config = &lpass_audio_cc_sc7280_regmap_config,
  729. .clks = lpass_aon_cc_sc7280_clocks,
  730. .num_clks = ARRAY_SIZE(lpass_aon_cc_sc7280_clocks),
  731. .gdscs = lpass_aon_cc_sc7280_gdscs,
  732. .num_gdscs = ARRAY_SIZE(lpass_aon_cc_sc7280_gdscs),
  733. };
  734. static const struct of_device_id lpass_aon_cc_sc7280_match_table[] = {
  735. { .compatible = "qcom,sc7280-lpassaoncc" },
  736. { }
  737. };
  738. MODULE_DEVICE_TABLE(of, lpass_aon_cc_sc7280_match_table);
  739. static int lpass_aon_cc_sc7280_probe(struct platform_device *pdev)
  740. {
  741. const struct qcom_cc_desc *desc;
  742. struct regmap *regmap;
  743. int ret;
  744. ret = lpass_audio_setup_runtime_pm(pdev);
  745. if (ret)
  746. return ret;
  747. if (of_property_read_bool(pdev->dev.of_node, "qcom,adsp-pil-mode")) {
  748. lpass_audio_cc_sc7280_regmap_config.name = "cc";
  749. desc = &lpass_cc_sc7280_desc;
  750. ret = qcom_cc_probe(pdev, desc);
  751. goto exit;
  752. }
  753. lpass_audio_cc_sc7280_regmap_config.name = "lpasscc_aon";
  754. lpass_audio_cc_sc7280_regmap_config.max_register = 0xa0008;
  755. desc = &lpass_aon_cc_sc7280_desc;
  756. regmap = qcom_cc_map(pdev, desc);
  757. if (IS_ERR(regmap)) {
  758. ret = PTR_ERR(regmap);
  759. goto exit;
  760. }
  761. clk_lucid_pll_configure(&lpass_aon_cc_pll, regmap, &lpass_aon_cc_pll_config);
  762. ret = qcom_cc_really_probe(&pdev->dev, &lpass_aon_cc_sc7280_desc, regmap);
  763. if (ret) {
  764. dev_err(&pdev->dev, "Failed to register LPASS AON CC clocks\n");
  765. goto exit;
  766. }
  767. pm_runtime_mark_last_busy(&pdev->dev);
  768. exit:
  769. pm_runtime_put_autosuspend(&pdev->dev);
  770. return ret;
  771. }
  772. static struct platform_driver lpass_aon_cc_sc7280_driver = {
  773. .probe = lpass_aon_cc_sc7280_probe,
  774. .driver = {
  775. .name = "lpass_aon_cc-sc7280",
  776. .of_match_table = lpass_aon_cc_sc7280_match_table,
  777. .pm = &lpass_audio_cc_pm_ops,
  778. },
  779. };
  780. static int __init lpass_audio_cc_sc7280_init(void)
  781. {
  782. int ret;
  783. ret = platform_driver_register(&lpass_aon_cc_sc7280_driver);
  784. if (ret)
  785. return ret;
  786. return platform_driver_register(&lpass_audio_cc_sc7280_driver);
  787. }
  788. subsys_initcall(lpass_audio_cc_sc7280_init);
  789. static void __exit lpass_audio_cc_sc7280_exit(void)
  790. {
  791. platform_driver_unregister(&lpass_audio_cc_sc7280_driver);
  792. platform_driver_unregister(&lpass_aon_cc_sc7280_driver);
  793. }
  794. module_exit(lpass_audio_cc_sc7280_exit);
  795. MODULE_DESCRIPTION("QTI LPASS_AUDIO_CC SC7280 Driver");
  796. MODULE_LICENSE("GPL v2");