Skip to contentSkip to conversation

ASoC CS4270 codec device driver

PATCH In review Timur Tabi 3 participants 8 messages Jul 31, 2007

Subsystems (3)
lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH v3 1/1 ASoC CS4270 codec device driver

This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The following features are suppored:

1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management

---

This code is based on git.kernel.org/pub/scm/linux/kernel/git/perex/alsa.git.

 include/linux/i2c-id.h    |    1 +
 sound/soc/codecs/Kconfig  |   20 ++
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/cs4270.c |  808 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs4270.h |   28 ++
 5 files changed, 859 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/codecs/cs4270.c
 create mode 100644 sound/soc/codecs/cs4270.h
include/linux/i2c-id.h +1 -0
index b690148..c4aadc6 100644
@@ -119,6 +119,7 @@
 #define I2C_DRIVERID_WM8750	90	/* Wolfson WM8750 audio codec */
 #define I2C_DRIVERID_WM8753	91	/* Wolfson WM8753 audio codec */
 #define I2C_DRIVERID_LM4857 	92 	/* LM4857 Audio Amplifier */
+#define I2C_DRIVERID_CS4270	93	/* Cirrus Logic 4270 audio codec */
 
 #define I2C_DRIVERID_I2CDEV	900
 #define I2C_DRIVERID_ARP        902    /* SMBus ARP Client              */
sound/soc/codecs/Kconfig +20 -0
index e5fb437..7824880 100644
@@ -17,3 +17,23 @@ config SND_SOC_WM8753
 config SND_SOC_WM9712
 	tristate
 	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+	tristate
+	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+	bool
+	depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V.  The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+	bool
+	depends on SND_SOC_CS4270
+
sound/soc/codecs/Makefile +2 -0
index e39a747..7ad78e3 100644
@@ -3,9 +3,11 @@ snd-soc-wm8731-objs := wm8731.o
 snd-soc-wm8750-objs := wm8750.o
 snd-soc-wm8753-objs := wm8753.o
 snd-soc-wm9712-objs := wm9712.o
+snd-soc-cs4270-objs := cs4270.o
 
 obj-$(CONFIG_SND_SOC_AC97_CODEC)	+= snd-soc-ac97.o
 obj-$(CONFIG_SND_SOC_WM8731)	+= snd-soc-wm8731.o
 obj-$(CONFIG_SND_SOC_WM8750)	+= snd-soc-wm8750.o
 obj-$(CONFIG_SND_SOC_WM8753)	+= snd-soc-wm8753.o
 obj-$(CONFIG_SND_SOC_WM9712)	+= snd-soc-wm9712.o
+obj-$(CONFIG_SND_SOC_CS4270)	+= snd-soc-cs4270.o
sound/soc/codecs/cs4270.c new file +808 -0

808 lines not on this page · raw message

sound/soc/codecs/cs4270.h new file +28 -0
new file mode 100644
index 0000000..0ced49b
@@ -0,0 +1,28 @@
+/*
+ * Cirrus Logic CS4270 ALSA SoC Codec Driver
+ *
+ * Author: Timur Tabi <[email protected]>
+ *
+ * Copyright 2007 Freescale Semiconductor, Inc.  This file is licensed under
+ * the terms of the GNU General Public License version 2.  This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#ifndef _CS4270_H
+#define _CS4270_H
+
+/*
+ * The ASoC codec DAI structure for the CS4270.  Assign this structure to
+ * the .codec_dai field of your machine driver's snd_soc_dai_link structure.
+ */
+extern struct snd_soc_codec_dai cs4270_dai;
+
+/*
+ * The ASoC codec device structure for the CS4270.  Assign this structure
+ * to the .codec_dev field of your machine driver's snd_soc_device
+ * structure.
+ */
+extern struct snd_soc_codec_device soc_codec_device_cs4270;
+
+#endif
Signature · 1 line
1.5.2.4
#1 lore raw

At Tue, 31 Jul 2007 10:46:52 -0500,

Quoted 10 lines · Timur Tabi

This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The following features are suppored:

1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management

Thanks, it can be now applied fine.

The only thing I noticed is below (oh I should have mentioned it before...):

Quoted 18 lines
sound/soc/codecs/Kconfig +10 -0
index e5fb437..7824880 100644
@@ -17,3 +17,23 @@ config SND_SOC_WM8753
 config SND_SOC_WM9712
 	tristate
 	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+	tristate
+	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+	bool

sound/soc/codecs/Kconfig config SND_SOC_WM8753 · line 39

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+	depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V.  The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+	bool
+	depends on SND_SOC_CS4270
+

I'd suggest to convert these comments to help texts. Also, usually the items to be chosen via menuconfig have
tristate "XXXX"
or
bool "XXX"

Could you fix them, then I'll finally merge it to upstream?

thanks,

Takashi

author
#2 lore raw
Quoted 52 lines · Takashi Iwai

At Tue, 31 Jul 2007 10:46:52 -0500,

Quoted 9 lines · Timur Tabi

This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The following features are suppored:

1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management

Thanks, it can be now applied fine.

The only thing I noticed is below (oh I should have mentioned it before...):

Quoted 18 lines
sound/soc/codecs/Kconfig +10 -0
index e5fb437..7824880 100644
@@ -17,3 +17,23 @@ config SND_SOC_WM8753
 config SND_SOC_WM9712
 	tristate
 	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+	tristate
+	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+	bool

sound/soc/codecs/Kconfig config SND_SOC_WM8753 · line 39

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+	depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V.  The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+	bool
+	depends on SND_SOC_CS4270
+

I'd suggest to convert these comments to help texts. Also, usually the items to be chosen via menuconfig have
tristate "XXXX"
or
bool "XXX"

Quoted 1 line

Could you fix them, then I'll finally merge it to upstream?

I am following the model of the other Kconfig options. If I add the "XXXX" and the help text, then they become selectable from "make menuconfig", but they would be the only ones to show up like that.

I think the reason why they are like this is because they're supposed to be selected from the machine driver that uses them, like this:

config SND_AT91_SOC_ETI_B1_WM8731
tristate "SoC Audio support for WM8731-based Endrelia ETI-B1 boards" depends on SND_AT91_SOC && (MACH_ETI_B1 || MACH_ETI_C1) select SND_AT91_SOC_SSC
select SND_SOC_WM8731
help
Say Y if you want to add support for SoC audio on WM8731-based Endrelia Technologies Inc ETI-B1 or ETI-C1 boards.

So that the only way you can specify the CS4270 is if you have a machine driver that uses it.

Signature · 2 lines
Timur Tabi
Linux Kernel Developer @ Freescale
#3 lore raw

At Tue, 31 Jul 2007 11:12:44 -0500,

Quoted 54 lines · Timur Tabi
Quoted 52 lines · Takashi Iwai

At Tue, 31 Jul 2007 10:46:52 -0500,

Quoted 9 lines · Timur Tabi

This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The following features are suppored:

1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management

Thanks, it can be now applied fine.

The only thing I noticed is below (oh I should have mentioned it before...):

Quoted 18 lines
sound/soc/codecs/Kconfig +10 -0
index e5fb437..7824880 100644
@@ -17,3 +17,23 @@ config SND_SOC_WM8753
 config SND_SOC_WM9712
 	tristate
 	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+	tristate
+	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+	bool

sound/soc/codecs/Kconfig config SND_SOC_WM8753 · line 39

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+	depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V.  The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+	bool
+	depends on SND_SOC_CS4270
+

I'd suggest to convert these comments to help texts. Also, usually the items to be chosen via menuconfig have
tristate "XXXX"
or
bool "XXX"

Quoted 8 lines
Quoted 1 line

Could you fix them, then I'll finally merge it to upstream?

I am following the model of the other Kconfig options. If I add the "XXXX" and the help text, then they become selectable from "make menuconfig", but they would be the only ones to show up like that.

I think the reason why they are like this is because they're supposed to be selected from the machine driver that uses them, like this:

Doh, I see, these are codecs only for reverse selections. Sorry for confusion. Then I'll merge it as it is.

Takashi

#4 lore raw

At Tue, 31 Jul 2007 18:17:33 +0200,

Quoted 63 lines · I wrote:

At Tue, 31 Jul 2007 11:12:44 -0500,

Quoted 60 lines · Timur Tabi
Quoted 52 lines · Takashi Iwai

At Tue, 31 Jul 2007 10:46:52 -0500,

Quoted 9 lines · Timur Tabi

This patch adds ALSA SoC support for the Cirrus Logic CS4270 codec. The following features are suppored:

1) Stand-alone and software mode
2) Software mode via I2C only
3) Master mode, not Slave
4) No power management

Thanks, it can be now applied fine.

The only thing I noticed is below (oh I should have mentioned it before...):

Quoted 18 lines
sound/soc/codecs/Kconfig +10 -0
index e5fb437..7824880 100644
@@ -17,3 +17,23 @@ config SND_SOC_WM8753
 config SND_SOC_WM9712
 	tristate
 	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec
+config SND_SOC_CS4270
+	tristate
+	depends on SND_SOC
+
+# Cirrus Logic CS4270 Codec Hardware Mute Support
+# Select if you have external muting circuitry attached to your CS4270.
+config SND_SOC_CS4270_HWMUTE
+	bool

sound/soc/codecs/Kconfig config SND_SOC_WM8753 · line 39

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+	depends on SND_SOC_CS4270
+
+# Cirrus Logic CS4270 Codec VD = 3.3V Errata
+# Select if you are affected by the errata where the part will not function
+# if MCLK divide-by-1.5 is selected and VD is set to 3.3V.  The driver will
+# not select any sample rates that require MCLK to be divided by 1.5.
+config SND_SOC_CS4270_VD33_ERRATA
+	bool
+	depends on SND_SOC_CS4270
+

I'd suggest to convert these comments to help texts. Also, usually the items to be chosen via menuconfig have
tristate "XXXX"
or
bool "XXX"

Quoted 1 line

Could you fix them, then I'll finally merge it to upstream?

I am following the model of the other Kconfig options. If I add the "XXXX" and the help text, then they become selectable from "make menuconfig", but they would be the only ones to show up like that.

Quoted 5 lines
Quoted 2 lines

I think the reason why they are like this is because they're supposed to be selected from the machine driver that uses them, like this:

Doh, I see, these are codecs only for reverse selections. Sorry for confusion. Then I'll merge it as it is.

OK, now found another problem. The driver seems not built without CONFIG_I2C.

In file included from sound/soc/codecs/cs4270.c:1:
sound/soc/codecs/cs4270.c:694: error: ‘cs4270_set_dai_sysclk’ undeclared here (not in a function) sound/soc/codecs/cs4270.c:695: error: ‘cs4270_set_dai_fmt’ undeclared here (not in a function)

Shouldn't the driver be dependent on I2C?

Also,

#ifdef CONFIG_I2C

isn't enough. It should be

#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)

since I2C can be a module.

I already merged V3 to HG tree, so please post the additional patch against it for fixing these issues.

thanks,

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

author
#5 lore raw
Quoted 8 lines · Takashi Iwai

OK, now found another problem. The driver seems not built without CONFIG_I2C.

In file included from sound/soc/codecs/cs4270.c:1:
sound/soc/codecs/cs4270.c:694: error: ‘cs4270_set_dai_sysclk’ undeclared here (not in a function) sound/soc/codecs/cs4270.c:695: error: ‘cs4270_set_dai_fmt’ undeclared here (not in a function)

Shouldn't the driver be dependent on I2C?

Well, technically no. It should work find without I2C, but I admit I never tried that. I'll provide a fix soon.

Quoted 7 lines

Also,

#ifdef CONFIG_I2C

isn't enough. It should be

#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)

I asked about that a while ago, and I never got an answer. Where does CONFIG_I2C_MODULE come from? I don't see it in any Kconfig or any header file. And if I2C can be a module, then why wouldn't CONFIG_I2C also be defined?

Signature · 2 lines
Timur Tabi
Linux Kernel Developer @ Freescale
#6 lore raw
Quoted 5 lines · Timur Tabi
Quoted 4 lines · Takashi Iwai

Also,

#ifdef CONFIG_I2C

Quoted 7 lines
Quoted 3 lines

isn't enough. It should be

#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)

I asked about that a while ago, and I never got an answer. Where does CONFIG_I2C_MODULE come from? I don't see it in any Kconfig or any header file. And if I2C can be a module, then why wouldn't CONFIG_I2C also be defined?

If config FOO is compiled in (i.e. it's "y"), CONFIG_FOO will be defined. If it's a module, CONFIG_FOO_MODULE will be defined. It's one or the other, not both.

If you want your code to comple differently if it has i2c available, you should do this:

#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) /* code that needs i2c goes here, i2c_transfer(), etc. */ #endif

Note that just checking defined(CONFIG_I2C_MODULE) isn't correct. If your code is compiled in and i2c is a module, you can't call i2c functions or the kernel won't link.

Of course, if you need i2c to work in any reasonble way, you should just have your driver depend on i2c in Kconfig.

author
#7 lore raw
Quoted 3 lines · Trent Piepho

If config FOO is compiled in (i.e. it's "y"), CONFIG_FOO will be defined. If it's a module, CONFIG_FOO_MODULE will be defined. It's one or the other, not both.

Learn something new every day. I should have known that already, though.

Quoted 10 lines

If you want your code to comple differently if it has i2c available, you should do this:

#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) /* code that needs i2c goes here, i2c_transfer(), etc. */ #endif

Note that just checking defined(CONFIG_I2C_MODULE) isn't correct. If your code is compiled in and i2c is a module, you can't call i2c functions or the kernel won't link.

Which is a problem because ASoC currently requires all modules to be linked together. The machine driver has hard-coded references to structures in the other drivers.

I think Liam was trying to fix that with the PowerPC branch, but it doesn't look like he's finished.

Quoted 2 lines

Of course, if you need i2c to work in any reasonble way, you should just have your driver depend on i2c in Kconfig.

Well, that's the odd thing about the CS4270 - it's not required. The CS4270 can work with or without I2C. I tried writing the driver to be intelligent about that - if I2C is enabled, but the device can't be found on the I2C bus, it falls back to "stand-alone" mode.

It looks like I'm not really going to be able to support stand-alone mode yet, anyway. So I'll just try to make it compile when I2C is disabled.

Signature · 2 lines
Timur Tabi
Linux Kernel Developer @ Freescale