* [PATCH 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier
@ 2026-11-30 15:28 Qianhui Xu
2026-11-30 15:28 ` [PATCH 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
2026-11-30 15:28 ` [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
0 siblings, 2 replies; 4+ messages in thread
From: Qianhui Xu @ 2026-11-30 15:28 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, robh, krzk+dt, conor+dt, wangweidong.a, perex, tiwai,
linux-sound, devicetree, alsa-devel, linux-kernel
This adds support for the Awinic AW88461, a speaker amplifier of the
AW88xxx family that is used as the speaker PA on Lenovo TB322FC (SM8750)
tablets, where two instances drive the left and right speaker.
The part reports PID 0x2308 and is tuned from an ACF firmware image, so
the existing AW88395 device library is reused for parsing and profile
selection. It differs from the other family members in two ways: it has
no sample-level VCALB backup register, so the startup ramp is done by the
driver itself, and it is always wired to a reset GPIO and always needs a
firmware image, which is why the new compatible makes both properties
mandatory in the binding.
Patch 1 extends the existing awinic,aw88395 binding, patch 2 adds the
driver (Kconfig + Makefile + sound/soc/codecs/aw88461.c).
On the tablet this driver is what the everyday kernel uses for its two
speakers: both instances bind (i2c9, amplifier@34 and amplifier@37 with
awinic,audio-channel = <0> and <1>), the card registers the two
components aw88461.9-0034 and aw88461.9-0037, and it exposes a
"Left Playback Volume" and a "Right Playback Volume" control (0..1023).
Playback of a left-only and of a right-only 1 kHz test file returns
without error and leaves no PLL lock or amplifier-ready timeout in the
kernel log, and both volumes and mute are honoured. The device-tree
consumers for the tablet travel with the board support series, not with
this one.
---
Qianhui Xu (2):
ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant
ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier
.../devicetree/bindings/sound/awinic,aw88395.yaml | 11 +
sound/soc/codecs/Kconfig | 13 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/aw88461.c | 547 +++++++++++++++++++++++++++++++++++++
4 files changed, 573 insertions(+)
*** AI-assistance disclosure ***
This series was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted above; the design decisions and any errors are
the author's. The same disclosure is below the tearline of 1/2 and 2/2.
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant
2026-11-30 15:28 [PATCH 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
@ 2026-11-30 15:28 ` Qianhui Xu
2026-11-30 15:28 ` [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
1 sibling, 0 replies; 4+ messages in thread
From: Qianhui Xu @ 2026-11-30 15:28 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, robh, krzk+dt, conor+dt, wangweidong.a, perex, tiwai,
linux-sound, devicetree, alsa-devel, linux-kernel
The AW88461 belongs to the same Awinic amplifier family as the AW88395 but
is always wired to a reset GPIO and always needs an ACF firmware image, so
those two properties are made mandatory for this compatible only. The part
has no phase-sync input, so awinic,sync-flag is rejected for it.
Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
---
.../devicetree/bindings/sound/awinic,aw88395.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
diff --git a/Documentation/devicetree/bindings/sound/awinic,aw88395.yaml b/Documentation/devicetree/bindings/sound/awinic,aw88395.yaml
index b9abb10..20a74e9 100644
--- a/Documentation/devicetree/bindings/sound/awinic,aw88395.yaml
+++ b/Documentation/devicetree/bindings/sound/awinic,aw88395.yaml
@@ -23,6 +23,7 @@ properties:
- awinic,aw88261
- awinic,aw88395
- awinic,aw88399
+ - awinic,aw88461
reg:
maxItems: 1
@@ -60,6 +61,16 @@ required:
allOf:
- $ref: dai-common.yaml#
+ - if:
+ properties:
+ compatible:
+ const: awinic,aw88461
+ then:
+ required:
+ - reset-gpios
+ - firmware-name
+ properties:
+ awinic,sync-flag: false
- if:
properties:
compatible:
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
2026-11-30 15:28 [PATCH 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
2026-11-30 15:28 ` [PATCH 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
@ 2026-11-30 15:28 ` Qianhui Xu
2026-11-30 15:52 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Qianhui Xu @ 2026-11-30 15:28 UTC (permalink / raw)
To: broonie
Cc: lgirdwood, robh, krzk+dt, conor+dt, wangweidong.a, perex, tiwai,
linux-sound, devicetree, alsa-devel, linux-kernel
The AW88461 is an I2S speaker amplifier of the AW88395 family, used as the
speaker PA on Lenovo TB322FC tablets. It reports PID 0x2308 and is tuned
from an ACF firmware image, so the AW88395 device library is reused for
parsing and profile selection instead of duplicating it.
Unlike its siblings the part has no sample-level VCALB backup register,
and it must be brought up as PWDN -> PLL lock -> AMPPD -> TXEN with a
volume ramp in both directions. That sequencing runs from a work item
because the PCM trigger callback itself runs in atomic context.
Signed-off-by: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
---
sound/soc/codecs/Kconfig | 13 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/aw88461.c | 547 +++++++++++++++++++++++++++++++++++++
3 files changed, 562 insertions(+)
create mode 100644 sound/soc/codecs/aw88461.c
*** AI-assistance disclosure ***
This patch was prepared with the help of an LLM coding assistant. The
author reviewed every line, checked every quoted claim against the tree,
and ran the gates quoted in the cover letter; the design decisions and
any errors are the author's.
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index ba59dab..e4642e2 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -667,6 +667,19 @@ config SND_SOC_AW8738
SND_SOC_SIMPLE_AMPLIFIER, but additionally allows setting the
operation mode using the Awinic-specific one-wire pulse control.
+config SND_SOC_AW88461
+ tristate "Awinic AW88461 I2S amplifier"
+ depends on I2C
+ select REGMAP_I2C
+ select GPIOLIB
+ select FW_LOADER
+ select SND_SOC_AW88395_LIB
+ help
+ Enable playback through the Awinic AW88461 amplifier, using the
+ speaker tuning image named in devicetree.
+ To compile this driver as a module, choose M here: the module
+ will be called snd-soc-aw88461.
+
config SND_SOC_AW88395_LIB
select CRC8
tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 3826f9e..3f08d20 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -56,6 +56,7 @@ snd-soc-aw88166-y := aw88166.o
snd-soc-aw88261-y := aw88261.o
snd-soc-aw88399-y := aw88399.o
snd-soc-aw88399-lib-y := aw88399-lib.o
+snd-soc-aw88461-y := aw88461.o
snd-soc-bd28623-y := bd28623.o
snd-soc-bt-sco-y := bt-sco.o
snd-soc-chv3-codec-y := chv3-codec.o
@@ -504,6 +505,7 @@ obj-$(CONFIG_SND_SOC_AW88166) +=snd-soc-aw88166.o
obj-$(CONFIG_SND_SOC_AW88261) +=snd-soc-aw88261.o
obj-$(CONFIG_SND_SOC_AW88399) += snd-soc-aw88399.o
obj-$(CONFIG_SND_SOC_AW88399_LIB) += snd-soc-aw88399-lib.o
+obj-$(CONFIG_SND_SOC_AW88461) += snd-soc-aw88461.o
obj-$(CONFIG_SND_SOC_BD28623) += snd-soc-bd28623.o
obj-$(CONFIG_SND_SOC_BT_SCO) += snd-soc-bt-sco.o
obj-$(CONFIG_SND_SOC_CHV3_CODEC) += snd-soc-chv3-codec.o
diff --git a/sound/soc/codecs/aw88461.c b/sound/soc/codecs/aw88461.c
new file mode 100644
index 0000000..73f37c2
--- /dev/null
+++ b/sound/soc/codecs/aw88461.c
@@ -0,0 +1,547 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Awinic AW88461 I2S amplifier (PID 0x2308).
+ * Register layout and power sequencing follow the AWINIC PID 2308 driver.
+ */
+#include <linux/bitfield.h>
+#include <linux/delay.h>
+#include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/unaligned.h>
+#include <linux/workqueue.h>
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+#include "aw88395/aw88395_device.h"
+
+#define AW88461_ID 0x00
+#define AW88461_SYSST 0x01
+#define AW88461_SYSINTM 0x03
+#define AW88461_SYSCTRL 0x04
+#define AW88461_SYSCTRL2 0x05
+#define AW88461_I2SCTRL1 0x06
+#define AW88461_NGCTRL3 0x5e
+#define AW88461_CHIP_ID 0x2308
+#define AW88461_SOFT_RESET 0x55aa
+#define AW88461_PWDN BIT(0)
+#define AW88461_AMPPD BIT(1)
+#define AW88461_HMUTE BIT(8)
+#define AW88461_TXEN BIT(13)
+#define AW88461_ULS_HMUTE BIT(15)
+#define AW88461_VOLUME GENMASK(9, 0)
+#define AW88461_NOISE_GATE BIT(0)
+#define AW88461_PLL_LOCK (BIT(4) | BIT(0))
+#define AW88461_BOOST_READY BIT(9)
+#define AW88461_SWITCHING BIT(8)
+#define AW88461_FAULTS (BIT(14) | BIT(11) | BIT(5) | BIT(3) | BIT(1))
+
+struct aw88461 {
+ struct aw_device aw_dev;
+ struct gpio_desc *reset;
+ /* Serialize DAPM power transitions and mixer/DAI register access. */
+ struct mutex lock;
+ struct work_struct start_work;
+ unsigned int volume;
+ unsigned int profile_volume;
+ unsigned int profile_txen;
+ bool enabled;
+ bool running;
+ bool powered;
+ bool faulted;
+};
+
+static const struct regmap_config aw88461_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 16,
+ .val_format_endian = REGMAP_ENDIAN_BIG,
+ .max_register = 0x7f,
+};
+
+static void aw88461_reset(void *data)
+{
+ struct aw88461 *amp = data;
+
+ gpiod_set_value_cansleep(amp->reset, 1);
+}
+
+static int aw88461_fault(struct aw88461 *amp, int error)
+{
+ amp->powered = false;
+ amp->faulted = true;
+ aw88461_reset(amp);
+ return error;
+}
+
+static int aw88461_set_volume(struct aw88461 *amp, unsigned int attenuation)
+{
+ return regmap_update_bits(amp->aw_dev.regmap, AW88461_SYSCTRL2,
+ AW88461_VOLUME, min(attenuation, 1023U));
+}
+
+static int aw88461_fade(struct aw88461 *amp, int from, int to,
+ unsigned int delay_us)
+{
+ int step = from < to ? 64 : -64;
+ int ret;
+
+ while (from != to) {
+ ret = aw88461_set_volume(amp, from);
+ if (ret)
+ return ret;
+ usleep_range(delay_us, delay_us + 10);
+ from = step > 0 ? min(from + step, to) : max(from + step, to);
+ }
+ return aw88461_set_volume(amp, to);
+}
+
+static int aw88461_stop(struct aw88461 *amp)
+{
+ struct regmap *map = amp->aw_dev.regmap;
+ int ret;
+
+ if (!amp->powered)
+ return 0;
+ amp->powered = false;
+ ret = regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_ULS_HMUTE, AW88461_ULS_HMUTE);
+ if (ret)
+ return aw88461_fault(amp, ret);
+ ret = aw88461_fade(amp, min(amp->profile_volume + 1023 - amp->volume, 1023U),
+ 1023, 500);
+ if (ret)
+ return aw88461_fault(amp, ret);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_HMUTE, AW88461_HMUTE);
+ if (ret)
+ return aw88461_fault(amp, ret);
+ usleep_range(10000, 10500);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN, 0);
+ if (ret)
+ return aw88461_fault(amp, ret);
+ usleep_range(1000, 1200);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_AMPPD | AW88461_PWDN,
+ AW88461_AMPPD | AW88461_PWDN);
+ return ret ? aw88461_fault(amp, ret) : 0;
+}
+
+static bool aw88461_active(struct aw88461 *amp)
+{
+ return READ_ONCE(amp->enabled) && READ_ONCE(amp->running);
+}
+
+static int aw88461_start(struct aw88461 *amp)
+{
+ struct regmap *map = amp->aw_dev.regmap;
+ unsigned int status = 0, noise_gate, ready;
+ int ret;
+
+ if (amp->faulted)
+ return -EIO;
+ if (amp->powered || !aw88461_active(amp))
+ return 0;
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_PWDN, 0);
+ if (ret)
+ goto stop;
+ amp->powered = true;
+ usleep_range(2000, 2200);
+ ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
+ (status & AW88461_PLL_LOCK) == AW88461_PLL_LOCK ||
+ !aw88461_active(amp),
+ 2000, 100000);
+ if (ret) {
+ dev_err(amp->aw_dev.dev, "PLL lock failed: %d, status %#x\n", ret, status);
+ goto stop;
+ }
+ if (!aw88461_active(amp))
+ return aw88461_stop(amp);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_AMPPD, 0);
+ if (ret)
+ goto stop;
+ usleep_range(1000, 1200);
+ ret = regmap_read(map, AW88461_NGCTRL3, &noise_gate);
+ if (ret)
+ goto stop;
+ ready = AW88461_PLL_LOCK | AW88461_BOOST_READY;
+ if (!(noise_gate & AW88461_NOISE_GATE))
+ ready |= AW88461_SWITCHING;
+ ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
+ (status & ready) == ready || !aw88461_active(amp),
+ 2000, 20000);
+ if (ret) {
+ dev_err(amp->aw_dev.dev, "amplifier ready failed: %d, status %#x\n", ret, status);
+ goto stop;
+ }
+ if (!aw88461_active(amp))
+ return aw88461_stop(amp);
+ if (status & AW88461_FAULTS) {
+ ret = -EIO;
+ goto stop;
+ }
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN,
+ amp->profile_txen);
+ if (ret)
+ goto stop;
+ ret = regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_HMUTE | AW88461_ULS_HMUTE, 0);
+ if (ret)
+ goto stop;
+ ret = aw88461_fade(amp, 1023,
+ min(amp->profile_volume + 1023 - amp->volume, 1023U), 100);
+ if (ret)
+ goto stop;
+ return 0;
+stop:
+ return aw88461_fault(amp, ret);
+}
+
+static int aw88461_load_profile(struct aw88461 *amp)
+{
+ struct aw_device *aw_dev = &->aw_dev;
+ const struct firmware *fw;
+ struct aw_container *cfg;
+ struct aw_sec_data_desc *regs = NULL;
+ const char *name;
+ unsigned int i, address, value;
+ int ret;
+
+ ret = device_property_read_string(aw_dev->dev, "firmware-name", &name);
+ if (ret)
+ return ret;
+ ret = request_firmware(&fw, name, aw_dev->dev);
+ if (ret)
+ return ret;
+ if (fw->size < sizeof(struct aw_cfg_hdr)) {
+ ret = -EINVAL;
+ goto release;
+ }
+ if (fw->size > INT_MAX) {
+ ret = -EFBIG;
+ goto release;
+ }
+ cfg = devm_kzalloc(aw_dev->dev, struct_size(cfg, data, fw->size), GFP_KERNEL);
+ if (!cfg) {
+ ret = -ENOMEM;
+ goto release;
+ }
+ cfg->len = fw->size;
+ memcpy(cfg->data, fw->data, fw->size);
+ ret = aw88395_dev_load_acf_check(aw_dev, cfg);
+ if (ret)
+ goto release;
+ ret = aw88395_dev_cfg_load(aw_dev, cfg);
+ if (ret)
+ goto release;
+ for (i = 0; i < aw_dev->prof_info.count; i++) {
+ struct aw_prof_desc *profile = &aw_dev->prof_info.prof_desc[i];
+
+ if (profile->id == AW88395_PROFILE_MUSIC) {
+ regs = &profile->sec_desc[AW88395_DATA_TYPE_REG];
+ break;
+ }
+ }
+ ret = -EINVAL;
+ if (!regs || !regs->len || regs->len % 4)
+ goto release;
+ /* Validate the entire section before writing any of its registers. */
+ for (i = 0; i < regs->len; i += 4) {
+ address = get_unaligned_le16(regs->data + i);
+ value = get_unaligned_le16(regs->data + i + 2);
+ if (address == 0xff && !value)
+ continue;
+ if (!((address >= 3 && address <= 0x1f) ||
+ (address >= 0x30 && address <= 0x38) ||
+ (address >= 0x3a && address <= 0x3f) ||
+ (address >= 0x50 && address <= 0x6d)))
+ goto release;
+ }
+ ret = regmap_write(aw_dev->regmap, AW88461_ID, AW88461_SOFT_RESET);
+ if (ret)
+ goto release;
+ usleep_range(1000, 1200);
+ for (i = 0; i < regs->len; i += 4) {
+ address = get_unaligned_le16(regs->data + i);
+ value = get_unaligned_le16(regs->data + i + 2);
+ /* PID 2308 has no software VCALB register; ff is its sentinel. */
+ if (address == 0xff)
+ continue;
+ if (address == AW88461_SYSINTM)
+ value = 0xffff;
+ if (address == AW88461_SYSCTRL) {
+ amp->profile_txen = value & AW88461_TXEN;
+ value |= AW88461_PWDN | AW88461_AMPPD |
+ AW88461_HMUTE | AW88461_ULS_HMUTE;
+ value &= ~AW88461_TXEN;
+ }
+ if (address == AW88461_SYSCTRL2) {
+ amp->profile_volume = value & AW88461_VOLUME;
+ value |= AW88461_VOLUME;
+ }
+ ret = regmap_write(aw_dev->regmap, address, value);
+ if (ret)
+ goto release;
+ }
+release:
+ release_firmware(fw);
+ return ret;
+}
+
+static int aw88461_hw_params(struct snd_pcm_substream *substream,
+ struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
+{
+ struct aw88461 *amp = snd_soc_component_get_drvdata(dai->component);
+ unsigned int frame, width;
+ int ret;
+
+ if (params_rate(params) != 48000 || params_channels(params) != 2)
+ return -EINVAL;
+ switch (params_width(params)) {
+ case 16:
+ width = 0;
+ break;
+ case 24:
+ width = 2;
+ break;
+ case 32:
+ width = 3;
+ break;
+ default:
+ return -EINVAL;
+ }
+ frame = params_physical_width(params) == 16 ? 0 : 2;
+ guard(mutex)(&->lock);
+ if (amp->faulted)
+ return -EIO;
+ ret = regmap_update_bits(amp->aw_dev.regmap, AW88461_I2SCTRL1,
+ GENMASK(9, 0), FIELD_PREP(GENMASK(7, 6), width) |
+ FIELD_PREP(GENMASK(5, 4), frame) | 8);
+ return ret ? aw88461_fault(amp, ret) : 0;
+}
+
+static int aw88461_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
+{
+ if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_I2S ||
+ (fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF ||
+ (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_BC_FC)
+ return -EINVAL;
+ return 0;
+}
+
+static int aw88461_trigger(struct snd_pcm_substream *substream, int cmd,
+ struct snd_soc_dai *dai)
+{
+ struct aw88461 *amp = snd_soc_component_get_drvdata(dai->component);
+
+ switch (cmd) {
+ case SNDRV_PCM_TRIGGER_START:
+ case SNDRV_PCM_TRIGGER_RESUME:
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ WRITE_ONCE(amp->running, true);
+ break;
+ case SNDRV_PCM_TRIGGER_STOP:
+ case SNDRV_PCM_TRIGGER_SUSPEND:
+ case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+ WRITE_ONCE(amp->running, false);
+ break;
+ default:
+ return -EINVAL;
+ }
+ /* Trigger may be atomic; all I2C and power sequencing runs in work. */
+ schedule_work(&->start_work);
+ return 0;
+}
+
+static const struct snd_soc_dai_ops aw88461_dai_ops = {
+ .hw_params = aw88461_hw_params,
+ .set_fmt = aw88461_set_fmt,
+ .trigger = aw88461_trigger,
+};
+
+static struct snd_soc_dai_driver aw88461_dai = {
+ .name = "aw88461-aif",
+ .playback = {
+ .stream_name = "Playback",
+ .channels_min = 2,
+ .channels_max = 2,
+ .rates = SNDRV_PCM_RATE_48000,
+ .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |
+ SNDRV_PCM_FMTBIT_S32_LE,
+ },
+ .ops = &aw88461_dai_ops,
+};
+
+static int aw88461_volume_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *value)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct aw88461 *amp = snd_soc_component_get_drvdata(component);
+
+ guard(mutex)(&->lock);
+ value->value.integer.value[0] = amp->volume;
+ return 0;
+}
+
+static int aw88461_volume_put(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *value)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct aw88461 *amp = snd_soc_component_get_drvdata(component);
+ long volume = value->value.integer.value[0];
+ int ret;
+
+ if (volume < 0 || volume > 1023)
+ return -EINVAL;
+ guard(mutex)(&->lock);
+ if (amp->faulted)
+ return -EIO;
+ if (amp->volume == volume)
+ return 0;
+ if (amp->powered) {
+ ret = aw88461_set_volume(amp, amp->profile_volume + 1023 - volume);
+ if (ret)
+ return aw88461_fault(amp, ret);
+ }
+ amp->volume = volume;
+ return 1;
+}
+
+static const struct snd_kcontrol_new aw88461_controls[] = {
+ SOC_SINGLE_EXT("Playback Volume", SND_SOC_NOPM, 0, 1023, 0,
+ aw88461_volume_get, aw88461_volume_put),
+};
+
+static int aw88461_event(struct snd_soc_dapm_widget *w,
+ struct snd_kcontrol *kcontrol, int event)
+{
+ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+ struct aw88461 *amp = snd_soc_component_get_drvdata(component);
+
+ if (event == SND_SOC_DAPM_POST_PMU) {
+ /* The I2S source may not start its clocks until PCM trigger. */
+ WRITE_ONCE(amp->enabled, true);
+ schedule_work(&->start_work);
+ return 0;
+ }
+ WRITE_ONCE(amp->enabled, false);
+ cancel_work_sync(&->start_work);
+ guard(mutex)(&->lock);
+ return aw88461_stop(amp);
+}
+
+static void aw88461_start_work(struct work_struct *work)
+{
+ struct aw88461 *amp = container_of(work, struct aw88461, start_work);
+ int ret;
+
+ guard(mutex)(&->lock);
+ ret = aw88461_active(amp) ? aw88461_start(amp) : aw88461_stop(amp);
+ if (ret)
+ dev_err(amp->aw_dev.dev, "amplifier power transition failed: %d\n", ret);
+}
+
+static void aw88461_cancel_work(void *data)
+{
+ struct aw88461 *amp = data;
+
+ WRITE_ONCE(amp->enabled, false);
+ disable_work_sync(&->start_work);
+}
+
+static const struct snd_soc_dapm_widget aw88461_widgets[] = {
+ SND_SOC_DAPM_AIF_IN("AIFIN", "Playback", 0, SND_SOC_NOPM, 0, 0),
+ SND_SOC_DAPM_PGA_E("Amplifier", SND_SOC_NOPM, 0, 0, NULL, 0,
+ aw88461_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
+ SND_SOC_DAPM_OUTPUT("OUT"),
+};
+
+static const struct snd_soc_dapm_route aw88461_routes[] = {
+ { "Amplifier", NULL, "AIFIN" },
+ { "OUT", NULL, "Amplifier" },
+};
+
+static const struct snd_soc_component_driver aw88461_component = {
+ .controls = aw88461_controls,
+ .num_controls = ARRAY_SIZE(aw88461_controls),
+ .dapm_widgets = aw88461_widgets,
+ .num_dapm_widgets = ARRAY_SIZE(aw88461_widgets),
+ .dapm_routes = aw88461_routes,
+ .num_dapm_routes = ARRAY_SIZE(aw88461_routes),
+};
+
+static int aw88461_probe(struct i2c_client *client)
+{
+ struct aw88461 *amp;
+ unsigned int id;
+ int ret;
+
+ amp = devm_kzalloc(&client->dev, sizeof(*amp), GFP_KERNEL);
+ if (!amp)
+ return -ENOMEM;
+ amp->aw_dev.dev = &client->dev;
+ amp->aw_dev.i2c = client;
+ amp->aw_dev.chip_id = AW88461_CHIP_ID;
+ amp->aw_dev.prof_info.prof_type = AW88395_DEV_NONE_TYPE_ID;
+ ret = device_property_read_u32(&client->dev, "awinic,audio-channel", &->aw_dev.channel);
+ if (ret && device_property_present(&client->dev, "awinic,audio-channel"))
+ return ret;
+ mutex_init(&->lock);
+ INIT_WORK(&->start_work, aw88461_start_work);
+ i2c_set_clientdata(client, amp);
+ amp->aw_dev.regmap = devm_regmap_init_i2c(client, &aw88461_regmap_config);
+ if (IS_ERR(amp->aw_dev.regmap))
+ return PTR_ERR(amp->aw_dev.regmap);
+ amp->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(amp->reset))
+ return dev_err_probe(&client->dev, PTR_ERR(amp->reset), "reset GPIO unavailable\n");
+ ret = devm_add_action_or_reset(&client->dev, aw88461_reset, amp);
+ if (ret)
+ return ret;
+ usleep_range(1000, 1200);
+ gpiod_set_value_cansleep(amp->reset, 0);
+ usleep_range(2000, 2500);
+ ret = regmap_read(amp->aw_dev.regmap, AW88461_ID, &id);
+ if (ret)
+ return ret;
+ if (id != AW88461_CHIP_ID)
+ return dev_err_probe(&client->dev, -ENODEV, "unexpected chip ID %#x\n", id);
+ ret = aw88461_load_profile(amp);
+ if (ret)
+ return dev_err_probe(&client->dev, ret, "amplifier profile load failed\n");
+ ret = devm_add_action_or_reset(&client->dev, aw88461_cancel_work, amp);
+ if (ret)
+ return ret;
+ return devm_snd_soc_register_component(&client->dev, &aw88461_component,
+ &aw88461_dai, 1);
+}
+
+static void aw88461_shutdown(struct i2c_client *client)
+{
+ struct aw88461 *amp = i2c_get_clientdata(client);
+
+ aw88461_cancel_work(amp);
+ guard(mutex)(&->lock);
+ aw88461_reset(amp);
+}
+
+static const struct of_device_id aw88461_of_match[] = {
+ { .compatible = "awinic,aw88461" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, aw88461_of_match);
+
+static struct i2c_driver aw88461_driver = {
+ .driver = {
+ .name = "aw88461",
+ .of_match_table = aw88461_of_match,
+ },
+ .probe = aw88461_probe,
+ .shutdown = aw88461_shutdown,
+};
+module_i2c_driver(aw88461_driver);
+
+MODULE_DESCRIPTION("Awinic AW88461 I2S amplifier driver");
+MODULE_LICENSE("GPL");
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
2026-11-30 15:28 ` [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
@ 2026-11-30 15:52 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-30 15:52 UTC (permalink / raw)
To: Qianhui Xu; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 5 potential
issues to consider:
- [High] ASoC: aw88461: permanent device lockout via aw88461_fault() in
aw88461_start()
- [Medium] ASoC: aw88461: broken V1 ACF profile match in
aw88461_load_profile()
- [Medium] ASoC: aw88461: uninitialized volume in aw88461_probe() mutes
output by default
- [Medium] ASoC: aw88461: TOCTOU race on amp->running in aw88461_start()
poll loops
- [Low] ASoC: codecs: missing imply SND_SOC_AW88461 under
SND_SOC_ALL_CODECS
--
commit e138f0073130da2e91b260e4720f2680fa0ccf3d
Author: Qianhui Xu <xiaqinghuan@mail.ustc.edu.cn>
ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
This commit adds an ASoC codec driver for the Awinic AW88461 I2S speaker
amplifier, reusing the AW88395 library to parse ACF firmware profiles.
> diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
> index 6239de3afa5a4..b6d4d7710728f 100644
> --- a/sound/soc/codecs/Kconfig
> +++ b/sound/soc/codecs/Kconfig
> @@ -671,6 +671,19 @@ config SND_SOC_AW8738
> SND_SOC_SIMPLE_AMPLIFIER, but additionally allows setting the
> operation mode using the Awinic-specific one-wire pulse control.
>
> +config SND_SOC_AW88461
> + tristate "Awinic AW88461 I2S amplifier"
> + depends on I2C
> + select REGMAP_I2C
> + select GPIOLIB
> + select FW_LOADER
> + select SND_SOC_AW88395_LIB
> + help
> + Enable playback through the Awinic AW88461 amplifier, using the
> + speaker tuning image named in devicetree.
> + To compile this driver as a module, choose M here: the module
> + will be called snd-soc-aw88461.
> +
[Severity: Low]
Should SND_SOC_ALL_CODECS also have an "imply SND_SOC_AW88461" entry like
the other Awinic codec drivers so it is included in all-codecs test builds?
> diff --git a/sound/soc/codecs/aw88461.c b/sound/soc/codecs/aw88461.c
> new file mode 100644
> index 0000000000000..73f37c253963c
> --- /dev/null
> +++ b/sound/soc/codecs/aw88461.c
[ ... ]
> +static int aw88461_fault(struct aw88461 *amp, int error)
> +{
> + amp->powered = false;
> + amp->faulted = true;
> + aw88461_reset(amp);
> + return error;
> +}
[ ... ]
> +static int aw88461_start(struct aw88461 *amp)
> +{
> + struct regmap *map = amp->aw_dev.regmap;
> + unsigned int status = 0, noise_gate, ready;
> + int ret;
> +
> + if (amp->faulted)
> + return -EIO;
> + if (amp->powered || !aw88461_active(amp))
> + return 0;
> + ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_PWDN, 0);
> + if (ret)
> + goto stop;
> + amp->powered = true;
> + usleep_range(2000, 2200);
> + ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
> + (status & AW88461_PLL_LOCK) == AW88461_PLL_LOCK ||
> + !aw88461_active(amp),
> + 2000, 100000);
> + if (ret) {
> + dev_err(amp->aw_dev.dev, "PLL lock failed: %d, status %#x\n", ret, status);
> + goto stop;
> + }
> + if (!aw88461_active(amp))
> + return aw88461_stop(amp);
[Severity: Medium]
Can a concurrent PCM stop/start toggle cause aw88461_start() to proceed
without AW88461_PLL_LOCK (or ready in the second poll loop)?
aw88461_trigger() updates amp->running locklessly with WRITE_ONCE() while
aw88461_start() holds amp->lock:
kworker (aw88461_start_work) CPU1 (PCM trigger)
aw88461_start()
amp->powered = true
regmap_read_poll_timeout()
status has no PLL_LOCK
aw88461_trigger(STOP)
WRITE_ONCE(amp->running, false)
!aw88461_active(amp) is true
poll returns 0
aw88461_trigger(START)
WRITE_ONCE(amp->running, true)
if (!aw88461_active(amp)) -> false
clears AMPPD, enables TXEN <-- runs without PLL lock
Because amp->powered is already true, the newly queued start_work will also
return 0 immediately without re-checking readiness. Checking whether the
expected status bits are actually set in status after the poll loop (and
calling aw88461_stop() if not) would avoid relying on a second read of
aw88461_active(amp).
> + ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_AMPPD, 0);
> + if (ret)
> + goto stop;
> + usleep_range(1000, 1200);
> + ret = regmap_read(map, AW88461_NGCTRL3, &noise_gate);
> + if (ret)
> + goto stop;
> + ready = AW88461_PLL_LOCK | AW88461_BOOST_READY;
> + if (!(noise_gate & AW88461_NOISE_GATE))
> + ready |= AW88461_SWITCHING;
> + ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
> + (status & ready) == ready || !aw88461_active(amp),
> + 2000, 20000);
> + if (ret) {
> + dev_err(amp->aw_dev.dev, "amplifier ready failed: %d, status %#x\n", ret, status);
> + goto stop;
> + }
> + if (!aw88461_active(amp))
> + return aw88461_stop(amp);
> + if (status & AW88461_FAULTS) {
> + ret = -EIO;
> + goto stop;
> + }
> + ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN,
> + amp->profile_txen);
> + if (ret)
> + goto stop;
> + ret = regmap_update_bits(map, AW88461_SYSCTRL,
> + AW88461_HMUTE | AW88461_ULS_HMUTE, 0);
> + if (ret)
> + goto stop;
> + ret = aw88461_fade(amp, 1023,
> + min(amp->profile_volume + 1023 - amp->volume, 1023U), 100);
> + if (ret)
> + goto stop;
> + return 0;
> +stop:
> + return aw88461_fault(amp, ret);
> +}
[Severity: High]
Does jumping to stop: on a poll timeout or transient status bit in
aw88461_start() permanently disable the amplifier until reboot?
aw88461_fault() asserts the hardware reset GPIO (wiping the register
configuration loaded from the ACF firmware at probe) and latches
amp->faulted = true, which is never cleared and causes all later start,
hw_params, and volume updates to fail with -EIO.
This is easy to hit during normal playback:
1. The second regmap_read_poll_timeout() exits as soon as (status & ready)
== ready without waiting for !(status & AW88461_FAULTS), so any
transient fault bit still set on that read immediately triggers
aw88461_fault().
2. On PCM stop or pause, snd_soc_pcm_dai_trigger() stops the CPU DAI
before calling aw88461_trigger(), so the I2S clock can stop while
aw88461_start() is still polling AW88461_SYSST with amp->running == true,
timing out the PLL lock poll or setting NOCLKS in AW88461_FAULTS.
If startup fails or times out, powering the chip back down cleanly (setting
AW88461_AMPPD | AW88461_PWDN) rather than asserting hardware reset and
latching amp->faulted would allow subsequent playback streams to retry.
> +
> +static int aw88461_load_profile(struct aw88461 *amp)
> +{
> + struct aw_device *aw_dev = &->aw_dev;
> + const struct firmware *fw;
> + struct aw_container *cfg;
> + struct aw_sec_data_desc *regs = NULL;
> + const char *name;
> + unsigned int i, address, value;
> + int ret;
> +
> + ret = device_property_read_string(aw_dev->dev, "firmware-name", &name);
> + if (ret)
> + return ret;
> + ret = request_firmware(&fw, name, aw_dev->dev);
> + if (ret)
> + return ret;
> + if (fw->size < sizeof(struct aw_cfg_hdr)) {
> + ret = -EINVAL;
> + goto release;
> + }
> + if (fw->size > INT_MAX) {
> + ret = -EFBIG;
> + goto release;
> + }
> + cfg = devm_kzalloc(aw_dev->dev, struct_size(cfg, data, fw->size), GFP_KERNEL);
> + if (!cfg) {
> + ret = -ENOMEM;
> + goto release;
> + }
> + cfg->len = fw->size;
> + memcpy(cfg->data, fw->data, fw->size);
> + ret = aw88395_dev_load_acf_check(aw_dev, cfg);
> + if (ret)
> + goto release;
> + ret = aw88395_dev_cfg_load(aw_dev, cfg);
> + if (ret)
> + goto release;
> + for (i = 0; i < aw_dev->prof_info.count; i++) {
> + struct aw_prof_desc *profile = &aw_dev->prof_info.prof_desc[i];
> +
> + if (profile->id == AW88395_PROFILE_MUSIC) {
> + regs = &profile->sec_desc[AW88395_DATA_TYPE_REG];
> + break;
> + }
> + }
[Severity: Medium]
Does checking profile->id == AW88395_PROFILE_MUSIC work on V1 ACF firmware
images (AW88395_CFG_HDR_VER_V1)?
In aw88395_dev_cfg_load() -> aw_dev_load_cfg_by_hdr_v1() ->
aw_dev_create_prof_name_list_v1(), the library overwrites prof_desc[i].id
with the sequential loop index i:
sound/soc/codecs/aw88395/aw88395_lib.c:aw_dev_create_prof_name_list_v1() {
...
for (i = 0; i < prof_info->count; i++) {
prof_desc[i].id = i;
prof_info->prof_name_list[i] = prof_desc[i].prf_str;
...
}
Because AW88395_PROFILE_MUSIC is 0, this loop always picks prof_desc[0] on
V1 ACF files regardless of which profile is at index 0, and cannot find
the Music profile if it is placed at a non-zero index.
Also, since aw88461_load_profile() writes the register values immediately
and never uses cfg or prof_info after returning, allocating cfg with
devm_kzalloc() keeps a copy of the firmware image allocated for the lifetime
of the device.
[ ... ]
> +static int aw88461_probe(struct i2c_client *client)
> +{
> + struct aw88461 *amp;
> + unsigned int id;
> + int ret;
> +
> + amp = devm_kzalloc(&client->dev, sizeof(*amp), GFP_KERNEL);
> + if (!amp)
> + return -ENOMEM;
[Severity: Medium]
Should aw88461_probe() initialize amp->volume to 1023?
aw88461_start(), aw88461_stop(), and aw88461_volume_put() compute the
hardware attenuation as:
min(amp->profile_volume + 1023 - amp->volume, 1023U)
With amp->volume left at 0 by devm_kzalloc(), the target attenuation is
clamped to 1023 (maximum attenuation), so the startup fade in
aw88461_start() fades from 1023 to 1023 and the amplifier stays muted after
probe until userspace raises "Playback Volume" above amp->profile_volume.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130152838.979263-1-xiaqinghuan@mail.ustc.edu.cn?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-30 15:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 15:28 [PATCH 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
2026-11-30 15:28 ` [PATCH 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
2026-11-30 15:28 ` [PATCH 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
2026-11-30 15:52 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox