Skip to contentSkip to conversation

ASoC: add CSR SiRFSoC sound drivers

PATCH Superseded RongJun Ying 4 participants 15 messages Jan 3, 2014 – Jan 8, 2014

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover ASoC: add CSR SiRFSoC sound drivers

From: Rongjun Ying <[email protected]>

This patchset adds CSR SiRFSoC sound drivers including:
1. the platform DMA driver which will be shard by all DAI
2. the I2S CPU DAI driver
3. the USP-based PCM CPU DAI driver
4. CPU DAI and Codec driver for internal chip codec
5. the mach driver for EVB board using internal codec

-v3:
1. Use devm_* API for driver
2. Remove the extcon stuff code
3. Calculated automatically the div vaule at runtime based on the sample rate
4. Automatically discovering the configuration of pcm hardware from the dmaengine driver
5. Add binding documents

Rongjun Ying (5):
ASoC: sirf: add sirf platform driver which provides DMA
ASoC: sirf: add I2S CPU DAI driver
ASoC: usp-pcm: add CPU DAI driver for PCM simulated from USP
ASoC: sirf-soc-inner: add drivers for both CPU and Codec DAIs
ASoC: sirf-inner: add mach driver for SiRFSoC internal codec

 .../bindings/sound/sirf,inner-audio-codec.txt      |   41 ++
 sound/soc/Kconfig                                  |    1 +
 sound/soc/Makefile                                 |    1 +
 sound/soc/sirf/Kconfig                             |   18 +
 sound/soc/sirf/Makefile                            |   11 +
 sound/soc/sirf/sirf-audio.h                        |  268 ++++++++
 sound/soc/sirf/sirf-i2s.c                          |  435 +++++++++++++
 sound/soc/sirf/sirf-inner.c                        |  155 +++++
 sound/soc/sirf/sirf-pcm.c                          |   68 ++
 sound/soc/sirf/sirf-soc-inner.c                    |  653 ++++++++++++++++++++
 sound/soc/sirf/sirf-usp.c                          |  463 ++++++++++++++
 sound/soc/sirf/sirf-usp.h                          |  276 +++++++++
 12 files changed, 2390 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/sirf,inner-audio-codec.txt
 create mode 100644 sound/soc/sirf/Kconfig
 create mode 100644 sound/soc/sirf/Makefile
 create mode 100644 sound/soc/sirf/sirf-audio.h
 create mode 100644 sound/soc/sirf/sirf-i2s.c
 create mode 100644 sound/soc/sirf/sirf-inner.c
 create mode 100644 sound/soc/sirf/sirf-pcm.c
 create mode 100644 sound/soc/sirf/sirf-soc-inner.c
 create mode 100644 sound/soc/sirf/sirf-usp.c
 create mode 100644 sound/soc/sirf/sirf-usp.h
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH v3 1/5 ASoC: sirf: add sirf platform driver which provides DMA

From: Rongjun Ying <[email protected]>

this driver uses dmaengine APIs and provides DMA to the CPU DAIs of I2S, USP and SiRF-soc-inner.
SiRFSoC has 3 audio DAIs: I2S, USP(Universal Serial Ports) and DAI connected to soc-inner-codec, all of them will use the same DMA driver here.

---
-v3:
Automatically discovering the configuration of pcm hardware from the dmaengine driver

 sound/soc/Kconfig         |    1 +
 sound/soc/Makefile        |    1 +
 sound/soc/sirf/Kconfig    |    4 ++
 sound/soc/sirf/Makefile   |    3 ++
 sound/soc/sirf/sirf-pcm.c |   68 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/sirf/Kconfig
 create mode 100644 sound/soc/sirf/Makefile
 create mode 100644 sound/soc/sirf/sirf-pcm.c
sound/soc/Kconfig +1 -0
index d62ce48..0060b31 100644
@@ -50,6 +50,7 @@ source "sound/soc/pxa/Kconfig"
 source "sound/soc/samsung/Kconfig"
 source "sound/soc/s6000/Kconfig"
 source "sound/soc/sh/Kconfig"
+source "sound/soc/sirf/Kconfig"
 source "sound/soc/spear/Kconfig"
 source "sound/soc/tegra/Kconfig"
 source "sound/soc/txx9/Kconfig"
sound/soc/Makefile +1 -0
index 62a1822..5f1df02 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_SND_SOC)	+= pxa/
 obj-$(CONFIG_SND_SOC)	+= samsung/
 obj-$(CONFIG_SND_SOC)	+= s6000/
 obj-$(CONFIG_SND_SOC)	+= sh/
+obj-$(CONFIG_SND_SOC)	+= sirf/
 obj-$(CONFIG_SND_SOC)	+= spear/
 obj-$(CONFIG_SND_SOC)	+= tegra/
 obj-$(CONFIG_SND_SOC)	+= txx9/
sound/soc/sirf/Kconfig new file +4 -0
new file mode 100644
index 0000000..1637089
@@ -0,0 +1,4 @@
+config SND_SIRF_SOC
+	tristate "Platform DMA driver for the SiRF SoC chips"
+	depends on ARCH_SIRF && SND_SOC
+	select SND_SOC_GENERIC_DMAENGINE_PCM
sound/soc/sirf/Makefile new file +3 -0
new file mode 100644
index 0000000..f268b83
@@ -0,0 +1,3 @@
+snd-soc-sirf-objs := sirf-pcm.o
+
+obj-$(CONFIG_SND_SIRF_SOC) += snd-soc-sirf.o
sound/soc/sirf/sirf-pcm.c new file +68 -0

68 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#2 lore raw

Re: [PATCH v3 1/5] ASoC: sirf: add sirf platform driver which provides DMA

Quoted 100 lines · RongJun Ying

From: Rongjun Ying <[email protected]>

this driver uses dmaengine APIs and provides DMA to the CPU DAIs of I2S, USP and SiRF-soc-inner.
SiRFSoC has 3 audio DAIs: I2S, USP(Universal Serial Ports) and DAI connected to soc-inner-codec, all of them will use the same DMA driver here.

---
-v3:
Automatically discovering the configuration of pcm hardware from the dmaengine driver

 sound/soc/Kconfig         |    1 +
 sound/soc/Makefile        |    1 +
 sound/soc/sirf/Kconfig    |    4 ++
 sound/soc/sirf/Makefile   |    3 ++
 sound/soc/sirf/sirf-pcm.c |   68 +++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/sirf/Kconfig
 create mode 100644 sound/soc/sirf/Makefile
 create mode 100644 sound/soc/sirf/sirf-pcm.c
sound/soc/Kconfig +1 -0
index d62ce48..0060b31 100644
@@ -50,6 +50,7 @@ source "sound/soc/pxa/Kconfig"
 source "sound/soc/samsung/Kconfig"
 source "sound/soc/s6000/Kconfig"
 source "sound/soc/sh/Kconfig"
+source "sound/soc/sirf/Kconfig"
 source "sound/soc/spear/Kconfig"
 source "sound/soc/tegra/Kconfig"
 source "sound/soc/txx9/Kconfig"
sound/soc/Makefile +1 -0
index 62a1822..5f1df02 100644
@@ -27,6 +27,7 @@ obj-$(CONFIG_SND_SOC)	+= pxa/
 obj-$(CONFIG_SND_SOC)	+= samsung/
 obj-$(CONFIG_SND_SOC)	+= s6000/
 obj-$(CONFIG_SND_SOC)	+= sh/
+obj-$(CONFIG_SND_SOC)	+= sirf/
 obj-$(CONFIG_SND_SOC)	+= spear/
 obj-$(CONFIG_SND_SOC)	+= tegra/
 obj-$(CONFIG_SND_SOC)	+= txx9/
sound/soc/sirf/Kconfig new file +4 -0
new file mode 100644
index 0000000..1637089
@@ -0,0 +1,4 @@
+config SND_SIRF_SOC
+	tristate "Platform DMA driver for the SiRF SoC chips"
+	depends on ARCH_SIRF && SND_SOC
+	select SND_SOC_GENERIC_DMAENGINE_PCM
sound/soc/sirf/Makefile new file +3 -0
new file mode 100644
index 0000000..f268b83
@@ -0,0 +1,3 @@
+snd-soc-sirf-objs := sirf-pcm.o
+
+obj-$(CONFIG_SND_SIRF_SOC) += snd-soc-sirf.o
sound/soc/sirf/sirf-pcm.c new file +27 -0
new file mode 100644
index 0000000..e4cb3a6
@@ -0,0 +1,68 @@
+/*
+ * ALSA PCM interface for the SiRF SoC
+ *
+ * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
+ *
+ * Licensed under GPLv2 or later.
+ */
+
+#include <linux/module.h>
+#include <sound/dmaengine_pcm.h>
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+static struct dma_chan *sirf_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
+	struct snd_pcm_substream *substream)
+{
+	struct snd_dmaengine_dai_dma_data *dma_data;
+
+	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+
+	return dma_request_slave_channel(rtd->cpu_dai->dev,
+			dma_data->chan_name);
+}
+
+static const struct snd_dmaengine_pcm_config sirf_dmaengine_pcm_config = {

sound/soc/sirf/sirf-pcm.c line 37

Quoted 10 lines
sound/soc/sirf/sirf-pcm.c new file +10 -0
+	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
+	.compat_request_channel = sirf_pcm_request_chan,
+};
+
+static int sirf_pcm_probe(struct platform_device *pdev)
+{
+	return devm_snd_dmaengine_pcm_register(&pdev->dev,
+		&sirf_dmaengine_pcm_config,
+		SND_DMAENGINE_PCM_FLAG_NO_DT |
+		SND_DMAENGINE_PCM_FLAG_COMPAT);

Since your platform is using DT you should drop the NO_DT and COMPAT flags. Your sirf_pcm_request_chan is essentially doing the same as what the DT path in the generic driver does.

sound/soc/sirf/sirf-pcm.c line 46

Quoted 9 lines
sound/soc/sirf/sirf-pcm.c new file +9 -0
+}
+
+static struct platform_driver sirf_pcm_driver = {
+	.driver = {
+		.name = "sirf-pcm-audio",
+		.owner = THIS_MODULE,
+	},
+	.probe = sirf_pcm_probe,
+};

Also I wouldn't bother to register a extra device for the PCM, just call devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0) from the DAI drivers, that's what everybody else is doing.

- Lars

maintainer
#3 lore raw

Re: [PATCH v3 1/5] ASoC: sirf: add sirf platform driver which provides DMA

In reply to RongJun Ying

sound/soc/sirf/Kconfig line 4

Quoted 8 lines · RongJun Ying

index 0000000..1637089

sound/soc/sirf/Kconfig new file +4 -0
@@ -0,0 +1,4 @@
+config SND_SIRF_SOC
+	tristate "Platform DMA driver for the SiRF SoC chips"
+	depends on ARCH_SIRF && SND_SOC
+	select SND_SOC_GENERIC_DMAENGINE_PCM

No need for the SND_SOC dependency, the subdirectories are only enumerated if it is selected, and looking at the code I don't see a build time dependency on ARCH_SIRF so it should be ARCH_SIRF || COMPILE_TEST.

Quoted 4 lines
sound/soc/sirf/Kconfig new file +4 -0
+static struct dma_chan *sirf_pcm_request_chan(struct snd_soc_pcm_runtime *rtd,
+	struct snd_pcm_substream *substream)
+{
+	struct snd_dmaengine_dai_dma_data *dma_data;

sound/soc/sirf/Kconfig

Quoted 10 lines
sound/soc/sirf/Kconfig new file +10 -0
+
+	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+
+	return dma_request_slave_channel(rtd->cpu_dai->dev,
+			dma_data->chan_name);
+}
+
+static const struct snd_dmaengine_pcm_config sirf_dmaengine_pcm_config = {
+	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
+	.compat_request_channel = sirf_pcm_request_chan,

Do you need the compat_request_chan - I'd expect a newish ARM system to be DT only and the code doesn't look like it's doing anything that the core couldn't handle?

sound/soc/sirf/Kconfig

Quoted 7 lines
sound/soc/sirf/Kconfig new file +7 -0
+static struct platform_driver sirf_pcm_driver = {
+	.driver = {
+		.name = "sirf-pcm-audio",
+		.owner = THIS_MODULE,
+	},
+	.probe = sirf_pcm_probe,
+};

This doesn't look to ever access any hardware directly so it probably shouldn't be a standalone driver as Lars-Peter says.

sound/soc/sirf/Kconfig

Quoted 9 lines
sound/soc/sirf/Kconfig new file +9 -0
+static int __init sirf_pcm_init(void)
+{
+	int ret = 0;
+
+	ret = platform_driver_register(&sirf_pcm_driver);
+	if (ret)
+		pr_err("failed to register platform driver\n");
+	return ret;
+}

module_platform_driver() if there is some real hardware here.

#4 lore raw

Re: [PATCH v3 1/5] ASoC: sirf: add sirf platform driver which provides DMA

Quoted 58 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Tuesday, January 07, 2014 1:07 AM
To: RongJun Ying
Cc: Liam Girdwood; Jaroslav Kysela; Takashi Iwai; alsa-devel@alsa- project.org; DL-SHA-WorkGroupLinux; Rongjun Ying
Subject: Re: [PATCH v3 1/5] ASoC: sirf: add sirf platform driver which provides DMA

sound/soc/sirf/Kconfig line 4

Quoted 8 lines · RongJun Ying

index 0000000..1637089

sound/soc/sirf/Kconfig new file +4 -0
@@ -0,0 +1,4 @@
+config SND_SIRF_SOC
+	tristate "Platform DMA driver for the SiRF SoC chips"
+	depends on ARCH_SIRF && SND_SOC
+	select SND_SOC_GENERIC_DMAENGINE_PCM

No need for the SND_SOC dependency, the subdirectories are only enumerated if it is selected, and looking at the code I don't see a build time dependency on ARCH_SIRF so it should be ARCH_SIRF || COMPILE_TEST.

Quoted 1 line

+static struct dma_chan *sirf_pcm_request_chan(struct

snd_soc_pcm_runtime *rtd,

sound/soc/sirf/Kconfig

Quoted 10 lines
sound/soc/sirf/Kconfig new file +10 -0
+	struct snd_pcm_substream *substream) {
+	struct snd_dmaengine_dai_dma_data *dma_data;
+
+	dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+
+	return dma_request_slave_channel(rtd->cpu_dai->dev,
+			dma_data->chan_name);
+}
+
+static const struct snd_dmaengine_pcm_config

sirf_dmaengine_pcm_config = {

sound/soc/sirf/Kconfig

Quoted 2 lines
sound/soc/sirf/Kconfig new file +2 -0
+	.prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
+	.compat_request_channel = sirf_pcm_request_chan,

Do you need the compat_request_chan - I'd expect a newish ARM system to be DT only and the code doesn't look like it's doing anything that the core couldn't handle?

sound/soc/sirf/Kconfig

Quoted 7 lines
sound/soc/sirf/Kconfig new file +7 -0
+static struct platform_driver sirf_pcm_driver = {
+	.driver = {
+		.name = "sirf-pcm-audio",
+		.owner = THIS_MODULE,
+	},
+	.probe = sirf_pcm_probe,
+};

This doesn't look to ever access any hardware directly so it probably shouldn't be a standalone driver as Lars-Peter says.

Quoted 10 lines

sound/soc/sirf/Kconfig

Quoted 8 lines
sound/soc/sirf/Kconfig new file +8 -0
+static int __init sirf_pcm_init(void) {
+	int ret = 0;
+
+	ret = platform_driver_register(&sirf_pcm_driver);
+	if (ret)
+		pr_err("failed to register platform driver\n");
+	return ret;
+}

module_platform_driver() if there is some real hardware here.

Do you mean to add pcm device into dts?

pcm {
compatible = "sirf,pcm-audio";
}

-------------------
BR
RongJun Ying

Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc. New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.

maintainer
#5 lore raw

Re: [PATCH v3 1/5] ASoC: sirf: add sirf platform driver which provides DMA

Quoted 7 lines · Rongjun Ying
Quoted 1 line

module_platform_driver() if there is some real hardware here.

Do you mean to add pcm device into dts?

pcm {
   compatible = "sirf,pcm-audio";
}

Only if this is an actual dedicated hardware block which as myself and Lars said doesn't seem to be the case.

#6 lore raw

PATCH v3 2/5 ASoC: sirf: add I2S CPU DAI driver

In reply to RongJun Ying

From: Rongjun Ying <[email protected]>

This patch adds I2S DAI driver for SiRFprima2 and SiRFatlas6. The hardware supports:
I2S bus specification compliant (Released by Philips Semiconductors in June, 1996) Supports I2S master and I2S slave mode
Provides MCLK to I2S CODEC in I2S master mode
Supports 16-bit resolution playback
Supports 16-bit resolution record
Supports 2 channel record
Supports 2 channel and 6 channel mode playback
Frame length, left channel length and right channel length are all programmable Supports two DMA channels for TXFIFO and RXFIFO
Supports floating mode (x_ac97_dout can be configured as input)

headfile sound/soc/sirf/sirf-audio.h will be shard by all I2S and soc-inner DAIs.

---
-v3:
Calculated automatically the div vaule at runtime based on the sample rate Move the master/slave mode setting from set_fmt to hw_parames

 sound/soc/sirf/Kconfig      |    3 +
 sound/soc/sirf/Makefile     |    2 +
 sound/soc/sirf/sirf-audio.h |  268 ++++++++++++++++++++++++++
 sound/soc/sirf/sirf-i2s.c   |  435 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 708 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/sirf/sirf-audio.h
 create mode 100644 sound/soc/sirf/sirf-i2s.c
sound/soc/sirf/Kconfig +3 -0
index 1637089..5064cfc 100644
@@ -2,3 +2,6 @@ config SND_SIRF_SOC
 	tristate "Platform DMA driver for the SiRF SoC chips"
 	depends on ARCH_SIRF && SND_SOC
 	select SND_SOC_GENERIC_DMAENGINE_PCM
+
+config SND_SOC_SIRF_I2S
+	tristate
sound/soc/sirf/Makefile +2 -0
index f268b83..9f754fe 100644
@@ -1,3 +1,5 @@
 snd-soc-sirf-objs := sirf-pcm.o
+snd-soc-sirf-i2s-objs := sirf-i2s.o
 
 obj-$(CONFIG_SND_SIRF_SOC) += snd-soc-sirf.o
+obj-$(CONFIG_SND_SOC_SIRF_I2S) += snd-soc-sirf-i2s.o
sound/soc/sirf/sirf-audio.h new file +268 -0

268 lines not on this page · raw message

sound/soc/sirf/sirf-i2s.c new file +435 -0

435 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#7 lore raw

Re: [PATCH v3 2/5] ASoC: sirf: add I2S CPU DAI driver

sound/soc/sirf/sirf-audio.h line 4

Quoted 10 lines · RongJun Ying
sound/soc/sirf/sirf-audio.h new file +4 -0
new file mode 100644
index 0000000..b6fdf06
@@ -0,0 +1,268 @@
+#ifndef _SIRF_INNER_AUDIO_CTRL_H
+#define _SIRF_INNER_AUDIO_CTRL_H
+
+#define AUDIO_CTRL_TX_FIFO_LEVEL_CHECK_MASK     0x3F

[...]

Adding a prefix like SIRF_ to all those defines wouldn't hurt.

Quoted 33 lines
sound/soc/sirf/sirf-audio.h new file +4 -0
+
+#define SIRF_I2S_EXT_CLK	0x0
+#define SIRF_I2S_PWM_CLK	0x1
+#endif /*__SIRF_INNER_AUDIO_CTRL_H*/
sound/soc/sirf/sirf-i2s.c new file +23 -0
new file mode 100644
index 0000000..d8b8732
@@ -0,0 +1,435 @@
+/*
+ * SiRF I2S driver
+ *
+ * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
+ *
+ * Licensed under GPLv2 or later.
+ */
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/pm_runtime.h>
+#include <linux/clk.h>
+
+#include <sound/soc.h>
+#include <sound/pcm_params.h>
+#include <sound/dmaengine_pcm.h>
+
+#include "sirf-audio.h"
+
+struct sirf_i2s {
+	void __iomem		*base;
+	struct clk		*clk;

sound/soc/sirf/sirf-i2s.c line 33

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	u32			i2s_ctrl;
+	u32			i2s_ctrl_tx_rx_en;
+	spinlock_t		lock;
+	struct platform_device	*sirf_pcm_pdev;
+	bool			master;
+	int			ext_clk;
+	int			src_clk_rate;
+};
+
+static struct snd_dmaengine_dai_dma_data dma_data[2];

This can be removed since you only use it to specify the channel names. But since you use the default names there is no need to do that.

Quoted 9 lines
sound/soc/sirf/sirf-i2s.c new file +9 -0
+
+static int sirf_i2s_dai_probe(struct snd_soc_dai *dai)
+{
+	dai->playback_dma_data = &dma_data[0];
+	dai->capture_dma_data = &dma_data[1];
+	return 0;
+}
+
+static int sirf_i2s_trigger(struct snd_pcm_substream *substream,

sound/soc/sirf/sirf-i2s.c line 52

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+		int cmd, struct snd_soc_dai *dai)
+{
+	struct sirf_i2s *si2s = snd_soc_dai_get_drvdata(dai);
+	int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		spin_lock(&si2s->lock);

This is the only place where you use the spinlock. The trigger callback is already protected by the ALSA core and can not race against itself, so you do not need the lock.

sound/soc/sirf/sirf-i2s.c line 63

Quoted 11 lines
sound/soc/sirf/sirf-i2s.c new file +11 -0
+
+		if (playback) {
+			/* First start the FIFO, then enable the tx/rx */
+			writel(AUDIO_FIFO_RESET,
+				si2s->base + AUDIO_CTRL_EXT_TXFIFO1_OP);
+			writel(AUDIO_FIFO_START,
+				si2s->base + AUDIO_CTRL_EXT_TXFIFO1_OP);
+
+			writel(readl(si2s->base+AUDIO_CTRL_I2S_TX_RX_EN)
+				| I2S_TX_ENABLE | I2S_DOUT_OE,
+				si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);

For better legibility this should probably be split into multiple statements, like

	val = read()
	val |= ...
	write(val);

sound/soc/sirf/sirf-i2s.c line 74

Quoted 11 lines
sound/soc/sirf/sirf-i2s.c new file +11 -0
+
+		} else {
+			/* First start the FIFO, then enable the tx/rx */
+			writel(AUDIO_FIFO_RESET,
+				si2s->base + AUDIO_CTRL_RXFIFO_OP);
+			writel(AUDIO_FIFO_START,
+				si2s->base + AUDIO_CTRL_RXFIFO_OP);
+
+			writel(readl(si2s->base+AUDIO_CTRL_I2S_TX_RX_EN)
+				| I2S_RX_ENABLE,
+				si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);

Same here

sound/soc/sirf/sirf-i2s.c line 87

Quoted 13 lines
sound/soc/sirf/sirf-i2s.c new file +13 -0
+		}
+
+		spin_unlock(&si2s->lock);
+		break;
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		spin_lock(&si2s->lock);
+
+		if (playback) {
+			writel(readl(si2s->base + AUDIO_CTRL_I2S_TX_RX_EN)
+				& ~(I2S_TX_ENABLE),
+				si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);

and here

sound/soc/sirf/sirf-i2s.c line 94

Quoted 7 lines
sound/soc/sirf/sirf-i2s.c new file +7 -0
+			/* First disable the tx/rx, then stop the FIFO */
+			writel(0, si2s->base + AUDIO_CTRL_EXT_TXFIFO1_OP);
+		} else {
+			writel(readl(si2s->base + AUDIO_CTRL_I2S_TX_RX_EN)
+				& ~(I2S_RX_ENABLE),
+				si2s->base+AUDIO_CTRL_I2S_TX_RX_EN);
+

and here

Quoted 29 lines
sound/soc/sirf/sirf-i2s.c new file +29 -0
+			/* First disable the tx/rx, then stop the FIFO */
+			writel(0, si2s->base + AUDIO_CTRL_RXFIFO_OP);
+		}
+
+		spin_unlock(&si2s->lock);
+		break;
+	default:
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static int sirf_i2s_hw_params(struct snd_pcm_substream *substream,
+		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+	struct sirf_i2s *si2s = snd_soc_dai_get_drvdata(dai);
+	u32 i2s_ctrl = readl(si2s->base + AUDIO_CTRL_I2S_CTRL);
+	u32 i2s_tx_rx_ctrl = readl(si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);
+	u32 left_len, frame_len;
+	int channels = params_channels(params);
+	u32 bitclk;
+	u32 bclk_div;
+	u32 div;
+
+	/*
+	 * SiRFSoC I2S controller only support 2 and 6 channells output.
+	 * I2S_SIX_CHANNELS bit clear: select 2 channels mode.
+	 * I2S_SIX_CHANNELS bit set: select 6 channels mode.
+	 */

sound/soc/sirf/sirf-i2s.c line 133

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	switch (channels) {
+	case 2:
+		i2s_ctrl &= ~I2S_SIX_CHANNELS;
+		break;
+	case 6:
+		i2s_ctrl |= I2S_SIX_CHANNELS;
+		break;
+	default:
+		dev_err(dai->dev, "%d channels unsupported\n", channels);
+		return -EINVAL;

Since you only support 2 and 6 for the number of channels you should add a constraint to that in your hwparams callback. Otherwise userspace will think you support any number of channels between 2 and 6. You can do this using this snippet:

static unsigned int sirf_i2s_channels[] = {2, 6};
static struct snd_pcm_hw_constraint_list sirf_i2s_channel_constraints = {
.count = ARRAY_SIZE(sirf_i2s_channels),
.list = sirf_i2s_channels,
};

snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &sirf_i2s_channel_constraints);

Quoted 15 lines
sound/soc/sirf/sirf-i2s.c new file +15 -0
+	}
+
+	switch (params_format(params)) {
+	case SNDRV_PCM_FORMAT_S8:
+		left_len = 8;
+		break;
+	case SNDRV_PCM_FORMAT_S16_LE:
+		left_len = 16;
+		break;
+	case SNDRV_PCM_FORMAT_S24_LE:
+		left_len = 24;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		left_len = 32;
+		break;

sound/soc/sirf/sirf-i2s.c line 158

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	default:
+		dev_err(dai->dev, "Format unsupported\n");
+		return -EINVAL;
+	}
+
+	frame_len = left_len * 2;
+	i2s_ctrl &= ~(I2S_L_CHAN_LEN_MASK | I2S_FRAME_LEN_MASK);
+	/* Fill the actual len - 1 */
+	i2s_ctrl |= ((frame_len - 1) << 9) | ((left_len - 1) << 4)
+		| (0 << 15) | (3 << 24);

You set the bclk_div to 3 here

sound/soc/sirf/sirf-i2s.c line 168

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+
+	if (si2s->master) {
+		i2s_ctrl &= ~I2S_SLAVE_MODE;
+		i2s_tx_rx_ctrl |= I2S_MCLK_EN;
+		bitclk = params_rate(params) * frame_len;
+		div = si2s->src_clk_rate / bitclk;
+		/* MCLK divide-by-2 from source clk */
+		div /= 2;
+		bclk_div = div / 2 - 1;
+		i2s_ctrl |= (bclk_div << 24);

and never clear it before setting it here again, this will probably not work.

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+		/*
+		 * MCLK coefficient must set to 0, means
+		 * divide-by-two from reference clock.
+		 */
+		i2s_ctrl &= ~(((1 << 10) - 1) << 15);
+	} else {
+		i2s_ctrl |= I2S_SLAVE_MODE;
+		i2s_tx_rx_ctrl &= ~I2S_MCLK_EN;
+	}
+

sound/soc/sirf/sirf-i2s.c line 188

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	if (si2s->ext_clk)
+		i2s_tx_rx_ctrl |= I2S_REF_CLK_SEL_EXT;
+	else
+		i2s_tx_rx_ctrl &= ~I2S_REF_CLK_SEL_EXT;
+
+	writel(i2s_ctrl, si2s->base + AUDIO_CTRL_I2S_CTRL);
+	writel(i2s_tx_rx_ctrl, si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);
+	writel(readl(si2s->base + AUDIO_CTRL_MODE_SEL)
+			| I2S_MODE,
+			si2s->base + AUDIO_CTRL_MODE_SEL);

again, break this into multiple statements.

sound/soc/sirf/sirf-i2s.c line 230

Quoted 6 lines
sound/soc/sirf/sirf-i2s.c new file +6 -0
+
+	return 0;
+}
+
+
+static int sirf_i2s_set_clkdiv(struct snd_soc_dai *dai, int div_id, int src_rate)

I think this should be set_sysclk not set_clkdiv.

Quoted 9 lines
sound/soc/sirf/sirf-i2s.c new file +9 -0
+{
+	struct sirf_i2s *si2s = snd_soc_dai_get_drvdata(dai);
+
+	switch (div_id) {
+	case SIRF_I2S_EXT_CLK:
+		si2s->ext_clk = 1;
+		break;
+	case SIRF_I2S_PWM_CLK:
+		si2s->ext_clk = 0;

sound/soc/sirf/sirf-i2s.c line 249

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	si2s->src_clk_rate = src_rate;
+	return 0;
+}
+
+struct snd_soc_dai_ops sirfsoc_i2s_dai_ops = {

static const

Quoted 6 lines
sound/soc/sirf/sirf-i2s.c new file +6 -0
+	.trigger	= sirf_i2s_trigger,
+	.hw_params	= sirf_i2s_hw_params,
+	.set_fmt	= sirf_i2s_set_dai_fmt,
+	.set_clkdiv	= sirf_i2s_set_clkdiv,
+};
+

[...]

sound/soc/sirf/sirf-i2s.c line 311

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+#ifdef CONFIG_PM_SLEEP
+static int sirf_i2s_suspend(struct device *dev)
+{
+	struct sirf_i2s *si2s = dev_get_drvdata(dev);
+
+	if (!pm_runtime_status_suspended(dev)) {
+		si2s->i2s_ctrl = readl(si2s->base + AUDIO_CTRL_I2S_CTRL);
+		si2s->i2s_ctrl_tx_rx_en =
+			readl(si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);
+		sirf_i2s_runtime_suspend(dev);

This will yield a compile error if CONFIG_PM_SLEEP is set, but CONFIG_PM_RUNTIME is not set

sound/soc/sirf/sirf-i2s.c line 321

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	}
+	return 0;
+}
+
+static int sirf_i2s_resume(struct device *dev)
+{
+	struct sirf_i2s *si2s = dev_get_drvdata(dev);
+	int ret;
+	if (!pm_runtime_status_suspended(dev)) {
+		ret = sirf_i2s_runtime_resume(dev);

Same here

Quoted 20 lines
sound/soc/sirf/sirf-i2s.c new file +20 -0
+		if (ret)
+			return ret;
+		writel(readl(si2s->base + AUDIO_CTRL_MODE_SEL)
+				| I2S_MODE,
+				si2s->base + AUDIO_CTRL_MODE_SEL);
+		writel(si2s->i2s_ctrl, si2s->base + AUDIO_CTRL_I2S_CTRL);
+		/*Restore MCLK enable and reference clock select bits.*/
+		writel(si2s->i2s_ctrl_tx_rx_en &
+			(I2S_MCLK_EN | I2S_REF_CLK_SEL_EXT),
+			si2s->base + AUDIO_CTRL_I2S_TX_RX_EN);
+
+		writel(0, si2s->base + AUDIO_CTRL_EXT_TXFIFO1_INT_MSK);
+		writel(0, si2s->base + AUDIO_CTRL_RXFIFO_INT_MSK);
+	}
+
+	return 0;
+}
+#endif
+
+static const struct snd_soc_component_driver sirf_i2s_component = {

sound/soc/sirf/sirf-i2s.c line 351

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	.name       = "sirf-i2s",
+};
+
+static int sirf_i2s_probe(struct platform_device *pdev)
+{
+	struct sirf_i2s *si2s;
+	int ret;
+	struct resource mem_res;
+
+	si2s = devm_kzalloc(&pdev->dev, sizeof(struct sirf_i2s),

sizeof(*si2s) is prefered by the coding style guidelines

Quoted 13 lines
sound/soc/sirf/sirf-i2s.c new file +13 -0
+			GFP_KERNEL);
+	if (!si2s)
+		return -ENOMEM;
+
+	si2s->sirf_pcm_pdev = platform_device_register_simple("sirf-pcm-audio",
+			0, NULL, 0);
+	if (IS_ERR(si2s->sirf_pcm_pdev))
+		return PTR_ERR(si2s->sirf_pcm_pdev);
+
+	platform_set_drvdata(pdev, si2s);
+
+	spin_lock_init(&si2s->lock);
+

sound/soc/sirf/sirf-i2s.c line 374

Quoted 10 lines
sound/soc/sirf/sirf-i2s.c new file +10 -0
+	dma_data[0].chan_name = "tx";
+	dma_data[1].chan_name = "rx";
+
+	ret = of_address_to_resource(pdev->dev.of_node, 0, &mem_res);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable to get i2s memory resource.\n");
+		return ret;
+	}
+	si2s->base = devm_ioremap(&pdev->dev, mem_res.start,
+		resource_size(&mem_res));

I think using devm_ioremap_resource() is better here. It will first request the region before remapping it.

Quoted 24 lines
sound/soc/sirf/sirf-i2s.c new file +24 -0
+	if (!si2s->base)
+		return -ENOMEM;
+
+	si2s->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(si2s->clk)) {
+		dev_err(&pdev->dev, "Get clock failed.\n");
+		ret = PTR_ERR(si2s->clk);
+		goto err;
+	}
+
+	pm_runtime_enable(&pdev->dev);
+
+	ret = devm_snd_soc_register_component(&pdev->dev, &sirf_i2s_component,
+			&sirf_i2s_dai, 1);
+	if (ret) {
+		dev_err(&pdev->dev, "Register Audio SoC dai failed.\n");
+		goto err;
+	}
+
+	return 0;
+
+err:
+	return ret;
+}

[...]

sound/soc/sirf/sirf-i2s.c line 413

Quoted 6 lines
sound/soc/sirf/sirf-i2s.c new file +6 -0
+
+static const struct of_device_id sirf_i2s_of_match[] = {
+	{ .compatible = "sirf,prima2-i2s", },
+	{}
+};
+MODULE_DEVICE_TABLE(of, sirf_i2s_of_match);

Binding documentation is missing.

maintainer
#8 lore raw

Re: [PATCH v3 2/5] ASoC: sirf: add I2S CPU DAI driver

In reply to RongJun Ying

sound/soc/sirf/sirf-i2s.c line 40

Quoted 6 lines · RongJun Ying
sound/soc/sirf/sirf-i2s.c new file +6 -0
+static int sirf_i2s_dai_probe(struct snd_soc_dai *dai)
+{
+	dai->playback_dma_data = &dma_data[0];
+	dai->capture_dma_data = &dma_data[1];
+	return 0;
+}

Call snd_soc_dai_init_dma_data() rather than assigning directly.

sound/soc/sirf/sirf-i2s.c line 282

Quoted 4 lines
sound/soc/sirf/sirf-i2s.c new file +4 -0
+	},
+	.ops = &sirfsoc_i2s_dai_ops,
+};
+#ifdef CONFIG_PM_RUNTIME

Blank line after the struct please.

sound/soc/sirf/sirf-i2s.c line 328

Quoted 2 lines
sound/soc/sirf/sirf-i2s.c new file +2 -0
+		writel(si2s->i2s_ctrl, si2s->base + AUDIO_CTRL_I2S_CTRL);
+		/*Restore MCLK enable and reference clock select bits.*/

/* text */

sound/soc/sirf/sirf-i2s.c line 359

Quoted 4 lines
sound/soc/sirf/sirf-i2s.c new file +4 -0
+	si2s->sirf_pcm_pdev = platform_device_register_simple("sirf-pcm-audio",
+			0, NULL, 0);
+	if (IS_ERR(si2s->sirf_pcm_pdev))
+		return PTR_ERR(si2s->sirf_pcm_pdev);

This should just be a call to register the DMA directly rather than create a device to do it.

sound/soc/sirf/sirf-i2s.c line 372

Quoted 5 lines
sound/soc/sirf/sirf-i2s.c new file +5 -0
+	ret = of_address_to_resource(pdev->dev.of_node, 0, &mem_res);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Unable to get i2s memory resource.\n");
+		return ret;
+	}

It is more normal to use platform_get_resource(), it works fine with OF resources and is more idiomatic than using the OF specific stuff.

#9 lore raw

PATCH v3 3/5 ASoC: usp-pcm: add CPU DAI driver for PCM simulated from USP

In reply to RongJun Ying

From: Rongjun Ying <[email protected]>

Universal Serial Ports (USP) can be used as PCM. this patch adds support for this functionality.

The USP provides 128-byte data FIFO which supports DMA and I/O modes. Here we use the common DMA driver.

---
-v3:
Use the generic dma dt-binding to get playback/capture dma channels Calculated automatically the div vaule at runtime based on the sample rate Move the master/slave mode setting from set_fmt to hw_parames Check the return value
Remove the pm_runtime_get_sync and pm_runtime_put invoke

 sound/soc/sirf/Kconfig    |    3 +
 sound/soc/sirf/Makefile   |    2 +
 sound/soc/sirf/sirf-usp.c |  463 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/sirf/sirf-usp.h |  276 +++++++++++++++++++++++++++
 4 files changed, 744 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/sirf/sirf-usp.c
 create mode 100644 sound/soc/sirf/sirf-usp.h
sound/soc/sirf/Kconfig +3 -0
index 5064cfc..5e395d3 100644
@@ -5,3 +5,6 @@ config SND_SIRF_SOC
 
 config SND_SOC_SIRF_I2S
 	tristate
+
+config SND_SOC_SIRF_USP
+	tristate
sound/soc/sirf/Makefile +2 -0
index 9f754fe..630c9be 100644
@@ -1,5 +1,7 @@
 snd-soc-sirf-objs := sirf-pcm.o
 snd-soc-sirf-i2s-objs := sirf-i2s.o
+snd-soc-sirf-usp-objs := sirf-usp.o
 
 obj-$(CONFIG_SND_SIRF_SOC) += snd-soc-sirf.o
 obj-$(CONFIG_SND_SOC_SIRF_I2S) += snd-soc-sirf-i2s.o
+obj-$(CONFIG_SND_SOC_SIRF_USP) += snd-soc-sirf-usp.o
sound/soc/sirf/sirf-usp.c new file +463 -0

463 lines not on this page · raw message

sound/soc/sirf/sirf-usp.h new file +276 -0

276 lines not on this page · raw message

Signature · 1 line
1.7.5.4
maintainer
#10 lore raw

Re: [PATCH v3 3/5] ASoC: usp-pcm: add CPU DAI driver for PCM simulated from USP

Quoted 5 lines · RongJun Ying
sound/soc/sirf/sirf-usp.c new file +5 -0
+static void sirf_usp_tx_fifo_op(struct sirf_usp *susp, int cmd)
+{
+	switch (cmd) {
+	case FIFO_RESET:
+		writel(USP_TX_FIFO_RESET, susp->base + USP_TX_FIFO_OP);

sound/soc/sirf/sirf-usp.c line 49

Quoted 10 lines
sound/soc/sirf/sirf-usp.c new file +10 -0
+		writel(0, susp->base + USP_TX_FIFO_OP);
+		break;
+	case FIFO_START:
+		writel(USP_TX_FIFO_START, susp->base + USP_TX_FIFO_OP);
+		break;
+	case FIFO_STOP:
+		writel(0, susp->base + USP_TX_FIFO_OP);
+		break;
+	}
+}

I'm not sure these functions and the switch statements in them are adding anything - none of the statements share any code. Either refactor this so that the callers pass in USP_TX_FIFO_blah for the argument or just inline the register operations.

sound/soc/sirf/sirf-usp.c line 71

Quoted 5 lines
sound/soc/sirf/sirf-usp.c new file +5 -0
+static inline void sirf_usp_tx_enable(struct sirf_usp *susp)
+{
+	writel(readl(susp->base + USP_TX_RX_ENABLE) | USP_TX_ENA,
+			susp->base + USP_TX_RX_ENABLE);
+}

Similar thing here, just inline.

sound/soc/sirf/sirf-usp.c line 94

Quoted 4 lines
sound/soc/sirf/sirf-usp.c new file +4 -0
+static int sirf_usp_pcm_dai_probe(struct snd_soc_dai *dai)
+{
+	dai->playback_dma_data = &dma_data[0];
+	dai->capture_dma_data = &dma_data[1];

snd_soc_dai_init_dma_data().

#11 lore raw

PATCH v3 4/5 ASoC: sirf-soc-inner: add drivers for both CPU and Codec DAIs

In reply to RongJun Ying

From: Rongjun Ying <[email protected]>

there is an internal codec embedded in the SiRF SoC. this is not a typical user scenerios of ASoC. but we can still get benefit by sharing platform DMA codes instead of implementing a pure ALSA driver.
This driver adds DAI drivers for this internal codec.

The features of Internal Codec Controller include:
Support two channel 16-bit resolution playback with fix 48KHz sample rate Support two channel 16-bit resolution record with fix 48KHz sample rate Use dedicated Internal Codec TXFIFO and Internal Codec RXFIFO Supports two DMA channels for Internal Codec TXFIFO and Internal Codec RXFIFO

---
-v3:
Remove the pm_runtime_get_sync and pm_runtime_put invoke
Use the generic dma dt-binding to get playback/capture dma channels Check the return value
Use devm_snd_soc_register_component instead of snd_soc_register_component for inner, usp-pcm and i2s platform interface

 sound/soc/sirf/Kconfig          |    3 +
 sound/soc/sirf/Makefile         |    2 +
 sound/soc/sirf/sirf-soc-inner.c |  653 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 658 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/sirf/sirf-soc-inner.c
sound/soc/sirf/Kconfig +3 -0
index 5e395d3..afa3952 100644
@@ -6,5 +6,8 @@ config SND_SIRF_SOC
 config SND_SOC_SIRF_I2S
 	tristate
 
+config SND_SIRF_SOC_INNER
+	tristate
+
 config SND_SOC_SIRF_USP
 	tristate
sound/soc/sirf/Makefile +2 -0
index 630c9be..8517c67 100644
@@ -1,7 +1,9 @@
 snd-soc-sirf-objs := sirf-pcm.o
+snd-soc-sirf-soc-inner-objs := sirf-soc-inner.o
 snd-soc-sirf-i2s-objs := sirf-i2s.o
 snd-soc-sirf-usp-objs := sirf-usp.o
 
 obj-$(CONFIG_SND_SIRF_SOC) += snd-soc-sirf.o
+obj-$(CONFIG_SND_SIRF_SOC_INNER) += snd-soc-sirf-soc-inner.o
 obj-$(CONFIG_SND_SOC_SIRF_I2S) += snd-soc-sirf-i2s.o
 obj-$(CONFIG_SND_SOC_SIRF_USP) += snd-soc-sirf-usp.o
sound/soc/sirf/sirf-soc-inner.c new file +653 -0

653 lines not on this page · raw message

Signature · 1 line
1.7.5.4
maintainer
#12 lore raw

Re: [PATCH v3 4/5] ASoC: sirf-soc-inner: add drivers for both CPU and Codec DAIs

sound/soc/sirf/Kconfig config SND_SIRF_SOC · line 12

Quoted 8 lines · RongJun Ying
sound/soc/sirf/Kconfig +3 -0
@@ -6,5 +6,8 @@ config SND_SIRF_SOC
 config SND_SOC_SIRF_I2S
 	tristate
 
+config SND_SIRF_SOC_INNER
+	tristate
+
 config SND_SOC_SIRF_USP

Everything else is SND_SOC_SIRF_, please keep this consistent.

sound/soc/sirf/sirf-soc-inner.c line 54

Quoted 7 lines
sound/soc/sirf/sirf-soc-inner.c new file +6 -0
+static struct sirf_soc_inner_audio_reg_bits sirf_soc_inner_audio_reg_bits_prima2 = {
+	20, 21, 22, 23, 24, 25, 26, 27,
+};
 
+static struct sirf_soc_inner_audio_reg_bits sirf_soc_inner_audio_reg_bits_atlas6 = {
+	22, 23, 24, 25, 26, 27, 28, 29,
+};

Please used named initialisers to set these values rather than just a list of numbers, this isn't very easy to read.

sound/soc/sirf/sirf-soc-inner.c line 63

Quoted 2 lines
sound/soc/sirf/sirf-soc-inner.c new file +2 -0
+static const struct snd_kcontrol_new sirf_inner_input_mode_control =
+	SOC_DAPM_ENUM("Route", sirf_inner_enum[0]);

Either use constants to reference the array or (better) use named variables for each enum. This is more readable and less error prone.

sound/soc/sirf/sirf-soc-inner.c line 69

Quoted 5 lines
sound/soc/sirf/sirf-soc-inner.c new file +5 -0
+static struct snd_kcontrol_new volume_controls_atlas6[] = {
+	SOC_DOUBLE("Playback Volume", AUDIO_IC_CODEC_CTRL0, 21, 14,
+			0x7F, 0),
+	SOC_DOUBLE("Capture Volume", AUDIO_IC_CODEC_CTRL1, 16, 10,
+			0x3F, 0),

Please provide TLV information.

sound/soc/sirf/sirf-soc-inner.c line 80

Quoted 2 lines
sound/soc/sirf/sirf-soc-inner.c new file +2 -0
+static struct snd_kcontrol_new left_input_path_controls[] = {
+	SOC_DAPM_SINGLE("Line left Switch", AUDIO_IC_CODEC_CTRL1, 6, 1, 0),

Line Left Switch.

sound/soc/sirf/sirf-soc-inner.c line 125

Quoted 12 lines
sound/soc/sirf/sirf-soc-inner.c new file +12 -0
+	switch (event) {
+	case SND_SOC_DAPM_PRE_PMU:
+		/* Enable capture power of codec*/
+		val = sirfsoc_rtc_iobrg_readl(sinner_audio->sys_pwrc_reg_base +
+			PWRC_PDN_CTRL_OFFSET);
+		val |= (1 << AUDIO_POWER_EN_BIT);
+		sirfsoc_rtc_iobrg_writel(val,
+			sinner_audio->sys_pwrc_reg_base + PWRC_PDN_CTRL_OFFSET);
+		break;
+	case SND_SOC_DAPM_POST_PMU:
+		/*After enable adc, Delay 200ms to avoid pop noise*/
+		msleep(200);

No need to split these operations, just have one callback. Why is there no power down callback?

Quoted 9 lines
sound/soc/sirf/sirf-soc-inner.c new file +9 -0
+static int hp_amp_left_event(struct snd_soc_dapm_widget *w,
+		struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_codec *codec = w->codec;
+	struct sirf_soc_inner_audio *sinner_audio = dev_get_drvdata(codec->dev);
+	u32 val;
+
+	val = snd_soc_read(codec, AUDIO_IC_CODEC_CTRL1);
+	switch (event) {

sound/soc/sirf/sirf-soc-inner.c line 151

Quoted 10 lines
sound/soc/sirf/sirf-soc-inner.c new file +10 -0
+	case SND_SOC_DAPM_PRE_PMU:
+		val |= (1 << sinner_audio->reg_bits->firdac_hsl_en_bits);
+		break;
+	case SND_SOC_DAPM_POST_PMD:
+		val &= ~(1 << sinner_audio->reg_bits->firdac_hsl_en_bits);
+	default:
+		break;
+	}
+	snd_soc_write(codec, AUDIO_IC_CODEC_CTRL1, val);
+	return 0;

snd_soc_update_bits(). Can this not be represented as multiple widgets
- remember that DAPM will coalesce writes as much as it can.

sound/soc/sirf/sirf-soc-inner.c line 297

Quoted 3 lines
sound/soc/sirf/sirf-soc-inner.c new file +3 -0
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		spin_lock(&sinner_audio->lock);
+		if (playback) {

The lock only gets used in the trigger function, is it needed?

sound/soc/sirf/sirf-soc-inner.c line 421

Quoted 5 lines
sound/soc/sirf/sirf-soc-inner.c new file +5 -0
+static struct snd_soc_codec_driver soc_codec_device_sirf_inner_codec = {
+	.probe = sirf_inner_codec_probe,
+	.remove = sirf_inner_codec_remove,
+	.read = sirf_inner_codec_reg_read,
+	.write = sirf_inner_codec_reg_write,

Don't use custom read and write callbacks, use a MMIO regmap.

#13 lore raw

PATCH v3 5/5 ASoC: sirf-inner: add mach driver for SiRFSoC internal codec

In reply to RongJun Ying

From: Rongjun Ying <[email protected]>

This connects DMA, CPU DAI and Codec DAI together and works as a mach driver.

---
-v3:
Use devm_gpio_request_one instead of gpio_request.
Remove the extcon stuff code.
Add binding document
Use the devm_snd_soc_register_card instead of soc-audio device register

 .../bindings/sound/sirf,inner-audio-codec.txt      |   41 +++++
 sound/soc/sirf/Kconfig                             |    5 +
 sound/soc/sirf/Makefile                            |    2 +
 sound/soc/sirf/sirf-inner.c                        |  155 ++++++++++++++++++++
 4 files changed, 203 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/sound/sirf,inner-audio-codec.txt
 create mode 100644 sound/soc/sirf/sirf-inner.c
Documentation/devicetree/bindings/sound/sirf,inner-audio-codec.txt new file +41 -0
new file mode 100644
index 0000000..67393e3
@@ -0,0 +1,41 @@
+* SiRF atlas6 and prima2 inner audio codec based audio setups
+
+Required properties:
+- compatible: "sirf,sirf-inner"
+- sirf,inner-platform: phandle for the platform node
+- sirf,inner-codec: phandle for the SiRF inner codec node
+
+Optional properties:
+- hp-pa-gpios: Need to be present if the board need control external
+  headphone amplifier.
+- spk-pa-gpios: Need to be present if the board need control external
+  speaker amplifier.
+- hp-switch-gpios: Need to be present if the board capable to detect jack
+  insertion, removal.
+
+Available audio endpoints for the audio-routing table:
+
+Board connectors:
+ * Headset Stereophone
+ * Ext Spk
+ * Line In
+ * Mic
+
+SiRF inner codec pins:
+ * HPOUTL
+ * HPOUTR
+ * SPKOUT
+ * Ext Mic
+ * Mic Bias
+
+Example:
+
+sound {
+		compatible = "sirf,sirf-inner";
+		sirf,inner-codec = <&audio>;
+		sirf,inner-platform = <&audio>;
+		hp-pa-gpios = <&gpio 44 0>;
+		spk-pa-gpios = <&gpio 46 0>;
+		hp-switch-gpios = <&gpio 45 0>;
+};
+
sound/soc/sirf/Kconfig +5 -0
index afa3952..564b0ec 100644
@@ -11,3 +11,8 @@ config SND_SIRF_SOC_INNER
 
 config SND_SOC_SIRF_USP
 	tristate
+
+config SND_SIRF_INNER
+	tristate "SoC Audio support for SiRF inner codec of SiRF EVB"
+	depends on SND_SIRF_SOC
+	select SND_SIRF_SOC_INNER
sound/soc/sirf/Makefile +2 -0
index 8517c67..80abdf6 100644
@@ -1,9 +1,11 @@
 snd-soc-sirf-objs := sirf-pcm.o
+snd-soc-sirf-inner-objs := sirf-inner.o
 snd-soc-sirf-soc-inner-objs := sirf-soc-inner.o
 snd-soc-sirf-i2s-objs := sirf-i2s.o
 snd-soc-sirf-usp-objs := sirf-usp.o
 
 obj-$(CONFIG_SND_SIRF_SOC) += snd-soc-sirf.o
+obj-$(CONFIG_SND_SIRF_INNER) += snd-soc-sirf-inner.o
 obj-$(CONFIG_SND_SIRF_SOC_INNER) += snd-soc-sirf-soc-inner.o
 obj-$(CONFIG_SND_SOC_SIRF_I2S) += snd-soc-sirf-i2s.o
 obj-$(CONFIG_SND_SOC_SIRF_USP) += snd-soc-sirf-usp.o
sound/soc/sirf/sirf-inner.c new file +155 -0

155 lines not on this page · raw message

Signature · 1 line
1.7.5.4
maintainer
#14 lore raw

Re: [PATCH v3 5/5] ASoC: sirf-inner: add mach driver for SiRFSoC internal codec

Review

Quoted 1 line · RongJun Ying
(quoted diff) +1 -0
+	struct sirf_inner_card *sinner_card = snd_soc_card_get_drvdata(card);

I see where it comes from but "sinner" is a really odd abbrevation to use in a mostly English context.

Otherwise this looks fine.