Skip to content

Commit c32805c

Browse files
committed
ASoC: codecs: nau8822: add support for speaker gain boost setting
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>
1 parent 1309c21 commit c32805c

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

sound/soc/codecs/nau8822.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
// Based on WM8974.c
1212

13+
#include "linux/regulator/consumer.h"
1314
#include <linux/module.h>
1415
#include <linux/moduleparam.h>
1516
#include <linux/kernel.h>
@@ -1168,7 +1169,7 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
11681169
{
11691170
struct device *dev = &i2c->dev;
11701171
struct nau8822 *nau8822 = dev_get_platdata(dev);
1171-
int ret, i;
1172+
int ret, i, vddspk;
11721173

11731174
if (!nau8822) {
11741175
nau8822 = devm_kzalloc(dev, sizeof(*nau8822), GFP_KERNEL);
@@ -1189,6 +1190,11 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
11891190
if (ret)
11901191
return dev_err_probe(dev, ret, "Failed to get regulators\n");
11911192

1193+
vddspk = regulator_get_voltage(nau8822->supplies[SUPPLY_VDDSPK].consumer);
1194+
if (vddspk < 0 && vddspk != -ENODEV)
1195+
return dev_err_probe(dev, vddspk,
1196+
"Failed to get VDDSPK voltage\n");
1197+
11921198
nau8822->regmap = devm_regmap_init_i2c(i2c, &nau8822_regmap_config);
11931199
if (IS_ERR(nau8822->regmap)) {
11941200
ret = PTR_ERR(nau8822->regmap);
@@ -1210,6 +1216,17 @@ static int nau8822_i2c_probe(struct i2c_client *i2c)
12101216
goto err_reg;
12111217
}
12121218

1219+
if (vddspk > 3600000) {
1220+
ret = regmap_update_bits(nau8822->regmap,
1221+
NAU8822_REG_OUTPUT_CONTROL,
1222+
NAU8822_SPKBST |
1223+
NAU8822_AUX2BST |
1224+
NAU8822_AUX1BST, 0x7);
1225+
if (ret != 0)
1226+
return dev_err_probe(dev, ret,
1227+
"Failed to update gain boost control\n");
1228+
}
1229+
12131230
ret = devm_snd_soc_register_component(dev, &soc_component_dev_nau8822,
12141231
&nau8822_dai, 1);
12151232
if (ret != 0) {

sound/soc/codecs/nau8822.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@
196196

197197
#define NAU8822_RAUXSMUT 0x01
198198

199+
/* NAU8822_REG_OUTPUT_CONTROL (0x31) */
200+
#define NAU8822_AOUTIMP (1 << 0)
201+
#define NAU8822_TSEN (1 << 1)
202+
#define NAU8822_SPKBST (1 << 2)
203+
#define NAU8822_AUX2BST (1 << 3)
204+
#define NAU8822_AUX1BST (1 << 4)
205+
#define NAU8822_RDACLMX (1 << 5)
206+
#define NAU8822_LDACLMX (1 << 6)
207+
199208
/* System Clock Source */
200209
enum {
201210
NAU8822_CLK_MCLK,
@@ -211,7 +220,13 @@ struct nau8822_pll {
211220
int freq_out;
212221
};
213222

214-
#define NAU8822_NUM_SUPPLIES 4
223+
enum {
224+
SUPPLY_VDDA = 0,
225+
SUPPLY_VDDB,
226+
SUPPLY_VDDC,
227+
SUPPLY_VDDSPK,
228+
NAU8822_NUM_SUPPLIES
229+
};
215230

216231
/* Codec Private Data */
217232
struct nau8822 {

0 commit comments

Comments
 (0)