bolero-clk-rsc.c 16 KB

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