Linux Sound subsystem development
 help / color / mirror / Atom feed
* [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; 3+ 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] 3+ messages in thread

end of thread, other threads:[~2026-12-01  8:42 UTC | newest]

Thread overview: 3+ 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
2026-12-01  8:42   ` Alexey Charkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox