soc-dai.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // soc-dai.c
  4. //
  5. // Copyright (C) 2019 Renesas Electronics Corp.
  6. // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  7. //
  8. #include <sound/soc.h>
  9. #include <sound/soc-dai.h>
  10. #include <sound/soc-link.h>
  11. #define soc_dai_ret(dai, ret) _soc_dai_ret(dai, __func__, ret)
  12. static inline int _soc_dai_ret(const struct snd_soc_dai *dai,
  13. const char *func, int ret)
  14. {
  15. return snd_soc_ret(dai->dev, ret,
  16. "at %s() on %s\n", func, dai->name);
  17. }
  18. /*
  19. * We might want to check substream by using list.
  20. * In such case, we can update these macros.
  21. */
  22. #define soc_dai_mark_push(dai, substream, tgt) ((dai)->mark_##tgt = substream)
  23. #define soc_dai_mark_pop(dai, tgt) ((dai)->mark_##tgt = NULL)
  24. #define soc_dai_mark_match(dai, substream, tgt) ((dai)->mark_##tgt == substream)
  25. /**
  26. * snd_soc_dai_set_sysclk - configure DAI system or master clock.
  27. * @dai: DAI
  28. * @clk_id: DAI specific clock ID
  29. * @freq: new clock frequency in Hz
  30. * @dir: new clock direction (SND_SOC_CLOCK_IN or SND_SOC_CLOCK_OUT)
  31. *
  32. * Configures the DAI master (MCLK) or system (SYSCLK) clocking.
  33. */
  34. int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  35. unsigned int freq, int dir)
  36. {
  37. int ret;
  38. if (dai->driver->ops &&
  39. dai->driver->ops->set_sysclk)
  40. ret = dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
  41. else
  42. ret = snd_soc_component_set_sysclk(dai->component, clk_id, 0,
  43. freq, dir);
  44. return soc_dai_ret(dai, ret);
  45. }
  46. EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
  47. /**
  48. * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  49. * @dai: DAI
  50. * @div_id: DAI specific clock divider ID
  51. * @div: new clock divisor.
  52. *
  53. * Configures the clock dividers. This is used to derive the best DAI bit and
  54. * frame clocks from the system or master clock. It's best to set the DAI bit
  55. * and frame clocks as low as possible to save system power.
  56. */
  57. int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
  58. int div_id, int div)
  59. {
  60. int ret = -EINVAL;
  61. if (dai->driver->ops &&
  62. dai->driver->ops->set_clkdiv)
  63. ret = dai->driver->ops->set_clkdiv(dai, div_id, div);
  64. return soc_dai_ret(dai, ret);
  65. }
  66. EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
  67. /**
  68. * snd_soc_dai_set_pll - configure DAI PLL.
  69. * @dai: DAI
  70. * @pll_id: DAI specific PLL ID
  71. * @source: DAI specific source for the PLL
  72. * @freq_in: PLL input clock frequency in Hz
  73. * @freq_out: requested PLL output clock frequency in Hz
  74. *
  75. * Configures and enables PLL to generate output clock based on input clock.
  76. */
  77. int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
  78. unsigned int freq_in, unsigned int freq_out)
  79. {
  80. int ret;
  81. if (dai->driver->ops &&
  82. dai->driver->ops->set_pll)
  83. ret = dai->driver->ops->set_pll(dai, pll_id, source,
  84. freq_in, freq_out);
  85. else
  86. ret = snd_soc_component_set_pll(dai->component, pll_id, source,
  87. freq_in, freq_out);
  88. return soc_dai_ret(dai, ret);
  89. }
  90. EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
  91. /**
  92. * snd_soc_dai_set_bclk_ratio - configure BCLK to sample rate ratio.
  93. * @dai: DAI
  94. * @ratio: Ratio of BCLK to Sample rate.
  95. *
  96. * Configures the DAI for a preset BCLK to sample rate ratio.
  97. */
  98. int snd_soc_dai_set_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
  99. {
  100. int ret = -ENOTSUPP;
  101. if (dai->driver->ops &&
  102. dai->driver->ops->set_bclk_ratio)
  103. ret = dai->driver->ops->set_bclk_ratio(dai, ratio);
  104. return soc_dai_ret(dai, ret);
  105. }
  106. EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
  107. int snd_soc_dai_get_fmt_max_priority(const struct snd_soc_pcm_runtime *rtd)
  108. {
  109. struct snd_soc_dai *dai;
  110. int i, max = 0;
  111. /*
  112. * return max num if *ALL* DAIs have .auto_selectable_formats
  113. */
  114. for_each_rtd_dais(rtd, i, dai) {
  115. if (dai->driver->ops &&
  116. dai->driver->ops->num_auto_selectable_formats)
  117. max = max(max, dai->driver->ops->num_auto_selectable_formats);
  118. else
  119. return 0;
  120. }
  121. return max;
  122. }
  123. /**
  124. * snd_soc_dai_get_fmt - get supported audio format.
  125. * @dai: DAI
  126. * @priority: priority level of supported audio format.
  127. *
  128. * This should return only formats implemented with high
  129. * quality by the DAI so that the core can configure a
  130. * format which will work well with other devices.
  131. * For example devices which don't support both edges of the
  132. * LRCLK signal in I2S style formats should only list DSP
  133. * modes. This will mean that sometimes fewer formats
  134. * are reported here than are supported by set_fmt().
  135. */
  136. u64 snd_soc_dai_get_fmt(const struct snd_soc_dai *dai, int priority)
  137. {
  138. const struct snd_soc_dai_ops *ops = dai->driver->ops;
  139. u64 fmt = 0;
  140. int i, max = 0, until = priority;
  141. /*
  142. * Collect auto_selectable_formats until priority
  143. *
  144. * ex)
  145. * auto_selectable_formats[] = { A, B, C };
  146. * (A, B, C = SND_SOC_POSSIBLE_DAIFMT_xxx)
  147. *
  148. * priority = 1 : A
  149. * priority = 2 : A | B
  150. * priority = 3 : A | B | C
  151. * priority = 4 : A | B | C
  152. * ...
  153. */
  154. if (ops)
  155. max = ops->num_auto_selectable_formats;
  156. if (max < until)
  157. until = max;
  158. if (ops && ops->auto_selectable_formats)
  159. for (i = 0; i < until; i++)
  160. fmt |= ops->auto_selectable_formats[i];
  161. return fmt;
  162. }
  163. /**
  164. * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  165. * @dai: DAI
  166. * @fmt: SND_SOC_DAIFMT_* format value.
  167. *
  168. * Configures the DAI hardware format and clocking.
  169. */
  170. int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  171. {
  172. int ret = -ENOTSUPP;
  173. if (dai->driver->ops && dai->driver->ops->set_fmt)
  174. ret = dai->driver->ops->set_fmt(dai, fmt);
  175. return soc_dai_ret(dai, ret);
  176. }
  177. EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
  178. /**
  179. * snd_soc_xlate_tdm_slot_mask - generate tx/rx slot mask.
  180. * @slots: Number of slots in use.
  181. * @tx_mask: bitmask representing active TX slots.
  182. * @rx_mask: bitmask representing active RX slots.
  183. *
  184. * Generates the TDM tx and rx slot default masks for DAI.
  185. */
  186. static int snd_soc_xlate_tdm_slot_mask(unsigned int slots,
  187. unsigned int *tx_mask,
  188. unsigned int *rx_mask)
  189. {
  190. if (*tx_mask || *rx_mask)
  191. return 0;
  192. if (!slots)
  193. return -EINVAL;
  194. *tx_mask = (1 << slots) - 1;
  195. *rx_mask = (1 << slots) - 1;
  196. return 0;
  197. }
  198. /**
  199. * snd_soc_dai_set_tdm_slot() - Configures a DAI for TDM operation
  200. * @dai: The DAI to configure
  201. * @tx_mask: bitmask representing active TX slots.
  202. * @rx_mask: bitmask representing active RX slots.
  203. * @slots: Number of slots in use.
  204. * @slot_width: Width in bits for each slot.
  205. *
  206. * This function configures the specified DAI for TDM operation. @slot contains
  207. * the total number of slots of the TDM stream and @slot_with the width of each
  208. * slot in bit clock cycles. @tx_mask and @rx_mask are bitmasks specifying the
  209. * active slots of the TDM stream for the specified DAI, i.e. which slots the
  210. * DAI should write to or read from. If a bit is set the corresponding slot is
  211. * active, if a bit is cleared the corresponding slot is inactive. Bit 0 maps to
  212. * the first slot, bit 1 to the second slot and so on. The first active slot
  213. * maps to the first channel of the DAI, the second active slot to the second
  214. * channel and so on.
  215. *
  216. * TDM mode can be disabled by passing 0 for @slots. In this case @tx_mask,
  217. * @rx_mask and @slot_width will be ignored.
  218. *
  219. * Returns 0 on success, a negative error code otherwise.
  220. */
  221. int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
  222. unsigned int tx_mask, unsigned int rx_mask,
  223. int slots, int slot_width)
  224. {
  225. int ret = -ENOTSUPP;
  226. int stream;
  227. unsigned int *tdm_mask[] = {
  228. &tx_mask,
  229. &rx_mask,
  230. };
  231. if (slots) {
  232. if (dai->driver->ops &&
  233. dai->driver->ops->xlate_tdm_slot_mask)
  234. ret = dai->driver->ops->xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
  235. else
  236. ret = snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
  237. if (ret)
  238. goto err;
  239. }
  240. for_each_pcm_streams(stream)
  241. snd_soc_dai_tdm_mask_set(dai, stream, *tdm_mask[stream]);
  242. if (dai->driver->ops &&
  243. dai->driver->ops->set_tdm_slot)
  244. ret = dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
  245. slots, slot_width);
  246. err:
  247. return soc_dai_ret(dai, ret);
  248. }
  249. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
  250. /**
  251. * snd_soc_dai_set_channel_map - configure DAI audio channel map
  252. * @dai: DAI
  253. * @tx_num: how many TX channels
  254. * @tx_slot: pointer to an array which imply the TX slot number channel
  255. * 0~num-1 uses
  256. * @rx_num: how many RX channels
  257. * @rx_slot: pointer to an array which imply the RX slot number channel
  258. * 0~num-1 uses
  259. *
  260. * configure the relationship between channel number and TDM slot number.
  261. */
  262. int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
  263. unsigned int tx_num, const unsigned int *tx_slot,
  264. unsigned int rx_num, const unsigned int *rx_slot)
  265. {
  266. int ret = -ENOTSUPP;
  267. if (dai->driver->ops &&
  268. dai->driver->ops->set_channel_map)
  269. ret = dai->driver->ops->set_channel_map(dai, tx_num, tx_slot,
  270. rx_num, rx_slot);
  271. return soc_dai_ret(dai, ret);
  272. }
  273. EXPORT_SYMBOL_GPL(snd_soc_dai_set_channel_map);
  274. /**
  275. * snd_soc_dai_get_channel_map - Get DAI audio channel map
  276. * @dai: DAI
  277. * @tx_num: how many TX channels
  278. * @tx_slot: pointer to an array which imply the TX slot number channel
  279. * 0~num-1 uses
  280. * @rx_num: how many RX channels
  281. * @rx_slot: pointer to an array which imply the RX slot number channel
  282. * 0~num-1 uses
  283. */
  284. int snd_soc_dai_get_channel_map(const struct snd_soc_dai *dai,
  285. unsigned int *tx_num, unsigned int *tx_slot,
  286. unsigned int *rx_num, unsigned int *rx_slot)
  287. {
  288. int ret = -ENOTSUPP;
  289. if (dai->driver->ops &&
  290. dai->driver->ops->get_channel_map)
  291. ret = dai->driver->ops->get_channel_map(dai, tx_num, tx_slot,
  292. rx_num, rx_slot);
  293. return soc_dai_ret(dai, ret);
  294. }
  295. EXPORT_SYMBOL_GPL(snd_soc_dai_get_channel_map);
  296. /**
  297. * snd_soc_dai_set_tristate - configure DAI system or master clock.
  298. * @dai: DAI
  299. * @tristate: tristate enable
  300. *
  301. * Tristates the DAI so that others can use it.
  302. */
  303. int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
  304. {
  305. int ret = -EINVAL;
  306. if (dai->driver->ops &&
  307. dai->driver->ops->set_tristate)
  308. ret = dai->driver->ops->set_tristate(dai, tristate);
  309. return soc_dai_ret(dai, ret);
  310. }
  311. EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
  312. int snd_soc_dai_prepare(struct snd_soc_dai *dai,
  313. struct snd_pcm_substream *substream)
  314. {
  315. int ret = 0;
  316. if (!snd_soc_dai_stream_valid(dai, substream->stream))
  317. return 0;
  318. if (dai->driver->ops &&
  319. dai->driver->ops->prepare)
  320. ret = dai->driver->ops->prepare(substream, dai);
  321. return soc_dai_ret(dai, ret);
  322. }
  323. EXPORT_SYMBOL_GPL(snd_soc_dai_prepare);
  324. int snd_soc_dai_mute_is_ctrled_at_trigger(struct snd_soc_dai *dai)
  325. {
  326. if (dai->driver->ops)
  327. return dai->driver->ops->mute_unmute_on_trigger;
  328. return 0;
  329. }
  330. /**
  331. * snd_soc_dai_digital_mute - configure DAI system or master clock.
  332. * @dai: DAI
  333. * @mute: mute enable
  334. * @direction: stream to mute
  335. *
  336. * Mutes the DAI DAC.
  337. */
  338. int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
  339. int direction)
  340. {
  341. int ret = -ENOTSUPP;
  342. /*
  343. * ignore if direction was CAPTURE
  344. * and it had .no_capture_mute flag
  345. */
  346. if (dai->driver->ops &&
  347. dai->driver->ops->mute_stream &&
  348. (direction == SNDRV_PCM_STREAM_PLAYBACK ||
  349. !dai->driver->ops->no_capture_mute))
  350. ret = dai->driver->ops->mute_stream(dai, mute, direction);
  351. return soc_dai_ret(dai, ret);
  352. }
  353. EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  354. int snd_soc_dai_hw_params(struct snd_soc_dai *dai,
  355. struct snd_pcm_substream *substream,
  356. struct snd_pcm_hw_params *params)
  357. {
  358. int ret = 0;
  359. if (dai->driver->ops &&
  360. dai->driver->ops->hw_params)
  361. ret = dai->driver->ops->hw_params(substream, params, dai);
  362. /* mark substream if succeeded */
  363. if (ret == 0)
  364. soc_dai_mark_push(dai, substream, hw_params);
  365. return soc_dai_ret(dai, ret);
  366. }
  367. void snd_soc_dai_hw_free(struct snd_soc_dai *dai,
  368. struct snd_pcm_substream *substream,
  369. int rollback)
  370. {
  371. if (rollback && !soc_dai_mark_match(dai, substream, hw_params))
  372. return;
  373. if (dai->driver->ops &&
  374. dai->driver->ops->hw_free)
  375. dai->driver->ops->hw_free(substream, dai);
  376. /* remove marked substream */
  377. soc_dai_mark_pop(dai, hw_params);
  378. }
  379. int snd_soc_dai_startup(struct snd_soc_dai *dai,
  380. struct snd_pcm_substream *substream)
  381. {
  382. int ret = 0;
  383. if (!snd_soc_dai_stream_valid(dai, substream->stream))
  384. return 0;
  385. if (dai->driver->ops &&
  386. dai->driver->ops->startup)
  387. ret = dai->driver->ops->startup(substream, dai);
  388. /* mark substream if succeeded */
  389. if (ret == 0)
  390. soc_dai_mark_push(dai, substream, startup);
  391. return soc_dai_ret(dai, ret);
  392. }
  393. void snd_soc_dai_shutdown(struct snd_soc_dai *dai,
  394. struct snd_pcm_substream *substream,
  395. int rollback)
  396. {
  397. if (!snd_soc_dai_stream_valid(dai, substream->stream))
  398. return;
  399. if (rollback && !soc_dai_mark_match(dai, substream, startup))
  400. return;
  401. if (dai->driver->ops &&
  402. dai->driver->ops->shutdown)
  403. dai->driver->ops->shutdown(substream, dai);
  404. /* remove marked substream */
  405. soc_dai_mark_pop(dai, startup);
  406. }
  407. int snd_soc_dai_compress_new(struct snd_soc_dai *dai,
  408. struct snd_soc_pcm_runtime *rtd)
  409. {
  410. int ret = -ENOTSUPP;
  411. if (dai->driver->ops &&
  412. dai->driver->ops->compress_new)
  413. ret = dai->driver->ops->compress_new(rtd);
  414. return soc_dai_ret(dai, ret);
  415. }
  416. /*
  417. * snd_soc_dai_stream_valid() - check if a DAI supports the given stream
  418. *
  419. * Returns true if the DAI supports the indicated stream type.
  420. */
  421. bool snd_soc_dai_stream_valid(const struct snd_soc_dai *dai, int dir)
  422. {
  423. const struct snd_soc_pcm_stream *stream = snd_soc_dai_get_pcm_stream(dai, dir);
  424. /* If the codec specifies any channels at all, it supports the stream */
  425. return stream->channels_min;
  426. }
  427. void snd_soc_dai_action(struct snd_soc_dai *dai,
  428. int stream, int action)
  429. {
  430. /* see snd_soc_dai_stream_active() */
  431. dai->stream[stream].active += action;
  432. /* see snd_soc_component_active() */
  433. dai->component->active += action;
  434. }
  435. EXPORT_SYMBOL_GPL(snd_soc_dai_action);
  436. int snd_soc_dai_active(const struct snd_soc_dai *dai)
  437. {
  438. int stream, active;
  439. active = 0;
  440. for_each_pcm_streams(stream)
  441. active += dai->stream[stream].active;
  442. return active;
  443. }
  444. EXPORT_SYMBOL_GPL(snd_soc_dai_active);
  445. int snd_soc_pcm_dai_probe(struct snd_soc_pcm_runtime *rtd, int order)
  446. {
  447. struct snd_soc_dai *dai;
  448. int i;
  449. for_each_rtd_dais(rtd, i, dai) {
  450. if (dai->probed)
  451. continue;
  452. if (dai->driver->ops) {
  453. if (dai->driver->ops->probe_order != order)
  454. continue;
  455. if (dai->driver->ops->probe) {
  456. int ret = dai->driver->ops->probe(dai);
  457. if (ret < 0)
  458. return soc_dai_ret(dai, ret);
  459. }
  460. }
  461. dai->probed = 1;
  462. }
  463. return 0;
  464. }
  465. int snd_soc_pcm_dai_remove(struct snd_soc_pcm_runtime *rtd, int order)
  466. {
  467. struct snd_soc_dai *dai;
  468. int i, r, ret = 0;
  469. for_each_rtd_dais(rtd, i, dai) {
  470. if (!dai->probed)
  471. continue;
  472. if (dai->driver->ops) {
  473. if (dai->driver->ops->remove_order != order)
  474. continue;
  475. if (dai->driver->ops->remove) {
  476. r = dai->driver->ops->remove(dai);
  477. if (r < 0)
  478. ret = r; /* use last error */
  479. }
  480. }
  481. dai->probed = 0;
  482. }
  483. return ret;
  484. }
  485. int snd_soc_pcm_dai_new(struct snd_soc_pcm_runtime *rtd)
  486. {
  487. struct snd_soc_dai *dai;
  488. int i;
  489. for_each_rtd_dais(rtd, i, dai) {
  490. if (dai->driver->ops &&
  491. dai->driver->ops->pcm_new) {
  492. int ret = dai->driver->ops->pcm_new(rtd, dai);
  493. if (ret < 0)
  494. return soc_dai_ret(dai, ret);
  495. }
  496. }
  497. return 0;
  498. }
  499. int snd_soc_pcm_dai_prepare(struct snd_pcm_substream *substream)
  500. {
  501. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  502. struct snd_soc_dai *dai;
  503. int i, ret;
  504. for_each_rtd_dais(rtd, i, dai) {
  505. ret = snd_soc_dai_prepare(dai, substream);
  506. if (ret < 0)
  507. return ret;
  508. }
  509. return 0;
  510. }
  511. static int soc_dai_trigger(struct snd_soc_dai *dai,
  512. struct snd_pcm_substream *substream, int cmd)
  513. {
  514. int ret = 0;
  515. if (!snd_soc_dai_stream_valid(dai, substream->stream))
  516. return 0;
  517. if (dai->driver->ops &&
  518. dai->driver->ops->trigger)
  519. ret = dai->driver->ops->trigger(substream, cmd, dai);
  520. return soc_dai_ret(dai, ret);
  521. }
  522. int snd_soc_pcm_dai_trigger(struct snd_pcm_substream *substream,
  523. int cmd, int rollback)
  524. {
  525. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  526. struct snd_soc_dai *dai;
  527. int i, r, ret = 0;
  528. switch (cmd) {
  529. case SNDRV_PCM_TRIGGER_START:
  530. case SNDRV_PCM_TRIGGER_RESUME:
  531. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  532. for_each_rtd_dais(rtd, i, dai) {
  533. ret = soc_dai_trigger(dai, substream, cmd);
  534. if (ret < 0)
  535. break;
  536. if (snd_soc_dai_mute_is_ctrled_at_trigger(dai))
  537. snd_soc_dai_digital_mute(dai, 0, substream->stream);
  538. soc_dai_mark_push(dai, substream, trigger);
  539. }
  540. break;
  541. case SNDRV_PCM_TRIGGER_STOP:
  542. case SNDRV_PCM_TRIGGER_SUSPEND:
  543. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  544. for_each_rtd_dais(rtd, i, dai) {
  545. if (rollback && !soc_dai_mark_match(dai, substream, trigger))
  546. continue;
  547. if (snd_soc_dai_mute_is_ctrled_at_trigger(dai))
  548. snd_soc_dai_digital_mute(dai, 1, substream->stream);
  549. r = soc_dai_trigger(dai, substream, cmd);
  550. if (r < 0)
  551. ret = r; /* use last ret */
  552. soc_dai_mark_pop(dai, trigger);
  553. }
  554. }
  555. return ret;
  556. }
  557. void snd_soc_pcm_dai_delay(struct snd_pcm_substream *substream,
  558. snd_pcm_sframes_t *cpu_delay,
  559. snd_pcm_sframes_t *codec_delay)
  560. {
  561. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  562. struct snd_soc_dai *dai;
  563. int i;
  564. /*
  565. * We're looking for the delay through the full audio path so it needs to
  566. * be the maximum of the DAIs doing transmit and the maximum of the DAIs
  567. * doing receive (ie, all CPUs and all CODECs) rather than just the maximum
  568. * of all DAIs.
  569. */
  570. /* for CPU */
  571. for_each_rtd_cpu_dais(rtd, i, dai)
  572. if (dai->driver->ops &&
  573. dai->driver->ops->delay)
  574. *cpu_delay = max(*cpu_delay, dai->driver->ops->delay(substream, dai));
  575. /* for Codec */
  576. for_each_rtd_codec_dais(rtd, i, dai)
  577. if (dai->driver->ops &&
  578. dai->driver->ops->delay)
  579. *codec_delay = max(*codec_delay, dai->driver->ops->delay(substream, dai));
  580. }
  581. int snd_soc_dai_compr_startup(struct snd_soc_dai *dai,
  582. struct snd_compr_stream *cstream)
  583. {
  584. int ret = 0;
  585. if (dai->driver->cops &&
  586. dai->driver->cops->startup)
  587. ret = dai->driver->cops->startup(cstream, dai);
  588. /* mark cstream if succeeded */
  589. if (ret == 0)
  590. soc_dai_mark_push(dai, cstream, compr_startup);
  591. return soc_dai_ret(dai, ret);
  592. }
  593. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_startup);
  594. void snd_soc_dai_compr_shutdown(struct snd_soc_dai *dai,
  595. struct snd_compr_stream *cstream,
  596. int rollback)
  597. {
  598. if (rollback && !soc_dai_mark_match(dai, cstream, compr_startup))
  599. return;
  600. if (dai->driver->cops &&
  601. dai->driver->cops->shutdown)
  602. dai->driver->cops->shutdown(cstream, dai);
  603. /* remove marked cstream */
  604. soc_dai_mark_pop(dai, compr_startup);
  605. }
  606. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_shutdown);
  607. int snd_soc_dai_compr_trigger(struct snd_soc_dai *dai,
  608. struct snd_compr_stream *cstream, int cmd)
  609. {
  610. int ret = 0;
  611. if (dai->driver->cops &&
  612. dai->driver->cops->trigger)
  613. ret = dai->driver->cops->trigger(cstream, cmd, dai);
  614. return soc_dai_ret(dai, ret);
  615. }
  616. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_trigger);
  617. int snd_soc_dai_compr_set_params(struct snd_soc_dai *dai,
  618. struct snd_compr_stream *cstream,
  619. struct snd_compr_params *params)
  620. {
  621. int ret = 0;
  622. if (dai->driver->cops &&
  623. dai->driver->cops->set_params)
  624. ret = dai->driver->cops->set_params(cstream, params, dai);
  625. return soc_dai_ret(dai, ret);
  626. }
  627. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_set_params);
  628. int snd_soc_dai_compr_get_params(struct snd_soc_dai *dai,
  629. struct snd_compr_stream *cstream,
  630. struct snd_codec *params)
  631. {
  632. int ret = 0;
  633. if (dai->driver->cops &&
  634. dai->driver->cops->get_params)
  635. ret = dai->driver->cops->get_params(cstream, params, dai);
  636. return soc_dai_ret(dai, ret);
  637. }
  638. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_get_params);
  639. int snd_soc_dai_compr_ack(struct snd_soc_dai *dai,
  640. struct snd_compr_stream *cstream,
  641. size_t bytes)
  642. {
  643. int ret = 0;
  644. if (dai->driver->cops &&
  645. dai->driver->cops->ack)
  646. ret = dai->driver->cops->ack(cstream, bytes, dai);
  647. return soc_dai_ret(dai, ret);
  648. }
  649. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_ack);
  650. int snd_soc_dai_compr_pointer(struct snd_soc_dai *dai,
  651. struct snd_compr_stream *cstream,
  652. struct snd_compr_tstamp64 *tstamp)
  653. {
  654. int ret = 0;
  655. if (dai->driver->cops &&
  656. dai->driver->cops->pointer)
  657. ret = dai->driver->cops->pointer(cstream, tstamp, dai);
  658. return soc_dai_ret(dai, ret);
  659. }
  660. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_pointer);
  661. int snd_soc_dai_compr_set_metadata(struct snd_soc_dai *dai,
  662. struct snd_compr_stream *cstream,
  663. struct snd_compr_metadata *metadata)
  664. {
  665. int ret = 0;
  666. if (dai->driver->cops &&
  667. dai->driver->cops->set_metadata)
  668. ret = dai->driver->cops->set_metadata(cstream, metadata, dai);
  669. return soc_dai_ret(dai, ret);
  670. }
  671. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_set_metadata);
  672. int snd_soc_dai_compr_get_metadata(struct snd_soc_dai *dai,
  673. struct snd_compr_stream *cstream,
  674. struct snd_compr_metadata *metadata)
  675. {
  676. int ret = 0;
  677. if (dai->driver->cops &&
  678. dai->driver->cops->get_metadata)
  679. ret = dai->driver->cops->get_metadata(cstream, metadata, dai);
  680. return soc_dai_ret(dai, ret);
  681. }
  682. EXPORT_SYMBOL_GPL(snd_soc_dai_compr_get_metadata);