* [PATCH] ASoC: codecs: nau8822: add support for speaker gain boost setting
@ 2026-12-01 8:24 Alexey Charkov
2026-12-01 8:31 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Alexey Charkov @ 2026-12-01 8:24 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai
Cc: linux-sound, Alexey Charkov
The speaker amplifier can be supplied by a higher voltage than the rest of
the codec, namely up to 5V.
When the speaker supply voltage is above 3.6V, the speaker gain boost
setting should be enabled to prevent distortion on speaker and AUX pins.
Enable gain boost setting based on the reading of the VDDSPK supply
regulator's voltage.
Signed-off-by: Alexey Charkov <alchark@flipper.net>
---
sound/soc/codecs/nau8822.c | 19 ++++++++++++++++++-
sound/soc/codecs/nau8822.h | 17 ++++++++++++++++-
2 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c
index 17b8ee0ab22c..1e90e00c99f2 100644
--- a/sound/soc/codecs/nau8822.c
+++ b/sound/soc/codecs/nau8822.c
@@ -10,6 +10,7 @@
//
// Based on WM8974.c
+#include "linux/regulator/consumer.h"
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
@@ -1189,7 +1190,7 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
{
struct device *dev = &i2c->dev;
struct nau8822 *nau8822 = dev_get_platdata(dev);
- int ret, i;
+ int ret, i, vddspk;
if (!nau8822) {
nau8822 = devm_kzalloc_obj(dev, *nau8822);
@@ -1210,6 +1211,11 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
if (ret)
return dev_err_probe(dev, ret, "Failed to get regulators\n");
+ vddspk = regulator_get_voltage(nau8822->supplies[SUPPLY_VDDSPK].consumer);
+ if (vddspk < 0 && vddspk != -ENODEV)
+ return dev_err_probe(dev, vddspk,
+ "Failed to get VDDSPK voltage\n");
+
nau8822->regmap = devm_regmap_init_i2c(i2c, &nau8822_regmap_config);
if (IS_ERR(nau8822->regmap)) {
ret = PTR_ERR(nau8822->regmap);
@@ -1231,6 +1237,17 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
goto err_reg;
}
+ if (vddspk > 3600000) {
+ ret = regmap_update_bits(nau8822->regmap,
+ NAU8822_REG_OUTPUT_CONTROL,
+ NAU8822_SPKBST |
+ NAU8822_AUX2BST |
+ NAU8822_AUX1BST, 0x7);
+ if (ret != 0)
+ return dev_err_probe(dev, ret,
+ "Failed to update gain boost control\n");
+ }
+
ret = devm_snd_soc_register_component(dev, &soc_component_dev_nau8822,
&nau8822_dai, 1);
if (ret != 0) {
diff --git a/sound/soc/codecs/nau8822.h b/sound/soc/codecs/nau8822.h
index 24799c7b5931..cefc2c3feca2 100644
--- a/sound/soc/codecs/nau8822.h
+++ b/sound/soc/codecs/nau8822.h
@@ -196,6 +196,15 @@
#define NAU8822_RAUXSMUT 0x01
+/* NAU8822_REG_OUTPUT_CONTROL (0x31) */
+#define NAU8822_AOUTIMP (1 << 0)
+#define NAU8822_TSEN (1 << 1)
+#define NAU8822_SPKBST (1 << 2)
+#define NAU8822_AUX2BST (1 << 3)
+#define NAU8822_AUX1BST (1 << 4)
+#define NAU8822_RDACLMX (1 << 5)
+#define NAU8822_LDACLMX (1 << 6)
+
/* System Clock Source */
enum {
NAU8822_CLK_MCLK,
@@ -211,7 +220,13 @@ struct nau8822_pll {
int freq_out;
};
-#define NAU8822_NUM_SUPPLIES 4
+enum {
+ SUPPLY_VDDA = 0,
+ SUPPLY_VDDB,
+ SUPPLY_VDDC,
+ SUPPLY_VDDSPK,
+ NAU8822_NUM_SUPPLIES
+};
/* Codec Private Data */
struct nau8822 {
---
base-commit: 253f86660c1f882fbf554db5eaa34bc5d66dc7e8
change-id: 20261201-nau8822-gain-boost-63bee51cd4a1
Best regards,
--
Alexey Charkov <alchark@flipper.net>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ASoC: codecs: nau8822: add support for speaker gain boost setting
2026-12-01 8:24 [PATCH] ASoC: codecs: nau8822: add support for speaker gain boost setting Alexey Charkov
@ 2026-12-01 8:31 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-01 8:31 UTC (permalink / raw)
To: Alexey Charkov; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] ASoC: nau8822: unshifted value 0x7 in nau8822_i2c_probe() boost
update
- [High] ASoC: nau8822: probe failure in nau8822_i2c_probe() on dummy
VDDSPK supply
- [Medium] ASoC: nau8822: unbalanced regulator enable in
nau8822_i2c_probe() error path
- [Low] ASoC: nau8822: duplicate linux/regulator/consumer.h include in
nau8822.c
--
commit 7be433b1cfde07c405213d2c8857611f51145778
Author: Alexey Charkov <alchark@flipper.net>
ASoC: codecs: nau8822: add support for speaker gain boost setting
This commit queries the VDDSPK regulator voltage during probe and enables
the speaker and AUX gain boost bits when the supply exceeds 3.6V.
> diff --git a/sound/soc/codecs/nau8822.c b/sound/soc/codecs/nau8822.c
> index 17b8ee0ab22c3..1e90e00c99f22 100644
> --- a/sound/soc/codecs/nau8822.c
> +++ b/sound/soc/codecs/nau8822.c
> @@ -10,6 +10,7 @@
> //
> // Based on WM8974.c
>
> +#include "linux/regulator/consumer.h"
> #include <linux/module.h>
> #include <linux/moduleparam.h>
> #include <linux/kernel.h>
[Severity: Low]
<linux/regulator/consumer.h> is already included a few lines below, so this
duplicate include can be dropped.
> @@ -1189,7 +1190,7 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
> {
> struct device *dev = &i2c->dev;
> struct nau8822 *nau8822 = dev_get_platdata(dev);
> - int ret, i;
> + int ret, i, vddspk;
>
> if (!nau8822) {
> nau8822 = devm_kzalloc_obj(dev, *nau8822);
> @@ -1210,6 +1211,11 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
> if (ret)
> return dev_err_probe(dev, ret, "Failed to get regulators\n");
>
> + vddspk = regulator_get_voltage(nau8822->supplies[SUPPLY_VDDSPK].consumer);
> + if (vddspk < 0 && vddspk != -ENODEV)
> + return dev_err_probe(dev, vddspk,
> + "Failed to get VDDSPK voltage\n");
[Severity: High]
Does this cause nau8822_i2c_probe() to fail with -EINVAL when vddspk-supply
is omitted from the device tree?
devm_regulator_bulk_get() substitutes the dummy regulator when an optional
supply is absent, and regulator_get_voltage() returns -EINVAL (not -ENODEV)
for regulators without voltage query operations or a fixed voltage.
> nau8822->regmap = devm_regmap_init_i2c(i2c, &nau8822_regmap_config);
> if (IS_ERR(nau8822->regmap)) {
> ret = PTR_ERR(nau8822->regmap);
> @@ -1231,6 +1237,17 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
> goto err_reg;
> }
>
> + if (vddspk > 3600000) {
> + ret = regmap_update_bits(nau8822->regmap,
> + NAU8822_REG_OUTPUT_CONTROL,
> + NAU8822_SPKBST |
> + NAU8822_AUX2BST |
> + NAU8822_AUX1BST, 0x7);
[Severity: High]
Does passing 0x7 to regmap_update_bits() leave NAU8822_AUX2BST and
NAU8822_AUX1BST cleared?
NAU8822_SPKBST, NAU8822_AUX2BST, and NAU8822_AUX1BST are defined at bits
2..4 (mask 0x1c), and regmap_update_bits() does not shift val to the mask
position, so (0x7 & 0x1c) only sets bit 2 (NAU8822_SPKBST). Passing the
combined bitmask as val (or using regmap_set_bits()) would set all three
bits.
> + if (ret != 0)
> + return dev_err_probe(dev, ret,
> + "Failed to update gain boost control\n");
> + }
[Severity: Medium]
Does this error return leak the regulator enable reference counts from
regulator_bulk_enable() earlier in nau8822_i2c_probe()? Jumping to err_reg
would disable the bulk supplies on failure.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261201-nau8822-gain-boost-v1-1-963846584511@flipper.net?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-01 8:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 8:24 [PATCH] ASoC: codecs: nau8822: add support for speaker gain boost setting Alexey Charkov
2026-12-01 8:31 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox