Commit 0959de65 authored by Piotr Wojtaszczyk's avatar Piotr Wojtaszczyk Committed by Mark Brown

ASoC: fsl: Add i2s and pcm drivers for LPC32xx CPUs

This driver was ported from an old version in linux 2.6.27 and adjusted
for the new ASoC framework and DMA API.
Signed-off-by: default avatarPiotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>
Link: https://patch.msgid.link/20240627150046.258795-12-piotr.wojtaszczyk@timesys.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 752fea92
......@@ -8917,6 +8917,7 @@ L: alsa-devel@alsa-project.org (moderated for non-subscribers)
L: linuxppc-dev@lists.ozlabs.org
S: Maintained
F: Documentation/devicetree/bindings/sound/nxp,lpc3220-i2s.yaml
F: sound/soc/fsl/lpc3xxx-*
FREESCALE SOC SOUND QMC DRIVER
M: Herve Codina <herve.codina@bootlin.com>
......
......@@ -131,6 +131,13 @@ config SND_SOC_FSL_RPMSG
This option is only useful for out-of-tree drivers since
in-tree drivers select it automatically.
config SND_SOC_FSL_LPC3XXX
tristate "SoC Audio for NXP LPC32XX CPUs"
depends on ARCH_LPC32XX || COMPILE_TEST
select SND_SOC_GENERIC_DMAENGINE_PCM
help
Say Y or M if you want to add support for the LPC3XXX I2S interface.
config SND_SOC_IMX_PCM_DMA
tristate
select SND_SOC_GENERIC_DMAENGINE_PCM
......
......@@ -11,6 +11,7 @@ obj-$(CONFIG_SND_SOC_P1022_RDK) += snd-soc-p1022-rdk.o
snd-soc-fsl-audmix-y := fsl_audmix.o
snd-soc-fsl-asoc-card-y := fsl-asoc-card.o
snd-soc-fsl-asrc-y := fsl_asrc.o fsl_asrc_dma.o
snd-soc-fsl-lpc3xxx-y := lpc3xxx-pcm.o lpc3xxx-i2s.o
snd-soc-fsl-sai-y := fsl_sai.o
snd-soc-fsl-ssi-y := fsl_ssi.o
snd-soc-fsl-ssi-$(CONFIG_DEBUG_FS) += fsl_ssi_dbg.o
......@@ -29,6 +30,7 @@ snd-soc-fsl-qmc-audio-y := fsl_qmc_audio.o
obj-$(CONFIG_SND_SOC_FSL_AUDMIX) += snd-soc-fsl-audmix.o
obj-$(CONFIG_SND_SOC_FSL_ASOC_CARD) += snd-soc-fsl-asoc-card.o
obj-$(CONFIG_SND_SOC_FSL_ASRC) += snd-soc-fsl-asrc.o
obj-$(CONFIG_SND_SOC_FSL_LPC3XXX) += snd-soc-fsl-lpc3xxx.o
obj-$(CONFIG_SND_SOC_FSL_SAI) += snd-soc-fsl-sai.o
obj-$(CONFIG_SND_SOC_FSL_SSI) += snd-soc-fsl-ssi.o
obj-$(CONFIG_SND_SOC_FSL_SPDIF) += snd-soc-fsl-spdif.o
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Author: Kevin Wells <kevin.wells@nxp.com>
*
* Copyright (C) 2008 NXP Semiconductors
* Copyright 2023 Timesys Corporation <piotr.wojtaszczyk@timesys.com>
*/
#ifndef __SOUND_SOC_LPC3XXX_I2S_H
#define __SOUND_SOC_LPC3XXX_I2S_H
#include <linux/types.h>
#include <linux/regmap.h>
struct lpc3xxx_i2s_info {
struct device *dev;
struct clk *clk;
struct mutex lock; /* To serialize user-space access */
struct regmap *regs;
u32 streams_in_use;
u32 clkrate;
int freq;
struct snd_dmaengine_dai_dma_data playback_dma_config;
struct snd_dmaengine_dai_dma_data capture_dma_config;
};
int lpc3xxx_pcm_register(struct platform_device *pdev);
/* I2S controller register offsets */
#define LPC3XXX_REG_I2S_DAO 0x00
#define LPC3XXX_REG_I2S_DAI 0x04
#define LPC3XXX_REG_I2S_TX_FIFO 0x08
#define LPC3XXX_REG_I2S_RX_FIFO 0x0C
#define LPC3XXX_REG_I2S_STAT 0x10
#define LPC3XXX_REG_I2S_DMA0 0x14
#define LPC3XXX_REG_I2S_DMA1 0x18
#define LPC3XXX_REG_I2S_IRQ 0x1C
#define LPC3XXX_REG_I2S_TX_RATE 0x20
#define LPC3XXX_REG_I2S_RX_RATE 0x24
/* i2s_daO i2s_dai register definitions */
#define LPC3XXX_I2S_WW8 FIELD_PREP(0x3, 0) /* Word width is 8bit */
#define LPC3XXX_I2S_WW16 FIELD_PREP(0x3, 1) /* Word width is 16bit */
#define LPC3XXX_I2S_WW32 FIELD_PREP(0x3, 3) /* Word width is 32bit */
#define LPC3XXX_I2S_MONO BIT(2) /* Mono */
#define LPC3XXX_I2S_STOP BIT(3) /* Stop, diables the access to FIFO, mutes the channel */
#define LPC3XXX_I2S_RESET BIT(4) /* Reset the channel */
#define LPC3XXX_I2S_WS_SEL BIT(5) /* Channel Master(0) or slave(1) mode select */
#define LPC3XXX_I2S_WS_HP(s) FIELD_PREP(0x7FC0, s) /* Word select half period - 1 */
#define LPC3XXX_I2S_MUTE BIT(15) /* Mute the channel, Transmit channel only */
#define LPC3XXX_I2S_WW32_HP 0x1f /* Word select half period for 32bit word width */
#define LPC3XXX_I2S_WW16_HP 0x0f /* Word select half period for 16bit word width */
#define LPC3XXX_I2S_WW8_HP 0x7 /* Word select half period for 8bit word width */
/* i2s_stat register definitions */
#define LPC3XXX_I2S_IRQ_STAT BIT(0)
#define LPC3XXX_I2S_DMA0_REQ BIT(1)
#define LPC3XXX_I2S_DMA1_REQ BIT(2)
/* i2s_dma0 Configuration register definitions */
#define LPC3XXX_I2S_DMA0_RX_EN BIT(0) /* Enable RX DMA1 */
#define LPC3XXX_I2S_DMA0_TX_EN BIT(1) /* Enable TX DMA1 */
#define LPC3XXX_I2S_DMA0_RX_DEPTH(s) FIELD_PREP(0xF00, s) /* Set the DMA1 RX Request level */
#define LPC3XXX_I2S_DMA0_TX_DEPTH(s) FIELD_PREP(0xF0000, s) /* Set the DMA1 TX Request level */
/* i2s_dma1 Configuration register definitions */
#define LPC3XXX_I2S_DMA1_RX_EN BIT(0) /* Enable RX DMA1 */
#define LPC3XXX_I2S_DMA1_TX_EN BIT(1) /* Enable TX DMA1 */
#define LPC3XXX_I2S_DMA1_RX_DEPTH(s) FIELD_PREP(0x700, s) /* Set the DMA1 RX Request level */
#define LPC3XXX_I2S_DMA1_TX_DEPTH(s) FIELD_PREP(0x70000, s) /* Set the DMA1 TX Request level */
/* i2s_irq register definitions */
#define LPC3XXX_I2S_RX_IRQ_EN BIT(0) /* Enable RX IRQ */
#define LPC3XXX_I2S_TX_IRQ_EN BIT(1) /* Enable TX IRQ */
#define LPC3XXX_I2S_IRQ_RX_DEPTH(s) FIELD_PREP(0xFF00, s) /* valid values ar 0 to 7 */
#define LPC3XXX_I2S_IRQ_TX_DEPTH(s) FIELD_PREP(0xFF0000, s) /* valid values ar 0 to 7 */
#endif
// SPDX-License-Identifier: GPL-2.0-or-later
//
// Author: Kevin Wells <kevin.wells@nxp.com>
//
// Copyright (C) 2008 NXP Semiconductors
// Copyright 2023 Timesys Corporation <piotr.wojtaszczyk@timesys.com>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/dma-mapping.h>
#include <linux/amba/pl08x.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/dmaengine_pcm.h>
#include <sound/soc.h>
#include "lpc3xxx-i2s.h"
#define STUB_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
SNDRV_PCM_FMTBIT_U8 | \
SNDRV_PCM_FMTBIT_S16_LE | \
SNDRV_PCM_FMTBIT_U16_LE | \
SNDRV_PCM_FMTBIT_S24_LE | \
SNDRV_PCM_FMTBIT_U24_LE | \
SNDRV_PCM_FMTBIT_S32_LE | \
SNDRV_PCM_FMTBIT_U32_LE | \
SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE)
static const struct snd_pcm_hardware lpc3xxx_pcm_hardware = {
.info = (SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER |
SNDRV_PCM_INFO_PAUSE |
SNDRV_PCM_INFO_RESUME),
.formats = STUB_FORMATS,
.period_bytes_min = 128,
.period_bytes_max = 2048,
.periods_min = 2,
.periods_max = 1024,
.buffer_bytes_max = 128 * 1024
};
static const struct snd_dmaengine_pcm_config lpc3xxx_dmaengine_pcm_config = {
.pcm_hardware = &lpc3xxx_pcm_hardware,
.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
.compat_filter_fn = pl08x_filter_id,
.prealloc_buffer_size = 128 * 1024,
};
const struct snd_soc_component_driver lpc3xxx_soc_platform_driver = {
.name = "lpc32xx-pcm",
};
int lpc3xxx_pcm_register(struct platform_device *pdev)
{
int ret;
ret = devm_snd_dmaengine_pcm_register(&pdev->dev, &lpc3xxx_dmaengine_pcm_config, 0);
if (ret) {
dev_err(&pdev->dev, "failed to register dmaengine: %d\n", ret);
return ret;
}
return devm_snd_soc_register_component(&pdev->dev, &lpc3xxx_soc_platform_driver,
NULL, 0);
}
EXPORT_SYMBOL(lpc3xxx_pcm_register);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment