2019-03-21 22:17:00

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 0/7] ASoC: tlv320aic26: Add device tree support and bug fixes

Hi,

The following patches were created to get the tlv320aic26 working
on our AM335x SoM.

I'm resubmitting this patch series. Previous version here:
https://lore.kernel.org/patchwork/cover/601439/

This patch series relies on the following patch for proper operation.
commit 93d0ad8f374c ("ASoC: tlv320aic26: Convert to params_width()")

Changes since RFC:
- Removed the unnecessary "#if defined(CONFIG_OF)"
- Dropped the DSP_B patch
Changes since V1:
- Reordered Kconfig patch to first so each patch can be built
- Rebased changes to Linux 5.1-rc1

Cormier, Jonathan (7):
ASoC: tlv320aic26: Allow tlv320aic26 to be selected in menuconfig
dt-bindings: ASoC: tlv320aic26: Add device tree binding
ASoC: tlv320aic26: Add device tree binding
ASoC: tlv320aic26: Fix module autoload
ASoC: tlv320aic26: Fix regmap by setting reg_defaults and reg_stride
ASoC: tlv320aic26: hw_params was unintentionally clearing AIC26 master
mode
ASoC: tlv320aic26: Change Capture Mute to Capture Switch to match alsa
documentation.

.../devicetree/bindings/sound/tlv320aic26.txt | 65 +++++++++++++++++++
sound/soc/codecs/Kconfig | 4 +-
sound/soc/codecs/tlv320aic26.c | 55 ++++++++++++++--
3 files changed, 116 insertions(+), 8 deletions(-)
create mode 100644 Documentation/devicetree/bindings/sound/tlv320aic26.txt

--
2.21.0



2019-03-21 22:16:56

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 1/7] ASoC: tlv320aic26: Allow tlv320aic26 to be selected in menuconfig

Without a description you can't select the device in menuconfig
Set depends to SPI_MASTER to match conditional in SND_SOC_ALL_CODECS

Signed-off-by: Cormier, Jonathan <[email protected]>
---
sound/soc/codecs/Kconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 419114edfd57..cd697a015819 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -1087,8 +1087,8 @@ config SND_SOC_TLV320AIC23_SPI
select SND_SOC_TLV320AIC23

config SND_SOC_TLV320AIC26
- tristate
- depends on SPI
+ tristate "Texas Instruments TLV320AIC26 audio CODEC - SPI"
+ depends on SPI_MASTER

config SND_SOC_TLV320AIC31XX
tristate "Texas Instruments TLV320AIC31xx CODECs"
--
2.21.0


2019-03-21 22:17:13

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 5/7] ASoC: tlv320aic26: Fix regmap by setting reg_defaults and reg_stride

tlv320aic26 codec wasn't being setup correctly on bootup due to
a misconfigured regmap cache.

Fixes: b7e9f3973279 "ASoC: tlv320aic26: Convert to direct regmap API usage"
Signed-off-by: Cormier, Jonathan <[email protected]>
---
sound/soc/codecs/tlv320aic26.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index db1d1704ae5c..cd1bcb9cbfe1 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -41,6 +41,27 @@ struct aic26 {
int keyclick_len;
};

+static const struct reg_default aic26_reg[] = {
+ /* Page 0 */
+ { 0x00A0, 0x0000 }, { 0x00C0, 0x0000 }, { 0x00E0, 0x0000 },
+ { 0x0120, 0x0000 }, { 0x0140, 0x0000 },
+ /* Page 1 */
+ { 0x0800, 0x0000 }, { 0x0820, 0x8000 }, { 0x0860, 0x0002 },
+ { 0x0880, 0xFFFF },
+ /* Page 2 */
+ { 0x1000, 0x0000 }, { 0x1020, 0x8000 }, { 0x1040, 0xFFFF },
+ { 0x1060, 0xC580 }, { 0x1080, 0x4410 }, { 0x10A0, 0xAFC0 },
+ { 0x10C0, 0x0000 }, { 0x10E0, 27619 }, { 0x1100, -27034 },
+ { 0x1120, 26461 }, { 0x1140, 27619 }, { 0x1160, -27034 },
+ { 0x1180, 26461 }, { 0x11A0, 32131 }, { 0x11C0, -31506 },
+ { 0x11E0, 32131 }, { 0x1200, -31506 }, { 0x1220, 27619 },
+ { 0x1240, -27034 }, { 0x1260, 26461 }, { 0x1280, 27619 },
+ { 0x12A0, -27034 }, { 0x12C0, 26461 }, { 0x12E0, 32131 },
+ { 0x1300, -31506 }, { 0x1320, 32131 }, { 0x1340, -31506 },
+ { 0x1360, 0x1004 }, { 0x1380, 0x0000 }, { 0x13A0, 0x0000 },
+ { 0x13C0, 0xFE00 },
+};
+
static const struct snd_soc_dapm_widget tlv320aic26_dapm_widgets[] = {
SND_SOC_DAPM_INPUT("MICIN"),
SND_SOC_DAPM_INPUT("AUX"),
@@ -336,6 +357,13 @@ static const struct snd_soc_component_driver aic26_soc_component_dev = {
static const struct regmap_config aic26_regmap = {
.reg_bits = 16,
.val_bits = 16,
+ /* AIC26_PAGE_ADDR(0, 0x01) */
+ .reg_stride = 0x20,
+
+ .max_register = AIC26_REG_AUDIO_CTRL5,
+ .reg_defaults = aic26_reg,
+ .num_reg_defaults = ARRAY_SIZE(aic26_reg),
+ .cache_type = REGCACHE_RBTREE,
};

/* ---------------------------------------------------------------------
--
2.21.0


2019-03-21 22:17:34

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 6/7] ASoC: tlv320aic26: hw_params was unintentionally clearing AIC26 master mode

Commit 5b0959d472c2 ("ASoC: tlv320aic26: Use snd_soc_update_bits()")
broke setting AIC26_REG_AUDIO_CTRL3 in master mode when fsref happens
to be 48000. The master mode bit was getting cleared.

Also fix setting AIC26_REG_DAC_GAIN and AIC26_REG_AUDIO_CTRL2 which
was broke by same commit.

Fixes 5b0959d472c2 ("ASoC: tlv320aic26: Use snd_soc_update_bits()")
Signed-off-by: Cormier, Jonathan <[email protected]>
---
sound/soc/codecs/tlv320aic26.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index cd1bcb9cbfe1..c6ff4ca29d43 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -138,11 +138,12 @@ static int aic26_hw_params(struct snd_pcm_substream *substream,
snd_soc_component_write(component, AIC26_REG_PLL_PROG2, reg);

/* Audio Control 3 (master mode, fsref rate) */
+ reg = 0;
if (aic26->master)
- reg = 0x0800;
+ reg |= 0x0800;
if (fsref == 48000)
- reg = 0x2000;
- snd_soc_component_update_bits(component, AIC26_REG_AUDIO_CTRL3, 0xf800, reg);
+ reg |= 0x2000;
+ snd_soc_component_update_bits(component, AIC26_REG_AUDIO_CTRL3, 0x2800, reg);

/* Audio Control 1 (FSref divisor) */
reg = wlen | aic26->datfm | (divisor << 3) | divisor;
@@ -167,7 +168,7 @@ static int aic26_mute(struct snd_soc_dai *dai, int mute)
reg = 0x8080;
else
reg = 0;
- snd_soc_component_update_bits(component, AIC26_REG_DAC_GAIN, 0x8000, reg);
+ snd_soc_component_update_bits(component, AIC26_REG_DAC_GAIN, 0x8080, reg);

return 0;
}
@@ -302,7 +303,7 @@ static ssize_t aic26_keyclick_set(struct device *dev,
struct aic26 *aic26 = dev_get_drvdata(dev);

snd_soc_component_update_bits(aic26->component, AIC26_REG_AUDIO_CTRL2,
- 0x8000, 0x800);
+ 0x8000, 0x8000);

return count;
}
--
2.21.0


2019-03-21 22:18:17

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 3/7] ASoC: tlv320aic26: Add device tree binding

Add support for the TI tlv320aic26 sound codec

Signed-off-by: Cormier, Jonathan <[email protected]>
---
sound/soc/codecs/tlv320aic26.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index b91b8d5f1ba3..5c9b320b918c 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -368,9 +368,16 @@ static int aic26_spi_probe(struct spi_device *spi)
return ret;
}

+static const struct of_device_id tlv320aic26_of_match[] = {
+ { .compatible = "ti,tlv320aic26", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, tlv320aic26_of_match);
+
static struct spi_driver aic26_spi = {
.driver = {
.name = "tlv320aic26-codec",
+ .of_match_table = of_match_ptr(tlv320aic26_of_match),
},
.probe = aic26_spi_probe,
};
--
2.21.0


2019-03-21 22:18:32

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 7/7] ASoC: tlv320aic26: Change Capture Mute to Capture Switch to match alsa documentation.

Control name needs to match Switch for alsa to use it as the channel mute

Signed-off-by: Cormier, Jonathan <[email protected]>
---
sound/soc/codecs/tlv320aic26.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index c6ff4ca29d43..3935be79b091 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -269,7 +269,7 @@ static const struct snd_kcontrol_new aic26_snd_controls[] = {
SOC_DOUBLE("PCM Playback Volume", AIC26_REG_DAC_GAIN, 8, 0, 0x7f, 1),
SOC_DOUBLE("PCM Playback Switch", AIC26_REG_DAC_GAIN, 15, 7, 1, 1),
SOC_SINGLE("PCM Capture Volume", AIC26_REG_ADC_GAIN, 8, 0x7f, 0),
- SOC_SINGLE("PCM Capture Mute", AIC26_REG_ADC_GAIN, 15, 1, 1),
+ SOC_SINGLE("PCM Capture Switch", AIC26_REG_ADC_GAIN, 15, 1, 1),
SOC_SINGLE("Keyclick activate", AIC26_REG_AUDIO_CTRL2, 15, 0x1, 0),
SOC_SINGLE("Keyclick amplitude", AIC26_REG_AUDIO_CTRL2, 12, 0x7, 0),
SOC_SINGLE("Keyclick frequency", AIC26_REG_AUDIO_CTRL2, 8, 0x7, 0),
--
2.21.0


2019-03-21 22:18:51

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 2/7] dt-bindings: ASoC: tlv320aic26: Add device tree binding

Add support for the TI tlv320aic26 sound codec

Signed-off-by: Cormier, Jonathan <[email protected]>
---
.../devicetree/bindings/sound/tlv320aic26.txt | 65 +++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 Documentation/devicetree/bindings/sound/tlv320aic26.txt

diff --git a/Documentation/devicetree/bindings/sound/tlv320aic26.txt b/Documentation/devicetree/bindings/sound/tlv320aic26.txt
new file mode 100644
index 000000000000..93aa0f76ec0d
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/tlv320aic26.txt
@@ -0,0 +1,65 @@
+Texas Instruments - tlv320aic26 Codec module
+
+The tlv320aic26 serial control bus communicates through I2C protocols
+
+Required properties:
+
+- compatible - "string" - One of:
+ "ti,tlv320aic26" - TLV320AIC26
+- reg - <int> - SPI chip select
+
+CODEC input pins:
+ * MICIN
+ * AUX
+
+CODEC output pins:
+ * HPL
+ * HPR
+
+The pins can be used in referring sound node's audio-routing property.
+
+Example:
+
+tlv320aic26: tlv320aic26@0 {
+ compatible = "ti,tlv320aic26";
+ reg = <0>;
+};
+
+&spi0 {
+ pinctrl-names = "default", "sleep";
+ pinctrl-0 = <&spi0_pins>;
+ pinctrl-1 = <&spi0_sleep_pins>;
+
+ status = "okay";
+ ti,pindir-d0-out-d1-in = <1>;
+
+ tlv320aic26: tlv320aic26@1 {
+ compatible = "ti,tlv320aic26";
+ reg = <0x1>;
+ status = "okay";
+
+ spi-max-frequency = <2000000>;
+ spi-cpha;
+ };
+};
+
+sound {
+ compatible = "simple-audio-card";
+ simple-audio-card,name = "AM335x_SND";
+ simple-audio-card,format = "dsp_b";
+ /* SND_SOC_DAIFMT_CBM_CFM */
+ simple-audio-card,bitclock-master = <&tlv320aic26_codec>;
+ simple-audio-card,frame-master = <&tlv320aic26_codec>;
+ /* SND_SOC_DAIFMT_IB_NF */
+ simple-audio-card,bitclock-inversion;
+
+ simple-audio-card,cpu {
+ sound-dai = <&mcasp1>;
+ system-clock-frequency = <24576000>;
+ };
+
+ tlv320aic26_codec: simple-audio-card,codec {
+ sound-dai = <&tlv320aic26>;
+ system-clock-frequency = <24576000>;
+ };
+};
--
2.21.0


2019-03-21 22:19:49

by Jonathan Cormier

[permalink] [raw]
Subject: [PATCH v2 4/7] ASoC: tlv320aic26: Fix module autoload

Add the missing MODULE_DEVICE_TABLE() for OF and SPI to export
the information so modules have the correct aliases built-in and
autoloading works correctly.

A longer explanation by Javier Canillas can be found here:
https://lkml.org/lkml/2015/7/30/519
https://lkml.org/lkml/2014/9/11/458

Signed-off-by: Cormier, Jonathan <[email protected]>
---
sound/soc/codecs/tlv320aic26.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 5c9b320b918c..db1d1704ae5c 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -368,6 +368,12 @@ static int aic26_spi_probe(struct spi_device *spi)
return ret;
}

+static const struct spi_device_id tlv320aic26_id_table[] = {
+ { "tlv320aic26" },
+ {},
+};
+MODULE_DEVICE_TABLE(spi, tlv320aic26_id_table);
+
static const struct of_device_id tlv320aic26_of_match[] = {
{ .compatible = "ti,tlv320aic26", },
{},
@@ -380,6 +386,7 @@ static struct spi_driver aic26_spi = {
.of_match_table = of_match_ptr(tlv320aic26_of_match),
},
.probe = aic26_spi_probe,
+ .id_table = tlv320aic26_id_table,
};

module_spi_driver(aic26_spi);
--
2.21.0


2019-03-31 06:42:59

by Rob Herring (Arm)

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] dt-bindings: ASoC: tlv320aic26: Add device tree binding

On Thu, Mar 21, 2019 at 06:15:44PM -0400, Cormier, Jonathan wrote:
> Add support for the TI tlv320aic26 sound codec
>
> Signed-off-by: Cormier, Jonathan <[email protected]>
> ---
> .../devicetree/bindings/sound/tlv320aic26.txt | 65 +++++++++++++++++++
> 1 file changed, 65 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/sound/tlv320aic26.txt
>
> diff --git a/Documentation/devicetree/bindings/sound/tlv320aic26.txt b/Documentation/devicetree/bindings/sound/tlv320aic26.txt
> new file mode 100644
> index 000000000000..93aa0f76ec0d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/sound/tlv320aic26.txt
> @@ -0,0 +1,65 @@
> +Texas Instruments - tlv320aic26 Codec module
> +
> +The tlv320aic26 serial control bus communicates through I2C protocols
> +
> +Required properties:
> +
> +- compatible - "string" - One of:
> + "ti,tlv320aic26" - TLV320AIC26
> +- reg - <int> - SPI chip select
> +
> +CODEC input pins:
> + * MICIN
> + * AUX
> +
> +CODEC output pins:
> + * HPL
> + * HPR
> +
> +The pins can be used in referring sound node's audio-routing property.
> +
> +Example:
> +
> +tlv320aic26: tlv320aic26@0 {

audio-codec@0

> + compatible = "ti,tlv320aic26";
> + reg = <0>;
> +};
> +
> +&spi0 {
> + pinctrl-names = "default", "sleep";
> + pinctrl-0 = <&spi0_pins>;
> + pinctrl-1 = <&spi0_sleep_pins>;
> +
> + status = "okay";

Don't show status in examples.

> + ti,pindir-d0-out-d1-in = <1>;
> +
> + tlv320aic26: tlv320aic26@1 {

This split is convention, but outside the scope of binding docs, so
please just show the complete node.

> + compatible = "ti,tlv320aic26";
> + reg = <0x1>;
> + status = "okay";
> +
> + spi-max-frequency = <2000000>;
> + spi-cpha;
> + };
> +};
> +
> +sound {
> + compatible = "simple-audio-card";
> + simple-audio-card,name = "AM335x_SND";
> + simple-audio-card,format = "dsp_b";
> + /* SND_SOC_DAIFMT_CBM_CFM */
> + simple-audio-card,bitclock-master = <&tlv320aic26_codec>;
> + simple-audio-card,frame-master = <&tlv320aic26_codec>;
> + /* SND_SOC_DAIFMT_IB_NF */
> + simple-audio-card,bitclock-inversion;
> +
> + simple-audio-card,cpu {
> + sound-dai = <&mcasp1>;
> + system-clock-frequency = <24576000>;
> + };
> +
> + tlv320aic26_codec: simple-audio-card,codec {
> + sound-dai = <&tlv320aic26>;
> + system-clock-frequency = <24576000>;
> + };
> +};
> --
> 2.21.0
>