lpc3xxx-pcm.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. //
  3. // Author: Kevin Wells <kevin.wells@nxp.com>
  4. //
  5. // Copyright (C) 2008 NXP Semiconductors
  6. // Copyright 2023 Timesys Corporation <piotr.wojtaszczyk@timesys.com>
  7. #include <linux/module.h>
  8. #include <linux/init.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/slab.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/amba/pl08x.h>
  13. #include <sound/core.h>
  14. #include <sound/pcm.h>
  15. #include <sound/pcm_params.h>
  16. #include <sound/dmaengine_pcm.h>
  17. #include <sound/soc.h>
  18. #include "lpc3xxx-i2s.h"
  19. #define STUB_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
  20. SNDRV_PCM_FMTBIT_U8 | \
  21. SNDRV_PCM_FMTBIT_S16_LE | \
  22. SNDRV_PCM_FMTBIT_U16_LE | \
  23. SNDRV_PCM_FMTBIT_S24_LE | \
  24. SNDRV_PCM_FMTBIT_U24_LE | \
  25. SNDRV_PCM_FMTBIT_S32_LE | \
  26. SNDRV_PCM_FMTBIT_U32_LE | \
  27. SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
  28. static const struct snd_pcm_hardware lpc3xxx_pcm_hardware = {
  29. .info = (SNDRV_PCM_INFO_MMAP |
  30. SNDRV_PCM_INFO_MMAP_VALID |
  31. SNDRV_PCM_INFO_INTERLEAVED |
  32. SNDRV_PCM_INFO_BLOCK_TRANSFER |
  33. SNDRV_PCM_INFO_PAUSE |
  34. SNDRV_PCM_INFO_RESUME),
  35. .formats = STUB_FORMATS,
  36. .period_bytes_min = 128,
  37. .period_bytes_max = 2048,
  38. .periods_min = 2,
  39. .periods_max = 1024,
  40. .buffer_bytes_max = 128 * 1024
  41. };
  42. static const struct snd_dmaengine_pcm_config lpc3xxx_dmaengine_pcm_config = {
  43. .pcm_hardware = &lpc3xxx_pcm_hardware,
  44. .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  45. .compat_filter_fn = pl08x_filter_id,
  46. .prealloc_buffer_size = 128 * 1024,
  47. };
  48. static const struct snd_soc_component_driver lpc3xxx_soc_platform_driver = {
  49. .name = "lpc32xx-pcm",
  50. };
  51. int lpc3xxx_pcm_register(struct platform_device *pdev)
  52. {
  53. int ret;
  54. ret = devm_snd_dmaengine_pcm_register(&pdev->dev, &lpc3xxx_dmaengine_pcm_config, 0);
  55. if (ret) {
  56. dev_err(&pdev->dev, "failed to register dmaengine: %d\n", ret);
  57. return ret;
  58. }
  59. return devm_snd_soc_register_component(&pdev->dev, &lpc3xxx_soc_platform_driver,
  60. NULL, 0);
  61. }
  62. EXPORT_SYMBOL(lpc3xxx_pcm_register);