bolero-cdc.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
  3. */
  4. #include <linux/of_platform.h>
  5. #include <linux/module.h>
  6. #include <linux/io.h>
  7. #include <linux/init.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/printk.h>
  10. #include <linux/delay.h>
  11. #include <linux/kernel.h>
  12. #include <linux/clk.h>
  13. #include <soc/snd_event.h>
  14. #include <linux/pm_runtime.h>
  15. #include <soc/swr-common.h>
  16. #include "bolero-cdc.h"
  17. #include "internal.h"
  18. #include "bolero-clk-rsc.h"
  19. #define DRV_NAME "bolero_codec"
  20. #define BOLERO_VERSION_ENTRY_SIZE 32
  21. #define BOLERO_CDC_STRING_LEN 80
  22. static const struct snd_soc_component_driver bolero;
  23. /* pm runtime auto suspend timer in msecs */
  24. #define BOLERO_AUTO_SUSPEND_DELAY 100 /* delay in msec */
  25. /* MCLK_MUX table for all macros */
  26. static u16 bolero_mclk_mux_tbl[MAX_MACRO][MCLK_MUX_MAX] = {
  27. {TX_MACRO, VA_MACRO},
  28. {TX_MACRO, RX_MACRO},
  29. {TX_MACRO, WSA_MACRO},
  30. {TX_MACRO, VA_MACRO},
  31. };
  32. static bool bolero_is_valid_codec_dev(struct device *dev);
  33. int bolero_set_port_map(struct snd_soc_component *component,
  34. u32 size, void *data)
  35. {
  36. struct bolero_priv *priv = NULL;
  37. struct swr_mstr_port_map *map = NULL;
  38. u16 idx;
  39. if (!component || (size == 0) || !data)
  40. return -EINVAL;
  41. priv = snd_soc_component_get_drvdata(component);
  42. if (!priv)
  43. return -EINVAL;
  44. if (!bolero_is_valid_codec_dev(priv->dev)) {
  45. dev_err(priv->dev, "%s: invalid codec\n", __func__);
  46. return -EINVAL;
  47. }
  48. map = (struct swr_mstr_port_map *)data;
  49. for (idx = 0; idx < size; idx++) {
  50. if (priv->macro_params[map->id].set_port_map)
  51. priv->macro_params[map->id].set_port_map(component,
  52. map->uc,
  53. SWR_MSTR_PORT_LEN,
  54. map->swr_port_params);
  55. map += 1;
  56. }
  57. return 0;
  58. }
  59. EXPORT_SYMBOL(bolero_set_port_map);
  60. static void bolero_ahb_write_device(char __iomem *io_base,
  61. u16 reg, u8 value)
  62. {
  63. u32 temp = (u32)(value) & 0x000000FF;
  64. iowrite32(temp, io_base + reg);
  65. }
  66. static void bolero_ahb_read_device(char __iomem *io_base,
  67. u16 reg, u8 *value)
  68. {
  69. u32 temp;
  70. temp = ioread32(io_base + reg);
  71. *value = (u8)temp;
  72. }
  73. static int __bolero_reg_read(struct bolero_priv *priv,
  74. u16 macro_id, u16 reg, u8 *val)
  75. {
  76. int ret = 0;
  77. mutex_lock(&priv->clk_lock);
  78. if (!priv->dev_up) {
  79. dev_dbg_ratelimited(priv->dev,
  80. "%s: SSR in progress, exit\n", __func__);
  81. ret = -EINVAL;
  82. goto ssr_err;
  83. }
  84. if (priv->macro_params[VA_MACRO].dev)
  85. pm_runtime_get_sync(priv->macro_params[VA_MACRO].dev);
  86. /* Request Clk before register access */
  87. ret = bolero_clk_rsc_request_clock(priv->macro_params[macro_id].dev,
  88. priv->macro_params[macro_id].default_clk_id,
  89. priv->macro_params[macro_id].clk_id_req,
  90. true);
  91. if (ret < 0) {
  92. dev_err_ratelimited(priv->dev,
  93. "%s: Failed to enable clock, ret:%d\n", __func__, ret);
  94. goto err;
  95. }
  96. bolero_ahb_read_device(
  97. priv->macro_params[macro_id].io_base, reg, val);
  98. bolero_clk_rsc_request_clock(priv->macro_params[macro_id].dev,
  99. priv->macro_params[macro_id].default_clk_id,
  100. priv->macro_params[macro_id].clk_id_req,
  101. false);
  102. err:
  103. if (priv->macro_params[VA_MACRO].dev) {
  104. pm_runtime_mark_last_busy(priv->macro_params[VA_MACRO].dev);
  105. pm_runtime_put_autosuspend(priv->macro_params[VA_MACRO].dev);
  106. }
  107. ssr_err:
  108. mutex_unlock(&priv->clk_lock);
  109. return ret;
  110. }
  111. static int __bolero_reg_write(struct bolero_priv *priv,
  112. u16 macro_id, u16 reg, u8 val)
  113. {
  114. int ret = 0;
  115. mutex_lock(&priv->clk_lock);
  116. if (!priv->dev_up) {
  117. dev_dbg_ratelimited(priv->dev,
  118. "%s: SSR in progress, exit\n", __func__);
  119. ret = -EINVAL;
  120. goto ssr_err;
  121. }
  122. if (priv->macro_params[VA_MACRO].dev)
  123. pm_runtime_get_sync(priv->macro_params[VA_MACRO].dev);
  124. /* Request Clk before register access */
  125. ret = bolero_clk_rsc_request_clock(priv->macro_params[macro_id].dev,
  126. priv->macro_params[macro_id].default_clk_id,
  127. priv->macro_params[macro_id].clk_id_req,
  128. true);
  129. if (ret < 0) {
  130. dev_err_ratelimited(priv->dev,
  131. "%s: Failed to enable clock, ret:%d\n", __func__, ret);
  132. goto err;
  133. }
  134. bolero_ahb_write_device(
  135. priv->macro_params[macro_id].io_base, reg, val);
  136. bolero_clk_rsc_request_clock(priv->macro_params[macro_id].dev,
  137. priv->macro_params[macro_id].default_clk_id,
  138. priv->macro_params[macro_id].clk_id_req,
  139. false);
  140. err:
  141. if (priv->macro_params[VA_MACRO].dev) {
  142. pm_runtime_mark_last_busy(priv->macro_params[VA_MACRO].dev);
  143. pm_runtime_put_autosuspend(priv->macro_params[VA_MACRO].dev);
  144. }
  145. ssr_err:
  146. mutex_unlock(&priv->clk_lock);
  147. return ret;
  148. }
  149. static int bolero_cdc_update_wcd_event(void *handle, u16 event, u32 data)
  150. {
  151. struct bolero_priv *priv = (struct bolero_priv *)handle;
  152. if (!priv) {
  153. pr_err("%s:Invalid bolero priv handle\n", __func__);
  154. return -EINVAL;
  155. }
  156. switch (event) {
  157. case WCD_BOLERO_EVT_RX_MUTE:
  158. if (priv->macro_params[RX_MACRO].event_handler)
  159. priv->macro_params[RX_MACRO].event_handler(
  160. priv->component,
  161. BOLERO_MACRO_EVT_RX_MUTE, data);
  162. break;
  163. case WCD_BOLERO_EVT_IMPED_TRUE:
  164. if (priv->macro_params[RX_MACRO].event_handler)
  165. priv->macro_params[RX_MACRO].event_handler(
  166. priv->component,
  167. BOLERO_MACRO_EVT_IMPED_TRUE, data);
  168. break;
  169. case WCD_BOLERO_EVT_IMPED_FALSE:
  170. if (priv->macro_params[RX_MACRO].event_handler)
  171. priv->macro_params[RX_MACRO].event_handler(
  172. priv->component,
  173. BOLERO_MACRO_EVT_IMPED_FALSE, data);
  174. break;
  175. case WCD_BOLERO_EVT_RX_COMPANDER_SOFT_RST:
  176. if (priv->macro_params[RX_MACRO].event_handler)
  177. priv->macro_params[RX_MACRO].event_handler(
  178. priv->component,
  179. BOLERO_MACRO_EVT_RX_COMPANDER_SOFT_RST, data);
  180. break;
  181. case WCD_BOLERO_EVT_BCS_CLK_OFF:
  182. if (priv->macro_params[TX_MACRO].event_handler)
  183. priv->macro_params[TX_MACRO].event_handler(
  184. priv->component,
  185. BOLERO_MACRO_EVT_BCS_CLK_OFF, data);
  186. break;
  187. default:
  188. dev_err(priv->dev, "%s: Invalid event %d trigger from wcd\n",
  189. __func__, event);
  190. return -EINVAL;
  191. }
  192. return 0;
  193. }
  194. static int bolero_cdc_register_notifier(void *handle,
  195. struct notifier_block *nblock,
  196. bool enable)
  197. {
  198. struct bolero_priv *priv = (struct bolero_priv *)handle;
  199. if (!priv) {
  200. pr_err("%s: bolero priv is null\n", __func__);
  201. return -EINVAL;
  202. }
  203. if (enable)
  204. return blocking_notifier_chain_register(&priv->notifier,
  205. nblock);
  206. return blocking_notifier_chain_unregister(&priv->notifier,
  207. nblock);
  208. }
  209. static void bolero_cdc_notifier_call(struct bolero_priv *priv,
  210. u32 data)
  211. {
  212. dev_dbg(priv->dev, "%s: notifier call, data:%d\n", __func__, data);
  213. blocking_notifier_call_chain(&priv->notifier,
  214. data, (void *)priv->wcd_dev);
  215. }
  216. static bool bolero_is_valid_child_dev(struct device *dev)
  217. {
  218. if (of_device_is_compatible(dev->parent->of_node, "qcom,bolero-codec"))
  219. return true;
  220. return false;
  221. }
  222. static bool bolero_is_valid_codec_dev(struct device *dev)
  223. {
  224. if (of_device_is_compatible(dev->of_node, "qcom,bolero-codec"))
  225. return true;
  226. return false;
  227. }
  228. /**
  229. * bolero_clear_amic_tx_hold - clears AMIC register on analog codec
  230. *
  231. * @dev: bolero device ptr.
  232. *
  233. */
  234. void bolero_clear_amic_tx_hold(struct device *dev, u16 adc_n)
  235. {
  236. struct bolero_priv *priv;
  237. u16 event;
  238. u16 amic = 0;
  239. if (!dev) {
  240. pr_err("%s: dev is null\n", __func__);
  241. return;
  242. }
  243. if (!bolero_is_valid_codec_dev(dev)) {
  244. pr_err("%s: invalid codec\n", __func__);
  245. return;
  246. }
  247. priv = dev_get_drvdata(dev);
  248. if (!priv) {
  249. dev_err(dev, "%s: priv is null\n", __func__);
  250. return;
  251. }
  252. event = BOLERO_WCD_EVT_TX_CH_HOLD_CLEAR;
  253. if (adc_n == BOLERO_ADC0)
  254. amic = 0x1;
  255. else if (adc_n == BOLERO_ADC1)
  256. amic = 0x2;
  257. else if (adc_n == BOLERO_ADC2)
  258. amic = 0x2;
  259. else if (adc_n == BOLERO_ADC3)
  260. amic = 0x3;
  261. else
  262. return;
  263. bolero_cdc_notifier_call(priv, (amic << 0x10 | event));
  264. }
  265. EXPORT_SYMBOL(bolero_clear_amic_tx_hold);
  266. /**
  267. * bolero_get_device_ptr - Get child or macro device ptr
  268. *
  269. * @dev: bolero device ptr.
  270. * @macro_id: ID of macro calling this API.
  271. *
  272. * Returns dev ptr on success or NULL on error.
  273. */
  274. struct device *bolero_get_device_ptr(struct device *dev, u16 macro_id)
  275. {
  276. struct bolero_priv *priv;
  277. if (!dev) {
  278. pr_err("%s: dev is null\n", __func__);
  279. return NULL;
  280. }
  281. if (!bolero_is_valid_codec_dev(dev)) {
  282. pr_err("%s: invalid codec\n", __func__);
  283. return NULL;
  284. }
  285. priv = dev_get_drvdata(dev);
  286. if (!priv || (macro_id >= MAX_MACRO)) {
  287. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  288. return NULL;
  289. }
  290. return priv->macro_params[macro_id].dev;
  291. }
  292. EXPORT_SYMBOL(bolero_get_device_ptr);
  293. /**
  294. * bolero_get_rsc_clk_device_ptr - Get rsc clk device ptr
  295. *
  296. * @dev: bolero device ptr.
  297. *
  298. * Returns dev ptr on success or NULL on error.
  299. */
  300. struct device *bolero_get_rsc_clk_device_ptr(struct device *dev)
  301. {
  302. struct bolero_priv *priv;
  303. if (!dev) {
  304. pr_err("%s: dev is null\n", __func__);
  305. return NULL;
  306. }
  307. if (!bolero_is_valid_codec_dev(dev)) {
  308. pr_err("%s: invalid codec\n", __func__);
  309. return NULL;
  310. }
  311. priv = dev_get_drvdata(dev);
  312. if (!priv) {
  313. dev_err(dev, "%s: priv is null\n", __func__);
  314. return NULL;
  315. }
  316. return priv->clk_dev;
  317. }
  318. EXPORT_SYMBOL(bolero_get_rsc_clk_device_ptr);
  319. static int bolero_copy_dais_from_macro(struct bolero_priv *priv)
  320. {
  321. struct snd_soc_dai_driver *dai_ptr;
  322. u16 macro_idx;
  323. /* memcpy into bolero_dais all macro dais */
  324. if (!priv->bolero_dais)
  325. priv->bolero_dais = devm_kzalloc(priv->dev,
  326. priv->num_dais *
  327. sizeof(
  328. struct snd_soc_dai_driver),
  329. GFP_KERNEL);
  330. if (!priv->bolero_dais)
  331. return -ENOMEM;
  332. dai_ptr = priv->bolero_dais;
  333. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  334. if (priv->macro_params[macro_idx].dai_ptr) {
  335. memcpy(dai_ptr,
  336. priv->macro_params[macro_idx].dai_ptr,
  337. priv->macro_params[macro_idx].num_dais *
  338. sizeof(struct snd_soc_dai_driver));
  339. dai_ptr += priv->macro_params[macro_idx].num_dais;
  340. }
  341. }
  342. return 0;
  343. }
  344. /**
  345. * bolero_register_res_clk - Registers rsc clk driver to bolero
  346. *
  347. * @dev: rsc clk device ptr.
  348. * @rsc_clk_cb: event handler callback for notifications like SSR
  349. *
  350. * Returns 0 on success or -EINVAL on error.
  351. */
  352. int bolero_register_res_clk(struct device *dev, rsc_clk_cb_t rsc_clk_cb)
  353. {
  354. struct bolero_priv *priv;
  355. if (!dev || !rsc_clk_cb) {
  356. pr_err("%s: dev or rsc_clk_cb is null\n", __func__);
  357. return -EINVAL;
  358. }
  359. if (!bolero_is_valid_child_dev(dev)) {
  360. dev_err(dev, "%s: child device :%pK not added yet\n",
  361. __func__, dev);
  362. return -EINVAL;
  363. }
  364. priv = dev_get_drvdata(dev->parent);
  365. if (!priv) {
  366. dev_err(dev, "%s: priv is null\n", __func__);
  367. return -EINVAL;
  368. }
  369. priv->clk_dev = dev;
  370. priv->rsc_clk_cb = rsc_clk_cb;
  371. return 0;
  372. }
  373. EXPORT_SYMBOL(bolero_register_res_clk);
  374. /**
  375. * bolero_unregister_res_clk - Unregisters rsc clk driver from bolero
  376. *
  377. * @dev: resource clk device ptr.
  378. */
  379. void bolero_unregister_res_clk(struct device *dev)
  380. {
  381. struct bolero_priv *priv;
  382. if (!dev) {
  383. pr_err("%s: dev is NULL\n", __func__);
  384. return;
  385. }
  386. if (!bolero_is_valid_child_dev(dev)) {
  387. dev_err(dev, "%s: child device :%pK not added\n",
  388. __func__, dev);
  389. return;
  390. }
  391. priv = dev_get_drvdata(dev->parent);
  392. if (!priv) {
  393. dev_err(dev, "%s: priv is null\n", __func__);
  394. return;
  395. }
  396. priv->clk_dev = NULL;
  397. priv->rsc_clk_cb = NULL;
  398. }
  399. EXPORT_SYMBOL(bolero_unregister_res_clk);
  400. /**
  401. * bolero_register_macro - Registers macro to bolero
  402. *
  403. * @dev: macro device ptr.
  404. * @macro_id: ID of macro calling this API.
  405. * @ops: macro params to register.
  406. *
  407. * Returns 0 on success or -EINVAL on error.
  408. */
  409. int bolero_register_macro(struct device *dev, u16 macro_id,
  410. struct macro_ops *ops)
  411. {
  412. struct bolero_priv *priv;
  413. int ret = -EINVAL;
  414. if (!dev || !ops) {
  415. pr_err("%s: dev or ops is null\n", __func__);
  416. return -EINVAL;
  417. }
  418. if (!bolero_is_valid_child_dev(dev)) {
  419. dev_err(dev, "%s: child device for macro:%d not added yet\n",
  420. __func__, macro_id);
  421. return -EINVAL;
  422. }
  423. priv = dev_get_drvdata(dev->parent);
  424. if (!priv || (macro_id >= MAX_MACRO)) {
  425. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  426. return -EINVAL;
  427. }
  428. priv->macro_params[macro_id].clk_id_req = ops->clk_id_req;
  429. priv->macro_params[macro_id].default_clk_id = ops->default_clk_id;
  430. priv->macro_params[macro_id].init = ops->init;
  431. priv->macro_params[macro_id].exit = ops->exit;
  432. priv->macro_params[macro_id].io_base = ops->io_base;
  433. priv->macro_params[macro_id].num_dais = ops->num_dais;
  434. priv->macro_params[macro_id].dai_ptr = ops->dai_ptr;
  435. priv->macro_params[macro_id].event_handler = ops->event_handler;
  436. priv->macro_params[macro_id].set_port_map = ops->set_port_map;
  437. priv->macro_params[macro_id].dev = dev;
  438. priv->current_mclk_mux_macro[macro_id] =
  439. bolero_mclk_mux_tbl[macro_id][MCLK_MUX0];
  440. if (macro_id == TX_MACRO) {
  441. priv->macro_params[macro_id].reg_wake_irq = ops->reg_wake_irq;
  442. priv->macro_params[macro_id].clk_switch = ops->clk_switch;
  443. priv->macro_params[macro_id].reg_evt_listener =
  444. ops->reg_evt_listener;
  445. }
  446. if (priv->version == BOLERO_VERSION_2_1) {
  447. if (macro_id == VA_MACRO)
  448. priv->macro_params[macro_id].reg_wake_irq =
  449. ops->reg_wake_irq;
  450. }
  451. priv->num_dais += ops->num_dais;
  452. priv->num_macros_registered++;
  453. priv->macros_supported[macro_id] = true;
  454. dev_dbg(dev, "%s: register macro successful:%d\n", macro_id);
  455. if (priv->num_macros_registered == priv->num_macros) {
  456. ret = bolero_copy_dais_from_macro(priv);
  457. if (ret < 0) {
  458. dev_err(dev, "%s: copy_dais failed\n", __func__);
  459. return ret;
  460. }
  461. if (priv->macros_supported[TX_MACRO] == false) {
  462. bolero_mclk_mux_tbl[WSA_MACRO][MCLK_MUX0] = WSA_MACRO;
  463. priv->current_mclk_mux_macro[WSA_MACRO] = WSA_MACRO;
  464. bolero_mclk_mux_tbl[VA_MACRO][MCLK_MUX0] = VA_MACRO;
  465. priv->current_mclk_mux_macro[VA_MACRO] = VA_MACRO;
  466. }
  467. ret = snd_soc_register_component(dev->parent, &bolero,
  468. priv->bolero_dais, priv->num_dais);
  469. if (ret < 0) {
  470. dev_err(dev, "%s: register codec failed\n", __func__);
  471. return ret;
  472. }
  473. }
  474. return 0;
  475. }
  476. EXPORT_SYMBOL(bolero_register_macro);
  477. /**
  478. * bolero_unregister_macro - De-Register macro from bolero
  479. *
  480. * @dev: macro device ptr.
  481. * @macro_id: ID of macro calling this API.
  482. *
  483. */
  484. void bolero_unregister_macro(struct device *dev, u16 macro_id)
  485. {
  486. struct bolero_priv *priv;
  487. if (!dev) {
  488. pr_err("%s: dev is null\n", __func__);
  489. return;
  490. }
  491. if (!bolero_is_valid_child_dev(dev)) {
  492. dev_err(dev, "%s: macro:%d not in valid registered macro-list\n",
  493. __func__, macro_id);
  494. return;
  495. }
  496. priv = dev_get_drvdata(dev->parent);
  497. if (!priv || (macro_id >= MAX_MACRO)) {
  498. dev_err(dev, "%s: priv is null or invalid macro\n", __func__);
  499. return;
  500. }
  501. priv->macro_params[macro_id].init = NULL;
  502. priv->macro_params[macro_id].num_dais = 0;
  503. priv->macro_params[macro_id].dai_ptr = NULL;
  504. priv->macro_params[macro_id].event_handler = NULL;
  505. priv->macro_params[macro_id].dev = NULL;
  506. if (macro_id == TX_MACRO) {
  507. priv->macro_params[macro_id].reg_wake_irq = NULL;
  508. priv->macro_params[macro_id].clk_switch = NULL;
  509. priv->macro_params[macro_id].reg_evt_listener = NULL;
  510. }
  511. priv->num_dais -= priv->macro_params[macro_id].num_dais;
  512. priv->num_macros_registered--;
  513. /* UNREGISTER CODEC HERE */
  514. if (priv->num_macros - 1 == priv->num_macros_registered)
  515. snd_soc_unregister_component(dev->parent);
  516. }
  517. EXPORT_SYMBOL(bolero_unregister_macro);
  518. void bolero_wsa_pa_on(struct device *dev)
  519. {
  520. struct bolero_priv *priv;
  521. if (!dev) {
  522. pr_err("%s: dev is null\n", __func__);
  523. return;
  524. }
  525. if (!bolero_is_valid_child_dev(dev)) {
  526. dev_err(dev, "%s: not a valid child dev\n",
  527. __func__);
  528. return;
  529. }
  530. priv = dev_get_drvdata(dev->parent);
  531. if (!priv) {
  532. dev_err(dev, "%s: priv is null\n", __func__);
  533. return;
  534. }
  535. bolero_cdc_notifier_call(priv, BOLERO_WCD_EVT_PA_ON_POST_FSCLK);
  536. }
  537. EXPORT_SYMBOL(bolero_wsa_pa_on);
  538. int bolero_get_version(struct device *dev)
  539. {
  540. struct bolero_priv *priv;
  541. if (!dev) {
  542. pr_err("%s: dev is null\n", __func__);
  543. return -EINVAL;
  544. }
  545. if (!bolero_is_valid_child_dev(dev)) {
  546. dev_err(dev, "%s: child device for macro not added yet\n",
  547. __func__);
  548. return -EINVAL;
  549. }
  550. priv = dev_get_drvdata(dev->parent);
  551. if (!priv) {
  552. dev_err(dev, "%s: priv is null\n", __func__);
  553. return -EINVAL;
  554. }
  555. return priv->version;
  556. }
  557. EXPORT_SYMBOL(bolero_get_version);
  558. static ssize_t bolero_version_read(struct snd_info_entry *entry,
  559. void *file_private_data,
  560. struct file *file,
  561. char __user *buf, size_t count,
  562. loff_t pos)
  563. {
  564. struct bolero_priv *priv;
  565. char buffer[BOLERO_VERSION_ENTRY_SIZE];
  566. int len = 0;
  567. priv = (struct bolero_priv *) entry->private_data;
  568. if (!priv) {
  569. pr_err("%s: bolero priv is null\n", __func__);
  570. return -EINVAL;
  571. }
  572. switch (priv->version) {
  573. case BOLERO_VERSION_1_0:
  574. len = snprintf(buffer, sizeof(buffer), "BOLERO_1_0\n");
  575. break;
  576. case BOLERO_VERSION_1_1:
  577. len = snprintf(buffer, sizeof(buffer), "BOLERO_1_1\n");
  578. break;
  579. case BOLERO_VERSION_1_2:
  580. len = snprintf(buffer, sizeof(buffer), "BOLERO_1_2\n");
  581. break;
  582. case BOLERO_VERSION_2_1:
  583. len = snprintf(buffer, sizeof(buffer), "BOLERO_2_1\n");
  584. break;
  585. default:
  586. len = snprintf(buffer, sizeof(buffer), "VER_UNDEFINED\n");
  587. }
  588. return simple_read_from_buffer(buf, count, &pos, buffer, len);
  589. }
  590. static int bolero_ssr_enable(struct device *dev, void *data)
  591. {
  592. struct bolero_priv *priv = data;
  593. int macro_idx;
  594. if (priv->initial_boot) {
  595. priv->initial_boot = false;
  596. return 0;
  597. }
  598. if (priv->rsc_clk_cb)
  599. priv->rsc_clk_cb(priv->clk_dev, BOLERO_MACRO_EVT_SSR_UP);
  600. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  601. if (priv->macro_params[macro_idx].event_handler)
  602. priv->macro_params[macro_idx].event_handler(
  603. priv->component,
  604. BOLERO_MACRO_EVT_CLK_RESET, 0x0);
  605. }
  606. regcache_cache_only(priv->regmap, false);
  607. mutex_lock(&priv->clk_lock);
  608. priv->dev_up = true;
  609. mutex_unlock(&priv->clk_lock);
  610. regcache_mark_dirty(priv->regmap);
  611. bolero_clk_rsc_enable_all_clocks(priv->clk_dev, true);
  612. regcache_sync(priv->regmap);
  613. /* Add a 100usec sleep to ensure last register write is done */
  614. usleep_range(100,110);
  615. bolero_clk_rsc_enable_all_clocks(priv->clk_dev, false);
  616. /* call ssr event for supported macros */
  617. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  618. if (!priv->macro_params[macro_idx].event_handler)
  619. continue;
  620. priv->macro_params[macro_idx].event_handler(
  621. priv->component,
  622. BOLERO_MACRO_EVT_SSR_UP, 0x0);
  623. }
  624. bolero_cdc_notifier_call(priv, BOLERO_WCD_EVT_SSR_UP);
  625. return 0;
  626. }
  627. static void bolero_ssr_disable(struct device *dev, void *data)
  628. {
  629. struct bolero_priv *priv = data;
  630. int macro_idx;
  631. bolero_cdc_notifier_call(priv, BOLERO_WCD_EVT_PA_OFF_PRE_SSR);
  632. regcache_cache_only(priv->regmap, true);
  633. mutex_lock(&priv->clk_lock);
  634. priv->dev_up = false;
  635. mutex_unlock(&priv->clk_lock);
  636. if (priv->rsc_clk_cb)
  637. priv->rsc_clk_cb(priv->clk_dev, BOLERO_MACRO_EVT_SSR_DOWN);
  638. /* call ssr event for supported macros */
  639. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  640. if (!priv->macro_params[macro_idx].event_handler)
  641. continue;
  642. priv->macro_params[macro_idx].event_handler(
  643. priv->component,
  644. BOLERO_MACRO_EVT_SSR_DOWN, 0x0);
  645. }
  646. bolero_cdc_notifier_call(priv, BOLERO_WCD_EVT_SSR_DOWN);
  647. }
  648. static struct snd_info_entry_ops bolero_info_ops = {
  649. .read = bolero_version_read,
  650. };
  651. static const struct snd_event_ops bolero_ssr_ops = {
  652. .enable = bolero_ssr_enable,
  653. .disable = bolero_ssr_disable,
  654. };
  655. /*
  656. * bolero_info_create_codec_entry - creates bolero module
  657. * @codec_root: The parent directory
  658. * @component: Codec component instance
  659. *
  660. * Creates bolero module and version entry under the given
  661. * parent directory.
  662. *
  663. * Return: 0 on success or negative error code on failure.
  664. */
  665. int bolero_info_create_codec_entry(struct snd_info_entry *codec_root,
  666. struct snd_soc_component *component)
  667. {
  668. struct snd_info_entry *version_entry;
  669. struct bolero_priv *priv;
  670. struct snd_soc_card *card;
  671. if (!codec_root || !component)
  672. return -EINVAL;
  673. priv = snd_soc_component_get_drvdata(component);
  674. if (priv->entry) {
  675. dev_dbg(priv->dev,
  676. "%s:bolero module already created\n", __func__);
  677. return 0;
  678. }
  679. card = component->card;
  680. priv->entry = snd_info_create_subdir(codec_root->module,
  681. "bolero", codec_root);
  682. if (!priv->entry) {
  683. dev_dbg(component->dev, "%s: failed to create bolero entry\n",
  684. __func__);
  685. return -ENOMEM;
  686. }
  687. version_entry = snd_info_create_card_entry(card->snd_card,
  688. "version",
  689. priv->entry);
  690. if (!version_entry) {
  691. dev_err(component->dev, "%s: failed to create bolero version entry\n",
  692. __func__);
  693. return -ENOMEM;
  694. }
  695. version_entry->private_data = priv;
  696. version_entry->size = BOLERO_VERSION_ENTRY_SIZE;
  697. version_entry->content = SNDRV_INFO_CONTENT_DATA;
  698. version_entry->c.ops = &bolero_info_ops;
  699. if (snd_info_register(version_entry) < 0) {
  700. snd_info_free_entry(version_entry);
  701. return -ENOMEM;
  702. }
  703. priv->version_entry = version_entry;
  704. return 0;
  705. }
  706. EXPORT_SYMBOL(bolero_info_create_codec_entry);
  707. /**
  708. * bolero_register_wake_irq - Register wake irq of Tx macro
  709. *
  710. * @component: codec component ptr.
  711. * @ipc_wakeup: bool to identify ipc_wakeup to be used or HW interrupt line.
  712. *
  713. * Return: 0 on success or negative error code on failure.
  714. */
  715. int bolero_register_wake_irq(struct snd_soc_component *component,
  716. u32 ipc_wakeup)
  717. {
  718. struct bolero_priv *priv = NULL;
  719. if (!component)
  720. return -EINVAL;
  721. priv = snd_soc_component_get_drvdata(component);
  722. if (!priv)
  723. return -EINVAL;
  724. if (!bolero_is_valid_codec_dev(priv->dev)) {
  725. dev_err(component->dev, "%s: invalid codec\n", __func__);
  726. return -EINVAL;
  727. }
  728. if (priv->version == BOLERO_VERSION_2_1) {
  729. if (priv->macro_params[VA_MACRO].reg_wake_irq)
  730. priv->macro_params[VA_MACRO].reg_wake_irq(
  731. component, ipc_wakeup);
  732. } else {
  733. if (priv->macro_params[TX_MACRO].reg_wake_irq)
  734. priv->macro_params[TX_MACRO].reg_wake_irq(
  735. component, ipc_wakeup);
  736. }
  737. return 0;
  738. }
  739. EXPORT_SYMBOL(bolero_register_wake_irq);
  740. /**
  741. * bolero_tx_clk_switch - Switch tx macro clock
  742. *
  743. * @component: pointer to codec component instance.
  744. *
  745. * Returns 0 on success or -EINVAL on error.
  746. */
  747. int bolero_tx_clk_switch(struct snd_soc_component *component)
  748. {
  749. struct bolero_priv *priv = NULL;
  750. int ret = 0;
  751. if (!component)
  752. return -EINVAL;
  753. priv = snd_soc_component_get_drvdata(component);
  754. if (!priv)
  755. return -EINVAL;
  756. if (!bolero_is_valid_codec_dev(priv->dev)) {
  757. dev_err(component->dev, "%s: invalid codec\n", __func__);
  758. return -EINVAL;
  759. }
  760. if (priv->macro_params[TX_MACRO].clk_switch)
  761. ret = priv->macro_params[TX_MACRO].clk_switch(component);
  762. return ret;
  763. }
  764. EXPORT_SYMBOL(bolero_tx_clk_switch);
  765. /**
  766. * bolero_register_event_listener - Register/Deregister to event listener
  767. *
  768. * @component: pointer to codec component instance.
  769. * @enable: when set to 1 registers to event listener otherwise, derigisters
  770. * from the event listener
  771. *
  772. * Returns 0 on success or -EINVAL on error.
  773. */
  774. int bolero_register_event_listener(struct snd_soc_component *component,
  775. bool enable)
  776. {
  777. struct bolero_priv *priv = NULL;
  778. int ret = 0;
  779. if (!component)
  780. return -EINVAL;
  781. priv = snd_soc_component_get_drvdata(component);
  782. if (!priv)
  783. return -EINVAL;
  784. if (!bolero_is_valid_codec_dev(priv->dev)) {
  785. dev_err(component->dev, "%s: invalid codec\n", __func__);
  786. return -EINVAL;
  787. }
  788. if (priv->macro_params[TX_MACRO].reg_evt_listener)
  789. ret = priv->macro_params[TX_MACRO].reg_evt_listener(component,
  790. enable);
  791. return ret;
  792. }
  793. EXPORT_SYMBOL(bolero_register_event_listener);
  794. static int bolero_soc_codec_probe(struct snd_soc_component *component)
  795. {
  796. struct bolero_priv *priv = dev_get_drvdata(component->dev);
  797. int macro_idx, ret = 0;
  798. snd_soc_component_init_regmap(component, priv->regmap);
  799. if (!priv->version) {
  800. /*
  801. * In order for the ADIE RTC to differentiate between targets
  802. * version info is used.
  803. * Assign 1.0 for target with only one macro
  804. * Assign 1.1 for target with two macros
  805. * Assign 1.2 for target with more than two macros
  806. */
  807. if (priv->num_macros_registered == 1)
  808. priv->version = BOLERO_VERSION_1_0;
  809. else if (priv->num_macros_registered == 2)
  810. priv->version = BOLERO_VERSION_1_1;
  811. else if (priv->num_macros_registered > 2)
  812. priv->version = BOLERO_VERSION_1_2;
  813. }
  814. /* Assign bolero version 2.1 for bolero 2.1 */
  815. if ((snd_soc_component_read32(component,
  816. BOLERO_CDC_VA_TOP_CSR_CORE_ID_0) == 0x2) &&
  817. (snd_soc_component_read32(component,
  818. BOLERO_CDC_VA_TOP_CSR_CORE_ID_1) == 0xE))
  819. priv->version = BOLERO_VERSION_2_1;
  820. /* call init for supported macros */
  821. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++) {
  822. if (priv->macro_params[macro_idx].init) {
  823. ret = priv->macro_params[macro_idx].init(component);
  824. if (ret < 0) {
  825. dev_err(component->dev,
  826. "%s: init for macro %d failed\n",
  827. __func__, macro_idx);
  828. goto err;
  829. }
  830. }
  831. }
  832. priv->component = component;
  833. ret = snd_event_client_register(priv->dev, &bolero_ssr_ops, priv);
  834. if (!ret) {
  835. snd_event_notify(priv->dev, SND_EVENT_UP);
  836. } else {
  837. dev_err(component->dev,
  838. "%s: Registration with SND event FWK failed ret = %d\n",
  839. __func__, ret);
  840. goto err;
  841. }
  842. dev_dbg(component->dev, "%s: bolero soc codec probe success\n",
  843. __func__);
  844. err:
  845. return ret;
  846. }
  847. static void bolero_soc_codec_remove(struct snd_soc_component *component)
  848. {
  849. struct bolero_priv *priv = dev_get_drvdata(component->dev);
  850. int macro_idx;
  851. snd_event_client_deregister(priv->dev);
  852. /* call exit for supported macros */
  853. for (macro_idx = START_MACRO; macro_idx < MAX_MACRO; macro_idx++)
  854. if (priv->macro_params[macro_idx].exit)
  855. priv->macro_params[macro_idx].exit(component);
  856. return;
  857. }
  858. static const struct snd_soc_component_driver bolero = {
  859. .name = DRV_NAME,
  860. .probe = bolero_soc_codec_probe,
  861. .remove = bolero_soc_codec_remove,
  862. };
  863. static void bolero_add_child_devices(struct work_struct *work)
  864. {
  865. struct bolero_priv *priv;
  866. bool split_codec = false;
  867. struct platform_device *pdev;
  868. struct device_node *node;
  869. int ret = 0, count = 0;
  870. struct wcd_ctrl_platform_data *platdata = NULL;
  871. char plat_dev_name[BOLERO_CDC_STRING_LEN] = "";
  872. priv = container_of(work, struct bolero_priv,
  873. bolero_add_child_devices_work);
  874. if (!priv) {
  875. pr_err("%s: Memory for bolero priv does not exist\n",
  876. __func__);
  877. return;
  878. }
  879. if (!priv->dev || !priv->dev->of_node) {
  880. dev_err(priv->dev, "%s: DT node for bolero does not exist\n",
  881. __func__);
  882. return;
  883. }
  884. platdata = &priv->plat_data;
  885. priv->child_count = 0;
  886. for_each_available_child_of_node(priv->dev->of_node, node) {
  887. split_codec = false;
  888. if (of_find_property(node, "qcom,split-codec", NULL)) {
  889. split_codec = true;
  890. dev_dbg(priv->dev, "%s: split codec slave exists\n",
  891. __func__);
  892. }
  893. strlcpy(plat_dev_name, node->name,
  894. (BOLERO_CDC_STRING_LEN - 1));
  895. pdev = platform_device_alloc(plat_dev_name, -1);
  896. if (!pdev) {
  897. dev_err(priv->dev, "%s: pdev memory alloc failed\n",
  898. __func__);
  899. ret = -ENOMEM;
  900. goto err;
  901. }
  902. pdev->dev.parent = priv->dev;
  903. pdev->dev.of_node = node;
  904. if (split_codec) {
  905. priv->dev->platform_data = platdata;
  906. priv->wcd_dev = &pdev->dev;
  907. }
  908. ret = platform_device_add(pdev);
  909. if (ret) {
  910. dev_err(&pdev->dev,
  911. "%s: Cannot add platform device\n",
  912. __func__);
  913. platform_device_put(pdev);
  914. goto fail_pdev_add;
  915. }
  916. if (priv->child_count < BOLERO_CDC_CHILD_DEVICES_MAX)
  917. priv->pdev_child_devices[priv->child_count++] = pdev;
  918. else
  919. goto err;
  920. }
  921. return;
  922. fail_pdev_add:
  923. for (count = 0; count < priv->child_count; count++)
  924. platform_device_put(priv->pdev_child_devices[count]);
  925. err:
  926. return;
  927. }
  928. static int bolero_probe(struct platform_device *pdev)
  929. {
  930. struct bolero_priv *priv;
  931. u32 num_macros = 0;
  932. int ret;
  933. struct clk *lpass_core_hw_vote = NULL;
  934. struct clk *lpass_audio_hw_vote = NULL;
  935. priv = devm_kzalloc(&pdev->dev, sizeof(struct bolero_priv),
  936. GFP_KERNEL);
  937. if (!priv)
  938. return -ENOMEM;
  939. ret = of_property_read_u32(pdev->dev.of_node, "qcom,num-macros",
  940. &num_macros);
  941. if (ret) {
  942. dev_err(&pdev->dev,
  943. "%s:num-macros property not found\n",
  944. __func__);
  945. return ret;
  946. }
  947. priv->num_macros = num_macros;
  948. if (priv->num_macros > MAX_MACRO) {
  949. dev_err(&pdev->dev,
  950. "%s:num_macros(%d) > MAX_MACRO(%d) than supported\n",
  951. __func__, priv->num_macros, MAX_MACRO);
  952. return -EINVAL;
  953. }
  954. priv->va_without_decimation = of_property_read_bool(pdev->dev.of_node,
  955. "qcom,va-without-decimation");
  956. if (priv->va_without_decimation)
  957. bolero_reg_access[VA_MACRO] = bolero_va_top_reg_access;
  958. ret = of_property_read_u32(pdev->dev.of_node,
  959. "qcom,bolero-version", &priv->version);
  960. if (ret) {
  961. dev_dbg(&pdev->dev, "%s:bolero version not specified\n",
  962. __func__);
  963. ret = 0;
  964. }
  965. priv->dev = &pdev->dev;
  966. priv->dev_up = true;
  967. priv->initial_boot = true;
  968. priv->regmap = bolero_regmap_init(priv->dev,
  969. &bolero_regmap_config);
  970. if (IS_ERR_OR_NULL((void *)(priv->regmap))) {
  971. dev_err(&pdev->dev, "%s:regmap init failed\n", __func__);
  972. return -EINVAL;
  973. }
  974. priv->read_dev = __bolero_reg_read;
  975. priv->write_dev = __bolero_reg_write;
  976. priv->plat_data.handle = (void *) priv;
  977. priv->plat_data.update_wcd_event = bolero_cdc_update_wcd_event;
  978. priv->plat_data.register_notifier = bolero_cdc_register_notifier;
  979. priv->core_hw_vote_count = 0;
  980. priv->core_audio_vote_count = 0;
  981. dev_set_drvdata(&pdev->dev, priv);
  982. mutex_init(&priv->io_lock);
  983. mutex_init(&priv->clk_lock);
  984. mutex_init(&priv->vote_lock);
  985. INIT_WORK(&priv->bolero_add_child_devices_work,
  986. bolero_add_child_devices);
  987. schedule_work(&priv->bolero_add_child_devices_work);
  988. /* Register LPASS core hw vote */
  989. lpass_core_hw_vote = devm_clk_get(&pdev->dev, "lpass_core_hw_vote");
  990. if (IS_ERR(lpass_core_hw_vote)) {
  991. ret = PTR_ERR(lpass_core_hw_vote);
  992. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  993. __func__, "lpass_core_hw_vote", ret);
  994. lpass_core_hw_vote = NULL;
  995. ret = 0;
  996. }
  997. priv->lpass_core_hw_vote = lpass_core_hw_vote;
  998. /* Register LPASS audio hw vote */
  999. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1000. if (IS_ERR(lpass_audio_hw_vote)) {
  1001. ret = PTR_ERR(lpass_audio_hw_vote);
  1002. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1003. __func__, "lpass_audio_hw_vote", ret);
  1004. lpass_audio_hw_vote = NULL;
  1005. ret = 0;
  1006. }
  1007. priv->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1008. return 0;
  1009. }
  1010. static int bolero_remove(struct platform_device *pdev)
  1011. {
  1012. struct bolero_priv *priv = dev_get_drvdata(&pdev->dev);
  1013. if (!priv)
  1014. return -EINVAL;
  1015. of_platform_depopulate(&pdev->dev);
  1016. mutex_destroy(&priv->io_lock);
  1017. mutex_destroy(&priv->clk_lock);
  1018. mutex_destroy(&priv->vote_lock);
  1019. return 0;
  1020. }
  1021. int bolero_runtime_resume(struct device *dev)
  1022. {
  1023. struct bolero_priv *priv = dev_get_drvdata(dev->parent);
  1024. int ret = 0;
  1025. mutex_lock(&priv->vote_lock);
  1026. if (priv->lpass_core_hw_vote == NULL) {
  1027. dev_dbg(dev, "%s: Invalid lpass core hw node\n", __func__);
  1028. goto audio_vote;
  1029. }
  1030. if (priv->core_hw_vote_count == 0) {
  1031. ret = clk_prepare_enable(priv->lpass_core_hw_vote);
  1032. if (ret < 0) {
  1033. dev_err(dev, "%s:lpass core hw enable failed\n",
  1034. __func__);
  1035. goto audio_vote;
  1036. }
  1037. }
  1038. priv->core_hw_vote_count++;
  1039. audio_vote:
  1040. if (priv->lpass_audio_hw_vote == NULL) {
  1041. dev_dbg(dev, "%s: Invalid lpass audio hw node\n", __func__);
  1042. goto done;
  1043. }
  1044. if (priv->core_audio_vote_count == 0) {
  1045. ret = clk_prepare_enable(priv->lpass_audio_hw_vote);
  1046. if (ret < 0) {
  1047. dev_err(dev, "%s:lpass audio hw enable failed\n",
  1048. __func__);
  1049. goto done;
  1050. }
  1051. }
  1052. priv->core_audio_vote_count++;
  1053. done:
  1054. mutex_unlock(&priv->vote_lock);
  1055. pm_runtime_set_autosuspend_delay(priv->dev, BOLERO_AUTO_SUSPEND_DELAY);
  1056. return 0;
  1057. }
  1058. EXPORT_SYMBOL(bolero_runtime_resume);
  1059. int bolero_runtime_suspend(struct device *dev)
  1060. {
  1061. struct bolero_priv *priv = dev_get_drvdata(dev->parent);
  1062. mutex_lock(&priv->vote_lock);
  1063. if (priv->lpass_core_hw_vote != NULL) {
  1064. if (--priv->core_hw_vote_count == 0)
  1065. clk_disable_unprepare(priv->lpass_core_hw_vote);
  1066. if (priv->core_hw_vote_count < 0)
  1067. priv->core_hw_vote_count = 0;
  1068. } else {
  1069. dev_dbg(dev, "%s: Invalid lpass core hw node\n",
  1070. __func__);
  1071. }
  1072. if (priv->lpass_audio_hw_vote != NULL) {
  1073. if (--priv->core_audio_vote_count == 0)
  1074. clk_disable_unprepare(priv->lpass_audio_hw_vote);
  1075. if (priv->core_audio_vote_count < 0)
  1076. priv->core_audio_vote_count = 0;
  1077. } else {
  1078. dev_dbg(dev, "%s: Invalid lpass audio hw node\n",
  1079. __func__);
  1080. }
  1081. mutex_unlock(&priv->vote_lock);
  1082. return 0;
  1083. }
  1084. EXPORT_SYMBOL(bolero_runtime_suspend);
  1085. bool bolero_check_core_votes(struct device *dev)
  1086. {
  1087. struct bolero_priv *priv = dev_get_drvdata(dev->parent);
  1088. bool ret = true;
  1089. mutex_lock(&priv->vote_lock);
  1090. if ((priv->lpass_core_hw_vote && !priv->core_hw_vote_count) ||
  1091. (priv->lpass_audio_hw_vote && !priv->core_audio_vote_count))
  1092. ret = false;
  1093. mutex_unlock(&priv->vote_lock);
  1094. return ret;
  1095. }
  1096. EXPORT_SYMBOL(bolero_check_core_votes);
  1097. static const struct of_device_id bolero_dt_match[] = {
  1098. {.compatible = "qcom,bolero-codec"},
  1099. {}
  1100. };
  1101. MODULE_DEVICE_TABLE(of, bolero_dt_match);
  1102. static struct platform_driver bolero_drv = {
  1103. .driver = {
  1104. .name = "bolero-codec",
  1105. .owner = THIS_MODULE,
  1106. .of_match_table = bolero_dt_match,
  1107. .suppress_bind_attrs = true,
  1108. },
  1109. .probe = bolero_probe,
  1110. .remove = bolero_remove,
  1111. };
  1112. static int bolero_drv_init(void)
  1113. {
  1114. return platform_driver_register(&bolero_drv);
  1115. }
  1116. static void bolero_drv_exit(void)
  1117. {
  1118. platform_driver_unregister(&bolero_drv);
  1119. }
  1120. static int __init bolero_init(void)
  1121. {
  1122. bolero_drv_init();
  1123. bolero_clk_rsc_mgr_init();
  1124. return 0;
  1125. }
  1126. module_init(bolero_init);
  1127. static void __exit bolero_exit(void)
  1128. {
  1129. bolero_clk_rsc_mgr_exit();
  1130. bolero_drv_exit();
  1131. }
  1132. module_exit(bolero_exit);
  1133. MODULE_DESCRIPTION("Bolero driver");
  1134. MODULE_LICENSE("GPL v2");