Skip to contentSkip to conversation

kirkwood openrd client audio support

PATCH In review [email protected] 6 participants 23 messages May 11, 2010 – May 13, 2010

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

cover kirkwood openrd client audio support

This patchset aims at adding ASoC support to ARM kirkwood systems and more precisely to openrd client boards.

Arnaud Patard

#1 lore raw

PATCH 1/6 kirkwood: add audio functions.

This patch add audio related definitions and functions

---

 arch/arm/mach-kirkwood/common.c                |    9 	9 +	0 -	0 !
 arch/arm/mach-kirkwood/common.h                |    2 	2 +	0 -	0 !
 arch/arm/mach-kirkwood/include/mach/audio.h    |   13 	13 +	0 -	0 !
 arch/arm/mach-kirkwood/include/mach/kirkwood.h |    3 	3 +	0 -	0 !
 4 files changed, 27 insertions(+)
 create mode 100644 include/linux/mv88fx_audio.h
 create mode 100644 sound/soc/kirkwood/Kconfig
 create mode 100644 sound/soc/kirkwood/Makefile
 create mode 100644 sound/soc/kirkwood/cs42l51.c
 create mode 100644 sound/soc/kirkwood/cs42l51.h
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_hal.c
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_hal.h
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_regs.h
 create mode 100644 sound/soc/kirkwood/kirkwood_pcm.c
arch/arm/mach-kirkwood/common.c +9 -0
Index: linux-2.6.33/arch/arm/mach-kirkwood/common.c
===================================================================
@@ -25,6 +25,7 @@
 #include <asm/mach/time.h>
 #include <mach/kirkwood.h>
 #include <mach/bridge-regs.h>
+#include <mach/audio.h>
 #include <plat/cache-feroceon-l2.h>
 #include <plat/ehci-orion.h>
 #include <plat/mvsdio.h>
@@ -977,3 +978,11 @@ static int __init kirkwood_clock_gate(vo
 	return 0;
 }
 late_initcall(kirkwood_clock_gate);
+
+/*****************************************************************************
+ * Audio
+ ****************************************************************************/
+void __init kirkwood_audio_init(struct kirkwood_soc_platform_data *audio_data)
+{
+	kirkwood_clk_ctrl |= CGC_AUDIO;
+}
arch/arm/mach-kirkwood/common.h +2 -0
Index: linux-2.6.33/arch/arm/mach-kirkwood/common.h
===================================================================
@@ -16,6 +16,7 @@ struct mv643xx_eth_platform_data;
 struct mv_sata_platform_data;
 struct mvsdio_platform_data;
 struct mtd_partition;
+struct kirkwood_soc_platform_data;
 
 /*
  * Basic Kirkwood init functions used early by machine-setup.
@@ -41,6 +42,7 @@ void kirkwood_i2c_init(void);
 void kirkwood_uart0_init(void);
 void kirkwood_uart1_init(void);
 void kirkwood_nand_init(struct mtd_partition *parts, int nr_parts, int delay);
+void kirkwood_audio_init(struct kirkwood_soc_platform_data *audio_data);
 
 extern int kirkwood_tclk;
 extern struct sys_timer kirkwood_timer;
arch/arm/mach-kirkwood/include/mach/kirkwood.h +3 -0
Index: linux-2.6.33/arch/arm/mach-kirkwood/include/mach/kirkwood.h
===================================================================
@@ -96,6 +96,9 @@
 
 #define SDIO_PHYS_BASE		(KIRKWOOD_REGS_PHYS_BASE | 0x90000)
 
+#define AUDIO_PHYS_BASE		(KIRKWOOD_REGS_PHYS_BASE | 0xA0000)
+#define AUDIO_VIRT_BASE		(KIRKWOOD_REGS_VIRT_BASE | 0xA0000)
+
 /*
  * Supported devices and revisions.
  */
arch/arm/mach-kirkwood/include/mach/audio.h new file +13 -0
Index: linux-2.6.33/arch/arm/mach-kirkwood/include/mach/audio.h
===================================================================
@@ -0,0 +1,13 @@
+#ifndef __MACH_AUDIO_H
+#define __MACH_AUDIO_H
+
+#include <linux/mbus.h>
+
+struct kirkwood_soc_platform_data {
+	u32 tclk;
+	struct mbus_dram_target_info *dram;
+};
+
+extern struct kirkwood_soc_platform_data kirkwood_soc_data;
+
+#endif
#5 lore raw

PATCH 3/6 asoc: Add SOC_DOUBLE_R_SX_TLV control

In reply to [email protected]

This patch is adding a new control which has the following capabilities:
- tlv
- variable data size (for instance, 7 ou 8 bit)
- double mixer

---

 include/sound/soc.h  |   22 	22 +	0 -	0 !
 sound/soc/soc-core.c |   95 	95 +	0 -	0 !
 2 files changed, 117 insertions(+)
include/sound/soc.h +22 -0
Index: linux-2.6.33/include/sound/soc.h
===================================================================
@@ -168,6 +168,21 @@
 	.get = xhandler_get, .put = xhandler_put, \
 	.private_value = (unsigned long)&xenum }
 
+#define SOC_DOUBLE_R_SX_TLV(xname, xreg_left, xreg_right, xshift,\
+		xmin, xmax, tlv_array) \
+{	.iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
+	.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
+		  SNDRV_CTL_ELEM_ACCESS_READWRITE, \
+	.tlv.p = (tlv_array), \
+	.info = snd_soc_info_volsw_2r_sx, \
+	.get = snd_soc_get_volsw_2r_sx, \
+	.put = snd_soc_put_volsw_2r_sx, \
+	.private_value = (unsigned long)&(struct soc_mixer_control) \
+		{.reg = xreg_left, \
+		 .rreg = xreg_right, .shift = xshift, \
+		 .min = xmin, .max = xmax} }
+
+
 /*
  * Simplified versions of above macros, declaring a struct and calculating
  * ARRAY_SIZE internally
@@ -320,6 +335,13 @@ int snd_soc_get_volsw_s8(struct snd_kcon
 	struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol);
+int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_info *uinfo);
+int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol);
+int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol);
+
 
 /**
  * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
sound/soc/soc-core.c +95 -0

101 lines not on this page · raw message

#8 lore raw

PATCH 4/6 cs42l51: add asoc driver

In reply to [email protected]

This patch is adding a ASoC driver for the cs42l51 from Cirrus Logic. Master mode and spi mode are not supported.

---

 sound/soc/codecs/Kconfig   |    4 	4 +	0 -	0 !
 sound/soc/codecs/Makefile  |    2 	2 +	0 -	0 !
 sound/soc/codecs/cs42l51.c |  682 	682 +	0 -	0 !
 sound/soc/codecs/cs42l51.h |  167 	167 +	0 -	0 !
 4 files changed, 855 insertions(+)
sound/soc/codecs/cs42l51.c new file +682 -0
Index: linux-2.6.33/sound/soc/codecs/cs42l51.c
===================================================================
@@ -0,0 +1,682 @@
+/*
+ * cs42l51.c
+ *
+ * ASoC Driver for Cirrus Logic CS42L51 codecs
+ *
+ * Copyright (c) 2010 Arnaud Patard <[email protected]>
+ *
+ * Based on cs4270.c - Copyright (c) Timur Tabi <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * For now:
+ *  - Only I2C is support. Not SPI
+ *  - master mode *NOT* supported
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <sound/core.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include <sound/initval.h>
+#include <sound/pcm_params.h>
+#include <sound/pcm.h>
+#include <linux/i2c.h>
+
+#include "cs42l51.h"
+
+enum funct_mode {
+	MODE_SLAVE,
+	MODE_SLAVE_AUTO,
+	MODE_MASTER,
+};
+
+struct cs42l51_private {
+	unsigned int mclk;
+	unsigned int audio_mode;	/* The mode (I2S or left-justified) */
+	enum funct_mode func;		/* See funct_mode */
+	struct snd_soc_codec codec;
+	u16 reg_cache[CS42L51_NUMREGS];
+};
+
+static struct snd_soc_codec *cs42l51_codec;
+
+#define CS42L51_FORMATS ( \
+		SNDRV_PCM_FMTBIT_S16_LE  | SNDRV_PCM_FMTBIT_S16_BE  | \
+		SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
+		SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
+		SNDRV_PCM_FMTBIT_S24_LE  | SNDRV_PCM_FMTBIT_S24_BE)
+
+static int cs42l51_fill_cache(struct snd_soc_codec *codec)
+{
+	u8 *cache = codec->reg_cache;
+	struct i2c_client *i2c_client = codec->control_data;
+	s32 length;
+
+	length = i2c_smbus_read_i2c_block_data(i2c_client,
+			CS42L51_FIRSTREG | 0x80, CS42L51_NUMREGS, cache);
+	if (length != CS42L51_NUMREGS) {
+		dev_err(&i2c_client->dev,
+				"I2C read failure, addr=0x%x (ret=%d vs %d)\n",
+				i2c_client->addr, length, CS42L51_NUMREGS);
+		return -EIO;
+	}
+
+	return 0;
+}
+
+static unsigned int cs42l51_read_reg_cache(struct snd_soc_codec *codec,
+	unsigned int reg)
+{
+	u8 *cache = codec->reg_cache;
+
+	if ((reg < CS42L51_FIRSTREG) || (reg > CS42L51_LASTREG))
+		return -EIO;
+
+	return cache[reg - CS42L51_FIRSTREG];
+}
+
+static int cs42l51_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
+	unsigned int value)
+{
+	u8 *cache = codec->reg_cache;
+	struct i2c_client *client = codec->control_data;
+
+	if ((reg < CS42L51_FIRSTREG) || (reg > CS42L51_LASTREG))
+		return -EIO;
+
+	/* Only perform an I2C operation if the new value is different */
+	if (cache[reg - CS42L51_FIRSTREG] != value) {
+		if (i2c_smbus_write_byte_data(client, reg, value)) {
+			dev_err(&client->dev, "I2C write failed\n");
+			return -EIO;
+		}
+		cache[reg - CS42L51_FIRSTREG] = value;
+	}
+
+	return 0;
+}
+
+
+static int cs42l51_i2c_probe(struct i2c_client *i2c_client,
+	const struct i2c_device_id *id)
+{
+	struct snd_soc_codec *codec;
+	struct cs42l51_private *cs42l51;
+	int ret = 0;
+	int reg;
+
+	if (cs42l51_codec)
+		return -EBUSY;
+
+	/* Verify that we have a CS42L51 */
+	ret = i2c_smbus_read_byte_data(i2c_client, CHIP_REV_ID);
+	if (ret < 0) {
+		dev_err(&i2c_client->dev, "failed to read I2C\n");
+		goto error;
+	}
+
+	if (ret != MK_CHIP_REV(CHIP_ID, CHIP_REV)) {
+		dev_err(&i2c_client->dev, "Invalid chip id\n");
+		ret = -ENODEV;
+		goto error;
+	}
+
+	dev_info(&i2c_client->dev, "found device at I2C address %X\n",
+				i2c_client->addr);
+
+	cs42l51 = kzalloc(sizeof(struct cs42l51_private), GFP_KERNEL);
+	if (!cs42l51) {
+		dev_err(&i2c_client->dev, "could not allocate codec\n");
+		return -ENOMEM;
+	}
+	codec = &cs42l51->codec;
+
+	mutex_init(&codec->mutex);
+	INIT_LIST_HEAD(&codec->dapm_widgets);
+	INIT_LIST_HEAD(&codec->dapm_paths);
+
+	codec->dev = &i2c_client->dev;
+	codec->name = "CS42L51";
+	codec->owner = THIS_MODULE;
+	codec->dai = &cs42l51_dai;
+	codec->num_dai = 1;
+	codec->private_data = cs42l51;
+
+	codec->control_data = i2c_client;
+	codec->read = cs42l51_read_reg_cache;
+	codec->write = cs42l51_i2c_write;
+	codec->reg_cache = cs42l51->reg_cache;
+	codec->reg_cache_size = CS42L51_NUMREGS;
+
+	ret = cs42l51_fill_cache(codec);
+	if (ret < 0) {
+		dev_err(&i2c_client->dev, "failed to fill register cache\n");
+		goto error;
+	}
+
+	i2c_set_clientdata(i2c_client, codec);
+
+	/*
+	 * DAC configuration (right place to do that ?)
+	 * - Use signal processor
+	 * - auto mute
+	 * - vol changes immediate
+	 * - no de-emphasize
+	 */
+	reg = DAC_CTL_DATA_SEL(1) | DAC_CTL_AMUTE | DAC_CTL_DACSZ(0);
+	ret = cs42l51_i2c_write(codec, DAC_CTL, reg);
+	if (ret < 0)
+		goto error;
+
+	/* Unmute PCM-A & PCM-B and set default vol to */
+	ret = cs42l51_i2c_write(codec, PCMA_VOL, 0x60);
+	if (ret < 0)
+		goto error;
+
+	ret = cs42l51_i2c_write(codec, PCMB_VOL, 0x60);
+	if (ret < 0)
+		goto error;
+
+	/* default for AOUTx */
+	ret = cs42l51_i2c_write(codec, AOUTA_VOL, 0x05);
+	if (ret < 0)
+		goto error;
+
+	ret = cs42l51_i2c_write(codec, AOUTB_VOL, 0x05);
+	if (ret < 0)
+		goto error;
+
+	/* route microphone */
+	ret = cs42l51_i2c_write(codec, ADC_INPUT, 0xF0);
+	if (ret < 0)
+		goto error;
+
+	cs42l51_dai.dev = codec->dev;
+	cs42l51_codec = codec;
+
+	ret = snd_soc_register_codec(codec);
+	if (ret != 0) {
+		dev_err(codec->dev, "Failed to register codec: %d\n", ret);
+		goto error;
+	}
+
+	ret = snd_soc_register_dai(&cs42l51_dai);
+	if (ret < 0) {
+		dev_err(&i2c_client->dev, "failed to register DAIe\n");
+		goto error_reg;
+	}
+
+	return 0;
+
+error_reg:
+	snd_soc_unregister_codec(codec);
+error:
+	return ret;
+}
+
+static int cs42l51_i2c_remove(struct i2c_client *client)
+{
+	struct cs42l51_private *cs42l51 = i2c_get_clientdata(client);
+	snd_soc_unregister_dai(&cs42l51_dai);
+	snd_soc_unregister_codec(&cs42l51->codec);
+	cs42l51_codec = NULL;
+	kfree(cs42l51);
+	return 0;
+}
+
+
+static const struct i2c_device_id cs42l51_id[] = {
+	{"cs42l51", 0},
+	{}
+};
+MODULE_DEVICE_TABLE(i2c, cs42l51_id);
+
+static struct i2c_driver cs42l51_i2c_driver = {
+	.driver = {
+		.name = "CS42L51 I2C",
+		.owner = THIS_MODULE,
+	},
+	.id_table = cs42l51_id,
+	.probe = cs42l51_i2c_probe,
+	.remove = cs42l51_i2c_remove,
+};
+
+static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	unsigned long value = snd_soc_read(codec, PCM_MIXER)&3;
+
+	switch (value) {
+	default:
+	case 0:
+		ucontrol->value.integer.value[0] = 0;
+		break;
+	case 1:
+	case 2:
+		ucontrol->value.integer.value[0] = 1;
+		break;
+	case 3:
+		ucontrol->value.integer.value[0] = 2;
+		break;
+	}
+
+	return 0;
+}
+
+#define CHAN_MIX_NORMAL	0x00
+#define CHAN_MIX_BOTH	0x55
+#define CHAN_MIX_SWAP	0xFF
+
+static int cs42l51_set_chan_mix(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	unsigned char val;
+
+	switch (ucontrol->value.integer.value[0]) {
+	default:
+	case 0:
+		val = CHAN_MIX_NORMAL;
+		break;
+	case 1:
+		val = CHAN_MIX_BOTH;
+		break;
+	case 2:
+		val = CHAN_MIX_SWAP;
+		break;
+	}
+
+	snd_soc_write(codec, PCM_MIXER, val);
+
+	return 1;
+}
+
+static const DECLARE_TLV_DB_SCALE(adc_pcm_tlv, -5150, 50, 0);
+static const DECLARE_TLV_DB_SCALE(tone_tlv, -1050, 150, 0);
+/* This is a lie. after -102 db, it stays at -102 */
+/* maybe a range would be better */
+static const DECLARE_TLV_DB_SCALE(aout_tlv, -11550, 50, 0);
+
+static const char *mic_boost[] = { "+16dB", "+32dB"};
+
+static const char *chan_mix[] = {
+	"L R",
+	"L+R",
+	"R L",
+};
+
+static const struct soc_enum cs42l51_mix[] = {
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(chan_mix), chan_mix),
+	SOC_ENUM_DOUBLE(MIC_CTL, 0, 1, 2, mic_boost),
+};
+
+static const struct snd_kcontrol_new cs42l51_snd_controls[] = {
+	SOC_DOUBLE_R_SX_TLV("PCM Playback Volume",
+			PCMA_VOL, PCMB_VOL, 7, 0xffffff99, 0x18, adc_pcm_tlv),
+	SOC_DOUBLE_R("PCM Playback Switch", PCMA_VOL, PCMB_VOL, 7, 1, 1),
+	SOC_DOUBLE_R_SX_TLV("Analog Playback Volume",
+			AOUTA_VOL, AOUTB_VOL, 8, 0xffffff19, 0x18, aout_tlv),
+	SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume",
+			ADCA_VOL, ADCB_VOL, 7, 0xffffff99, 0x18, adc_pcm_tlv),
+	SOC_DOUBLE_R("ADC Mixer Switch", PCMA_VOL, PCMB_VOL, 7, 1, 1),
+	SOC_SINGLE("Playback Deemphasis", DAC_CTL, 3, 1, 0),
+	SOC_SINGLE("Auto-Mute Switch", DAC_CTL, 2, 1, 0),
+	SOC_SINGLE("Soft Ramp Switch", DAC_CTL, 1, 1, 0),
+	SOC_SINGLE("Zero Cross Switch", DAC_CTL, 0, 0, 0),
+	SOC_SINGLE("Mic Bias", MIC_POWER_CTL, 1, 1, 1),
+	SOC_DOUBLE("Mic Powerdown", MIC_POWER_CTL, 2, 3, 1, 0),
+	SOC_ENUM("Mic Boost", cs42l51_mix[1]),
+	SOC_SINGLE_TLV("Bass Volume", TONE_CTL, 0, 0xf, 1, tone_tlv),
+	SOC_SINGLE_TLV("Treble Volume", TONE_CTL, 4, 0xf, 1, tone_tlv),
+	SOC_ENUM_EXT("PCM channel mixer",
+			cs42l51_mix[0],
+			cs42l51_get_chan_mix, cs42l51_set_chan_mix),
+};
+
+static int cs42l51_set_dai_fmt(struct snd_soc_dai *codec_dai,
+		unsigned int format)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct cs42l51_private *cs42l51 = codec->private_data;
+	int ret = 0;
+
+	switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
+	case SND_SOC_DAIFMT_I2S:
+	case SND_SOC_DAIFMT_LEFT_J:
+	case SND_SOC_DAIFMT_RIGHT_J:
+		cs42l51->audio_mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
+		break;
+	default:
+		printk(KERN_ERR "cs4270: invalid DAI format\n");
+		ret = -EINVAL;
+	}
+
+	switch (SND_SOC_DAIFMT_MASTER_MASK) {
+	default:
+	case SND_SOC_DAIFMT_CBM_CFM:
+		cs42l51->func = MODE_SLAVE_AUTO;
+		break;
+	case SND_SOC_DAIFMT_CBS_CFS:
+		cs42l51->func = MODE_MASTER;
+		break;
+	}
+
+	return ret;
+}
+
+struct cs42l51_ratios {
+	unsigned int ratio;
+	unsigned char speed_mode;
+	unsigned char mclk;
+};
+
+static struct cs42l51_ratios slave_ratios[] = {
+	{  512, QSM_MODE, 0 }, {  768, QSM_MODE, 0 }, { 1024, QSM_MODE, 0 },
+	{ 1536, QSM_MODE, 0 }, { 2048, QSM_MODE, 0 }, { 3072, QSM_MODE, 0 },
+	{  256, HSM_MODE, 0 }, {  384, HSM_MODE, 0 }, {  512, HSM_MODE, 0 },
+	{  768, HSM_MODE, 0 }, { 1024, HSM_MODE, 0 }, { 1536, HSM_MODE, 0 },
+	{  128, SSM_MODE, 0 }, {  192, SSM_MODE, 0 }, {  256, SSM_MODE, 0 },
+	{  384, SSM_MODE, 0 }, {  512, SSM_MODE, 0 }, {  768, SSM_MODE, 0 },
+	{  128, DSM_MODE, 0 }, {  192, DSM_MODE, 0 }, {  256, DSM_MODE, 0 },
+	{  384, DSM_MODE, 0 },
+};
+
+static struct cs42l51_ratios slave_auto_ratios[] = {
+	{ 1024, QSM_MODE, 0 }, { 1536, QSM_MODE, 0 }, { 2048, QSM_MODE, 1 },
+	{ 3072, QSM_MODE, 1 },
+	{  512, HSM_MODE, 0 }, {  768, HSM_MODE, 0 }, { 1024, HSM_MODE, 1 },
+	{ 1536, HSM_MODE, 1 },
+	{  256, SSM_MODE, 0 }, {  384, SSM_MODE, 0 }, {  512, SSM_MODE, 1 },
+	{  768, SSM_MODE, 1 },
+	{  128, DSM_MODE, 0 }, {  192, DSM_MODE, 0 }, {  256, DSM_MODE, 1 },
+	{  384, DSM_MODE, 1 },
+};
+
+/* Fill me */
+static struct cs42l51_ratios master_ratios[] = { {},
+};
+
+static int cs42l51_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+		int clk_id, unsigned int freq, int dir)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct cs42l51_private *cs42l51 = codec->private_data;
+	struct cs42l51_ratios *ratios = NULL;
+	int nr_ratios = 0;
+	unsigned int rates = 0;
+	unsigned int rate_min = -1;
+	unsigned int rate_max = 0;
+	int i;
+
+	cs42l51->mclk = freq;
+
+	switch (cs42l51->func) {
+	case MODE_MASTER:
+		ratios = master_ratios;
+		nr_ratios = ARRAY_SIZE(master_ratios);
+		break;
+	case MODE_SLAVE:
+		ratios = slave_ratios;
+		nr_ratios = ARRAY_SIZE(slave_ratios);
+		break;
+	case MODE_SLAVE_AUTO:
+		ratios = slave_auto_ratios;
+		nr_ratios = ARRAY_SIZE(slave_auto_ratios);
+		break;
+	}
+
+	for (i = 0; i < nr_ratios; i++) {
+		unsigned int rate = freq / ratios[i].ratio;
+		rates |= snd_pcm_rate_to_rate_bit(rate);
+		if (rate < rate_min)
+			rate_min = rate;
+		if (rate > rate_max)
+			rate_max = rate;
+	}
+	rates &= ~SNDRV_PCM_RATE_KNOT;
+
+	if (!rates) {
+		printk(KERN_ERR "cs42l51: could not find a valid sample rate\n");
+		return -EINVAL;
+	}
+
+	codec_dai->playback.rates = rates;
+	codec_dai->playback.rate_min = rate_min;
+	codec_dai->playback.rate_max = rate_max;
+
+	codec_dai->capture.rates = rates;
+	codec_dai->capture.rate_min = rate_min;
+	codec_dai->capture.rate_max = rate_max;
+
+	return 0;
+}
+
+static int cs42l51_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_device *socdev = rtd->socdev;
+	struct snd_soc_codec *codec = socdev->card->codec;
+	struct cs42l51_private *cs42l51 = codec->private_data;
+	int ret;
+	unsigned int i;
+	unsigned int rate;
+	unsigned int ratio;
+	struct cs42l51_ratios *ratios = NULL;
+	int nr_ratios = 0;
+	int intf_ctl, power_ctl;
+
+	switch (cs42l51->func) {
+	case MODE_MASTER:
+		ratios = master_ratios;
+		nr_ratios = ARRAY_SIZE(master_ratios);
+		break;
+	case MODE_SLAVE:
+		ratios = slave_ratios;
+		nr_ratios = ARRAY_SIZE(slave_ratios);
+		break;
+	case MODE_SLAVE_AUTO:
+		ratios = slave_auto_ratios;
+		nr_ratios = ARRAY_SIZE(slave_auto_ratios);
+		break;
+	}
+
+	/* Figure out which MCLK/LRCK ratio to use */
+	rate = params_rate(params);     /* Sampling rate, in Hz */
+	ratio = cs42l51->mclk / rate;    /* MCLK/LRCK ratio */
+	for (i = 0; i < nr_ratios; i++) {
+		if (ratios[i].ratio == ratio)
+			break;
+	}
+
+	if (i == nr_ratios) {
+		/* We did not find a matching ratio */
+		printk(KERN_ERR "cs42l51: could not find matching ratio\n");
+		return -EINVAL;
+	}
+
+	intf_ctl = snd_soc_read(codec, INTF_CTL);
+	power_ctl = snd_soc_read(codec, MIC_POWER_CTL);
+
+	intf_ctl &= ~(INTF_CTL_MASTER|INTF_CTL_ADC_I2S|INTF_CTL_DAC_FORMAT(7));
+	power_ctl &= ~(MIC_POWER_CTL_SPEED(3)|MIC_POWER_CTL_MCLK_DIV2);
+
+	switch (cs42l51->func) {
+	case MODE_MASTER:
+		intf_ctl |= INTF_CTL_MASTER;
+		power_ctl |= MIC_POWER_CTL_SPEED(ratios[i].speed_mode);
+		break;
+	case MODE_SLAVE:
+		power_ctl |= MIC_POWER_CTL_SPEED(ratios[i].speed_mode);
+		break;
+	case MODE_SLAVE_AUTO:
+		power_ctl |= MIC_POWER_CTL_AUTO;
+		break;
+	}
+
+	switch (cs42l51->audio_mode) {
+	case SND_SOC_DAIFMT_I2S:
+		intf_ctl |= INTF_CTL_ADC_I2S | INTF_CTL_DAC_FORMAT(DAC_DIF_I2S);
+		break;
+	case SND_SOC_DAIFMT_LEFT_J:
+		intf_ctl |= INTF_CTL_DAC_FORMAT(DAC_DIF_LJ24);
+		break;
+	case SND_SOC_DAIFMT_RIGHT_J:
+		switch (params_format(params)) {
+		case SNDRV_PCM_FORMAT_S16_LE:
+		case SNDRV_PCM_FORMAT_S16_BE:
+			intf_ctl |= INTF_CTL_DAC_FORMAT(DAC_DIF_RJ16);
+			break;
+		case SNDRV_PCM_FORMAT_S18_3LE:
+		case SNDRV_PCM_FORMAT_S18_3BE:
+			intf_ctl |= INTF_CTL_DAC_FORMAT(DAC_DIF_RJ18);
+			break;
+		case SNDRV_PCM_FORMAT_S20_3LE:
+		case SNDRV_PCM_FORMAT_S20_3BE:
+			intf_ctl |= INTF_CTL_DAC_FORMAT(DAC_DIF_RJ20);
+			break;
+		case SNDRV_PCM_FORMAT_S24_LE:
+		case SNDRV_PCM_FORMAT_S24_BE:
+			intf_ctl |= INTF_CTL_DAC_FORMAT(DAC_DIF_RJ24);
+			break;
+		default:
+			printk(KERN_ERR "cs42l51: unknown format\n");
+			return -EINVAL;
+		}
+		break;
+	default:
+		printk(KERN_ERR "cs42l51: unknown format\n");
+		return -EINVAL;
+	}
+
+	if (ratios[i].mclk)
+		power_ctl |= MIC_POWER_CTL_MCLK_DIV2;
+
+	ret = snd_soc_write(codec, INTF_CTL, intf_ctl);
+	if (ret < 0)
+		return ret;
+
+	ret = snd_soc_write(codec, MIC_POWER_CTL, power_ctl);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static struct snd_soc_dai_ops cs42l51_dai_ops = {
+	.hw_params      = cs42l51_hw_params,
+	.set_sysclk     = cs42l51_set_dai_sysclk,
+	.set_fmt        = cs42l51_set_dai_fmt,
+};
+
+struct snd_soc_dai cs42l51_dai = {
+	.name = "CS42L51 HiFi",
+	.playback = {
+		.stream_name = "Playback",
+		.channels_min = 1,
+		.channels_max = 2,
+		.rates = SNDRV_PCM_RATE_8000_96000,
+		.formats = CS42L51_FORMATS,
+	},
+	.capture = {
+		.stream_name = "Capture",
+		.channels_min = 1,
+		.channels_max = 2,
+		.rates = SNDRV_PCM_RATE_8000_96000,
+		.formats = CS42L51_FORMATS,
+	},
+	.ops = &cs42l51_dai_ops,
+};
+EXPORT_SYMBOL_GPL(cs42l51_dai);
+
+
+static int cs42l51_probe(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_codec *codec;
+	int ret = 0;
+	int i;
+
+	if (!cs42l51_codec) {
+		dev_err(&pdev->dev, "CS42L51 codec not yet registered\n");
+		return -EINVAL;
+	}
+
+	dev_info(&pdev->dev, "CS42L51 ALSA SoC Codec\n");
+
+	socdev->card->codec = cs42l51_codec;
+	codec = socdev->card->codec;
+
+	/* Register PCMs */
+	ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to create PCMs\n");
+		return ret;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(cs42l51_snd_controls); i++) {
+		ret = snd_ctl_add(codec->card,
+				snd_soc_cnew(&cs42l51_snd_controls[i],
+				codec, NULL));
+		if (ret < 0) {
+			dev_err(&pdev->dev, "failed to add controls\n");
+			snd_soc_free_pcms(socdev);
+			return ret;
+		}
+	}
+
+	return 0;
+}
+
+
+static int cs42l51_remove(struct platform_device *pdev)
+{
+	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+
+	snd_soc_free_pcms(socdev);
+
+	return 0;
+}
+
+struct snd_soc_codec_device soc_codec_device_cs42l51 = {
+	.probe =	cs42l51_probe,
+	.remove =	cs42l51_remove
+};
+EXPORT_SYMBOL_GPL(soc_codec_device_cs42l51);
+
+static int __init cs42l51_init(void)
+{
+	int ret;
+
+	ret = i2c_add_driver(&cs42l51_i2c_driver);
+	if (ret != 0) {
+		printk(KERN_ERR "can't add i2c driver\n");
+		return ret;
+	}
+	return 0;
+}
+module_init(cs42l51_init);
+
+static void __exit cs42l51_exit(void)
+{
+	i2c_del_driver(&cs42l51_i2c_driver);
+}
+module_exit(cs42l51_exit);
+
+MODULE_AUTHOR("Arnaud Patard <[email protected]>");
+MODULE_DESCRIPTION("Cirrus Logic CS42L51 ALSA SoC Codec Driver");
+MODULE_LICENSE("GPL");
+
sound/soc/codecs/cs42l51.h new file +167 -0

167 lines not on this page · raw message

sound/soc/codecs/Kconfig +4 -0
Index: linux-2.6.33/sound/soc/codecs/Kconfig
===================================================================
@@ -21,6 +21,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_AK4535 if I2C
 	select SND_SOC_AK4642 if I2C
 	select SND_SOC_AK4671 if I2C
+	select SND_SOC_CS42L51 if I2C
 	select SND_SOC_CS4270 if I2C
 	select SND_SOC_MAX9877 if I2C
 	select SND_SOC_DA7210 if I2C
@@ -114,6 +115,9 @@ config SND_SOC_AK4642
 config SND_SOC_AK4671
 	tristate
 
+config SND_SOC_CS42L51
+	tristate
+
 # Cirrus Logic CS4270 Codec
 config SND_SOC_CS4270
 	tristate
sound/soc/codecs/Makefile +2 -0
Index: linux-2.6.33/sound/soc/codecs/Makefile
===================================================================
@@ -8,6 +8,7 @@ snd-soc-ak4104-objs := ak4104.o
 snd-soc-ak4535-objs := ak4535.o
 snd-soc-ak4642-objs := ak4642.o
 snd-soc-ak4671-objs := ak4671.o
+snd-soc-cs42l51-objs := cs42l51.o
 snd-soc-cs4270-objs := cs4270.o
 snd-soc-cx20442-objs := cx20442.o
 snd-soc-da7210-objs := da7210.o
@@ -70,6 +71,7 @@ obj-$(CONFIG_SND_SOC_AK4104)	+= snd-soc-
 obj-$(CONFIG_SND_SOC_AK4535)	+= snd-soc-ak4535.o
 obj-$(CONFIG_SND_SOC_AK4642)	+= snd-soc-ak4642.o
 obj-$(CONFIG_SND_SOC_AK4671)	+= snd-soc-ak4671.o
+obj-$(CONFIG_SND_SOC_CS42L51)	+= snd-soc-cs42l51.o
 obj-$(CONFIG_SND_SOC_CS4270)	+= snd-soc-cs4270.o
 obj-$(CONFIG_SND_SOC_CX20442)	+= snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_DA7210)	+= snd-soc-da7210.o
#13 lore raw

PATCH 5/6 kirkwood: Add i2s support

In reply to [email protected]

This patch enables support for the i2s codec available on kirkwood platforms

---

 sound/soc/Kconfig                 |    1 	1 +	0 -	0 !
 sound/soc/Makefile                |    1 	1 +	0 -	0 !
 sound/soc/kirkwood/Kconfig        |   11 	11 +	0 -	0 !
 sound/soc/kirkwood/Makefile       |    6 	6 +	0 -	0 !
 sound/soc/kirkwood/kirkwood-dma.c |  366 	366 +	0 -	0 !
 sound/soc/kirkwood/kirkwood-dma.h |   17 	17 +	0 -	0 !
 sound/soc/kirkwood/kirkwood-i2s.c |  471 	471 +	0 -	0 !
 sound/soc/kirkwood/kirkwood-i2s.h |   17 	17 +	0 -	0 !
 sound/soc/kirkwood/kirkwood.h     |  168 	168 +	0 -	0 !
 9 files changed, 1058 insertions(+)
sound/soc/kirkwood/Kconfig new file +11 -0
Index: linux-2.6.33/sound/soc/kirkwood/Kconfig
===================================================================
@@ -0,0 +1,11 @@
+config SND_KIRKWOOD_SOC
+	tristate "SoC Audio for the Marvell Kirkwood chip"
+	depends on ARCH_KIRKWOOD
+	help
+	  Say Y or M if you want to add support for codecs attached to
+	  the Kirkwood I2S interface. You will also need
+	  to select the audio interfaces to support below.
+
+config SND_KIRKWOOD_SOC_I2S
+	tristate
+
sound/soc/kirkwood/kirkwood-dma.c new file +366 -0

366 lines not on this page · raw message

sound/soc/kirkwood/kirkwood.h new file +168 -0

168 lines not on this page · raw message

sound/soc/kirkwood/kirkwood-i2s.c new file +471 -0

471 lines not on this page · raw message

sound/soc/kirkwood/Makefile new file +6 -0
Index: linux-2.6.33/sound/soc/kirkwood/Makefile
===================================================================
@@ -0,0 +1,6 @@
+snd-soc-kirkwood-objs := kirkwood-dma.o
+snd-soc-kirkwood-i2s-objs := kirkwood-i2s.o
+
+obj-$(CONFIG_SND_KIRKWOOD_SOC) += snd-soc-kirkwood.o
+obj-$(CONFIG_SND_KIRKWOOD_SOC_I2S) += snd-soc-kirkwood-i2s.o
+
sound/soc/Makefile +1 -0
Index: linux-2.6.33/sound/soc/Makefile
===================================================================
@@ -8,6 +8,7 @@ obj-$(CONFIG_SND_SOC)	+= blackfin/
 obj-$(CONFIG_SND_SOC)	+= davinci/
 obj-$(CONFIG_SND_SOC)	+= fsl/
 obj-$(CONFIG_SND_SOC)   += imx/
+obj-$(CONFIG_SND_SOC)	+= kirkwood/
 obj-$(CONFIG_SND_SOC)	+= omap/
 obj-$(CONFIG_SND_SOC)	+= pxa/
 obj-$(CONFIG_SND_SOC)	+= s3c24xx/
sound/soc/kirkwood/kirkwood-dma.h new file +17 -0
Index: linux-2.6.33/sound/soc/kirkwood/kirkwood-dma.h
===================================================================
@@ -0,0 +1,17 @@
+/*
+ * kirkwood-dma.h
+ *
+ * (c) 2010 Arnaud Patard <[email protected]>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#ifndef _KIRKWOOD_DMA_H
+#define _KIRKWOOD_DMA_H
+
+extern struct snd_soc_platform kirkwood_soc_platform;
+
+#endif
sound/soc/kirkwood/kirkwood-i2s.h new file +17 -0
Index: linux-2.6.33/sound/soc/kirkwood/kirkwood-i2s.h
===================================================================
@@ -0,0 +1,17 @@
+/*
+ * kirkwood-i2s.h
+ *
+ * (c) 2010 Arnaud Patard <[email protected]>
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#ifndef _KIRKWOOD_I2S_H
+#define _KIRKWOOD_I2S_H
+
+extern struct snd_soc_dai kirkwood_i2s_dai;
+
+#endif
sound/soc/Kconfig +1 -0
Index: linux-2.6.33/sound/soc/Kconfig
===================================================================
@@ -30,6 +30,7 @@ source "sound/soc/blackfin/Kconfig"
 source "sound/soc/davinci/Kconfig"
 source "sound/soc/fsl/Kconfig"
 source "sound/soc/imx/Kconfig"
+source "sound/soc/kirkwood/Kconfig"
 source "sound/soc/omap/Kconfig"
 source "sound/soc/pxa/Kconfig"
 source "sound/soc/s3c24xx/Kconfig"
#20 lore raw

PATCH 6/6 kirkwood: Add audio support to openrd client platforms

In reply to [email protected]

This patch is adding support for openrd client platforms. It's using the cs42l51 codec and has one mic and one speaker plugs.

---

 sound/soc/kirkwood/Kconfig           |    9 	9 +	0 -	0 !
 sound/soc/kirkwood/Makefile          |    3 	3 +	0 -	0 !
 sound/soc/kirkwood/kirkwood-openrd.c |  176 	176 +	0 -	0 !
 3 files changed, 188 insertions(+)
sound/soc/kirkwood/Kconfig +9 -0
Index: linux-2.6.33/sound/soc/kirkwood/Kconfig
===================================================================
@@ -9,3 +9,12 @@ config SND_KIRKWOOD_SOC
 config SND_KIRKWOOD_SOC_I2S
 	tristate
 
+config SND_KIRKWOOD_SOC_OPENRD
+	tristate "SoC Audio support for Kirkwood Openrd Client"
+	depends on SND_KIRKWOOD_SOC && MACH_OPENRD_CLIENT
+	select SND_KIRKWOOD_SOC_I2S
+	select SND_SOC_CS42L51
+	help
+	  Say Y if you want to add support for SoC audio on
+	  Openrd Client.
+
sound/soc/kirkwood/Makefile +3 -0
Index: linux-2.6.33/sound/soc/kirkwood/Makefile
===================================================================
@@ -4,3 +4,6 @@ snd-soc-kirkwood-i2s-objs := kirkwood-i2
 obj-$(CONFIG_SND_KIRKWOOD_SOC) += snd-soc-kirkwood.o
 obj-$(CONFIG_SND_KIRKWOOD_SOC_I2S) += snd-soc-kirkwood-i2s.o
 
+snd-soc-openrd-objs := kirkwood-openrd.o
+
+obj-$(CONFIG_SND_KIRKWOOD_SOC_OPENRD) += snd-soc-openrd.o
sound/soc/kirkwood/kirkwood-openrd.c new file +176 -0

176 lines not on this page · raw message

#3 lore raw

PATCH 2/6 openrd-client: initialise audio

In reply to [email protected]

This patch is reponsible for enabling audio on the openrd client board

---
arch/arm/mach-kirkwood/openrd-setup.c | 11 11 + 0 - 0 !

 1 file changed, 11 insertions(+)
arch/arm/mach-kirkwood/openrd-setup.c +11 -0
Index: linux-2.6.33/arch/arm/mach-kirkwood/openrd-setup.c
===================================================================
@@ -18,6 +18,7 @@
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/kirkwood.h>
+#include <mach/audio.h>
 #include <plat/mvsdio.h>
 #include "common.h"
 #include "mpp.h"
@@ -47,6 +48,11 @@ static struct mv643xx_eth_platform_data
 	.phy_addr	= MV643XX_ETH_PHY_ADDR(24),
 };
 
+struct kirkwood_soc_platform_data kirkwood_soc_data = {
+	.dram        = &kirkwood_mbus_dram_info,
+};
+EXPORT_SYMBOL_GPL(kirkwood_soc_data);
+
 static struct mv_sata_platform_data openrd_sata_data = {
 	.n_ports	= 2,
 };
@@ -80,6 +86,11 @@ static void __init openrd_init(void)
 	kirkwood_sdio_init(&openrd_mvsdio_data);
 
 	kirkwood_i2c_init();
+
+	if (machine_is_openrd_client()) {
+		kirkwood_soc_data.tclk = kirkwood_tclk,
+		kirkwood_audio_init(&kirkwood_soc_data);
+	}
 }
 
 static int __init openrd_pci_init(void)
#9 lore raw

Re: [patch 4/6] cs42l51: add asoc driver

In reply to [email protected]
Quoted 8 lines · On Tue, May 11, 2010 at 11:23 AM, <[email protected]> wrote:

+ * Copyright (c) 2010 Arnaud Patard <[email protected]>
+ *
+ * Based on cs4270.c - Copyright (c) Timur Tabi <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.

The cs4270.c driver is licensed under the GPL v2 only. Since you based your driver on mine, you cannot change the license to "v2 or later".

Signature · 2 lines
Timur Tabi
Linux kernel developer at Freescale
#22 lore raw
In reply to [email protected]
Quoted 7 lines · <apatard <at> mandriva.com> writes:

This patchset aims at adding ASoC support to ARM kirkwood systems and more precisely to openrd client boards.

Arnaud Patard

Hi Arnaud,
this i2s controller was first added into the Orion-1-90 (88F6183), and also
it's found on dove soc. so can you please rename to orion to make more generic?

saeed

#4 lore raw

Re: [patch 2/6] openrd-client: initialise audio

In reply to [email protected]
Quoted 1 line · <apatard <at> mandriva.com> writes:

--- linux-2.6.33.orig/arch/arm/mach-kirkwood/openrd-setup.c 2010-05-11

17:53:34.753650304 +0200

Quoted 1 line

+++ linux-2.6.33/arch/arm/mach-kirkwood/openrd-setup.c 2010-05-11

17:55:13.313650581 +0200

Quoted 9 lines
arch/arm/mach-kirkwood/openrd-setup.c +1 -0
@@ -18,6 +18,7 @@
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/kirkwood.h>
+#include <mach/audio.h>
 #include <plat/mvsdio.h>
 #include "common.h"
 #include "mpp.h"

arch/arm/mach-kirkwood/openrd-setup.c static struct mv643xx_eth_platform_data · line 55

Quoted 8 lines
arch/arm/mach-kirkwood/openrd-setup.c +5 -0
@@ -47,6 +48,11 @@ static struct mv643xx_eth_platform_data
 	.phy_addr	= MV643XX_ETH_PHY_ADDR(24),
 };
 
+struct kirkwood_soc_platform_data kirkwood_soc_data = {
+	.dram        = &kirkwood_mbus_dram_info,
+};
+EXPORT_SYMBOL_GPL(kirkwood_soc_data);
+

The kirkwood_soc_data is the same for all boards, so you can move it to the mack-kirkwood/common.c, the tclk usually set at kirkwood_init().

saeed

#2 lore raw

Re: [patch 1/6] kirkwood: add audio functions.

In reply to [email protected]
Quoted 6 lines · On Tue, 2010-05-11 at 18:23 +0200, [email protected] wrote:

plain text document attachment (kirkwood_add_audio_dev.patch) This patch add audio related definitions and functions

---

Quoted 15 lines
 arch/arm/mach-kirkwood/common.c                |    9 	9 +	0 -	0 !
 arch/arm/mach-kirkwood/common.h                |    2 	2 +	0 -	0 !
 arch/arm/mach-kirkwood/include/mach/audio.h    |   13 	13 +	0 -	0 !
 arch/arm/mach-kirkwood/include/mach/kirkwood.h |    3 	3 +	0 -	0 !
 4 files changed, 27 insertions(+)
 create mode 100644 include/linux/mv88fx_audio.h
 create mode 100644 sound/soc/kirkwood/Kconfig
 create mode 100644 sound/soc/kirkwood/Makefile
 create mode 100644 sound/soc/kirkwood/cs42l51.c
 create mode 100644 sound/soc/kirkwood/cs42l51.h
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_hal.c
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_hal.h
 create mode 100644 sound/soc/kirkwood/kirkwood_audio_regs.h
 create mode 100644 sound/soc/kirkwood/kirkwood_pcm.c

Some of the files above are missing from this patch series i.e. kirkwood_audio_hal. Are they required ?

Liam

Signature · 3 lines
Freelance Developer, SlimLogic Ltd
ASoC and Voltage Regulator Maintainer.
http://www.slimlogic.co.uk
#6 lore raw

Re: [patch 3/6] asoc: Add SOC_DOUBLE_R_SX_TLV control

In reply to [email protected]
Quoted 4 lines · On Tue, May 11, 2010 at 06:23:45PM +0200, [email protected] wrote:

This patch is adding a new control which has the following capabilities:
- tlv
- variable data size (for instance, 7 ou 8 bit)
- double mixer

The major new change here is that the control allows for ranges which wrap around in the middle rather than continuously increasing or decreasing. The change itself looks OK but if you repost please make the changelog clearer.

Oh, and ASoC, not asoc.

#10 lore raw

Re: [patch 4/6] cs42l51: add asoc driver

In reply to [email protected]
Quoted 2 lines · On Tue, May 11, 2010 at 06:23:46PM +0200, [email protected] wrote:

This patch is adding a ASoC driver for the cs42l51 from Cirrus Logic. Master mode and spi mode are not supported.

This is mostly OK - there's quite a few comments below but there's no massive structural things in here, it's generally small, local things.

Quoted 1 line

+ * Based on cs4270.c - Copyright (c) Timur Tabi <[email protected]>

While we're picking up on the copyright stuff IIRC it's actually Freescale copyright rather than Timur's personal copyright :)

sound/soc/codecs/cs42l51.c line 42

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +5 -0
+enum funct_mode {
+	MODE_SLAVE,
+	MODE_SLAVE_AUTO,
+	MODE_MASTER,
+};

I'd prefer a more meaningful name than "funct_mode" here - I don't really know what a funct is.

sound/soc/codecs/cs42l51.c line 86

Quoted 9 lines
sound/soc/codecs/cs42l51.c new file +9 -0
+static unsigned int cs42l51_read_reg_cache(struct snd_soc_codec *codec,
+	unsigned int reg)
+{
+	u8 *cache = codec->reg_cache;
+
+	if ((reg < CS42L51_FIRSTREG) || (reg > CS42L51_LASTREG))
+		return -EIO;
+
+	return cache[reg - CS42L51_FIRSTREG];

Please just use the standard register cache access stuff in soc-cache.c. The first register is 1 so you're only burning a single byte of RAM by using the generic code.

sound/soc/codecs/cs42l51.c line 129

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	if (ret != MK_CHIP_REV(CHIP_ID, CHIP_REV)) {

Are you sure there's only one device revision in production?

sound/soc/codecs/cs42l51.c line 136

Quoted 7 lines
sound/soc/codecs/cs42l51.c new file +6 -0
+		dev_err(&i2c_client->dev, "Invalid chip id\n");
+		ret = -ENODEV;
+		goto error;
+	}
 
+	dev_info(&i2c_client->dev, "found device at I2C address %X\n",
+				i2c_client->addr);

The dev_() will already be including the I2C address in the log message anyway. I'd be inclined to just drop this, or make it log the device revision.

sound/soc/codecs/cs42l51.c line 166

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +5 -0
+	ret = cs42l51_fill_cache(codec);
+	if (ret < 0) {
+		dev_err(&i2c_client->dev, "failed to fill register cache\n");
+		goto error;
+	}

Normal practice is to reset the chip so it's in a known sensible state when the driver starts trying to use it. Is there a good reason not to do this here?

sound/soc/codecs/cs42l51.c line 171

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +2 -0
+	/*
+	 * DAC configuration (right place to do that ?)

It's OK to do this for things that the user would unconditionally want.

sound/soc/codecs/cs42l51.c line 172

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - Use signal processor

What does this mean? It sounds like something that would need to be power managed via DAPM?

sound/soc/codecs/cs42l51.c line 173

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - auto mute

This is probably OK, but exposing as a user visible control would be better.

sound/soc/codecs/cs42l51.c line 174

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - vol changes immediate

This is OK.

sound/soc/codecs/cs42l51.c line 175

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - no de-emphasize

This is normally exposed as a user selectable switch.

sound/soc/codecs/cs42l51.c line 185

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+	/* Unmute PCM-A & PCM-B and set default vol to */
+	ret = cs42l51_i2c_write(codec, PCMA_VOL, 0x60);
+	if (ret < 0)
+		goto error;

This should not be done in the driver, leave it up to userspace. This driver will be used by all systems using this CODEC so just rely on the hardware defaults to provide a sane power on configuration - the designers will usually ensure that this is at least not harmful.

sound/soc/codecs/cs42l51.c line 203

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+	/* route microphone */
+	ret = cs42l51_i2c_write(codec, ADC_INPUT, 0xF0);
+	if (ret < 0)
+		goto error;

Ditto.

sound/soc/codecs/cs42l51.c line 225

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+error_reg:
+	snd_soc_unregister_codec(codec);
+error:
+	return ret;

You're missing some error handling here - there's no free of the device data, for example.

Quoted 12 lines
sound/soc/codecs/cs42l51.c new file +12 -0
+static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	unsigned long value = snd_soc_read(codec, PCM_MIXER)&3;
+
+	switch (value) {
+	default:
+	case 0:
+		ucontrol->value.integer.value[0] = 0;
+		break;
+	case 1:

sound/soc/codecs/cs42l51.c line 276

Quoted 10 lines
sound/soc/codecs/cs42l51.c new file +10 -0
+	case 2:
+		ucontrol->value.integer.value[0] = 1;
+		break;
+	case 3:
+		ucontrol->value.integer.value[0] = 2;
+		break;
+	}
+
+	return 0;
+}

Some comments here might be a little clearer... Why is the difference between 1 and 2 not interesting?

Quoted 1 line

+static const char *mic_boost[] = { "+16dB", "+32dB"};

Could use TLV for this too.

sound/soc/codecs/cs42l51.c line 323

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+static const struct soc_enum cs42l51_mix[] = {
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(chan_mix), chan_mix),
+	SOC_ENUM_DOUBLE(MIC_CTL, 0, 1, 2, mic_boost),
+};

Don't do this, declare separate variables for each. Indexing into a table of mixer elements doesn't help leigibility and is asking for off by one errors. Some drivers do this for historical reasons but modern drivers don't.

sound/soc/codecs/cs42l51.c line 328

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_DOUBLE_R("PCM Playback Switch", PCMA_VOL, PCMB_VOL, 7, 1, 1),

I suspect that this should be managed via the DAI mute function.

sound/soc/codecs/cs42l51.c line 334

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_SINGLE("Playback Deemphasis", DAC_CTL, 3, 1, 0),

Should have "Switch" at the end of the control name.

sound/soc/codecs/cs42l51.c line 338

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_SINGLE("Mic Bias", MIC_POWER_CTL, 1, 1, 1),

This should be a DAPM MICBIAS control.

sound/soc/codecs/cs42l51.c line 339

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_DOUBLE("Mic Powerdown", MIC_POWER_CTL, 2, 3, 1, 0),

What does this do? Sounds like it should be DAPM controls.

sound/soc/codecs/cs42l51.c line 362

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +2 -0
+	default:
+		printk(KERN_ERR "cs4270: invalid DAI format\n");

Cut'n'paste.

sound/soc/codecs/cs42l51.c line 409

Quoted 3 lines
sound/soc/codecs/cs42l51.c new file +3 -0
+/* Fill me */
+static struct cs42l51_ratios master_ratios[] = { {},
+};

Just remove this stuff for master mode if it's not implemented.

sound/soc/codecs/cs42l51.c line 639

Quoted 10 lines
sound/soc/codecs/cs42l51.c new file +10 -0
+	for (i = 0; i < ARRAY_SIZE(cs42l51_snd_controls); i++) {
+		ret = snd_ctl_add(codec->card,
+				snd_soc_cnew(&cs42l51_snd_controls[i],
+				codec, NULL));
+		if (ret < 0) {
+			dev_err(&pdev->dev, "failed to add controls\n");
+			snd_soc_free_pcms(socdev);
+			return ret;
+		}
+	}

snd_soc_add_controls() rather than open coding.

sound/soc/codecs/cs42l51.h line 123

Quoted 3 lines
sound/soc/codecs/cs42l51.h new file +3 -0
+#define BEEP_FREQ		0x12
+#define BEEP_VOL		0x13
+#define BEEP_CONF		0x14

Please namespace everything in the header - things like this are asking for namespace clashes.

#14 lore raw

Re: [patch 5/6] kirkwood: Add i2s support

In reply to [email protected]
Quoted 1 line · On Tue, May 11, 2010 at 06:23:47PM +0200, [email protected] wrote:

This patch enables support for the i2s codec available on kirkwood platforms

It's not a CODEC, it's the I2S controller in the CPU. A CODEC is a device with DACs and ADCs in it.

sound/soc/kirkwood/kirkwood-dma.c line 71

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+	do {
+		/* we've enabled only bytes interrupts ... */

You were checking for error interrupts further up the function?

sound/soc/kirkwood/kirkwood-dma.c line 74

Quoted 3 lines
sound/soc/kirkwood/kirkwood-dma.c new file +3 -0
+		if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \
+				KIRKWOOD_INT_CAUSE_REC_BYTES))
+			return IRQ_NONE;

Surely it'd make sense to log the unexpected interrupts for diagnostics? You should never get here if there are no interrupts you've enabled. Unless the interrupt is shared, but that'd be a bit surprising for a SoC.

It also looks like it'd be more sensible to either drop the do/while loop entirely (the IRQ core should handle the interrupt still being asserted and it doesn't look like any of the handling should take so long that interrupts reassert while it's running anyway) or move the handling of error interrupts and the first read into the loop so you don't have two slightly different paths.

sound/soc/kirkwood/kirkwood-dma.c line 86

Quoted 11 lines
sound/soc/kirkwood/kirkwood-dma.c new file +11 -0
+		/* ack int */
+		writel(status, priv->io + KIRKWOOD_INT_CAUSE);
+
+		if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES)
+			snd_pcm_period_elapsed(prdata->play_stream);
+
+		if (status & KIRKWOOD_INT_CAUSE_REC_BYTES)
+			snd_pcm_period_elapsed(prdata->rec_stream);
+
+		mask = readl(priv->io + KIRKWOOD_INT_MASK);
+		status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask;

This masking didn't happen prior to the first entry into the loop.

Quoted 1 line

+ if (soc_runtime->dai->cpu_dai->private_data == NULL) {

It seems a bit icky to be managing the DAI private data here...

sound/soc/kirkwood/kirkwood-dma.c line 132

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+		err = request_irq(priv->irq, kirkwood_dma_irq, IRQF_SHARED,
+				  "kirkwood-dma", prdata);

I'd suggest "kirkwood-i2s" as a name here. Or take the name from the DAI.

sound/soc/kirkwood/kirkwood-dma.c line 231

Quoted 4 lines
sound/soc/kirkwood/kirkwood-dma.c new file +4 -0
+static int kirkwood_dma_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	return 0;
+}

Remove this if it's not implemented.

sound/soc/kirkwood/kirkwood-dma.c line 262

Quoted 10 lines
sound/soc/kirkwood/kirkwood-dma.c new file +10 -0
+static int kirkwood_dma_mmap(struct snd_pcm_substream *substream,
+		struct vm_area_struct *vma)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	return dma_mmap_coherent(substream->pcm->card->dev, vma,
+					runtime->dma_area,
+					runtime->dma_addr,
+					runtime->dma_bytes);
+}

Hrm, this looks like there should be a utility function to do it, it's not terribly driver specific.

sound/soc/kirkwood/kirkwood-dma.c line 344

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+struct snd_soc_platform kirkwood_soc_platform = {
+	.name		= "kirkwood-dma",

I'd also add an audio in here or something.

sound/soc/kirkwood/kirkwood.h line 20

Quoted 2 lines
sound/soc/kirkwood/kirkwood.h new file +2 -0
+#define AUDIO_WIN_BASE_REG(win)			(0xA00 + ((win)<<3))
+#define AUDIO_WIN_CTRL_REG(win)			(0xA04 + ((win)<<3))

Namespacing. Or move into the driver, there seems little reason for anything else to be peering at these.

sound/soc/kirkwood/kirkwood.h line 125

Quoted 7 lines
sound/soc/kirkwood/kirkwood.h new file +7 -0
+#define KIRKWOOD_RATES \
+	(SNDRV_PCM_RATE_44100 | \
+	 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+#define KIRKWOOD_FORMATS \
+	(SNDRV_PCM_FMTBIT_S16_LE | \
+	 SNDRV_PCM_FMTBIT_S24_LE | \
+	 SNDRV_PCM_FMTBIT_S32_LE)

Move these into the driver.

Quoted 16 lines
sound/soc/kirkwood/kirkwood.h new file +16 -0
+static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate)
+{
+	unsigned long value;
+
+	value = KIRKWOOD_DCO_CTL_OFFSET_0;
+	switch (rate) {
+	default:
+	case 44100:
+		value |= KIRKWOOD_DCO_CTL_FREQ_11;
+		break;
+	case 48000:
+		value |= KIRKWOOD_DCO_CTL_FREQ_12;
+		break;
+	case 96000:
+		value |= KIRKWOOD_DCO_CTL_FREQ_24;
+		break;

sound/soc/kirkwood/kirkwood.h line 166

Quoted 10 lines
sound/soc/kirkwood/kirkwood.h new file +10 -0
+	}
+	writel(value, io + KIRKWOOD_DCO_CTL);
+
+	/* wait for dco locked */
+	do {
+		cpu_relax();
+		value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
+		value &= KIRKWOOD_DCO_SPCR_STATUS;
+	} while (value == 0);
+}

Why is this an inline function in the header?

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

Quoted 3 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +3 -0
+	 * Size settings in play/rec i2s control regs and play/rec control
+	 * regs must be the same.
+	 */

Ideally you'd be setting up constraints for this.

sound/soc/kirkwood/kirkwood-i2s.c line 134

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+	/*
+	 * specs says KIRKWOOD_PLAYCTL must be read 2 times before
+	 * changing it. So read 1 time here and 1 later.
+	 */
+	value = readl(priv->io + KIRKWOOD_PLAYCTL);

Nice...

sound/soc/kirkwood/kirkwood-i2s.c line 138

Quoted 3 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +3 -0
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* stop audio, enable interrupts */

If audio is running when you're getting a start trigger something is wrong...

sound/soc/kirkwood/kirkwood-i2s.c line 283

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+static int kirkwood_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
+				int clk_id, unsigned int freq, int dir)
+{
+	return 0;
+}

Remove this.

sound/soc/kirkwood/kirkwood-i2s.c line 317

Quoted 9 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +9 -0
+static void mv_audio_init(void __iomem *base)
+{
+	int timeout = 10000000;
+	unsigned int reg_data;
+
+	reg_data = readl(base + 0x1200);
+	reg_data &= (~(0x333FF8));
+	reg_data |= 0x111D18;
+	writel(reg_data, base + 0x1200);

It's like magic!

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

Quoted 4 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +4 -0
+
+	do {
+		timeout--;
+	} while (timeout);

The driver is busy waiting here but not polling anything. Just use a sleep?

sound/soc/kirkwood/kirkwood-i2s.c line 384

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +2 -0
+	/* FIXME : should not be hardcoded */
+	priv->burst = 128;

Platform data?

sound/soc/kirkwood/kirkwood-i2s.c line 331

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +2 -0
+static int kirkwood_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)

This is the ASoC probe but...

+ mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);

...it's pulling all sorts of resources out of the device which are specific to the I2S controller. You should have the I2S controller have a normal platform device which is probed on system startup and triggers DAI registration, just as you're doing in the CODEC driver. All the resources should be there. Apart from anything else this means you only need to set up each I2S controller once in the arch/arm code for the CPU.

sound/soc/kirkwood/kirkwood-i2s.c line 394

Quoted 1 line
sound/soc/kirkwood/kirkwood-i2s.c new file +1 -0
+	mv_audio_init(priv->io);

Seems a bit odd ot have the separate init function in the middle of a bunch of other register writes.

sound/soc/kirkwood/kirkwood-i2s.c line 405

Quoted 1 line
sound/soc/kirkwood/kirkwood-i2s.c new file +1 -0
+	dev_info(&pdev->dev, "kirkwood-i2s driver loaded\n");

May as well remove this. The core logs device registration anyway.

#21 lore raw

Re: [patch 6/6] kirkwood: Add audio support to openrd client platforms

In reply to [email protected]

sound/soc/kirkwood/kirkwood-openrd.c line 127

Quoted 8 lines · On Tue, May 11, 2010 at 06:23:48PM +0200, [email protected] wrote:
sound/soc/kirkwood/kirkwood-openrd.c new file +8 -0
+	adapter = i2c_get_adapter(0);
+	if (!adapter)
+		return -ENODEV;
+
+	cs42l51_client = i2c_new_device(i2c_get_adapter(0), i2c_board_info);
+	i2c_put_adapter(adapter);
+	if (!cs42l51_client)
+		return -ENODEV;

This should be in the arch/arm code. There's no reason to dynamically add this at runtime.

sound/soc/kirkwood/kirkwood-openrd.c line 158

Quoted 13 lines
sound/soc/kirkwood/kirkwood-openrd.c new file +13 -0
+	ret = platform_device_add_resources(openrd_client_snd_device,
+					kirkwood_audio_resources,
+					ARRAY_SIZE(kirkwood_audio_resources));
+	if (ret) {
+		printk(KERN_ERR "%s: Failed to add ressources\n", __func__);
+		return ret;
+	}
+
+	ret = platform_device_add(openrd_client_snd_device);
+	if (ret) {
+		printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
+		platform_device_put(openrd_client_snd_device);
+	}

As I said when reviewing the CPU drivers these should be part of the setup of the I2S device in arch/arm.

#15 lore raw

Re: [patch 5/6] kirkwood: Add i2s support

In reply to Mark Brown

Hi,
some of the dma stuff handled by the i2s! For example the i2s trigger function actually enables the dma, this should be moved to the dma driver. Also, the playback and capture trigger funtions looks alike except to registers offsets, maybe you can unify them. I suggest also to used devm_ functions in the i2s_probe (devm_request_mem_region, devm_kzalloc, devm_ioremap), this way you can remove the err_ cases.

saeed

Quoted 218 lines

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Wednesday, May 12, 2010 1:24 PM
To: [email protected]
Cc: [email protected]; Saeed Bishara; [email protected]; [email protected]
Subject: Re: [patch 5/6] kirkwood: Add i2s support

Quoted 1 line · On Tue, May 11, 2010 at 06:23:47PM +0200, [email protected] wrote:

This patch enables support for the i2s codec available on

kirkwood platforms

It's not a CODEC, it's the I2S controller in the CPU. A CODEC is a device with DACs and ADCs in it.

sound/soc/kirkwood/kirkwood-dma.c line 71

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+	do {
+		/* we've enabled only bytes interrupts ... */

You were checking for error interrupts further up the function?

sound/soc/kirkwood/kirkwood-dma.c line 74

Quoted 3 lines
sound/soc/kirkwood/kirkwood-dma.c new file +3 -0
+		if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \
+				KIRKWOOD_INT_CAUSE_REC_BYTES))
+			return IRQ_NONE;

Surely it'd make sense to log the unexpected interrupts for diagnostics?
You should never get here if there are no interrupts you've enabled. Unless the interrupt is shared, but that'd be a bit surprising for a SoC.

It also looks like it'd be more sensible to either drop the do/while loop entirely (the IRQ core should handle the interrupt still being asserted and it doesn't look like any of the handling should take so long that interrupts reassert while it's running anyway) or move the handling of error interrupts and the first read into the loop so you don't have two slightly different paths.

sound/soc/kirkwood/kirkwood-dma.c line 86

Quoted 11 lines
sound/soc/kirkwood/kirkwood-dma.c new file +11 -0
+		/* ack int */
+		writel(status, priv->io + KIRKWOOD_INT_CAUSE);
+
+		if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES)
+			snd_pcm_period_elapsed(prdata->play_stream);
+
+		if (status & KIRKWOOD_INT_CAUSE_REC_BYTES)
+			snd_pcm_period_elapsed(prdata->rec_stream);
+
+		mask = readl(priv->io + KIRKWOOD_INT_MASK);
+		status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask;

This masking didn't happen prior to the first entry into the loop.

Quoted 1 line

+ if (soc_runtime->dai->cpu_dai->private_data == NULL) {

It seems a bit icky to be managing the DAI private data here...

Review

Quoted 1 line
(quoted diff) +1 -0
+		err = request_irq(priv->irq, kirkwood_dma_irq, 

IRQF_SHARED,

sound/soc/kirkwood/kirkwood-dma.c line 132

Quoted 1 line
sound/soc/kirkwood/kirkwood-dma.c new file +1 -0
+				  "kirkwood-dma", prdata);

I'd suggest "kirkwood-i2s" as a name here. Or take the name from the DAI.

Quoted 1 line

+static int kirkwood_dma_trigger(struct snd_pcm_substream

*substream, int cmd)

sound/soc/kirkwood/kirkwood-dma.c line 153

Quoted 3 lines
sound/soc/kirkwood/kirkwood-dma.c new file +3 -0
+{
+	return 0;
+}

Remove this if it's not implemented.

sound/soc/kirkwood/kirkwood-dma.c line 262

Quoted 10 lines
sound/soc/kirkwood/kirkwood-dma.c new file +10 -0
+static int kirkwood_dma_mmap(struct snd_pcm_substream *substream,
+		struct vm_area_struct *vma)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	return dma_mmap_coherent(substream->pcm->card->dev, vma,
+					runtime->dma_area,
+					runtime->dma_addr,
+					runtime->dma_bytes);
+}

Hrm, this looks like there should be a utility function to do it, it's not terribly driver specific.

sound/soc/kirkwood/kirkwood-dma.c line 344

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+struct snd_soc_platform kirkwood_soc_platform = {
+	.name		= "kirkwood-dma",

I'd also add an audio in here or something.

Quoted 1 line

+#define AUDIO_WIN_BASE_REG(win) (0xA00

+ ((win)<<3))

Quoted 1 line

+#define AUDIO_WIN_CTRL_REG(win) (0xA04

+ ((win)<<3))

Namespacing. Or move into the driver, there seems little reason for anything else to be peering at these.

sound/soc/kirkwood/kirkwood.h line 125

Quoted 7 lines
sound/soc/kirkwood/kirkwood.h new file +7 -0
+#define KIRKWOOD_RATES \
+	(SNDRV_PCM_RATE_44100 | \
+	 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+#define KIRKWOOD_FORMATS \
+	(SNDRV_PCM_FMTBIT_S16_LE | \
+	 SNDRV_PCM_FMTBIT_S24_LE | \
+	 SNDRV_PCM_FMTBIT_S32_LE)

Move these into the driver.

Quoted 1 line

+static inline void kirkwood_set_dco(void __iomem *io,

unsigned long rate)

Quoted 15 lines
sound/soc/kirkwood/kirkwood.h new file +15 -0
+{
+	unsigned long value;
+
+	value = KIRKWOOD_DCO_CTL_OFFSET_0;
+	switch (rate) {
+	default:
+	case 44100:
+		value |= KIRKWOOD_DCO_CTL_FREQ_11;
+		break;
+	case 48000:
+		value |= KIRKWOOD_DCO_CTL_FREQ_12;
+		break;
+	case 96000:
+		value |= KIRKWOOD_DCO_CTL_FREQ_24;
+		break;

sound/soc/kirkwood/kirkwood.h line 166

Quoted 10 lines
sound/soc/kirkwood/kirkwood.h new file +10 -0
+	}
+	writel(value, io + KIRKWOOD_DCO_CTL);
+
+	/* wait for dco locked */
+	do {
+		cpu_relax();
+		value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
+		value &= KIRKWOOD_DCO_SPCR_STATUS;
+	} while (value == 0);
+}

Why is this an inline function in the header?

Review

Quoted 1 line
(quoted diff) +1 -0
+	 * Size settings in play/rec i2s control regs and 

play/rec control

Review

Quoted 2 lines
(quoted diff) +2 -0
+	 * regs must be the same.
+	 */

Ideally you'd be setting up constraints for this.

sound/soc/kirkwood/kirkwood-i2s.c line 134

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+	/*
+	 * specs says KIRKWOOD_PLAYCTL must be read 2 times before
+	 * changing it. So read 1 time here and 1 later.
+	 */
+	value = readl(priv->io + KIRKWOOD_PLAYCTL);

Nice...

sound/soc/kirkwood/kirkwood-i2s.c line 138

Quoted 3 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +3 -0
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* stop audio, enable interrupts */

If audio is running when you're getting a start trigger something is wrong...

sound/soc/kirkwood/kirkwood-i2s.c line 283

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+static int kirkwood_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
+				int clk_id, unsigned int freq, int dir)
+{
+	return 0;
+}

Remove this.

sound/soc/kirkwood/kirkwood-i2s.c line 317

Quoted 9 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +9 -0
+static void mv_audio_init(void __iomem *base)
+{
+	int timeout = 10000000;
+	unsigned int reg_data;
+
+	reg_data = readl(base + 0x1200);
+	reg_data &= (~(0x333FF8));
+	reg_data |= 0x111D18;
+	writel(reg_data, base + 0x1200);

It's like magic!

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

Quoted 4 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +4 -0
+
+	do {
+		timeout--;
+	} while (timeout);

The driver is busy waiting here but not polling anything. Just use a sleep?

sound/soc/kirkwood/kirkwood-i2s.c line 384

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +2 -0
+	/* FIXME : should not be hardcoded */
+	priv->burst = 128;

Platform data?

sound/soc/kirkwood/kirkwood-i2s.c line 331

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +2 -0
+static int kirkwood_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)

This is the ASoC probe but...

+ mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);

...it's pulling all sorts of resources out of the device which are specific to the I2S controller. You should have the I2S controller have
a normal platform device which is probed on system startup and triggers DAI registration, just as you're doing in the CODEC driver. All the resources should be there. Apart from anything else this means you only
need to set up each I2S controller once in the arch/arm code for the CPU.

sound/soc/kirkwood/kirkwood-i2s.c line 394

Quoted 1 line
sound/soc/kirkwood/kirkwood-i2s.c new file +1 -0
+	mv_audio_init(priv->io);

Seems a bit odd ot have the separate init function in the middle of a bunch of other register writes.

sound/soc/kirkwood/kirkwood-i2s.c line 405

Quoted 1 line
sound/soc/kirkwood/kirkwood-i2s.c new file +1 -0
+	dev_info(&pdev->dev, "kirkwood-i2s driver loaded\n");

May as well remove this. The core logs device registration anyway.

#16 lore raw

Re: [patch 5/6] kirkwood: Add i2s support

In reply to Mark Brown

Hi,
some of the dma stuff handled by the i2s! For example the i2s trigger
function actually enables the dma, this should be moved to the dma driver. Also, the playback and capture trigger funtions looks alike except to registers offsets, maybe you can unify them.
I suggest also to used devm_ functions in the i2s_probe
(devm_request_mem_region, devm_kzalloc, devm_ioremap), this way you can remove the err_ cases.

saeed

Quoted 196 lines · Mark Brown
Quoted 1 line · On Tue, May 11, 2010 at 06:23:47PM +0200, [email protected] wrote:

This patch enables support for the i2s codec available on kirkwood platforms

It's not a CODEC, it's the I2S controller in the CPU.  A CODEC is a device with DACs and ADCs in it.

Quoted 2 lines

+     do {
+             /* we've enabled only bytes interrupts ... */

You were checking for error interrupts further up the function?

Quoted 3 lines

+             if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \
+                             KIRKWOOD_INT_CAUSE_REC_BYTES))
+                     return IRQ_NONE;

Surely it'd make sense to log the unexpected interrupts for diagnostics? You should never get here if there are no interrupts you've enabled. Unless the interrupt is shared, but that'd be a bit surprising for a SoC.

It also looks like it'd be more sensible to either drop the do/while loop entirely (the IRQ core should handle the interrupt still being asserted and it doesn't look like any of the handling should take so long that interrupts reassert while it's running anyway) or move the handling of error interrupts and the first read into the loop so you don't have two slightly different paths.

sound/soc/kirkwood/kirkwood-dma.c line 86

Quoted 11 lines

+             /* ack int */
+             writel(status, priv->io + KIRKWOOD_INT_CAUSE);

sound/soc/kirkwood/kirkwood-dma.c new file +9 -0
+
+             if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES)
+                     snd_pcm_period_elapsed(prdata->play_stream);
+
+             if (status & KIRKWOOD_INT_CAUSE_REC_BYTES)
+                     snd_pcm_period_elapsed(prdata->rec_stream);
+
+             mask = readl(priv->io + KIRKWOOD_INT_MASK);
+             status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask;

This masking didn't happen prior to the first entry into the loop.

Quoted 1 line

+       if (soc_runtime->dai->cpu_dai->private_data == NULL) {

It seems a bit icky to be managing the DAI private data here...

Quoted 2 lines

+             err = request_irq(priv->irq, kirkwood_dma_irq, IRQF_SHARED,
+                               "kirkwood-dma", prdata);

I'd suggest "kirkwood-i2s" as a name here.  Or take the name from the DAI.

sound/soc/kirkwood/kirkwood-dma.c line 231

Quoted 4 lines
sound/soc/kirkwood/kirkwood-dma.c new file +4 -0
+static int kirkwood_dma_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+     return 0;
+}

Remove this if it's not implemented.

sound/soc/kirkwood/kirkwood-dma.c line 262

Quoted 10 lines
sound/soc/kirkwood/kirkwood-dma.c new file +10 -0
+static int kirkwood_dma_mmap(struct snd_pcm_substream *substream,
+             struct vm_area_struct *vma)
+{
+     struct snd_pcm_runtime *runtime = substream->runtime;
+
+     return dma_mmap_coherent(substream->pcm->card->dev, vma,
+                                     runtime->dma_area,
+                                     runtime->dma_addr,
+                                     runtime->dma_bytes);
+}

Hrm, this looks like there should be a utility function to do it, it's not terribly driver specific.

Quoted 2 lines

+struct snd_soc_platform kirkwood_soc_platform = {
+     .name           = "kirkwood-dma",

I'd also add an audio in here or something.

sound/soc/kirkwood/kirkwood.h line 20

Quoted 2 lines
sound/soc/kirkwood/kirkwood.h new file +2 -0
+#define AUDIO_WIN_BASE_REG(win)                      (0xA00 + ((win)<<3))
+#define AUDIO_WIN_CTRL_REG(win)                      (0xA04 + ((win)<<3))

Namespacing.  Or move into the driver, there seems little reason for anything else to be peering at these.

sound/soc/kirkwood/kirkwood.h line 125

Quoted 7 lines
sound/soc/kirkwood/kirkwood.h new file +7 -0
+#define KIRKWOOD_RATES \
+     (SNDRV_PCM_RATE_44100 | \
+      SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+#define KIRKWOOD_FORMATS \
+     (SNDRV_PCM_FMTBIT_S16_LE | \
+      SNDRV_PCM_FMTBIT_S24_LE | \
+      SNDRV_PCM_FMTBIT_S32_LE)

Move these into the driver.

Quoted 16 lines
sound/soc/kirkwood/kirkwood.h new file +16 -0
+static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate)
+{
+     unsigned long value;
+
+     value = KIRKWOOD_DCO_CTL_OFFSET_0;
+     switch (rate) {
+     default:
+     case 44100:
+             value |= KIRKWOOD_DCO_CTL_FREQ_11;
+             break;
+     case 48000:
+             value |= KIRKWOOD_DCO_CTL_FREQ_12;
+             break;
+     case 96000:
+             value |= KIRKWOOD_DCO_CTL_FREQ_24;
+             break;

sound/soc/kirkwood/kirkwood.h line 166

Quoted 10 lines
sound/soc/kirkwood/kirkwood.h new file +10 -0
+     }
+     writel(value, io + KIRKWOOD_DCO_CTL);
+
+     /* wait for dco locked */
+     do {
+             cpu_relax();
+             value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
+             value &= KIRKWOOD_DCO_SPCR_STATUS;
+     } while (value == 0);
+}

Why is this an inline function in the header?

Quoted 3 lines

+      * Size settings in play/rec i2s control regs and play/rec control
+      * regs must be the same.
+      */

Ideally you'd be setting up constraints for this.

Quoted 5 lines

+     /*
+      * specs says KIRKWOOD_PLAYCTL must be read 2 times before
+      * changing it. So read 1 time here and 1 later.
+      */
+     value = readl(priv->io + KIRKWOOD_PLAYCTL);

Nice...

Quoted 3 lines

+     switch (cmd) {
+     case SNDRV_PCM_TRIGGER_START:
+             /* stop audio, enable interrupts */

If audio is running when you're getting a start trigger something is wrong...

sound/soc/kirkwood/kirkwood-i2s.c line 283

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+static int kirkwood_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
+                             int clk_id, unsigned int freq, int dir)
+{
+     return 0;
+}

Remove this.

sound/soc/kirkwood/kirkwood-i2s.c line 317

Quoted 9 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +9 -0
+static void mv_audio_init(void __iomem *base)
+{
+     int timeout = 10000000;
+     unsigned int reg_data;
+
+     reg_data = readl(base + 0x1200);
+     reg_data &= (~(0x333FF8));
+     reg_data |= 0x111D18;
+     writel(reg_data, base + 0x1200);

It's like magic!

Quoted 4 lines

+
+     do {
+             timeout--;
+     } while (timeout);

The driver is busy waiting here but not polling anything.  Just use a sleep?

Quoted 2 lines

+     /* FIXME : should not be hardcoded */
+     priv->burst = 128;

Platform data?

Quoted 2 lines

+static int kirkwood_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)

This is the ASoC probe but...

+       mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);

...it's pulling all sorts of resources out of the device which are specific to the I2S controller.  You should have the I2S controller have a normal platform device which is probed on system startup and triggers DAI registration, just as you're doing in the CODEC driver.  All the resources should be there.  Apart from anything else this means you only need to set up each I2S controller once in the arch/arm code for the CPU.

Quoted 1 line

+     mv_audio_init(priv->io);

Seems a bit odd ot have the separate init function in the middle of a bunch of other register writes.

Quoted 8 lines
Quoted 1 line

+     dev_info(&pdev->dev, "kirkwood-i2s driver loaded\n");

May as well remove this.  The core logs device registration anyway.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#17 lore raw

Re: [patch 5/6] kirkwood: Add i2s support

On Wed, May 12, 2010 at 01:48:57PM +0300, saeed bishara wrote:

Please don't top post.

Quoted 3 lines

some of the dma stuff handled by the i2s! For example the i2s trigger
function actually enables the dma, this should be moved to the dma driver. Also, the playback and capture trigger funtions looks alike

There's no real problem with doing this from an ASoC point of view, both devices are part of the same chip so they're free to peer into each other's implementations as much as makes sense for that hardware.

#11 lore raw

Re: [patch 4/6] cs42l51: add asoc driver

In reply to Mark Brown

Mark Brown <[email protected]> writes:

Hi,

Quoted 22 lines · On Tue, May 11, 2010 at 06:23:46PM +0200, [email protected] wrote:
Quoted 3 lines

This patch is adding a ASoC driver for the cs42l51 from Cirrus Logic. Master mode and spi mode are not supported.

This is mostly OK - there's quite a few comments below but there's no massive structural things in here, it's generally small, local things.

Quoted 1 line

+ * Based on cs4270.c - Copyright (c) Timur Tabi <[email protected]>

While we're picking up on the copyright stuff IIRC it's actually Freescale copyright rather than Timur's personal copyright :)

sound/soc/codecs/cs42l51.c line 42

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +5 -0
+enum funct_mode {
+	MODE_SLAVE,
+	MODE_SLAVE_AUTO,
+	MODE_MASTER,
+};

I'd prefer a more meaningful name than "funct_mode" here - I don't really know what a funct is.

Quoted 13 lines

sound/soc/codecs/cs42l51.c line 86

Quoted 9 lines
sound/soc/codecs/cs42l51.c new file +9 -0
+static unsigned int cs42l51_read_reg_cache(struct snd_soc_codec *codec,
+	unsigned int reg)
+{
+	u8 *cache = codec->reg_cache;
+
+	if ((reg < CS42L51_FIRSTREG) || (reg > CS42L51_LASTREG))
+		return -EIO;
+
+	return cache[reg - CS42L51_FIRSTREG];

Please just use the standard register cache access stuff in soc-cache.c. The first register is 1 so you're only burning a single byte of RAM by using the generic code.

I'm using i2c_smbus_read_i2c_block_data() and didn't notice it in the soc-cache.c file. I didn't look further so it's possible that there's actually something working for my case.

Quoted 4 lines

sound/soc/codecs/cs42l51.c line 129

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +1 -0
+	if (ret != MK_CHIP_REV(CHIP_ID, CHIP_REV)) {

Are you sure there's only one device revision in production?

According to the specs there are 2 revs id, the A and B. As I've got a rev B, I assumed that the rev A has not been on prod. I've changed the check to handle both revs.

Quoted 6 lines
Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+		dev_err(&i2c_client->dev, "Invalid chip id\n");
+		ret = -ENODEV;
+		goto error;
+	}
Quoted 6 lines

sound/soc/codecs/cs42l51.c line 136

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +2 -0
+	dev_info(&i2c_client->dev, "found device at I2C address %X\n",
+				i2c_client->addr);

The dev_() will already be including the I2C address in the log message anyway. I'd be inclined to just drop this, or make it log the device revision.

I'll make it log the device revision then. I prefer having a message telling us something was found than no message at all. It's usefull when debugging.

Quoted 10 lines

sound/soc/codecs/cs42l51.c line 166

Quoted 6 lines
sound/soc/codecs/cs42l51.c new file +5 -0
+	ret = cs42l51_fill_cache(codec);
+	if (ret < 0) {
+		dev_err(&i2c_client->dev, "failed to fill register cache\n");
+		goto error;
+	}

Normal practice is to reset the chip so it's in a known sensible state when the driver starts trying to use it. Is there a good reason not to do this here?

The default reset state is good except for the bits I'm changing few lines later.

Quoted 10 lines

sound/soc/codecs/cs42l51.c line 171

Quoted 3 lines
sound/soc/codecs/cs42l51.c new file +2 -0
+	/*
+	 * DAC configuration (right place to do that ?)

It's OK to do this for things that the user would unconditionally want.

sound/soc/codecs/cs42l51.c line 172

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - Use signal processor

What does this mean? It sounds like something that would need to be power managed via DAPM?

there are 3 options for DAC:
00 - PCM Serial Port to DAC
01 - Signal Processing Engine to DAC
10 - ADC Serial Port to DAC

but only the "signal processing engine to DAC" configuration is useful. Using others are dropping some functionnalities.

Quoted 5 lines

sound/soc/codecs/cs42l51.c line 173

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - auto mute

This is probably OK, but exposing as a user visible control would be better.

there's a control for that. I'm only setting the register in a known good state.

Quoted 8 lines

sound/soc/codecs/cs42l51.c line 174

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - vol changes immediate

This is OK.

sound/soc/codecs/cs42l51.c line 175

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - no de-emphasize

This is normally exposed as a user selectable switch.

idem

Quoted 11 lines

sound/soc/codecs/cs42l51.c line 185

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+	/* Unmute PCM-A & PCM-B and set default vol to */
+	ret = cs42l51_i2c_write(codec, PCMA_VOL, 0x60);
+	if (ret < 0)
+		goto error;

This should not be done in the driver, leave it up to userspace. This driver will be used by all systems using this CODEC so just rely on the hardware defaults to provide a sane power on configuration - the designers will usually ensure that this is at least not harmful.

ok. Default is 0db with channel enabled so it's fine I guess.

Quoted 6 lines

sound/soc/codecs/cs42l51.c line 203

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+	/* route microphone */
+	ret = cs42l51_i2c_write(codec, ADC_INPUT, 0xF0);
+	if (ret < 0)
+		goto error;

Ditto.

That's the only way to get microphone support, that's why I didn't consider it as an option.

Quoted 26 lines

sound/soc/codecs/cs42l51.c line 225

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+error_reg:
+	snd_soc_unregister_codec(codec);
+error:
+	return ret;

You're missing some error handling here - there's no free of the device data, for example.

Quoted 17 lines
sound/soc/codecs/cs42l51.c new file +17 -0
+static int cs42l51_get_chan_mix(struct snd_kcontrol *kcontrol,
+			struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+	unsigned long value = snd_soc_read(codec, PCM_MIXER)&3;
+
+	switch (value) {
+	default:
+	case 0:
+		ucontrol->value.integer.value[0] = 0;
+		break;
+	case 1:
+	case 2:
+		ucontrol->value.integer.value[0] = 1;
+		break;
+	case 3:
+		ucontrol->value.integer.value[0] = 2;
Quoted 8 lines

sound/soc/codecs/cs42l51.c line 276

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +5 -0
+		break;
+	}
+
+	return 0;
+}

Some comments here might be a little clearer... Why is the difference between 1 and 2 not interesting?

1 and 2 are 2 values for the same things. (L+R)/2 signal is sent to both channels.

Quoted 15 lines
Quoted 2 lines

+static const char *mic_boost[] = { "+16dB", "+32dB"};

Could use TLV for this too.

sound/soc/codecs/cs42l51.c line 323

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+static const struct soc_enum cs42l51_mix[] = {
+	SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(chan_mix), chan_mix),
+	SOC_ENUM_DOUBLE(MIC_CTL, 0, 1, 2, mic_boost),
+};

Don't do this, declare separate variables for each. Indexing into a table of mixer elements doesn't help leigibility and is asking for off by one errors. Some drivers do this for historical reasons but modern drivers don't.

Quoted 3 lines

sound/soc/codecs/cs42l51.c line 328

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_DOUBLE_R("PCM Playback Switch", PCMA_VOL, PCMB_VOL, 7, 1, 1),

I suspect that this should be managed via the DAI mute function.

I wondered about this too and I choose to not use it. My thoughts was that if I was to go and implement the DAI mute, it should rather mute PCM playback and Analog playback channels at the same time I guess.

Quoted 5 lines

sound/soc/codecs/cs42l51.c line 334

Quoted 2 lines
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_SINGLE("Playback Deemphasis", DAC_CTL, 3, 1, 0),

Should have "Switch" at the end of the control name.

Quoted 7 lines

sound/soc/codecs/cs42l51.c line 338

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_SINGLE("Mic Bias", MIC_POWER_CTL, 1, 1, 1),

This should be a DAPM MICBIAS control.

sound/soc/codecs/cs42l51.c line 339

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_DOUBLE("Mic Powerdown", MIC_POWER_CTL, 2, 3, 1, 0),

What does this do? Sounds like it should be DAPM controls.

It's to power down (or not) the 2 preamplifiers of the microphone channels and not to power down the microphone. Maybe the name is not the best one. Better names accepted.
With this new explanation, should I convert it to DAPM or is it fine as mixer control ?

Arnaud

#12 lore raw

Re: [patch 4/6] cs42l51: add asoc driver

Quoted 12 lines · Arnaud Patard
Quoted 10 lines · Mark Brown

sound/soc/codecs/cs42l51.c line 86

Quoted 4 lines · On Tue, May 11, 2010 at 06:23:46PM +0200, [email protected] wrote:
sound/soc/codecs/cs42l51.c new file +3 -0
+	if ((reg < CS42L51_FIRSTREG) || (reg > CS42L51_LASTREG))
+		return -EIO;
 
+	return cache[reg - CS42L51_FIRSTREG];

Please just use the standard register cache access stuff in soc-cache.c. The first register is 1 so you're only burning a single byte of RAM by using the generic code.

Quoted 3 lines

I'm using i2c_smbus_read_i2c_block_data() and didn't notice it in the soc-cache.c file. I didn't look further so it's possible that there's actually something working for my case.

The soc-cache stuff doesn't deal with initialising the cache so you can still use that to initialise the cache. Generally people use the I2C APIs rather than smbus ones, smbus is just an I2C subset.

Quoted 10 lines
Quoted 9 lines

sound/soc/codecs/cs42l51.c line 166

Quoted 5 lines
sound/soc/codecs/cs42l51.c new file +5 -0
+	ret = cs42l51_fill_cache(codec);
+	if (ret < 0) {
+		dev_err(&i2c_client->dev, "failed to fill register cache\n");
+		goto error;
+	}

Normal practice is to reset the chip so it's in a known sensible state when the driver starts trying to use it. Is there a good reason not to do this here?

Quoted 2 lines

The default reset state is good except for the bits I'm changing few lines later.

In that case a table of register defaults plus doing a reset is likely to be more robust.

Quoted 5 lines
Quoted 4 lines

sound/soc/codecs/cs42l51.c line 172

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	 * - Use signal processor

What does this mean? It sounds like something that would need to be power managed via DAPM?

Quoted 7 lines

there are 3 options for DAC:
00 - PCM Serial Port to DAC
01 - Signal Processing Engine to DAC
10 - ADC Serial Port to DAC

but only the "signal processing engine to DAC" configuration is useful. Using others are dropping some functionnalities.

This sounds like useful stuff to offer to the user as a runtime option - ADC->DAC can be used for bypass paths, and PCM to DAC will presumably save power if the DSP is not in use.

Quoted 9 lines
Quoted 6 lines

sound/soc/codecs/cs42l51.c line 203

Quoted 4 lines
sound/soc/codecs/cs42l51.c new file +4 -0
+	/* route microphone */
+	ret = cs42l51_i2c_write(codec, ADC_INPUT, 0xF0);
+	if (ret < 0)
+		goto error;

Ditto.

That's the only way to get microphone support, that's why I didn't consider it as an option.

The routing should be runtime configurable. I've no idea what the options the chip offers are, but presumably some of the other options are usable.

Quoted 7 lines
Quoted 3 lines

sound/soc/codecs/cs42l51.c line 328

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_DOUBLE_R("PCM Playback Switch", PCMA_VOL, PCMB_VOL, 7, 1, 1),

I suspect that this should be managed via the DAI mute function.

I wondered about this too and I choose to not use it. My thoughts was that if I was to go and implement the DAI mute, it should rather mute PCM playback and Analog playback channels at the same time I guess.

No, the purpose of the DAI mute is specifically to stop the data coming out of the DAC while the digital audio interface is coming up - some systems see noise there when starting up so we do the DAC unmute last in the stream start to ensure that we don't play any of that back to the user.

Quoted 9 lines
Quoted 3 lines

sound/soc/codecs/cs42l51.c line 339

Quoted 1 line
sound/soc/codecs/cs42l51.c new file +1 -0
+	SOC_DOUBLE("Mic Powerdown", MIC_POWER_CTL, 2, 3, 1, 0),

What does this do? Sounds like it should be DAPM controls.

It's to power down (or not) the 2 preamplifiers of the microphone channels and not to power down the microphone. Maybe the name is not the best one. Better names accepted.
With this new explanation, should I convert it to DAPM or is it fine as mixer control ?

That's definitely something that should be managed via DAPM - we only need to power up the amplifier when the signal is being used.

#18 lore raw

Re: [patch 5/6] kirkwood: Add i2s support

In reply to Mark Brown
Quoted 11 lines · Mark Brown
Quoted 1 line · On Tue, May 11, 2010 at 06:23:47PM +0200, [email protected] wrote:

This patch enables support for the i2s codec available on kirkwood platforms

It's not a CODEC, it's the I2S controller in the CPU. A CODEC is a device with DACs and ADCs in it.

sound/soc/kirkwood/kirkwood-dma.c line 71

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+	do {
+		/* we've enabled only bytes interrupts ... */

You were checking for error interrupts further up the function?

Quoted 8 lines

sound/soc/kirkwood/kirkwood-dma.c line 74

Quoted 3 lines
sound/soc/kirkwood/kirkwood-dma.c new file +3 -0
+		if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \
+				KIRKWOOD_INT_CAUSE_REC_BYTES))
+			return IRQ_NONE;

Surely it'd make sense to log the unexpected interrupts for diagnostics? You should never get here if there are no interrupts you've enabled. Unless the interrupt is shared, but that'd be a bit surprising for a SoC.

it's not shared iirc but there are different possible interrupt cause. There used to be a message but I think it has been removed by error. Should I had it back or remove the check ? (I prefer adding it back but your point of view does matter).

Quoted 7 lines

It also looks like it'd be more sensible to either drop the do/while loop entirely (the IRQ core should handle the interrupt still being asserted and it doesn't look like any of the handling should take so long that interrupts reassert while it's running anyway) or move the handling of error interrupts and the first read into the loop so you don't have two slightly different paths.

The loop is there to handle playback and record interrupts at the same time. As regards the error interrupts, I preferred to put outside the loop to differentiate "normal" interrupts from "error" interrupts.

Quoted 14 lines

sound/soc/kirkwood/kirkwood-dma.c line 86

Quoted 12 lines
sound/soc/kirkwood/kirkwood-dma.c new file +11 -0
+		/* ack int */
+		writel(status, priv->io + KIRKWOOD_INT_CAUSE);
+
+		if (status & KIRKWOOD_INT_CAUSE_PLAY_BYTES)
+			snd_pcm_period_elapsed(prdata->play_stream);
+
+		if (status & KIRKWOOD_INT_CAUSE_REC_BYTES)
+			snd_pcm_period_elapsed(prdata->rec_stream);
+
+		mask = readl(priv->io + KIRKWOOD_INT_MASK);
+		status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask;

This masking didn't happen prior to the first entry into the loop.

Can you explain a little bit more ? at the beginning of the function, there are the 2 same lines.

Quoted 10 lines
Quoted 2 lines

+ if (soc_runtime->dai->cpu_dai->private_data == NULL) {

It seems a bit icky to be managing the DAI private data here...

sound/soc/kirkwood/kirkwood-dma.c line 132

Quoted 2 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+		err = request_irq(priv->irq, kirkwood_dma_irq, IRQF_SHARED,
+				  "kirkwood-dma", prdata);

I'd suggest "kirkwood-i2s" as a name here. Or take the name from the DAI.

ok

Quoted 8 lines

sound/soc/kirkwood/kirkwood-dma.c line 231

Quoted 5 lines
sound/soc/kirkwood/kirkwood-dma.c new file +4 -0
+static int kirkwood_dma_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	return 0;
+}

Remove this if it's not implemented.

Quoted 13 lines

sound/soc/kirkwood/kirkwood-dma.c line 262

Quoted 10 lines
sound/soc/kirkwood/kirkwood-dma.c new file +10 -0
+static int kirkwood_dma_mmap(struct snd_pcm_substream *substream,
+		struct vm_area_struct *vma)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
+	return dma_mmap_coherent(substream->pcm->card->dev, vma,
+					runtime->dma_area,
+					runtime->dma_addr,
+					runtime->dma_bytes);
+}

Hrm, this looks like there should be a utility function to do it, it's not terribly driver specific.

hmm... I need to double check. I got some troubles with this kind of stuff on my ST LS2E/F mips platforms, so I wrote something known to be working.

Quoted 65 lines

sound/soc/kirkwood/kirkwood-dma.c line 344

Quoted 3 lines
sound/soc/kirkwood/kirkwood-dma.c new file +2 -0
+struct snd_soc_platform kirkwood_soc_platform = {
+	.name		= "kirkwood-dma",

I'd also add an audio in here or something.

sound/soc/kirkwood/kirkwood.h line 20

Quoted 2 lines
sound/soc/kirkwood/kirkwood.h new file +2 -0
+#define AUDIO_WIN_BASE_REG(win)			(0xA00 + ((win)<<3))
+#define AUDIO_WIN_CTRL_REG(win)			(0xA04 + ((win)<<3))

Namespacing. Or move into the driver, there seems little reason for anything else to be peering at these.

sound/soc/kirkwood/kirkwood.h line 125

Quoted 7 lines
sound/soc/kirkwood/kirkwood.h new file +7 -0
+#define KIRKWOOD_RATES \
+	(SNDRV_PCM_RATE_44100 | \
+	 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
+#define KIRKWOOD_FORMATS \
+	(SNDRV_PCM_FMTBIT_S16_LE | \
+	 SNDRV_PCM_FMTBIT_S24_LE | \
+	 SNDRV_PCM_FMTBIT_S32_LE)

Move these into the driver.

Quoted 16 lines
sound/soc/kirkwood/kirkwood.h new file +16 -0
+static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate)
+{
+	unsigned long value;
+
+	value = KIRKWOOD_DCO_CTL_OFFSET_0;
+	switch (rate) {
+	default:
+	case 44100:
+		value |= KIRKWOOD_DCO_CTL_FREQ_11;
+		break;
+	case 48000:
+		value |= KIRKWOOD_DCO_CTL_FREQ_12;
+		break;
+	case 96000:
+		value |= KIRKWOOD_DCO_CTL_FREQ_24;
+		break;

sound/soc/kirkwood/kirkwood.h line 166

Quoted 10 lines
sound/soc/kirkwood/kirkwood.h new file +10 -0
+	}
+	writel(value, io + KIRKWOOD_DCO_CTL);
+
+	/* wait for dco locked */
+	do {
+		cpu_relax();
+		value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
+		value &= KIRKWOOD_DCO_SPCR_STATUS;
+	} while (value == 0);
+}

Why is this an inline function in the header?

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

Quoted 3 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +3 -0
+	 * Size settings in play/rec i2s control regs and play/rec control
+	 * regs must be the same.
+	 */

Ideally you'd be setting up constraints for this.

sound/soc/kirkwood/kirkwood-i2s.c line 134

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+	/*
+	 * specs says KIRKWOOD_PLAYCTL must be read 2 times before
+	 * changing it. So read 1 time here and 1 later.
+	 */
+	value = readl(priv->io + KIRKWOOD_PLAYCTL);

Nice...

Quoted 6 lines

sound/soc/kirkwood/kirkwood-i2s.c line 138

Quoted 3 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +3 -0
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		/* stop audio, enable interrupts */

If audio is running when you're getting a start trigger something is wrong...

I'm too paranoid ? here

Quoted 9 lines

sound/soc/kirkwood/kirkwood-i2s.c line 283

Quoted 6 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +5 -0
+static int kirkwood_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
+				int clk_id, unsigned int freq, int dir)
+{
+	return 0;
+}

Remove this.

Quoted 11 lines

sound/soc/kirkwood/kirkwood-i2s.c line 317

Quoted 9 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +9 -0
+static void mv_audio_init(void __iomem *base)
+{
+	int timeout = 10000000;
+	unsigned int reg_data;
+
+	reg_data = readl(base + 0x1200);
+	reg_data &= (~(0x333FF8));
+	reg_data |= 0x111D18;
+	writel(reg_data, base + 0x1200);

It's like magic!

yeah. I've not been able to find out any info in the specs about that and last time I tried with that it was not working :(

Quoted 21 lines

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

Quoted 5 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +4 -0
+
+	do {
+		timeout--;
+	} while (timeout);

The driver is busy waiting here but not polling anything. Just use a sleep?

sound/soc/kirkwood/kirkwood-i2s.c line 384

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +2 -0
+	/* FIXME : should not be hardcoded */
+	priv->burst = 128;

Platform data?

sound/soc/kirkwood/kirkwood-i2s.c line 331

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +2 -0
+static int kirkwood_i2s_probe(struct platform_device *pdev,
+                            struct snd_soc_dai *dai)

This is the ASoC probe but...

+ mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);

Quoted 7 lines

...it's pulling all sorts of resources out of the device which are specific to the I2S controller. You should have the I2S controller have a normal platform device which is probed on system startup and triggers DAI registration, just as you're doing in the CODEC driver. All the resources should be there. Apart from anything else this means you only need to set up each I2S controller once in the arch/arm code for the CPU.

ok. Will look at that stuff.

Quoted 5 lines

sound/soc/kirkwood/kirkwood-i2s.c line 394

Quoted 2 lines
sound/soc/kirkwood/kirkwood-i2s.c new file +1 -0
+	mv_audio_init(priv->io);

Seems a bit odd ot have the separate init function in the middle of a bunch of other register writes.

I want to have interrupts disable before calling it. I don't want bad suprises.

Arnaud

#19 lore raw

Re: [patch 5/6] kirkwood: Add i2s support

Quoted 12 lines · Arnaud Patard
Quoted 10 lines · Mark Brown

sound/soc/kirkwood/kirkwood-dma.c line 74

Quoted 3 lines · On Tue, May 11, 2010 at 06:23:47PM +0200, [email protected] wrote:
sound/soc/kirkwood/kirkwood-dma.c new file +3 -0
+		if (status & ~(KIRKWOOD_INT_CAUSE_PLAY_BYTES | \
+				KIRKWOOD_INT_CAUSE_REC_BYTES))
+			return IRQ_NONE;

Surely it'd make sense to log the unexpected interrupts for diagnostics? You should never get here if there are no interrupts you've enabled. Unless the interrupt is shared, but that'd be a bit surprising for a SoC.

Quoted 4 lines

it's not shared iirc but there are different possible interrupt cause. There used to be a message but I think it has been removed by error. Should I had it back or remove the check ? (I prefer adding it back but your point of view does matter).

Add it back and also log it, but also fix the IRQ_NONE thing - it's defintiely going to be wrong if this is the second spin through the loop for example.

Quoted 8 lines
Quoted 6 lines

It also looks like it'd be more sensible to either drop the do/while loop entirely (the IRQ core should handle the interrupt still being asserted and it doesn't look like any of the handling should take so long that interrupts reassert while it's running anyway) or move the handling of error interrupts and the first read into the loop so you don't have two slightly different paths.

The loop is there to handle playback and record interrupts at the same

Why is this required? You check both interrupts in sequence anyway.

Quoted 2 lines

time. As regards the error interrupts, I preferred to put outside the loop to differentiate "normal" interrupts from "error" interrupts.

Actually looking again they are in a separate status register too so I suppose that's not quite so bad. It is a bit odd that they all come in on the same status line and can't be muxed out from a single register but hardware designers are like that sometimes.

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		mask = readl(priv->io + KIRKWOOD_INT_MASK);
+		status = readl(priv->io + KIRKWOOD_INT_CAUSE) & mask;

This masking didn't happen prior to the first entry into the loop.

Can you explain a little bit more ? at the beginning of the function, there are the 2 same lines.

I was looking at the read of cause there, I hadn't noticed the separate status register.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
sound/soc/kirkwood/kirkwood-dma.c new file +5 -0
+static int kirkwood_dma_mmap(struct snd_pcm_substream *substream,
+		struct vm_area_struct *vma)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+
Quoted 8 lines

sound/soc/kirkwood/kirkwood-dma.c line 262

Quoted 5 lines
sound/soc/kirkwood/kirkwood-dma.c new file +5 -0
+	return dma_mmap_coherent(substream->pcm->card->dev, vma,
+					runtime->dma_area,
+					runtime->dma_addr,
+					runtime->dma_bytes);
+}

Hrm, this looks like there should be a utility function to do it, it's not terribly driver specific.

Quoted 3 lines

hmm... I need to double check. I got some troubles with this kind of stuff on my ST LS2E/F mips platforms, so I wrote something known to be working.

The point is that it looks like either there should already be an implementation of this function you can use or this should be put somewhere were other folks are able to use it.

Quoted 7 lines
Quoted 4 lines

sound/soc/kirkwood/kirkwood-i2s.c line 394

Quoted 1 line
sound/soc/kirkwood/kirkwood-i2s.c new file +1 -0
+	mv_audio_init(priv->io);

Seems a bit odd ot have the separate init function in the middle of a bunch of other register writes.

I want to have interrupts disable before calling it. I don't want bad suprises.

My point is that you may as well just have the mv_audio_init() function in line in the code here, jumping out into another function seems a bit odd when all it is is more register writes.

#7 lore raw

Re: [patch 3/6] asoc: Add SOC_DOUBLE_R_SX_TLV control

In reply to [email protected]
Quoted 7 lines · On Tue, May 11, 2010 at 06:23:45PM +0200, [email protected] wrote:

This patch is adding a new control which has the following capabilities:
- tlv
- variable data size (for instance, 7 ou 8 bit)
- double mixer

So, after discussing with Liam on IRC I was going to rewrite the commit message and apply this but it doesn't apply to current ASoC. Please make sure any patches for ASoC apply to:

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

(or whatever the latest kernel version there's a branch for is.)