Skip to content

Commit

Permalink
ASoC: jz4740: Use the generic dmaengine PCM driver
Browse files Browse the repository at this point in the history
Now that there is a dmaengine driver for the jz4740 DMA core we can use the
generic dmaengine PCM driver. This allows us to remove the custom jz4740-pcm
code completely.

Signed-off-by: Lars-Peter Clausen <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
larsclausen authored and broonie committed Dec 3, 2013
1 parent b84c9ce commit 0406a40
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 411 deletions.
1 change: 1 addition & 0 deletions sound/soc/jz4740/Kconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
config SND_JZ4740_SOC
tristate "SoC Audio for Ingenic JZ4740 SoC"
depends on MACH_JZ4740 && SND_SOC
select SND_SOC_GENERIC_DMAENGINE_PCM
help
Say Y or M if you want to add support for codecs attached to
the JZ4740 I2S interface. You will also need to select the audio
Expand Down
54 changes: 22 additions & 32 deletions sound/soc/jz4740/jz4740-i2s.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <sound/dmaengine_pcm.h>

#include <asm/mach-jz4740/dma.h>

#include "jz4740-i2s.h"
#include "jz4740-pcm.h"

#define JZ_REG_AIC_CONF 0x00
#define JZ_REG_AIC_CTRL 0x04
Expand Down Expand Up @@ -89,8 +91,8 @@ struct jz4740_i2s {
struct clk *clk_aic;
struct clk *clk_i2s;

struct jz4740_pcm_config pcm_config_playback;
struct jz4740_pcm_config pcm_config_capture;
struct snd_dmaengine_dai_dma_data playback_dma_data;
struct snd_dmaengine_dai_dma_data capture_dma_data;
};

static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s,
Expand Down Expand Up @@ -233,8 +235,6 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{
struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
enum jz4740_dma_width dma_width;
struct jz4740_pcm_config *pcm_config;
unsigned int sample_size;
uint32_t ctrl;

Expand All @@ -243,11 +243,9 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
switch (params_format(params)) {
case SNDRV_PCM_FORMAT_S8:
sample_size = 0;
dma_width = JZ4740_DMA_WIDTH_8BIT;
break;
case SNDRV_PCM_FORMAT_S16:
sample_size = 1;
dma_width = JZ4740_DMA_WIDTH_16BIT;
break;
default:
return -EINVAL;
Expand All @@ -260,22 +258,13 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
ctrl |= JZ_AIC_CTRL_MONO_TO_STEREO;
else
ctrl &= ~JZ_AIC_CTRL_MONO_TO_STEREO;

pcm_config = &i2s->pcm_config_playback;
pcm_config->dma_config.dst_width = dma_width;

} else {
ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK;
ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET;

pcm_config = &i2s->pcm_config_capture;
pcm_config->dma_config.src_width = dma_width;
}

jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl);

snd_soc_dai_set_dma_data(dai, substream, pcm_config);

return 0;
}

Expand Down Expand Up @@ -342,25 +331,19 @@ static int jz4740_i2s_resume(struct snd_soc_dai *dai)

static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s)
{
struct jz4740_dma_config *dma_config;
struct snd_dmaengine_dai_dma_data *dma_data;

/* Playback */
dma_config = &i2s->pcm_config_playback.dma_config;
dma_config->src_width = JZ4740_DMA_WIDTH_32BIT;
dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT;
dma_config->flags = JZ4740_DMA_SRC_AUTOINC;
dma_config->mode = JZ4740_DMA_MODE_SINGLE;
i2s->pcm_config_playback.fifo_addr = i2s->phys_base + JZ_REG_AIC_FIFO;
dma_data = &i2s->playback_dma_data;
dma_data->maxburst = 16;
dma_data->slave_id = JZ4740_DMA_TYPE_AIC_TRANSMIT;
dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;

/* Capture */
dma_config = &i2s->pcm_config_capture.dma_config;
dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT;
dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE;
dma_config->flags = JZ4740_DMA_DST_AUTOINC;
dma_config->mode = JZ4740_DMA_MODE_SINGLE;
i2s->pcm_config_capture.fifo_addr = i2s->phys_base + JZ_REG_AIC_FIFO;
dma_data = &i2s->capture_dma_data;
dma_data->maxburst = 16;
dma_data->slave_id = JZ4740_DMA_TYPE_AIC_RECEIVE;
dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
}

static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai)
Expand All @@ -371,6 +354,8 @@ static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai)
clk_prepare_enable(i2s->clk_aic);

jz4740_i2c_init_pcm_config(i2s);
snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data,
&i2s->capture_dma_data);

conf = (7 << JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
(8 << JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
Expand Down Expand Up @@ -456,8 +441,13 @@ static int jz4740_i2s_dev_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, i2s);

return devm_snd_soc_register_component(&pdev->dev,
ret = devm_snd_soc_register_component(&pdev->dev,
&jz4740_i2s_component, &jz4740_i2s_dai, 1);
if (ret)
return ret;

return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL,
SND_DMAENGINE_PCM_FLAG_COMPAT);
}

static struct platform_driver jz4740_i2s_driver = {
Expand Down
Loading

0 comments on commit 0406a40

Please sign in to comment.