Skip to contentSkip to conversation

Cirrus Logic CS35L41 Amplifier

PATCH Superseded David Rhodes 3 participants 12 messages Jul 2, 2021 – Jul 22, 2021

Subsystems (4)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 cover Cirrus Logic CS35L41 Amplifier

ASoC driver and devicetree documentation for a new Cirrus Logic amplifier CS35L41

v3 changes:
Removed redundant info from license header
Alphabetized includes
Changed comment on ACPI ID to reflect that vendor portion is a PnP ID Removed some unnecessary initializations
Changed some uses of (x == NULL) to (!x)

David Rhodes (2):
ASoC: cs35l41: CS35L41 Boosted Smart Amplifier
ASoC: cs35l41: Add bindings for CS35L41

 .../devicetree/bindings/sound/cs35l41.yaml    |  395 ++++
 include/sound/cs35l41.h                       |   79 +
 sound/soc/codecs/Kconfig                      |   12 +
 sound/soc/codecs/Makefile                     |    4 +
 sound/soc/codecs/cs35l41-i2c.c                |  120 ++
 sound/soc/codecs/cs35l41-spi.c                |  147 ++
 sound/soc/codecs/cs35l41-tables.c             |  612 ++++++
 sound/soc/codecs/cs35l41.c                    | 1765 +++++++++++++++++
 sound/soc/codecs/cs35l41.h                    |  750 +++++++
 9 files changed, 3884 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cs35l41.yaml
 create mode 100644 include/sound/cs35l41.h
 create mode 100644 sound/soc/codecs/cs35l41-i2c.c
 create mode 100644 sound/soc/codecs/cs35l41-spi.c
 create mode 100644 sound/soc/codecs/cs35l41-tables.c
 create mode 100644 sound/soc/codecs/cs35l41.c
 create mode 100644 sound/soc/codecs/cs35l41.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v3 1/2 ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

SoC Audio driver for the Cirrus Logic CS35L41 amplifier

---
 include/sound/cs35l41.h           |   79 ++
 sound/soc/codecs/Kconfig          |   12 +
 sound/soc/codecs/Makefile         |    4 +
 sound/soc/codecs/cs35l41-i2c.c    |  120 ++
 sound/soc/codecs/cs35l41-spi.c    |  147 +++
 sound/soc/codecs/cs35l41-tables.c |  612 ++++++++++
 sound/soc/codecs/cs35l41.c        | 1765 +++++++++++++++++++++++++++++
 sound/soc/codecs/cs35l41.h        |  750 ++++++++++++
 8 files changed, 3489 insertions(+)
 create mode 100644 include/sound/cs35l41.h
 create mode 100644 sound/soc/codecs/cs35l41-i2c.c
 create mode 100644 sound/soc/codecs/cs35l41-spi.c
 create mode 100644 sound/soc/codecs/cs35l41-tables.c
 create mode 100644 sound/soc/codecs/cs35l41.c
 create mode 100644 sound/soc/codecs/cs35l41.h
include/sound/cs35l41.h new file +79 -0
new file mode 100644
index 000000000000..7ee60ff0de26
@@ -0,0 +1,79 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/*
+ * linux/sound/cs35l41.h -- Platform data for CS35L41
+ *
+ * Copyright (c) 2017-2021 Cirrus Logic Inc.
+ *
+ * Author: David Rhodes	<[email protected]>
+ */
+
+#ifndef __CS35L41_H
+#define __CS35L41_H
+
+enum cs35l41_clk_ids {
+	CS35L41_CLKID_SCLK = 0,
+	CS35L41_CLKID_LRCLK = 1,
+	CS35L41_CLKID_MCLK = 4,
+};
+
+struct cs35l41_classh_cfg {
+	bool classh_bst_override;
+	bool classh_algo_enable;
+	int classh_bst_max_limit;
+	int classh_mem_depth;
+	int classh_release_rate;
+	int classh_headroom;
+	int classh_wk_fet_delay;
+	int classh_wk_fet_thld;
+};
+
+struct cs35l41_irq_cfg {
+	bool irq_pol_inv;
+	bool irq_out_en;
+	int irq_src_sel;
+};
+
+struct cs35l41_platform_data {
+	bool sclk_frc;
+	bool lrclk_frc;
+	bool right_channel;
+	bool amp_gain_zc;
+	bool dsp_ng_enable;
+	bool invert_pcm;
+	int bst_ind;
+	int bst_vctrl;
+	int bst_ipk;
+	int bst_cap;
+	int temp_warn_thld;
+	int dsp_ng_pcm_thld;
+	int dsp_ng_delay;
+	unsigned int hw_ng_sel;
+	unsigned int hw_ng_delay;
+	unsigned int hw_ng_thld;
+	int dout_hiz;
+	struct cs35l41_irq_cfg irq_config1;
+	struct cs35l41_irq_cfg irq_config2;
+	struct cs35l41_classh_cfg classh_config;
+};
+
+struct cs35l41_private {
+	struct snd_soc_codec *codec;
+	struct cs35l41_platform_data pdata;
+	struct device *dev;
+	struct regmap *regmap;
+	struct regulator_bulk_data supplies[2];
+	int num_supplies;
+	int irq;
+	bool i2s_mode;
+	/* GPIO for /RST */
+	struct gpio_desc *reset_gpio;
+	void (*otp_setup)(struct cs35l41_private *cs35l41, bool is_pre_setup,
+						unsigned int *freq);
+};
+
+int cs35l41_probe(struct cs35l41_private *cs35l41,
+				struct cs35l41_platform_data *pdata);
+int cs35l41_remove(struct cs35l41_private *cs35l41);
+
+#endif /* __CS35L41_H */
sound/soc/codecs/Kconfig +12 -0
index 2a7b3e363069..bd30de9a1f71 100644
@@ -61,6 +61,8 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_CS35L34
 	imply SND_SOC_CS35L35
 	imply SND_SOC_CS35L36
+	imply SND_SOC_CS35L41_SPI
+	imply SND_SOC_CS35L41_I2C
 	imply SND_SOC_CS42L42
 	imply SND_SOC_CS42L51_I2C
 	imply SND_SOC_CS42L52
@@ -597,6 +599,16 @@ config SND_SOC_CS35L36
 	tristate "Cirrus Logic CS35L36 CODEC"
 	depends on I2C
 
+config SND_SOC_CS35L41_SPI
+	tristate "Cirrus Logic CS35L41 CODEC (SPI)"
+	depends on SPI_MASTER
+	select REGMAP_SPI
+
+config SND_SOC_CS35L41_I2C
+	tristate "Cirrus Logic CS35L41 CODEC (I2C)"
+	depends on I2C
+	select REGMAP_I2C
+
 config SND_SOC_CS42L42
 	tristate "Cirrus Logic CS42L42 CODEC"
 	depends on I2C
sound/soc/codecs/Makefile +4 -0
index 0efdba609048..056e1180cd67 100644
@@ -54,6 +54,8 @@ snd-soc-cs35l33-objs := cs35l33.o
 snd-soc-cs35l34-objs := cs35l34.o
 snd-soc-cs35l35-objs := cs35l35.o
 snd-soc-cs35l36-objs := cs35l36.o
+snd-soc-cs35l41-spi-objs := cs35l41-spi.o cs35l41.o cs35l41-tables.o
+snd-soc-cs35l41-i2c-objs := cs35l41-i2c.o cs35l41.o cs35l41-tables.o
 snd-soc-cs42l42-objs := cs42l42.o
 snd-soc-cs42l51-objs := cs42l51.o
 snd-soc-cs42l51-i2c-objs := cs42l51-i2c.o
@@ -379,6 +381,8 @@ obj-$(CONFIG_SND_SOC_CS35L33)	+= snd-soc-cs35l33.o
 obj-$(CONFIG_SND_SOC_CS35L34)	+= snd-soc-cs35l34.o
 obj-$(CONFIG_SND_SOC_CS35L35)	+= snd-soc-cs35l35.o
 obj-$(CONFIG_SND_SOC_CS35L36)	+= snd-soc-cs35l36.o
+obj-$(CONFIG_SND_SOC_CS35L41_SPI)	+= snd-soc-cs35l41-spi.o
+obj-$(CONFIG_SND_SOC_CS35L41_I2C)	+= snd-soc-cs35l41-i2c.o
 obj-$(CONFIG_SND_SOC_CS42L42)	+= snd-soc-cs42l42.o
 obj-$(CONFIG_SND_SOC_CS42L51)	+= snd-soc-cs42l51.o
 obj-$(CONFIG_SND_SOC_CS42L51_I2C)	+= snd-soc-cs42l51-i2c.o
sound/soc/codecs/cs35l41-i2c.c new file +120 -0

120 lines not on this page · raw message

sound/soc/codecs/cs35l41-spi.c new file +147 -0

147 lines not on this page · raw message

sound/soc/codecs/cs35l41-tables.c new file +612 -0

612 lines not on this page · raw message

sound/soc/codecs/cs35l41.c new file +1765 -0

1,765 lines not on this page · raw message

sound/soc/codecs/cs35l41.h new file +750 -0

237 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.25.1

Part of the diff is not shown here. View the raw message.

maintainer
#2 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

On Fri, Jul 02, 2021 at 03:51:26PM -0500, David Rhodes wrote:

This looks pretty good - a few fairly small issues and some queries below:

include/sound/cs35l41.h line 62

Quoted 8 lines

index 000000000000..7ee60ff0de26

include/sound/cs35l41.h new file +3 -0
@@ -0,0 +1,79 @@
 
+struct cs35l41_private {
+	struct snd_soc_codec *codec;
+	struct cs35l41_platform_data pdata;

Why does anything looking in include/sound need the driver private data? It's not entirely clear why this is in include/sound at all.

include/sound/cs35l41.h line 66

Quoted 2 lines
include/sound/cs35l41.h new file +2 -0
+	struct regulator_bulk_data supplies[2];
+	int num_supplies;

Why might the number of supplies vary?

include/sound/cs35l41.h line 4

Quoted 6 lines

+++ b/sound/soc/codecs/cs35l41-i2c.c

include/sound/cs35l41.h new file +4 -0
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * cs35l41-i2c.c -- CS35l41 I2C driver

Please make the entire comment a C++ one so things look more intentional.

include/sound/cs35l41.h line 6

Quoted 2 lines
include/sound/cs35l41.h new file +2 -0
+#include <linux/slab.h>
+#include <linux/version.h>

You probably don't need at least version.h here.

include/sound/cs35l41.h line 16

Quoted 10 lines
include/sound/cs35l41.h new file +10 -0
+static void cs35l41_spi_otp_setup(struct cs35l41_private *cs35l41,
+					bool is_pre_setup, unsigned int *freq)
+{
+	struct spi_device *spi;
+	u32 orig_spi_freq;
+
+	spi = to_spi_device(cs35l41->dev);
+
+	if (!spi)
+		return;

Why might this reasonably happen, shouldn't we complain loudly?

include/sound/cs35l41.h line 21

Quoted 5 lines
include/sound/cs35l41.h new file +5 -0
+#ifdef CONFIG_OF
+static const struct of_device_id cs35l41_of_match[] = {
+	{.compatible = "cirrus,cs35l40"},
+	{.compatible = "cirrus,cs35l41"},
+	{},

Coding style - spaces around the { } like everywhere else.

include/sound/cs35l41.h

Quoted 10 lines
include/sound/cs35l41.h new file +8 -0
+	/* Check to see if unmasked bits are active */
+	if (!(status[0] & ~masks[0]) && !(status[1] & ~masks[1]) &&
+		!(status[2] & ~masks[2]) && !(status[3] & ~masks[3]))
+		return IRQ_NONE;
 
 
+	}
+
+	return IRQ_HANDLED;
+}

This seems to handle any asserted interrupt, is it clear on read?

include/sound/cs35l41.h

Quoted 5 lines
include/sound/cs35l41.h new file +5 -0
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_read(cs35l41->regmap, CS35L41_PWR_CTRL1, &val);
+		if (val & CS35L41_GLOBAL_EN_MASK) {
+			regmap_update_bits(cs35l41->regmap, CS35L41_PWR_CTRL1,
+					CS35L41_GLOBAL_EN_MASK, 0);

I can't see any references to GLOBAL_EN outside this function, why might it not be set?

include/sound/cs35l41.h

Quoted 9 lines
include/sound/cs35l41.h new file +9 -0
+static int cs35l41_set_pdata(struct cs35l41_private *cs35l41)
+{
+	struct cs35l41_classh_cfg *classh = &cs35l41->pdata.classh_config;
+	int ret;
+
+	/* Set Platform Data */
+	/* Required */
+	if (cs35l41->pdata.bst_ipk &&
+			cs35l41->pdata.bst_ind && cs35l41->pdata.bst_cap) {

The indentation here is weird, normally the second line would be indented with the (.

include/sound/cs35l41.h

Quoted 5 lines
include/sound/cs35l41.h new file +5 -0
+	if (cs35l41->pdata.dout_hiz <= CS35L41_ASP_DOUT_HIZ_MASK &&
+	    cs35l41->pdata.dout_hiz >= 0)
+		regmap_update_bits(cs35l41->regmap, CS35L41_SP_HIZ_CTRL,
+				CS35L41_ASP_DOUT_HIZ_MASK,
+				cs35l41->pdata.dout_hiz);

No error or warning on out of range?

include/sound/cs35l41.h

Quoted 9 lines
include/sound/cs35l41.h new file +9 -0
+static int cs35l41_component_probe(struct snd_soc_component *component)
+{
+	struct cs35l41_private *cs35l41 =
+		snd_soc_component_get_drvdata(component);
+
+	component->regmap = cs35l41->regmap;
+
+	return cs35l41_set_pdata(cs35l41);
+}

Why wait until here to apply the configuration, why not just do it immediately on the bus level probe? I didn't notice anything that needed the card, just the regmap.

include/sound/cs35l41.h

Quoted 3 lines
include/sound/cs35l41.h new file +3 -0
+static const struct reg_sequence cs35l41_reva0_errata_patch[] = {
+	{0x00000040,			0x00005555},
+	{0x00000040,			0x0000AAAA},

Spaces around the { }.

include/sound/cs35l41.h

Quoted 12 lines
include/sound/cs35l41.h new file +12 -0
+
+	do {
+		if (timeout == 0) {
+			dev_err(cs35l41->dev,
+				"Timeout waiting for OTP_BOOT_DONE\n");
+			ret = -EBUSY;
+			goto err;
+		}
+		usleep_range(1000, 1100);
+		regmap_read(cs35l41->regmap, CS35L41_IRQ1_STATUS4, &int_status);
+		timeout--;
+	} while (!(int_status & CS35L41_OTP_BOOT_DONE));

It would be clearer to assign timeout at the top of the loop rather than when declaring the variable so people don't have to search back and make sure it was set.

Quoted 4 lines
include/sound/cs35l41.h new file +4 -0
+	ret = devm_request_threaded_irq(cs35l41->dev, cs35l41->irq, NULL,
+			cs35l41_irq, IRQF_ONESHOT | IRQF_SHARED | irq_pol,
+			"cs35l41", cs35l41);
+

include/sound/cs35l41.h

Quoted 10 lines
include/sound/cs35l41.h new file +10 -0
+	/* CS35L41 needs INT for PDN_DONE */
+	if (ret != 0) {
+		dev_err(cs35l41->dev, "Failed to request IRQ: %d\n", ret);
+		ret = -ENODEV;
+		goto err;
+	}
+
+	/* Set interrupt masks for critical errors */
+	regmap_write(cs35l41->regmap, CS35L41_IRQ1_MASK1,
+			CS35L41_INT1_MASK_DEFAULT);

Shouldn't this be configured prior to requesting interrupts or might there be a race?

Quoted 5 lines
include/sound/cs35l41.h new file +5 -0
+	switch (reg_revid) {
+	case CS35L41_REVID_A0:
+		ret = regmap_register_patch(cs35l41->regmap,
+				cs35l41_reva0_errata_patch,
+				ARRAY_SIZE(cs35l41_reva0_errata_patch));

include/sound/cs35l41.h

Quoted 10 lines
include/sound/cs35l41.h new file +10 -0
+		if (ret < 0) {
+			dev_err(cs35l41->dev,
+				"Failed to apply A0 errata patch %d\n", ret);
+			goto err;
+		}
+		break;
+	case CS35L41_REVID_B0:
+		ret = regmap_register_patch(cs35l41->regmap,
+				cs35l41_revb0_errata_patch,
+				ARRAY_SIZE(cs35l41_revb0_errata_patch));

I'd also expect patching to be done prior to requesting interrupts so the device is in a known good state first. Perhaps it doesn't make any difference but the patches are undocumented so...

#3 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

On 7/5/21 2:20 PM, Mark Brown wrote:

Thanks for the review. I believe I can fix all of these in the next revision.

Quoted 7 lines · David Rhodes

include/sound/cs35l41.h line 66

Quoted 3 lines
include/sound/cs35l41.h new file +2 -0
+	struct regulator_bulk_data supplies[2];
+	int num_supplies;

Why might the number of supplies vary?

Good point. This is set by the size of a const array so I will replace this with a #define.

Quoted 7 lines
Quoted 5 lines
sound/soc/codecs/cs35l41.c new file +4 -0
+	/* Check to see if unmasked bits are active */
+	if (!(status[0] & ~masks[0]) && !(status[1] & ~masks[1]) &&
+		!(status[2] & ~masks[2]) && !(status[3] & ~masks[3]))
+		return IRQ_NONE;
Quoted 7 lines

sound/soc/codecs/cs35l41.c line 537

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

This seems to handle any asserted interrupt, is it clear on read?

Theoretically every unmasked interrupt source should have a handler here, so the function should have exited early if there was nothing handled.
I think it's easier to read and more explicitly enforced if I change it so that the return code is only set to IRQ_HANDLED inside the conditions where the bits are actually cleared.

Quoted 9 lines

sound/soc/codecs/cs35l41.c line 583

Quoted 5 lines
sound/soc/codecs/cs35l41.c new file +5 -0
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_read(cs35l41->regmap, CS35L41_PWR_CTRL1, &val);
+		if (val & CS35L41_GLOBAL_EN_MASK) {
+			regmap_update_bits(cs35l41->regmap, CS35L41_PWR_CTRL1,
+					CS35L41_GLOBAL_EN_MASK, 0);

I can't see any references to GLOBAL_EN outside this function, why might it not be set?

This check prevents an incorrect 'PDN Failed' message if DAPM initializes and turns the widget off at boot (with no prior power-up).

Quoted 9 lines
Quoted 9 lines
sound/soc/codecs/cs35l41.c new file +9 -0
+	ret = devm_request_threaded_irq(cs35l41->dev, cs35l41->irq, NULL,
+			cs35l41_irq, IRQF_ONESHOT | IRQF_SHARED | irq_pol,
+			"cs35l41", cs35l41);
+
+	/* CS35L41 needs INT for PDN_DONE */
+	if (ret != 0) {
+		dev_err(cs35l41->dev, "Failed to request IRQ: %d\n", ret);
+		ret = -ENODEV;
+		goto err;
Quoted 9 lines

sound/soc/codecs/cs35l41.c line 1689

Quoted 5 lines
sound/soc/codecs/cs35l41.c new file +5 -0
+	}
+
+	/* Set interrupt masks for critical errors */
+	regmap_write(cs35l41->regmap, CS35L41_IRQ1_MASK1,
+			CS35L41_INT1_MASK_DEFAULT);

Shouldn't this be configured prior to requesting interrupts or might there be a race?

Should not be any problems with unmasking before the request as long as the pin configuration is also done beforehand.

Thanks,
David

maintainer
#4 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

Quoted 11 lines · David Rhodes
Quoted 8 lines · Mark Brown

sound/soc/codecs/cs35l41.c line 583

Quoted 5 lines
sound/soc/codecs/cs35l41.c new file +5 -0
+	case SND_SOC_DAPM_POST_PMD:
+		regmap_read(cs35l41->regmap, CS35L41_PWR_CTRL1, &val);
+		if (val & CS35L41_GLOBAL_EN_MASK) {
+			regmap_update_bits(cs35l41->regmap, CS35L41_PWR_CTRL1,
+					CS35L41_GLOBAL_EN_MASK, 0);

I can't see any references to GLOBAL_EN outside this function, why might it not be set?

Quoted 2 lines

This check prevents an incorrect 'PDN Failed' message if DAPM initializes and turns the widget off at boot (with no prior power-up).

In what way does it prevent this message and why is this a good approach to the issue?

#5 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

Quoted 12 lines · Mark Brown
Quoted 7 lines · David Rhodes
Quoted 2 lines · Mark Brown

I can't see any references to GLOBAL_EN outside this function, why might it not be set?

This check prevents an incorrect 'PDN Failed' message if DAPM initializes and turns the widget off at boot (with no prior power-up).

In what way does it prevent this message and why is this a good approach to the issue?

There is a better approach that I will include in v4.
The chip has a bit field that indicates if GLOBAL_EN has been asserted. The 'PDN Failed' message can be skipped if this bit is not set.

#6 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

Quoted 10 lines · David Rhodes
Quoted 9 lines · Mark Brown
Quoted 7 lines · David Rhodes
Quoted 2 lines · Mark Brown

I can't see any references to GLOBAL_EN outside this function, why might it not be set?

This check prevents an incorrect 'PDN Failed' message if DAPM initializes and turns the widget off at boot (with no prior power-up).

Quoted 7 lines
Quoted 3 lines

In what way does it prevent this message and why is this a good approach to the issue?

There is a better approach that I will include in v4.
The chip has a bit field that indicates if GLOBAL_EN has been asserted. The 'PDN Failed' message can be skipped if this bit is not set.

I am not sure that really addresses the comment here. The issue isn't so much the way you are avoiding printing that error message, but why that is necessary in the first place. AFAIK DAPM won't attempt to power down a widget without powering it up first. So, at least to me, its not clear how you get to this code without GLOBAL_EN having first been set by the power up?

Often with comments like this what people are looking for is for you to explain more about why the code does what it does, rather than just jump to a new implementation. After the reasoning is well understood then its much easier to have a discussion about if it is the right way to solve the problem.

Thanks,
Charles

maintainer
#7 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

Quoted 2 lines · Charles Keepax

why that is necessary in the first place. AFAIK DAPM won't attempt to power down a widget without powering it up first. So, at least

If the power control register bit for the widget defaults to enabled then DAPM will see the widget as initially enabled and power it down unless it's part of a complete path, that's pretty unusual though.

#8 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

In reply to Charles Keepax
Quoted 5 lines · Charles Keepax

why that is necessary in the first place. AFAIK DAPM won't attempt to power down a widget without powering it up first. So, at least to me, its not clear how you get to this code without GLOBAL_EN having first been set by the power up?

This is a case where the bit controlling the widget defaults to enabled. Would it be better to clear that bit before registering the codec?

Thanks,
David

maintainer
#9 lore raw

Re: [PATCH v3 1/2] ASoC: cs35l41: CS35L41 Boosted Smart Amplifier

Quoted 9 lines · David Rhodes
Quoted 4 lines · Charles Keepax

why that is necessary in the first place. AFAIK DAPM won't attempt to power down a widget without powering it up first. So, at least to me, its not clear how you get to this code without GLOBAL_EN having first been set by the power up?

This is a case where the bit controlling the widget defaults to enabled. Would it be better to clear that bit before registering the codec?

That's probably a clearer and simpler option.

#10 lore raw

PATCH v3 2/2 ASoC: cs35l41: Add bindings for CS35L41

In reply to David Rhodes

Devicetree binding documentation for CS35L41 driver

CS35L41 is a 11-V Boosted Mono Class D Amplifier with DSP Speaker Protection and Equalization

---
 .../devicetree/bindings/sound/cs35l41.yaml    | 395 ++++++++++++++++++
 1 file changed, 395 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cs35l41.yaml
Documentation/devicetree/bindings/sound/cs35l41.yaml new file +395 -0
new file mode 100644
index 000000000000..538558eea9ce
@@ -0,0 +1,395 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cs35l41.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cirrus Logic CS35L41 Speaker Amplifier
+
+maintainers:
+  - [email protected]
+
+description: |
+  CS35L41 is a boosted mono Class D amplifier with DSP
+  speaker protection and equalization
+
+properties:
+  compatible:
+    enum:
+      - cirrus,cs35l40
+      - cirrus,cs35l41
+
+  reg:
+    maxItems: 1
+
+  '#sound-dai-cells':
+    description:
+      The first cell indicating the audio interface.
+    const: 1
+
+  cirrus,boost-peak-milliamp:
+    description:
+      Boost-converter peak current limit in mA.
+      Configures the peak current by monitoring the current through the boost FET.
+      Range starts at 1600 mA and goes to a maximum of 4500 mA with increments
+      of 50 mA. See section 4.3.6 of the datasheet for details.
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 1600
+    maximum: 4500
+    default: 4500
+
+  cirrus,boost-ind-nanohenry:
+    description:
+      Boost inductor value, expressed in nH. Valid
+      values include 1000, 1200, 1500 and 2200.
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 1000
+    maximum: 2200
+
+  cirrus,boost-cap-microfarad:
+    description:
+      Total equivalent boost capacitance on the VBST
+      and VAMP pins, derated at 11 volts DC. The value must be rounded to the
+      nearest integer and expressed in uF.
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+
+
+  cirrus,sclk-force-output:
+    description:
+      Audio serial port SCLK force
+      output control. Forces the SCLK to continue to drive even
+      if no ASP_TXn channels are enabled.
+    type: boolean
+
+  cirrus,lrclk-force-output:
+    description:
+      Audio serial port LRCLK force
+      output control. Forces the LRCLK to continue to drive even
+      if no ASP_TXn channels are enabled.
+    type: boolean
+
+  cirrus,right-channel-amp:
+    description:
+      Boolean to determine which channel
+      the amplifier is to receive the audio data on. If present the
+      amplifier receives data on the right channel of I2S data.
+      If not present the amplifier receives data on the left
+      channel of I2S data
+    type: boolean
+
+  cirrus,boost-ctl-millivolt:
+    description:
+      Boost Voltage Value. Configures the
+      boost converter's output voltage in mV. The range is from 2550 mV to
+      11000 mV with increments of 50 mV.  This will be the maximum voltage
+      in Class-H mode if 'classh-bst-max-limit' is set to 1, or the fixed
+      boost voltage if 'classh-bst-overide' is set to true.
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 2550
+    maximum: 11000
+
+  cirrus,amp-gain-zc:
+    description:
+      Boolean to determine whether to use the amplifier
+      gain-change zero-crossing feature. If the feature is enabled, any
+      user-controlled amplifier gain change will occur on a zero-crossing point.
+      (Default) Disabled
+    type: boolean
+
+  cirrus,asp-sdout-hiz:
+    description:
+      Audio serial port SDOUT Hi-Z control. Sets the Hi-Z
+      configuration for SDOUT pin of amplifier.
+      0 = Logic 0 during unused slots, and while all transmit channels disabled
+      1 = Hi-Z during unused slots but logic 0 while all transmit channels disabled
+      2 = (Default) Logic 0 during unused slots, but Hi-Z while all transmit channels disabled
+      3 = Hi-Z during unused slots and while all transmit channels disabled
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 3
+    default: 2
+
+  cirrus,temp-warn-threshold:
+    description:
+      Amplifier overtemperature warning threshold.
+      Configures the threshold at which the overtemperature warning condition occurs.
+      When the threshold is met, the ovetemperature warning attenuation is applied
+      and the TEMP_WARN_EINT interrupt status bit is set.
+      If TEMP_WARN_MASK = 0, INTb is asserted.
+      0 = 105C
+      1 = 115C
+      2 = 125C (Default)
+      3 = 135C
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 3
+    default: 2
+
+  cirrus,hw-noise-gate-select:
+    description: Hardware Noise Gate feature. Each bit selects
+      a different block for detection.
+      000000 - All noise gating functionality disabled
+      xxxxx1 - Amplifier noise gating detection enabled
+      xxxx1x - Boost converter DCM detection enabled
+      xxx1xx - VMON low power mode detection enabled
+      xx1xxx - IMON low power mode detection enabled
+      x1xxxx - VP brownout prevention detection enabled
+      1xxxxx - VBST brownout prevention detection enabled
+    type: boolean
+
+  cirrus,hw-noise-gate-delay:
+    description: Time that the incoming audio signal must be
+      below the noise gate threshold prior to entering a noise gated state
+      0 = 5 ms
+      1 = 10 ms
+      2 = 25 ms
+      3 = 50 ms (default)
+      4 = 100 ms
+      5 = 250 ms
+      6 = 500 ms
+      7 = 1 s
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 7
+    default: 3
+
+  cirrus,hw-noise-gate-threshold:
+    description: Threshold of audio signal input which the
+      noise gate considers the input audio to be at a low enough level to be
+      valid to enter a noise gating state of operation.
+      0 = 0.654 mVpk
+      1 = 0.328 mVpk
+      2 = 0.164 mVpk
+      3 = 0.082 mVpk (default)
+      4 = 0.041 mVpk
+      5 = 0.021 mVpk
+      6 = 0.010 mVpk
+      7 = True zero data (no LSB dither)
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 7
+    default: 3
+
+  cirrus,dsp-noise-gate-enable:
+    description:
+      DSP Noise Gate feature. If present, noise gate feature will be enabled.
+    type: boolean
+
+  cirrus,dsp-noise-gate-threshold:
+    description:
+      Threshold of audio signal input which the
+      noise gate considers the input audio to be at a low enough level to be
+      valid to enter a noise gating state of operation.
+      0 = -66 dBFS
+      1 = -72 dBFS
+      2 = -78 dBFS
+      3 = -84 dBFS (default)
+      4 = -90 dBFS
+      5 = -96 dBFS
+      6 = -102 dBFS
+      7 = -108 dBFS
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 7
+    default: 3
+
+  cirrus,dsp-noise-gate-delay:
+    description:
+      Time that the incoming audio signal must be
+      below the noise gate threshold prior to entering a noise gated state
+      0 = 5 ms
+      1 = 10 ms
+      2 = 25 ms
+      3 = 50 ms (default)
+      4 = 100 ms
+      5 = 250 ms
+      6 = 500 ms
+      7 = 1 s
+      8 = 5 s
+      9 = 10 s
+      10 = 20 s
+      11 = 30 s
+      12 = 40 s
+      13 = 50 s
+      14 = 60 s
+      15 = 120 s
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 15
+    default: 3
+
+  cirrus,invert-pcm:
+    description:
+      Inverts the polarity of the audio signal output from
+      the Class-D amplifier.
+    type: boolean
+
+  classh-internal-algo:
+    description:
+      Sub-node for the Internal Class H Algorithm
+      See Section 4.4 Internal Class H Algorithm in the Datasheet.
+      If not used, the device manages the ClassH Algorithm internally.
+      It is strongly recommended that the Datasheet be referenced when adjusting
+      or using these Class H Algorithm controls over the internal Algorithm.
+      Serious damage can occur to the Device and surrounding components.
+      Unavailable for cs35l41l.
+    type:
+      boolean
+  cirrus,classh-bst-overide:
+    description:
+      Boolean which will disable Class H tracking and
+      set Boost voltage to the value in the 'boost-ctl-millivolt' property
+    type: boolean
+  cirrus,classh-bst-max-limit:
+    description:
+      Value set to the BST_CTL_LIM_EN field.
+      A value of 1 will limit the Class-H voltage to the value in the
+      'boost-ctl-millivolt' property.
+      0 = No Class-H limit (default)
+      1 = Class-H limited to 'boost-ctl-millivolt' value
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 1
+  cirrus,classh-headroom:
+    description:
+      Class H algorithm headroom. Controls VBST headroom
+      in the max detection path of the Class H algorithm. Step size is 0.1 V.
+      Range is from -6.4V to +6.3V with 7-bit 2's complement representation.
+      0 = 0V
+      1 = 0.1V
+      2 = 0.2V
+      ===
+      11 = 1.1V (Default)
+      ===
+      62 = 6.2V
+      63 = 6.3V
+      64 = -6.4V
+      65 = -6.3V
+      ===
+      126 = -0.2V
+      127 = -0.1V
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 127
+  cirrus,classh-release-rate:
+    description:
+      Class H release rate. Controls the amount of
+      time required before allowing consecutive release condition VBST supply
+      tracking updates. Step size is 5us with range from 20us to 1275us.
+      4 = 20us (Default)
+      5 = 25us
+      ===
+      254 = 1270us
+      255 = 1275us
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 4
+    maximum: 255
+  cirrus,classh-mem-depth:
+    description:
+      Class H memory depth. Controls the memory depth
+      used in the Class H algorithm for audio data buffering and analysis.
+      0 = 20.83 - 23.4 us
+      1 = 41.67 - 46.88 us
+      2 = 83.33 - 85.94 us
+      3 = 166.67 - 171.88 us
+      4 = 250.00 - 255.10 us
+      5 = 333.33 - 335.93 us (Default)
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 5
+  cirrus,classh-wk-fet-thld:
+    description:
+      Weak-FET amplifier driver threshold.
+      Configures the signal threshold at which the PWM output stage enters weak-FET
+      operation. Step size is 0.05V. Range is from 0.05V to 0.7V.
+      1 = 0.05V
+      2 = 0.1V
+      3 = 0.15V
+      ===
+      13 = 0.65V
+      14 = 0.7V
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 1
+    maximum: 14
+  cirrus,classh-wk-fet-delay:
+    description:
+      Weak-Fet entry . Controls the delay in ms
+      before the Class H algorithm switches to the weak-FET voltage after the audio
+      falls and remains below the value specified in 'classh-wk-fet-thld'.
+      0 = 0ms
+      1 = 5ms
+      2 = 10ms
+      3 = 50ms
+      4 = 100ms (Default)
+      5 = 200ms
+      6 = 500ms
+      7 = 1000ms
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 7
+  cirrus,gpio1-polarity-invert:
+    description:
+      Boolean which specifies whether the GPIO1
+      level is inverted. If this property is not present the level is not inverted.
+    type: boolean
+  cirrus,gpio1-output-enable:
+    description:
+      Boolean which specifies whether the GPIO1 pin
+      is configured as an output. If this property is not present the
+      pin will be configured as an input.
+    type: boolean
+  cirrus,gpio1-src-select:
+    description:
+      Configures the function of the GPIO1 pin.
+      Note that the options are different from the GPIO2 pin
+      0 = High Impedance (Default)
+      1 = GPIO
+      2 = Sync
+      3 = MCLK input
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 3
+  cirrus,gpio2-polarity-invert:
+    description:
+      Boolean which specifies whether the GPIO2
+      level is inverted. If this property is not present the level is not inverted.
+    type: boolean
+  cirrus,gpio2-output-enable:
+    description:
+      Boolean which specifies whether the GPIO2 pin
+      is configured as an output. If this property is not present the
+      pin will be configured as an input.
+    type: boolean
+  cirrus,gpio2-src-select:
+    description:
+      Configures the function of the GPIO2 pin.
+      Note that the options are different from the GPIO1 pin.
+      0 = High Impedance (Default)
+      1 = GPIO
+      2 = Open Drain INTB
+      3 = MCLK input
+      4 = Push-pull INTB (active low)
+      5 = Push-pull INT (active high)
+    $ref: "/schemas/types.yaml#/definitions/uint32"
+    minimum: 0
+    maximum: 5
+
+required:
+  - compatible
+  - cirrus,boost-peak-milliamp
+  - cirrus,boost-ind-nanohenry
+  - cirrus,boost-cap-microfarad
+
+unevaluatedProperties: false
+
+examples:
+  - |
+      cs35l41: cs35l41@2 {
+        compatible = "cirrus,cs35l41";
+        reg = <2>;
+        VA-supply = <&dummy_vreg>;
+        VP-supply = <&dummy_vreg>;
+        cirrus,boost-peak-milliamp = <4500>;
+        cirrus,boost-ind-nanohenry = <1000>;
+        cirrus,boost-cap-microfarad = <15>;
+      };
\ No newline at end of file
Signature · 1 line
2.25.1
maintainer
#11 lore raw

Re: [PATCH v3 2/2] ASoC: cs35l41: Add bindings for CS35L41

Documentation/devicetree/bindings/sound/cs35l41.yaml line 138

Quoted 11 lines · David Rhodes
Documentation/devicetree/bindings/sound/cs35l41.yaml new file +11 -0
+  cirrus,hw-noise-gate-select:
+    description: Hardware Noise Gate feature. Each bit selects
+      a different block for detection.
+      000000 - All noise gating functionality disabled
+      xxxxx1 - Amplifier noise gating detection enabled
+      xxxx1x - Boost converter DCM detection enabled
+      xxx1xx - VMON low power mode detection enabled
+      xx1xxx - IMON low power mode detection enabled
+      x1xxxx - VP brownout prevention detection enabled
+      1xxxxx - VBST brownout prevention detection enabled
+    type: boolean

That description doesn't appear to be for a boolean field, either this should be a number of properties or it's not a boolean. It's also not clear to me that we shouldn't be able to control these features at runtime.

Documentation/devicetree/bindings/sound/cs35l41.yaml line 225

Quoted 5 lines
Documentation/devicetree/bindings/sound/cs35l41.yaml new file +5 -0
+  cirrus,invert-pcm:
+    description:
+      Inverts the polarity of the audio signal output from
+      the Class-D amplifier.
+    type: boolean

Given the potential confusion with the audio interface it might be better to call this invert-class-d or something.