bolero-cdc.c 32 KB

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