hda-trace.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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) 2018 Intel Corporation. All rights reserved.
  7. //
  8. // Authors: Liam Girdwood <[email protected]>
  9. // Ranjani Sridharan <[email protected]>
  10. // Rander Wang <[email protected]>
  11. // Keyon Jie <[email protected]>
  12. //
  13. /*
  14. * Hardware interface for generic Intel audio DSP HDA IP
  15. */
  16. #include <sound/hdaudio_ext.h>
  17. #include "../ops.h"
  18. #include "hda.h"
  19. static int hda_dsp_trace_prepare(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab)
  20. {
  21. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  22. struct hdac_ext_stream *hext_stream = hda->dtrace_stream;
  23. struct hdac_stream *hstream = &hext_stream->hstream;
  24. int ret;
  25. hstream->period_bytes = 0;/* initialize period_bytes */
  26. hstream->bufsize = dmab->bytes;
  27. ret = hda_dsp_stream_hw_params(sdev, hext_stream, dmab, NULL);
  28. if (ret < 0)
  29. dev_err(sdev->dev, "error: hdac prepare failed: %d\n", ret);
  30. return ret;
  31. }
  32. int hda_dsp_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
  33. struct sof_ipc_dma_trace_params_ext *dtrace_params)
  34. {
  35. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  36. int ret;
  37. hda->dtrace_stream = hda_dsp_stream_get(sdev, SNDRV_PCM_STREAM_CAPTURE,
  38. SOF_HDA_STREAM_DMI_L1_COMPATIBLE);
  39. if (!hda->dtrace_stream) {
  40. dev_err(sdev->dev,
  41. "error: no available capture stream for DMA trace\n");
  42. return -ENODEV;
  43. }
  44. dtrace_params->stream_tag = hda->dtrace_stream->hstream.stream_tag;
  45. /*
  46. * initialize capture stream, set BDL address and return corresponding
  47. * stream tag which will be sent to the firmware by IPC message.
  48. */
  49. ret = hda_dsp_trace_prepare(sdev, dmab);
  50. if (ret < 0) {
  51. dev_err(sdev->dev, "error: hdac trace init failed: %d\n", ret);
  52. hda_dsp_stream_put(sdev, SNDRV_PCM_STREAM_CAPTURE,
  53. dtrace_params->stream_tag);
  54. hda->dtrace_stream = NULL;
  55. dtrace_params->stream_tag = 0;
  56. }
  57. return ret;
  58. }
  59. int hda_dsp_trace_release(struct snd_sof_dev *sdev)
  60. {
  61. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  62. struct hdac_stream *hstream;
  63. if (hda->dtrace_stream) {
  64. hstream = &hda->dtrace_stream->hstream;
  65. hda_dsp_stream_put(sdev,
  66. SNDRV_PCM_STREAM_CAPTURE,
  67. hstream->stream_tag);
  68. hda->dtrace_stream = NULL;
  69. return 0;
  70. }
  71. dev_dbg(sdev->dev, "DMA trace stream is not opened!\n");
  72. return -ENODEV;
  73. }
  74. int hda_dsp_trace_trigger(struct snd_sof_dev *sdev, int cmd)
  75. {
  76. struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
  77. return hda_dsp_stream_trigger(sdev, hda->dtrace_stream, cmd);
  78. }