acp-pcm.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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) 2021 Advanced Micro Devices, Inc.
  7. //
  8. // Authors: Ajit Kumar Pandey <[email protected]>
  9. /*
  10. * PCM interface for generic AMD audio ACP DSP block
  11. */
  12. #include <sound/pcm_params.h>
  13. #include "../ops.h"
  14. #include "acp.h"
  15. #include "acp-dsp-offset.h"
  16. int acp_pcm_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
  17. struct snd_pcm_hw_params *params,
  18. struct snd_sof_platform_stream_params *platform_params)
  19. {
  20. struct snd_pcm_runtime *runtime = substream->runtime;
  21. struct acp_dsp_stream *stream = runtime->private_data;
  22. unsigned int buf_offset, index;
  23. u32 size;
  24. int ret;
  25. size = runtime->dma_bytes;
  26. stream->num_pages = PFN_UP(runtime->dma_bytes);
  27. stream->dmab = substream->runtime->dma_buffer_p;
  28. ret = acp_dsp_stream_config(sdev, stream);
  29. if (ret < 0) {
  30. dev_err(sdev->dev, "stream configuration failed\n");
  31. return ret;
  32. }
  33. platform_params->use_phy_address = true;
  34. platform_params->phy_addr = stream->reg_offset;
  35. platform_params->stream_tag = stream->stream_tag;
  36. /* write buffer size of stream in scratch memory */
  37. buf_offset = sdev->debug_box.offset +
  38. offsetof(struct scratch_reg_conf, buf_size);
  39. index = stream->stream_tag - 1;
  40. buf_offset = buf_offset + index * 4;
  41. snd_sof_dsp_write(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + buf_offset, size);
  42. return 0;
  43. }
  44. EXPORT_SYMBOL_NS(acp_pcm_hw_params, SND_SOC_SOF_AMD_COMMON);
  45. int acp_pcm_open(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream)
  46. {
  47. struct acp_dsp_stream *stream;
  48. stream = acp_dsp_stream_get(sdev, 0);
  49. if (!stream)
  50. return -ENODEV;
  51. substream->runtime->private_data = stream;
  52. stream->substream = substream;
  53. return 0;
  54. }
  55. EXPORT_SYMBOL_NS(acp_pcm_open, SND_SOC_SOF_AMD_COMMON);
  56. int acp_pcm_close(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream)
  57. {
  58. struct acp_dsp_stream *stream;
  59. stream = substream->runtime->private_data;
  60. if (!stream) {
  61. dev_err(sdev->dev, "No open stream\n");
  62. return -EINVAL;
  63. }
  64. stream->substream = NULL;
  65. substream->runtime->private_data = NULL;
  66. return acp_dsp_stream_put(sdev, stream);
  67. }
  68. EXPORT_SYMBOL_NS(acp_pcm_close, SND_SOC_SOF_AMD_COMMON);