Skip to contentSkip to conversation

ASoC: pcm512x: Add PCM512x driver

PATCH In review Mark Brown 5 participants 13 messages Feb 6, 2014 – Feb 24, 2014 6 messages not in the archive

Subsystems (4)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 ASoC: pcm512x: Add PCM512x driver

From: Mark Brown <[email protected]>

The PCM512x devices are a family of monolithic CMOS integrated circuits that include a stereo digital-to-analog converter and additional support circuitry.

This is an initial driver which supports some core functionality for the device which covers common use cases but does not cover all features. Currently only slave clocking modes with automatic clock configuration are supported and most of the DSP configuration for the device is not enabled.

---
 .../devicetree/bindings/sound/pcm512x.txt          |  30 +
 sound/soc/codecs/Kconfig                           |   4 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/pcm512x.c                         | 671 +++++++++++++++++++++
 sound/soc/codecs/pcm512x.h                         | 142 +++++
 5 files changed, 849 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/pcm512x.txt
 create mode 100644 sound/soc/codecs/pcm512x.c
 create mode 100644 sound/soc/codecs/pcm512x.h
Documentation/devicetree/bindings/sound/pcm512x.txt new file +30 -0
new file mode 100644
index 000000000000..faff75e64573
@@ -0,0 +1,30 @@
+PCM512x audio CODECs
+
+These devices support both I2C and SPI (configured with pin strapping
+on the board).
+
+Required properties:
+
+  - compatible : One of "ti,pcm5121" or "ti,pcm5122"
+
+  - reg : the I2C address of the device for I2C, the chip select
+          number for SPI.
+
+  - AVDD-supply, DVDD-supply, and CPVDD-supply : power supplies for the
+    device, as covered in bindings/regulator/regulator.txt
+
+Optional properties:
+
+  - clocks : A clock specifier for the clock connected as SCLK.  If this
+    is absent the device will be configured to clock from BCLK.
+
+Example:
+
+	pcm5122: pcm5122@4c {
+		compatible = "ti,pcm5122";
+		reg = <0x4c>;
+
+		AVDD-supply = <&reg_3v3_analog>;
+		DVDD-supply = <&reg_1v8>;
+		CPVDD-supply = <&reg_3v3>;
+	};
sound/soc/codecs/Kconfig +4 -0
index f0bdcc5abe83..28faa2d0eaef 100644
@@ -60,6 +60,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_PCM1681 if I2C
 	select SND_SOC_PCM1792A if SPI_MASTER
 	select SND_SOC_PCM3008
+	select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
 	select SND_SOC_RT5631 if I2C
 	select SND_SOC_RT5640 if I2C
 	select SND_SOC_SGTL5000 if I2C
@@ -324,6 +325,9 @@ config SND_SOC_PCM1792A
 config SND_SOC_PCM3008
        tristate
 
+config SND_SOC_PCM512x
+       tristate "Texas Instruments PCM512x CODECs"
+
 config SND_SOC_RT5631
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index bc126764a44d..d3b536fc075d 100644
@@ -46,6 +46,7 @@ snd-soc-hdmi-codec-objs := hdmi.o
 snd-soc-pcm1681-objs := pcm1681.o
 snd-soc-pcm1792a-codec-objs := pcm1792a.o
 snd-soc-pcm3008-objs := pcm3008.o
+snd-soc-pcm512x-objs := pcm512x.o
 snd-soc-rt5631-objs := rt5631.o
 snd-soc-rt5640-objs := rt5640.o
 snd-soc-sgtl5000-objs := sgtl5000.o
@@ -179,6 +180,7 @@ obj-$(CONFIG_SND_SOC_HDMI_CODEC) += snd-soc-hdmi-codec.o
 obj-$(CONFIG_SND_SOC_PCM1681)	+= snd-soc-pcm1681.o
 obj-$(CONFIG_SND_SOC_PCM1792A)	+= snd-soc-pcm1792a-codec.o
 obj-$(CONFIG_SND_SOC_PCM3008)	+= snd-soc-pcm3008.o
+obj-$(CONFIG_SND_SOC_PCM512x)	+= snd-soc-pcm512x.o
 obj-$(CONFIG_SND_SOC_RT5631)	+= snd-soc-rt5631.o
 obj-$(CONFIG_SND_SOC_RT5640)	+= snd-soc-rt5640.o
 obj-$(CONFIG_SND_SOC_SGTL5000)  += snd-soc-sgtl5000.o
sound/soc/codecs/pcm512x.c new file +671 -0

671 lines not on this page · raw message

sound/soc/codecs/pcm512x.h new file +142 -0

142 lines not on this page · raw message

Signature · 6 lines
1.9.rc1

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

A message that is not in the archive (sent off-list or not yet received): 1391689575-4039-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#2 lore raw

At Thu, 6 Feb 2014 12:26:15 +0000,

Quoted 1 line · Mark Brown
sound/soc/codecs/pcm512x.c +0 -0

(snip)

Quoted 4 lines
sound/soc/codecs/pcm512x.c +4 -0
+static const char *pcm512x_dsp_program_texts[] = {
+	"FIR interpolation with de-emphasis",
+	"Low latency IIR with de-emphasis",
+	"High attenuation with de-emphasis",

sound/soc/codecs/pcm512x.c line 183

Quoted 10 lines
sound/soc/codecs/pcm512x.c +10 -0
+	"Ringing-less low latency FIR",
+};
+
+static const unsigned int pcm512x_dsp_program_values[] = {
+	1,
+	2,
+	3,
+	5,
+	7,
+};

The numbers of items in pcm512x_dsp_program_texts[] and _values[] don't match.

sound/soc/codecs/pcm512x.c line 195

Quoted 11 lines
sound/soc/codecs/pcm512x.c +11 -0
+static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
+					PCM512x_DSP_PROGRAM, 0, 0x1f,
+					pcm512x_dsp_program_texts,
+					pcm512x_dsp_program_values);
+
+static const char *pcm512x_clk_missing_text[] = {
+	"1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
+};
+
+static const struct soc_enum pcm512x_clk_missing =
+	SOC_ENUM_SINGLE(PCM512x_CLKDET, 0,  7, pcm512x_clk_missing_text);

Isn't it 8?

sound/soc/codecs/pcm512x.c line 207

Quoted 12 lines
sound/soc/codecs/pcm512x.c +12 -0
+
+static const char *pcm512x_autom_text[] = {
+	"21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
+};
+
+static const struct soc_enum pcm512x_autom_l =
+	SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
+			pcm512x_autom_text);
+
+static const struct soc_enum pcm512x_autom_r =
+	SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
+			pcm512x_autom_text);

Ditto.

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

A message that is not in the archive (sent off-list or not yet received): s5hr47gv1yi.wl%[email protected]

author
#4 lore raw
Quoted 6 lines · Takashi Iwai
Quoted 1 line · Mark Brown

+static const char *pcm512x_dsp_program_texts[] = {

The numbers of items in pcm512x_dsp_program_texts[] and _values[] don't match.

Yeah, fixed.

Quoted 4 lines

sound/soc/codecs/pcm512x.c line 195

Quoted 2 lines
sound/soc/codecs/pcm512x.c new file +2 -0
+static const struct soc_enum pcm512x_clk_missing =
+	SOC_ENUM_SINGLE(PCM512x_CLKDET, 0,  7, pcm512x_clk_missing_text);

Isn't it 8?

Hrm, it is but this points out an error in the control helpers which has been there since forever - they call that parameter max but it's not a maximum, it's the number of elements in the enumeration. I bet we have a bunch of other enumerations which miss the last element as a result.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

At Thu, 6 Feb 2014 13:07:35 +0000,

Quoted 10 lines · Mark Brown
Quoted 6 lines · Takashi Iwai
Quoted 1 line · Mark Brown

+static const char *pcm512x_dsp_program_texts[] = {

The numbers of items in pcm512x_dsp_program_texts[] and _values[] don't match.

Yeah, fixed.

I'm thinking whether we can check this in the macro.
I thought of using BUILD_BUG_ON(), but it's unsure whether it aligns there well.

Quoted 9 lines
Quoted 4 lines

sound/soc/codecs/pcm512x.c line 195

Quoted 2 lines
sound/soc/codecs/pcm512x.c new file +2 -0
+static const struct soc_enum pcm512x_clk_missing =
+	SOC_ENUM_SINGLE(PCM512x_CLKDET, 0,  7, pcm512x_clk_missing_text);

Isn't it 8?

Hrm, it is but this points out an error in the control helpers which has been there since forever - they call that parameter max but it's not a maximum, it's the number of elements in the enumeration. I bet we have a bunch of other enumerations which miss the last element as a result.

Yeah, the argument name is really confusing. I had to double-check the code when I reviewed your patch, too :)

Also it'd be better to have a practice to use either ARRAY_SIZE() or a constant there, too.

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

A message that is not in the archive (sent off-list or not yet received): s5hob2kv0z3.wl%[email protected]

#8 lore raw
Quoted 2 lines · Takashi Iwai

At Thu, 6 Feb 2014 13:07:35 +0000,
Mark Brown wrote:

[...]

Quoted 10 lines
Quoted 4 lines

Hrm, it is but this points out an error in the control helpers which has been there since forever - they call that parameter max but it's not a maximum, it's the number of elements in the enumeration. I bet we have a bunch of other enumerations which miss the last element as a result.

Yeah, the argument name is really confusing. I had to double-check the code when I reviewed your patch, too :)

Also it'd be better to have a practice to use either ARRAY_SIZE() or a constant there, too.

There is also SOC_ENUM_SINGLE_DECL(...) which takes care of the common case where you want as many items as your array contains.

- Lars

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

A message that is not in the archive (sent off-list or not yet received): 52F38B27.1040502-Qo5EllUWu/[email protected]

#10 lore raw

At Thu, 06 Feb 2014 14:16:23 +0100,

Quoted 10 lines · Lars-Peter Clausen
Quoted 2 lines · Takashi Iwai

At Thu, 6 Feb 2014 13:07:35 +0000,
Mark Brown wrote:

[...]

Quoted 5 lines
Quoted 4 lines

Hrm, it is but this points out an error in the control helpers which has been there since forever - they call that parameter max but it's not a maximum, it's the number of elements in the enumeration. I bet we have a bunch of other enumerations which miss the last element as a result.

Quoted 8 lines
Quoted 5 lines

Yeah, the argument name is really confusing. I had to double-check the code when I reviewed your patch, too :)

Also it'd be better to have a practice to use either ARRAY_SIZE() or a constant there, too.

There is also SOC_ENUM_SINGLE_DECL(...) which takes care of the common case where you want as many items as your array contains.

Ah, right, that makes life easier.

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

author
#11 lore raw
In reply to a message not in the archive
Quoted 10 lines · Takashi Iwai
Quoted 4 lines · Mark Brown
Quoted 2 lines

The numbers of items in pcm512x_dsp_program_texts[] and _values[] don't match.

Yeah, fixed.

I'm thinking whether we can check this in the macro.
I thought of using BUILD_BUG_ON(), but it's unsure whether it aligns there well.

Yes, or changing the way we pass things in so it's an array of key/value. Usability isn't great for enums in general and particularly poor for sparse ones.

Quoted 10 lines
Quoted 4 lines

Hrm, it is but this points out an error in the control helpers which has been there since forever - they call that parameter max but it's not a maximum, it's the number of elements in the enumeration. I bet we have a bunch of other enumerations which miss the last element as a result.

Yeah, the argument name is really confusing. I had to double-check the code when I reviewed your patch, too :)

Also it'd be better to have a practice to use either ARRAY_SIZE() or a constant there, too.

Indeed - even better would be to just remove the parameter entirely and use ARRAY_SIZE() on the array of strings we get passed in so there's no way it could be messed up.

#12 lore raw
In reply to Mark Brown

[dropped devicetree ML, as it's irrelevant now]

At Thu, 6 Feb 2014 13:07:35 +0000,

Quoted 16 lines · Mark Brown
Quoted 6 lines · Takashi Iwai
Quoted 1 line · Mark Brown

+static const char *pcm512x_dsp_program_texts[] = {

The numbers of items in pcm512x_dsp_program_texts[] and _values[] don't match.

Yeah, fixed.

Quoted 4 lines

sound/soc/codecs/pcm512x.c line 195

Quoted 2 lines
sound/soc/codecs/pcm512x.c new file +2 -0
+static const struct soc_enum pcm512x_clk_missing =
+	SOC_ENUM_SINGLE(PCM512x_CLKDET, 0,  7, pcm512x_clk_missing_text);

Isn't it 8?

Quoted 4 lines

Hrm, it is but this points out an error in the control helpers which has been there since forever - they call that parameter max but it's not a maximum, it's the number of elements in the enumeration. I bet we have a bunch of other enumerations which miss the last element as a result.

I audited through the current code, and indeed there are quite a few bugs because of this. I'm going to send a full patch series including cleanups to alsa-devel ML. Since I split patches over each driver, it ended up 102 patches. So, be prepared :)

There are still open issues after this, and let's discuss in another thread.

Takashi

maintainer
#13 lore raw
Quoted 4 lines · Takashi Iwai

I audited through the current code, and indeed there are quite a few bugs because of this. I'm going to send a full patch series including cleanups to alsa-devel ML. Since I split patches over each driver, it ended up 102 patches. So, be prepared :)

OK, I think that's everything handled now.

Quoted 2 lines

There are still open issues after this, and let's discuss in another thread.

What were these?

#14 lore raw

At Sun, 23 Feb 2014 12:07:55 +0900,

Quoted 9 lines · Mark Brown
Quoted 4 lines · Takashi Iwai

I audited through the current code, and indeed there are quite a few bugs because of this. I'm going to send a full patch series including cleanups to alsa-devel ML. Since I split patches over each driver, it ended up 102 patches. So, be prepared :)

OK, I think that's everything handled now.

Thanks!

Quoted 4 lines
Quoted 2 lines

There are still open issues after this, and let's discuss in another thread.

What were these?

The strange usages of SOC_VALUE_ENUM in a couple of cirrus codec drivers.

Takashi

maintainer
#15 lore raw
Quoted 10 lines · Takashi Iwai
Quoted 6 lines · Mark Brown
Quoted 2 lines · Takashi Iwai

There are still open issues after this, and let's discuss in another thread.

What were these?

The strange usages of SOC_VALUE_ENUM in a couple of cirrus codec drivers.

Right, OK - there's also some volume controls are a bit odd there in some of the older ones, seems a few things only worked by luck.

#16 lore raw
In reply to a message not in the archive

On 02/06/2014 01:26 PM, Mark Brown wrote:
[...]

Quoted 1 line

+static const char *pcm512x_dsp_program_texts[] = {

Nitpick: should be "static const char * const ...", a immutable array of pointers pointing to immutable strings. Same for all the enum texts in this driver. [...]

Quoted 8 lines
sound/soc/codecs/pcm512x.c new file +8 -0
+static int __init pcm512x_modinit(void)
+{
+	int ret = 0;
+
+#if IS_ENABLED(CONFIG_I2C)
+	ret = i2c_add_driver(&pcm512x_i2c_driver);
+	if (ret) {
+		printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",

sound/soc/codecs/pcm512x.c line 653

Quoted 10 lines
sound/soc/codecs/pcm512x.c new file +10 -0
+		       ret);
+	}
+#endif
+#if defined(CONFIG_SPI_MASTER)
+	ret = spi_register_driver(&pcm512x_spi_driver);
+	if (ret != 0) {
+		printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
+		       ret);
+	}
+#endif

Another reason why I think it is better to separate the I2C and SPI bits into different modules. If the registration of the SPI driver fails you'll return an error and the module will not be loaded. At the same time the i2c driver is already registered. I know that this is rather theoretical, but if we don't care if our error handling is correct, because we assume that the error will never happen, we do not need error handling at all.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return ret;
+}

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

A message that is not in the archive (sent off-list or not yet received): 52F38CF7.7060306-Qo5EllUWu/[email protected]

author
#18 lore raw
Quoted 7 lines · Lars-Peter Clausen
Quoted 1 line · Mark Brown

+static const char *pcm512x_dsp_program_texts[] = {

Nitpick: should be "static const char * const ...", a immutable array of pointers pointing to immutable strings. Same for all the enum texts in this driver.

Oh, good - someone fixed the core code for that without me noticing. Last time I looked if you made the strings const there were annoying warnings since they got passed in to things that weren't expecting const strings and it seemed to annoying to check that it was actually safe in all cases.

Quoted 7 lines

Another reason why I think it is better to separate the I2C and SPI bits into different modules. If the registration of the SPI driver fails you'll return an error and the module will not be loaded. At the same time the i2c driver is already registered. I know that this is rather theoretical, but if we don't care if our error handling is correct, because we assume that the error will never happen, we do not need error handling at all.

Like I say I'm perfectly aware of the issues, I just don't have much enthusiasm myself since they pretty much only affect unrealistic and apparently quite rare randconfigs - the time I might spend on that is more likely to get spent on things like the format negotiation stuff. If someone (you? :P) wants to do the work that's fine but nobody had shown any sign of that until your driver the other day.

I do also want to see some explicit conversion happening so it's clearer that this is a deliberate change that's being rolled out.