Skip to content

Commit 18d8306

Browse files
John-Hsubroonie
authored andcommitted
ASoC: nau8825: add programmable biquad filter control
Add programmable biquad filter configuration control for user space. The filter is configurable for low pass filters, high pass filters, Notch filter, etc in the ADC and DAC path. Signed-off-by: John Hsu <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent ffd7250 commit 18d8306

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

sound/soc/codecs/nau8825.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ static bool nau8825_volatile_reg(struct device *dev, unsigned int reg)
217217
case NAU8825_REG_SARDOUT_RAM_STATUS:
218218
case NAU8825_REG_CHARGE_PUMP_INPUT_READ:
219219
case NAU8825_REG_GENERAL_STATUS:
220+
case NAU8825_REG_BIQ_CTRL ... NAU8825_REG_BIQ_COF10:
220221
return true;
221222
default:
222223
return false;
@@ -293,6 +294,54 @@ static int nau8825_output_dac_event(struct snd_soc_dapm_widget *w,
293294
return 0;
294295
}
295296

297+
static int nau8825_biq_coeff_get(struct snd_kcontrol *kcontrol,
298+
struct snd_ctl_elem_value *ucontrol)
299+
{
300+
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
301+
struct soc_bytes_ext *params = (void *)kcontrol->private_value;
302+
303+
if (!component->regmap)
304+
return -EINVAL;
305+
306+
regmap_raw_read(component->regmap, NAU8825_REG_BIQ_COF1,
307+
ucontrol->value.bytes.data, params->max);
308+
return 0;
309+
}
310+
311+
static int nau8825_biq_coeff_put(struct snd_kcontrol *kcontrol,
312+
struct snd_ctl_elem_value *ucontrol)
313+
{
314+
struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
315+
struct soc_bytes_ext *params = (void *)kcontrol->private_value;
316+
void *data;
317+
318+
if (!component->regmap)
319+
return -EINVAL;
320+
321+
data = kmemdup(ucontrol->value.bytes.data,
322+
params->max, GFP_KERNEL | GFP_DMA);
323+
if (!data)
324+
return -ENOMEM;
325+
326+
regmap_update_bits(component->regmap, NAU8825_REG_BIQ_CTRL,
327+
NAU8825_BIQ_WRT_EN, 0);
328+
regmap_raw_write(component->regmap, NAU8825_REG_BIQ_COF1,
329+
data, params->max);
330+
regmap_update_bits(component->regmap, NAU8825_REG_BIQ_CTRL,
331+
NAU8825_BIQ_WRT_EN, NAU8825_BIQ_WRT_EN);
332+
333+
kfree(data);
334+
return 0;
335+
}
336+
337+
static const char * const nau8825_biq_path[] = {
338+
"ADC", "DAC"
339+
};
340+
341+
static const struct soc_enum nau8825_biq_path_enum =
342+
SOC_ENUM_SINGLE(NAU8825_REG_BIQ_CTRL, NAU8825_BIQ_PATH_SFT,
343+
ARRAY_SIZE(nau8825_biq_path), nau8825_biq_path);
344+
296345
static const char * const nau8825_adc_decimation[] = {
297346
"32", "64", "128", "256"
298347
};
@@ -329,6 +378,10 @@ static const struct snd_kcontrol_new nau8825_controls[] = {
329378

330379
SOC_ENUM("ADC Decimation Rate", nau8825_adc_decimation_enum),
331380
SOC_ENUM("DAC Oversampling Rate", nau8825_dac_oversampl_enum),
381+
/* programmable biquad filter */
382+
SOC_ENUM("BIQ Path Select", nau8825_biq_path_enum),
383+
SND_SOC_BYTES_EXT("BIQ Coefficeints", 20,
384+
nau8825_biq_coeff_get, nau8825_biq_coeff_put),
332385
};
333386

334387
/* DAC Mux 0x33[9] and 0x34[9] */

sound/soc/codecs/nau8825.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@
231231
#define NAU8825_I2S_MS_MASTER (1 << NAU8825_I2S_MS_SFT)
232232
#define NAU8825_I2S_MS_SLAVE (0 << NAU8825_I2S_MS_SFT)
233233

234+
/* BIQ_CTRL (0x20) */
235+
#define NAU8825_BIQ_WRT_SFT 4
236+
#define NAU8825_BIQ_WRT_EN (1 << NAU8825_BIQ_WRT_SFT)
237+
#define NAU8825_BIQ_PATH_SFT 0
238+
#define NAU8825_BIQ_PATH_MASK (1 << NAU8825_BIQ_PATH_SFT)
239+
#define NAU8825_BIQ_PATH_ADC (0 << NAU8825_BIQ_PATH_SFT)
240+
#define NAU8825_BIQ_PATH_DAC (1 << NAU8825_BIQ_PATH_SFT)
241+
234242
/* ADC_RATE (0x2b) */
235243
#define NAU8825_ADC_SYNC_DOWN_SFT 0
236244
#define NAU8825_ADC_SYNC_DOWN_MASK 0x3

0 commit comments

Comments
 (0)