* [PATCH v2 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier
@ 2026-11-30 23:47 Qianhui Xu
2026-11-30 23:47 ` [PATCH v2 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
2026-11-30 23:47 ` [PATCH v2 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 23:47 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).
Changes in v2:
- Do not latch a permanent error when the start sequence fails. The
amplifier is parked muted and powered down, so the next playback can
retry; the reset line is cycled only for a real hardware fault.
- After such a reset, replay both the ACF register sequence and the I2S
format computed in hw_params(), which the reset would otherwise drop.
- Only over-current, over-temperature and boost faults are treated as
fatal, and they are checked inside the poll loops, so a stuck clock
fault ends as a retryable power-down instead of a timeout.
- Select the Music profile by name for V1 ACF images, whose profile ids
the library renumbers sequentially.
- Initialise the software volume to the profile level, so the amplifier is
not stuck at maximum attenuation before userspace sets a level.
- Verify the expected SYSST bits after each poll loop; a stop/start race
could otherwise enable the output without PLL lock.
- Add the driver to SND_SOC_ALL_CODECS.
*** 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.
Qianhui Xu (2):
ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant
ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
.../bindings/sound/awinic,aw88395.yaml | 11 +
sound/soc/codecs/Kconfig | 14 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/aw88461.c | 645 ++++++++++++++++++
4 files changed, 672 insertions(+)
create mode 100644 sound/soc/codecs/aw88461.c
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant
2026-11-30 23:47 [PATCH v2 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
@ 2026-11-30 23:47 ` Qianhui Xu
2026-11-30 23:47 ` [PATCH v2 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 23:47 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>
---
*** 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.
.../devicetree/bindings/sound/awinic,aw88395.yaml | 11 +++++++++++
1 file changed, 11 insertions(+)
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 v2 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
2026-11-30 23:47 [PATCH v2 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
2026-11-30 23:47 ` [PATCH v2 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
@ 2026-11-30 23:47 ` Qianhui Xu
2026-11-30 23:57 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Qianhui Xu @ 2026-11-30 23:47 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>
---
*** 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.
sound/soc/codecs/Kconfig | 14 +
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/aw88461.c | 645 +++++++++++++++++++++++++++++++++++++
3 files changed, 661 insertions(+)
create mode 100644 sound/soc/codecs/aw88461.c
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index ba59dab..6ec05c0 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -60,6 +60,7 @@ config SND_SOC_ALL_CODECS
imply SND_SOC_AW88166
imply SND_SOC_AW88261
imply SND_SOC_AW88399
+ imply SND_SOC_AW88461
imply SND_SOC_BT_SCO
imply SND_SOC_BD28623
imply SND_SOC_CHV3_CODEC
@@ -667,6 +668,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..e5fb31f
--- /dev/null
+++ b/sound/soc/codecs/aw88461.c
@@ -0,0 +1,645 @@
+// 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/string.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_I2SEN BIT(3)
+#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(11) | 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;
+ unsigned int i2sctrl1;
+ bool enabled;
+ bool running;
+ bool powered;
+ /* Register sequence of the Music profile, replayed after a reset. */
+ u8 *seq;
+ size_t seq_len;
+};
+
+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_apply_seq(struct aw88461 *amp)
+{
+ struct regmap *map = amp->aw_dev.regmap;
+ unsigned int i, address, value;
+ int ret;
+
+ ret = regmap_write(map, AW88461_ID, AW88461_SOFT_RESET);
+ if (ret)
+ return ret;
+ usleep_range(1000, 1200);
+ for (i = 0; i < amp->seq_len; i += 4) {
+ address = get_unaligned_le16(amp->seq + i);
+ value = get_unaligned_le16(amp->seq + 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(map, address, value);
+ if (ret)
+ return ret;
+ }
+ return 0;
+}
+
+/*
+ * Park the chip in a silent, powered-down state. The driver deliberately does
+ * not latch an error (and does not touch the profile loaded into the chip), so
+ * that the DAPM power-up event of the next playback can retry.
+ */
+static int aw88461_down(struct aw88461 *amp, int error)
+{
+ struct regmap *map = amp->aw_dev.regmap;
+
+ amp->powered = false;
+ if (regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_HMUTE | AW88461_ULS_HMUTE,
+ AW88461_HMUTE | AW88461_ULS_HMUTE))
+ dev_err(amp->aw_dev.dev, "failed to mute the amplifier\n");
+ if (regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_AMPPD | AW88461_PWDN,
+ AW88461_AMPPD | AW88461_PWDN))
+ dev_err(amp->aw_dev.dev, "failed to power down the amplifier\n");
+ return error;
+}
+
+/*
+ * The fault bits of SYSST are sticky in the chip, so a hardware fault needs a
+ * reset; the ACF register sequence and the I2S format computed in hw_params()
+ * are replayed afterwards because the reset also drops them.
+ */
+static int aw88461_recover(struct aw88461 *amp, unsigned int status)
+{
+ dev_err(amp->aw_dev.dev, "amplifier fault, status %#x\n", status);
+ aw88461_reset(amp);
+ usleep_range(1000, 1200);
+ gpiod_set_value_cansleep(amp->reset, 0);
+ usleep_range(2000, 2500);
+ amp->powered = false;
+ if (aw88461_apply_seq(amp))
+ return -EIO;
+ if (amp->i2sctrl1)
+ regmap_update_bits(amp->aw_dev.regmap, AW88461_I2SCTRL1,
+ GENMASK(9, 0), amp->i2sctrl1);
+ return aw88461_down(amp, -EIO);
+}
+
+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_down(amp, ret);
+ ret = aw88461_fade(amp, min(amp->profile_volume + 1023 - amp->volume, 1023U),
+ 1023, 500);
+ if (ret)
+ return aw88461_down(amp, ret);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_HMUTE, AW88461_HMUTE);
+ if (ret)
+ return aw88461_down(amp, ret);
+ usleep_range(10000, 10500);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN, 0);
+ if (ret)
+ return aw88461_down(amp, ret);
+ usleep_range(1000, 1200);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_AMPPD | AW88461_PWDN,
+ AW88461_AMPPD | AW88461_PWDN);
+ return ret ? aw88461_down(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->powered || !aw88461_active(amp))
+ return 0;
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_PWDN, 0);
+ if (ret)
+ goto down;
+ amp->powered = true;
+ usleep_range(2000, 2200);
+ ret = regmap_read_poll_timeout(map, AW88461_SYSST, status,
+ (status & AW88461_PLL_LOCK) == AW88461_PLL_LOCK ||
+ (status & AW88461_FAULTS) ||
+ !aw88461_active(amp),
+ 2000, 100000);
+ if (ret) {
+ dev_err(amp->aw_dev.dev, "PLL lock failed: %d, status %#x\n", ret, status);
+ goto down;
+ }
+ /*
+ * aw88461_active() may have changed while the poll was running, so check
+ * the expected status bits instead of trusting the escape condition.
+ */
+ if (!aw88461_active(amp))
+ return aw88461_stop(amp);
+ if (status & AW88461_FAULTS)
+ return aw88461_recover(amp, status);
+ if ((status & AW88461_PLL_LOCK) != AW88461_PLL_LOCK)
+ return aw88461_stop(amp);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_AMPPD, 0);
+ if (ret)
+ goto down;
+ usleep_range(1000, 1200);
+ ret = regmap_read(map, AW88461_NGCTRL3, &noise_gate);
+ if (ret)
+ goto down;
+ 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 ||
+ (status & AW88461_FAULTS) ||
+ !aw88461_active(amp),
+ 2000, 20000);
+ if (ret) {
+ dev_err(amp->aw_dev.dev, "amplifier ready failed: %d, status %#x\n", ret, status);
+ goto down;
+ }
+ if (!aw88461_active(amp))
+ return aw88461_stop(amp);
+ if (status & AW88461_FAULTS)
+ return aw88461_recover(amp, status);
+ if ((status & ready) != ready)
+ return aw88461_stop(amp);
+ ret = regmap_update_bits(map, AW88461_SYSCTRL, AW88461_TXEN,
+ amp->profile_txen);
+ if (ret)
+ goto down;
+ ret = regmap_update_bits(map, AW88461_SYSCTRL,
+ AW88461_HMUTE | AW88461_ULS_HMUTE, 0);
+ if (ret)
+ goto down;
+ ret = aw88461_fade(amp, 1023,
+ min(amp->profile_volume + 1023 - amp->volume, 1023U), 100);
+ if (ret)
+ goto down;
+ return 0;
+down:
+ return aw88461_down(amp, ret);
+}
+
+/*
+ * Pick the Music profile. V1 ACF images are renumbered sequentially by
+ * aw_dev_create_prof_name_list_v1(), so the id is useless there and the name
+ * the library built for each entry has to be used instead.
+ */
+static int aw88461_music_profile(struct aw_device *aw_dev, u32 hdr_version)
+{
+ struct aw_prof_info *info = &aw_dev->prof_info;
+ unsigned int i;
+
+ if (hdr_version == AW88395_CFG_HDR_VER_V1) {
+ for (i = 0; i < info->count; i++) {
+ if (info->prof_name_list[i] &&
+ !strncasecmp(info->prof_name_list[i], "Music",
+ PROFILE_STR_MAX))
+ return i;
+ }
+ } else {
+ for (i = 0; i < info->count; i++) {
+ if (info->prof_desc[i].id == AW88395_PROFILE_MUSIC)
+ return i;
+ }
+ }
+ /* Single-profile images carry no usable name. */
+ if (info->count == 1)
+ return 0;
+ return -ENOENT;
+}
+
+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_cfg_hdr *hdr;
+ struct aw_sec_data_desc *regs = NULL;
+ const char *name;
+ unsigned int i, address, value;
+ int idx, 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;
+ hdr = (struct aw_cfg_hdr *)cfg->data;
+ idx = aw88461_music_profile(aw_dev, hdr->hdr_version);
+ if (idx < 0) {
+ ret = idx;
+ goto release;
+ }
+ regs = &aw_dev->prof_info.prof_desc[idx].sec_desc[AW88395_DATA_TYPE_REG];
+ if (!regs->len || regs->len % 4) {
+ ret = -EINVAL;
+ 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))) {
+ ret = -EINVAL;
+ goto release;
+ }
+ }
+ amp->seq = devm_kmemdup(aw_dev->dev, regs->data, regs->len, GFP_KERNEL);
+ if (!amp->seq) {
+ ret = -ENOMEM;
+ goto release;
+ }
+ amp->seq_len = regs->len;
+ ret = aw88461_apply_seq(amp);
+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, val, 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;
+ val = FIELD_PREP(GENMASK(7, 6), width) |
+ FIELD_PREP(GENMASK(5, 4), frame) | AW88461_I2SEN;
+ guard(mutex)(&->lock);
+ ret = regmap_update_bits(amp->aw_dev.regmap, AW88461_I2SCTRL1,
+ GENMASK(9, 0), val);
+ if (ret)
+ return aw88461_down(amp, ret);
+ amp->i2sctrl1 = val;
+ return 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->volume == volume)
+ return 0;
+ if (amp->powered) {
+ ret = aw88461_set_volume(amp, amp->profile_volume + 1023 - volume);
+ if (ret)
+ return aw88461_down(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;
+ /* Play at the profile level until userspace sets a volume. */
+ amp->volume = 1023;
+ 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 v2 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver
2026-11-30 23:47 ` [PATCH v2 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
@ 2026-11-30 23:57 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-30 23:57 UTC (permalink / raw)
To: Qianhui Xu; +Cc: linux-sound, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ASoC: aw88461: incomplete TXEN and volume reset in
aw88461_down()
--
commit 914e755a0639c9d9a327147970c1f3e4b660cca3
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 (PID 0x2308)
I2S speaker amplifier, reusing the AW88395 library for ACF firmware parsing
and profile loading.
> diff --git a/sound/soc/codecs/aw88461.c b/sound/soc/codecs/aw88461.c
> new file mode 100644
> index 0000000000000..e5fb31f318caf
> --- /dev/null
> +++ b/sound/soc/codecs/aw88461.c
> @@ -0,0 +1,645 @@
[ ... ]
> +/*
> + * Park the chip in a silent, powered-down state. The driver deliberately does
> + * not latch an error (and does not touch the profile loaded into the chip), so
> + * that the DAPM power-up event of the next playback can retry.
> + */
> +static int aw88461_down(struct aw88461 *amp, int error)
> +{
> + struct regmap *map = amp->aw_dev.regmap;
> +
> + amp->powered = false;
> + if (regmap_update_bits(map, AW88461_SYSCTRL,
> + AW88461_HMUTE | AW88461_ULS_HMUTE,
> + AW88461_HMUTE | AW88461_ULS_HMUTE))
> + dev_err(amp->aw_dev.dev, "failed to mute the amplifier\n");
> + if (regmap_update_bits(map, AW88461_SYSCTRL,
> + AW88461_AMPPD | AW88461_PWDN,
> + AW88461_AMPPD | AW88461_PWDN))
> + dev_err(amp->aw_dev.dev, "failed to power down the amplifier\n");
> + return error;
> +}
[Severity: Medium]
Should aw88461_down() also clear AW88461_TXEN in AW88461_SYSCTRL and
restore AW88461_VOLUME to 1023 in AW88461_SYSCTRL2?
If a regmap write fails after the amplifier is running (for example, in
aw88461_volume_put() or aw88461_stop()), aw88461_down() leaves
AW88461_TXEN enabled and AW88461_VOLUME at the active attenuation level.
On the next playback retry, aw88461_start() then brings the chip out of
AW88461_PWDN and AW88461_AMPPD with AW88461_TXEN already asserted instead
of following PWDN -> PLL lock -> AMPPD -> TXEN, and clears AW88461_HMUTE |
AW88461_ULS_HMUTE before aw88461_fade() resets the volume to 1023.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130234745.1063224-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 23:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 23:47 [PATCH v2 0/2] ASoC: aw88461: add the Awinic AW88461 speaker amplifier Qianhui Xu
2026-11-30 23:47 ` [PATCH v2 1/2] ASoC: dt-bindings: awinic,aw88395: add the AW88461 variant Qianhui Xu
2026-11-30 23:47 ` [PATCH v2 2/2] ASoC: codecs: aw88461: add the Awinic AW88461 speaker amplifier driver Qianhui Xu
2026-11-30 23:57 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox