lpass-cdc-clk-rsc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/of_platform.h>
  6. #include <linux/module.h>
  7. #include <linux/io.h>
  8. #include <linux/init.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/kernel.h>
  11. #include <linux/clk.h>
  12. #include <linux/clk-provider.h>
  13. #include "lpass-cdc.h"
  14. #include "lpass-cdc-clk-rsc.h"
  15. #define DRV_NAME "lpass-cdc-clk-rsc"
  16. #define LPASS_CDC_CLK_NAME_LENGTH 30
  17. static char clk_src_name[MAX_CLK][LPASS_CDC_CLK_NAME_LENGTH] = {
  18. "tx_core_clk",
  19. "rx_core_clk",
  20. "wsa_core_clk",
  21. "va_core_clk",
  22. "wsa2_core_clk",
  23. "rx_tx_core_clk",
  24. "wsa_tx_core_clk",
  25. "wsa2_tx_core_clk",
  26. };
  27. struct lpass_cdc_clk_rsc {
  28. struct device *dev;
  29. struct mutex rsc_clk_lock;
  30. struct mutex fs_gen_lock;
  31. struct clk *clk[MAX_CLK];
  32. int clk_cnt[MAX_CLK];
  33. int reg_seq_en_cnt;
  34. int va_tx_clk_cnt;
  35. bool dev_up;
  36. bool dev_up_gfmux;
  37. u32 num_fs_reg;
  38. u32 *fs_gen_seq;
  39. int default_clk_id[MAX_CLK];
  40. struct regmap *regmap;
  41. char __iomem *rx_clk_muxsel;
  42. char __iomem *wsa_clk_muxsel;
  43. char __iomem *va_clk_muxsel;
  44. };
  45. static int lpass_cdc_clk_rsc_cb(struct device *dev, u16 event)
  46. {
  47. struct lpass_cdc_clk_rsc *priv;
  48. if (!dev) {
  49. pr_err("%s: Invalid device pointer\n",
  50. __func__);
  51. return -EINVAL;
  52. }
  53. priv = dev_get_drvdata(dev);
  54. if (!priv) {
  55. pr_err("%s: Invalid clk rsc priviate data\n",
  56. __func__);
  57. return -EINVAL;
  58. }
  59. mutex_lock(&priv->rsc_clk_lock);
  60. if (event == LPASS_CDC_MACRO_EVT_SSR_UP) {
  61. priv->dev_up = true;
  62. } else if (event == LPASS_CDC_MACRO_EVT_SSR_DOWN) {
  63. priv->dev_up = false;
  64. priv->dev_up_gfmux = false;
  65. } else if (event == LPASS_CDC_MACRO_EVT_SSR_GFMUX_UP) {
  66. priv->dev_up_gfmux = true;
  67. }
  68. mutex_unlock(&priv->rsc_clk_lock);
  69. return 0;
  70. }
  71. static char __iomem *lpass_cdc_clk_rsc_get_clk_muxsel(struct lpass_cdc_clk_rsc *priv,
  72. int clk_id)
  73. {
  74. switch (clk_id) {
  75. case RX_CORE_CLK:
  76. return priv->rx_clk_muxsel;
  77. case WSA_CORE_CLK:
  78. case WSA2_CORE_CLK:
  79. return priv->wsa_clk_muxsel;
  80. case VA_CORE_CLK:
  81. return priv->va_clk_muxsel;
  82. case TX_CORE_CLK:
  83. case RX_TX_CORE_CLK:
  84. case WSA_TX_CORE_CLK:
  85. case WSA2_TX_CORE_CLK:
  86. default:
  87. dev_err_ratelimited(priv->dev, "%s: Invalid case\n", __func__);
  88. break;
  89. }
  90. return NULL;
  91. }
  92. int lpass_cdc_rsc_clk_reset(struct device *dev, int clk_id)
  93. {
  94. struct device *clk_dev = NULL;
  95. struct lpass_cdc_clk_rsc *priv = NULL;
  96. int count = 0;
  97. if (!dev) {
  98. pr_err("%s: dev is null %d\n", __func__);
  99. return -EINVAL;
  100. }
  101. if (clk_id < 0 || clk_id >= MAX_CLK) {
  102. pr_err("%s: Invalid clk_id: %d\n",
  103. __func__, clk_id);
  104. return -EINVAL;
  105. }
  106. clk_dev = lpass_cdc_get_rsc_clk_device_ptr(dev->parent);
  107. if (!clk_dev) {
  108. pr_err("%s: Invalid rsc clk device\n", __func__);
  109. return -EINVAL;
  110. }
  111. priv = dev_get_drvdata(clk_dev);
  112. if (!priv) {
  113. pr_err("%s: Invalid rsc clk priviate data\n", __func__);
  114. return -EINVAL;
  115. }
  116. mutex_lock(&priv->rsc_clk_lock);
  117. while (__clk_is_enabled(priv->clk[clk_id])) {
  118. clk_disable_unprepare(priv->clk[clk_id]);
  119. count++;
  120. }
  121. dev_dbg(priv->dev,
  122. "%s: clock reset after ssr, count %d\n", __func__, count);
  123. trace_printk("%s: clock reset after ssr, count %d\n", __func__, count);
  124. while (count--) {
  125. clk_prepare_enable(priv->clk[clk_id]);
  126. }
  127. mutex_unlock(&priv->rsc_clk_lock);
  128. return 0;
  129. }
  130. EXPORT_SYMBOL(lpass_cdc_rsc_clk_reset);
  131. void lpass_cdc_clk_rsc_enable_all_clocks(struct device *dev, bool enable)
  132. {
  133. struct device *clk_dev = NULL;
  134. struct lpass_cdc_clk_rsc *priv = NULL;
  135. int i = 0;
  136. if (!dev) {
  137. pr_err("%s: dev is null %d\n", __func__);
  138. return;
  139. }
  140. clk_dev = lpass_cdc_get_rsc_clk_device_ptr(dev->parent);
  141. if (!clk_dev) {
  142. pr_err("%s: Invalid rsc clk device\n", __func__);
  143. return;
  144. }
  145. priv = dev_get_drvdata(clk_dev);
  146. if (!priv) {
  147. pr_err("%s: Invalid rsc clk private data\n", __func__);
  148. return;
  149. }
  150. mutex_lock(&priv->rsc_clk_lock);
  151. for (i = 0; i < MAX_CLK; i++) {
  152. if (enable) {
  153. if (priv->clk[i])
  154. clk_prepare_enable(priv->clk[i]);
  155. } else {
  156. if (priv->clk[i])
  157. clk_disable_unprepare(priv->clk[i]);
  158. }
  159. }
  160. mutex_unlock(&priv->rsc_clk_lock);
  161. return;
  162. }
  163. EXPORT_SYMBOL(lpass_cdc_clk_rsc_enable_all_clocks);
  164. static int lpass_cdc_clk_rsc_mux0_clk_request(struct lpass_cdc_clk_rsc *priv,
  165. int clk_id,
  166. bool enable)
  167. {
  168. int ret = 0;
  169. if (enable) {
  170. /* Enable Requested Core clk */
  171. if (priv->clk_cnt[clk_id] == 0) {
  172. ret = clk_prepare_enable(priv->clk[clk_id]);
  173. if (ret < 0) {
  174. dev_err_ratelimited(priv->dev, "%s:clk_id %d enable failed\n",
  175. __func__, clk_id);
  176. goto done;
  177. }
  178. }
  179. priv->clk_cnt[clk_id]++;
  180. } else {
  181. if (priv->clk_cnt[clk_id] <= 0) {
  182. dev_err_ratelimited(priv->dev, "%s: clk_id: %d is already disabled\n",
  183. __func__, clk_id);
  184. priv->clk_cnt[clk_id] = 0;
  185. goto done;
  186. }
  187. priv->clk_cnt[clk_id]--;
  188. if (priv->clk_cnt[clk_id] == 0)
  189. clk_disable_unprepare(priv->clk[clk_id]);
  190. }
  191. done:
  192. return ret;
  193. }
  194. static int lpass_cdc_clk_rsc_mux1_clk_request(struct lpass_cdc_clk_rsc *priv,
  195. int clk_id,
  196. bool enable)
  197. {
  198. char __iomem *clk_muxsel = NULL;
  199. int ret = 0;
  200. int default_clk_id = priv->default_clk_id[clk_id];
  201. u32 muxsel = 0;
  202. clk_muxsel = lpass_cdc_clk_rsc_get_clk_muxsel(priv, clk_id);
  203. if (!clk_muxsel) {
  204. ret = -EINVAL;
  205. goto done;
  206. }
  207. if (enable) {
  208. if (priv->clk_cnt[clk_id] == 0) {
  209. ret = lpass_cdc_clk_rsc_mux0_clk_request(priv,
  210. default_clk_id,
  211. true);
  212. if (ret < 0)
  213. goto done;
  214. ret = clk_prepare_enable(priv->clk[clk_id]);
  215. if (ret < 0) {
  216. dev_err_ratelimited(priv->dev, "%s:clk_id %d enable failed\n",
  217. __func__, clk_id);
  218. goto err_clk;
  219. }
  220. if (priv->dev_up_gfmux) {
  221. iowrite32(0x1, clk_muxsel);
  222. muxsel = ioread32(clk_muxsel);
  223. trace_printk("%s: muxsel value after enable: %d\n",
  224. __func__, muxsel);
  225. }
  226. lpass_cdc_clk_rsc_mux0_clk_request(priv, default_clk_id,
  227. false);
  228. }
  229. priv->clk_cnt[clk_id]++;
  230. } else {
  231. if (priv->clk_cnt[clk_id] <= 0) {
  232. dev_err_ratelimited(priv->dev, "%s: clk_id: %d is already disabled\n",
  233. __func__, clk_id);
  234. priv->clk_cnt[clk_id] = 0;
  235. goto done;
  236. }
  237. priv->clk_cnt[clk_id]--;
  238. if (priv->clk_cnt[clk_id] == 0) {
  239. ret = lpass_cdc_clk_rsc_mux0_clk_request(priv,
  240. default_clk_id, true);
  241. if (!ret && priv->dev_up_gfmux) {
  242. iowrite32(0x0, clk_muxsel);
  243. muxsel = ioread32(clk_muxsel);
  244. trace_printk("%s: muxsel value after disable: %d\n",
  245. __func__, muxsel);
  246. }
  247. clk_disable_unprepare(priv->clk[clk_id]);
  248. if (!ret)
  249. lpass_cdc_clk_rsc_mux0_clk_request(priv,
  250. default_clk_id, false);
  251. }
  252. }
  253. return ret;
  254. err_clk:
  255. lpass_cdc_clk_rsc_mux0_clk_request(priv, default_clk_id, false);
  256. done:
  257. return ret;
  258. }
  259. static int lpass_cdc_clk_rsc_check_and_update_va_clk(struct lpass_cdc_clk_rsc *priv,
  260. bool mux_switch,
  261. int clk_id,
  262. bool enable)
  263. {
  264. int ret = 0;
  265. if (enable) {
  266. if (clk_id == VA_CORE_CLK && mux_switch) {
  267. /*
  268. * Handle the following usecase scenarios during enable
  269. * 1. VA only, Active clk is VA_CORE_CLK
  270. * 2. record -> record + VA, Active clk is TX_CORE_CLK
  271. */
  272. if (priv->clk_cnt[TX_CORE_CLK] == 0) {
  273. ret = lpass_cdc_clk_rsc_mux1_clk_request(priv,
  274. VA_CORE_CLK, enable);
  275. if (ret < 0)
  276. goto err;
  277. } else {
  278. ret = lpass_cdc_clk_rsc_mux0_clk_request(priv,
  279. TX_CORE_CLK, enable);
  280. if (ret < 0)
  281. goto err;
  282. priv->va_tx_clk_cnt++;
  283. }
  284. } else if ((priv->clk_cnt[TX_CORE_CLK] > 0) &&
  285. (priv->clk_cnt[VA_CORE_CLK] > 0)) {
  286. /*
  287. * Handle following concurrency scenario during enable
  288. * 1. VA-> Record+VA, Increment TX CLK and Disable VA
  289. * 2. VA-> Playback+VA, Increment TX CLK and Disable VA
  290. */
  291. while (priv->clk_cnt[VA_CORE_CLK] > 0) {
  292. ret = lpass_cdc_clk_rsc_mux0_clk_request(priv,
  293. TX_CORE_CLK, true);
  294. if (ret < 0)
  295. goto err;
  296. lpass_cdc_clk_rsc_mux1_clk_request(priv,
  297. VA_CORE_CLK, false);
  298. priv->va_tx_clk_cnt++;
  299. }
  300. }
  301. } else {
  302. if (clk_id == VA_CORE_CLK && mux_switch) {
  303. /*
  304. * Handle the following usecase scenarios during disable
  305. * 1. VA only, disable VA_CORE_CLK
  306. * 2. Record + VA -> Record, decrement TX CLK count
  307. */
  308. if (priv->clk_cnt[VA_CORE_CLK]) {
  309. lpass_cdc_clk_rsc_mux1_clk_request(priv,
  310. VA_CORE_CLK, enable);
  311. } else if (priv->va_tx_clk_cnt) {
  312. lpass_cdc_clk_rsc_mux0_clk_request(priv,
  313. TX_CORE_CLK, enable);
  314. priv->va_tx_clk_cnt--;
  315. }
  316. } else if (priv->va_tx_clk_cnt == priv->clk_cnt[TX_CORE_CLK]) {
  317. /*
  318. * Handle the following usecase scenarios during disable
  319. * Record+VA-> VA: enable VA CLK, decrement TX CLK count
  320. */
  321. while (priv->va_tx_clk_cnt) {
  322. ret = lpass_cdc_clk_rsc_mux1_clk_request(priv,
  323. VA_CORE_CLK, true);
  324. if (ret < 0)
  325. goto err;
  326. lpass_cdc_clk_rsc_mux0_clk_request(priv,
  327. TX_CORE_CLK, false);
  328. priv->va_tx_clk_cnt--;
  329. }
  330. }
  331. }
  332. err:
  333. return ret;
  334. }
  335. /**
  336. * lpass_cdc_clk_rsc_fs_gen_request - request to enable/disable fs generation
  337. * sequence
  338. *
  339. * @dev: Macro device pointer
  340. * @enable: enable or disable flag
  341. */
  342. void lpass_cdc_clk_rsc_fs_gen_request(struct device *dev, bool enable)
  343. {
  344. int i;
  345. struct regmap *regmap;
  346. struct device *clk_dev = NULL;
  347. struct lpass_cdc_clk_rsc *priv = NULL;
  348. if (!dev) {
  349. pr_err("%s: dev is null %d\n", __func__);
  350. return;
  351. }
  352. clk_dev = lpass_cdc_get_rsc_clk_device_ptr(dev->parent);
  353. if (!clk_dev) {
  354. pr_err("%s: Invalid rsc clk device\n", __func__);
  355. return;
  356. }
  357. priv = dev_get_drvdata(clk_dev);
  358. if (!priv) {
  359. pr_err("%s: Invalid rsc clk priviate data\n", __func__);
  360. return;
  361. }
  362. regmap = dev_get_regmap(priv->dev->parent, NULL);
  363. if (!regmap) {
  364. pr_err("%s: regmap is null\n", __func__);
  365. return;
  366. }
  367. mutex_lock(&priv->fs_gen_lock);
  368. if (enable) {
  369. if (priv->reg_seq_en_cnt++ == 0) {
  370. for (i = 0; i < (priv->num_fs_reg * 3); i += 3) {
  371. dev_dbg(priv->dev, "%s: Register: %d, mask: %d, value: %d\n",
  372. __func__, priv->fs_gen_seq[i],
  373. priv->fs_gen_seq[i + 1],
  374. priv->fs_gen_seq[i + 2]);
  375. regmap_update_bits(regmap,
  376. priv->fs_gen_seq[i],
  377. priv->fs_gen_seq[i + 1],
  378. priv->fs_gen_seq[i + 2]);
  379. }
  380. }
  381. } else {
  382. if (priv->reg_seq_en_cnt <= 0) {
  383. dev_err_ratelimited(priv->dev, "%s: req_seq_cnt: %d is already disabled\n",
  384. __func__, priv->reg_seq_en_cnt);
  385. priv->reg_seq_en_cnt = 0;
  386. mutex_unlock(&priv->fs_gen_lock);
  387. return;
  388. }
  389. if (--priv->reg_seq_en_cnt == 0) {
  390. for (i = ((priv->num_fs_reg - 1) * 3); i >= 0; i -= 3) {
  391. dev_dbg(priv->dev, "%s: Register: %d, mask: %d\n",
  392. __func__, priv->fs_gen_seq[i],
  393. priv->fs_gen_seq[i + 1]);
  394. regmap_update_bits(regmap, priv->fs_gen_seq[i],
  395. priv->fs_gen_seq[i + 1], 0x0);
  396. }
  397. }
  398. }
  399. mutex_unlock(&priv->fs_gen_lock);
  400. }
  401. EXPORT_SYMBOL(lpass_cdc_clk_rsc_fs_gen_request);
  402. /**
  403. * lpass_cdc_clk_rsc_request_clock - request for clock to
  404. * enable/disable
  405. *
  406. * @dev: Macro device pointer.
  407. * @default_clk_id: mux0 Core clock ID input.
  408. * @clk_id_req: Core clock ID requested to enable/disable
  409. * @enable: enable or disable clock flag
  410. *
  411. * Returns 0 on success or -EINVAL on error.
  412. */
  413. int lpass_cdc_clk_rsc_request_clock(struct device *dev,
  414. int default_clk_id,
  415. int clk_id_req,
  416. bool enable)
  417. {
  418. int ret = 0;
  419. struct device *clk_dev = NULL;
  420. struct lpass_cdc_clk_rsc *priv = NULL;
  421. bool mux_switch = false;
  422. if (!dev) {
  423. pr_err("%s: dev is null %d\n", __func__);
  424. return -EINVAL;
  425. }
  426. if ((clk_id_req < 0 || clk_id_req >= MAX_CLK) &&
  427. (default_clk_id < 0 || default_clk_id >= MAX_CLK)) {
  428. pr_err("%s: Invalid clk_id_req: %d or default_clk_id: %d\n",
  429. __func__, clk_id_req, default_clk_id);
  430. return -EINVAL;
  431. }
  432. clk_dev = lpass_cdc_get_rsc_clk_device_ptr(dev->parent);
  433. if (!clk_dev) {
  434. pr_err("%s: Invalid rsc clk device\n", __func__);
  435. return -EINVAL;
  436. }
  437. priv = dev_get_drvdata(clk_dev);
  438. if (!priv) {
  439. pr_err("%s: Invalid rsc clk priviate data\n", __func__);
  440. return -EINVAL;
  441. }
  442. mutex_lock(&priv->rsc_clk_lock);
  443. if (!priv->dev_up && enable) {
  444. dev_err_ratelimited(priv->dev, "%s: SSR is in progress..\n",
  445. __func__);
  446. trace_printk("%s: SSR is in progress..\n", __func__);
  447. ret = -EINVAL;
  448. goto err;
  449. }
  450. priv->default_clk_id[clk_id_req] = default_clk_id;
  451. if (default_clk_id != clk_id_req)
  452. mux_switch = true;
  453. if (mux_switch) {
  454. ret = lpass_cdc_clk_rsc_mux1_clk_request(priv, clk_id_req,
  455. enable);
  456. if (ret < 0)
  457. goto err;
  458. } else {
  459. ret = lpass_cdc_clk_rsc_mux0_clk_request(priv, clk_id_req, enable);
  460. if (ret < 0)
  461. goto err;
  462. }
  463. ret = lpass_cdc_clk_rsc_check_and_update_va_clk(priv, mux_switch,
  464. clk_id_req,
  465. enable);
  466. if (ret < 0)
  467. goto err;
  468. dev_dbg(priv->dev, "%s: clk_cnt: %d for requested clk: %d, enable: %d\n",
  469. __func__, priv->clk_cnt[clk_id_req], clk_id_req,
  470. enable);
  471. trace_printk("%s: clk_cnt: %d for requested clk: %d, enable: %d\n",
  472. __func__, priv->clk_cnt[clk_id_req], clk_id_req,
  473. enable);
  474. mutex_unlock(&priv->rsc_clk_lock);
  475. return 0;
  476. err:
  477. mutex_unlock(&priv->rsc_clk_lock);
  478. return ret;
  479. }
  480. EXPORT_SYMBOL(lpass_cdc_clk_rsc_request_clock);
  481. static int lpass_cdc_clk_rsc_probe(struct platform_device *pdev)
  482. {
  483. int ret = 0, fs_gen_size, i, j;
  484. const char **clk_name_array;
  485. int clk_cnt;
  486. struct clk *clk;
  487. struct lpass_cdc_clk_rsc *priv = NULL;
  488. u32 muxsel = 0;
  489. priv = devm_kzalloc(&pdev->dev, sizeof(struct lpass_cdc_clk_rsc),
  490. GFP_KERNEL);
  491. if (!priv)
  492. return -ENOMEM;
  493. /* Get clk fs gen sequence from device tree */
  494. if (!of_find_property(pdev->dev.of_node, "qcom,fs-gen-sequence",
  495. &fs_gen_size)) {
  496. dev_err(&pdev->dev, "%s: unable to find qcom,fs-gen-sequence property\n",
  497. __func__);
  498. ret = -EINVAL;
  499. goto err;
  500. }
  501. priv->num_fs_reg = fs_gen_size/(3 * sizeof(u32));
  502. priv->fs_gen_seq = devm_kzalloc(&pdev->dev, fs_gen_size, GFP_KERNEL);
  503. if (!priv->fs_gen_seq) {
  504. ret = -ENOMEM;
  505. goto err;
  506. }
  507. dev_dbg(&pdev->dev, "%s: num_fs_reg %d\n", __func__, priv->num_fs_reg);
  508. /* Parse fs-gen-sequence */
  509. ret = of_property_read_u32_array(pdev->dev.of_node,
  510. "qcom,fs-gen-sequence",
  511. priv->fs_gen_seq,
  512. priv->num_fs_reg * 3);
  513. if (ret < 0) {
  514. dev_err(&pdev->dev, "%s: unable to parse fs-gen-sequence, ret = %d\n",
  515. __func__, ret);
  516. goto err;
  517. }
  518. /* Get clk details from device tree */
  519. clk_cnt = of_property_count_strings(pdev->dev.of_node, "clock-names");
  520. if (clk_cnt <= 0 || clk_cnt > MAX_CLK) {
  521. dev_err(&pdev->dev, "%s: Invalid number of clocks %d",
  522. __func__, clk_cnt);
  523. ret = -EINVAL;
  524. goto err;
  525. }
  526. clk_name_array = devm_kzalloc(&pdev->dev, clk_cnt * sizeof(char *),
  527. GFP_KERNEL);
  528. if (!clk_name_array) {
  529. ret = -ENOMEM;
  530. goto err;
  531. }
  532. ret = of_property_read_string_array(pdev->dev.of_node, "clock-names",
  533. clk_name_array, clk_cnt);
  534. for (i = 0; i < MAX_CLK; i++) {
  535. priv->clk[i] = NULL;
  536. for (j = 0; j < clk_cnt; j++) {
  537. if (!strcmp(clk_src_name[i], clk_name_array[j])) {
  538. clk = devm_clk_get(&pdev->dev, clk_src_name[i]);
  539. if (IS_ERR(clk)) {
  540. ret = PTR_ERR(clk);
  541. dev_err(&pdev->dev, "%s: clk get failed for %s with ret %d\n",
  542. __func__, clk_src_name[i], ret);
  543. goto err;
  544. }
  545. priv->clk[i] = clk;
  546. dev_dbg(&pdev->dev, "%s: clk get success for clk name %s\n",
  547. __func__, clk_src_name[i]);
  548. break;
  549. }
  550. }
  551. }
  552. ret = of_property_read_u32(pdev->dev.of_node,
  553. "qcom,rx_mclk_mode_muxsel", &muxsel);
  554. if (ret) {
  555. dev_dbg(&pdev->dev, "%s: could not find qcom,rx_mclk_mode_muxsel entry in dt\n",
  556. __func__);
  557. } else {
  558. priv->rx_clk_muxsel = devm_ioremap(&pdev->dev, muxsel, 0x4);
  559. if (!priv->rx_clk_muxsel) {
  560. dev_err(&pdev->dev, "%s: ioremap failed for rx muxsel\n",
  561. __func__);
  562. return -ENOMEM;
  563. }
  564. }
  565. ret = of_property_read_u32(pdev->dev.of_node,
  566. "qcom,wsa_mclk_mode_muxsel", &muxsel);
  567. if (ret) {
  568. dev_dbg(&pdev->dev, "%s: could not find qcom,wsa_mclk_mode_muxsel entry in dt\n",
  569. __func__);
  570. } else {
  571. priv->wsa_clk_muxsel = devm_ioremap(&pdev->dev, muxsel, 0x4);
  572. if (!priv->wsa_clk_muxsel) {
  573. dev_err(&pdev->dev, "%s: ioremap failed for wsa muxsel\n",
  574. __func__);
  575. return -ENOMEM;
  576. }
  577. }
  578. ret = of_property_read_u32(pdev->dev.of_node,
  579. "qcom,va_mclk_mode_muxsel", &muxsel);
  580. if (ret) {
  581. dev_dbg(&pdev->dev, "%s: could not find qcom,va_mclk_mode_muxsel entry in dt\n",
  582. __func__);
  583. } else {
  584. priv->va_clk_muxsel = devm_ioremap(&pdev->dev, muxsel, 0x4);
  585. if (!priv->va_clk_muxsel) {
  586. dev_err(&pdev->dev, "%s: ioremap failed for va muxsel\n",
  587. __func__);
  588. return -ENOMEM;
  589. }
  590. }
  591. ret = lpass_cdc_register_res_clk(&pdev->dev, lpass_cdc_clk_rsc_cb);
  592. if (ret < 0) {
  593. dev_err(&pdev->dev, "%s: Failed to register cb %d",
  594. __func__, ret);
  595. goto err;
  596. }
  597. priv->dev = &pdev->dev;
  598. priv->dev_up = true;
  599. priv->dev_up_gfmux = true;
  600. mutex_init(&priv->rsc_clk_lock);
  601. mutex_init(&priv->fs_gen_lock);
  602. dev_set_drvdata(&pdev->dev, priv);
  603. err:
  604. return ret;
  605. }
  606. static int lpass_cdc_clk_rsc_remove(struct platform_device *pdev)
  607. {
  608. struct lpass_cdc_clk_rsc *priv = dev_get_drvdata(&pdev->dev);
  609. lpass_cdc_unregister_res_clk(&pdev->dev);
  610. of_platform_depopulate(&pdev->dev);
  611. if (!priv)
  612. return -EINVAL;
  613. mutex_destroy(&priv->rsc_clk_lock);
  614. mutex_destroy(&priv->fs_gen_lock);
  615. return 0;
  616. }
  617. static const struct of_device_id lpass_cdc_clk_rsc_dt_match[] = {
  618. {.compatible = "qcom,lpass-cdc-clk-rsc-mngr"},
  619. {}
  620. };
  621. MODULE_DEVICE_TABLE(of, lpass_cdc_clk_rsc_dt_match);
  622. static struct platform_driver lpass_cdc_clk_rsc_mgr = {
  623. .driver = {
  624. .name = "lpass-cdc-clk-rsc-mngr",
  625. .owner = THIS_MODULE,
  626. .of_match_table = lpass_cdc_clk_rsc_dt_match,
  627. .suppress_bind_attrs = true,
  628. },
  629. .probe = lpass_cdc_clk_rsc_probe,
  630. .remove = lpass_cdc_clk_rsc_remove,
  631. };
  632. int lpass_cdc_clk_rsc_mgr_init(void)
  633. {
  634. return platform_driver_register(&lpass_cdc_clk_rsc_mgr);
  635. }
  636. void lpass_cdc_clk_rsc_mgr_exit(void)
  637. {
  638. platform_driver_unregister(&lpass_cdc_clk_rsc_mgr);
  639. }
  640. MODULE_DESCRIPTION("LPASS codec clock resource manager driver");
  641. MODULE_LICENSE("GPL v2");