Skip to contentSkip to conversation

ASoC: cs35l33: Initial commit of the cs35l33 CODEC driver.

PATCH Superseded [email protected] 2 participants 6 messages May 13, 2016 – May 26, 2016

Subsystems (4)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 ASoC: cs35l33: Initial commit of the cs35l33 CODEC driver.

From: Paul Handrigan <[email protected]>

Initial commit of the Cirrus Logic cs35l33 8V boosted class D amplifier.

---
 include/sound/cs35l33.h    |   54 ++
 sound/soc/codecs/Kconfig   |    5 +
 sound/soc/codecs/Makefile  |    2 +
 sound/soc/codecs/cs35l33.c | 1304 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cs35l33.h |  221 ++++++++
 5 files changed, 1586 insertions(+)
 create mode 100644 include/sound/cs35l33.h
 create mode 100644 sound/soc/codecs/cs35l33.c
 create mode 100644 sound/soc/codecs/cs35l33.h
include/sound/cs35l33.h new file +54 -0
new file mode 100644
index 0000000..d18181c
@@ -0,0 +1,54 @@
+/*
+ * linux/sound/cs35l33.h -- Platform data for CS35l33
+ *
+ * Copyright (c) 2015 Cirrus Logic Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __CS35L33_H
+#define __CS35L33_H
+
+struct cs35l33_hg {
+	bool enable_hg_algo;
+	unsigned int mem_depth;
+	unsigned int release_rate;
+	unsigned int hd_rm;
+	unsigned int ldo_thld;
+	unsigned int ldo_path_disable;
+	unsigned int ldo_entry_delay;
+	bool vp_hg_auto;
+	unsigned int vp_hg;
+	unsigned int vp_hg_rate;
+	unsigned int vp_hg_va;
+};
+
+struct cs35l33_pdata {
+	/* GPIO for IRQ */
+	int gpio_irq;
+
+	/* irq line */
+	int irq;
+
+	/* Boost Controller Voltage Setting */
+	unsigned int boost_ctl;
+
+	/* Boost Controller Peak Current */
+	unsigned int boost_ipk;
+
+	/* Amplifier Drive Select */
+	unsigned int amp_drv_sel;
+
+	/* soft volume ramp */
+	unsigned int ramp_rate;
+
+	/* IMON adc scale */
+	unsigned int imon_adc_scale;
+
+	/* H/G algo configuration */
+	struct cs35l33_hg hg_config;
+};
+
+#endif /* __CS35L33_H */
sound/soc/codecs/Kconfig +5 -0
index c6f86ef..6ba6f8f 100644
@@ -46,6 +46,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_BT_SCO
 	select SND_SOC_CQ0093VC if MFD_DAVINCI_VOICECODEC
 	select SND_SOC_CS35L32 if I2C
+	select SND_SOC_CS35L33 if I2C
 	select SND_SOC_CS42L51_I2C if I2C
 	select SND_SOC_CS42L52 if I2C && INPUT
 	select SND_SOC_CS42L56 if I2C && INPUT
@@ -379,6 +380,10 @@ config SND_SOC_CS35L32
 	tristate "Cirrus Logic CS35L32 CODEC"
 	depends on I2C
 
+config SND_SOC_CS35L33
+	tristate "Cirrus Logic CS35L33 CODEC"
+	depends on I2C
+
 config SND_SOC_CS42L51
 	tristate
 
sound/soc/codecs/Makefile +2 -0
index 94873ee..22e7474 100644
@@ -35,6 +35,7 @@ snd-soc-arizona-objs := arizona.o
 snd-soc-bt-sco-objs := bt-sco.o
 snd-soc-cq93vc-objs := cq93vc.o
 snd-soc-cs35l32-objs := cs35l32.o
+snd-soc-cs35l33-objs := cs35l33.o
 snd-soc-cs42l51-objs := cs42l51.o
 snd-soc-cs42l51-i2c-objs := cs42l51-i2c.o
 snd-soc-cs42l52-objs := cs42l52.o
@@ -249,6 +250,7 @@ obj-$(CONFIG_SND_SOC_ARIZONA)	+= snd-soc-arizona.o
 obj-$(CONFIG_SND_SOC_BT_SCO)	+= snd-soc-bt-sco.o
 obj-$(CONFIG_SND_SOC_CQ0093VC) += snd-soc-cq93vc.o
 obj-$(CONFIG_SND_SOC_CS35L32)	+= snd-soc-cs35l32.o
+obj-$(CONFIG_SND_SOC_CS35L33)	+= snd-soc-cs35l33.o
 obj-$(CONFIG_SND_SOC_CS42L51)	+= snd-soc-cs42l51.o
 obj-$(CONFIG_SND_SOC_CS42L51_I2C)	+= snd-soc-cs42l51-i2c.o
 obj-$(CONFIG_SND_SOC_CS42L52)	+= snd-soc-cs42l52.o
sound/soc/codecs/cs35l33.c new file +1304 -0

1,304 lines not on this page · raw message

sound/soc/codecs/cs35l33.h new file +221 -0

221 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 2/2 ASoC: cs35l33: Add device tree bindings file for cs35l33

From: Paul Handrigan <[email protected]>

Add device tree bindings file for the cs35l33 8V boosted class D amplifier.

---
 .../devicetree/bindings/sound/cs35l33.txt          | 73 ++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cs35l33.txt
Documentation/devicetree/bindings/sound/cs35l33.txt new file +73 -0
new file mode 100644
index 0000000..273d73a
@@ -0,0 +1,73 @@
+CS35L33 Speaker Amplifier
+
+Required properties:
+
+  - compatible : "cirrus,cs35l33"
+
+  - reg : the I2C address of the device for I2C
+
+  - VA-supply, VP-supply : power supplies for the device,
+    as covered in
+    Documentation/devicetree/bindings/regulator/regulator.txt.
+
+Optional properties:
+
+  - reset-gpios : gpio used to reset the amplifier
+
+  - interrupt-parent : Specifies the phandle of the interrupt controller to
+    which the IRQs from CS35L33 are delivered to.
+ -  interrupts : IRQ line info CS35L33.
+    (See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+    for further information relating to interrupt properties)
+
+  - boost-ctl : Booster voltage use to supply the amp. If the value is
+    0, then VBST = VP. If greater than 0, the boost voltage will be 3.3V with
+    a value of 1 and will increase at a step size of 0.1V until a maximum of
+    8.0V.
+
+  - ramp-rate : On power up, it affects the time from when the power
+    up sequence begins to the time the audio reaches a full-scale output.
+    On power down, it affects the time from when the power-down sequence
+    begins to when the amplifier disables the PWM outputs. If this property
+    is not set then soft ramping will be disabled and ramp time would be
+    20ms. If this property is set to 0,1,2,3 then ramp times would be 40ms,
+    60ms,100ms,175ms respectively for 48KHz sample rate.
+
+  - boost-ipk : The maximum current allowed for the boost converter.
+    The range starts at 1.85A (0xF0) and goes to a maximum of 3.60A (0xE0)
+    with a step size of 0.015625A. The default is 2.50A (0x90).
+
+  - hg-algo : Parameters for internal Class H/G algorithm that
+    controls the amplifier supplies.
+
+Example:
+
+cs35l33: cs35l33@40 {
+	compatible = "cirrus,cs35l33";
+	reg = <0x40>;
+
+	VA-supply = <&ldo5_reg>;
+	VP-supply = <&ldo5_reg>;
+
+	interrupt-parent = <&gpio8>;
+	interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+
+	reset-gpios = <&cs47l91 34 0>;
+
+	ramp-rate = <0x0>;
+	boost-ctl = <0x30>;  /* VBST = 8.0V */
+	boost-ipk = <0xE0>; /* 3.60A */
+
+	hg-algo {
+		mem-depth = <0x3>;
+		release-rate = <0x3>;
+		hd-rm = <0xA>;
+		ldo-thld = <0x1>;
+		ldo-path-disable = <0x0>;
+		ldo-entry-delay=<0x4>;
+		vp-hg-auto;
+		vp-hg=<0xF>;
+		vp-hg-rate=<0x2>;
+		vp-hg-va=<0x0>;
+	};
+};
Signature · 1 line
1.9.1
maintainer
#2 lore raw
In reply to [email protected]

sound/soc/codecs/cs35l33.c line 814

Quoted 6 lines · On Fri, May 13, 2016 at 03:50:28PM -0500, [email protected] wrote:
sound/soc/codecs/cs35l33.c new file +6 -0
+static struct regmap *cs35l33_get_regmap(struct device *dev)
+{
+	struct cs35l33_private *cs35l33 = dev_get_drvdata(dev);
+
+	return cs35l33->regmap;
+}

Doesn't the default work for you?

sound/soc/codecs/cs35l33.c line 955

Quoted 2 lines
sound/soc/codecs/cs35l33.c new file +2 -0
+	for (i = 0; i < CS35L33_INT_ATTEMPTS; i++) {
+		/* ack the irq by reading both status registers */

Why do we need this...?

sound/soc/codecs/cs35l33.c line 977

Quoted 3 lines
sound/soc/codecs/cs35l33.c new file +3 -0
+		if (sticky_val1 & CS35L33_AMP_SHORT) {
+			dev_err(codec->dev, "Amp short error\n");
+			if (!(current_val & CS35L33_AMP_SHORT)) {

dev_crit()

sound/soc/codecs/cs35l33.c line 1014

Quoted 2 lines
sound/soc/codecs/cs35l33.c new file +2 -0
+		if (sticky_val1 & CS35L33_OTE) {
+			dev_err(codec->dev, "Over temperature error\n");

Same here - these are extremely serious and probably indicate very serious physical problems.

sound/soc/codecs/cs35l33.c line 1178

Quoted 4 lines
sound/soc/codecs/cs35l33.c new file +4 -0
+	} else if (IS_ERR(cs35l33->reset_gpio)) {
+	dev_err(&i2c_client->dev, "%s ERROR: Can't get reset GPIO\n",
+			__func__);
+		return PTR_ERR(cs35l33->reset_gpio);

Indentation is messed up here.

#3 lore raw
Quoted 11 lines · Mark Brown

sound/soc/codecs/cs35l33.c line 814

Quoted 6 lines · On Fri, May 13, 2016 at 03:50:28PM -0500, [email protected] wrote:
sound/soc/codecs/cs35l33.c new file +6 -0
+static struct regmap *cs35l33_get_regmap(struct device *dev)
+{
+	struct cs35l33_private *cs35l33 = dev_get_drvdata(dev);
+
+	return cs35l33->regmap;
+}

Doesn't the default work for you?

I can remove this function.

Quoted 4 lines

sound/soc/codecs/cs35l33.c line 955

Quoted 2 lines
sound/soc/codecs/cs35l33.c new file +2 -0
+	for (i = 0; i < CS35L33_INT_ATTEMPTS; i++) {
+		/* ack the irq by reading both status registers */

Why do we need this...?

The we need to keep handling the unmasked interrupts until they are all cleared. We could get another interrupt while handling the first triggered interrupt, but the interrupt line could be de-asserted due to the read-to-clear nature of the interrupt status registers.

Quoted 7 lines

sound/soc/codecs/cs35l33.c line 992

Quoted 4 lines
sound/soc/codecs/cs35l33.c new file +3 -0
+		if (sticky_val1 & CS35L33_AMP_SHORT) {
+			dev_err(codec->dev, "Amp short error\n");
+
			if (!(current_val & CS35L33_AMP_SHORT)) {

dev_crit()

OK.

Quoted 7 lines

sound/soc/codecs/cs35l33.c line 1014

Quoted 3 lines
sound/soc/codecs/cs35l33.c new file +2 -0
+		if (sticky_val1 & CS35L33_OTE) {
+			dev_err(codec->dev, "Over temperature error\n");

Same here - these are extremely serious and probably indicate very serious physical problems.

OK.

Quoted 7 lines

sound/soc/codecs/cs35l33.c line 1178

Quoted 5 lines
sound/soc/codecs/cs35l33.c new file +4 -0
+	} else if (IS_ERR(cs35l33->reset_gpio)) {
+	dev_err(&i2c_client->dev, "%s ERROR: Can't get reset GPIO\n",
+			__func__);
+		return PTR_ERR(cs35l33->reset_gpio);

Indentation is messed up here.

OK. Thanks!

Quoted 1 line
maintainer
#4 lore raw
Quoted 8 lines · Paul Handrigan
Quoted 6 lines · Mark Brown

sound/soc/codecs/cs35l33.c line 955

Quoted 2 lines · On Fri, May 13, 2016 at 03:50:28PM -0500, [email protected] wrote:
sound/soc/codecs/cs35l33.c new file +2 -0
+	for (i = 0; i < CS35L33_INT_ATTEMPTS; i++) {
+		/* ack the irq by reading both status registers */

Why do we need this...?

Quoted 4 lines

The we need to keep handling the unmasked interrupts until they are all cleared. We could get another interrupt while handling the first triggered interrupt, but the interrupt line could be de-asserted due to the read-to-clear nature of the interrupt status registers.

This doesn't follow? Clear to read shouldn't be affected by reading repeatedly, or at least I don't see that helps any problems in a non-racy fashion, and the interrupt subsystem will happily call the handler again if the interrupt reasserts during handling so new interrupts shouldn't be an issue either. New interrupts are an issue for most devices so we really ought to have handling for that in the interrupt subsystem if it's needed, or possibly the usage of the subsystem needs to change to take advantage of preexisting handling...

#5 lore raw
Quoted 14 lines · Mark Brown
Quoted 8 lines · Paul Handrigan
Quoted 6 lines · Mark Brown

sound/soc/codecs/cs35l33.c line 955

Quoted 2 lines · On Fri, May 13, 2016 at 03:50:28PM -0500, [email protected] wrote:
sound/soc/codecs/cs35l33.c new file +2 -0
+	for (i = 0; i < CS35L33_INT_ATTEMPTS; i++) {
+		/* ack the irq by reading both status registers */

Why do we need this...?

Quoted 4 lines

The we need to keep handling the unmasked interrupts until they are all cleared. We could get another interrupt while handling the first triggered interrupt, but the interrupt line could be de-asserted due to the read-to-clear nature of the interrupt status registers.

Quoted 9 lines

This doesn't follow? Clear to read shouldn't be affected by reading repeatedly, or at least I don't see that helps any problems in a non-racy fashion, and the interrupt subsystem will happily call the handler again if the interrupt reasserts during handling so new interrupts shouldn't be an issue either. New interrupts are an issue for most devices so we really ought to have handling for that in the interrupt subsystem if it's needed, or possibly the usage of the subsystem needs to change to take advantage of preexisting handling...

After taking a closer look at it, it would make sence to remove the for loop. We will still need to attempt clear the unmasked interrupt status bits since it may take a few reads to clear those bits.