bolero-clk-rsc.c 18 KB

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