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 8 #include <linux/module.h> 9 #include <linux/init.h> 10 #include <linux/platform_device.h> 11 #include <linux/slab.h> 12 #include <linux/dma-mapping.h> 13 #include <linux/amba/pl08x.h> 14 15 #include <sound/core.h> 16 #include <sound/pcm.h> 17 #include <sound/pcm_params.h> 18 #include <sound/dmaengine_pcm.h> 19 #include <sound/soc.h> 20 21 #include "lpc3xxx-i2s.h" 22 23 #define STUB_FORMATS (SNDRV_PCM_FMTBIT_S8 | \ 24 SNDRV_PCM_FMTBIT_U8 | \ 25 SNDRV_PCM_FMTBIT_S16_LE | \ 26 SNDRV_PCM_FMTBIT_U16_LE | \ 27 SNDRV_PCM_FMTBIT_S24_LE | \ 28 SNDRV_PCM_FMTBIT_U24_LE | \ 29 SNDRV_PCM_FMTBIT_S32_LE | \ 30 SNDRV_PCM_FMTBIT_U32_LE | \ 31 SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE) 32 33 static const struct snd_pcm_hardware lpc3xxx_pcm_hardware = { 34 .info = (SNDRV_PCM_INFO_MMAP | 35 SNDRV_PCM_INFO_MMAP_VALID | 36 SNDRV_PCM_INFO_INTERLEAVED | 37 SNDRV_PCM_INFO_BLOCK_TRANSFER | 38 SNDRV_PCM_INFO_PAUSE | 39 SNDRV_PCM_INFO_RESUME), 40 .formats = STUB_FORMATS, 41 .period_bytes_min = 128, 42 .period_bytes_max = 2048, 43 .periods_min = 2, 44 .periods_max = 1024, 45 .buffer_bytes_max = 128 * 1024 46 }; 47 48 static const struct snd_dmaengine_pcm_config lpc3xxx_dmaengine_pcm_config = { 49 .pcm_hardware = &lpc3xxx_pcm_hardware, 50 .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, 51 .compat_filter_fn = pl08x_filter_id, 52 .prealloc_buffer_size = 128 * 1024, 53 }; 54 55 const struct snd_soc_component_driver lpc3xxx_soc_platform_driver = { 56 .name = "lpc32xx-pcm", 57 }; 58 59 int lpc3xxx_pcm_register(struct platform_device *pdev) 60 { 61 int ret; 62 63 ret = devm_snd_dmaengine_pcm_register(&pdev->dev, &lpc3xxx_dmaengine_pcm_config, 0); 64 if (ret) { 65 dev_err(&pdev->dev, "failed to register dmaengine: %d\n", ret); 66 return ret; 67 } 68 69 return devm_snd_soc_register_component(&pdev->dev, &lpc3xxx_soc_platform_driver, 70 NULL, 0); 71 } 72 EXPORT_SYMBOL(lpc3xxx_pcm_register); 73