Skip to contentSkip to conversation

ASoC: add driver for Atmel I2S controller

PATCH Superseded Cyrille Pitchen 2 participants 4 messages Sep 29, 2015 – Oct 5, 2015

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ASoC: add driver for Atmel I2S controller

This series of patches adds support to the new Atmel I2S controller embedded on sama5d2 SoCs.

ChangeLog

v2:
- initialize dev->dev before calling dev->caps->mck_init().

Cyrille Pitchen (2):
ASoC: atmel-i2s: add DT bindings for I2S controller
ASoC: atmel-i2s: add driver for the new Atmel I2S controller

 .../devicetree/bindings/sound/atmel-i2s.txt        |  43 ++
 sound/soc/atmel/Kconfig                            |  10 +
 sound/soc/atmel/Makefile                           |   2 +
 sound/soc/atmel/atmel-i2s.c                        | 760 +++++++++++++++++++++
 4 files changed, 815 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/atmel-i2s.txt
 create mode 100644 sound/soc/atmel/atmel-i2s.c
Signature · 1 line
1.8.2.2
#1 lore raw

PATCH v2 1/2 ASoC: atmel-i2s: add DT bindings for I2S controller

This patch adds DT bindings for the new Atmel I2S controller embedded inside sama5d2x SoCs.

---
 .../devicetree/bindings/sound/atmel-i2s.txt        | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/atmel-i2s.txt
Documentation/devicetree/bindings/sound/atmel-i2s.txt new file +43 -0
new file mode 100644
index 000000000000..83bc6b9070bf
@@ -0,0 +1,43 @@
+* Atmel I2S controller
+
+Required properties:
+- compatible:     Should be "atmel,sama5d2-i2s".
+- reg:            Should be the physical base address of the controller and the
+                  length of memory mapped region.
+- interrupts:     Should contain the interrupt for the controller.
+- dmas:           Should be a list of pairs of DMA controller phandle and flags.
+- dma-names:      Should be a list of DMA channel name among "rx", "tx" or
+                  "rx-tx".
+- clocks:         Should be a list of phandles of clocks used by the controller
+                  (1).
+- clock-names:    Should be a list matching the clocks phandles list:
+                  - "pclk" (peripheral clock) Required.
+                  - "gclk" (generated clock) Optional (1).
+                  - "aclk" (Audio PLL clock) Optional (1).
+
+Optional properties:
+- pinctrl-0:      Should specify pin control groups used for this controller.
+- princtrl-names: Should contain only one value - "default".
+
+
+(1) : Only the peripheral clock is required. The generated clock and the Audio
+      PLL clock are optional and should only be set together.
+
+Example:
+
+	i2s@f8050000 {
+		compatible = "atmel,sama5d2-i2s";
+		reg = <0xf8050000 0x300>;
+		interrupts = <54 IRQ_TYPE_LEVEL_HIGH 7>;
+		dmas = <&dma0
+			(AT91_XDMAC_DT_MEM_IF(0) | AT91_XDMAC_DT_PER_IF(1) |
+			 AT91_XDMAC_DT_PERID(31))>,
+		       <&dma0
+			(AT91_XDMAC_DT_MEM_IF(0) | AT91_XDMAC_DT_PER_IF(1) |
+			 AT91_XDMAC_DT_PERID(32))>;
+		dma-names = "tx", "rx";
+		clocks = <&i2s0_clk>, <&i2s0_gclk>, <&audio_pll_pmc>;
+		clock-names = "pclk", "gclk", "aclk";
+		pinctrl-names = "default";
+		pinctrl-0 = <&pinctrl_i2s0_default>;
+	};
Signature · 6 lines
1.8.2.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

PATCH v2 2/2 ASoC: atmel-i2s: add driver for the new Atmel I2S controller

In reply to Cyrille Pitchen

This patch adds support for the Atmel I2S controller embedded into sama5d2x SoCs.

---
 sound/soc/atmel/Kconfig     |  10 +
 sound/soc/atmel/Makefile    |   2 +
 sound/soc/atmel/atmel-i2s.c | 760 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 772 insertions(+)
 create mode 100644 sound/soc/atmel/atmel-i2s.c
sound/soc/atmel/Kconfig +10 -0
index 1489cd461aec..c026c207a386 100644
@@ -30,6 +30,16 @@ config SND_ATMEL_SOC_SSC
 	default y if SND_ATMEL_SOC_SSC_DMA=y || SND_ATMEL_SOC_SSC_PDC=y
 	default m if SND_ATMEL_SOC_SSC_DMA=m || SND_ATMEL_SOC_SSC_PDC=m
 
+config SND_ATMEL_SOC_I2S
+	tristate "SoC Audio support for the Atmel I2S module"
+	select SND_SOC_GENERIC_DMAENGINE_PCM
+	select REGMAP_MMIO
+	depends on OF && (ARCH_AT91 || COMPILE_TEST)
+	help
+	  Say Y or M if you want to add support for codecs attached to
+	  the Atmel I2S interface. You will also need
+	  to select the audio interfaces to support below.
+
 config SND_AT91_SOC_SAM9G20_WM8731
 	tristate "SoC Audio support for WM8731-based At91sam9g20 evaluation board"
 	depends on ARCH_AT91 || COMPILE_TEST
sound/soc/atmel/Makefile +2 -0
index b327e5cc8de3..4d960464aecb 100644
@@ -2,10 +2,12 @@
 snd-soc-atmel-pcm-pdc-objs := atmel-pcm-pdc.o
 snd-soc-atmel-pcm-dma-objs := atmel-pcm-dma.o
 snd-soc-atmel_ssc_dai-objs := atmel_ssc_dai.o
+snd-soc-atmel-i2s-objs := atmel-i2s.o
 
 obj-$(CONFIG_SND_ATMEL_SOC_PDC) += snd-soc-atmel-pcm-pdc.o
 obj-$(CONFIG_SND_ATMEL_SOC_DMA) += snd-soc-atmel-pcm-dma.o
 obj-$(CONFIG_SND_ATMEL_SOC_SSC) += snd-soc-atmel_ssc_dai.o
+obj-$(CONFIG_SND_ATMEL_SOC_I2S) += snd-soc-atmel-i2s.o
 
 # AT91 Machine Support
 snd-soc-sam9g20-wm8731-objs := sam9g20_wm8731.o
sound/soc/atmel/atmel-i2s.c new file +760 -0

760 lines not on this page · raw message

Signature · 6 lines
1.8.2.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#3 lore raw

Re: [PATCH v2 2/2] ASoC: atmel-i2s: add driver for the new Atmel I2S controller

sound/soc/atmel/atmel-i2s.c line 245

Quoted 11 lines · Cyrille Pitchen
sound/soc/atmel/atmel-i2s.c new file +11 -0
+	if (pending & ATMEL_I2SC_INT_RXOR) {
+		mask = ATMEL_I2SC_SR_RXOR;
+
+		for (ch = 0; ch < ATMEL_I2SC_MAX_TDM_CHANNELS; ++ch)
+			if (sr & ATMEL_I2SC_SR_RXORCH(ch)) {
+				mask |= ATMEL_I2SC_SR_RXORCH(ch);
+				dev_err(dev->dev,
+					"RX overrun on channel %d\n", ch);
+			}
+		regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask);
+	}

Coding style - the for loop needs { } for legibility.

Quoted 4 lines
sound/soc/atmel/atmel-i2s.c new file +4 -0
+	if (pending & ATMEL_I2SC_INT_TXUR) {
+		mask = ATMEL_I2SC_SR_TXUR;
+
+		for (ch = 0; ch < ATMEL_I2SC_MAX_TDM_CHANNELS; ++ch)

sound/soc/atmel/atmel-i2s.c line 260

Quoted 10 lines
sound/soc/atmel/atmel-i2s.c new file +10 -0
+			if (sr & ATMEL_I2SC_SR_TXURCH(ch)) {
+				mask |= ATMEL_I2SC_SR_TXURCH(ch);
+				dev_err(dev->dev,
+					"TX underrun on channel %d\n", ch);
+			}
+		regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask);
+
+	}
+
+	return IRQ_HANDLED;

This IRQ_HANDLED should be generated only if one of the interrupts we know about got handled - there was a check to see if any of the unmasked bits is set earlier on in the function but that's not quite the same check.

Quoted 5 lines
sound/soc/atmel/atmel-i2s.c new file +5 -0
+
+static int atmel_i2s_prepare(struct snd_pcm_substream *substream,
+			     struct snd_soc_dai *dai)
+{
+	struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);

sound/soc/atmel/atmel-i2s.c line 295

Quoted 10 lines
sound/soc/atmel/atmel-i2s.c new file +10 -0
+	bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
+	unsigned int rhr, sr = 0;
+
+	if (is_playback) {
+		regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr);
+		if (sr & ATMEL_I2SC_SR_RXRDY) {
+			dev_dbg(dev->dev, "RXRDY is set\n");
+			regmap_read(dev->regmap, ATMEL_I2SC_RHR, &rhr);
+		}
+	}

What's this doing? It just seems to do two reads and issue a debug message...

Quoted 6 lines
sound/soc/atmel/atmel-i2s.c new file +6 -0
+static int atmel_i2s_sama5d2_mck_init(struct atmel_i2s_dev *dev,
+				      struct device_node *np)
+{
+	#define SFR_I2SCLKSEL 0x90U
+	struct regmap *sfr;
+	int id;

sound/soc/atmel/atmel-i2s.c line 591

Quoted 10 lines
sound/soc/atmel/atmel-i2s.c new file +10 -0
+
+	id = of_alias_get_id(np, "i2s");
+	if (id < 0) {
+		dev_err(dev->dev, "failed to get alias ID\n");
+		return id;
+	}
+	if (id > 1) {
+		dev_err(dev->dev, "invalid I2S controller ID: %d\n", id);
+		return -EINVAL;
+	}

This didn't appear in the DT binding and looks pretty funky - what's going on here?

sound/soc/atmel/atmel-i2s.c line 597

Quoted 5 lines
sound/soc/atmel/atmel-i2s.c new file +5 -0
+	sfr = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
+	if (IS_ERR(sfr)) {
+		dev_err(dev->dev, "failed to get SFR syscon\n");
+		return PTR_ERR(sfr);
+	}

This didn't appear in the binding either.

sound/soc/atmel/atmel-i2s.c line 637

Quoted 3 lines
sound/soc/atmel/atmel-i2s.c new file +3 -0
+	/* Get hardware capabilities. */
+	match = of_match_node(atmel_i2s_dt_ids, np);
+	dev->caps = match ? match->data : NULL;

Please don't abuse the ternery operator like this, just write a normal if statement :/