Skip to contentSkip to conversation

Adding ASoC drivers for SPEAr13XX platform

PATCH In review Rajeev Kumar 4 participants 17 messages Jun 6, 2011 – Jun 8, 2011

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

v4 cover Adding ASoC drivers for SPEAr13XX platform

This patchset contains five patches which add support for ASoC sound drivers on ST's SPEAr13XX platform. Details of the SPEAr13XX platforms can be seen here:
http://www.st.com/internet/mcu/product/250658.jsp

The ARCH and PLATFORM specific code for SPEAr13XX are already under review in Russell King's ARM mailing list(Linux-kernel-version 2.6.38-rc4).

This patchset has been tested for linux-kernel-version 2.6.38-rc4 and on ARM platform.

Please review the same and consider for mainline inclusion.

Changes in machine driver code since V3
1.Use of snd_soc_register_card() rather than using the soc-audio device. Changes in codec code since V3:
1. use standard cache sync implementation i.e. snd_soc_cache_sync() Changes in spear Kconfig and Makefile since V2:
1.giving all the the modules snd-soc- prefixes to their names Changes in codec code since V2:
1. use SOC_DOUBLE for volume control
2. remove default configuration for codec .offer them as runtime controls.
3. restore the register cache in resume
changes in platform code since V1:
1. Spilt machine driver from platform driver.
2. Updated rate supported.
3. Moved clock specific part from "spear13xx_i2s_set_dai_sysclk". function to platform code. This function is removed now.
4. Function "spear13xx_i2s_startup" removed.
5. Function "spear13xx_i2s_shutdown" removed.

Changes in codec code since V1:
1. Removed sta529 version number.
2. Removed "sta529_read_reg_cache".
3. Removed function "sta529_write_reg_cache".
4. Removed function "sta529_write".
5. Moved sta529.h file contents to sta529.c file.
6. Move clock specific part from "spear_sta_set_dai_sysclk". function to platform code. This function is removed now.
7. Renamed function names from spear_sta_* to sta_*.
8. Modified probe() function to avoid rewriting default chip values to hardware.

Rajeev Kumar (5):
sound: asoc: Adding support for STA529 Audio Codec
sound: asoc: Adding support for SPEAr13XX ASoC platform driver
sound: asoc: Adding support for SPEAr13XX ASoC machine driver
sound: asoc: Adding Kconfig and Makefile to support SPEAr13XX ASoC
driver
sound: asoc: Adding support for SPEAr13XX in soc

 sound/soc/Kconfig               |    1 +
 sound/soc/Makefile              |    1 +
 sound/soc/codecs/Kconfig        |    5 +
 sound/soc/codecs/Makefile       |    2 +
 sound/soc/codecs/sta529.c       |  374 ++++++++++++++++++++++++++++
 sound/soc/spear/Kconfig         |   19 ++
 sound/soc/spear/Makefile        |   12 +
 sound/soc/spear/evb_sta529.c    |  121 +++++++++
 sound/soc/spear/spear13xx-i2s.c |  524 +++++++++++++++++++++++++++++++++++++++
 sound/soc/spear/spear13xx-i2s.h |   19 ++
 sound/soc/spear/spear13xx-pcm.c |  500 +++++++++++++++++++++++++++++++++++++
 sound/soc/spear/spear13xx-pcm.h |   50 ++++
 12 files changed, 1628 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/sta529.c
 create mode 100644 sound/soc/spear/Kconfig
 create mode 100644 sound/soc/spear/Makefile
 create mode 100644 sound/soc/spear/evb_sta529.c
 create mode 100644 sound/soc/spear/spear13xx-i2s.c
 create mode 100644 sound/soc/spear/spear13xx-i2s.h
 create mode 100644 sound/soc/spear/spear13xx-pcm.c
 create mode 100644 sound/soc/spear/spear13xx-pcm.h
#1 lore raw

PATCH v4 1/5 sound: asoc: Adding support for STA529 Audio Codec

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

---
 sound/soc/codecs/Kconfig  |    5 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/sta529.c |  374 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/sta529.c
sound/soc/codecs/Kconfig +5 -0
index 98175a0..c5c65ba 100644
@@ -42,6 +42,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_SN95031 if INTEL_SCU_IPC
 	select SND_SOC_SPDIF
 	select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI
+	select SND_SOC_STA529 if I2C
 	select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
 	select SND_SOC_TLV320AIC23 if I2C
 	select SND_SOC_TLV320AIC26 if SPI_MASTER
@@ -216,6 +217,10 @@ config SND_SOC_SPDIF
 config SND_SOC_SSM2602
 	tristate
 
+config SND_SOC_STA529
+	tristate
+	depends on I2C
+
 config SND_SOC_STAC9766
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index fd85584..cb0060a 100644
@@ -28,6 +28,7 @@ snd-soc-alc5623-objs := alc5623.o
 snd-soc-sn95031-objs := sn95031.o
 snd-soc-spdif-objs := spdif_transciever.o
 snd-soc-ssm2602-objs := ssm2602.o
+snd-soc-sta529-objs := sta529.o
 snd-soc-stac9766-objs := stac9766.o
 snd-soc-tlv320aic23-objs := tlv320aic23.o
 snd-soc-tlv320aic26-objs := tlv320aic26.o
@@ -120,6 +121,7 @@ obj-$(CONFIG_SND_SOC_SGTL5000)  += snd-soc-sgtl5000.o
 obj-$(CONFIG_SND_SOC_SN95031)	+=snd-soc-sn95031.o
 obj-$(CONFIG_SND_SOC_SPDIF)	+= snd-soc-spdif.o
 obj-$(CONFIG_SND_SOC_SSM2602)	+= snd-soc-ssm2602.o
+obj-$(CONFIG_SND_SOC_STA529)	+= snd-soc-sta529.o
 obj-$(CONFIG_SND_SOC_STAC9766)	+= snd-soc-stac9766.o
 obj-$(CONFIG_SND_SOC_TLV320AIC23)	+= snd-soc-tlv320aic23.o
 obj-$(CONFIG_SND_SOC_TLV320AIC26)	+= snd-soc-tlv320aic26.o
sound/soc/codecs/sta529.c new file +374 -0

374 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#2 lore raw

PATCH v4 2/5 sound: asoc: Adding support for SPEAr13XX ASoC platform driver

This patch adds the support for the SPEAr13XX Platform Driver (I2S based) as per the ASoC framework.

SPEAr13XX internally uses a Designware I2S IP and some glue logic on top of the same.

---
 sound/soc/spear/spear13xx-i2s.c |  524 +++++++++++++++++++++++++++++++++++++++
 sound/soc/spear/spear13xx-i2s.h |   19 ++
 sound/soc/spear/spear13xx-pcm.c |  500 +++++++++++++++++++++++++++++++++++++
 sound/soc/spear/spear13xx-pcm.h |   50 ++++
 4 files changed, 1093 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/spear/spear13xx-i2s.c
 create mode 100644 sound/soc/spear/spear13xx-i2s.h
 create mode 100644 sound/soc/spear/spear13xx-pcm.c
 create mode 100644 sound/soc/spear/spear13xx-pcm.h
sound/soc/spear/spear13xx-i2s.c new file +524 -0
new file mode 100644
index 0000000..a551110
@@ -0,0 +1,524 @@
+/*
+ * ALSA SoC I2S Audio Layer for ST spear13xx processor
+ *
+ * sound/soc/spear/spear13xx-i2s.c
+ *
+ * Copyright (C) 2011 ST Microelectronics
+ * Rajeev Kumar <[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.
+ */
+
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <mach/misc_regs.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/core.h>
+#include <sound/initval.h>
+#include <sound/soc.h>
+#include "spear13xx-pcm.h"
+#include "spear13xx-i2s.h"
+
+/* common register for all channel */
+#define IER		0x000
+#define IRER		0x004
+#define ITER		0x008
+#define CER		0x00C
+#define CCR		0x010
+#define RXFFR		0x014
+#define TXFFR		0x018
+
+/* I2STxRxRegisters for channel 0 */
+#define LRBR0_LTHR0	0x020
+#define RRBR0_RTHR0	0x024
+#define RER0		0x028
+#define TER0		0x02C
+#define RCR0		0x030
+#define TCR0		0x034
+#define ISR0		0x038
+#define IMR0		0x03C
+#define ROR0		0x040
+#define TOR0		0x044
+#define RFCR0		0x048
+#define TFCR0		0x04C
+#define RFF0		0x050
+#define TFF0		0x054
+
+/* I2STxRxRegisters for channel 1 */
+#define LRBR1_LTHR1	0x060
+#define RRBR1_RTHR1	0x064
+#define RER1		0x068
+#define TER1		0x06C
+#define RCR1		0x070
+#define TCR1		0x074
+#define ISR1		0x078
+#define IMR1		0x07C
+#define ROR1		0x080
+#define TOR1		0x084
+#define RFCR1		0x088
+#define TFCR1		0x08C
+#define RFF1		0x090
+#define TFF1		0x094
+
+/* I2STxRxRegisters for channel 2 */
+#define LRBR2_LTHR2	0x0A0
+#define RRBR2_RTHR2	0x0A4
+#define RER2		0x0A8
+#define TER2		0x0AC
+#define RCR2		0x0B0
+#define TCR2		0x0B4
+#define ISR2		0x0B8
+#define IMR2		0x0BC
+#define ROR2		0x0C0
+#define TOR2		0x0C4
+#define RFCR2		0x0C8
+#define TFCR2		0x0CC
+#define RFF2		0x0D0
+#define TFF2		0x0D4
+
+/* I2STxRxRegisters for channel 3*/
+#define LRBR3_LTHR3	0x0E0
+#define RRBR3_RTHR3	0x0E4
+#define RER3		0x0E8
+#define TER3		0x0EC
+#define RCR3		0x0F0
+#define TCR3		0x0F4
+#define ISR3		0x0F8
+#define IMR3		0x0FC
+#define ROR3		0x100
+#define TOR3		0x104
+#define RFCR3		0x108
+#define TFCR3		0x10C
+#define RFF3		0x110
+#define TFF3		0x114
+
+/* I2SDMARegisters */
+#define RXDMA		0x01C0
+#define RRXDMA		0x01C4
+#define TXDMA		0x01C8
+#define RTXDMA		0x01CC
+
+/* I2SCOMPRegisters */
+#define I2S_COMP_PARAM_2	0x01F0
+#define I2S_COMP_PARAM_1	0x01F4
+#define I2S_COMP_VERSION	0x01F8
+#define I2S_COMP_TYPE		0x01FC
+
+#define SPEAR13XX_I2S_RATES	SNDRV_PCM_RATE_8000_96000
+#define SPEAR13XX_I2S_FORMAT	SNDRV_PCM_FMTBIT_S16_LE
+#define MAX_CHANNEL_NUM		2
+#define MIN_CHANNEL_NUM		2
+
+struct spear13xx_i2s_dev {
+	void __iomem *i2s_base;
+	struct resource *res;
+	struct clk *clk;
+	int play_irq;
+	int mode;
+	int active;
+	int capture_irq;
+	struct device *dev;
+	struct spear13xx_pcm_dma_params *dma_params[2];
+};
+
+void get_dma_start_addr(struct snd_pcm_substream *substream)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct spear13xx_runtime_data *prtd = substream->runtime->private_data;
+	struct spear13xx_i2s_dev *dev = snd_soc_dai_get_drvdata(rtd->cpu_dai);
+
+	prtd->txdma = dev->res->start + TXDMA;
+	prtd->rxdma = dev->res->start + RXDMA;
+
+	substream->runtime->private_data = prtd;
+}
+
+static inline void i2s_write_reg(void *io_base, int reg, u32 val)
+{
+	writel(val, io_base + reg);
+}
+
+static inline u32 i2s_read_reg(void *io_base, int reg)
+{
+	return readl(io_base + reg);
+}
+
+static void i2s_start_play(struct spear13xx_i2s_dev *dev,
+		struct snd_pcm_substream *substream)
+{
+	u32 val; /*dma mode slection*/
+
+	val = readl(PERIP_CFG);
+	val &= ~0xFFFFFFFC;
+	i2s_write_reg(dev->i2s_base, TER0, 0);
+	i2s_write_reg(dev->i2s_base, TER1, 0);
+
+	/* for 2.0 audio*/
+	if (dev->mode <= 2) {
+		if (!val) {
+			i2s_write_reg(dev->i2s_base, TCR0, 0x2);
+			i2s_write_reg(dev->i2s_base, TFCR0, 0x07);
+			i2s_write_reg(dev->i2s_base, IMR0, 0x00);
+			i2s_write_reg(dev->i2s_base, TER0, 1);
+		} else {
+			i2s_write_reg(dev->i2s_base, TCR1, 0x2);
+			i2s_write_reg(dev->i2s_base, TFCR1, 0x07);
+			i2s_write_reg(dev->i2s_base, IMR1, 0x00);
+			i2s_write_reg(dev->i2s_base, TER1, 1);
+		}
+	} else { /*audio 2.0 onwards */
+		i2s_write_reg(dev->i2s_base, TCR0, 0x5);
+		i2s_write_reg(dev->i2s_base, TCR1, 0x5);
+
+		i2s_write_reg(dev->i2s_base, TFCR0, 0x07);
+		i2s_write_reg(dev->i2s_base, TFCR1, 0x07);
+		i2s_write_reg(dev->i2s_base, IMR0, 0x00);
+		i2s_write_reg(dev->i2s_base, IMR1, 0x00);
+		i2s_write_reg(dev->i2s_base, TER0, 1);
+		i2s_write_reg(dev->i2s_base, TER1, 1);
+	}
+
+	i2s_write_reg(dev->i2s_base, ITER, 1);
+}
+
+static void i2s_start_rec(struct spear13xx_i2s_dev *dev,
+		struct snd_pcm_substream *substream)
+{
+	u32 val; /*dma mode slection*/
+
+	val = readl(PERIP_CFG);
+	val &= ~0xFFFFFFFC;
+	i2s_write_reg(dev->i2s_base, RER0, 0);
+	i2s_write_reg(dev->i2s_base, RER1, 0);
+
+	/* for 2.0 audio*/
+	if (dev->mode <= 2) {
+		if (!val) {
+			i2s_write_reg(dev->i2s_base, RCR0, 0x2);
+			i2s_write_reg(dev->i2s_base, RFCR0, 0x07);
+			i2s_write_reg(dev->i2s_base, IMR0, 0x00);
+			i2s_write_reg(dev->i2s_base, RER0, 1);
+		} else {
+			i2s_write_reg(dev->i2s_base, RCR1, 0x2);
+			i2s_write_reg(dev->i2s_base, RFCR1, 0x07);
+			i2s_write_reg(dev->i2s_base, IMR1, 0x00);
+			i2s_write_reg(dev->i2s_base, TER1, 1);
+		}
+	} else { /*audio 2.0 onwards */
+		i2s_write_reg(dev->i2s_base, RCR0, 0x5);
+		i2s_write_reg(dev->i2s_base, RCR1, 0x5);
+
+		i2s_write_reg(dev->i2s_base, RFCR0, 0x07);
+		i2s_write_reg(dev->i2s_base, RFCR1, 0x07);
+		i2s_write_reg(dev->i2s_base, IMR0, 0x00);
+		i2s_write_reg(dev->i2s_base, IMR1, 0x00);
+		i2s_write_reg(dev->i2s_base, RER0, 1);
+		i2s_write_reg(dev->i2s_base, RER1, 1);
+	}
+
+	i2s_write_reg(dev->i2s_base, IRER, 1);
+}
+
+static void i2s_stop(struct spear13xx_i2s_dev *dev,
+		struct snd_pcm_substream *substream)
+{
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		i2s_write_reg(dev->i2s_base, ITER, 0);
+		i2s_write_reg(dev->i2s_base, ITER, 1);
+		i2s_write_reg(dev->i2s_base, IMR0, 0x30);
+		i2s_write_reg(dev->i2s_base, IMR1, 0x30);
+	} else {
+		i2s_write_reg(dev->i2s_base, IRER, 0);
+		i2s_write_reg(dev->i2s_base, IRER, 1);
+		i2s_write_reg(dev->i2s_base, IMR0, 0x03);
+		i2s_write_reg(dev->i2s_base, IMR1, 0x03);
+	}
+	if (!dev->active--) {
+		i2s_write_reg(dev->i2s_base, CER, 0);
+		i2s_write_reg(dev->i2s_base, IER, 0);
+	}
+
+}
+
+static irqreturn_t i2s_play_irq(int irq, void *_dev)
+{
+	struct spear13xx_i2s_dev *dev = (struct spear13xx_i2s_dev *)_dev;
+	u32 ch0, ch1;
+
+	/* check for the tx data overrun condition */
+	dev_info(dev->dev, "data overrun condition for TX channel\n");
+	ch0 = i2s_read_reg(dev->i2s_base, ISR0) & 0x20;
+	ch1 = i2s_read_reg(dev->i2s_base, ISR1) & 0x20;
+	if (ch0 || ch1) {
+
+		/* disable tx block */
+		i2s_write_reg(dev->i2s_base, ITER, 0);
+
+		/* flush all the tx fifo */
+		i2s_write_reg(dev->i2s_base, TXFFR, 1);
+
+		/* clear tx data overrun interrupt: channel 0 */
+		i2s_read_reg(dev->i2s_base, TOR0);
+
+		/* clear tx data overrun interrupt: channel 1 */
+		i2s_read_reg(dev->i2s_base, TOR1);
+
+	}
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t i2s_capture_irq(int irq, void *_dev)
+{
+	struct spear13xx_i2s_dev *dev = (struct spear13xx_i2s_dev *)_dev;
+	u32 ch0, ch1;
+
+	/* check for the rx data overrun condition */
+	dev_info(dev->dev, "data overrun condition for RX channel\n");
+	ch0 = i2s_read_reg(dev->i2s_base, ISR0) & 0x02;
+	ch1 = i2s_read_reg(dev->i2s_base, ISR1) & 0x02;
+	if (ch0 || ch1) {
+
+		/* disable rx block */
+		i2s_write_reg(dev->i2s_base, IRER, 0);
+
+		/* flush all the rx fifo */
+		i2s_write_reg(dev->i2s_base, RXFFR, 1);
+
+		/* clear rx data overrun interrupt: channel 0 */
+		i2s_read_reg(dev->i2s_base, ROR0);
+
+		/* clear rx data overrun interrupt: channel 1 */
+		i2s_read_reg(dev->i2s_base, ROR1);
+
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int spear13xx_i2s_hw_params(struct snd_pcm_substream *substream,
+		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+	struct spear13xx_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
+
+	dev->mode = params_channels(params);
+
+	if (dev->mode <= 2)
+		i2s_write_reg(dev->i2s_base, CCR, 0x00);
+	else
+		i2s_write_reg(dev->i2s_base, CCR, 0x10);
+
+	return 0;
+}
+
+static int
+spear13xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
+		struct snd_soc_dai *dai)
+{
+	struct spear13xx_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
+	int ret = 0;
+
+	i2s_write_reg(dev->i2s_base, IER, 1);
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		dev->active++;
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+			i2s_start_play(dev, substream);
+		else
+			i2s_start_rec(dev, substream);
+		i2s_write_reg(dev->i2s_base, CER, 1);
+	case SNDRV_PCM_TRIGGER_RESUME:
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+	case SNDRV_PCM_TRIGGER_SUSPEND:
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		i2s_stop(dev, substream);
+		break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+	return ret;
+}
+
+static struct snd_soc_dai_ops spear13xx_i2s_dai_ops = {
+	.hw_params	= spear13xx_i2s_hw_params,
+	.trigger	= spear13xx_i2s_trigger,
+};
+
+struct snd_soc_dai_driver spear13xx_i2s_dai = {
+	.playback = {
+		.channels_min = MAX_CHANNEL_NUM,
+		.channels_max = MIN_CHANNEL_NUM,
+		.rates = SPEAR13XX_I2S_RATES,
+		.formats = SPEAR13XX_I2S_FORMAT,
+	},
+	.capture = {
+		.channels_min = MAX_CHANNEL_NUM,
+		.channels_max = MIN_CHANNEL_NUM,
+		.rates = SPEAR13XX_I2S_RATES,
+		.formats = SPEAR13XX_I2S_FORMAT,
+	},
+	.ops = &spear13xx_i2s_dai_ops,
+};
+
+static int spear13xx_i2s_probe(struct platform_device *pdev)
+{
+	struct spear13xx_i2s_dev *dev;
+	struct resource *res;
+	int ret;
+
+	if (!pdev) {
+		dev_err(&pdev->dev, "Invalid platform device\n");
+		return -EINVAL;
+	}
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "no i2s resource defined\n");
+		return -ENODEV;
+	}
+
+	if (!request_mem_region(res->start, resource_size(res), pdev->name)) {
+		dev_err(&pdev->dev, "i2s region already claimed\n");
+		return -EBUSY;
+	}
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev) {
+		ret = -ENOMEM;
+		goto err_release_mem_region;
+	}
+
+	dev->res = res;
+
+	dev->clk = clk_get(&pdev->dev, NULL);
+	if (IS_ERR(dev->clk)) {
+		ret = PTR_ERR(dev->clk);
+		goto err_kfree;
+	}
+
+	ret = clk_enable(dev->clk);
+	if (ret < 0)
+		goto err_clk_put;
+
+	dev->i2s_base = ioremap(res->start, resource_size(res));
+	if (!dev->i2s_base) {
+		dev_err(&pdev->dev, "ioremap fail for i2s_region\n");
+		ret = -ENOMEM;
+		goto err_clk_disable;
+	}
+
+	dev->play_irq = platform_get_irq_byname(pdev, "play_irq");
+	if (!dev->play_irq) {
+		dev_err(&pdev->dev, "play irq not defined\n");
+		ret = -EBUSY;
+		goto err_iounmap_i2s;
+	}
+	ret = request_irq(dev->play_irq, i2s_play_irq, 0, "spear13xx-i2s", dev);
+	if (ret) {
+		dev_err(&pdev->dev, "play IRQ%d already claimed\n",
+				dev->play_irq);
+		goto err_iounmap_i2s;
+	}
+
+	dev->capture_irq = platform_get_irq_byname(pdev, "record_irq");
+
+	if (!dev->capture_irq) {
+		dev_err(&pdev->dev, "record irq not defined\n");
+		ret = -EBUSY;
+		goto err_free_play_irq;
+	}
+
+	ret = request_irq(dev->capture_irq, i2s_capture_irq, 0, "spear13xx-i2s",
+			dev);
+	if (ret) {
+		dev_err(&pdev->dev, "capture IRQ%d already claimed\n",
+				dev->capture_irq);
+		goto err_free_play_irq;
+	}
+
+	dev->dev = &pdev->dev;
+	dev_set_drvdata(&pdev->dev, dev);
+
+	ret = snd_soc_register_dai(&pdev->dev, &spear13xx_i2s_dai);
+	if (ret != 0)
+		goto err_free_capture_irq;
+
+	/* unmask i2s interrupt for channel 0 */
+	i2s_write_reg(dev->i2s_base, IMR0, 0x00);
+
+	/* unmask i2s interrupt for channel 1 */
+	i2s_write_reg(dev->i2s_base, IMR1, 0x00);
+
+	return 0;
+
+err_free_capture_irq:
+	dev_set_drvdata(&pdev->dev, NULL);
+	free_irq(dev->capture_irq, pdev);
+err_free_play_irq:
+	free_irq(dev->play_irq, pdev);
+err_iounmap_i2s:
+	iounmap(dev->i2s_base);
+err_clk_disable:
+	clk_disable(dev->clk);
+err_clk_put:
+	clk_put(dev->clk);
+err_kfree:
+	kfree(dev);
+err_release_mem_region:
+	release_mem_region(res->start, resource_size(res));
+	return ret;
+}
+
+static int spear13xx_i2s_remove(struct platform_device *pdev)
+{
+	struct spear13xx_i2s_dev *dev = dev_get_drvdata(&pdev->dev);
+
+	snd_soc_unregister_dai(&pdev->dev);
+	free_irq(dev->capture_irq, pdev);
+	free_irq(dev->play_irq, pdev);
+	iounmap(dev->i2s_base);
+	clk_disable(dev->clk);
+	clk_put(dev->clk);
+	kfree(dev);
+	release_mem_region(dev->res->start, resource_size(dev->res));
+
+	return 0;
+}
+
+static struct platform_driver spear13xx_i2s_driver = {
+	.probe		= spear13xx_i2s_probe,
+	.remove		= spear13xx_i2s_remove,
+	.driver		= {
+		.name	= "spear13xx-i2s",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init spear13xx_i2s_init(void)
+{
+	return platform_driver_register(&spear13xx_i2s_driver);
+}
+module_init(spear13xx_i2s_init);
+
+static void __exit spear13xx_i2s_exit(void)
+{
+	platform_driver_unregister(&spear13xx_i2s_driver);
+}
+module_exit(spear13xx_i2s_exit);
+
+MODULE_AUTHOR("Rajeev Kumar");
+MODULE_DESCRIPTION("SPEAr I2S SoC Interface");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:spear13xx-i2s");
sound/soc/spear/spear13xx-i2s.h new file +19 -0
new file mode 100644
index 0000000..26e2ea2
@@ -0,0 +1,19 @@
+/*
+ * ALSA SoC I2S Audio Layer for ST spear13xx processor
+ *
+ * sound/soc/spear/spear13xx-i2s.h
+ *
+ * Copyright (C) 2011 ST Microelectronics
+ * Rajeev Kumar <[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 SPEAR_I2S_H
+#define SPEAR_I2S_H
+
+void get_dma_start_addr(struct snd_pcm_substream *substream);
+
+#endif /*end if i2s header file */
sound/soc/spear/spear13xx-pcm.c new file +500 -0

500 lines not on this page · raw message

sound/soc/spear/spear13xx-pcm.h new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#3 lore raw

PATCH v4 3/5 sound: asoc: Adding support for SPEAr13XX ASoC machine driver

The patch adds support for SPEAr13XX machine driver.

---
 sound/soc/spear/evb_sta529.c |  121 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/spear/evb_sta529.c
sound/soc/spear/evb_sta529.c new file +121 -0
new file mode 100644
index 0000000..d43b433
@@ -0,0 +1,121 @@
+/*
+ * ASoC machine driver for spear platform
+ *
+ * sound/soc/spear/evb_sta529.c
+ *
+ * Copyright (C) 2011 ST Microelectronics
+ * Rajeev Kumar <[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.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/platform_device.h>
+#include <linux/timer.h>
+
+#include <mach/generic.h>
+#include <mach/misc_regs.h>
+
+#include <sound/core.h>
+#include <sound/pcm.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+
+#include "spear13xx-i2s.h"
+#include "spear13xx-pcm.h"
+
+static int
+sta529_evb_hw_params(struct snd_pcm_substream *substream,
+		struct snd_pcm_hw_params *params)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_dai *codec_dai = rtd->codec_dai;
+	int ret = 0;
+
+	/* set codec DAI configuration */
+	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
+			SND_SOC_DAIFMT_CBS_CFM);
+	return ret;
+
+}
+
+static struct snd_soc_ops sta529_evb_ops = {
+	.hw_params	= sta529_evb_hw_params,
+};
+
+/* spear digital audio interface glue - connects codec <--> CPU */
+static struct snd_soc_dai_link evb_dai = {
+	.name		= "SPEARSTA529",
+	.stream_name	= "I2S Audio",
+	.cpu_dai_name	= "spear13xx-i2s.0",
+	.platform_name	= "spear-pcm-audio",
+	.codec_dai_name	= "sta529-audio",
+	.codec_name	= "sta529.0-001a",
+	.ops		= &sta529_evb_ops,
+};
+
+/* spear audio machine driver */
+static struct snd_soc_card snd_soc_evb = {
+	.name		= "sta529",
+	.dai_link	= &evb_dai,
+	.num_links	= 1,
+};
+
+static __devinit int spear_evb_probe(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = &snd_soc_evb;
+	int ret;
+
+	card->dev = &pdev->dev;
+
+	ret = snd_soc_register_card(card);
+	if (ret) {
+		dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
+			ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int __devexit spear_evb_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+	snd_soc_unregister_card(card);
+
+	return 0;
+}
+
+static struct platform_driver evb_driver = {
+	.driver = {
+		.name = "sta529",
+		.owner = THIS_MODULE,
+		.pm = &snd_soc_pm_ops,
+	},
+	.probe = spear_evb_probe,
+	.remove = __devexit_p(spear_evb_remove),
+};
+
+static int __init spear_audio_init(void)
+{
+	return platform_driver_register(&evb_driver);
+}
+module_init(spear_audio_init);
+
+static void __exit spear_audio_exit(void)
+{
+	platform_driver_unregister(&evb_driver);
+}
+module_exit(spear_audio_exit);
+
+MODULE_DESCRIPTION("ST SPEAR EVB ASoC driver");
+MODULE_AUTHOR("Rajeev Kumar<[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:sta529");
Signature · 1 line
1.6.0.2
#4 lore raw

PATCH v4 4/5 sound: asoc: Adding Kconfig and Makefile to support SPEAr13XX ASoC driver

This patch adds Kconfig and Makefile to support SPEAr13XX ASoC driver

---
 sound/soc/spear/Kconfig  |   19 +++++++++++++++++++
 sound/soc/spear/Makefile |   12 ++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/spear/Kconfig
 create mode 100644 sound/soc/spear/Makefile
sound/soc/spear/Kconfig new file +19 -0
new file mode 100644
index 0000000..666f95f
@@ -0,0 +1,19 @@
+config SND_SOC_SPEAR_PCM
+	tristate "SoC Audio for the ST chip"
+	help
+	 Say Y or M if you want to add support for codecs attached to
+	 the I2S interface. You will also need
+	 to select the audio interfaces to support below.
+
+config SND_SOC_SPEAR_I2S
+	tristate
+
+config SND_SOC_SPEAR_EVM
+	tristate "SoC Audio support for Spear EVM"
+	depends on SND_SOC_SPEAR_PCM
+	select SND_SOC_SPEAR_I2S
+	select SND_SOC_STA529
+	help
+	 A driver for the EVM machine.
+	 Say Y if you want to select audio on ST SPEAR board
+
sound/soc/spear/Makefile new file +12 -0
new file mode 100644
index 0000000..cc0972e
@@ -0,0 +1,12 @@
+# SPEAR Platform Support
+snd-soc-pcm-objs := spear13xx-pcm.o
+snd-soc-i2s-objs := spear13xx-i2s.o
+
+obj-$(CONFIG_SND_SOC_SPEAR_PCM) += snd-soc-pcm.o
+obj-$(CONFIG_SND_SOC_SPEAR_I2S) += snd-soc-i2s.o
+
+# SPEAR Machine Support
+snd-soc-evb-objs := evb_sta529.o
+
+obj-$(CONFIG_SND_SOC_SPEAR_EVM) += snd-soc-evb.o
+
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH v4 5/5 sound: asoc: Adding support for SPEAr13XX in soc

This patch adds the SPEAr13XX support by updating the Kconfig and Makefile present in soc directory

---
 sound/soc/Kconfig  |    1 +
 sound/soc/Makefile |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
sound/soc/Kconfig +1 -0
index 8224db5..31cceca 100644
@@ -55,6 +55,7 @@ source "sound/soc/pxa/Kconfig"
 source "sound/soc/samsung/Kconfig"
 source "sound/soc/s6000/Kconfig"
 source "sound/soc/sh/Kconfig"
+source "sound/soc/spear/Kconfig"
 source "sound/soc/tegra/Kconfig"
 source "sound/soc/txx9/Kconfig"
 
sound/soc/Makefile +1 -0
index 1ed61c5..dd9c624 100644
@@ -18,5 +18,6 @@ obj-$(CONFIG_SND_SOC)	+= pxa/
 obj-$(CONFIG_SND_SOC)	+= samsung/
 obj-$(CONFIG_SND_SOC)	+= s6000/
 obj-$(CONFIG_SND_SOC)	+= sh/
+obj-$(CONFIG_SND_SOC)	+= spear/
 obj-$(CONFIG_SND_SOC)	+= tegra/
 obj-$(CONFIG_SND_SOC)	+= txx9/
Signature · 1 line
1.6.0.2
#6 lore raw

Re: [PATCH V4 4/5] sound: asoc: Adding Kconfig and Makefile to support SPEAr13XX ASoC driver

In reply to Rajeev Kumar

sound/soc/spear/Kconfig line 12

Quoted 2 lines · Rajeev Kumar
sound/soc/spear/Kconfig new file +2 -0
+config SND_SOC_SPEAR_EVM
+	tristate "SoC Audio support for Spear EVM"

The code doesn't seem to be able to make up its mind if the board is called "evb" or "evm" - this should be consistent.

#7 lore raw

Re: [PATCH V4 3/5] sound: asoc: Adding support for SPEAr13XX ASoC machine driver

In reply to Rajeev Kumar

sound/soc/spear/evb_sta529.c line 98

Quoted 3 lines · Rajeev Kumar
sound/soc/spear/evb_sta529.c new file +3 -0
+static struct platform_driver evb_driver = {
+	.driver = {
+		.name = "sta529",

This isn't a good name for the driver - the name should reflect the board. This looks like it should be a driver for the CODEC.

#8 lore raw

Re: [PATCH V4 2/5] sound: asoc: Adding support for SPEAr13XX ASoC platform driver

In reply to Rajeev Kumar

sound/soc/spear/spear13xx-i2s.h line 19

Quoted 7 lines · Rajeev Kumar
sound/soc/spear/spear13xx-i2s.h new file +7 -0
+
+#ifndef SPEAR_I2S_H
+#define SPEAR_I2S_H
+
+void get_dma_start_addr(struct snd_pcm_substream *substream);
+
+#endif /*end if i2s header file */

This needs to be namespaced.

#9 lore raw

Re: [PATCH V4 2/5] sound: asoc: Adding support for SPEAr13XX ASoC platform driver

In reply to Rajeev Kumar
Quoted 8 lines · Rajeev Kumar

This patch adds the support for the SPEAr13XX Platform Driver (I2S based) as per the ASoC framework.

SPEAr13XX internally uses a Designware I2S IP and some glue logic on top of the same.

---

snip

sound/soc/spear/spear13xx-pcm.c line 430

Quoted 5 lines
sound/soc/spear/spear13xx-pcm.c new file +5 -0
+}
+
+static int spear13xx_pcm_new(struct snd_card *card,
+               struct snd_soc_dai *dai, struct snd_pcm *pcm)
+{

Btw, this API call has recently been refactored to only accept 1 argument since you posted V4.

Thanks

Liam

#10 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

In reply to Rajeev Kumar
Quoted 13 lines · Rajeev Kumar

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

---
 sound/soc/codecs/Kconfig  |    5 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/sta529.c |  374 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/sta529.c

[...]

sound/soc/codecs/sta529.c line 97

Quoted 3 lines
sound/soc/codecs/sta529.c new file +3 -0
+
+struct sta529 {
+	unsigned int sysclk;

sysclk is unused

sound/soc/codecs/sta529.c line 99

Quoted 2 lines
sound/soc/codecs/sta529.c new file +2 -0
+	enum snd_soc_control_type control_type;
+	void *control_data;

control_data is unused

Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+};
+
+static const char *pwm_mode_text[] = { "binary", "headphone", "ternary",
+	"phase-shift"};
+static const char *interface_mode_text[] = { "slave", "master"};

sound/soc/codecs/sta529.c line 114

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+
+static const struct soc_enum pwm_src_enum =
+SOC_ENUM_SINGLE(STA529_FFXCFG1, 4, 4, pwm_mode_text);
+
+static const struct soc_enum mode_src_enum =
+SOC_ENUM_SINGLE(STA529_P2SCFG0, 0, 2, interface_mode_text);
+
+static const struct snd_kcontrol_new sta529_new_snd_controls[] = {
+	SOC_ENUM("PWM Select", pwm_src_enum),
+	SOC_ENUM("MODE Select", mode_src_enum),

The mode should be configured by the dai_drivers set_fmt callback, and not by a control.

Quoted 50 lines
sound/soc/codecs/sta529.c new file +50 -0
+};
+
+static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -9150, 50, 0);
+static const DECLARE_TLV_DB_SCALE(master_vol_tlv, -12750, 50, 0);
+
+static const struct snd_kcontrol_new sta529_snd_controls[] = {
+	SOC_DOUBLE_R_TLV("Digital Playback Volume", STA529_LVOL, STA529_RVOL, 0,
+			127, 0, out_gain_tlv),
+	SOC_SINGLE_TLV("Master Playback Volume", STA529_MVOL, 0, 127, 1,
+			master_vol_tlv),
+};
+
+static int sta529_hw_params(struct snd_pcm_substream *substream,
+		struct snd_pcm_hw_params *params,
+		struct snd_soc_dai *dai)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_codec *codec = rtd->codec;
+	int pdata = 0;
+
+	switch (params_format(params)) {
+	case SNDRV_PCM_FORMAT_S16_LE:
+		pdata = 1;
+		break;
+	case SNDRV_PCM_FORMAT_S24_LE:
+		pdata = 2;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		pdata = 3;
+		break;
+	}
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		snd_soc_update_bits(codec, STA529_S2PCFG1, 0xC0, (pdata << 6));
+	else
+		snd_soc_update_bits(codec, STA529_P2SCFG1, 0xC0, (pdata << 6));
+
+	return 0;
+}
+
+static int sta529_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	u8 mode = 0;
+
+	/* interface format */
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_LEFT_J:
+		mode = LEFT_J_DATA_FORMAT;
+		break;
+	case SND_SOC_DAIFMT_I2S:

sound/soc/codecs/sta529.c line 174

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+		mode = I2S_DATA_FORMAT;
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		mode = RIGHT_J_DATA_FORMAT;
+		break;
+	default:
+		return -EINVAL;
+	}
+	mode |= 0x20;
+	snd_soc_update_bits(codec, STA529_S2PCFG0, 0xE0, mode);

What about the P2SCFG0 register, I would suspect, that the same data needs to be written to it.

Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+
+	return 0;
+}
+

sound/soc/codecs/sta529.c line 188

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+static int sta529_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+
+	u8 mute_reg = snd_soc_read(codec, STA529_FFXCFG0) & ~CODEC_MUTE_VAL;
+
+	if (mute)
+		mute_reg |= CODEC_MUTE_VAL;
+
+	snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, 00);

I guess, it should be mute_reg instead of 00

Quoted 27 lines
sound/soc/codecs/sta529.c new file +27 -0
+
+	return 0;
+}
+
+static int
+sta529_set_bias_level(struct snd_soc_codec *codec,
+		enum snd_soc_bias_level level)
+{
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+	case SND_SOC_BIAS_PREPARE:
+		snd_soc_update_bits(codec, STA529_FFXCFG0, POWER_CNTLMSAK,
+				POWER_UP);
+		snd_soc_update_bits(codec, STA529_MISC, 1, 0x01);
+		break;
+	case SND_SOC_BIAS_STANDBY:
+	case SND_SOC_BIAS_OFF:
+		snd_soc_update_bits(codec, STA529_FFXCFG0, POWER_CNTLMSAK,
+				POWER_STDBY);
+		/* Making FFX output to zero */
+		snd_soc_update_bits(codec, STA529_FFXCFG0, FFX_MASK,
+				FFX_OFF);
+		snd_soc_update_bits(codec, STA529_MISC, 1, 0x00);
+
+		break;
+	}
+

sound/soc/codecs/sta529.c line 225

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+	/*
+	 * store the label for powers down audio subsystem for suspend.This is
+	 * used by soc core layer
+	 */
+	codec->dapm.bias_level = level;
+	return 0;
+
+}
+
+static struct snd_soc_dai_ops sta529_dai_ops = {

Can be const

sound/soc/codecs/sta529.c line 255

Quoted 13 lines
sound/soc/codecs/sta529.c new file +12 -0
+	.hw_params	=	sta529_hw_params,
+	.set_fmt	=	sta529_set_dai_fmt,
+	.digital_mute	=	sta529_mute,
+};
+
[..]
+
+static int sta529_probe(struct snd_soc_codec *codec)
+{
+	struct sta529 *sta529 = snd_soc_codec_get_drvdata(codec);
+	int ret;
+
+	ret = snd_soc_codec_set_cache_io(codec, 8, 8, sta529->control_type);

If your codec only supports I2C, you can pass SND_SOC_I2C here directly and get rid of the control_type field.

sound/soc/codecs/sta529.c line 266

Quoted 11 lines
sound/soc/codecs/sta529.c new file +11 -0
+	if (ret < 0) {
+		dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+		return ret;
+	}
+	sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+
+	snd_soc_add_controls(codec, sta529_snd_controls,
+			ARRAY_SIZE(sta529_snd_controls));
+
+	snd_soc_add_controls(codec, sta529_new_snd_controls,
+			ARRAY_SIZE(sta529_new_snd_controls));

You should use table based controls setup. i.e assign the control table to the 'controls' field of your codec_driver.

Quoted 54 lines
sound/soc/codecs/sta529.c new file +54 -0
+	return 0;
+}
+
+/* power down chip */
+static int sta529_remove(struct snd_soc_codec *codec)
+{
+	sta529_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+	return 0;
+}
+
+static int sta529_suspend(struct snd_soc_codec *codec, pm_message_t state)
+{
+	sta529_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+	return 0;
+}
+
+static int sta529_resume(struct snd_soc_codec *codec)
+{
+	snd_soc_cache_sync(codec);
+	sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+	sta529_set_bias_level(codec, codec->dapm.suspend_bias_level);
+
+	return 0;
+}
+
+struct snd_soc_codec_driver soc_codec_dev_sta529 = {
+	.probe = sta529_probe,
+	.remove = sta529_remove,
+	.set_bias_level = sta529_set_bias_level,
+	.suspend = sta529_suspend,
+	.resume = sta529_resume,
+	.reg_cache_size = STA529_CACHEREGNUM,
+	.reg_word_size = sizeof(u8),
+	.reg_cache_default = sta529_reg,
+
+};
+
+static __devinit int sta529_i2c_probe(struct i2c_client *i2c,
+		const struct i2c_device_id *id)
+{
+	struct sta529 *sta529;
+	int ret;
+
+	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+		return -EINVAL;
+
+	sta529 = kzalloc(sizeof(struct sta529), GFP_KERNEL);
+	if (sta529 == NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, sta529);
+	sta529->control_data = i2c;

sound/soc/codecs/sta529.c line 330

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+	sta529->control_type = SND_SOC_I2C;
+
+	ret = snd_soc_register_codec(&i2c->dev,
+			&soc_codec_dev_sta529, &sta529_dai, 1);
+	if (ret < 0)
+		kfree(sta529);
+	return ret;
+}
+
+static int sta529_i2c_remove(struct i2c_client *client)

__devexit

sound/soc/codecs/sta529.c line 336

Quoted 7 lines
sound/soc/codecs/sta529.c new file +6 -0
+{
+	snd_soc_unregister_codec(&client->dev);
+	kfree(i2c_get_clientdata(client));
+	return 0;
+}
+
[...]

Your driver doesn't use any DAPM. You should at least define input and output pins and their routing, but I would expect that there is more that can be done, like dynamicly powering unused sections of the codec down, like the DAC or ADC.

author
#11 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

Hi Lars-Peter Clausen
Please find my answer inline below.

Quoted 13 lines · Lars-Peter Clausen
Quoted 12 lines · Rajeev Kumar

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

---
 sound/soc/codecs/Kconfig  |    5 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/sta529.c |  374 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/sta529.c
Quoted 9 lines

sound/soc/codecs/sta529.c line 97

Quoted 4 lines

[...]

sound/soc/codecs/sta529.c new file +3 -0
+
+struct sta529 {
+	unsigned int sysclk;

sysclk is unused

sound/soc/codecs/sta529.c line 99

Quoted 2 lines
sound/soc/codecs/sta529.c new file +2 -0
+	enum snd_soc_control_type control_type;
+	void *control_data;

control_data is unused

Oops, will be removed.

Quoted 10 lines
Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+};
+
+static const char *pwm_mode_text[] = { "binary", "headphone", "ternary",
+	"phase-shift"};
+static const char *interface_mode_text[] = { "slave", "master"};
+
+static const struct soc_enum pwm_src_enum =
+SOC_ENUM_SINGLE(STA529_FFXCFG1, 4, 4, pwm_mode_text);
+
+static const struct soc_enum mode_src_enum =
Quoted 9 lines

sound/soc/codecs/sta529.c line 114

Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+SOC_ENUM_SINGLE(STA529_P2SCFG0, 0, 2, interface_mode_text);
+
+static const struct snd_kcontrol_new sta529_new_snd_controls[] = {
+	SOC_ENUM("PWM Select", pwm_src_enum),
+	SOC_ENUM("MODE Select", mode_src_enum),

The mode should be configured by the dai_drivers set_fmt callback, and not by a control.

I think giving a interface to the user is better option rather than doing it in set_fmt callback.

Quoted 54 lines
Quoted 54 lines
sound/soc/codecs/sta529.c new file +54 -0
+};
+
+static const DECLARE_TLV_DB_SCALE(out_gain_tlv, -9150, 50, 0);
+static const DECLARE_TLV_DB_SCALE(master_vol_tlv, -12750, 50, 0);
+
+static const struct snd_kcontrol_new sta529_snd_controls[] = {
+	SOC_DOUBLE_R_TLV("Digital Playback Volume", STA529_LVOL, STA529_RVOL, 0,
+			127, 0, out_gain_tlv),
+	SOC_SINGLE_TLV("Master Playback Volume", STA529_MVOL, 0, 127, 1,
+			master_vol_tlv),
+};
+
+static int sta529_hw_params(struct snd_pcm_substream *substream,
+		struct snd_pcm_hw_params *params,
+		struct snd_soc_dai *dai)
+{
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	struct snd_soc_codec *codec = rtd->codec;
+	int pdata = 0;
+
+	switch (params_format(params)) {
+	case SNDRV_PCM_FORMAT_S16_LE:
+		pdata = 1;
+		break;
+	case SNDRV_PCM_FORMAT_S24_LE:
+		pdata = 2;
+		break;
+	case SNDRV_PCM_FORMAT_S32_LE:
+		pdata = 3;
+		break;
+	}
+	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+		snd_soc_update_bits(codec, STA529_S2PCFG1, 0xC0, (pdata << 6));
+	else
+		snd_soc_update_bits(codec, STA529_P2SCFG1, 0xC0, (pdata << 6));
+
+	return 0;
+}
+
+static int sta529_set_dai_fmt(struct snd_soc_dai *codec_dai, u32 fmt)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	u8 mode = 0;
+
+	/* interface format */
+	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_LEFT_J:
+		mode = LEFT_J_DATA_FORMAT;
+		break;
+	case SND_SOC_DAIFMT_I2S:
+		mode = I2S_DATA_FORMAT;
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		mode = RIGHT_J_DATA_FORMAT;
Quoted 9 lines

sound/soc/codecs/sta529.c line 174

Quoted 6 lines
sound/soc/codecs/sta529.c new file +6 -0
+		break;
+	default:
+		return -EINVAL;
+	}
+	mode |= 0x20;
+	snd_soc_update_bits(codec, STA529_S2PCFG0, 0xE0, mode);

What about the P2SCFG0 register, I would suspect, that the same data needs to be written to it.

Yes we need to update this.

Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/sta529.c new file +7 -0
+
+	return 0;
+}
+
+static int sta529_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
Quoted 9 lines

sound/soc/codecs/sta529.c line 188

Quoted 7 lines
sound/soc/codecs/sta529.c new file +7 -0
+
+	u8 mute_reg = snd_soc_read(codec, STA529_FFXCFG0) & ~CODEC_MUTE_VAL;
+
+	if (mute)
+		mute_reg |= CODEC_MUTE_VAL;
+
+	snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, 00);

I guess, it should be mute_reg instead of 00

No, This is value, register is STA529_FFXCFG0

Quoted 30 lines
Quoted 30 lines
sound/soc/codecs/sta529.c new file +30 -0
+
+	return 0;
+}
+
+static int
+sta529_set_bias_level(struct snd_soc_codec *codec,
+		enum snd_soc_bias_level level)
+{
+	switch (level) {
+	case SND_SOC_BIAS_ON:
+	case SND_SOC_BIAS_PREPARE:
+		snd_soc_update_bits(codec, STA529_FFXCFG0, POWER_CNTLMSAK,
+				POWER_UP);
+		snd_soc_update_bits(codec, STA529_MISC, 1, 0x01);
+		break;
+	case SND_SOC_BIAS_STANDBY:
+	case SND_SOC_BIAS_OFF:
+		snd_soc_update_bits(codec, STA529_FFXCFG0, POWER_CNTLMSAK,
+				POWER_STDBY);
+		/* Making FFX output to zero */
+		snd_soc_update_bits(codec, STA529_FFXCFG0, FFX_MASK,
+				FFX_OFF);
+		snd_soc_update_bits(codec, STA529_MISC, 1, 0x00);
+
+		break;
+	}
+
+	/*
+	 * store the label for powers down audio subsystem for suspend.This is
+	 * used by soc core layer
Quoted 8 lines

sound/soc/codecs/sta529.c line 225

Quoted 7 lines
sound/soc/codecs/sta529.c new file +7 -0
+	 */
+	codec->dapm.bias_level = level;
+	return 0;
+
+}
+
+static struct snd_soc_dai_ops sta529_dai_ops = {

Can be const

It can not be. Please check snd_soc_dai_ops structure in include/sound/soc-dai.h

Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/sta529.c new file +6 -0
+	.hw_params	=	sta529_hw_params,
+	.set_fmt	=	sta529_set_dai_fmt,
+	.digital_mute	=	sta529_mute,
+};
+
[..]
+
Quoted 9 lines

sound/soc/codecs/sta529.c line 255

Quoted 6 lines
sound/soc/codecs/sta529.c new file +6 -0
+static int sta529_probe(struct snd_soc_codec *codec)
+{
+	struct sta529 *sta529 = snd_soc_codec_get_drvdata(codec);
+	int ret;
+
+	ret = snd_soc_codec_set_cache_io(codec, 8, 8, sta529->control_type);

If your codec only supports I2C, you can pass SND_SOC_I2C here directly and get rid of the control_type field.

ok

Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+	if (ret < 0) {
+		dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
+		return ret;
+	}
+	sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
Quoted 9 lines

sound/soc/codecs/sta529.c line 266

Quoted 6 lines
sound/soc/codecs/sta529.c new file +6 -0
+
+	snd_soc_add_controls(codec, sta529_snd_controls,
+			ARRAY_SIZE(sta529_snd_controls));
+
+	snd_soc_add_controls(codec, sta529_new_snd_controls,
+			ARRAY_SIZE(sta529_new_snd_controls));

You should use table based controls setup. i.e assign the control table to the 'controls' field of your codec_driver.

You can do it in either way.

Quoted 65 lines
Quoted 54 lines
sound/soc/codecs/sta529.c new file +54 -0
+	return 0;
+}
+
+/* power down chip */
+static int sta529_remove(struct snd_soc_codec *codec)
+{
+	sta529_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+	return 0;
+}
+
+static int sta529_suspend(struct snd_soc_codec *codec, pm_message_t state)
+{
+	sta529_set_bias_level(codec, SND_SOC_BIAS_OFF);
+
+	return 0;
+}
+
+static int sta529_resume(struct snd_soc_codec *codec)
+{
+	snd_soc_cache_sync(codec);
+	sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+	sta529_set_bias_level(codec, codec->dapm.suspend_bias_level);
+
+	return 0;
+}
+
+struct snd_soc_codec_driver soc_codec_dev_sta529 = {
+	.probe = sta529_probe,
+	.remove = sta529_remove,
+	.set_bias_level = sta529_set_bias_level,
+	.suspend = sta529_suspend,
+	.resume = sta529_resume,
+	.reg_cache_size = STA529_CACHEREGNUM,
+	.reg_word_size = sizeof(u8),
+	.reg_cache_default = sta529_reg,
+
+};
+
+static __devinit int sta529_i2c_probe(struct i2c_client *i2c,
+		const struct i2c_device_id *id)
+{
+	struct sta529 *sta529;
+	int ret;
+
+	if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+		return -EINVAL;
+
+	sta529 = kzalloc(sizeof(struct sta529), GFP_KERNEL);
+	if (sta529 == NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, sta529);
+	sta529->control_data = i2c;

sound/soc/codecs/sta529.c line 330

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+	sta529->control_type = SND_SOC_I2C;
+
+	ret = snd_soc_register_codec(&i2c->dev,
+			&soc_codec_dev_sta529, &sta529_dai, 1);
+	if (ret < 0)
+		kfree(sta529);
+	return ret;
+}
+
+static int sta529_i2c_remove(struct i2c_client *client)

__devexit

Quoted 13 lines

sound/soc/codecs/sta529.c line 336

Quoted 7 lines
sound/soc/codecs/sta529.c new file +6 -0
+{
+	snd_soc_unregister_codec(&client->dev);
+	kfree(i2c_get_clientdata(client));
+	return 0;
+}
+
[...]

Your driver doesn't use any DAPM. You should at least define input and output pins and their routing, but I would expect that there is more that can be done, like dynamicly powering unused sections of the codec down, like the DAC or ADC. .

Right now since my driver has not support for DAPM, so definitions for input and output pins are not there.Once I will implement DAPM feature in future I will send separate patch for that.

Best Rgds
Rajeev

#12 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

Quoted 26 lines · rajeev

Hi Lars-Peter Clausen
Please find my answer inline below.

Quoted 13 lines · Lars-Peter Clausen
Quoted 12 lines · Rajeev Kumar

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

---
 sound/soc/codecs/Kconfig  |    5 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/sta529.c |  374 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/sta529.c
Quoted 9 lines

sound/soc/codecs/sta529.c line 114

Quoted 5 lines

[...]

sound/soc/codecs/sta529.c new file +4 -0
+
+static const struct snd_kcontrol_new sta529_new_snd_controls[] = {
+	SOC_ENUM("PWM Select", pwm_src_enum),
+	SOC_ENUM("MODE Select", mode_src_enum),

The mode should be configured by the dai_drivers set_fmt callback, and not by a control.

Quoted 1 line

I think giving a interface to the user is better option rather than doing it in set_fmt callback.

Why? Both the codec_dai and the cpu_dai have to agree on who is the master and who is the slave. So letting the user select the codec mode instead of defining it in the board driver doesn't make sense, since the setup will stop working if the cpu dai isn't configured to match the codec dais mode. Furthermore you don't want to switch the mode while playback is active and generally you won't even change it at all, once it has been setup.

Quoted 14 lines

[...[

Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+
+static int sta529_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
Quoted 9 lines

sound/soc/codecs/sta529.c line 188

Quoted 7 lines
sound/soc/codecs/sta529.c new file +7 -0
+
+	u8 mute_reg = snd_soc_read(codec, STA529_FFXCFG0) & ~CODEC_MUTE_VAL;
+
+	if (mute)
+		mute_reg |= CODEC_MUTE_VAL;
+
+	snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, 00);

I guess, it should be mute_reg instead of 00

Quoted 1 line

No, This is value, register is STA529_FFXCFG0

You are always clearing the mute bit, regardless of whether mute is enabled or disabled.
snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, mute_reg); is probably what you want to do.

Quoted 4 lines

[...]

Quoted 2 lines
Quoted 1 line

+static struct snd_soc_dai_ops sta529_dai_ops = {

Can be const

It can not be. Please check snd_soc_dai_ops structure in include/sound/soc-dai.h

Yes, it can. Maybe you are using an outdated ASoC version. Check line 206 of include/sound/soc-dai.h in Mark's for-next branch.

Quoted 11 lines

[...]

Quoted 9 lines

sound/soc/codecs/sta529.c line 266

Quoted 6 lines
sound/soc/codecs/sta529.c new file +6 -0
+
+	snd_soc_add_controls(codec, sta529_snd_controls,
+			ARRAY_SIZE(sta529_snd_controls));
+
+	snd_soc_add_controls(codec, sta529_new_snd_controls,
+			ARRAY_SIZE(sta529_new_snd_controls));

You should use table based controls setup. i.e assign the control table to the 'controls' field of your codec_driver.

You can do it in either way.

Yes, you can, but you should use the codec_driver fields unless you have good reasoning not to.

Quoted 10 lines
Quoted 7 lines
Quoted 1 line

[...]

Your driver doesn't use any DAPM. You should at least define input and output pins and their routing, but I would expect that there is more that can be done, like dynamicly powering unused sections of the codec down, like the DAC or ADC. .

Right now since my driver has not support for DAPM, so definitions for input and output pins are not there.Once I will implement DAPM feature in future I will send separate patch for that.

Currently there is a bug in the ASoC core, which will cause codec drivers without DAPM to be not powered down, even though if they are not used. Given that it will maybe take 5 minutes or so to add basic DAPM (Input/Output pins and ADC/DAC) it would be a good idea to add it to the inital version of the driver.

- Lars

author
#13 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

Hi Lars

Quoted 27 lines · Lars-Peter Clausen
Quoted 26 lines · rajeev

Hi Lars-Peter Clausen
Please find my answer inline below.

Quoted 22 lines · Lars-Peter Clausen
Quoted 13 lines · Rajeev Kumar

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

---
 sound/soc/codecs/Kconfig  |    5 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/sta529.c |  374 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 381 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/sta529.c

[...]

sound/soc/codecs/sta529.c line 114

Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+
+static const struct snd_kcontrol_new sta529_new_snd_controls[] = {
+	SOC_ENUM("PWM Select", pwm_src_enum),
+	SOC_ENUM("MODE Select", mode_src_enum),

The mode should be configured by the dai_drivers set_fmt callback, and not by a control.

Quoted 8 lines
Quoted 1 line

I think giving a interface to the user is better option rather than doing it in set_fmt callback.

Why? Both the codec_dai and the cpu_dai have to agree on who is the master and who is the slave. So letting the user select the codec mode instead of defining it in the board driver doesn't make sense, since the setup will stop working if the cpu dai isn't configured to match the codec dais mode. Furthermore you don't want to switch the mode while playback is active and generally you won't even change it at all, once it has been setup.

Ok.

Quoted 14 lines
Quoted 14 lines

[...[

Quoted 13 lines

sound/soc/codecs/sta529.c line 188

Quoted 11 lines
sound/soc/codecs/sta529.c new file +11 -0
+
+static int sta529_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+
+	u8 mute_reg = snd_soc_read(codec, STA529_FFXCFG0) & ~CODEC_MUTE_VAL;
+
+	if (mute)
+		mute_reg |= CODEC_MUTE_VAL;
+
+	snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, 00);

I guess, it should be mute_reg instead of 00

Quoted 7 lines
Quoted 1 line

No, This is value, register is STA529_FFXCFG0

You are always clearing the mute bit, regardless of whether mute is enabled or disabled.
snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, mute_reg); is probably what you want to do.

Ok will be corrected in next patch

Quoted 8 lines
Quoted 4 lines

[...]

Quoted 2 lines
Quoted 1 line

+static struct snd_soc_dai_ops sta529_dai_ops = {

Can be const

It can not be. Please check snd_soc_dai_ops structure in include/sound/soc-dai.h

Yes, it can. Maybe you are using an outdated ASoC version. Check line 206 of include/sound/soc-dai.h in Mark's for-next branch.

Ok.

Quoted 10 lines
Quoted 10 lines

[...]

Quoted 9 lines

sound/soc/codecs/sta529.c line 266

Quoted 6 lines
sound/soc/codecs/sta529.c new file +6 -0
+
+	snd_soc_add_controls(codec, sta529_snd_controls,
+			ARRAY_SIZE(sta529_snd_controls));
+
+	snd_soc_add_controls(codec, sta529_new_snd_controls,
+			ARRAY_SIZE(sta529_new_snd_controls));

You should use table based controls setup. i.e assign the control table to the 'controls' field of your codec_driver.

Quoted 3 lines
Quoted 1 line

You can do it in either way.

Yes, you can, but you should use the codec_driver fields unless you have good reasoning not to.

could you please suggest any driver for refrence?

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

[...]

Your driver doesn't use any DAPM. You should at least define input and output pins and their routing, but I would expect that there is more that can be done, like dynamicly powering unused sections of the codec down, like the DAC or ADC. .

Right now since my driver has not support for DAPM, so definitions for input and output pins are not there.Once I will implement DAPM feature in future I will send separate patch for that.

Quoted 6 lines

Currently there is a bug in the ASoC core, which will cause codec drivers without DAPM to be not powered down, even though if they are not used. Given that it will maybe take 5 minutes or so to add basic DAPM (Input/Output pins and ADC/DAC) it would be a good idea to add it to the inital version of the driver.

OK,I Wlll.
Please check the steps I need to do for dapm update.

1. static const struct snd_soc_dapm_widget sta529_dapm_widgets[] = {
	SND_SOC_DAPM_ADC("ADC", "Capture", STA529_ADCCGF, 3, 0),
	
	SND_SOC_DAPM_OUTPUT("HPL"),
        SND_SOC_DAPM_OUTPUT("HPR"),
    	SND_SOC_DAPM_OUTPUT("SPKL"),
	SND_SOC_DAPM_OUTPUT("SPKR"),

	SND_SOC_DAPM_INPUT("MIC1"),
};
2. static const struct snd_soc_dapm_route sat529_audio_map[] = {
      {"ADC", NULL, " ADC Mixer"},
      
      {"HPL", NULL, "HP Left Out"},
      {"HPR", NULL, "HP Right Out"},
      {"SPKL", NULL, "SPK Left Out"},
      {"SPKR", NULL, "SPK Right Out"},                 
      {"Left HP Mixer", "MIC Switch", "MIC Input"},
};
3. struct snd_soc_codec_driver soc_codec_dev_sta529 = {
       .probe = sta529_probe,
       .remove = sta529_remove,
       .set_bias_level = sta529_set_bias_level,
       .suspend = sta529_suspend,
       .resume = sta529_resume,
       .reg_cache_size = STA529_CACHEREGNUM,
       .reg_word_size = sizeof(u8),
       .reg_cache_default = sta529_reg,
       .dapm_widgets = sta529_dapm_widgets,
       .num_dapm_widgets = ARRAY_SIZE(sta529_dapm_widgets),
       .dapm_routes = sta529_audio_map,
       .num_dapm_routes = ARRAY_SIZE(sta529_audio_map),

};
Please let me know is it fine for you?

Best Rgds
Rajeev

Quoted 3 lines

- Lars
.

#14 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

Quoted 7 lines · rajeev

Hi Lars

[...]
OK,I Wlll.
Please check the steps I need to do for dapm update.

1. static const struct snd_soc_dapm_widget sta529_dapm_widgets[] = {
	SND_SOC_DAPM_ADC("ADC", "Capture", STA529_ADCCGF, 3, 0),

Even if your DAC itself does not support dynamic power management you probably still want to define it. Use SND_SOC_NOPM as the register value in this case. This will allow DAPM determine, whether the outputs are active or not. i.e. if there is audio playback on the DACs stream, DAPM will know that the outputs connected to the DAC are active. This will allow for example to turn speakers connected to the outputs dynamically on or off based on DAPM events.

Quoted 19 lines
	
	SND_SOC_DAPM_OUTPUT("HPL"),
        SND_SOC_DAPM_OUTPUT("HPR"),
    	SND_SOC_DAPM_OUTPUT("SPKL"),
	SND_SOC_DAPM_OUTPUT("SPKR"),

	SND_SOC_DAPM_INPUT("MIC1"),
};
2. static const struct snd_soc_dapm_route sat529_audio_map[] = {
      {"ADC", NULL, " ADC Mixer"},
      
      {"HPL", NULL, "HP Left Out"},
      {"HPR", NULL, "HP Right Out"},
      {"SPKL", NULL, "SPK Left Out"},
      {"SPKR", NULL, "SPK Right Out"},                 
      {"Left HP Mixer", "MIC Switch", "MIC Input"},
};
Quoted 2 lines

[...]
Please let me know is it fine for you?

Your routinges seem to be a bit off. You use path elements which are not defined in your widget list, like "HP Left Out", "MIC Switch", ... Since your codec seems to be quite simple, I guess what you basically want to do is route all inputs to the ADC and route the DAC to all outputs, without any mixers or switches in between.

- Lars

#15 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

In reply to Rajeev Kumar
Quoted 3 lines · Rajeev Kumar

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

As I'm fairly sure I've said before please do try to use subject lines for your patches which are consistent with the style for the subsystem you're submitting against.

sound/soc/codecs/sta529.c line 99

Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+struct sta529 {
+	unsigned int sysclk;
+	enum snd_soc_control_type control_type;
+	void *control_data;

why do you need the control_data here? You also don't need to pass the control_type if the device is I2C only.

sound/soc/codecs/sta529.c line 114

Quoted 3 lines
sound/soc/codecs/sta529.c new file +3 -0
+static const struct snd_kcontrol_new sta529_new_snd_controls[] = {
+	SOC_ENUM("PWM Select", pwm_src_enum),
+	SOC_ENUM("MODE Select", mode_src_enum),

MODE especially should be configured by _dai_fmt().

sound/soc/codecs/sta529.c line 188

Quoted 10 lines
sound/soc/codecs/sta529.c new file +10 -0
+static int sta529_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+
+	u8 mute_reg = snd_soc_read(codec, STA529_FFXCFG0) & ~CODEC_MUTE_VAL;
+
+	if (mute)
+		mute_reg |= CODEC_MUTE_VAL;
+
+	snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, 00);

This update completely ignores the check you've made above...

sound/soc/codecs/sta529.c line 219

Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+	/*
+	 * store the label for powers down audio subsystem for suspend.This is
+	 * used by soc core layer
+	 */

You want a space after the period here.

sound/soc/codecs/sta529.c line 232

Quoted 2 lines
sound/soc/codecs/sta529.c new file +2 -0
+static struct snd_soc_dai_driver sta529_dai = {
+	.name = "sta529-audio",

Does the chip have non-audio funtionality?

sound/soc/codecs/sta529.c line 266

Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+	snd_soc_add_controls(codec, sta529_snd_controls,
+			ARRAY_SIZE(sta529_snd_controls));
+
+	snd_soc_add_controls(codec, sta529_new_snd_controls,
+			ARRAY_SIZE(sta529_new_snd_controls));

Like Lars-Peter said use data based init here.

sound/soc/codecs/sta529.c line 289

Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+static int sta529_resume(struct snd_soc_codec *codec)
+{
+	snd_soc_cache_sync(codec);
+	sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+	sta529_set_bias_level(codec, codec->dapm.suspend_bias_level);

The second set_bias_level() should be redundant - we'll always have been shut down by the core before we get to suspending.

sound/soc/codecs/sta529.c line 359

Quoted 7 lines
sound/soc/codecs/sta529.c new file +7 -0
+static int __init sta529_modinit(void)
+{
+	int ret = 0;
+
+	ret = i2c_add_driver(&sta529_i2c_driver);
+	if (ret != 0)
+		printk(KERN_ERR "Failed to reg sta529 I2C driver: %d\n", ret);

Error out if we can't load; ignoring the error only makes sense if we have multiple bus types and another might have succeeded.

author
#16 lore raw

Re: [PATCH V4 1/5] sound: asoc: Adding support for STA529 Audio Codec

Hi Mark

Quoted 9 lines · Mark Brown
Quoted 3 lines · Rajeev Kumar

This patch adds the support for STA529 audio codec. Details of the audio codec can be seen here:
http://www.st.com/internet/imag_video/product/159187.jsp

As I'm fairly sure I've said before please do try to use subject lines for your patches which are consistent with the style for the subsystem you're submitting against.

Ok,do You mean like,
ASoC: Add STA529 codec support

Quoted 8 lines

sound/soc/codecs/sta529.c line 99

Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+struct sta529 {
+	unsigned int sysclk;
+	enum snd_soc_control_type control_type;
+	void *control_data;

why do you need the control_data here? You also don't need to pass the control_type if the device is I2C only.

Will be removed

Quoted 6 lines

sound/soc/codecs/sta529.c line 114

Quoted 3 lines
sound/soc/codecs/sta529.c new file +3 -0
+static const struct snd_kcontrol_new sta529_new_snd_controls[] = {
+	SOC_ENUM("PWM Select", pwm_src_enum),
+	SOC_ENUM("MODE Select", mode_src_enum),

MODE especially should be configured by _dai_fmt().

OK

Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/sta529.c new file +4 -0
+static int sta529_mute(struct snd_soc_dai *dai, int mute)
+{
+	struct snd_soc_codec *codec = dai->codec;
+
Quoted 8 lines

sound/soc/codecs/sta529.c line 188

Quoted 6 lines
sound/soc/codecs/sta529.c new file +6 -0
+	u8 mute_reg = snd_soc_read(codec, STA529_FFXCFG0) & ~CODEC_MUTE_VAL;
+
+	if (mute)
+		mute_reg |= CODEC_MUTE_VAL;
+
+	snd_soc_update_bits(codec, STA529_FFXCFG0, 0x80, 00);

This update completely ignores the check you've made above...

It should be mute_reg instead of 00

Quoted 8 lines

sound/soc/codecs/sta529.c line 219

Quoted 5 lines
sound/soc/codecs/sta529.c new file +4 -0
+	/*
+	 * store the label for powers down audio subsystem for suspend.This is
+	 * used by soc core layer
+	 */

You want a space after the period here.

OK

Quoted 5 lines

sound/soc/codecs/sta529.c line 232

Quoted 2 lines
sound/soc/codecs/sta529.c new file +2 -0
+static struct snd_soc_dai_driver sta529_dai = {
+	.name = "sta529-audio",

Does the chip have non-audio funtionality?

No, you mean name to be changed to sta529.

Quoted 8 lines

sound/soc/codecs/sta529.c line 266

Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+	snd_soc_add_controls(codec, sta529_snd_controls,
+			ARRAY_SIZE(sta529_snd_controls));
+
+	snd_soc_add_controls(codec, sta529_new_snd_controls,
+			ARRAY_SIZE(sta529_new_snd_controls));

Like Lars-Peter said use data based init here.

ok

Quoted 9 lines

sound/soc/codecs/sta529.c line 289

Quoted 5 lines
sound/soc/codecs/sta529.c new file +5 -0
+static int sta529_resume(struct snd_soc_codec *codec)
+{
+	snd_soc_cache_sync(codec);
+	sta529_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
+	sta529_set_bias_level(codec, codec->dapm.suspend_bias_level);

The second set_bias_level() should be redundant - we'll always have been shut down by the core before we get to suspending.

sta529_set_bias_level(codec, codec->dapm.suspend_bias_level) is not required

Quoted 12 lines

sound/soc/codecs/sta529.c line 359

Quoted 7 lines
sound/soc/codecs/sta529.c new file +7 -0
+static int __init sta529_modinit(void)
+{
+	int ret = 0;
+
+	ret = i2c_add_driver(&sta529_i2c_driver);
+	if (ret != 0)
+		printk(KERN_ERR "Failed to reg sta529 I2C driver: %d\n", ret);

Error out if we can't load; ignoring the error only makes sense if we have multiple bus types and another might have succeeded. .

Sorry I have not got the point.
Best Rgds
Rajeev