wcd9xxx-slimslave.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #include <linux/slab.h>
  13. #include <linux/mutex.h>
  14. #include <linux/mfd/wcd9xxx/wcd9xxx_registers.h>
  15. #include "wcd9xxx-slimslave.h"
  16. struct wcd9xxx_slim_sch {
  17. u16 rx_port_ch_reg_base;
  18. u16 port_tx_cfg_reg_base;
  19. u16 port_rx_cfg_reg_base;
  20. };
  21. static struct wcd9xxx_slim_sch sh_ch;
  22. static int wcd9xxx_alloc_slim_sh_ch(struct wcd9xxx *wcd9xxx,
  23. u8 wcd9xxx_pgd_la, u32 cnt,
  24. struct wcd9xxx_ch *channels, u32 path);
  25. static int wcd9xxx_dealloc_slim_sh_ch(struct slim_device *slim,
  26. u32 cnt, struct wcd9xxx_ch *channels);
  27. static int wcd9xxx_configure_ports(struct wcd9xxx *wcd9xxx)
  28. {
  29. if (wcd9xxx->codec_type->slim_slave_type ==
  30. WCD9XXX_SLIM_SLAVE_ADDR_TYPE_0) {
  31. sh_ch.rx_port_ch_reg_base = 0x180;
  32. sh_ch.port_rx_cfg_reg_base = 0x040;
  33. sh_ch.port_tx_cfg_reg_base = 0x040;
  34. } else {
  35. sh_ch.rx_port_ch_reg_base =
  36. 0x180 - (TAIKO_SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS * 4);
  37. sh_ch.port_rx_cfg_reg_base =
  38. 0x040 - TAIKO_SB_PGD_OFFSET_OF_RX_SLAVE_DEV_PORTS;
  39. sh_ch.port_tx_cfg_reg_base = 0x050;
  40. }
  41. return 0;
  42. }
  43. /**
  44. * wcd9xxx_init_slimslave
  45. *
  46. * @wcd9xxx: pointer to wcd9xxx struct
  47. * @wcd9xxx_pgd_la: pgd_la value
  48. * @tx_num: tx number
  49. * @rx_num: rx number
  50. * @tx_slot: pointer to tx slot
  51. * @rx_slot: pointer to rx slot
  52. *
  53. * Returns 0 on success, appropriate error code otherwise
  54. */
  55. int wcd9xxx_init_slimslave(struct wcd9xxx *wcd9xxx, u8 wcd9xxx_pgd_la,
  56. unsigned int tx_num, unsigned int *tx_slot,
  57. unsigned int rx_num, unsigned int *rx_slot)
  58. {
  59. int ret = 0;
  60. int i;
  61. ret = wcd9xxx_configure_ports(wcd9xxx);
  62. if (ret) {
  63. pr_err("%s: Failed to configure register address offset\n",
  64. __func__);
  65. goto err;
  66. }
  67. if (!rx_num || rx_num > wcd9xxx->num_rx_port) {
  68. pr_err("%s: invalid rx num %d\n", __func__, rx_num);
  69. return -EINVAL;
  70. }
  71. if (wcd9xxx->rx_chs) {
  72. wcd9xxx->num_rx_port = rx_num;
  73. for (i = 0; i < rx_num; i++) {
  74. wcd9xxx->rx_chs[i].ch_num = rx_slot[i];
  75. INIT_LIST_HEAD(&wcd9xxx->rx_chs[i].list);
  76. }
  77. ret = wcd9xxx_alloc_slim_sh_ch(wcd9xxx, wcd9xxx_pgd_la,
  78. wcd9xxx->num_rx_port,
  79. wcd9xxx->rx_chs,
  80. SLIM_SINK);
  81. if (ret) {
  82. pr_err("%s: Failed to alloc %d rx slimbus channels\n",
  83. __func__, wcd9xxx->num_rx_port);
  84. kfree(wcd9xxx->rx_chs);
  85. wcd9xxx->rx_chs = NULL;
  86. wcd9xxx->num_rx_port = 0;
  87. }
  88. } else {
  89. pr_err("Not able to allocate memory for %d slimbus rx ports\n",
  90. wcd9xxx->num_rx_port);
  91. }
  92. if (!tx_num || tx_num > wcd9xxx->num_tx_port) {
  93. pr_err("%s: invalid tx num %d\n", __func__, tx_num);
  94. return -EINVAL;
  95. }
  96. if (wcd9xxx->tx_chs) {
  97. wcd9xxx->num_tx_port = tx_num;
  98. for (i = 0; i < tx_num; i++) {
  99. wcd9xxx->tx_chs[i].ch_num = tx_slot[i];
  100. INIT_LIST_HEAD(&wcd9xxx->tx_chs[i].list);
  101. }
  102. ret = wcd9xxx_alloc_slim_sh_ch(wcd9xxx, wcd9xxx_pgd_la,
  103. wcd9xxx->num_tx_port,
  104. wcd9xxx->tx_chs,
  105. SLIM_SRC);
  106. if (ret) {
  107. pr_err("%s: Failed to alloc %d tx slimbus channels\n",
  108. __func__, wcd9xxx->num_tx_port);
  109. kfree(wcd9xxx->tx_chs);
  110. wcd9xxx->tx_chs = NULL;
  111. wcd9xxx->num_tx_port = 0;
  112. }
  113. } else {
  114. pr_err("Not able to allocate memory for %d slimbus tx ports\n",
  115. wcd9xxx->num_tx_port);
  116. }
  117. return 0;
  118. err:
  119. return ret;
  120. }
  121. EXPORT_SYMBOL(wcd9xxx_init_slimslave);
  122. int wcd9xxx_deinit_slimslave(struct wcd9xxx *wcd9xxx)
  123. {
  124. if (wcd9xxx->num_rx_port) {
  125. wcd9xxx_dealloc_slim_sh_ch(wcd9xxx->slim,
  126. wcd9xxx->num_rx_port,
  127. wcd9xxx->rx_chs);
  128. wcd9xxx->num_rx_port = 0;
  129. }
  130. if (wcd9xxx->num_tx_port) {
  131. wcd9xxx_dealloc_slim_sh_ch(wcd9xxx->slim,
  132. wcd9xxx->num_tx_port,
  133. wcd9xxx->tx_chs);
  134. wcd9xxx->num_tx_port = 0;
  135. }
  136. return 0;
  137. }
  138. static int wcd9xxx_alloc_slim_sh_ch(struct wcd9xxx *wcd9xxx,
  139. u8 wcd9xxx_pgd_la, u32 cnt,
  140. struct wcd9xxx_ch *channels, u32 path)
  141. {
  142. int ret = 0;
  143. u32 ch_idx;
  144. /* The slimbus channel allocation seem take longer time
  145. * so do the allocation up front to avoid delay in start of
  146. * playback
  147. */
  148. pr_debug("%s: pgd_la[%d]\n", __func__, wcd9xxx_pgd_la);
  149. for (ch_idx = 0; ch_idx < cnt; ch_idx++) {
  150. ret = slim_get_slaveport(wcd9xxx_pgd_la,
  151. channels[ch_idx].port,
  152. &channels[ch_idx].sph, path);
  153. pr_debug("%s: pgd_la[%d] channels[%d].port[%d]\n"
  154. "channels[%d].sph[%d] path[%d]\n",
  155. __func__, wcd9xxx_pgd_la, ch_idx,
  156. channels[ch_idx].port,
  157. ch_idx, channels[ch_idx].sph, path);
  158. if (ret < 0) {
  159. pr_err("%s: slave port failure id[%d] ret[%d]\n",
  160. __func__, channels[ch_idx].ch_num, ret);
  161. goto err;
  162. }
  163. ret = slim_query_ch(wcd9xxx->slim,
  164. channels[ch_idx].ch_num,
  165. &channels[ch_idx].ch_h);
  166. if (ret < 0) {
  167. pr_err("%s: slim_query_ch failed ch-num[%d] ret[%d]\n",
  168. __func__, channels[ch_idx].ch_num, ret);
  169. goto err;
  170. }
  171. }
  172. err:
  173. return ret;
  174. }
  175. static int wcd9xxx_dealloc_slim_sh_ch(struct slim_device *slim,
  176. u32 cnt, struct wcd9xxx_ch *channels)
  177. {
  178. int idx = 0;
  179. int ret = 0;
  180. /* slim_dealloc_ch */
  181. for (idx = 0; idx < cnt; idx++) {
  182. ret = slim_dealloc_ch(slim, channels[idx].ch_h);
  183. if (ret < 0) {
  184. pr_err("%s: slim_dealloc_ch fail ret[%d] ch_h[%d]\n",
  185. __func__, ret, channels[idx].ch_h);
  186. }
  187. }
  188. return ret;
  189. }
  190. /* Enable slimbus slave device for RX path */
  191. int wcd9xxx_cfg_slim_sch_rx(struct wcd9xxx *wcd9xxx,
  192. struct list_head *wcd9xxx_ch_list,
  193. unsigned int rate, unsigned int bit_width,
  194. u16 *grph)
  195. {
  196. u8 ch_cnt = 0;
  197. u16 ch_h[SLIM_MAX_RX_PORTS] = {0};
  198. u8 payload = 0;
  199. u16 codec_port = 0;
  200. int ret;
  201. struct slim_ch prop;
  202. struct wcd9xxx_ch *rx;
  203. int size = ARRAY_SIZE(ch_h);
  204. /* Configure slave interface device */
  205. list_for_each_entry(rx, wcd9xxx_ch_list, list) {
  206. payload |= 1 << rx->shift;
  207. if (ch_cnt < size) {
  208. ch_h[ch_cnt] = rx->ch_h;
  209. ch_cnt++;
  210. pr_debug("list ch->ch_h %d ch->sph %d\n",
  211. rx->ch_h, rx->sph);
  212. } else {
  213. pr_err("%s: allocated channel number %u is out of max rangae %d\n",
  214. __func__, ch_cnt,
  215. size);
  216. ret = EINVAL;
  217. goto err;
  218. }
  219. }
  220. pr_debug("%s: ch_cnt[%d] rate=%d WATER_MARK_VAL %d\n",
  221. __func__, ch_cnt, rate, WATER_MARK_VAL);
  222. /* slim_define_ch api */
  223. prop.prot = SLIM_AUTO_ISO;
  224. if ((rate == 44100) || (rate == 88200) || (rate == 176400) ||
  225. (rate == 352800)) {
  226. prop.baser = SLIM_RATE_11025HZ;
  227. prop.ratem = (rate/11025);
  228. } else {
  229. prop.baser = SLIM_RATE_4000HZ;
  230. prop.ratem = (rate/4000);
  231. }
  232. prop.dataf = SLIM_CH_DATAF_NOT_DEFINED;
  233. prop.auxf = SLIM_CH_AUXF_NOT_APPLICABLE;
  234. prop.sampleszbits = bit_width;
  235. pr_debug("Before slim_define_ch:\n"
  236. "ch_cnt %d,ch_h[0] %d ch_h[1] %d, grph %d\n",
  237. ch_cnt, ch_h[0], ch_h[1], *grph);
  238. ret = slim_define_ch(wcd9xxx->slim, &prop, ch_h, ch_cnt,
  239. true, grph);
  240. if (ret < 0) {
  241. pr_err("%s: slim_define_ch failed ret[%d]\n",
  242. __func__, ret);
  243. goto err;
  244. }
  245. list_for_each_entry(rx, wcd9xxx_ch_list, list) {
  246. codec_port = rx->port;
  247. pr_debug("%s: codec_port %d rx 0x%p, payload %d\n"
  248. "sh_ch.rx_port_ch_reg_base0 0x%x\n"
  249. "sh_ch.port_rx_cfg_reg_base 0x%x\n",
  250. __func__, codec_port, rx, payload,
  251. sh_ch.rx_port_ch_reg_base,
  252. sh_ch.port_rx_cfg_reg_base);
  253. /* look for the valid port range and chose the
  254. * payload accordingly
  255. */
  256. /* write to interface device */
  257. ret = wcd9xxx_interface_reg_write(wcd9xxx,
  258. SB_PGD_RX_PORT_MULTI_CHANNEL_0(
  259. sh_ch.rx_port_ch_reg_base, codec_port),
  260. payload);
  261. if (ret < 0) {
  262. pr_err("%s:Intf-dev fail reg[%d] payload[%d] ret[%d]\n",
  263. __func__,
  264. SB_PGD_RX_PORT_MULTI_CHANNEL_0(
  265. sh_ch.rx_port_ch_reg_base, codec_port),
  266. payload, ret);
  267. goto err;
  268. }
  269. /* configure the slave port for water mark and enable*/
  270. ret = wcd9xxx_interface_reg_write(wcd9xxx,
  271. SB_PGD_PORT_CFG_BYTE_ADDR(
  272. sh_ch.port_rx_cfg_reg_base, codec_port),
  273. WATER_MARK_VAL);
  274. if (ret < 0) {
  275. pr_err("%s:watermark set failure for port[%d] ret[%d]",
  276. __func__, codec_port, ret);
  277. }
  278. ret = slim_connect_sink(wcd9xxx->slim, &rx->sph, 1, rx->ch_h);
  279. if (ret < 0) {
  280. pr_err("%s: slim_connect_sink failed ret[%d]\n",
  281. __func__, ret);
  282. goto err_close_slim_sch;
  283. }
  284. }
  285. /* slim_control_ch */
  286. ret = slim_control_ch(wcd9xxx->slim, *grph, SLIM_CH_ACTIVATE,
  287. true);
  288. if (ret < 0) {
  289. pr_err("%s: slim_control_ch failed ret[%d]\n",
  290. __func__, ret);
  291. goto err_close_slim_sch;
  292. }
  293. return 0;
  294. err_close_slim_sch:
  295. /* release all acquired handles */
  296. wcd9xxx_close_slim_sch_rx(wcd9xxx, wcd9xxx_ch_list, *grph);
  297. err:
  298. return ret;
  299. }
  300. EXPORT_SYMBOL(wcd9xxx_cfg_slim_sch_rx);
  301. /* Enable slimbus slave device for RX path */
  302. int wcd9xxx_cfg_slim_sch_tx(struct wcd9xxx *wcd9xxx,
  303. struct list_head *wcd9xxx_ch_list,
  304. unsigned int rate, unsigned int bit_width,
  305. u16 *grph)
  306. {
  307. u16 ch_cnt = 0;
  308. u16 payload = 0;
  309. u16 ch_h[SLIM_MAX_TX_PORTS] = {0};
  310. u16 codec_port;
  311. int ret = 0;
  312. struct wcd9xxx_ch *tx;
  313. int size = ARRAY_SIZE(ch_h);
  314. struct slim_ch prop;
  315. list_for_each_entry(tx, wcd9xxx_ch_list, list) {
  316. payload |= 1 << tx->shift;
  317. if (ch_cnt < size) {
  318. ch_h[ch_cnt] = tx->ch_h;
  319. ch_cnt++;
  320. } else {
  321. pr_err("%s: allocated channel number %u is out of max rangae %d\n",
  322. __func__, ch_cnt,
  323. size);
  324. ret = EINVAL;
  325. goto err;
  326. }
  327. }
  328. /* slim_define_ch api */
  329. prop.prot = SLIM_AUTO_ISO;
  330. prop.baser = SLIM_RATE_4000HZ;
  331. prop.dataf = SLIM_CH_DATAF_NOT_DEFINED;
  332. prop.auxf = SLIM_CH_AUXF_NOT_APPLICABLE;
  333. prop.ratem = (rate/4000);
  334. prop.sampleszbits = bit_width;
  335. ret = slim_define_ch(wcd9xxx->slim, &prop, ch_h, ch_cnt,
  336. true, grph);
  337. if (ret < 0) {
  338. pr_err("%s: slim_define_ch failed ret[%d]\n",
  339. __func__, ret);
  340. goto err;
  341. }
  342. pr_debug("%s: ch_cnt[%d] rate[%d] bitwidth[%u]\n", __func__, ch_cnt,
  343. rate, bit_width);
  344. list_for_each_entry(tx, wcd9xxx_ch_list, list) {
  345. codec_port = tx->port;
  346. pr_debug("%s: codec_port %d tx 0x%p, payload 0x%x\n",
  347. __func__, codec_port, tx, payload);
  348. /* write to interface device */
  349. ret = wcd9xxx_interface_reg_write(wcd9xxx,
  350. SB_PGD_TX_PORT_MULTI_CHANNEL_0(codec_port),
  351. payload & 0x00FF);
  352. if (ret < 0) {
  353. pr_err("%s:Intf-dev fail reg[%d] payload[%d] ret[%d]\n",
  354. __func__,
  355. SB_PGD_TX_PORT_MULTI_CHANNEL_0(codec_port),
  356. payload, ret);
  357. goto err;
  358. }
  359. /* ports 8,9 */
  360. ret = wcd9xxx_interface_reg_write(wcd9xxx,
  361. SB_PGD_TX_PORT_MULTI_CHANNEL_1(codec_port),
  362. (payload & 0xFF00)>>8);
  363. if (ret < 0) {
  364. pr_err("%s:Intf-dev fail reg[%d] payload[%d] ret[%d]\n",
  365. __func__,
  366. SB_PGD_TX_PORT_MULTI_CHANNEL_1(codec_port),
  367. payload, ret);
  368. goto err;
  369. }
  370. /* configure the slave port for water mark and enable*/
  371. ret = wcd9xxx_interface_reg_write(wcd9xxx,
  372. SB_PGD_PORT_CFG_BYTE_ADDR(
  373. sh_ch.port_tx_cfg_reg_base, codec_port),
  374. WATER_MARK_VAL);
  375. if (ret < 0) {
  376. pr_err("%s:watermark set failure for port[%d] ret[%d]",
  377. __func__, codec_port, ret);
  378. }
  379. ret = slim_connect_src(wcd9xxx->slim, tx->sph, tx->ch_h);
  380. if (ret < 0) {
  381. pr_err("%s: slim_connect_src failed ret[%d]\n",
  382. __func__, ret);
  383. goto err;
  384. }
  385. }
  386. /* slim_control_ch */
  387. ret = slim_control_ch(wcd9xxx->slim, *grph, SLIM_CH_ACTIVATE,
  388. true);
  389. if (ret < 0) {
  390. pr_err("%s: slim_control_ch failed ret[%d]\n",
  391. __func__, ret);
  392. goto err;
  393. }
  394. return 0;
  395. err:
  396. /* release all acquired handles */
  397. wcd9xxx_close_slim_sch_tx(wcd9xxx, wcd9xxx_ch_list, *grph);
  398. return ret;
  399. }
  400. EXPORT_SYMBOL(wcd9xxx_cfg_slim_sch_tx);
  401. int wcd9xxx_close_slim_sch_rx(struct wcd9xxx *wcd9xxx,
  402. struct list_head *wcd9xxx_ch_list, u16 grph)
  403. {
  404. u32 sph[SLIM_MAX_RX_PORTS] = {0};
  405. int ch_cnt = 0;
  406. int ret = 0;
  407. struct wcd9xxx_ch *rx;
  408. list_for_each_entry(rx, wcd9xxx_ch_list, list)
  409. sph[ch_cnt++] = rx->sph;
  410. pr_debug("%s ch_cht %d, sph[0] %d sph[1] %d\n", __func__, ch_cnt,
  411. sph[0], sph[1]);
  412. /* slim_control_ch (REMOVE) */
  413. pr_debug("%s before slim_control_ch grph %d\n", __func__, grph);
  414. ret = slim_control_ch(wcd9xxx->slim, grph, SLIM_CH_REMOVE, true);
  415. if (ret < 0) {
  416. pr_err("%s: slim_control_ch failed ret[%d]\n", __func__, ret);
  417. goto err;
  418. }
  419. err:
  420. return ret;
  421. }
  422. EXPORT_SYMBOL(wcd9xxx_close_slim_sch_rx);
  423. int wcd9xxx_close_slim_sch_tx(struct wcd9xxx *wcd9xxx,
  424. struct list_head *wcd9xxx_ch_list,
  425. u16 grph)
  426. {
  427. u32 sph[SLIM_MAX_TX_PORTS] = {0};
  428. int ret = 0;
  429. int ch_cnt = 0;
  430. struct wcd9xxx_ch *tx;
  431. pr_debug("%s\n", __func__);
  432. list_for_each_entry(tx, wcd9xxx_ch_list, list)
  433. sph[ch_cnt++] = tx->sph;
  434. pr_debug("%s ch_cht %d, sph[0] %d sph[1] %d\n",
  435. __func__, ch_cnt, sph[0], sph[1]);
  436. /* slim_control_ch (REMOVE) */
  437. ret = slim_control_ch(wcd9xxx->slim, grph, SLIM_CH_REMOVE, true);
  438. if (ret < 0) {
  439. pr_err("%s: slim_control_ch failed ret[%d]\n",
  440. __func__, ret);
  441. goto err;
  442. }
  443. err:
  444. return ret;
  445. }
  446. EXPORT_SYMBOL(wcd9xxx_close_slim_sch_tx);
  447. int wcd9xxx_get_slave_port(unsigned int ch_num)
  448. {
  449. int ret = 0;
  450. ret = (ch_num - BASE_CH_NUM);
  451. pr_debug("%s: ch_num[%d] slave port[%d]\n", __func__, ch_num, ret);
  452. if (ret < 0) {
  453. pr_err("%s: Error:- Invalid slave port found = %d\n",
  454. __func__, ret);
  455. return -EINVAL;
  456. }
  457. return ret;
  458. }
  459. EXPORT_SYMBOL(wcd9xxx_get_slave_port);
  460. int wcd9xxx_disconnect_port(struct wcd9xxx *wcd9xxx,
  461. struct list_head *wcd9xxx_ch_list, u16 grph)
  462. {
  463. u32 sph[SLIM_MAX_TX_PORTS + SLIM_MAX_RX_PORTS] = {0};
  464. int ch_cnt = 0;
  465. int ret = 0;
  466. struct wcd9xxx_ch *slim_ch;
  467. list_for_each_entry(slim_ch, wcd9xxx_ch_list, list)
  468. sph[ch_cnt++] = slim_ch->sph;
  469. /* slim_disconnect_port */
  470. ret = slim_disconnect_ports(wcd9xxx->slim, sph, ch_cnt);
  471. if (ret < 0) {
  472. pr_err("%s: slim_disconnect_ports failed ret[%d]\n",
  473. __func__, ret);
  474. }
  475. return ret;
  476. }
  477. EXPORT_SYMBOL(wcd9xxx_disconnect_port);
  478. /* This function is called with mutex acquired */
  479. int wcd9xxx_rx_vport_validation(u32 port_id,
  480. struct list_head *codec_dai_list)
  481. {
  482. struct wcd9xxx_ch *ch;
  483. int ret = 0;
  484. pr_debug("%s: port_id %u\n", __func__, port_id);
  485. list_for_each_entry(ch,
  486. codec_dai_list, list) {
  487. pr_debug("%s: ch->port %u\n", __func__, ch->port);
  488. if (ch->port == port_id) {
  489. ret = -EINVAL;
  490. break;
  491. }
  492. }
  493. return ret;
  494. }
  495. EXPORT_SYMBOL(wcd9xxx_rx_vport_validation);
  496. /* This function is called with mutex acquired */
  497. int wcd9xxx_tx_vport_validation(u32 table, u32 port_id,
  498. struct wcd9xxx_codec_dai_data *codec_dai,
  499. u32 num_codec_dais)
  500. {
  501. struct wcd9xxx_ch *ch;
  502. int ret = 0;
  503. u32 index;
  504. unsigned long vtable = table;
  505. u32 size = sizeof(table) * BITS_PER_BYTE;
  506. pr_debug("%s: vtable 0x%lx port_id %u size %d\n", __func__,
  507. vtable, port_id, size);
  508. for_each_set_bit(index, &vtable, size) {
  509. if (index < num_codec_dais) {
  510. list_for_each_entry(ch,
  511. &codec_dai[index].wcd9xxx_ch_list,
  512. list) {
  513. pr_debug("%s: index %u ch->port %u vtable 0x%lx\n",
  514. __func__, index, ch->port,
  515. vtable);
  516. if (ch->port == port_id) {
  517. pr_err("%s: TX%u is used by AIF%u_CAP Mixer\n",
  518. __func__, port_id + 1,
  519. (index + 1)/2);
  520. ret = -EINVAL;
  521. break;
  522. }
  523. }
  524. } else {
  525. pr_err("%s: Invalid index %d of codec dai",
  526. __func__, index);
  527. ret = -EINVAL;
  528. }
  529. if (ret)
  530. break;
  531. }
  532. return ret;
  533. }
  534. EXPORT_SYMBOL(wcd9xxx_tx_vport_validation);