Skip to contentSkip to conversation

ASoC: Add CS4271 codec support

PATCH In review Ryan Mallon 3 participants 8 messages Oct 7, 2010

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ASoC: Add CS4271 codec support

From: Alexander Sverdlin <[email protected]>

Added support for Cirrus CS4271 codec to ALSA SoC subsystem.

Applies on: 2.6.36-rc6

---

 sound/soc/codecs/Kconfig  |    3 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/cs4271.c |  840 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs4271.h |   27 ++
 4 files changed, 872 insertions(+), 0 deletions(-)
sound/soc/codecs/Kconfig +3 -0
index 83f5c67..608cf88 100644
@@ -138,6 +138,9 @@ config SND_SOC_CS4270_VD33_ERRATA
 	bool
 	depends on SND_SOC_CS4270
 
+config SND_SOC_CS4271
+	tristate
+
 config SND_SOC_CX20442
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 5352409..d7dd676 100644
@@ -11,6 +11,7 @@ snd-soc-ak4671-objs := ak4671.o
 snd-soc-cq93vc-objs := cq93vc.o
 snd-soc-cs42l51-objs := cs42l51.o
 snd-soc-cs4270-objs := cs4270.o
+snd-soc-cs4271-objs := cs4271.o
 snd-soc-cx20442-objs := cx20442.o
 snd-soc-da7210-objs := da7210.o
 snd-soc-l3-objs := l3.o
@@ -79,6 +80,7 @@ obj-$(CONFIG_SND_SOC_AK4671)	+= snd-soc-ak4671.o
 obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
 obj-$(CONFIG_SND_SOC_CS42L51)	+= snd-soc-cs42l51.o
 obj-$(CONFIG_SND_SOC_CS4270)	+= snd-soc-cs4270.o
+obj-$(CONFIG_SND_SOC_CS4271)	+= snd-soc-cs4271.o
 obj-$(CONFIG_SND_SOC_CX20442)	+= snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_DA7210)	+= snd-soc-da7210.o
 obj-$(CONFIG_SND_SOC_L3)	+= snd-soc-l3.o
sound/soc/codecs/cs4271.c new file +840 -0

840 lines not on this page · raw message

sound/soc/codecs/cs4271.h new file +27 -0
new file mode 100644
index 0000000..7cf6af2
@@ -0,0 +1,27 @@
+/*
+ * Cirrus Logic CS4271 ALSA SoC Codec Driver
+ *
+ * Copyright (c) 2010 Alexander Sverdlin <[email protected]>
+ *
+ * This file is licensed under the terms of the GNU General Public License 
+ * version 2.  This program is licensed "as is" without any warranty of any 
+ * kind, whether express or implied.
+ */
+
+#ifndef _CS4271_H
+#define _CS4271_H
+
+/*
+ * The ASoC codec DAI structure for the CS4271.  Assign this structure to
+ * the .codec_dai field of your machine driver's snd_soc_dai_link structure.
+ */
+extern struct snd_soc_dai cs4271_dai;
+
+/*
+ * The ASoC codec device structure for the CS4271.  Assign this structure
+ * to the .codec_dev field of your machine driver's snd_soc_device
+ * structure.
+ */
+extern struct snd_soc_codec_device soc_codec_device_cs4271;
+
+#endif
#1 lore raw
Quoted 5 lines · Ryan Mallon

From: Alexander Sverdlin <[email protected]>

Added support for Cirrus CS4271 codec to ALSA SoC subsystem.

Applies on: 2.6.36-rc6

Unfortunately there have been major changes in the ASoC APIs in -next for Liam's multi-component work so you'll need to update this before it can be applied. You should always submit code against -next (except for bug fixes to be sent to Linus).

See

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git

for current code.

I gave the driver a quick review and it looks really good - it just needs to be updated for current APIs.

sound/soc/codecs/cs4271.c line 402

Quoted 2 lines
sound/soc/codecs/cs4271.c new file +2 -0
+static const struct snd_kcontrol_new cs4271_snd_controls[] = {
+	SOC_DOUBLE_R("Master Playback Volume", CS4271_VOLA, CS4271_VOLB, 0, 0x7F, 1),

TLV information would be nice but isn't essential.

sound/soc/codecs/cs4271.c line 403

Quoted 1 line
sound/soc/codecs/cs4271.c new file +1 -0
+	SOC_SINGLE("Digital Loopback Switch", CS4271_MODE2, 4, 1, 0),

This should probably be done as part of DAPM. Again probably not essential.

#2 lore raw
Quoted 7 lines · Mark Brown
Quoted 5 lines · Ryan Mallon

From: Alexander Sverdlin <[email protected]>

Added support for Cirrus CS4271 codec to ALSA SoC subsystem.

Applies on: 2.6.36-rc6

Ugh, I managed to miss Alexander from the CC list :-/. Alexander, can you please update the patch as detailed below.

~Ryan

Quoted 23 lines

Unfortunately there have been major changes in the ASoC APIs in -next for Liam's multi-component work so you'll need to update this before it can be applied. You should always submit code against -next (except for bug fixes to be sent to Linus).

See

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git

for current code.

I gave the driver a quick review and it looks really good - it just needs to be updated for current APIs.

sound/soc/codecs/cs4271.c line 402

Quoted 2 lines
sound/soc/codecs/cs4271.c new file +2 -0
+static const struct snd_kcontrol_new cs4271_snd_controls[] = {
+	SOC_DOUBLE_R("Master Playback Volume", CS4271_VOLA, CS4271_VOLB, 0, 0x7F, 1),

TLV information would be nice but isn't essential.

sound/soc/codecs/cs4271.c line 403

Quoted 1 line
sound/soc/codecs/cs4271.c new file +1 -0
+	SOC_SINGLE("Digital Loopback Switch", CS4271_MODE2, 4, 1, 0),

This should probably be done as part of DAPM. Again probably not essential.

Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

Ryan Mallon         		5 Amuri Park, 404 Barbadoes St
[email protected]         	PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com	New Zealand
Phone: +64 3 3779127		Freecall: Australia 1800 148 751
Fax:   +64 3 3779135			  USA 1800 261 2934
#3 lore raw

PATCH 2/2 ASoC: EDB93xx machine sound driver

In reply to Ryan Mallon

From: Alexander Sverdlin <[email protected]>

Added support for EDB93xx sound with CS4271 codec. Features:
Playback, Capture
Sample rates from 8kHz to 96kHz tested
Limitations:
Depends on ALSA auto sample format conversion No DAPM support

Applies on: 2.6.36-rc6

---

 arch/arm/mach-ep93xx/edb93xx.c |   46 +++++++++
 sound/soc/ep93xx/Kconfig       |    9 ++
 sound/soc/ep93xx/Makefile      |    5 +
 sound/soc/ep93xx/edb93xx.c     |  205 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 265 insertions(+), 0 deletions(-)
arch/arm/mach-ep93xx/edb93xx.c +46 -0
index c2ce903..1b24203 100644
@@ -30,12 +30,19 @@
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
+#include <linux/spi/spi.h>
+#include <mach/ep93xx_spi.h>
 
 #include <mach/hardware.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 
+#define edb93xx_has_audio() (machine_is_edb9301() ||	\
+			     machine_is_edb9302() ||	\
+			     machine_is_edb9302a() ||	\
+			     machine_is_edb9307a() ||	\
+			     machine_is_edb9315a())
 
 static void __init edb93xx_register_flash(void)
 {
@@ -93,6 +100,43 @@ static void __init edb93xx_register_i2c(void)
 
 
 /*************************************************************************
+ * EDB93xx SPI peripheral handling
+ *************************************************************************/
+static struct spi_board_info edb93xx_spi_board_info[] = {
+	{
+		.modalias		= "cs4271",
+		.max_speed_hz		= 6000000,
+		.bus_num		= 0,
+		.chip_select		= 0,
+		.mode			= SPI_MODE_3,
+	},
+};
+
+static struct ep93xx_spi_info edb93xx_spi_info = {
+	.num_chipselect	= ARRAY_SIZE(edb93xx_spi_board_info),
+};
+
+static void __init edb93xx_register_spi(void)
+{
+	if (edb93xx_has_audio()) {
+		ep93xx_register_spi(&edb93xx_spi_info,
+				    edb93xx_spi_board_info,
+				    ARRAY_SIZE(edb93xx_spi_board_info));
+	}
+}
+
+/*************************************************************************
+ * EDB93xx I2S
+ *************************************************************************/
+static void __init edb93xx_register_i2s(void)
+{
+	if (edb93xx_has_audio()) {
+		ep93xx_register_i2s();
+	}
+}
+
+
+/*************************************************************************
  * EDB93xx pwm
  *************************************************************************/
 static void __init edb93xx_register_pwm(void)
@@ -117,6 +161,8 @@ static void __init edb93xx_init_machine(void)
 	edb93xx_register_flash();
 	ep93xx_register_eth(&edb93xx_eth_data, 1);
 	edb93xx_register_i2c();
+	edb93xx_register_spi();
+	edb93xx_register_i2s();
 	edb93xx_register_pwm();
 }
 
sound/soc/ep93xx/Kconfig +9 -0
index f617f56..22cb673 100644
@@ -16,3 +16,12 @@ config SND_EP93XX_SOC_SNAPPERCL15
         help
           Say Y or M here if you want to add support for I2S audio on the
           Bluewater Systems Snapper CL15 module.
+
+config SND_EP93XX_SOC_EDB93XX
+        tristate "SoC Audio support for Cirrus Logic EDB93xx boards"
+        depends on SND_EP93XX_SOC && (MACH_EDB9301 || MACH_EDB9302 || MACH_EDB9302A || MACH_EDB9307A || MACH_EDB9315A)
+        select SND_EP93XX_SOC_I2S
+        select SND_SOC_CS4271
+        help
+          Say Y or M here if you want to add support for I2S audio on the
+          Cirrus Logic EDB93xx boards.
sound/soc/ep93xx/Makefile +5 -0
index 272e60f..4f62ad8 100644
@@ -9,3 +9,8 @@ obj-$(CONFIG_SND_EP93XX_SOC_I2S)		+= snd-soc-ep93xx-i2s.o
 snd-soc-snappercl15-objs			:= snappercl15.o
 
 obj-$(CONFIG_SND_EP93XX_SOC_SNAPPERCL15)	+= snd-soc-snappercl15.o
+
+# EDB93XX Machine Support
+snd-soc-edb93xx-objs				:= edb93xx.o
+
+obj-$(CONFIG_SND_EP93XX_SOC_EDB93XX)		+= snd-soc-edb93xx.o
sound/soc/ep93xx/edb93xx.c new file +205 -0

205 lines not on this page · raw message

#4 lore raw

Re: [PATCH 2/2] ASoC: EDB93xx machine sound driver

sound/soc/ep93xx/edb93xx.c line 137

Quoted 13 lines · Ryan Mallon
sound/soc/ep93xx/edb93xx.c new file +13 -0
+	ret = gpio_request(EP93XX_GPIO_LINE_EGPIO6, "CS4271 SFRM1 Disable");
+	if (ret)
+		return ret;
+	ret = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO6, 0);
+	if (ret)
+		goto free_EGPIO6;
+
+	ret = gpio_request(EP93XX_GPIO_LINE_EGPIO1, "CS4271 Reset");
+	if (ret)
+		goto free_EGPIO6;
+	ret = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO1, 1);
+	if (ret)
+		goto free_EGPIO1;

It'd seem to make sense for these to be handled by the CODEC driver, using platform data to supply the GPIOs so that their management can be integrated with the CODEC flow?

Otherwise this looks good.

#5 lore raw
In reply to Ryan Mallon

sound/soc/codecs/Kconfig config SND_SOC_CS4270_VD33_ERRATA · line 146

Quoted 12 lines · Ryan Mallon
sound/soc/codecs/Kconfig +3 -0
@@ -138,6 +138,9 @@ config SND_SOC_CS4270_VD33_ERRATA
 	bool
 	depends on SND_SOC_CS4270
 
+config SND_SOC_CS4271
+	tristate
+
 config SND_SOC_CX20442
 	tristate
 

Oh, one actual problem: you should add the driver to SND_SOC_ALL_CODECS too so we get build coverage for testing.

#6 lore raw
In reply to Ryan Mallon
Quoted 4 lines · Ryan Mallon

+ * For setups with variable MCLKs, pass 0 as 'freq' argument. This will cause
+ * theoretically possible sample rates to be enabled. Call it again with a
+ * proper value set one the external clock is set (most probably you would do
+ * that from a machine's driver 'hw_param' hook.

If you're going to copy/paste parts of my driver verbatim into yours, you should put something like this in the comments:

Based on the CS4270 driver by Timur Tabi <[email protected]>

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#7 lore raw
Quoted 11 lines · Timur Tabi
Quoted 4 lines · Ryan Mallon

+ * For setups with variable MCLKs, pass 0 as 'freq' argument. This will cause
+ * theoretically possible sample rates to be enabled. Call it again with a
+ * proper value set one the external clock is set (most probably you would do
+ * that from a machine's driver 'hw_param' hook.

If you're going to copy/paste parts of my driver verbatim into yours, you should put something like this in the comments:

Based on the CS4270 driver by Timur Tabi <[email protected]>

Thanks. CC'ed Alexander, the driver author, who I stupidly left of the reply list.

~Ryan

Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

Ryan Mallon         		5 Amuri Park, 404 Barbadoes St
[email protected]         	PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com	New Zealand
Phone: +64 3 3779127		Freecall: Australia 1800 148 751
Fax:   +64 3 3779135			  USA 1800 261 2934