bolero-cdc.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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. if (priv->version == BOLERO_VERSION_2_1) {
  966. bolero_reg_access[TX_MACRO] = bolero_tx_reg_access_v2;
  967. bolero_reg_access[VA_MACRO] = bolero_va_reg_access_v2;
  968. } else if (priv->version == BOLERO_VERSION_2_0) {
  969. bolero_reg_access[VA_MACRO] = bolero_va_reg_access_v3;
  970. }
  971. priv->dev = &pdev->dev;
  972. priv->dev_up = true;
  973. priv->initial_boot = true;
  974. priv->regmap = bolero_regmap_init(priv->dev,
  975. &bolero_regmap_config);
  976. if (IS_ERR_OR_NULL((void *)(priv->regmap))) {
  977. dev_err(&pdev->dev, "%s:regmap init failed\n", __func__);
  978. return -EINVAL;
  979. }
  980. priv->read_dev = __bolero_reg_read;
  981. priv->write_dev = __bolero_reg_write;
  982. priv->plat_data.handle = (void *) priv;
  983. priv->plat_data.update_wcd_event = bolero_cdc_update_wcd_event;
  984. priv->plat_data.register_notifier = bolero_cdc_register_notifier;
  985. priv->core_hw_vote_count = 0;
  986. priv->core_audio_vote_count = 0;
  987. dev_set_drvdata(&pdev->dev, priv);
  988. mutex_init(&priv->io_lock);
  989. mutex_init(&priv->clk_lock);
  990. mutex_init(&priv->vote_lock);
  991. INIT_WORK(&priv->bolero_add_child_devices_work,
  992. bolero_add_child_devices);
  993. schedule_work(&priv->bolero_add_child_devices_work);
  994. /* Register LPASS core hw vote */
  995. lpass_core_hw_vote = devm_clk_get(&pdev->dev, "lpass_core_hw_vote");
  996. if (IS_ERR(lpass_core_hw_vote)) {
  997. ret = PTR_ERR(lpass_core_hw_vote);
  998. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  999. __func__, "lpass_core_hw_vote", ret);
  1000. lpass_core_hw_vote = NULL;
  1001. ret = 0;
  1002. }
  1003. priv->lpass_core_hw_vote = lpass_core_hw_vote;
  1004. /* Register LPASS audio hw vote */
  1005. lpass_audio_hw_vote = devm_clk_get(&pdev->dev, "lpass_audio_hw_vote");
  1006. if (IS_ERR(lpass_audio_hw_vote)) {
  1007. ret = PTR_ERR(lpass_audio_hw_vote);
  1008. dev_dbg(&pdev->dev, "%s: clk get %s failed %d\n",
  1009. __func__, "lpass_audio_hw_vote", ret);
  1010. lpass_audio_hw_vote = NULL;
  1011. ret = 0;
  1012. }
  1013. priv->lpass_audio_hw_vote = lpass_audio_hw_vote;
  1014. return 0;
  1015. }
  1016. static int bolero_remove(struct platform_device *pdev)
  1017. {
  1018. struct bolero_priv *priv = dev_get_drvdata(&pdev->dev);
  1019. if (!priv)
  1020. return -EINVAL;
  1021. of_platform_depopulate(&pdev->dev);
  1022. mutex_destroy(&priv->io_lock);
  1023. mutex_destroy(&priv->clk_lock);
  1024. mutex_destroy(&priv->vote_lock);
  1025. return 0;
  1026. }
  1027. int bolero_runtime_resume(struct device *dev)
  1028. {
  1029. struct bolero_priv *priv = dev_get_drvdata(dev->parent);
  1030. int ret = 0;
  1031. mutex_lock(&priv->vote_lock);
  1032. if (priv->lpass_core_hw_vote == NULL) {
  1033. dev_dbg(dev, "%s: Invalid lpass core hw node\n", __func__);
  1034. goto audio_vote;
  1035. }
  1036. if (priv->core_hw_vote_count == 0) {
  1037. ret = clk_prepare_enable(priv->lpass_core_hw_vote);
  1038. if (ret < 0) {
  1039. dev_err(dev, "%s:lpass core hw enable failed\n",
  1040. __func__);
  1041. goto audio_vote;
  1042. }
  1043. }
  1044. priv->core_hw_vote_count++;
  1045. audio_vote:
  1046. if (priv->lpass_audio_hw_vote == NULL) {
  1047. dev_dbg(dev, "%s: Invalid lpass audio hw node\n", __func__);
  1048. goto done;
  1049. }
  1050. if (priv->core_audio_vote_count == 0) {
  1051. ret = clk_prepare_enable(priv->lpass_audio_hw_vote);
  1052. if (ret < 0) {
  1053. dev_err(dev, "%s:lpass audio hw enable failed\n",
  1054. __func__);
  1055. goto done;
  1056. }
  1057. }
  1058. priv->core_audio_vote_count++;
  1059. done:
  1060. mutex_unlock(&priv->vote_lock);
  1061. pm_runtime_set_autosuspend_delay(priv->dev, BOLERO_AUTO_SUSPEND_DELAY);
  1062. return 0;
  1063. }
  1064. EXPORT_SYMBOL(bolero_runtime_resume);
  1065. int bolero_runtime_suspend(struct device *dev)
  1066. {
  1067. struct bolero_priv *priv = dev_get_drvdata(dev->parent);
  1068. mutex_lock(&priv->vote_lock);
  1069. if (priv->lpass_core_hw_vote != NULL) {
  1070. if (--priv->core_hw_vote_count == 0)
  1071. clk_disable_unprepare(priv->lpass_core_hw_vote);
  1072. if (priv->core_hw_vote_count < 0)
  1073. priv->core_hw_vote_count = 0;
  1074. } else {
  1075. dev_dbg(dev, "%s: Invalid lpass core hw node\n",
  1076. __func__);
  1077. }
  1078. if (priv->lpass_audio_hw_vote != NULL) {
  1079. if (--priv->core_audio_vote_count == 0)
  1080. clk_disable_unprepare(priv->lpass_audio_hw_vote);
  1081. if (priv->core_audio_vote_count < 0)
  1082. priv->core_audio_vote_count = 0;
  1083. } else {
  1084. dev_dbg(dev, "%s: Invalid lpass audio hw node\n",
  1085. __func__);
  1086. }
  1087. mutex_unlock(&priv->vote_lock);
  1088. return 0;
  1089. }
  1090. EXPORT_SYMBOL(bolero_runtime_suspend);
  1091. bool bolero_check_core_votes(struct device *dev)
  1092. {
  1093. struct bolero_priv *priv = dev_get_drvdata(dev->parent);
  1094. bool ret = true;
  1095. mutex_lock(&priv->vote_lock);
  1096. if ((priv->lpass_core_hw_vote && !priv->core_hw_vote_count) ||
  1097. (priv->lpass_audio_hw_vote && !priv->core_audio_vote_count))
  1098. ret = false;
  1099. mutex_unlock(&priv->vote_lock);
  1100. return ret;
  1101. }
  1102. EXPORT_SYMBOL(bolero_check_core_votes);
  1103. static const struct of_device_id bolero_dt_match[] = {
  1104. {.compatible = "qcom,bolero-codec"},
  1105. {}
  1106. };
  1107. MODULE_DEVICE_TABLE(of, bolero_dt_match);
  1108. static struct platform_driver bolero_drv = {
  1109. .driver = {
  1110. .name = "bolero-codec",
  1111. .owner = THIS_MODULE,
  1112. .of_match_table = bolero_dt_match,
  1113. .suppress_bind_attrs = true,
  1114. },
  1115. .probe = bolero_probe,
  1116. .remove = bolero_remove,
  1117. };
  1118. static int bolero_drv_init(void)
  1119. {
  1120. return platform_driver_register(&bolero_drv);
  1121. }
  1122. static void bolero_drv_exit(void)
  1123. {
  1124. platform_driver_unregister(&bolero_drv);
  1125. }
  1126. static int __init bolero_init(void)
  1127. {
  1128. bolero_drv_init();
  1129. bolero_clk_rsc_mgr_init();
  1130. return 0;
  1131. }
  1132. module_init(bolero_init);
  1133. static void __exit bolero_exit(void)
  1134. {
  1135. bolero_clk_rsc_mgr_exit();
  1136. bolero_drv_exit();
  1137. }
  1138. module_exit(bolero_exit);
  1139. MODULE_DESCRIPTION("Bolero driver");
  1140. MODULE_LICENSE("GPL v2");