Skip to contentSkip to conversation

ASoC: codecs: add Texas Instruments TAS2557 smart amplifier driver

PATCH In review Gianluca Boiano 3 participants 5 messages Nov 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v4 cover ASoC: codecs: add Texas Instruments TAS2557 smart amplifier driver

The TAS2557 is a mono Class-D smart amplifier with an on-chip DSP for speaker protection, controlled over I2C, with audio over I2S/TDM. The DSP needs a firmware image tuned for the speaker; without it the chip passes no audio.

Patch 1 adds the binding, patch 2 the driver. One node describes one chip or a stereo pair on one bus, using the reg-array convention of ti,tas2781.yaml: reg index 0 is DEV_A, index 1 is DEV_B.

v4 uses tas2781-comlib for register access, adds the firmware rate constraint asked for in the v2 review, and addresses the v3 review from Mark Brown, Krzysztof Kozlowski and Markus Elfring. The ti,imon-slot-nos/ti,vmon-slot-nos properties are gone: the register they were written to only holds the I-sense scale. I/V sense now stays on while the amplifier plays, as in TI's driver. Details are in the per-patch changelogs.

Testing: built against broonie/sound for-next with W=1, checkpatch --strict and dt_binding_check clean. The v4 driver was run in mono on a Xiaomi Redmi Note 6 Pro (SDM636, ASI2) on a 7.2-based kernel:
firmware load, playback, stream restarts without a program reload and unbind/bind. Stereo pairs, TDM, DSP_A, ASI1 and suspend were not tested with v4.

Link to v3: https://lore.kernel.org/linux-sound/[email protected]/
Link to v2: https://lore.kernel.org/linux-sound/[email protected]/
Link to v1: https://lore.kernel.org/linux-sound/[email protected]/

Gianluca Boiano (2):
ASoC: dt-bindings: add Texas Instruments TAS2557
ASoC: codecs: add TAS2557 mono smart amplifier driver

 .../devicetree/bindings/sound/ti,tas2557.yaml |  158 +
 MAINTAINERS                                   |    1 +
 sound/soc/codecs/Kconfig                      |   13 +
 sound/soc/codecs/Makefile                     |    2 +
 sound/soc/codecs/tas2557.c                    | 2973 +++++++++++++++++
 sound/soc/codecs/tas2557.h                    |  207 ++
 6 files changed, 3354 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ti,tas2557.yaml
 create mode 100644 sound/soc/codecs/tas2557.c
 create mode 100644 sound/soc/codecs/tas2557.h

base-commit: cee03387d20bb267663085d9ac2622ff9263d302

Signature · 1 line
2.56.1
#1 lore raw

PATCH v4 1/2 ASoC: dt-bindings: add Texas Instruments TAS2557

Document the TAS2557 mono Class-D smart amplifier with an integrated DSP for speaker protection. The device is controlled over I2C and receives audio over I2S/TDM (ASI).

One node describes either a single device or, with a two-entry reg, a stereo pair sharing one bus. The device at each reg index applies one half of a stereo-tuned firmware image: index 0 is DEV_A and index 1 is DEV_B. No channel selection property is needed, as for ti,tas2781.yaml. reg is limited to two entries because the firmware format only defines mono or DEV_A/DEV_B devices.

reset-gpios and interrupts are per device: the item at array index N configures the device at the Nth reg entry, and a single entry is shared by every device in the group. A pair wired to independent RESET and INT pins uses two entries each.

ti,asi-port selects which of the two audio serial interfaces, ASI1 or ASI2, is wired to the host.

The DSP boots from a firmware image generated per speaker design with the TI PurePath Console tuning tools. The optional firmware-name property selects a board specific image shared by the whole group. The default names are the mono images, so a pair must set it.

---

Notes:
Changes in v4:
- use the ASoC subject prefix (Mark Brown)
- reset-gpios and interrupts take one entry per reg index, a single entry is shared by the group (boards with independent RESET/INT lines per chip)
- add ti,asi-port to name the wired ASI (Mark Brown)
- drop ti,imon-slot-nos and ti,vmon-slot-nos: the chip has no slot field for I/V sense, SNS_CTRL only holds the I-sense scale, which the firmware programs
- require firmware-name for two chips, the default names are mono images
- move the review history out of the commit message (Krzysztof Kozlowski); Reviewed-by not carried over because of the property changes

Changes in v3:
- single-node reg-array model (up to two devices), matching ti,tas2781.yaml; drop ti,channel, derive DEV_A/DEV_B from reg order
- rename ti,imon-slot-no/ti,vmon-slot-no to the plural ti,imon-slot-nos/ti,vmon-slot-nos arrays; firmware-name maxItems: 1

Changes in v2:
- add the four mandatory supplies to "required" (Wang Sen)

 .../devicetree/bindings/sound/ti,tas2557.yaml | 158 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 159 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/ti,tas2557.yaml
Documentation/devicetree/bindings/sound/ti,tas2557.yaml new file +158 -0
new file mode 100644
index 000000000..4a7f90659
@@ -0,0 +1,158 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright (C) 2026 Gianluca Boiano <[email protected]>
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/ti,tas2557.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments TAS2557 Mono Smart Amplifier
+
+maintainers:
+  - Gianluca Boiano <[email protected]>
+
+description: |
+  The TAS2557 is a mono, digital-input Class-D amplifier with an
+  integrated DSP for speaker protection, controlled over I2C, with
+  audio over I2S/TDM (ASI). The DSP runs a firmware image generated for
+  the speaker with the TI PurePath Console tuning tools.
+
+  One node describes one device or a pair sharing one ASI bus, using
+  the reg-array convention of ti,tas2781.yaml. The device at reg index 0
+  is DEV_A and the one at index 1 is DEV_B; they select the two halves
+  of a stereo-tuned firmware image. The firmware format defines no
+  other device types, so a node has at most two devices.
+
+  Datasheet: https://www.ti.com/lit/gpn/tas2557
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: ti,tas2557
+
+  reg:
+    minItems: 1
+    maxItems: 2
+    description:
+      I2C address of each physical device sharing this node. One
+      entry configures a single mono TAS2557. Two entries configure a
+      device pair; the device at index 0 is DEV_A and the device at
+      index 1 is DEV_B.
+
+  '#sound-dai-cells':
+    const: 0
+
+  reset-gpios:
+    minItems: 1
+    maxItems: 2
+    description:
+      GPIO connected to the active-low RESET pin of each physical
+      device sharing this node, one entry per reg entry. A single
+      entry is shared by every device in the group.
+
+  interrupts:
+    minItems: 1
+    maxItems: 2
+    description:
+      Fault interrupt output (INT) of each physical device sharing
+      this node, one entry per reg entry. A single entry is shared
+      by every device in the group.
+
+  vbat-supply:
+    description: Battery/boost input supply (VBAT), 2.9 V to 5.5 V.
+
+  iovdd-supply:
+    description: Digital I/O supply, 1.62 V to 3.6 V.
+
+  avdd-supply:
+    description: Analog supply, 1.65 V to 1.95 V.
+
+  dvdd-supply:
+    description: Digital core supply, 1.65 V to 1.95 V.
+
+  firmware-name:
+    maxItems: 1
+    description:
+      Name of the DSP firmware image to load. Defaults to a name
+      derived from the silicon revision, which is the mono image, so a
+      device pair must set this property. A device pair shares one
+      image; each device's half of it is selected by its reg index,
+      not by this property.
+
+  ti,asi-port:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    enum: [1, 2]
+    default: 2
+    description:
+      Which audio serial interface (ASI1 or ASI2) of the chip is
+      wired to the host. Only the selected interface is configured.
+
+required:
+  - compatible
+  - reg
+  - '#sound-dai-cells'
+  - vbat-supply
+  - iovdd-supply
+  - avdd-supply
+  - dvdd-supply
+
+if:
+  properties:
+    reg:
+      minItems: 2
+then:
+  required:
+    - firmware-name
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        audio-codec@4c {
+            compatible = "ti,tas2557";
+            reg = <0x4c>;
+            #sound-dai-cells = <0>;
+            reset-gpios = <&tlmm 77 GPIO_ACTIVE_LOW>;
+            interrupt-parent = <&tlmm>;
+            interrupts = <73 IRQ_TYPE_LEVEL_HIGH>;
+
+            vbat-supply = <&vph_pwr>;
+            iovdd-supply = <&vreg_l6b_1p8>;
+            avdd-supply = <&vreg_l6b_1p8>;
+            dvdd-supply = <&vreg_l6b_1p8>;
+        };
+    };
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        audio-codec@4c {
+            compatible = "ti,tas2557";
+            reg = <0x4c>, <0x4e>;
+            #sound-dai-cells = <0>;
+            reset-gpios = <&tlmm 77 GPIO_ACTIVE_LOW>,
+                          <&tlmm 78 GPIO_ACTIVE_LOW>;
+            interrupt-parent = <&tlmm>;
+            interrupts = <73 IRQ_TYPE_LEVEL_HIGH>, <74 IRQ_TYPE_LEVEL_HIGH>;
+
+            vbat-supply = <&vph_pwr>;
+            iovdd-supply = <&vreg_l6b_1p8>;
+            avdd-supply = <&vreg_l6b_1p8>;
+            dvdd-supply = <&vreg_l6b_1p8>;
+
+            firmware-name = "tas2557-stereo.bin";
+        };
+    };
+...
MAINTAINERS +1 -0
index d37ed235d..8e024bcfb 100644
@@ -27724,6 +27724,7 @@ M:	Sen Wang <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/sound/ti,tas2552.yaml
+F:	Documentation/devicetree/bindings/sound/ti,tas2557.yaml
 F:	Documentation/devicetree/bindings/sound/ti,tas2562.yaml
 F:	Documentation/devicetree/bindings/sound/ti,tas2770.yaml
 F:	Documentation/devicetree/bindings/sound/ti,tas27xx.yaml
Signature · 1 line
2.56.1
#2 lore raw

PATCH v4 2/2 ASoC: codecs: add TAS2557 mono smart amplifier driver

In reply to Gianluca Boiano

Add a driver for the Texas Instruments TAS2557 mono Class-D smart amplifier with an integrated DSP. One DT node drives a group of up to two chips that share one firmware image, DAI and mute/power state, like the grouped tas2781 devices.

Register access, the paged regmap and the i2c_client address swap used to reach each chip come from tas2781-comlib and tas2781-comlib-i2c. The driver keeps what comlib has no field for: firmware parsing and loading, DSP program and config bookkeeping, ASI slot offsets and the per chip reset and IRQ lines. Secondary I2C addresses are reserved with dummy clients. The firmware file header is the one tas2781-fmwlib parses, but the PLL and config records are not handled there, so the file is parsed in this driver. The header device field uses the TASDEVICE_DSP_TAS_2557_* values.

reset-gpios and interrupts take one or two entries, a single entry applying to every chip. All configured reset lines are toggled together and every IRQ line shares one threaded handler that recovers the whole group. An interrupt that is not available yet defers the probe.

ti,asi-port (1 or 2, default 2) selects the wired ASI. Only its pin mux, clock dividers and format and offset registers are programmed, and DAPM has a single ASI widget. The ASI1 table also sets GPIO3 to ASI1_DOUT. In a stereo group only chip 0 drives DOUT, the others have the pin disabled. INT1 can be routed to any GPIO; the driver uses GPIO4, the reset default and the ball labelled IRQ.

The chip's DSP format at OFFSET1 = 0 is DSP_B, so DSP_A adds one BCLK to OFFSET1. With set_tdm_slot(), an rx_mask with at least two slots and at least as many as chips gives chip n the n-th slot; otherwise all chips use the first slot. Without TDM the offset is 0, plus one BCLK for DSP_A. Only the I2S, DSP and justified formats with the chip as clock consumer and no clock inversion are accepted.

The default firmware names are the mono images, so a pair requires firmware-name.

The firmware's mono/stereo device type is checked against the number of configured chips before the image is installed; on a mismatch the image is dropped. The PLL index of each config is checked when the image is parsed and an out of range index rejects the image.

Firmware configs have fixed sample rates. The DAI startup callback waits for the firmware load, bounded, and restricts the stream to the rates of the current program's configs. hw_params rejects a rate without a config before changing any state.

The firmware program, PLL and config are loaded when the firmware arrives and again only after a reset, fault recovery or resume, or when the sample rate needs another config, instead of on every DAPM power-up. Power-up then only runs the startup sequence and restores the cached runtime and mute state. The shutdown sequence mutes and powers down the blocks; it does not reset the chips or make program, coefficient or PLL writes. A rate or word length change
while powered is applied immediately. As in the TI driver, I and V sense are powered at startup and muted and unmuted together with the amplifier, since the DSP needs the feedback while it plays; the capture stream is not muted separately.

Fault recovery resets the chips once and reuses the common mute restore code. The comlib lock is destroyed by a devm action registered after tasdevice_init(), so it outlives the component, the IRQs and the firmware teardown. SND_SOC_TAS2781_COMLIB is selected together with the I2C helper, which does not pull it in.

---

Notes:
Changes in v4:
- use tas2781-comlib(-i2c) for the paged regmap, book/page switching and per-chip access instead of a private copy (Mark Brown)
- check the firmware's mono/stereo device type, using the TASDEVICE_DSP_TAS_2557_* values, against the chip count before installing the image (Mark Brown)
- reject an image with an out-of-range config PLL index (Mark Brown)
- constrain the stream to the firmware config rates in DAI startup and reject other rates in hw_params() (Mark Brown, v2)
- apply rate/word-length changes from hw_params() while powered, keeping use_pmdown_time (Mark Brown)
- program only the ASI selected by ti,asi-port; one ASI widget (Mark Brown)
- one reset GPIO and fault IRQ per chip; defer the probe on -EPROBE_DEFER from the interrupt
- load program/PLL/config only after a reset, recovery, resume or a rate needing another config, not on every power-up
- I/V sense stays powered and is muted together with the amplifier, as in TI's driver; remove the ISENSE/VSENSE switches, the SNS_CTRL slot writes and the separate capture mute (answers Mark Brown's sense_muted over suspend question)
- DSP_A adds one BCLK to OFFSET1; per-chip rx slots from set_tdm_slot(); OFFSET2 and the undocumented ADC format registers are no longer written
- accept only clock consumer, non-inverted DAI formats
- GPIO3 is ASI1_DOUT; only chip 0 drives DOUT in a stereo group
- INT1 stays on GPIO4, the reset default and the IRQ ball (Mark Brown asked if it is the only option; it is not)
- fix the volume TLV: DAC_GAIN is 0 to 15 dB in 1 dB steps
- destroy the comlib lock in a devm action so it outlives the component, IRQs and firmware teardown
- return the error from suspend
- guard(mutex) where the lock covers the whole function (Markus Elfring)

Changes in v3:
- rework to a single-node, reg-array driver managing up to two devices (per-device book/page/program/config state, group DAI/IRQ)
- derive the ASI word length from params_width() and re-apply it after each reset instead of hardcoding 32-bit
- set symmetric_rate on the DAI (Mark Brown), and symmetric_sample_bits (playback and capture share the single ASI word length)
- commit the DAC-gain cache only after the hardware write succeeds (Mark Brown), and apply the same ordering to the ISENSE/VSENSE mixer setters
- default the ASI data-slot offset to 0; explicit snd_soc_dai_set_tdm_slot() still takes precedence

Changes in v2:
- propagate hw_params() register-write failures (Wang Sen)
- return IRQ_NONE when the device was not in a state to raise the fault IRQ, for correct shared-IRQ accounting (Mark Brown)
- re-apply cached runtime state after every reset, including fault recovery (Mark Brown)
- honour explicit snd_soc_dai_set_tdm_slot(); restore TX slot offsets after reset
- wait for the async firmware load on first stream start
- make mute_stream direction-aware

 sound/soc/codecs/Kconfig   |   13 +
 sound/soc/codecs/Makefile  |    2 +
 sound/soc/codecs/tas2557.c | 2973 ++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/tas2557.h |  207 +++
 4 files changed, 3195 insertions(+)
 create mode 100644 sound/soc/codecs/tas2557.c
 create mode 100644 sound/soc/codecs/tas2557.h
sound/soc/codecs/Kconfig +13 -0
index 513c8dbcf..9a4e3290f 100644
@@ -274,6 +274,7 @@ config SND_SOC_ALL_CODECS
 	imply SND_SOC_STI_SAS
 	imply SND_SOC_TAC5XX2_SDW
 	imply SND_SOC_TAS2552
+	imply SND_SOC_TAS2557
 	imply SND_SOC_TAS2562
 	imply SND_SOC_TAS2764
 	imply SND_SOC_TAS2770
@@ -2236,6 +2237,18 @@ config SND_SOC_TAS2552
 	tristate "Texas Instruments TAS2552 Mono Audio amplifier"
 	depends on I2C
 
+config SND_SOC_TAS2557
+	tristate "Texas Instruments TAS2557 Mono Smart Amplifier"
+	depends on I2C
+	select SND_SOC_TAS2781_COMLIB
+	select SND_SOC_TAS2781_COMLIB_I2C
+	help
+	  Enable support for the Texas Instruments TAS2557 mono smart
+	  amplifier with integrated DSP. The on-chip DSP requires firmware
+	  (tas2557_uCDSP.bin) to be present in the firmware search path;
+	  audio cannot pass through the device without it. Uses the
+	  tas2781-comlib(-i2c) helpers for paged register access.
+
 config SND_SOC_TAS2562
 	tristate "Texas Instruments TAS2562 Mono Audio amplifier"
 	depends on I2C
sound/soc/codecs/Makefile +2 -0
index fde073828..5660028c6 100644
@@ -443,6 +443,7 @@ snd-soc-max98504-y := max98504.o
 snd-soc-simple-amplifier-y := simple-amplifier.o
 snd-soc-tpa6130a2-y := tpa6130a2.o
 snd-soc-tas2552-y := tas2552.o
+snd-soc-tas2557-y := tas2557.o
 snd-soc-tas2562-y := tas2562.o
 snd-soc-tas2764-y := tas2764.o
 snd-soc-tas2780-y := tas2780.o
@@ -771,6 +772,7 @@ obj-$(CONFIG_SND_SOC_STAC9766)	+= snd-soc-stac9766.o
 obj-$(CONFIG_SND_SOC_STI_SAS)	+= snd-soc-sti-sas.o
 obj-$(CONFIG_SND_SOC_TAC5XX2_SDW)	+= snd-soc-tac5xx2-sdw.o
 obj-$(CONFIG_SND_SOC_TAS2552)	+= snd-soc-tas2552.o
+obj-$(CONFIG_SND_SOC_TAS2557)	+= snd-soc-tas2557.o
 obj-$(CONFIG_SND_SOC_TAS2562)	+= snd-soc-tas2562.o
 obj-$(CONFIG_SND_SOC_TAS2764)	+= snd-soc-tas2764.o
 obj-$(CONFIG_SND_SOC_TAS2780)	+= snd-soc-tas2780.o
sound/soc/codecs/tas2557.c new file +2973 -0

2,961 lines not on this page · raw message

sound/soc/codecs/tas2557.h new file +207 -0

207 lines not on this page · raw message

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

Signature · 1 line
2.56.1

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

#3 lore raw

Re: [PATCH v4 2/2] ASoC: codecs: add TAS2557 mono smart amplifier driver

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] ASoC: tas2557: tas2557_power_up_locked() clobbers unmuted state on reload - [Medium] ASoC…

Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] ASoC: tas2557: tas2557_power_up_locked() clobbers unmuted state on reload
- [Medium] ASoC: tas2557: tas2557_startup_sequence() powers PLL and clk-err before ASI
- [Low] ASoC: tas2557: missing offset check for bulk write in tas2557_load_block()
- [Low] ASoC: tas2557: tas2557_parse_dt() fails probe with -ENOSYS when !CONFIG_OF
--

commit b6c7726849d63f604c14fd11d9de768bf9364c52
Author: Gianluca Boiano <[email protected]>

ASoC: codecs: add TAS2557 mono smart amplifier driver

This commit adds an ASoC codec driver for the Texas Instruments TAS2557 mono Class-D smart amplifier, supporting single and dual-chip groups, DSP firmware loading, and fault recovery.

Quoted 5 lines
sound/soc/codecs/tas2557.c new file +0 -0
new file mode 100644
index 0000000000000..c49917149c863

[ ... ]

Quoted 12 lines
sound/soc/codecs/tas2557.c new file +12 -0
+static const unsigned int tas2557_startup_common_data[] = {
+	TAS2557_GPI_PIN_REG,      0x15,	/* enable DIN, MCLK, CCI */
+	/* Power sequencing: Class-D + Boost first, then DSP/PLL */
+	TAS2557_POWER_CTRL2_REG, 0xA0,		/* Class-D, Boost power up */
+	TAS2557_POWER_CTRL2_REG, 0xA3,		/* Class-D, Boost, IV-sense power up */
+	TAS2557_POWER_CTRL1_REG, 0xF8,		/* PLL, DSP, clock dividers power up */
+	TAS2557_UDELAY, 2000,			/* 2 ms stabilisation */
+	/* CE1_IC = ASI1; TI's ASI2 build writes the same value */
+	TAS2557_CLK_ERR_CTRL, 0x2b,		/* enable clock error detection */
+	TAS2557_DBOOST_CFG_REG, 0x0b,		/* reduce full-band noise */
+	0xFFFFFFFF, 0xFFFFFFFF
+};

[ ... ]

Quoted 17 lines
sound/soc/codecs/tas2557.c new file +17 -0
+static int tas2557_startup_sequence(struct tas2557_priv *tas2557)
+{
+	const unsigned int *asi = tas2557->asi_port == TAS2557_ASI_PORT1 ?
+				  tas2557_startup_asi1_data :
+				  tas2557_startup_asi2_data;
+	unsigned int dout_reg = tas2557_asi_reg(tas2557, TAS2557_GPIO3_PIN_REG,
+						TAS2557_GPIO7_PIN_REG);
+	unsigned int chn;
+	int ret;
+
+	ret = tas2557_load_data_all(tas2557, tas2557_startup_common_data);
+	if (ret < 0)
+		return ret;
+
+	ret = tas2557_load_data_all(tas2557, asi);
+	if (ret < 0)
+		return ret;

sound/soc/codecs/tas2557.c line 505

Quoted 10 lines
sound/soc/codecs/tas2557.c new file +10 -0
+
+	/* Only chip 0 drives DOUT of the shared ASI */
+	for (chn = 1; chn < tas2557->tas_priv->ndev; chn++) {
+		ret = tas2557_dev_write(tas2557, chn, dout_reg, 0x00);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}

[Severity: Medium]
Does tas2557_startup_sequence() power up the PLL and arm clock-error detection before the ASI clock pins and dividers are enabled?

tas2557_startup_common_data powers up the PLL/DSP, waits 2 ms, and writes 0x2b to TAS2557_CLK_ERR_CTRL while the ASI BCLK/WCLK GPIO muxes and ASI2 dividers in the asi table are still disabled. In a two-chip group, chip 0 sits with clock-error detection armed and its clock inputs disabled for over 2 ms while chip 1 runs tas2557_startup_common_data, exceeding the 0.34 ms hysteresis in TAS2557_CLK_ERR_CTRL2 and tripping a clock fault before chip 0's ASI pins are configured. Writing TAS2557_CLK_ERR_CTRL in tas2557_startup_common_data also arms detection when dac_muted is true and the host has not started the I2S clocks, until tas2557_apply_mute_state() clears it later. In addition, tas2557_load_data_all(tas2557, asi) enables DOUT on every chip before the loop zeroes dout_reg on chn >= 1, briefly driving the shared DOUT line from both chips at once.

[ ... ]

Quoted 43 lines
sound/soc/codecs/tas2557.c new file +43 -0
+static int tas2557_load_block(struct tas2557_priv *tas2557,
+			      struct tas2557_block *block, unsigned int chn)
+{
+	const u8 *data = block->data;
+	unsigned int i;
+	u8 book, page, offset, value;
+	u16 sleep_time, bulk_len;
+	int ret;
+
+	dev_dbg(tas2557->tas_priv->dev, "chn %u: load block type=0x%x cmds=%u\n",
+		chn, block->type, block->num_commands);
+
+	for (i = 0; i < block->num_commands; ) {
+		book   = data[i * 4];
+		page   = data[i * 4 + 1];
+		offset = data[i * 4 + 2];
+		value  = data[i * 4 + 3];
+		i++;
+
+		if (offset <= 0x7f) {
+			ret = tas2557_dev_write(tas2557, chn,
+						TAS2557_REG(book, page, offset),
+						value);
+			if (ret < 0)
+				return ret;
+		} else if (offset == 0x81) {
+			sleep_time = ((u16)book << 8) | page;
+			msleep(sleep_time);
+		} else if (offset == 0x85) {
+			bulk_len = ((u16)book << 8) | page;
+
+			if (bulk_len == 0)
+				return -EINVAL;
+
+			if (i >= block->num_commands)
+				return -EINVAL;
+			/* Verify bulk payload stays within block->data */
+			if ((size_t)i * 4 + 3 + bulk_len >
+			    (size_t)block->num_commands * 4)
+				return -EINVAL;
+
+			book   = data[i * 4];
+			page   = data[i * 4 + 1];

sound/soc/codecs/tas2557.c line 1057

Quoted 10 lines
sound/soc/codecs/tas2557.c new file +10 -0
+			offset = data[i * 4 + 2];
+
+			if (bulk_len > 1)
+				ret = tas2557_dev_bulk_write(tas2557, chn,
+							     TAS2557_REG(book, page, offset),
+							     &data[i * 4 + 3], bulk_len);
+			else
+				ret = tas2557_dev_write(tas2557, chn,
+							TAS2557_REG(book, page, offset),
+							data[i * 4 + 3]);

[Severity: Low]
Can a bulk write command (0x85) with offset > 0x7f overflow into the next page in TAS2557_REG(book, page, offset)?

Unlike the single-write branch, the 0x85 branch does not check that the target register offset is <= 0x7f. Because TASDEVICE_REG() computes (book * 256 * 128) + (page * 128) + reg and TASDEVICE_PAGE_REG() reduces reg modulo 128, an offset >= 0x80 increments the encoded page (or book) and wraps TASDEVICE_PAGE_REG(reg) to offset - 128, bypassing the TASDEVICE_PAGE_REG(reg) + len > 128 check in tas2557_dev_bulk_write().

[ ... ]

Quoted 34 lines
sound/soc/codecs/tas2557.c new file +34 -0
+static int tas2557_power_up_locked(struct tas2557_priv *tas2557,
+				   unsigned int prog_idx)
+{
+	int cfg_idx, ret;
+
+	lockdep_assert_held(&tas2557->tas_priv->codec_lock);
+
+	cfg_idx = tas2557_find_config(tas2557->fw, prog_idx, tas2557->sample_rate);
+	if (cfg_idx < 0) {
+		dev_err(tas2557->tas_priv->dev, "no config for program %u at %u Hz\n",
+			prog_idx, tas2557->sample_rate);
+		return cfg_idx;
+	}
+
+	if (tas2557->powered || !tas2557->prog_valid ||
+	    tas2557->devs[0].current_program != prog_idx ||
+	    tas2557->devs[0].current_config != cfg_idx) {
+		if (tas2557->powered) {
+			ret = tas2557_shutdown_sequence(tas2557);
+			if (ret < 0)
+				return ret;
+			/* Callers set powered again on success */
+			tas2557->powered = false;
+			tas2557->dac_muted = true;
+		}
+
+		ret = tas2557_set_program(tas2557, prog_idx, cfg_idx);
+		if (ret < 0) {
+			dev_err(tas2557->tas_priv->dev,
+				"firmware program load failed on power-up: %d\n",
+				ret);
+			return ret;
+		}
+	}

[ ... ]

sound/soc/codecs/tas2557.c line 1979

Quoted 3 lines
sound/soc/codecs/tas2557.c new file +3 -0
+	ret = tas2557_apply_mute_state(tas2557);
+	if (ret < 0)
+		goto err_shutdown;

[Severity: Medium]
Does setting tas2557->dac_muted = true when shutting down an already-powered group prevent tas2557_apply_mute_state() from restoring an unmuted state?

When tas2557_hw_params() calls tas2557_power_up_locked() for a live rate_changed reload while the amplifier is powered and unmuted, tas2557->dac_muted is overwritten with true before tas2557_set_program() runs. tas2557_apply_mute_state() then sees dac_muted == true (and tas2557_hw_params() skips remute when rate_changed is true), leaving the amplifier muted and clock-error detection disabled.

[ ... ]

Quoted 2 lines
sound/soc/codecs/tas2557.c new file +2 -0
+static int tas2557_parse_dt(struct tas2557_priv *tas2557, struct i2c_client *client)
+{

[ ... ]

sound/soc/codecs/tas2557.c line 2802

Quoted 5 lines
sound/soc/codecs/tas2557.c new file +5 -0
+	/* Which ASI's pins/dividers/format registers to program */
+	tas2557->asi_port = TAS2557_ASI_PORT_DEFAULT;
+	ret = of_property_read_u32(np, "ti,asi-port", &tas2557->asi_port);
+	if (ret && ret != -EINVAL)
+		return dev_err_probe(dev, ret, "failed to read ti,asi-port\n");

[Severity: Low]
Does of_property_read_u32() fail probe with -ENOSYS when CONFIG_OF is disabled?

Earlier in tas2557_parse_dt(), of_property_read_reg() is guarded with if (np) so non-OF instantiation falls back to client->addr and client->irq, and SND_SOC_TAS2557 does not depend on OF. When CONFIG_OF=n, the of_property_read_u32() stub returns -ENOSYS rather than -EINVAL, which causes this check to abort probe.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw
In reply to Gianluca Boiano
Quoted 17 lines · Gianluca Boiano

The TAS2557 is a mono Class-D smart amplifier with an on-chip DSP for speaker protection, controlled over I2C, with audio over I2S/TDM. The DSP needs a firmware image tuned for the speaker; without it the chip passes no audio.

Patch 1 adds the binding, patch 2 the driver. One node describes one chip or a stereo pair on one bus, using the reg-array convention of ti,tas2781.yaml: reg index 0 is DEV_A, index 1 is DEV_B.

v4 uses tas2781-comlib for register access, adds the firmware rate constraint asked for in the v2 review, and addresses the v3 review from Mark Brown, Krzysztof Kozlowski and Markus Elfring. The ti,imon-slot-nos/ti,vmon-slot-nos properties are gone: the register they were written to only holds the I-sense scale. I/V sense now stays on while the amplifier plays, as in TI's driver. Details are in the per-patch changelogs.

Quoted 6 lines

Testing: built against broonie/sound for-next with W=1, checkpatch --strict and dt_binding_check clean. The v4 driver was run in mono on a Xiaomi Redmi Note 6 Pro (SDM636, ASI2) on a 7.2-based kernel:
firmware load, playback, stream restarts without a program reload and unbind/bind. Stereo pairs, TDM, DSP_A, ASI1 and suspend were not tested with v4.

Thank you for working on this. We have mutiple use-cases in sdm845, please let me and possibly [email protected] in CC.

I may sent tas2559 a top of your patch at some point, thou I think it has some cleaning ahead first :)

David

Quoted 22 lines

Link to v3: https://lore.kernel.org/linux-sound/[email protected]/
Link to v2: https://lore.kernel.org/linux-sound/[email protected]/
Link to v1: https://lore.kernel.org/linux-sound/[email protected]/

Gianluca Boiano (2):
ASoC: dt-bindings: add Texas Instruments TAS2557
ASoC: codecs: add TAS2557 mono smart amplifier driver

  .../devicetree/bindings/sound/ti,tas2557.yaml |  158 +
  MAINTAINERS                                   |    1 +
  sound/soc/codecs/Kconfig                      |   13 +
  sound/soc/codecs/Makefile                     |    2 +
  sound/soc/codecs/tas2557.c                    | 2973 +++++++++++++++++
  sound/soc/codecs/tas2557.h                    |  207 ++
  6 files changed, 3354 insertions(+)

create mode 100644 Documentation/devicetree/bindings/sound/ti,tas2557.yaml create mode 100644 sound/soc/codecs/tas2557.c
create mode 100644 sound/soc/codecs/tas2557.h

base-commit: cee03387d20bb267663085d9ac2622ff9263d302