hda-dai-ops.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // This file is provided under a dual BSD/GPLv2 license. When using or
  4. // redistributing this file, you may do so under either license.
  5. //
  6. // Copyright(c) 2022 Intel Corporation
  7. #include <sound/pcm_params.h>
  8. #include <sound/hdaudio_ext.h>
  9. #include <sound/hda_register.h>
  10. #include <sound/hda-mlink.h>
  11. #include <sound/sof/ipc4/header.h>
  12. #include <uapi/sound/sof/header.h>
  13. #include "../ipc4-priv.h"
  14. #include "../ipc4-topology.h"
  15. #include "../sof-priv.h"
  16. #include "../sof-audio.h"
  17. #include "hda.h"
  18. /* These ops are only applicable for the HDA DAI's in their current form */
  19. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_LINK)
  20. /*
  21. * This function checks if the host dma channel corresponding
  22. * to the link DMA stream_tag argument is assigned to one
  23. * of the FEs connected to the BE DAI.
  24. */
  25. static bool hda_check_fes(struct snd_soc_pcm_runtime *rtd,
  26. int dir, int stream_tag)
  27. {
  28. struct snd_pcm_substream *fe_substream;
  29. struct hdac_stream *fe_hstream;
  30. struct snd_soc_dpcm *dpcm;
  31. for_each_dpcm_fe(rtd, dir, dpcm) {
  32. fe_substream = snd_soc_dpcm_get_substream(dpcm->fe, dir);
  33. fe_hstream = fe_substream->runtime->private_data;
  34. if (fe_hstream->stream_tag == stream_tag)
  35. return true;
  36. }
  37. return false;
  38. }
  39. static struct hdac_ext_stream *
  40. hda_link_stream_assign(struct hdac_bus *bus, struct snd_pcm_substream *substream)
  41. {
  42. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  43. struct sof_intel_hda_stream *hda_stream;
  44. const struct sof_intel_dsp_desc *chip;
  45. struct snd_sof_dev *sdev;
  46. struct hdac_ext_stream *res = NULL;
  47. struct hdac_stream *hstream = NULL;
  48. int stream_dir = substream->stream;
  49. if (!bus->ppcap) {
  50. dev_err(bus->dev, "stream type not supported\n");
  51. return NULL;
  52. }
  53. spin_lock_irq(&bus->reg_lock);
  54. list_for_each_entry(hstream, &bus->stream_list, list) {
  55. struct hdac_ext_stream *hext_stream =
  56. stream_to_hdac_ext_stream(hstream);
  57. if (hstream->direction != substream->stream)
  58. continue;
  59. hda_stream = hstream_to_sof_hda_stream(hext_stream);
  60. sdev = hda_stream->sdev;
  61. chip = get_chip_info(sdev->pdata);
  62. /* check if link is available */
  63. if (!hext_stream->link_locked) {
  64. /*
  65. * choose the first available link for platforms that do not have the
  66. * PROCEN_FMT_QUIRK set.
  67. */
  68. if (!(chip->quirks & SOF_INTEL_PROCEN_FMT_QUIRK)) {
  69. res = hext_stream;
  70. break;
  71. }
  72. if (hstream->opened) {
  73. /*
  74. * check if the stream tag matches the stream
  75. * tag of one of the connected FEs
  76. */
  77. if (hda_check_fes(rtd, stream_dir,
  78. hstream->stream_tag)) {
  79. res = hext_stream;
  80. break;
  81. }
  82. } else {
  83. res = hext_stream;
  84. /*
  85. * This must be a hostless stream.
  86. * So reserve the host DMA channel.
  87. */
  88. hda_stream->host_reserved = 1;
  89. break;
  90. }
  91. }
  92. }
  93. if (res) {
  94. /* Make sure that host and link DMA is decoupled. */
  95. snd_hdac_ext_stream_decouple_locked(bus, res, true);
  96. res->link_locked = 1;
  97. res->link_substream = substream;
  98. }
  99. spin_unlock_irq(&bus->reg_lock);
  100. return res;
  101. }
  102. static struct hdac_ext_stream *hda_get_hext_stream(struct snd_sof_dev *sdev,
  103. struct snd_soc_dai *cpu_dai,
  104. struct snd_pcm_substream *substream)
  105. {
  106. return snd_soc_dai_get_dma_data(cpu_dai, substream);
  107. }
  108. static struct hdac_ext_stream *hda_ipc4_get_hext_stream(struct snd_sof_dev *sdev,
  109. struct snd_soc_dai *cpu_dai,
  110. struct snd_pcm_substream *substream)
  111. {
  112. struct snd_sof_widget *pipe_widget;
  113. struct sof_ipc4_pipeline *pipeline;
  114. struct snd_sof_widget *swidget;
  115. struct snd_soc_dapm_widget *w;
  116. w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
  117. swidget = w->dobj.private;
  118. pipe_widget = swidget->spipe->pipe_widget;
  119. pipeline = pipe_widget->private;
  120. /* mark pipeline so that it can be skipped during FE trigger */
  121. pipeline->skip_during_fe_trigger = true;
  122. return snd_soc_dai_get_dma_data(cpu_dai, substream);
  123. }
  124. static struct hdac_ext_stream *hda_assign_hext_stream(struct snd_sof_dev *sdev,
  125. struct snd_soc_dai *cpu_dai,
  126. struct snd_pcm_substream *substream)
  127. {
  128. struct hdac_ext_stream *hext_stream;
  129. hext_stream = hda_link_stream_assign(sof_to_bus(sdev), substream);
  130. if (!hext_stream)
  131. return NULL;
  132. snd_soc_dai_set_dma_data(cpu_dai, substream, (void *)hext_stream);
  133. return hext_stream;
  134. }
  135. static void hda_release_hext_stream(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
  136. struct snd_pcm_substream *substream)
  137. {
  138. struct hdac_ext_stream *hext_stream = hda_get_hext_stream(sdev, cpu_dai, substream);
  139. snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
  140. snd_hdac_ext_stream_release(hext_stream, HDAC_EXT_STREAM_TYPE_LINK);
  141. }
  142. static void hda_setup_hext_stream(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream,
  143. unsigned int format_val)
  144. {
  145. snd_hdac_ext_stream_setup(hext_stream, format_val);
  146. }
  147. static void hda_reset_hext_stream(struct snd_sof_dev *sdev, struct hdac_ext_stream *hext_stream)
  148. {
  149. snd_hdac_ext_stream_reset(hext_stream);
  150. }
  151. static void hda_codec_dai_set_stream(struct snd_sof_dev *sdev,
  152. struct snd_pcm_substream *substream,
  153. struct hdac_stream *hstream)
  154. {
  155. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  156. struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
  157. /* set the hdac_stream in the codec dai */
  158. snd_soc_dai_set_stream(codec_dai, hstream, substream->stream);
  159. }
  160. static unsigned int hda_calc_stream_format(struct snd_sof_dev *sdev,
  161. struct snd_pcm_substream *substream,
  162. struct snd_pcm_hw_params *params)
  163. {
  164. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  165. struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
  166. unsigned int link_bps;
  167. unsigned int format_val;
  168. unsigned int bits;
  169. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  170. link_bps = codec_dai->driver->playback.sig_bits;
  171. else
  172. link_bps = codec_dai->driver->capture.sig_bits;
  173. bits = snd_hdac_stream_format_bits(params_format(params), SNDRV_PCM_SUBFORMAT_STD,
  174. link_bps);
  175. format_val = snd_hdac_stream_format(params_channels(params), bits, params_rate(params));
  176. dev_dbg(sdev->dev, "format_val=%#x, rate=%d, ch=%d, format=%d\n", format_val,
  177. params_rate(params), params_channels(params), params_format(params));
  178. return format_val;
  179. }
  180. static struct hdac_ext_link *hda_get_hlink(struct snd_sof_dev *sdev,
  181. struct snd_pcm_substream *substream)
  182. {
  183. struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
  184. struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
  185. struct hdac_bus *bus = sof_to_bus(sdev);
  186. return snd_hdac_ext_bus_get_hlink_by_name(bus, codec_dai->component->name);
  187. }
  188. static unsigned int generic_calc_stream_format(struct snd_sof_dev *sdev,
  189. struct snd_pcm_substream *substream,
  190. struct snd_pcm_hw_params *params)
  191. {
  192. unsigned int format_val;
  193. unsigned int bits;
  194. bits = snd_hdac_stream_format_bits(params_format(params), SNDRV_PCM_SUBFORMAT_STD,
  195. params_physical_width(params));
  196. format_val = snd_hdac_stream_format(params_channels(params), bits, params_rate(params));
  197. dev_dbg(sdev->dev, "format_val=%#x, rate=%d, ch=%d, format=%d\n", format_val,
  198. params_rate(params), params_channels(params), params_format(params));
  199. return format_val;
  200. }
  201. static unsigned int dmic_calc_stream_format(struct snd_sof_dev *sdev,
  202. struct snd_pcm_substream *substream,
  203. struct snd_pcm_hw_params *params)
  204. {
  205. unsigned int format_val;
  206. snd_pcm_format_t format;
  207. unsigned int channels;
  208. unsigned int width;
  209. unsigned int bits;
  210. channels = params_channels(params);
  211. format = params_format(params);
  212. width = params_physical_width(params);
  213. if (format == SNDRV_PCM_FORMAT_S16_LE) {
  214. format = SNDRV_PCM_FORMAT_S32_LE;
  215. channels /= 2;
  216. width = 32;
  217. }
  218. bits = snd_hdac_stream_format_bits(format, SNDRV_PCM_SUBFORMAT_STD, width);
  219. format_val = snd_hdac_stream_format(channels, bits, params_rate(params));
  220. dev_dbg(sdev->dev, "format_val=%#x, rate=%d, ch=%d, format=%d\n", format_val,
  221. params_rate(params), channels, format);
  222. return format_val;
  223. }
  224. static struct hdac_ext_link *ssp_get_hlink(struct snd_sof_dev *sdev,
  225. struct snd_pcm_substream *substream)
  226. {
  227. struct hdac_bus *bus = sof_to_bus(sdev);
  228. return hdac_bus_eml_ssp_get_hlink(bus);
  229. }
  230. static struct hdac_ext_link *dmic_get_hlink(struct snd_sof_dev *sdev,
  231. struct snd_pcm_substream *substream)
  232. {
  233. struct hdac_bus *bus = sof_to_bus(sdev);
  234. return hdac_bus_eml_dmic_get_hlink(bus);
  235. }
  236. static struct hdac_ext_link *sdw_get_hlink(struct snd_sof_dev *sdev,
  237. struct snd_pcm_substream *substream)
  238. {
  239. struct hdac_bus *bus = sof_to_bus(sdev);
  240. return hdac_bus_eml_sdw_get_hlink(bus);
  241. }
  242. static int hda_ipc4_pre_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
  243. struct snd_pcm_substream *substream, int cmd)
  244. {
  245. struct sof_ipc4_fw_data *ipc4_data = sdev->private;
  246. struct snd_sof_widget *pipe_widget;
  247. struct sof_ipc4_pipeline *pipeline;
  248. struct snd_sof_widget *swidget;
  249. struct snd_soc_dapm_widget *w;
  250. int ret = 0;
  251. w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
  252. swidget = w->dobj.private;
  253. pipe_widget = swidget->spipe->pipe_widget;
  254. pipeline = pipe_widget->private;
  255. if (pipe_widget->instance_id < 0)
  256. return 0;
  257. mutex_lock(&ipc4_data->pipeline_state_mutex);
  258. switch (cmd) {
  259. case SNDRV_PCM_TRIGGER_START:
  260. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  261. break;
  262. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  263. case SNDRV_PCM_TRIGGER_SUSPEND:
  264. case SNDRV_PCM_TRIGGER_STOP:
  265. ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
  266. SOF_IPC4_PIPE_PAUSED);
  267. if (ret < 0)
  268. goto out;
  269. pipeline->state = SOF_IPC4_PIPE_PAUSED;
  270. break;
  271. default:
  272. dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
  273. ret = -EINVAL;
  274. }
  275. out:
  276. mutex_unlock(&ipc4_data->pipeline_state_mutex);
  277. return ret;
  278. }
  279. static int hda_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
  280. struct snd_pcm_substream *substream, int cmd)
  281. {
  282. struct hdac_ext_stream *hext_stream = snd_soc_dai_get_dma_data(cpu_dai, substream);
  283. switch (cmd) {
  284. case SNDRV_PCM_TRIGGER_START:
  285. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  286. snd_hdac_ext_stream_start(hext_stream);
  287. break;
  288. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  289. /*
  290. * Save the LLP registers since in case of PAUSE the LLP
  291. * register are not reset to 0, the delay calculation will use
  292. * the saved offsets for compensating the delay calculation.
  293. */
  294. hext_stream->pplcllpl = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPL);
  295. hext_stream->pplcllpu = readl(hext_stream->pplc_addr + AZX_REG_PPLCLLPU);
  296. snd_hdac_ext_stream_clear(hext_stream);
  297. break;
  298. case SNDRV_PCM_TRIGGER_SUSPEND:
  299. case SNDRV_PCM_TRIGGER_STOP:
  300. hext_stream->pplcllpl = 0;
  301. hext_stream->pplcllpu = 0;
  302. snd_hdac_ext_stream_clear(hext_stream);
  303. break;
  304. default:
  305. dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
  306. return -EINVAL;
  307. }
  308. return 0;
  309. }
  310. static int hda_ipc4_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
  311. struct snd_pcm_substream *substream, int cmd)
  312. {
  313. struct sof_ipc4_fw_data *ipc4_data = sdev->private;
  314. struct snd_sof_widget *pipe_widget;
  315. struct sof_ipc4_pipeline *pipeline;
  316. struct snd_sof_widget *swidget;
  317. struct snd_soc_dapm_widget *w;
  318. int ret = 0;
  319. w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
  320. swidget = w->dobj.private;
  321. pipe_widget = swidget->spipe->pipe_widget;
  322. pipeline = pipe_widget->private;
  323. if (pipe_widget->instance_id < 0)
  324. return 0;
  325. mutex_lock(&ipc4_data->pipeline_state_mutex);
  326. switch (cmd) {
  327. case SNDRV_PCM_TRIGGER_START:
  328. if (pipeline->state != SOF_IPC4_PIPE_PAUSED) {
  329. ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
  330. SOF_IPC4_PIPE_PAUSED);
  331. if (ret < 0)
  332. goto out;
  333. pipeline->state = SOF_IPC4_PIPE_PAUSED;
  334. }
  335. ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
  336. SOF_IPC4_PIPE_RUNNING);
  337. if (ret < 0)
  338. goto out;
  339. pipeline->state = SOF_IPC4_PIPE_RUNNING;
  340. swidget->spipe->started_count++;
  341. break;
  342. case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  343. ret = sof_ipc4_set_pipeline_state(sdev, pipe_widget->instance_id,
  344. SOF_IPC4_PIPE_RUNNING);
  345. if (ret < 0)
  346. goto out;
  347. pipeline->state = SOF_IPC4_PIPE_RUNNING;
  348. break;
  349. case SNDRV_PCM_TRIGGER_SUSPEND:
  350. case SNDRV_PCM_TRIGGER_STOP:
  351. /*
  352. * STOP/SUSPEND trigger is invoked only once when all users of this pipeline have
  353. * been stopped. So, clear the started_count so that the pipeline can be reset
  354. */
  355. swidget->spipe->started_count = 0;
  356. break;
  357. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  358. break;
  359. default:
  360. dev_err(sdev->dev, "unknown trigger command %d\n", cmd);
  361. ret = -EINVAL;
  362. break;
  363. }
  364. out:
  365. mutex_unlock(&ipc4_data->pipeline_state_mutex);
  366. return ret;
  367. }
  368. static const struct hda_dai_widget_dma_ops hda_ipc4_dma_ops = {
  369. .get_hext_stream = hda_ipc4_get_hext_stream,
  370. .assign_hext_stream = hda_assign_hext_stream,
  371. .release_hext_stream = hda_release_hext_stream,
  372. .setup_hext_stream = hda_setup_hext_stream,
  373. .reset_hext_stream = hda_reset_hext_stream,
  374. .pre_trigger = hda_ipc4_pre_trigger,
  375. .trigger = hda_trigger,
  376. .post_trigger = hda_ipc4_post_trigger,
  377. .codec_dai_set_stream = hda_codec_dai_set_stream,
  378. .calc_stream_format = hda_calc_stream_format,
  379. .get_hlink = hda_get_hlink,
  380. };
  381. static const struct hda_dai_widget_dma_ops ssp_ipc4_dma_ops = {
  382. .get_hext_stream = hda_ipc4_get_hext_stream,
  383. .assign_hext_stream = hda_assign_hext_stream,
  384. .release_hext_stream = hda_release_hext_stream,
  385. .setup_hext_stream = hda_setup_hext_stream,
  386. .reset_hext_stream = hda_reset_hext_stream,
  387. .pre_trigger = hda_ipc4_pre_trigger,
  388. .trigger = hda_trigger,
  389. .post_trigger = hda_ipc4_post_trigger,
  390. .calc_stream_format = generic_calc_stream_format,
  391. .get_hlink = ssp_get_hlink,
  392. };
  393. static const struct hda_dai_widget_dma_ops dmic_ipc4_dma_ops = {
  394. .get_hext_stream = hda_ipc4_get_hext_stream,
  395. .assign_hext_stream = hda_assign_hext_stream,
  396. .release_hext_stream = hda_release_hext_stream,
  397. .setup_hext_stream = hda_setup_hext_stream,
  398. .reset_hext_stream = hda_reset_hext_stream,
  399. .pre_trigger = hda_ipc4_pre_trigger,
  400. .trigger = hda_trigger,
  401. .post_trigger = hda_ipc4_post_trigger,
  402. .calc_stream_format = dmic_calc_stream_format,
  403. .get_hlink = dmic_get_hlink,
  404. };
  405. static const struct hda_dai_widget_dma_ops sdw_ipc4_dma_ops = {
  406. .get_hext_stream = hda_ipc4_get_hext_stream,
  407. .assign_hext_stream = hda_assign_hext_stream,
  408. .release_hext_stream = hda_release_hext_stream,
  409. .setup_hext_stream = hda_setup_hext_stream,
  410. .reset_hext_stream = hda_reset_hext_stream,
  411. .pre_trigger = hda_ipc4_pre_trigger,
  412. .trigger = hda_trigger,
  413. .post_trigger = hda_ipc4_post_trigger,
  414. .calc_stream_format = generic_calc_stream_format,
  415. .get_hlink = sdw_get_hlink,
  416. };
  417. static const struct hda_dai_widget_dma_ops hda_ipc4_chain_dma_ops = {
  418. .get_hext_stream = hda_get_hext_stream,
  419. .assign_hext_stream = hda_assign_hext_stream,
  420. .release_hext_stream = hda_release_hext_stream,
  421. .setup_hext_stream = hda_setup_hext_stream,
  422. .reset_hext_stream = hda_reset_hext_stream,
  423. .trigger = hda_trigger,
  424. .codec_dai_set_stream = hda_codec_dai_set_stream,
  425. .calc_stream_format = hda_calc_stream_format,
  426. .get_hlink = hda_get_hlink,
  427. };
  428. static const struct hda_dai_widget_dma_ops sdw_ipc4_chain_dma_ops = {
  429. .get_hext_stream = hda_get_hext_stream,
  430. .assign_hext_stream = hda_assign_hext_stream,
  431. .release_hext_stream = hda_release_hext_stream,
  432. .setup_hext_stream = hda_setup_hext_stream,
  433. .reset_hext_stream = hda_reset_hext_stream,
  434. .trigger = hda_trigger,
  435. .calc_stream_format = generic_calc_stream_format,
  436. .get_hlink = sdw_get_hlink,
  437. };
  438. static int hda_ipc3_post_trigger(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
  439. struct snd_pcm_substream *substream, int cmd)
  440. {
  441. struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
  442. switch (cmd) {
  443. case SNDRV_PCM_TRIGGER_SUSPEND:
  444. case SNDRV_PCM_TRIGGER_STOP:
  445. {
  446. struct snd_sof_dai_config_data data = { 0 };
  447. int ret;
  448. data.dai_data = DMA_CHAN_INVALID;
  449. ret = hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_HW_FREE, &data);
  450. if (ret < 0)
  451. return ret;
  452. break;
  453. }
  454. case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  455. return hda_dai_config(w, SOF_DAI_CONFIG_FLAGS_PAUSE, NULL);
  456. default:
  457. break;
  458. }
  459. return 0;
  460. }
  461. static const struct hda_dai_widget_dma_ops hda_ipc3_dma_ops = {
  462. .get_hext_stream = hda_get_hext_stream,
  463. .assign_hext_stream = hda_assign_hext_stream,
  464. .release_hext_stream = hda_release_hext_stream,
  465. .setup_hext_stream = hda_setup_hext_stream,
  466. .reset_hext_stream = hda_reset_hext_stream,
  467. .trigger = hda_trigger,
  468. .post_trigger = hda_ipc3_post_trigger,
  469. .codec_dai_set_stream = hda_codec_dai_set_stream,
  470. .calc_stream_format = hda_calc_stream_format,
  471. .get_hlink = hda_get_hlink,
  472. };
  473. static struct hdac_ext_stream *
  474. hda_dspless_get_hext_stream(struct snd_sof_dev *sdev, struct snd_soc_dai *cpu_dai,
  475. struct snd_pcm_substream *substream)
  476. {
  477. struct hdac_stream *hstream = substream->runtime->private_data;
  478. return stream_to_hdac_ext_stream(hstream);
  479. }
  480. static void hda_dspless_setup_hext_stream(struct snd_sof_dev *sdev,
  481. struct hdac_ext_stream *hext_stream,
  482. unsigned int format_val)
  483. {
  484. /*
  485. * Save the format_val which was adjusted by the maxbps of the codec.
  486. * This information is not available on the FE side since there we are
  487. * using dummy_codec.
  488. */
  489. hext_stream->hstream.format_val = format_val;
  490. }
  491. static const struct hda_dai_widget_dma_ops hda_dspless_dma_ops = {
  492. .get_hext_stream = hda_dspless_get_hext_stream,
  493. .setup_hext_stream = hda_dspless_setup_hext_stream,
  494. .codec_dai_set_stream = hda_codec_dai_set_stream,
  495. .calc_stream_format = hda_calc_stream_format,
  496. .get_hlink = hda_get_hlink,
  497. };
  498. static const struct hda_dai_widget_dma_ops sdw_dspless_dma_ops = {
  499. .get_hext_stream = hda_dspless_get_hext_stream,
  500. .setup_hext_stream = hda_dspless_setup_hext_stream,
  501. .calc_stream_format = generic_calc_stream_format,
  502. .get_hlink = sdw_get_hlink,
  503. };
  504. #endif
  505. const struct hda_dai_widget_dma_ops *
  506. hda_select_dai_widget_ops(struct snd_sof_dev *sdev, struct snd_sof_widget *swidget)
  507. {
  508. #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_LINK)
  509. struct snd_sof_dai *sdai;
  510. const struct sof_intel_dsp_desc *chip;
  511. chip = get_chip_info(sdev->pdata);
  512. sdai = swidget->private;
  513. if (sdev->dspless_mode_selected) {
  514. switch (sdai->type) {
  515. case SOF_DAI_INTEL_HDA:
  516. return &hda_dspless_dma_ops;
  517. case SOF_DAI_INTEL_ALH:
  518. if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
  519. return NULL;
  520. return &sdw_dspless_dma_ops;
  521. default:
  522. return NULL;
  523. }
  524. }
  525. switch (sdev->pdata->ipc_type) {
  526. case SOF_IPC_TYPE_3:
  527. {
  528. struct sof_dai_private_data *private = sdai->private;
  529. if (private->dai_config->type == SOF_DAI_INTEL_HDA)
  530. return &hda_ipc3_dma_ops;
  531. break;
  532. }
  533. case SOF_IPC_TYPE_4:
  534. {
  535. struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget;
  536. struct sof_ipc4_pipeline *pipeline = pipe_widget->private;
  537. switch (sdai->type) {
  538. case SOF_DAI_INTEL_HDA:
  539. if (pipeline->use_chain_dma)
  540. return &hda_ipc4_chain_dma_ops;
  541. return &hda_ipc4_dma_ops;
  542. case SOF_DAI_INTEL_SSP:
  543. if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
  544. return NULL;
  545. return &ssp_ipc4_dma_ops;
  546. case SOF_DAI_INTEL_DMIC:
  547. if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
  548. return NULL;
  549. return &dmic_ipc4_dma_ops;
  550. case SOF_DAI_INTEL_ALH:
  551. if (chip->hw_ip_version < SOF_INTEL_ACE_2_0)
  552. return NULL;
  553. if (pipeline->use_chain_dma)
  554. return &sdw_ipc4_chain_dma_ops;
  555. return &sdw_ipc4_dma_ops;
  556. default:
  557. break;
  558. }
  559. break;
  560. }
  561. default:
  562. break;
  563. }
  564. #endif
  565. return NULL;
  566. }