npucc-sm8150.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/clk-provider.h>
  8. #include <linux/err.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/of_device.h>
  12. #include <linux/of.h>
  13. #include <linux/regmap.h>
  14. #include <dt-bindings/clock/qcom,npucc-sm8150.h>
  15. #include "clk-alpha-pll.h"
  16. #include "clk-branch.h"
  17. #include "clk-rcg.h"
  18. #include "clk-regmap.h"
  19. #include "common.h"
  20. #include "reset.h"
  21. #include "vdd-level-sm8150.h"
  22. #include "clk-pm.h"
  23. #define CRC_SID_FSM_CTRL 0x100c
  24. #define CRC_SID_FSM_CTRL_SETTING 0x800000
  25. #define CRC_MND_CFG 0x1010
  26. #define CRC_MND_CFG_SETTING 0x15010
  27. static DEFINE_VDD_REGULATORS(vdd_cx, VDD_NUM, 1, vdd_corner);
  28. static struct clk_vdd_class *npu_cc_sm8150_regulators[] = {
  29. &vdd_cx,
  30. };
  31. enum {
  32. P_BI_TCXO,
  33. P_GPLL0_OUT_MAIN,
  34. P_GPLL0_OUT_MAIN_DIV,
  35. P_NPU_CC_PLL0_OUT_EVEN,
  36. P_NPU_CC_PLL1_OUT_EVEN,
  37. P_NPU_CC_CRC_DIV,
  38. };
  39. static struct pll_vco trion_vco[] = {
  40. { 249600000, 2000000000, 0 },
  41. };
  42. /* 600MHz configuration */
  43. static struct alpha_pll_config npu_cc_pll0_config = {
  44. .l = 0x1F,
  45. .alpha = 0x4000,
  46. .config_ctl_val = 0x20485699,
  47. .config_ctl_hi_val = 0x00002267,
  48. .config_ctl_hi1_val = 0x00000024,
  49. .test_ctl_val = 0x00000000,
  50. .test_ctl_hi_val = 0x00000000,
  51. .test_ctl_hi1_val = 0x00000020,
  52. .user_ctl_val = 0x00000000,
  53. .user_ctl_hi_val = 0x00000805,
  54. .user_ctl_hi1_val = 0x000000D0,
  55. };
  56. static struct clk_alpha_pll npu_cc_pll0 = {
  57. .offset = 0x0,
  58. .vco_table = trion_vco,
  59. .num_vco = ARRAY_SIZE(trion_vco),
  60. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TRION],
  61. .config = &npu_cc_pll0_config,
  62. .clkr = {
  63. .hw.init = &(struct clk_init_data){
  64. .name = "npu_cc_pll0",
  65. .parent_data = &(const struct clk_parent_data){
  66. .fw_name = "bi_tcxo",
  67. },
  68. .num_parents = 1,
  69. .ops = &clk_alpha_pll_trion_ops,
  70. },
  71. .vdd_data = {
  72. .vdd_class = &vdd_cx,
  73. .num_rate_max = VDD_NUM,
  74. .rate_max = (unsigned long[VDD_NUM]) {
  75. [VDD_MIN] = 615000000,
  76. [VDD_LOW] = 1066000000,
  77. [VDD_LOW_L1] = 1600000000,
  78. [VDD_NOMINAL] = 2000000000},
  79. },
  80. },
  81. };
  82. /* 800MHz configuration */
  83. static struct alpha_pll_config npu_cc_pll1_config = {
  84. .l = 0x29,
  85. .alpha = 0xAAAA,
  86. .config_ctl_val = 0x20485699,
  87. .config_ctl_hi_val = 0x00002267,
  88. .config_ctl_hi1_val = 0x00000024,
  89. .test_ctl_val = 0x00000000,
  90. .test_ctl_hi_val = 0x00000000,
  91. .test_ctl_hi1_val = 0x00000020,
  92. .user_ctl_val = 0x00000000,
  93. .user_ctl_hi_val = 0x00000805,
  94. .user_ctl_hi1_val = 0x000000D0,
  95. };
  96. static struct clk_alpha_pll npu_cc_pll1 = {
  97. .offset = 0x400,
  98. .vco_table = trion_vco,
  99. .num_vco = ARRAY_SIZE(trion_vco),
  100. .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_TRION],
  101. .config = &npu_cc_pll1_config,
  102. .clkr = {
  103. .hw.init = &(struct clk_init_data){
  104. .name = "npu_cc_pll1",
  105. .parent_data = &(const struct clk_parent_data){
  106. .fw_name = "bi_tcxo",
  107. },
  108. .num_parents = 1,
  109. .ops = &clk_alpha_pll_trion_ops,
  110. },
  111. .vdd_data = {
  112. .vdd_class = &vdd_cx,
  113. .num_rate_max = VDD_NUM,
  114. .rate_max = (unsigned long[VDD_NUM]) {
  115. [VDD_MIN] = 615000000,
  116. [VDD_LOW] = 1066000000,
  117. [VDD_LOW_L1] = 1600000000,
  118. [VDD_NOMINAL] = 2000000000},
  119. },
  120. },
  121. };
  122. static const struct parent_map npu_cc_parent_map_0[] = {
  123. { P_BI_TCXO, 0 },
  124. { P_NPU_CC_PLL1_OUT_EVEN, 1 },
  125. { P_NPU_CC_PLL0_OUT_EVEN, 2 },
  126. { P_GPLL0_OUT_MAIN, 4 },
  127. { P_GPLL0_OUT_MAIN_DIV, 5 },
  128. };
  129. static const struct clk_parent_data npu_cc_parent_data_0[] = {
  130. { .fw_name = "bi_tcxo" },
  131. { .hw = &npu_cc_pll1.clkr.hw },
  132. { .hw = &npu_cc_pll0.clkr.hw },
  133. { .fw_name = "gcc_npu_gpll0_clk_src" },
  134. { .fw_name = "gcc_npu_gpll0_div_clk_src" },
  135. };
  136. static struct clk_fixed_factor npu_cc_crc_div = {
  137. .mult = 1,
  138. .div = 2,
  139. .hw.init = &(struct clk_init_data){
  140. .name = "npu_cc_crc_div",
  141. .parent_data = &(const struct clk_parent_data){
  142. .hw = &npu_cc_pll0.clkr.hw,
  143. },
  144. .num_parents = 1,
  145. .flags = CLK_SET_RATE_PARENT,
  146. .ops = &clk_fixed_factor_ops,
  147. },
  148. };
  149. static const struct parent_map npu_cc_parent_map_1[] = {
  150. { P_BI_TCXO, 0 },
  151. { P_NPU_CC_PLL1_OUT_EVEN, 1 },
  152. { P_NPU_CC_CRC_DIV, 2 },
  153. { P_GPLL0_OUT_MAIN, 4 },
  154. { P_GPLL0_OUT_MAIN_DIV, 5 },
  155. };
  156. static const struct clk_parent_data npu_cc_parent_data_1[] = {
  157. { .fw_name = "bi_tcxo" },
  158. { .hw = &npu_cc_pll1.clkr.hw },
  159. { .hw = &npu_cc_crc_div.hw },
  160. { .fw_name = "gcc_npu_gpll0_clk_src" },
  161. { .fw_name = "gcc_npu_gpll0_div_clk_src" },
  162. };
  163. static const struct freq_tbl ftbl_npu_cc_cal_dp_clk_src[] = {
  164. F(300000000, P_NPU_CC_CRC_DIV, 1, 0, 0),
  165. F(400000000, P_NPU_CC_CRC_DIV, 1, 0, 0),
  166. F(487000000, P_NPU_CC_CRC_DIV, 1, 0, 0),
  167. F(652000000, P_NPU_CC_CRC_DIV, 1, 0, 0),
  168. F(811000000, P_NPU_CC_CRC_DIV, 1, 0, 0),
  169. F(908000000, P_NPU_CC_CRC_DIV, 1, 0, 0),
  170. { }
  171. };
  172. static struct clk_rcg2 npu_cc_cal_dp_clk_src = {
  173. .cmd_rcgr = 0x1004,
  174. .mnd_width = 0,
  175. .hid_width = 5,
  176. .parent_map = npu_cc_parent_map_1,
  177. .freq_tbl = ftbl_npu_cc_cal_dp_clk_src,
  178. .enable_safe_config = true,
  179. .clkr.hw.init = &(struct clk_init_data){
  180. .name = "npu_cc_cal_dp_clk_src",
  181. .parent_data = npu_cc_parent_data_1,
  182. .num_parents = ARRAY_SIZE(npu_cc_parent_data_1),
  183. .flags = CLK_SET_RATE_PARENT,
  184. .ops = &clk_rcg2_ops,
  185. },
  186. .clkr.vdd_data = {
  187. .vdd_class = &vdd_cx,
  188. .num_rate_max = VDD_NUM,
  189. .rate_max = (unsigned long[VDD_NUM]) {
  190. [VDD_LOWER] = 300000000,
  191. [VDD_LOW] = 400000000,
  192. [VDD_LOW_L1] = 487000000,
  193. [VDD_NOMINAL] = 652000000,
  194. [VDD_HIGH] = 811000000,
  195. [VDD_HIGH] = 908000000},
  196. },
  197. };
  198. static const struct freq_tbl ftbl_npu_cc_npu_core_clk_src[] = {
  199. F(60000000, P_GPLL0_OUT_MAIN_DIV, 5, 0, 0),
  200. F(100000000, P_GPLL0_OUT_MAIN, 6, 0, 0),
  201. F(150000000, P_GPLL0_OUT_MAIN, 4, 0, 0),
  202. F(200000000, P_NPU_CC_PLL1_OUT_EVEN, 4, 0, 0),
  203. F(300000000, P_GPLL0_OUT_MAIN, 2, 0, 0),
  204. F(400000000, P_NPU_CC_PLL1_OUT_EVEN, 2, 0, 0),
  205. { }
  206. };
  207. static struct clk_rcg2 npu_cc_npu_core_clk_src = {
  208. .cmd_rcgr = 0x1030,
  209. .mnd_width = 0,
  210. .hid_width = 5,
  211. .parent_map = npu_cc_parent_map_0,
  212. .freq_tbl = ftbl_npu_cc_npu_core_clk_src,
  213. .enable_safe_config = true,
  214. .clkr.hw.init = &(struct clk_init_data){
  215. .name = "npu_cc_npu_core_clk_src",
  216. .parent_data = npu_cc_parent_data_0,
  217. .num_parents = ARRAY_SIZE(npu_cc_parent_data_0),
  218. .ops = &clk_rcg2_ops,
  219. },
  220. .clkr.vdd_data = {
  221. .vdd_class = &vdd_cx,
  222. .num_rate_max = VDD_NUM,
  223. .rate_max = (unsigned long[VDD_NUM]) {
  224. [VDD_LOWER] = 100000000,
  225. [VDD_LOW] = 150000000,
  226. [VDD_LOW_L1] = 200000000,
  227. [VDD_NOMINAL] = 300000000,
  228. [VDD_HIGH] = 400000000},
  229. },
  230. };
  231. static struct clk_branch npu_cc_armwic_core_clk = {
  232. .halt_reg = 0x1058,
  233. .halt_check = BRANCH_HALT,
  234. .clkr = {
  235. .enable_reg = 0x1058,
  236. .enable_mask = BIT(0),
  237. .hw.init = &(struct clk_init_data){
  238. .name = "npu_cc_armwic_core_clk",
  239. .parent_hws = (const struct clk_hw*[]){
  240. &npu_cc_npu_core_clk_src.clkr.hw,
  241. },
  242. .num_parents = 1,
  243. .flags = CLK_SET_RATE_PARENT,
  244. .ops = &clk_branch2_ops,
  245. },
  246. },
  247. };
  248. /* CLK_DONT_HOLD_STATE flag is needed due to sync_state */
  249. static struct clk_branch npu_cc_bto_core_clk = {
  250. .halt_reg = 0x1090,
  251. .halt_check = BRANCH_HALT,
  252. .clkr = {
  253. .enable_reg = 0x1090,
  254. .enable_mask = BIT(0),
  255. .hw.init = &(struct clk_init_data){
  256. .name = "npu_cc_bto_core_clk",
  257. .flags = CLK_DONT_HOLD_STATE,
  258. .ops = &clk_branch2_ops,
  259. },
  260. },
  261. };
  262. static struct clk_branch npu_cc_bwmon_clk = {
  263. .halt_reg = 0x1088,
  264. .halt_check = BRANCH_HALT,
  265. .clkr = {
  266. .enable_reg = 0x1088,
  267. .enable_mask = BIT(0),
  268. .hw.init = &(struct clk_init_data){
  269. .name = "npu_cc_bwmon_clk",
  270. .ops = &clk_branch2_ops,
  271. },
  272. },
  273. };
  274. static struct clk_branch npu_cc_cal_dp_cdc_clk = {
  275. .halt_reg = 0x1068,
  276. .halt_check = BRANCH_HALT,
  277. .clkr = {
  278. .enable_reg = 0x1068,
  279. .enable_mask = BIT(0),
  280. .hw.init = &(struct clk_init_data){
  281. .name = "npu_cc_cal_dp_cdc_clk",
  282. .parent_hws = (const struct clk_hw*[]){
  283. &npu_cc_cal_dp_clk_src.clkr.hw,
  284. },
  285. .num_parents = 1,
  286. .flags = CLK_SET_RATE_PARENT,
  287. .ops = &clk_branch2_ops,
  288. },
  289. },
  290. };
  291. static struct clk_branch npu_cc_cal_dp_clk = {
  292. .halt_reg = 0x101c,
  293. .halt_check = BRANCH_HALT,
  294. .clkr = {
  295. .enable_reg = 0x101c,
  296. .enable_mask = BIT(0),
  297. .hw.init = &(struct clk_init_data){
  298. .name = "npu_cc_cal_dp_clk",
  299. .parent_hws = (const struct clk_hw*[]){
  300. &npu_cc_cal_dp_clk_src.clkr.hw,
  301. },
  302. .num_parents = 1,
  303. .flags = CLK_SET_RATE_PARENT,
  304. .ops = &clk_branch2_ops,
  305. },
  306. },
  307. };
  308. static struct clk_branch npu_cc_comp_noc_axi_clk = {
  309. .halt_reg = 0x106c,
  310. .halt_check = BRANCH_HALT,
  311. .clkr = {
  312. .enable_reg = 0x106c,
  313. .enable_mask = BIT(0),
  314. .hw.init = &(struct clk_init_data){
  315. .name = "npu_cc_comp_noc_axi_clk",
  316. .parent_data = &(const struct clk_parent_data){
  317. .fw_name = "gcc_npu_axi_clk",
  318. },
  319. .num_parents = 1,
  320. .ops = &clk_branch2_ops,
  321. },
  322. },
  323. };
  324. static struct clk_branch npu_cc_conf_noc_ahb_clk = {
  325. .halt_reg = 0x1074,
  326. .halt_check = BRANCH_HALT,
  327. .clkr = {
  328. .enable_reg = 0x1074,
  329. .enable_mask = BIT(0),
  330. .hw.init = &(struct clk_init_data){
  331. .name = "npu_cc_conf_noc_ahb_clk",
  332. .ops = &clk_branch2_ops,
  333. },
  334. },
  335. };
  336. static struct clk_branch npu_cc_npu_core_apb_clk = {
  337. .halt_reg = 0x1080,
  338. .halt_check = BRANCH_HALT,
  339. .clkr = {
  340. .enable_reg = 0x1080,
  341. .enable_mask = BIT(0),
  342. .hw.init = &(struct clk_init_data){
  343. .name = "npu_cc_npu_core_apb_clk",
  344. .ops = &clk_branch2_ops,
  345. },
  346. },
  347. };
  348. static struct clk_branch npu_cc_npu_core_atb_clk = {
  349. .halt_reg = 0x1078,
  350. .halt_check = BRANCH_HALT,
  351. .clkr = {
  352. .enable_reg = 0x1078,
  353. .enable_mask = BIT(0),
  354. .hw.init = &(struct clk_init_data){
  355. .name = "npu_cc_npu_core_atb_clk",
  356. .ops = &clk_branch2_ops,
  357. },
  358. },
  359. };
  360. static struct clk_branch npu_cc_npu_core_clk = {
  361. .halt_reg = 0x1048,
  362. .halt_check = BRANCH_HALT,
  363. .clkr = {
  364. .enable_reg = 0x1048,
  365. .enable_mask = BIT(0),
  366. .hw.init = &(struct clk_init_data){
  367. .name = "npu_cc_npu_core_clk",
  368. .parent_hws = (const struct clk_hw*[]){
  369. &npu_cc_npu_core_clk_src.clkr.hw,
  370. },
  371. .num_parents = 1,
  372. .flags = CLK_SET_RATE_PARENT,
  373. .ops = &clk_branch2_ops,
  374. },
  375. },
  376. };
  377. static struct clk_branch npu_cc_npu_core_cti_clk = {
  378. .halt_reg = 0x107c,
  379. .halt_check = BRANCH_HALT,
  380. .clkr = {
  381. .enable_reg = 0x107c,
  382. .enable_mask = BIT(0),
  383. .hw.init = &(struct clk_init_data){
  384. .name = "npu_cc_npu_core_cti_clk",
  385. .ops = &clk_branch2_ops,
  386. },
  387. },
  388. };
  389. static struct clk_branch npu_cc_npu_cpc_clk = {
  390. .halt_reg = 0x1050,
  391. .halt_check = BRANCH_HALT,
  392. .clkr = {
  393. .enable_reg = 0x1050,
  394. .enable_mask = BIT(0),
  395. .hw.init = &(struct clk_init_data){
  396. .name = "npu_cc_npu_cpc_clk",
  397. .parent_hws = (const struct clk_hw*[]){
  398. &npu_cc_npu_core_clk_src.clkr.hw,
  399. },
  400. .num_parents = 1,
  401. .flags = CLK_SET_RATE_PARENT,
  402. .ops = &clk_branch2_ops,
  403. },
  404. },
  405. };
  406. static struct clk_branch npu_cc_npu_cpc_timer_clk = {
  407. .halt_reg = 0x105c,
  408. .halt_check = BRANCH_HALT,
  409. .clkr = {
  410. .enable_reg = 0x105c,
  411. .enable_mask = BIT(0),
  412. .hw.init = &(struct clk_init_data){
  413. .name = "npu_cc_npu_cpc_timer_clk",
  414. .ops = &clk_branch2_ops,
  415. },
  416. },
  417. };
  418. static struct clk_branch npu_cc_perf_cnt_clk = {
  419. .halt_reg = 0x108c,
  420. .halt_check = BRANCH_HALT_DELAY,
  421. .clkr = {
  422. .enable_reg = 0x108c,
  423. .enable_mask = BIT(0),
  424. .hw.init = &(struct clk_init_data){
  425. .name = "npu_cc_perf_cnt_clk",
  426. .parent_hws = (const struct clk_hw*[]){
  427. &npu_cc_cal_dp_clk_src.clkr.hw,
  428. },
  429. .num_parents = 1,
  430. .flags = CLK_SET_RATE_PARENT,
  431. .ops = &clk_branch2_ops,
  432. },
  433. },
  434. };
  435. static struct clk_branch npu_cc_qtimer_core_clk = {
  436. .halt_reg = 0x1060,
  437. .halt_check = BRANCH_HALT,
  438. .clkr = {
  439. .enable_reg = 0x1060,
  440. .enable_mask = BIT(0),
  441. .hw.init = &(struct clk_init_data){
  442. .name = "npu_cc_qtimer_core_clk",
  443. .ops = &clk_branch2_ops,
  444. },
  445. },
  446. };
  447. static struct clk_branch npu_cc_sleep_clk = {
  448. .halt_reg = 0x1064,
  449. .halt_check = BRANCH_HALT,
  450. .clkr = {
  451. .enable_reg = 0x1064,
  452. .enable_mask = BIT(0),
  453. .hw.init = &(struct clk_init_data){
  454. .name = "npu_cc_sleep_clk",
  455. .ops = &clk_branch2_ops,
  456. },
  457. },
  458. };
  459. static struct critical_clk_offset critical_clk_list[] = {
  460. { .offset = 0x3020, .mask = BIT(0) },
  461. };
  462. static struct clk_regmap *npu_cc_sm8150_clocks[] = {
  463. [NPU_CC_PLL0] = &npu_cc_pll0.clkr,
  464. [NPU_CC_PLL1] = &npu_cc_pll1.clkr,
  465. [NPU_CC_ARMWIC_CORE_CLK] = &npu_cc_armwic_core_clk.clkr,
  466. [NPU_CC_BTO_CORE_CLK] = &npu_cc_bto_core_clk.clkr,
  467. [NPU_CC_BWMON_CLK] = &npu_cc_bwmon_clk.clkr,
  468. [NPU_CC_CAL_DP_CDC_CLK] = &npu_cc_cal_dp_cdc_clk.clkr,
  469. [NPU_CC_CAL_DP_CLK] = &npu_cc_cal_dp_clk.clkr,
  470. [NPU_CC_CAL_DP_CLK_SRC] = &npu_cc_cal_dp_clk_src.clkr,
  471. [NPU_CC_COMP_NOC_AXI_CLK] = &npu_cc_comp_noc_axi_clk.clkr,
  472. [NPU_CC_CONF_NOC_AHB_CLK] = &npu_cc_conf_noc_ahb_clk.clkr,
  473. [NPU_CC_NPU_CORE_APB_CLK] = &npu_cc_npu_core_apb_clk.clkr,
  474. [NPU_CC_NPU_CORE_ATB_CLK] = &npu_cc_npu_core_atb_clk.clkr,
  475. [NPU_CC_NPU_CORE_CLK] = &npu_cc_npu_core_clk.clkr,
  476. [NPU_CC_NPU_CORE_CLK_SRC] = &npu_cc_npu_core_clk_src.clkr,
  477. [NPU_CC_NPU_CORE_CTI_CLK] = &npu_cc_npu_core_cti_clk.clkr,
  478. [NPU_CC_NPU_CPC_CLK] = &npu_cc_npu_cpc_clk.clkr,
  479. [NPU_CC_NPU_CPC_TIMER_CLK] = &npu_cc_npu_cpc_timer_clk.clkr,
  480. [NPU_CC_PERF_CNT_CLK] = &npu_cc_perf_cnt_clk.clkr,
  481. [NPU_CC_QTIMER_CORE_CLK] = &npu_cc_qtimer_core_clk.clkr,
  482. [NPU_CC_SLEEP_CLK] = &npu_cc_sleep_clk.clkr,
  483. };
  484. static const struct qcom_reset_map npu_cc_sm8150_resets[] = {
  485. [NPU_CC_CAL_DP_BCR] = { 0x1000 },
  486. [NPU_CC_NPU_CORE_BCR] = { 0x1024 },
  487. };
  488. static const struct regmap_config npu_cc_sm8150_regmap_config = {
  489. .reg_bits = 32,
  490. .reg_stride = 4,
  491. .val_bits = 32,
  492. .max_register = 0x8000,
  493. .fast_io = true,
  494. };
  495. static struct qcom_cc_desc npu_cc_sm8150_desc = {
  496. .config = &npu_cc_sm8150_regmap_config,
  497. .clks = npu_cc_sm8150_clocks,
  498. .num_clks = ARRAY_SIZE(npu_cc_sm8150_clocks),
  499. .resets = npu_cc_sm8150_resets,
  500. .num_resets = ARRAY_SIZE(npu_cc_sm8150_resets),
  501. .clk_regulators = npu_cc_sm8150_regulators,
  502. .num_clk_regulators = ARRAY_SIZE(npu_cc_sm8150_regulators),
  503. .critical_clk_en = critical_clk_list,
  504. .num_critical_clk = ARRAY_SIZE(critical_clk_list),
  505. };
  506. static const struct of_device_id npu_cc_sm8150_match_table[] = {
  507. { .compatible = "qcom,sm8150-npucc" },
  508. { .compatible = "qcom,sa8155-npucc" },
  509. { }
  510. };
  511. MODULE_DEVICE_TABLE(of, npu_cc_sm8150_match_table);
  512. static struct regulator *vdd_gdsc;
  513. static int enable_npu_crc(struct regmap *regmap)
  514. {
  515. int ret;
  516. /* Set npu_cc_cal_cp_clk to the lowest supported frequency */
  517. clk_set_rate(npu_cc_cal_dp_clk.clkr.hw.clk,
  518. clk_round_rate(npu_cc_cal_dp_clk_src.clkr.hw.clk, 1));
  519. /* Turn on the NPU GDSC */
  520. ret = regulator_enable(vdd_gdsc);
  521. if (ret) {
  522. pr_err("Failed to enable the NPU GDSC during CRC sequence\n");
  523. return ret;
  524. }
  525. /* Enable npu_cc_cal_cp_clk */
  526. ret = clk_prepare_enable(npu_cc_cal_dp_clk.clkr.hw.clk);
  527. if (ret) {
  528. pr_err("Failed to enable npu_cc_cal_dp_clk during CRC sequence\n");
  529. return ret;
  530. }
  531. /* Enable MND RC */
  532. regmap_write(regmap, CRC_MND_CFG, CRC_MND_CFG_SETTING);
  533. regmap_write(regmap, CRC_SID_FSM_CTRL, CRC_SID_FSM_CTRL_SETTING);
  534. /* Wait for 16 cycles before continuing */
  535. udelay(1);
  536. /* Disable npu_cc_cal_cp_clk */
  537. clk_disable_unprepare(npu_cc_cal_dp_clk.clkr.hw.clk);
  538. /* Turn off the NPU GDSC */
  539. regulator_disable(vdd_gdsc);
  540. return ret;
  541. }
  542. static int npu_cc_sm8150_probe(struct platform_device *pdev)
  543. {
  544. struct regmap *regmap;
  545. int ret;
  546. vdd_gdsc = devm_regulator_get(&pdev->dev, "vdd_gdsc");
  547. if (IS_ERR(vdd_gdsc)) {
  548. if (!(PTR_ERR(vdd_gdsc) == -EPROBE_DEFER))
  549. dev_err(&pdev->dev,
  550. "Unable to get vdd_gdsc regulator\n");
  551. return PTR_ERR(vdd_gdsc);
  552. }
  553. regmap = qcom_cc_map(pdev, &npu_cc_sm8150_desc);
  554. if (IS_ERR(regmap)) {
  555. pr_err("Failed to map the npu CC registers\n");
  556. return PTR_ERR(regmap);
  557. }
  558. clk_trion_pll_configure(&npu_cc_pll0, regmap, npu_cc_pll0.config);
  559. clk_trion_pll_configure(&npu_cc_pll1, regmap, npu_cc_pll1.config);
  560. /*
  561. * Keep clocks always enabled:
  562. * npu_cc_xo_clk
  563. */
  564. regmap_update_bits(regmap, 0x3020, BIT(0), BIT(0));
  565. /* Register the fixed factor clock for CRC divide */
  566. ret = devm_clk_hw_register(&pdev->dev, &npu_cc_crc_div.hw);
  567. if (ret) {
  568. dev_err(&pdev->dev, "Failed to register CRC divide clock\n");
  569. return ret;
  570. }
  571. ret = qcom_cc_really_probe(pdev, &npu_cc_sm8150_desc, regmap);
  572. if (ret) {
  573. dev_err(&pdev->dev, "Failed to register NPU CC clocks\n");
  574. return ret;
  575. }
  576. ret = enable_npu_crc(regmap);
  577. if (ret) {
  578. dev_err(&pdev->dev, "Failed to enable CRC for NPU cal RCG\n");
  579. return ret;
  580. }
  581. ret = register_qcom_clks_pm(pdev, false, &npu_cc_sm8150_desc);
  582. if (ret)
  583. dev_err(&pdev->dev, "Failed to register for pm ops\n");
  584. dev_info(&pdev->dev, "Registered NPU CC clocks\n");
  585. return ret;
  586. }
  587. static void npu_cc_sm8150_sync_state(struct device *dev)
  588. {
  589. qcom_cc_sync_state(dev, &npu_cc_sm8150_desc);
  590. }
  591. static struct platform_driver npu_cc_sm8150_driver = {
  592. .probe = npu_cc_sm8150_probe,
  593. .driver = {
  594. .name = "npu_cc-sm8150",
  595. .of_match_table = npu_cc_sm8150_match_table,
  596. .sync_state = npu_cc_sm8150_sync_state,
  597. },
  598. };
  599. static int __init npu_cc_sm8150_init(void)
  600. {
  601. return platform_driver_register(&npu_cc_sm8150_driver);
  602. }
  603. subsys_initcall(npu_cc_sm8150_init);
  604. static void __exit npu_cc_sm8150_exit(void)
  605. {
  606. platform_driver_unregister(&npu_cc_sm8150_driver);
  607. }
  608. module_exit(npu_cc_sm8150_exit);
  609. MODULE_DESCRIPTION("QTI NPU_CC SM8150 Driver");
  610. MODULE_LICENSE("GPL");