audio-ext-clk-up.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/init.h>
  7. #include <linux/io.h>
  8. #include <linux/err.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/clk.h>
  12. #include <linux/clk-provider.h>
  13. #include <linux/pinctrl/consumer.h>
  14. #include <linux/platform_device.h>
  15. #include <bindings/qcom,audio-ext-clk.h>
  16. #include <linux/ratelimit.h>
  17. #ifdef CONFIG_AUDIO_PRM
  18. #include <dsp/audio_prm.h>
  19. #else
  20. #include "audio-ext-clk-up.h"
  21. #endif
  22. enum {
  23. AUDIO_EXT_CLK_PMI,
  24. AUDIO_EXT_CLK_LNBB2,
  25. AUDIO_EXT_CLK_LPASS,
  26. AUDIO_EXT_CLK_LPASS2,
  27. AUDIO_EXT_CLK_LPASS3,
  28. AUDIO_EXT_CLK_LPASS4,
  29. AUDIO_EXT_CLK_LPASS5,
  30. AUDIO_EXT_CLK_LPASS6,
  31. AUDIO_EXT_CLK_LPASS7,
  32. AUDIO_EXT_CLK_LPASS_CORE_HW_VOTE,
  33. AUDIO_EXT_CLK_LPASS8,
  34. AUDIO_EXT_CLK_LPASS_AUDIO_HW_VOTE,
  35. AUDIO_EXT_CLK_LPASS9,
  36. AUDIO_EXT_CLK_LPASS10,
  37. AUDIO_EXT_CLK_LPASS11,
  38. AUDIO_EXT_CLK_LPASS12,
  39. AUDIO_EXT_CLK_LPASS13,
  40. AUDIO_EXT_CLK_LPASS_MAX,
  41. AUDIO_EXT_CLK_EXTERNAL_PLL = AUDIO_EXT_CLK_LPASS_MAX,
  42. AUDIO_EXT_CLK_MAX,
  43. };
  44. struct pinctrl_info {
  45. struct pinctrl *pinctrl;
  46. struct pinctrl_state *sleep;
  47. struct pinctrl_state *active;
  48. char __iomem *base;
  49. };
  50. struct audio_ext_clk {
  51. struct pinctrl_info pnctrl_info;
  52. struct clk_fixed_factor fact;
  53. };
  54. struct audio_ext_clk_priv {
  55. struct device *dev;
  56. int clk_src;
  57. uint32_t enable;
  58. #ifdef CONFIG_AUDIO_PRM
  59. struct clk_cfg prm_clk_cfg;
  60. #endif
  61. struct audio_ext_clk audio_clk;
  62. const char *clk_name;
  63. uint32_t lpass_core_hwvote_client_handle;
  64. uint32_t lpass_audio_hwvote_client_handle;
  65. };
  66. static inline struct audio_ext_clk_priv *to_audio_clk(struct clk_hw *hw)
  67. {
  68. return container_of(hw, struct audio_ext_clk_priv, audio_clk.fact.hw);
  69. }
  70. static int audio_ext_clk_prepare(struct clk_hw *hw)
  71. {
  72. struct audio_ext_clk_priv *clk_priv = to_audio_clk(hw);
  73. struct pinctrl_info *pnctrl_info = &clk_priv->audio_clk.pnctrl_info;
  74. int ret;
  75. static DEFINE_RATELIMIT_STATE(rtl, 1 * HZ, 1);
  76. if ((clk_priv->clk_src >= AUDIO_EXT_CLK_LPASS) &&
  77. (clk_priv->clk_src < AUDIO_EXT_CLK_LPASS_MAX) && !clk_priv->enable) {
  78. #ifdef CONFIG_AUDIO_PRM
  79. pr_debug("%s: clk_id %x ", __func__, clk_priv->prm_clk_cfg.clk_id);
  80. trace_printk("%s: clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  81. ret = audio_prm_set_lpass_clk_cfg(&clk_priv->prm_clk_cfg,1);
  82. #else
  83. pr_debug("%s: audio prm not enabled", __func__);
  84. ret = -EPERM;
  85. #endif
  86. if (ret < 0) {
  87. if (__ratelimit(&rtl))
  88. pr_err_ratelimited("%s prm set lpass clk failed\n",
  89. __func__);
  90. return ret;
  91. }
  92. clk_priv->enable = 1;
  93. }
  94. if (pnctrl_info->pinctrl) {
  95. ret = pinctrl_select_state(pnctrl_info->pinctrl,
  96. pnctrl_info->active);
  97. if (ret) {
  98. pr_err("%s: active state select failed with %d\n",
  99. __func__, ret);
  100. return -EIO;
  101. }
  102. }
  103. if (pnctrl_info->base)
  104. iowrite32(1, pnctrl_info->base);
  105. return 0;
  106. }
  107. static void audio_ext_clk_unprepare(struct clk_hw *hw)
  108. {
  109. struct audio_ext_clk_priv *clk_priv = to_audio_clk(hw);
  110. struct pinctrl_info *pnctrl_info = &clk_priv->audio_clk.pnctrl_info;
  111. int ret;
  112. static DEFINE_RATELIMIT_STATE(rtl, 1 * HZ, 1);
  113. if (pnctrl_info->pinctrl) {
  114. ret = pinctrl_select_state(pnctrl_info->pinctrl,
  115. pnctrl_info->sleep);
  116. if (ret) {
  117. pr_err("%s: active state select failed with %d\n",
  118. __func__, ret);
  119. return;
  120. }
  121. }
  122. if ((clk_priv->clk_src >= AUDIO_EXT_CLK_LPASS) &&
  123. (clk_priv->clk_src < AUDIO_EXT_CLK_LPASS_MAX)) {
  124. clk_priv->enable = 0;
  125. #ifdef CONFIG_AUDIO_PRM
  126. pr_debug("%s: clk_id %x", __func__,
  127. clk_priv->prm_clk_cfg.clk_id);
  128. ret = audio_prm_set_lpass_clk_cfg(&clk_priv->prm_clk_cfg, 0);
  129. trace_printk("%s: clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  130. #else
  131. pr_debug("%s: audio prm not enabled", __func__);
  132. ret = -EPERM;
  133. #endif
  134. if (ret < 0) {
  135. if (__ratelimit(&rtl))
  136. pr_err_ratelimited("%s: unset lpass clk cfg failed, ret = %d\n",
  137. __func__, ret);
  138. }
  139. }
  140. if (pnctrl_info->base)
  141. iowrite32(0, pnctrl_info->base);
  142. }
  143. static u8 audio_ext_clk_get_parent(struct clk_hw *hw)
  144. {
  145. struct audio_ext_clk_priv *clk_priv = to_audio_clk(hw);
  146. int num_parents = clk_hw_get_num_parents(hw);
  147. const char * const *parent_names = hw->init->parent_names;
  148. u8 i = 0, ret = hw->init->num_parents + 1;
  149. if ((clk_priv->clk_src == AUDIO_EXT_CLK_PMI) && clk_priv->clk_name) {
  150. for (i = 0; i < num_parents; i++) {
  151. if (!strcmp(parent_names[i], clk_priv->clk_name))
  152. ret = i;
  153. }
  154. pr_debug("%s: parent index = %u\n", __func__, ret);
  155. return ret;
  156. } else
  157. return 0;
  158. }
  159. static int lpass_hw_vote_prepare(struct clk_hw *hw)
  160. {
  161. struct audio_ext_clk_priv *clk_priv = to_audio_clk(hw);
  162. int ret;
  163. static DEFINE_RATELIMIT_STATE(rtl, 1 * HZ, 1);
  164. if (clk_priv->clk_src == AUDIO_EXT_CLK_LPASS_CORE_HW_VOTE) {
  165. #ifdef CONFIG_AUDIO_PRM
  166. pr_debug("%s: core vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  167. ret = audio_prm_set_lpass_hw_core_req(&clk_priv->prm_clk_cfg,
  168. HW_CORE_ID_LPASS, 1);
  169. trace_printk("%s: core vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  170. #else
  171. pr_debug("%s: audio prm not enabled", __func__);
  172. ret = -EPERM;
  173. #endif
  174. if (ret < 0) {
  175. if (__ratelimit(&rtl))
  176. pr_err("%s lpass core hw vote failed %d\n",
  177. __func__, ret);
  178. return ret;
  179. }
  180. }
  181. if (clk_priv->clk_src == AUDIO_EXT_CLK_LPASS_AUDIO_HW_VOTE) {
  182. #ifdef CONFIG_AUDIO_PRM
  183. pr_debug("%s: audio vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  184. ret = audio_prm_set_lpass_hw_core_req(&clk_priv->prm_clk_cfg,
  185. HW_CORE_ID_DCODEC, 1);
  186. trace_printk("%s: audio vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  187. #else
  188. pr_debug("%s: audio prm not enabled", __func__);
  189. ret = -EPERM;
  190. #endif
  191. if (ret < 0) {
  192. if (__ratelimit(&rtl))
  193. pr_err("%s lpass audio hw vote failed %d\n",
  194. __func__, ret);
  195. return ret;
  196. }
  197. }
  198. return 0;
  199. }
  200. static void lpass_hw_vote_unprepare(struct clk_hw *hw)
  201. {
  202. struct audio_ext_clk_priv *clk_priv = to_audio_clk(hw);
  203. int ret = 0;
  204. if (clk_priv->clk_src == AUDIO_EXT_CLK_LPASS_CORE_HW_VOTE) {
  205. #ifdef CONFIG_AUDIO_PRM
  206. pr_debug("%s: core vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  207. ret = audio_prm_set_lpass_hw_core_req(&clk_priv->prm_clk_cfg,
  208. HW_CORE_ID_LPASS, 0);
  209. trace_printk("%s: core vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  210. #else
  211. pr_debug("%s: audio prm not enabled", __func__);
  212. ret = -EPERM;
  213. #endif
  214. if (ret < 0) {
  215. pr_err("%s lpass core hw vote failed %d\n",
  216. __func__, ret);
  217. }
  218. }
  219. if (clk_priv->clk_src == AUDIO_EXT_CLK_LPASS_AUDIO_HW_VOTE) {
  220. #ifdef CONFIG_AUDIO_PRM
  221. pr_debug("%s: audio vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  222. ret = audio_prm_set_lpass_hw_core_req(&clk_priv->prm_clk_cfg,
  223. HW_CORE_ID_DCODEC, 0);
  224. trace_printk("%s: audio vote clk_id %x \n", __func__, clk_priv->prm_clk_cfg.clk_id);
  225. #else
  226. pr_debug("%s: audio prm not enabled", __func__);
  227. ret = -EPERM;
  228. #endif
  229. if (ret < 0) {
  230. pr_err("%s lpass audio hw unvote failed %d\n",
  231. __func__, ret);
  232. }
  233. }
  234. }
  235. static const struct clk_ops audio_ext_clk_ops = {
  236. .prepare = audio_ext_clk_prepare,
  237. .unprepare = audio_ext_clk_unprepare,
  238. .get_parent = audio_ext_clk_get_parent,
  239. };
  240. static const struct clk_ops lpass_hw_vote_ops = {
  241. .prepare = lpass_hw_vote_prepare,
  242. .unprepare = lpass_hw_vote_unprepare,
  243. };
  244. static const char * const audio_ext_pmi_div_clk[] = {
  245. "qpnp_clkdiv_1",
  246. "pms405_div_clk1",
  247. "pm6150_div_clk1",
  248. "pm6125_div_clk1",
  249. };
  250. static int audio_ext_clk_dummy_prepare(struct clk_hw *hw)
  251. {
  252. return 0;
  253. }
  254. static void audio_ext_clk_dummy_unprepare(struct clk_hw *hw)
  255. {
  256. }
  257. static const struct clk_ops audio_ext_clk_dummy_ops = {
  258. .prepare = audio_ext_clk_dummy_prepare,
  259. .unprepare = audio_ext_clk_dummy_unprepare,
  260. };
  261. static struct audio_ext_clk audio_clk_array[] = {
  262. {
  263. .pnctrl_info = {NULL},
  264. .fact = {
  265. .mult = 1,
  266. .div = 1,
  267. .hw.init = &(struct clk_init_data){
  268. .name = "audio_ext_pmi_clk",
  269. .parent_names = audio_ext_pmi_div_clk,
  270. .num_parents =
  271. ARRAY_SIZE(audio_ext_pmi_div_clk),
  272. .ops = &audio_ext_clk_ops,
  273. },
  274. },
  275. },
  276. {
  277. .pnctrl_info = {NULL},
  278. .fact = {
  279. .mult = 1,
  280. .div = 1,
  281. .hw.init = &(struct clk_init_data){
  282. .name = "audio_ext_pmi_lnbb_clk",
  283. .parent_names = (const char *[])
  284. { "ln_bb_clk2" },
  285. .num_parents = 1,
  286. .ops = &audio_ext_clk_dummy_ops,
  287. },
  288. },
  289. },
  290. {
  291. .pnctrl_info = {NULL},
  292. .fact = {
  293. .mult = 1,
  294. .div = 1,
  295. .hw.init = &(struct clk_init_data){
  296. .name = "audio_lpass_mclk",
  297. .ops = &audio_ext_clk_ops,
  298. },
  299. },
  300. },
  301. {
  302. .pnctrl_info = {NULL},
  303. .fact = {
  304. .mult = 1,
  305. .div = 1,
  306. .hw.init = &(struct clk_init_data){
  307. .name = "audio_lpass_mclk2",
  308. .ops = &audio_ext_clk_ops,
  309. },
  310. },
  311. },
  312. {
  313. .pnctrl_info = {NULL},
  314. .fact = {
  315. .mult = 1,
  316. .div = 1,
  317. .hw.init = &(struct clk_init_data){
  318. .name = "audio_lpass_mclk3",
  319. .ops = &audio_ext_clk_ops,
  320. },
  321. },
  322. },
  323. {
  324. .pnctrl_info = {NULL},
  325. .fact = {
  326. .mult = 1,
  327. .div = 1,
  328. .hw.init = &(struct clk_init_data){
  329. .name = "audio_lpass_mclk4",
  330. .ops = &audio_ext_clk_ops,
  331. },
  332. },
  333. },
  334. {
  335. .pnctrl_info = {NULL},
  336. .fact = {
  337. .mult = 1,
  338. .div = 1,
  339. .hw.init = &(struct clk_init_data){
  340. .name = "audio_lpass_mclk5",
  341. .ops = &audio_ext_clk_ops,
  342. },
  343. },
  344. },
  345. {
  346. .pnctrl_info = {NULL},
  347. .fact = {
  348. .mult = 1,
  349. .div = 1,
  350. .hw.init = &(struct clk_init_data){
  351. .name = "audio_lpass_mclk6",
  352. .ops = &audio_ext_clk_ops,
  353. },
  354. },
  355. },
  356. {
  357. .pnctrl_info = {NULL},
  358. .fact = {
  359. .mult = 1,
  360. .div = 1,
  361. .hw.init = &(struct clk_init_data){
  362. .name = "audio_lpass_mclk7",
  363. .ops = &audio_ext_clk_ops,
  364. },
  365. },
  366. },
  367. {
  368. .pnctrl_info = {NULL},
  369. .fact = {
  370. .hw.init = &(struct clk_init_data){
  371. .name = "lpass_hw_vote_clk",
  372. .ops = &lpass_hw_vote_ops,
  373. },
  374. },
  375. },
  376. {
  377. .pnctrl_info = {NULL},
  378. .fact = {
  379. .mult = 1,
  380. .div = 1,
  381. .hw.init = &(struct clk_init_data){
  382. .name = "audio_lpass_mclk8",
  383. .ops = &audio_ext_clk_ops,
  384. },
  385. },
  386. },
  387. {
  388. .pnctrl_info = {NULL},
  389. .fact = {
  390. .hw.init = &(struct clk_init_data){
  391. .name = "lpass_audio_hw_vote_clk",
  392. .ops = &lpass_hw_vote_ops,
  393. },
  394. },
  395. },
  396. {
  397. .pnctrl_info = {NULL},
  398. .fact = {
  399. .mult = 1,
  400. .div = 1,
  401. .hw.init = &(struct clk_init_data){
  402. .name = "audio_lpass_mclk9",
  403. .ops = &audio_ext_clk_ops,
  404. },
  405. },
  406. },
  407. {
  408. .pnctrl_info = {NULL},
  409. .fact = {
  410. .mult = 1,
  411. .div = 1,
  412. .hw.init = &(struct clk_init_data){
  413. .name = "audio_lpass_mclk10",
  414. .ops = &audio_ext_clk_ops,
  415. },
  416. },
  417. },
  418. {
  419. .pnctrl_info = {NULL},
  420. .fact = {
  421. .mult = 1,
  422. .div = 1,
  423. .hw.init = &(struct clk_init_data){
  424. .name = "audio_lpass_mclk11",
  425. .ops = &audio_ext_clk_ops,
  426. },
  427. },
  428. },
  429. {
  430. .pnctrl_info = {NULL},
  431. .fact = {
  432. .mult = 1,
  433. .div = 1,
  434. .hw.init = &(struct clk_init_data){
  435. .name = "audio_lpass_mclk12",
  436. .ops = &audio_ext_clk_ops,
  437. },
  438. },
  439. },
  440. {
  441. .pnctrl_info = {NULL},
  442. .fact = {
  443. .mult = 1,
  444. .div = 1,
  445. .hw.init = &(struct clk_init_data){
  446. .name = "audio_lpass_mclk13",
  447. .ops = &audio_ext_clk_ops,
  448. },
  449. },
  450. },
  451. {
  452. .pnctrl_info = {NULL},
  453. .fact = {
  454. .mult = 1,
  455. .div = 1,
  456. .hw.init = &(struct clk_init_data){
  457. .name = "audio_external_pll_clk",
  458. .ops = &audio_ext_clk_ops,
  459. },
  460. },
  461. },
  462. };
  463. static int audio_get_pinctrl(struct platform_device *pdev)
  464. {
  465. struct device *dev = &pdev->dev;
  466. struct audio_ext_clk_priv *clk_priv = platform_get_drvdata(pdev);
  467. struct pinctrl_info *pnctrl_info;
  468. struct pinctrl *pinctrl;
  469. int ret;
  470. u32 reg;
  471. pnctrl_info = &clk_priv->audio_clk.pnctrl_info;
  472. if (pnctrl_info->pinctrl) {
  473. dev_err(dev, "%s: already requested before\n",
  474. __func__);
  475. return -EINVAL;
  476. }
  477. pinctrl = devm_pinctrl_get(dev);
  478. if (IS_ERR_OR_NULL(pinctrl)) {
  479. dev_err(dev, "%s: Unable to get pinctrl handle\n",
  480. __func__);
  481. return -EINVAL;
  482. }
  483. pnctrl_info->pinctrl = pinctrl;
  484. /* get all state handles from Device Tree */
  485. pnctrl_info->sleep = pinctrl_lookup_state(pinctrl, "sleep");
  486. if (IS_ERR(pnctrl_info->sleep)) {
  487. dev_err(dev, "%s: could not get sleep pinstate\n",
  488. __func__);
  489. goto err;
  490. }
  491. pnctrl_info->active = pinctrl_lookup_state(pinctrl, "active");
  492. if (IS_ERR(pnctrl_info->active)) {
  493. dev_err(dev, "%s: could not get active pinstate\n",
  494. __func__);
  495. goto err;
  496. }
  497. /* Reset the TLMM pins to a default state */
  498. ret = pinctrl_select_state(pnctrl_info->pinctrl,
  499. pnctrl_info->sleep);
  500. if (ret) {
  501. dev_err(dev, "%s: Disable TLMM pins failed with %d\n",
  502. __func__, ret);
  503. goto err;
  504. }
  505. ret = of_property_read_u32(dev->of_node, "qcom,mclk-clk-reg", &reg);
  506. if (ret < 0) {
  507. dev_dbg(dev, "%s: miss mclk reg\n", __func__);
  508. } else {
  509. pnctrl_info->base = ioremap(reg, sizeof(u32));
  510. if (pnctrl_info->base == NULL) {
  511. dev_err(dev, "%s ioremap failed\n", __func__);
  512. goto err;
  513. }
  514. }
  515. return 0;
  516. err:
  517. devm_pinctrl_put(pnctrl_info->pinctrl);
  518. return -EINVAL;
  519. }
  520. static int audio_put_pinctrl(struct platform_device *pdev)
  521. {
  522. struct audio_ext_clk_priv *clk_priv = platform_get_drvdata(pdev);
  523. struct pinctrl_info *pnctrl_info = NULL;
  524. pnctrl_info = &clk_priv->audio_clk.pnctrl_info;
  525. if (pnctrl_info && pnctrl_info->pinctrl) {
  526. devm_pinctrl_put(pnctrl_info->pinctrl);
  527. pnctrl_info->pinctrl = NULL;
  528. }
  529. return 0;
  530. }
  531. static int audio_get_clk_data(struct platform_device *pdev)
  532. {
  533. int ret;
  534. struct clk *audio_clk;
  535. struct clk_hw *clkhw;
  536. struct clk_onecell_data *clk_data;
  537. struct audio_ext_clk_priv *clk_priv = platform_get_drvdata(pdev);
  538. clk_data = devm_kzalloc(&pdev->dev, sizeof(*clk_data), GFP_KERNEL);
  539. if (!clk_data)
  540. return -ENOMEM;
  541. clk_data->clk_num = 1;
  542. clk_data->clks = devm_kzalloc(&pdev->dev,
  543. sizeof(struct clk *),
  544. GFP_KERNEL);
  545. if (!clk_data->clks)
  546. return -ENOMEM;
  547. clkhw = &clk_priv->audio_clk.fact.hw;
  548. audio_clk = devm_clk_register(&pdev->dev, clkhw);
  549. if (IS_ERR(audio_clk)) {
  550. dev_err(&pdev->dev,
  551. "%s: clock register failed for clk_src = %d\\n",
  552. __func__, clk_priv->clk_src);
  553. ret = PTR_ERR(audio_clk);
  554. return ret;
  555. }
  556. clk_data->clks[0] = audio_clk;
  557. ret = of_clk_add_provider(pdev->dev.of_node,
  558. of_clk_src_onecell_get, clk_data);
  559. if (ret)
  560. dev_err(&pdev->dev, "%s: clock add failed for clk_src = %d\n",
  561. __func__, clk_priv->clk_src);
  562. return ret;
  563. }
  564. static int audio_ref_clk_probe(struct platform_device *pdev)
  565. {
  566. int ret;
  567. struct audio_ext_clk_priv *clk_priv;
  568. u32 clk_freq = 0, clk_id = 0, clk_src = 0, use_pinctrl = 0;
  569. clk_priv = devm_kzalloc(&pdev->dev, sizeof(*clk_priv), GFP_KERNEL);
  570. if (!clk_priv)
  571. return -ENOMEM;
  572. ret = of_property_read_u32(pdev->dev.of_node,
  573. "qcom,codec-ext-clk-src",
  574. &clk_src);
  575. if (ret) {
  576. dev_err(&pdev->dev, "%s: could not get clk source, ret = %d\n",
  577. __func__, ret);
  578. return ret;
  579. }
  580. if (clk_src >= AUDIO_EXT_CLK_MAX) {
  581. dev_err(&pdev->dev, "%s: Invalid clk source = %d\n",
  582. __func__, clk_src);
  583. return -EINVAL;
  584. }
  585. clk_priv->clk_name = NULL;
  586. clk_priv->clk_src = clk_src;
  587. memcpy(&clk_priv->audio_clk, &audio_clk_array[clk_src],
  588. sizeof(struct audio_ext_clk));
  589. #ifdef CONFIG_AUDIO_PRM
  590. /* Init prm clk cfg default values */
  591. clk_priv->prm_clk_cfg.clk_id = CLOCK_ID_QUI_MI2S_OSR;
  592. clk_priv->prm_clk_cfg.clk_freq_in_hz = OSR_CLOCK_9_P600_MHZ;
  593. clk_priv->prm_clk_cfg.clk_attri = CLOCK_ATTRIBUTE_COUPLE_NO;
  594. clk_priv->prm_clk_cfg.clk_root = 0;
  595. #endif
  596. ret = of_property_read_u32(pdev->dev.of_node,
  597. "qcom,codec-lpass-ext-clk-freq",
  598. &clk_freq);
  599. if (!ret) {
  600. #ifdef CONFIG_AUDIO_PRM
  601. clk_priv->prm_clk_cfg.clk_freq_in_hz = clk_freq;
  602. #endif
  603. }
  604. ret = of_property_read_u32(pdev->dev.of_node,
  605. "qcom,codec-lpass-clk-id",
  606. &clk_id);
  607. if (!ret) {
  608. #ifdef CONFIG_AUDIO_PRM
  609. clk_priv->prm_clk_cfg.clk_id = clk_id;
  610. dev_dbg(&pdev->dev, "%s: PRM ext-clk freq: %d, lpass clk_id: %d, clk_src: %d\n",
  611. __func__, clk_priv->prm_clk_cfg.clk_freq_in_hz,
  612. clk_priv->prm_clk_cfg.clk_id, clk_priv->clk_src);
  613. #endif
  614. }
  615. dev_dbg(&pdev->dev, "%s: PRM2 ext-clk freq: %d, lpass clk_id: %d, clk_src: %d\n",
  616. __func__, clk_priv->prm_clk_cfg.clk_freq_in_hz,
  617. clk_priv->prm_clk_cfg.clk_id, clk_priv->clk_src);
  618. platform_set_drvdata(pdev, clk_priv);
  619. ret = of_property_read_string(pdev->dev.of_node, "pmic-clock-names",
  620. &clk_priv->clk_name);
  621. if (ret)
  622. dev_dbg(&pdev->dev, "%s: could not find pmic clock names\n",
  623. __func__);
  624. /*
  625. * property qcom,use-pinctrl to be defined in DTSI to val 1
  626. * for clock nodes using pinctrl
  627. */
  628. of_property_read_u32(pdev->dev.of_node, "qcom,use-pinctrl",
  629. &use_pinctrl);
  630. dev_dbg(&pdev->dev, "%s: use-pinctrl : %d\n",
  631. __func__, use_pinctrl);
  632. if (use_pinctrl) {
  633. ret = audio_get_pinctrl(pdev);
  634. if (ret) {
  635. dev_err(&pdev->dev, "%s: Parsing PMI pinctrl failed\n",
  636. __func__);
  637. return ret;
  638. }
  639. }
  640. ret = audio_get_clk_data(pdev);
  641. if (ret) {
  642. dev_err(&pdev->dev, "%s: clk_init is failed\n",
  643. __func__);
  644. audio_put_pinctrl(pdev);
  645. return ret;
  646. }
  647. return 0;
  648. }
  649. static int audio_ref_clk_remove(struct platform_device *pdev)
  650. {
  651. audio_put_pinctrl(pdev);
  652. return 0;
  653. }
  654. static const struct of_device_id audio_ref_clk_match[] = {
  655. {.compatible = "qcom,audio-ref-clk"},
  656. {}
  657. };
  658. MODULE_DEVICE_TABLE(of, audio_ref_clk_match);
  659. static struct platform_driver audio_ref_clk_driver = {
  660. .driver = {
  661. .name = "audio-ref-clk",
  662. .owner = THIS_MODULE,
  663. .of_match_table = audio_ref_clk_match,
  664. .suppress_bind_attrs = true,
  665. },
  666. .probe = audio_ref_clk_probe,
  667. .remove = audio_ref_clk_remove,
  668. };
  669. int audio_ref_clk_platform_init(void)
  670. {
  671. return platform_driver_register(&audio_ref_clk_driver);
  672. }
  673. void audio_ref_clk_platform_exit(void)
  674. {
  675. platform_driver_unregister(&audio_ref_clk_driver);
  676. }
  677. MODULE_DESCRIPTION("Audio Ref Up Clock module platform driver");
  678. MODULE_LICENSE("GPL v2");