Skip to contentSkip to conversation

ASoC: Add support for DA7219 audio codec

PATCH Superseded Adam Thomson 2 participants 12 messages Sep 17, 2015 – Oct 2, 2015

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: Add support for DA7219 audio codec

This patch set adds support for the DA7219 audio codec with built-in advanced accessory detection functionality. Patch set includes codec driver, associated DT bindings documentation and MAINTAINERS file updates to cover new bindings.

Adam Thomson (3):
ASoC: codecs: Add da7219 codec driver
ASoC: da7219: Add bindings documentation for DA7219 audio codec
MAINTAINERS: da7219: Add entry to cover DA7219 bindings document

 Documentation/devicetree/bindings/sound/da7219.txt |  106 ++
 MAINTAINERS                                        |    1 +
 include/sound/da7219-aad.h                         |   99 ++
 include/sound/da7219.h                             |   76 +
 sound/soc/codecs/Kconfig                           |    4 +
 sound/soc/codecs/Makefile                          |    2 +
 sound/soc/codecs/da7219-aad.c                      |  800 +++++++++
 sound/soc/codecs/da7219-aad.h                      |  209 +++
 sound/soc/codecs/da7219.c                          | 1877 ++++++++++++++++++++
 sound/soc/codecs/da7219.h                          |  807 +++++++++
 10 files changed, 3981 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/da7219.txt
 create mode 100644 include/sound/da7219-aad.h
 create mode 100644 include/sound/da7219.h
 create mode 100644 sound/soc/codecs/da7219-aad.c
 create mode 100644 sound/soc/codecs/da7219-aad.h
 create mode 100644 sound/soc/codecs/da7219.c
 create mode 100644 sound/soc/codecs/da7219.h

--
1.9.3

#1 lore raw

PATCH 1/3 ASoC: codecs: Add da7219 codec driver

This adds support for the DA7219 audio codec with built-in advanced accessory detect features.

---
 include/sound/da7219-aad.h    |   99 +++
 include/sound/da7219.h        |   76 ++
 sound/soc/codecs/Kconfig      |    4 +
 sound/soc/codecs/Makefile     |    2 +
 sound/soc/codecs/da7219-aad.c |  800 ++++++++++++++++++
 sound/soc/codecs/da7219-aad.h |  209 +++++
 sound/soc/codecs/da7219.c     | 1877 +++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/da7219.h     |  807 ++++++++++++++++++
 8 files changed, 3874 insertions(+)
 create mode 100644 include/sound/da7219-aad.h
 create mode 100644 include/sound/da7219.h
 create mode 100644 sound/soc/codecs/da7219-aad.c
 create mode 100644 sound/soc/codecs/da7219-aad.h
 create mode 100644 sound/soc/codecs/da7219.c
 create mode 100644 sound/soc/codecs/da7219.h
include/sound/da7219-aad.h new file +99 -0
new file mode 100644
index 0000000..17802fb
@@ -0,0 +1,99 @@
+/*
+ * da7219-aad.h - DA7322 ASoC Codec AAD Driver Platform Data
+ *
+ * Copyright (c) 2015 Dialog Semiconductor Ltd.
+ *
+ * Author: Adam Thomson <[email protected]>
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#ifndef __DA7219_AAD_PDATA_H
+#define __DA7219_AAD_PDATA_H
+
+enum da7219_aad_micbias_pulse_lvl {
+	DA7219_AAD_MICBIAS_PULSE_LVL_OFF = 0,
+	DA7219_AAD_MICBIAS_PULSE_LVL_2_8V = 6,
+	DA7219_AAD_MICBIAS_PULSE_LVL_2_9V,
+};
+
+enum da7219_aad_btn_cfg {
+	DA7219_AAD_BTN_CFG_2MS = 1,
+	DA7219_AAD_BTN_CFG_5MS,
+	DA7219_AAD_BTN_CFG_10MS,
+	DA7219_AAD_BTN_CFG_50MS,
+	DA7219_AAD_BTN_CFG_100MS,
+	DA7219_AAD_BTN_CFG_200MS,
+	DA7219_AAD_BTN_CFG_500MS,
+};
+
+enum da7219_aad_mic_det_thr {
+	DA7219_AAD_MIC_DET_THR_200_OHMS = 0,
+	DA7219_AAD_MIC_DET_THR_500_OHMS,
+	DA7219_AAD_MIC_DET_THR_750_OHMS,
+	DA7219_AAD_MIC_DET_THR_1000_OHMS,
+};
+
+enum da7219_aad_jack_ins_deb {
+	DA7219_AAD_JACK_INS_DEB_5MS = 0,
+	DA7219_AAD_JACK_INS_DEB_10MS,
+	DA7219_AAD_JACK_INS_DEB_20MS,
+	DA7219_AAD_JACK_INS_DEB_50MS,
+	DA7219_AAD_JACK_INS_DEB_100MS,
+	DA7219_AAD_JACK_INS_DEB_200MS,
+	DA7219_AAD_JACK_INS_DEB_500MS,
+	DA7219_AAD_JACK_INS_DEB_1S,
+};
+
+enum da7219_aad_jack_det_rate {
+	DA7219_AAD_JACK_DET_RATE_32_64MS = 0,
+	DA7219_AAD_JACK_DET_RATE_64_128MS,
+	DA7219_AAD_JACK_DET_RATE_128_256MS,
+	DA7219_AAD_JACK_DET_RATE_256_512MS,
+};
+
+enum da7219_aad_jack_rem_deb {
+	DA7219_AAD_JACK_REM_DEB_1MS = 0,
+	DA7219_AAD_JACK_REM_DEB_5MS,
+	DA7219_AAD_JACK_REM_DEB_10MS,
+	DA7219_AAD_JACK_REM_DEB_20MS,
+};
+
+enum da7219_aad_btn_avg {
+	DA7219_AAD_BTN_AVG_1 = 0,
+	DA7219_AAD_BTN_AVG_2,
+	DA7219_AAD_BTN_AVG_4,
+	DA7219_AAD_BTN_AVG_8,
+};
+
+enum da7219_aad_adc_1bit_rpt {
+	DA7219_AAD_ADC_1BIT_RPT_1 = 0,
+	DA7219_AAD_ADC_1BIT_RPT_2,
+	DA7219_AAD_ADC_1BIT_RPT_4,
+	DA7219_AAD_ADC_1BIT_RPT_8,
+};
+
+struct da7219_aad_pdata {
+	int irq;
+
+	enum da7219_aad_micbias_pulse_lvl micbias_pulse_lvl;
+	u32 micbias_pulse_time;
+	enum da7219_aad_btn_cfg btn_cfg;
+	enum da7219_aad_mic_det_thr mic_det_thr;
+	enum da7219_aad_jack_ins_deb jack_ins_deb;
+	enum da7219_aad_jack_det_rate jack_det_rate;
+	enum da7219_aad_jack_rem_deb jack_rem_deb;
+
+	u8 a_d_btn_thr;
+	u8 d_b_btn_thr;
+	u8 b_c_btn_thr;
+	u8 c_mic_btn_thr;
+
+	enum da7219_aad_btn_avg btn_avg;
+	enum da7219_aad_adc_1bit_rpt adc_1bit_rpt;
+};
+
+#endif /* __DA7219_AAD_PDATA_H */
include/sound/da7219.h new file +76 -0

76 lines not on this page · raw message

sound/soc/codecs/Kconfig +4 -0
index 0c9733e..c9a895c 100644
@@ -57,6 +57,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_CX20442 if TTY
 	select SND_SOC_DA7210 if SND_SOC_I2C_AND_SPI
 	select SND_SOC_DA7213 if I2C
+	select SND_SOC_DA7219 if I2C
 	select SND_SOC_DA732X if I2C
 	select SND_SOC_DA9055 if I2C
 	select SND_SOC_DMIC
@@ -430,6 +431,9 @@ config SND_SOC_DA7210
 config SND_SOC_DA7213
         tristate
 
+config SND_SOC_DA7219
+        tristate
+
 config SND_SOC_DA732X
         tristate
 
sound/soc/codecs/Makefile +2 -0
index 4a32077..eb10a34 100644
@@ -49,6 +49,7 @@ snd-soc-cs4349-objs := cs4349.o
 snd-soc-cx20442-objs := cx20442.o
 snd-soc-da7210-objs := da7210.o
 snd-soc-da7213-objs := da7213.o
+snd-soc-da7219-objs := da7219.o da7219-aad.o
 snd-soc-da732x-objs := da732x.o
 snd-soc-da9055-objs := da9055.o
 snd-soc-bt-sco-objs := bt-sco.o
@@ -241,6 +242,7 @@ obj-$(CONFIG_SND_SOC_CS4349)	+= snd-soc-cs4349.o
 obj-$(CONFIG_SND_SOC_CX20442)	+= snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_DA7210)	+= snd-soc-da7210.o
 obj-$(CONFIG_SND_SOC_DA7213)	+= snd-soc-da7213.o
+obj-$(CONFIG_SND_SOC_DA7219)	+= snd-soc-da7219.o
 obj-$(CONFIG_SND_SOC_DA732X)	+= snd-soc-da732x.o
 obj-$(CONFIG_SND_SOC_DA9055)	+= snd-soc-da9055.o
 obj-$(CONFIG_SND_SOC_BT_SCO)	+= snd-soc-bt-sco.o
sound/soc/codecs/da7219-aad.c new file +800 -0

800 lines not on this page · raw message

sound/soc/codecs/da7219-aad.h new file +209 -0

209 lines not on this page · raw message

sound/soc/codecs/da7219.c new file +1877 -0

1,786 lines not on this page · raw message

sound/soc/codecs/da7219.h new file +807 -0

807 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.3

Part of the diff is not shown here. View the raw message.

maintainer
#2 lore raw

Re: [PATCH 1/3] ASoC: codecs: Add da7219 codec driver

sound/soc/codecs/da7219-aad.c line 79

Quoted 5 lines · Adam Thomson
sound/soc/codecs/da7219-aad.c new file +5 -0
+	do {
+		statusa = snd_soc_read(codec, DA7219_ACCDET_STATUS_A);
+		if (statusa & DA7219_MICBIAS_UP_STS_MASK)
+			micbias_up = true;
+	} while (!micbias_up);

This could go into an inifinite loop.

Quoted 6 lines
sound/soc/codecs/da7219-aad.c new file +6 -0
+static void da7219_aad_hptest_work(struct work_struct *work)
+{
+	struct da7219_aad_priv *da7219_aad =
+		container_of(work, struct da7219_aad_priv, hptest_work);
+	struct snd_soc_codec *codec = da7219_aad->codec;
+	struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec);

sound/soc/codecs/da7219-aad.c line 116

Quoted 10 lines
sound/soc/codecs/da7219-aad.c new file +10 -0
+
+	u8 tonegen_cfg1, tonegen_cfg2, tonegen_onper;
+	u16 tonegen_freq1, tonegen_freq_hptest;
+	u8 hpl_gain, hpr_gain, dacl_gain, dacr_gain, dac_filters1, dac_filters4;
+	u8 dac_filters5, cp_ctrl, routing_dac, dacl_ctrl, dacr_ctrl;
+	u8 mixoutl_sel, mixoutr_sel, st_outfilt_1l, st_outfilt_1r;
+	u8 mixoutl_ctrl, mixoutr_ctrl, hpl_ctrl, hpr_ctrl, accdet_cfg8;
+	int report = 0;
+
+	/* Save current settings */

This is obviously a massive reconfiguration of the device. I'm not seeing anything here which prevents userspace coming in and change the configuration while we're in this function, that would obviously have serious issues.

I'm also wondering if this might be more elegantly implemented by going into cache bypass mode, doing the test and then using a cache resync to restore the initial configuration. That will at least avoid issues with updates adding a new register but not modifying it.

sound/soc/codecs/da7219-aad.c line 327

Quoted 7 lines
sound/soc/codecs/da7219-aad.c new file +7 -0
+			if (statusa & DA7219_JACK_TYPE_STS_MASK) {
+				report |= SND_JACK_HEADSET;
+				mask |=	SND_JACK_HEADSET | SND_JACK_LINEOUT;
+				schedule_work(&da7219_aad->btn_det_work);
+			} else {
+				schedule_work(&da7219_aad->hptest_work);
+			}

Why are we scheduling work - we're already in thread context?

sound/soc/codecs/da7219-aad.c line 362

Quoted 5 lines
sound/soc/codecs/da7219-aad.c new file +5 -0
+			/* Un-drive headphones/lineout */
+			snd_soc_update_bits(codec, DA7219_HP_R_CTRL,
+					    DA7219_HP_R_AMP_OE_MASK, 0);
+			snd_soc_update_bits(codec, DA7219_HP_L_CTRL,
+					    DA7219_HP_L_AMP_OE_MASK, 0);

This looks like DAPM?

Quoted 11 lines
sound/soc/codecs/da7219-aad.c new file +11 -0
+static enum da7219_aad_jack_ins_deb da7219_aad_of_jack_ins_deb(u32 val)
+{
+	switch (val) {
+	case 5:
+		return DA7219_AAD_JACK_INS_DEB_5MS;
+	case 10:
+		return DA7219_AAD_JACK_INS_DEB_10MS;
+	case 20:
+		return DA7219_AAD_JACK_INS_DEB_20MS;
+	case 50:
+		return DA7219_AAD_JACK_INS_DEB_50MS;

sound/soc/codecs/da7219-aad.c line 457

Quoted 10 lines
sound/soc/codecs/da7219-aad.c new file +10 -0
+	case 100:
+		return DA7219_AAD_JACK_INS_DEB_100MS;
+	case 200:
+		return DA7219_AAD_JACK_INS_DEB_200MS;
+	case 500:
+		return DA7219_AAD_JACK_INS_DEB_500MS;
+	case 1000:
+		return DA7219_AAD_JACK_INS_DEB_1S;
+	default:
+		return DA7219_AAD_JACK_INS_DEB_20MS;

This isn't an error?

sound/soc/codecs/da7219.c line 117

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+/* Input/Output Enums */
+static const char * const da7219_gain_ramp_rate_txt[] = {
+	"nominal rate * 8", "nominal rate", "nominal rate / 8",
+	"nominal rate / 16"
+};

The ALSA ABI generally capitalises words.

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+/* ToneGen */
+static int da7219_tonegen_freq_get(struct snd_kcontrol *kcontrol,
+				   struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
+	struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec);
+	struct soc_mixer_control *mixer_ctrl =

sound/soc/codecs/da7219.c line 340

Quoted 10 lines
sound/soc/codecs/da7219.c new file +10 -0
+		(struct soc_mixer_control *) kcontrol->private_value;
+	unsigned int reg = mixer_ctrl->reg;
+	u16 val;
+	int ret;
+
+	ret = regmap_bulk_read(da7219->regmap, reg, &val, sizeof(val));
+	if (ret)
+		return ret;
+
+	ucontrol->value.integer.value[0] = le16_to_cpu(val);

This is *weird*. We do a bulk read for a single register using an API that returns CPU endian data then make it CPU endian (without any annotations on variables...). Why not use regmap_read()? Why swap? Why not use raw I/O?

Quoted 17 lines
sound/soc/codecs/da7219.c new file +17 -0
+static int da7219_hpf_put(struct snd_kcontrol *kcontrol,
+			  struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
+	struct soc_enum *enum_ctrl = (struct soc_enum *)kcontrol->private_value;
+	unsigned int reg = enum_ctrl->reg;
+	unsigned int sel = ucontrol->value.integer.value[0];
+	unsigned int bits;
+
+	switch (sel) {
+	case DA7219_HPF_MODE_DISABLED:
+		bits = DA7219_HPF_DISABLED;
+		break;
+	case DA7219_HPF_MODE_AUDIO:
+		bits = DA7219_HPF_AUDIO_EN;
+		break;
+	case DA7219_HPF_MODE_VOICE:

sound/soc/codecs/da7219.c line 387

Quoted 10 lines
sound/soc/codecs/da7219.c new file +10 -0
+		bits = DA7219_HPF_VOICE_EN;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	snd_soc_update_bits(codec, reg, DA7219_HPF_MODE_MASK, bits);
+
+	return 0;
+}

This looks like a standard enumeration with a simple mapping to the register map?

sound/soc/codecs/da7219.c line 454

Quoted 12 lines
sound/soc/codecs/da7219.c new file +12 -0
+
+	/* ADCs */
+	SOC_SINGLE_TLV("ADC Volume", DA7219_ADC_L_GAIN,
+		       DA7219_ADC_L_DIGITAL_GAIN_SHIFT,
+		       DA7219_ADC_L_DIGITAL_GAIN_MAX, DA7219_NO_INVERT,
+		       da7219_adc_dig_gain_tlv),
+	SOC_SINGLE("ADC Switch", DA7219_ADC_L_CTRL,
+		   DA7219_ADC_L_MUTE_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		   DA7219_INVERT),
+	SOC_SINGLE("ADC Gain Ramp Switch", DA7219_ADC_L_CTRL,
+		   DA7219_ADC_L_RAMP_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		   DA7219_NO_INVERT),

Capture Digital rather than ADC.

Quoted 4 lines
sound/soc/codecs/da7219.c new file +4 -0
+	SOC_SINGLE_TLV("ALC Max Attenuation", DA7219_ALC_GAIN_LIMITS,
+		       DA7219_ALC_ATTEN_MAX_SHIFT, DA7219_ALC_ATTEN_GAIN_MAX,
+		       DA7219_NO_INVERT, da7219_alc_gain_tlv),
+	SOC_SINGLE_TLV("ALC Max Gain", DA7219_ALC_GAIN_LIMITS,

sound/soc/codecs/da7219.c line 484

Quoted 10 lines
sound/soc/codecs/da7219.c new file +10 -0
+		       DA7219_ALC_GAIN_MAX_SHIFT, DA7219_ALC_ATTEN_GAIN_MAX,
+		       DA7219_NO_INVERT, da7219_alc_gain_tlv),
+	SOC_SINGLE_RANGE_TLV("ALC Min Analog Gain", DA7219_ALC_ANA_GAIN_LIMITS,
+			     DA7219_ALC_ANA_GAIN_MIN_SHIFT,
+			     DA7219_ALC_ANA_GAIN_MIN, DA7219_ALC_ANA_GAIN_MAX,
+			     DA7219_NO_INVERT, da7219_alc_ana_gain_tlv),
+	SOC_SINGLE_RANGE_TLV("ALC Max Analog Gain", DA7219_ALC_ANA_GAIN_LIMITS,
+			     DA7219_ALC_ANA_GAIN_MAX_SHIFT,
+			     DA7219_ALC_ANA_GAIN_MIN, DA7219_ALC_ANA_GAIN_MAX,
+			     DA7219_NO_INVERT, da7219_alc_ana_gain_tlv),

Volume not Gain.

sound/soc/codecs/da7219.c line 513

Quoted 3 lines
sound/soc/codecs/da7219.c new file +3 -0
+	SOC_SINGLE("ToneGen DTMF Key", DA7219_TONE_GEN_CFG1,
+		   DA7219_DTMF_REG_SHIFT, DA7219_DTMF_REG_MAX,
+		   DA7219_NO_INVERT),

Should this be an enumeration with the DTMF digits in it (# and * aren't numbers)?

sound/soc/codecs/da7219.c line 587

Quoted 11 lines
sound/soc/codecs/da7219.c new file +11 -0
+	/* DACs */
+	SOC_DOUBLE_R_TLV("DAC Volume", DA7219_DAC_L_GAIN, DA7219_DAC_R_GAIN,
+			 DA7219_DAC_L_DIGITAL_GAIN_SHIFT,
+			 DA7219_DAC_DIGITAL_GAIN_MAX, DA7219_NO_INVERT,
+			 da7219_dac_dig_gain_tlv),
+	SOC_DOUBLE_R("DAC Switch", DA7219_DAC_L_CTRL, DA7219_DAC_R_CTRL,
+		     DA7219_DAC_L_MUTE_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		     DA7219_INVERT),
+	SOC_DOUBLE_R("DAC Gain Ramp Switch", DA7219_DAC_L_CTRL,
+		     DA7219_DAC_R_CTRL, DA7219_DAC_L_RAMP_EN_SHIFT,
+		     DA7219_SWITCH_EN_MAX, DA7219_NO_INVERT),

All the DAC controls should probably be Playback Digital instead.

sound/soc/codecs/da7219.c line 948

Quoted 9 lines
sound/soc/codecs/da7219.c new file +9 -0
+
+static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+				 int clk_id, unsigned int freq, int dir)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec);
+
+	if (da7219->mclk_rate == freq)
+		return 0;

Given that we also have source selection is this safe - should we also be checking the source?

sound/soc/codecs/da7219.c line 974

Quoted 4 lines
sound/soc/codecs/da7219.c new file +4 -0
+	if (da7219->mclk) {
+		freq = clk_round_rate(da7219->mclk, freq);
+		clk_set_rate(da7219->mclk, freq);
+	}

Missing error checking.

sound/soc/codecs/da7219.c line 1464

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+			/* Internal LDO */
+			if (da7219->use_int_ldo)
+				snd_soc_update_bits(codec, DA7219_LDO_CTRL,
+						    DA7219_LDO_EN_MASK,
+						    DA7219_LDO_EN_MASK);

If there is an option to use an external supply I would expect to see the regulator API used to discover the external LDO (and ideally also to configure the integrated LDO). If the driver works outside the frameworks then it is likely this will lead to integration issues later on.

Review

Quoted 2 lines
(quoted diff) +2 -0
+		/* Internal LDO */
+		da7219->use_int_ldo = pdata->use_internal_ldo;

This is likely to lead to surprises for example...

sound/soc/codecs/da7219.c line 1582

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+	/* Check if MCLK provided, if not the clock is NULL */
+	da7219->mclk = devm_clk_get(codec->dev, "mclk");
+	if (IS_ERR(da7219->mclk)) {
+		if (PTR_ERR(da7219->mclk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		da7219->mclk = NULL;
+	}

This should specifically look for the error code that corresponds to a clock not being mapped and only continue silently in that case rather than silently accepting all failures to obtain a clock - if we silently accept all failures that will mean that actual errors will be ignored.

sound/soc/codecs/da7219.c line 1594

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+	/*
+	 * There are multiple control bits for the input mixer.
+	 * The following can be enabled now as it's not power related.
+	 */
+	snd_soc_update_bits(codec, DA7219_MIXIN_L_CTRL,
+			    DA7219_MIXIN_L_MIX_EN_MASK,
+			    DA7219_MIXIN_L_MIX_EN_MASK);

So the chip designers just put these in for randomness? Fun. It'd be more idiomatic to do something like making these supply widgets so they're controlled via DAPM even if they don't matter much.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	else if (device_may_wakeup(codec->dev))
+		disable_irq_wake(da7219->aad->irq);

You can use dev_pm_set_wake_irq() and skip having to manage this stuff explicitly in the driver.

#3 lore raw

RE: [PATCH 1/3] ASoC: codecs: Add da7219 codec driver

Quoted 8 lines · Mark Brown

sound/soc/codecs/da7219-aad.c line 79

Quoted 5 lines
sound/soc/codecs/da7219-aad.c new file +5 -0
+	do {
+		statusa = snd_soc_read(codec, DA7219_ACCDET_STATUS_A);
+		if (statusa & DA7219_MICBIAS_UP_STS_MASK)
+			micbias_up = true;
+	} while (!micbias_up);

This could go into an inifinite loop.

Only if the HW is unresponsive. However, it's probably better to add a timeout and some debug in the unlikely event that does happen.

Quoted 22 lines
Quoted 6 lines
sound/soc/codecs/da7219-aad.c new file +6 -0
+static void da7219_aad_hptest_work(struct work_struct *work)
+{
+	struct da7219_aad_priv *da7219_aad =
+		container_of(work, struct da7219_aad_priv, hptest_work);
+	struct snd_soc_codec *codec = da7219_aad->codec;
+	struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec);

sound/soc/codecs/da7219-aad.c line 116

Quoted 10 lines
sound/soc/codecs/da7219-aad.c new file +10 -0
+
+	u8 tonegen_cfg1, tonegen_cfg2, tonegen_onper;
+	u16 tonegen_freq1, tonegen_freq_hptest;
+	u8 hpl_gain, hpr_gain, dacl_gain, dacr_gain, dac_filters1, dac_filters4;
+	u8 dac_filters5, cp_ctrl, routing_dac, dacl_ctrl, dacr_ctrl;
+	u8 mixoutl_sel, mixoutr_sel, st_outfilt_1l, st_outfilt_1r;
+	u8 mixoutl_ctrl, mixoutr_ctrl, hpl_ctrl, hpr_ctrl, accdet_cfg8;
+	int report = 0;
+
+	/* Save current settings */

This is obviously a massive reconfiguration of the device. I'm not seeing anything here which prevents userspace coming in and change the configuration while we're in this function, that would obviously have serious issues.

Quoted 4 lines

I'm also wondering if this might be more elegantly implemented by going into cache bypass mode, doing the test and then using a cache resync to restore the initial configuration. That will at least avoid issues with updates adding a new register but not modifying it.

In a system scenario the likelihood of that happening is small as you cannot use the mic or headphones until they've been inserted. The system is only likely to act after the jack insertion events have occurred. However, it would be better to prevent any chance of concurrent access. The problem is how best to lock the Kcontrols whilst the test procedure in progress. At the moment the only way I can see is to add explicit control set() functions which would use a lock that can also be controlled by the HP test code. Does this make sense to you or do you know of a simpler method? Obviously dapm has function to lock as required.

For the cache resync idea, in terms of code, it will look cleaner, but you are talking about 4 to 5 times the number of I2C accesses to the device, to restore configuration. Does that not seem like a bit too much overhead?

Quoted 10 lines

sound/soc/codecs/da7219-aad.c

Quoted 3 lines
sound/soc/codecs/da7219-aad.c new file +3 -0
+			if (statusa & DA7219_JACK_TYPE_STS_MASK) {
+				report |= SND_JACK_HEADSET;
+				mask |=	SND_JACK_HEADSET |

SND_JACK_LINEOUT;

sound/soc/codecs/da7219-aad.c line 327

Quoted 4 lines
sound/soc/codecs/da7219-aad.c new file +4 -0
+				schedule_work(&da7219_aad->btn_det_work);
+			} else {
+				schedule_work(&da7219_aad->hptest_work);
+			}

Why are we scheduling work - we're already in thread context?

hptest will take some time to complete (over 100ms), and in that time it's plausible that a user could remove the jack. If we deal with this in the IRQ thread, we won't be aware of jack removal during the process, and will send a report regardless, which will almost definitely be incorrect, and unnecessary. By spawning off work, it allows the removal to be dealt with if the hptest work procedure is currently in process, and then we can avoid sending incorrect jack reports at the end.

For button detection, for certain mics it's required to pulse the micbias to a higher voltage, for a defined period of time, to enable the mic. Again this period is likely to take maybe 100ms, depending on the mic, so it made far more sense to me to do this outside of the IRQ thread. However, if you have a better proposal for this then am happy to take it on board.

Quoted 7 lines

sound/soc/codecs/da7219-aad.c line 362

Quoted 5 lines
sound/soc/codecs/da7219-aad.c new file +5 -0
+			/* Un-drive headphones/lineout */
+			snd_soc_update_bits(codec, DA7219_HP_R_CTRL,
+					    DA7219_HP_R_AMP_OE_MASK, 0);
+			snd_soc_update_bits(codec, DA7219_HP_L_CTRL,
+					    DA7219_HP_L_AMP_OE_MASK, 0);

This looks like DAPM?

The control of driving the headphones or making them high impedance is handled in the AAD code because we cannot have the headphones driven before a jack is inserted as it will affect the pole detection. Adding it to DAPM seemed like it would cause more problems in terms of controlling when it would and wouldn't be enabled.

Quoted 15 lines
Quoted 15 lines
sound/soc/codecs/da7219-aad.c new file +15 -0
+static enum da7219_aad_jack_ins_deb da7219_aad_of_jack_ins_deb(u32 val)
+{
+	switch (val) {
+	case 5:
+		return DA7219_AAD_JACK_INS_DEB_5MS;
+	case 10:
+		return DA7219_AAD_JACK_INS_DEB_10MS;
+	case 20:
+		return DA7219_AAD_JACK_INS_DEB_20MS;
+	case 50:
+		return DA7219_AAD_JACK_INS_DEB_50MS;
+	case 100:
+		return DA7219_AAD_JACK_INS_DEB_100MS;
+	case 200:
+		return DA7219_AAD_JACK_INS_DEB_200MS;
Quoted 8 lines

sound/soc/codecs/da7219-aad.c line 457

Quoted 6 lines
sound/soc/codecs/da7219-aad.c new file +6 -0
+	case 500:
+		return DA7219_AAD_JACK_INS_DEB_500MS;
+	case 1000:
+		return DA7219_AAD_JACK_INS_DEB_1S;
+	default:
+		return DA7219_AAD_JACK_INS_DEB_20MS;

This isn't an error?

Opted for HW default in case of invalid values provided. Maybe a dev_warn() would be useful though to indicate this is the case?

Quoted 7 lines

sound/soc/codecs/da7219.c line 117

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+/* Input/Output Enums */
+static const char * const da7219_gain_ramp_rate_txt[] = {
+	"nominal rate * 8", "nominal rate", "nominal rate / 8",
+	"nominal rate / 16"
+};

The ALSA ABI generally capitalises words.

Ok, no problem. Will adjust accordingly.

Quoted 14 lines
Quoted 14 lines
sound/soc/codecs/da7219.c new file +14 -0
+/* ToneGen */
+static int da7219_tonegen_freq_get(struct snd_kcontrol *kcontrol,
+				   struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
+	struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec);
+	struct soc_mixer_control *mixer_ctrl =
+		(struct soc_mixer_control *) kcontrol->private_value;
+	unsigned int reg = mixer_ctrl->reg;
+	u16 val;
+	int ret;
+
+	ret = regmap_bulk_read(da7219->regmap, reg, &val, sizeof(val));
+	if (ret)
Quoted 8 lines

sound/soc/codecs/da7219.c line 340

Quoted 3 lines
sound/soc/codecs/da7219.c new file +3 -0
+		return ret;
+
+	ucontrol->value.integer.value[0] = le16_to_cpu(val);

This is *weird*. We do a bulk read for a single register using an API that returns CPU endian data then make it CPU endian (without any annotations on variables...). Why not use regmap_read()? Why swap? Why not use raw I/O?

The device is 8-bit register access only, and the value spans two registers, hence why this is done here. The register defined for the Kcontrol is the first in the sequence of two registers (first lower byte, second upper byte). Thought this was cleaner than having two separate controls to configure upper and lower bytes.

Quoted 23 lines
Quoted 23 lines
sound/soc/codecs/da7219.c new file +22 -0
+static int da7219_hpf_put(struct snd_kcontrol *kcontrol,
+			  struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
+	struct soc_enum *enum_ctrl = (struct soc_enum *)kcontrol->private_value;
+	unsigned int reg = enum_ctrl->reg;
+	unsigned int sel = ucontrol->value.integer.value[0];
+	unsigned int bits;
+
+	switch (sel) {
+	case DA7219_HPF_MODE_DISABLED:
+		bits = DA7219_HPF_DISABLED;
+		break;
+	case DA7219_HPF_MODE_AUDIO:
+		bits = DA7219_HPF_AUDIO_EN;
+		break;
+	case DA7219_HPF_MODE_VOICE:
+		bits = DA7219_HPF_VOICE_EN;
+		break;
+	default:
+		return -EINVAL;
+	}
Quoted 9 lines

sound/soc/codecs/da7219.c line 387

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+
+	snd_soc_update_bits(codec, reg, DA7219_HPF_MODE_MASK, bits);
+
+	return 0;
+}

This looks like a standard enumeration with a simple mapping to the register map?

The bit values aren't sequential as per a normal enumeration, which is why I added this approach to setting the correct bits. However, I've just spotted the SOC_VALUE_ENUM_SINGLE macro which looks like it will do the job, so I'll use that instead. Thanks.

Quoted 6 lines
Quoted 6 lines
sound/soc/codecs/da7219.c new file +6 -0
+
+	/* ADCs */
+	SOC_SINGLE_TLV("ADC Volume", DA7219_ADC_L_GAIN,
+		       DA7219_ADC_L_DIGITAL_GAIN_SHIFT,
+		       DA7219_ADC_L_DIGITAL_GAIN_MAX, DA7219_NO_INVERT,
+		       da7219_adc_dig_gain_tlv),
Quoted 8 lines

sound/soc/codecs/da7219.c line 454

Quoted 6 lines
sound/soc/codecs/da7219.c new file +6 -0
+	SOC_SINGLE("ADC Switch", DA7219_ADC_L_CTRL,
+		   DA7219_ADC_L_MUTE_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		   DA7219_INVERT),
+	SOC_SINGLE("ADC Gain Ramp Switch", DA7219_ADC_L_CTRL,
+		   DA7219_ADC_L_RAMP_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		   DA7219_NO_INVERT),

Capture Digital rather than ADC.

Ok, fine. Is this now the common naming to be used for all future codecs?

Quoted 17 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	SOC_SINGLE_TLV("ALC Max Attenuation", DA7219_ALC_GAIN_LIMITS,
+		       DA7219_ALC_ATTEN_MAX_SHIFT,

DA7219_ALC_ATTEN_GAIN_MAX,

sound/soc/codecs/da7219.c

Quoted 3 lines
sound/soc/codecs/da7219.c new file +3 -0
+		       DA7219_NO_INVERT, da7219_alc_gain_tlv),
+	SOC_SINGLE_TLV("ALC Max Gain", DA7219_ALC_GAIN_LIMITS,
+		       DA7219_ALC_GAIN_MAX_SHIFT,

DA7219_ALC_ATTEN_GAIN_MAX,

Review

Quoted 2 lines
(quoted diff) +2 -0
+		       DA7219_NO_INVERT, da7219_alc_gain_tlv),
+	SOC_SINGLE_RANGE_TLV("ALC Min Analog Gain",

DA7219_ALC_ANA_GAIN_LIMITS,

Review

Quoted 2 lines
(quoted diff) +2 -0
+			     DA7219_ALC_ANA_GAIN_MIN_SHIFT,
+			     DA7219_ALC_ANA_GAIN_MIN,

DA7219_ALC_ANA_GAIN_MAX,

Review

Quoted 2 lines
(quoted diff) +2 -0
+			     DA7219_NO_INVERT, da7219_alc_ana_gain_tlv),
+	SOC_SINGLE_RANGE_TLV("ALC Max Analog Gain",

DA7219_ALC_ANA_GAIN_LIMITS,

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+			     DA7219_ALC_ANA_GAIN_MAX_SHIFT,
+			     DA7219_ALC_ANA_GAIN_MIN,

DA7219_ALC_ANA_GAIN_MAX,

Review

Quoted 1 line
(quoted diff) +1 -0
+			     DA7219_NO_INVERT, da7219_alc_ana_gain_tlv),

Volume not Gain.

Fine, will update.

Quoted 6 lines

sound/soc/codecs/da7219.c line 513

Quoted 3 lines
sound/soc/codecs/da7219.c new file +3 -0
+	SOC_SINGLE("ToneGen DTMF Key", DA7219_TONE_GEN_CFG1,
+		   DA7219_DTMF_REG_SHIFT, DA7219_DTMF_REG_MAX,
+		   DA7219_NO_INVERT),

Should this be an enumeration with the DTMF digits in it (# and * aren't numbers)?

Yes, agreed. Will update.

Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	/* DACs */
+	SOC_DOUBLE_R_TLV("DAC Volume", DA7219_DAC_L_GAIN,

DA7219_DAC_R_GAIN,

sound/soc/codecs/da7219.c

Quoted 4 lines
sound/soc/codecs/da7219.c new file +4 -0
+			 DA7219_DAC_L_DIGITAL_GAIN_SHIFT,
+			 DA7219_DAC_DIGITAL_GAIN_MAX, DA7219_NO_INVERT,
+			 da7219_dac_dig_gain_tlv),
+	SOC_DOUBLE_R("DAC Switch", DA7219_DAC_L_CTRL,

DA7219_DAC_R_CTRL,

Quoted 8 lines

sound/soc/codecs/da7219.c line 587

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+		     DA7219_DAC_L_MUTE_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		     DA7219_INVERT),
+	SOC_DOUBLE_R("DAC Gain Ramp Switch", DA7219_DAC_L_CTRL,
+		     DA7219_DAC_R_CTRL, DA7219_DAC_L_RAMP_EN_SHIFT,
+		     DA7219_SWITCH_EN_MAX, DA7219_NO_INVERT),

All the DAC controls should probably be Playback Digital instead.

Ok, similar naming convention as for Capture Digital. Will update.

Quoted 13 lines

sound/soc/codecs/da7219.c line 948

Quoted 10 lines
sound/soc/codecs/da7219.c new file +9 -0
+
+static int da7219_set_dai_sysclk(struct snd_soc_dai *codec_dai,
+				 int clk_id, unsigned int freq, int dir)
+{
+	struct snd_soc_codec *codec = codec_dai->codec;
+	struct da7219_priv *da7219 = snd_soc_codec_get_drvdata(codec);
+
+	if (da7219->mclk_rate == freq)
+		return 0;

Given that we also have source selection is this safe - should we also be checking the source?

Good spot. Will amend.

Quoted 6 lines

sound/soc/codecs/da7219.c line 974

Quoted 4 lines
sound/soc/codecs/da7219.c new file +4 -0
+	if (da7219->mclk) {
+		freq = clk_round_rate(da7219->mclk, freq);
+		clk_set_rate(da7219->mclk, freq);
+	}

Missing error checking.

Yes, will add in checking.

Quoted 12 lines

sound/soc/codecs/da7219.c line 1464

Quoted 6 lines
sound/soc/codecs/da7219.c new file +5 -0
+			/* Internal LDO */
+			if (da7219->use_int_ldo)
+				snd_soc_update_bits(codec, DA7219_LDO_CTRL,
+						    DA7219_LDO_EN_MASK,
+						    DA7219_LDO_EN_MASK);

If there is an option to use an external supply I would expect to see the regulator API used to discover the external LDO (and ideally also to configure the integrated LDO). If the driver works outside the frameworks then it is likely this will lead to integration issues later on.

Given the simplistic nature of the internal LDO, I didn't think it would be necessary to use the framework as it seemed overkill. I assume you mean following something like what is done in the sgtl5000 codec?

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		/* Internal LDO */
+		da7219->use_int_ldo = pdata->use_internal_ldo;

This is likely to lead to surprises for example...

Quoted 12 lines

sound/soc/codecs/da7219.c line 1582

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+	/* Check if MCLK provided, if not the clock is NULL */
+	da7219->mclk = devm_clk_get(codec->dev, "mclk");
+	if (IS_ERR(da7219->mclk)) {
+		if (PTR_ERR(da7219->mclk) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		da7219->mclk = NULL;
+	}

This should specifically look for the error code that corresponds to a clock not being mapped and only continue silently in that case rather than silently accepting all failures to obtain a clock - if we silently accept all failures that will mean that actual errors will be ignored.

Ok, I will add further error checking to cover this.

Quoted 11 lines

sound/soc/codecs/da7219.c line 1594

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+	/*
+	 * There are multiple control bits for the input mixer.
+	 * The following can be enabled now as it's not power related.
+	 */
+	snd_soc_update_bits(codec, DA7219_MIXIN_L_CTRL,
+			    DA7219_MIXIN_L_MIX_EN_MASK,
+			    DA7219_MIXIN_L_MIX_EN_MASK);

So the chip designers just put these in for randomness? Fun. It'd be more idiomatic to do something like making these supply widgets so they're controlled via DAPM even if they don't matter much.

Figured we'd be saving on additional I2C accesses if it's just done the once. Do you really think it needs to be a widget as it seems a little unnecessary enabling and disabling every time that path is powered up and down?

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	else if (device_may_wakeup(codec->dev))
+		disable_irq_wake(da7219->aad->irq);

You can use dev_pm_set_wake_irq() and skip having to manage this stuff explicitly in the driver.

Ah, didn't know about that. Will convert over to using that. Thanks.

maintainer
#4 lore raw

Re: [PATCH 1/3] ASoC: codecs: Add da7219 codec driver

Quoted 10 lines · Opensource [Adam Thomson]
Quoted 4 lines · Mark Brown

This is obviously a massive reconfiguration of the device. I'm not seeing anything here which prevents userspace coming in and change the configuration while we're in this function, that would obviously have serious issues.

In a system scenario the likelihood of that happening is small as you cannot use the mic or headphones until they've been inserted. The system is only likely to act after the jack insertion events have occurred. However, it

This really isn't an OK approach here, you're making a whole bunch of assumptions about how the system is implemented that aren't robust and will lead to loss of audio if things go wrong which is a pretty serious consequence. Are you *sure* there's going to be a quick enough response to cover all jack inserts and remove (especially under load), or that userspace even bothers paying attention given that there's no other input and output devices?

Quoted 6 lines

would be better to prevent any chance of concurrent access. The problem is how best to lock the Kcontrols whilst the test procedure in progress. At the moment the only way I can see is to add explicit control set() functions which would use a lock that can also be controlled by the HP test code. Does this make sense to you or do you know of a simpler method? Obviously dapm has function to lock as required.

Yes, you're going to have to do something like that if you want to do this - you'll also need to lock the reads since otherwise userspace will see the intermediate control states.

Quoted 3 lines

For the cache resync idea, in terms of code, it will look cleaner, but you are talking about 4 to 5 times the number of I2C accesses to the device, to restore configuration. Does that not seem like a bit too much overhead?

There's regcache_sync_region().

Quoted 9 lines
Quoted 1 line

Why are we scheduling work - we're already in thread context?

hptest will take some time to complete (over 100ms), and in that time it's plausible that a user could remove the jack. If we deal with this in the IRQ thread, we won't be aware of jack removal during the process, and will send a report regardless, which will almost definitely be incorrect, and unnecessary. By spawning off work, it allows the removal to be dealt with if the hptest work procedure is currently in process, and then we can avoid sending incorrect jack reports at the end.

OK, please document this then.

Quoted 8 lines
Quoted 7 lines

sound/soc/codecs/da7219-aad.c line 362

Quoted 5 lines
sound/soc/codecs/da7219-aad.c new file +5 -0
+			/* Un-drive headphones/lineout */
+			snd_soc_update_bits(codec, DA7219_HP_R_CTRL,
+					    DA7219_HP_R_AMP_OE_MASK, 0);
+			snd_soc_update_bits(codec, DA7219_HP_L_CTRL,
+					    DA7219_HP_L_AMP_OE_MASK, 0);

This looks like DAPM?

Quoted 5 lines

The control of driving the headphones or making them high impedance is handled in the AAD code because we cannot have the headphones driven before a jack is inserted as it will affect the pole detection. Adding it to DAPM seemed like it would cause more problems in terms of controlling when it would and wouldn't be enabled.

IIRC you had some DAPM updates in adjacent code?

Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	default:
+		return DA7219_AAD_JACK_INS_DEB_20MS;

This isn't an error?

Opted for HW default in case of invalid values provided. Maybe a dev_warn() would be useful though to indicate this is the case?

Yes - the user has explicitly tried to set something and the driver is ignoring it.

Quoted 11 lines
Quoted 10 lines

sound/soc/codecs/da7219.c line 340

Quoted 5 lines
sound/soc/codecs/da7219.c new file +4 -0
+	ret = regmap_bulk_read(da7219->regmap, reg, &val, sizeof(val));
+	if (ret)
+		return ret;
 
+	ucontrol->value.integer.value[0] = le16_to_cpu(val);

This is *weird*. We do a bulk read for a single register using an API that returns CPU endian data then make it CPU endian (without any annotations on variables...). Why not use regmap_read()? Why swap? Why not use raw I/O?

Quoted 5 lines

The device is 8-bit register access only, and the value spans two registers, hence why this is done here. The register defined for the Kcontrol is the first in the sequence of two registers (first lower byte, second upper byte). Thought this was cleaner than having two separate controls to configure upper and lower bytes.

Again some documentation would help, and also using raw reads rather than bulk reads (which imply that all endianness issues will be taken care of). If you're doing a bulk read and handling endianness that's worrying. You should also have an endianness annotation for val.

Quoted 7 lines
Quoted 2 lines

This looks like a standard enumeration with a simple mapping to the register map?

The bit values aren't sequential as per a normal enumeration, which is why I added this approach to setting the correct bits. However, I've just spotted the SOC_VALUE_ENUM_SINGLE macro which looks like it will do the job, so I'll use that instead. Thanks.

Yes, you want a VALUE_ENUM.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+	/* ADCs */
+	SOC_SINGLE_TLV("ADC Volume", DA7219_ADC_L_GAIN,
+		       DA7219_ADC_L_DIGITAL_GAIN_SHIFT,
+		       DA7219_ADC_L_DIGITAL_GAIN_MAX, DA7219_NO_INVERT,
+		       da7219_adc_dig_gain_tlv),
Quoted 8 lines

sound/soc/codecs/da7219.c line 454

Quoted 6 lines
sound/soc/codecs/da7219.c new file +6 -0
+	SOC_SINGLE("ADC Switch", DA7219_ADC_L_CTRL,
+		   DA7219_ADC_L_MUTE_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		   DA7219_INVERT),
+	SOC_SINGLE("ADC Gain Ramp Switch", DA7219_ADC_L_CTRL,
+		   DA7219_ADC_L_RAMP_EN_SHIFT, DA7219_SWITCH_EN_MAX,
+		   DA7219_NO_INVERT),

Capture Digital rather than ADC.

Quoted 1 line

Ok, fine. Is this now the common naming to be used for all future codecs?

It's always been the naming in ControlNames.txt - we don't generally worry about it on devices with more flexible routing which mean that the associated meaning won't always be really true but for this device it seems that the options are sufficiently limited to allow userspace to use the standard name.

Quoted 12 lines
Quoted 11 lines

sound/soc/codecs/da7219.c line 1464

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+			/* Internal LDO */
+			if (da7219->use_int_ldo)
+				snd_soc_update_bits(codec, DA7219_LDO_CTRL,
+						    DA7219_LDO_EN_MASK,
+						    DA7219_LDO_EN_MASK);

If there is an option to use an external supply I would expect to see the regulator API used to discover the external LDO (and ideally also to configure the integrated LDO). If the driver works outside the frameworks then it is likely this will lead to integration issues later on.

Quoted 3 lines

Given the simplistic nature of the internal LDO, I didn't think it would be necessary to use the framework as it seemed overkill. I assume you mean following something like what is done in the sgtl5000 codec?

That should work I think. The point here isn't really the control of the LDO itself, it's making sure that the integration with external supplies works well - the key bit is that how we figure out that we don't have an external supply connected should be joined up with how we normally integrate external supplies.

Quoted 12 lines
Quoted 11 lines

sound/soc/codecs/da7219.c line 1594

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+	/*
+	 * There are multiple control bits for the input mixer.
+	 * The following can be enabled now as it's not power related.
+	 */
+	snd_soc_update_bits(codec, DA7219_MIXIN_L_CTRL,
+			    DA7219_MIXIN_L_MIX_EN_MASK,
+			    DA7219_MIXIN_L_MIX_EN_MASK);

So the chip designers just put these in for randomness? Fun. It'd be more idiomatic to do something like making these supply widgets so they're controlled via DAPM even if they don't matter much.

Quoted 3 lines

Figured we'd be saving on additional I2C accesses if it's just done the once. Do you really think it needs to be a widget as it seems a little unnecessary enabling and disabling every time that path is powered up and down?

It seems likely to be more robust against someone realising that the register bits actually do something useful and need toggling and it raises less eyebrows code wise.

If you're worried about the register writes you should also be able to arrange to map these in as mixer widgets which would mean that the the core will combine the writes with the main power controls.

#5 lore raw

RE: [PATCH 1/3] ASoC: codecs: Add da7219 codec driver

Quoted 11 lines · Mark Brown
Quoted 3 lines

In a system scenario the likelihood of that happening is small as you cannot use the mic or headphones until they've been inserted. The system is only likely to act after the jack insertion events have occurred. However, it

This really isn't an OK approach here, you're making a whole bunch of assumptions about how the system is implemented that aren't robust and will lead to loss of audio if things go wrong which is a pretty serious consequence. Are you *sure* there's going to be a quick enough response to cover all jack inserts and remove (especially under load), or that userspace even bothers paying attention given that there's no other input and output devices?

You make a fair point, and I'd much rather it was bullet proof.

Quoted 10 lines
Quoted 6 lines

would be better to prevent any chance of concurrent access. The problem is how best to lock the Kcontrols whilst the test procedure in progress. At the moment the only way I can see is to add explicit control set() functions which would use a lock that can also be controlled by the HP test code. Does this make sense to you or do you know of a simpler method? Obviously dapm has function to lock as required.

Yes, you're going to have to do something like that if you want to do this - you'll also need to lock the reads since otherwise userspace will see the intermediate control states.

Ok, will look at adding set() and get() functions for the controls affected.

Quoted 6 lines
Quoted 4 lines

For the cache resync idea, in terms of code, it will look cleaner, but you are talking about 4 to 5 times the number of I2C accesses to the device, to restore configuration. Does that not seem like a bit too much overhead?

There's regcache_sync_region().

That's fine if the registers are clumped closely together. Will have a look and see if it works out cleaner. Thanks.

Quoted 11 lines
Quoted 9 lines
Quoted 1 line

Why are we scheduling work - we're already in thread context?

hptest will take some time to complete (over 100ms), and in that time it's plausible that a user could remove the jack. If we deal with this in the IRQ thread, we won't be aware of jack removal during the process, and will send a report regardless, which will almost definitely be incorrect, and unnecessary. By spawning off work, it allows the removal to be dealt with if the hptest work procedure is currently in process, and then we can avoid sending incorrect jack reports at the end.

OK, please document this then.

Ok, will add comments to clarify.

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines

sound/soc/codecs/da7219-aad.c line 362

Quoted 6 lines
sound/soc/codecs/da7219-aad.c new file +5 -0
+			/* Un-drive headphones/lineout */
+			snd_soc_update_bits(codec, DA7219_HP_R_CTRL,
+					    DA7219_HP_R_AMP_OE_MASK, 0);
+			snd_soc_update_bits(codec, DA7219_HP_L_CTRL,
+					    DA7219_HP_L_AMP_OE_MASK, 0);

This looks like DAPM?

Quoted 7 lines
Quoted 5 lines

The control of driving the headphones or making them high impedance is handled in the AAD code because we cannot have the headphones driven before a jack is inserted as it will affect the pole detection. Adding it to DAPM seemed like it would cause more problems in terms of controlling when it would and wouldn't be enabled.

IIRC you had some DAPM updates in adjacent code?

Yes, there's a disable_pin() call for micbias. However that will not disable the pin indefinitely which is what I would require for this. I need to know that there's no chance of the pin being enabled prior to jack insertion.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	default:
+		return DA7219_AAD_JACK_INS_DEB_20MS;

This isn't an error?

Opted for HW default in case of invalid values provided. Maybe a dev_warn() would be useful though to indicate this is the case?

Yes - the user has explicitly tried to set something and the driver is ignoring it.

Agreed. Will update accordingly.

Quoted 18 lines
Quoted 12 lines
Quoted 11 lines

sound/soc/codecs/da7219.c line 340

Quoted 6 lines
sound/soc/codecs/da7219.c new file +4 -0
+	ret = regmap_bulk_read(da7219->regmap, reg, &val, sizeof(val));
+	if (ret)
+		return ret;
 
+	ucontrol->value.integer.value[0] = le16_to_cpu(val);

This is *weird*. We do a bulk read for a single register using an API that returns CPU endian data then make it CPU endian (without any annotations on variables...). Why not use regmap_read()? Why swap? Why not use raw I/O?

Quoted 5 lines

The device is 8-bit register access only, and the value spans two registers, hence why this is done here. The register defined for the Kcontrol is the first in the sequence of two registers (first lower byte, second upper byte). Thought this was cleaner than having two separate controls to configure upper and lower bytes.

Quoted 4 lines

Again some documentation would help, and also using raw reads rather than bulk reads (which imply that all endianness issues will be taken care of). If you're doing a bulk read and handling endianness that's worrying. You should also have an endianness annotation for val.

If I had used bulk_read() and an array of 2 u8 values instead, and then converted what was read into a u16, would that have been better/clearer? I can do that, but figured this might be a more elegant soluion. Either, way I'll add some comments to clarify what's going on.

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

Capture Digital rather than ADC.

Ok, fine. Is this now the common naming to be used for all future codecs?

It's always been the naming in ControlNames.txt - we don't generally worry about it on devices with more flexible routing which mean that the associated meaning won't always be really true but for this device it seems that the options are sufficiently limited to allow userspace to use the standard name.

Ok, understood.

Quoted 16 lines
Quoted 12 lines
Quoted 11 lines

sound/soc/codecs/da7219.c line 1464

Quoted 5 lines
sound/soc/codecs/da7219.c new file +5 -0
+			/* Internal LDO */
+			if (da7219->use_int_ldo)
+				snd_soc_update_bits(codec, DA7219_LDO_CTRL,
+						    DA7219_LDO_EN_MASK,
+						    DA7219_LDO_EN_MASK);

If there is an option to use an external supply I would expect to see the regulator API used to discover the external LDO (and ideally also to configure the integrated LDO). If the driver works outside the frameworks then it is likely this will lead to integration issues later on.

Quoted 3 lines

Given the simplistic nature of the internal LDO, I didn't think it would be necessary to use the framework as it seemed overkill. I assume you mean following something like what is done in the sgtl5000 codec?

Quoted 5 lines

That should work I think. The point here isn't really the control of the LDO itself, it's making sure that the integration with external supplies works well - the key bit is that how we figure out that we don't have an external supply connected should be joined up with how we normally integrate external supplies.

Ok, thanks. Will update.

Quoted 16 lines
Quoted 12 lines
Quoted 11 lines

sound/soc/codecs/da7219.c line 1594

Quoted 7 lines
sound/soc/codecs/da7219.c new file +7 -0
+	/*
+	 * There are multiple control bits for the input mixer.
+	 * The following can be enabled now as it's not power related.
+	 */
+	snd_soc_update_bits(codec, DA7219_MIXIN_L_CTRL,
+			    DA7219_MIXIN_L_MIX_EN_MASK,
+			    DA7219_MIXIN_L_MIX_EN_MASK);

So the chip designers just put these in for randomness? Fun. It'd be more idiomatic to do something like making these supply widgets so they're controlled via DAPM even if they don't matter much.

Quoted 3 lines

Figured we'd be saving on additional I2C accesses if it's just done the once. Do you really think it needs to be a widget as it seems a little unnecessary enabling and disabling every time that path is powered up and down?

Quoted 7 lines

It seems likely to be more robust against someone realising that the register bits actually do something useful and need toggling and it raises less eyebrows code wise.

If you're worried about the register writes you should also be able to arrange to map these in as mixer widgets which would mean that the the core will combine the writes with the main power controls.

Just didn't seem necessary. However, will change it as requested.

#6 lore raw

PATCH 2/3 ASoC: da7219: Add bindings documentation for DA7219 audio codec

In reply to Adam Thomson
---
 Documentation/devicetree/bindings/sound/da7219.txt | 106 +++++++++++++++++++++
 1 file changed, 106 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/da7219.txt
Documentation/devicetree/bindings/sound/da7219.txt new file +106 -0
new file mode 100644
index 0000000..b29fe2e
@@ -0,0 +1,106 @@
+Dialog Semiconductor DA7219 Audio Codec bindings
+
+DA7219 is an audio codec with advanced accessory detect features.
+
+======
+
+Required properties:
+- compatible : Should be "dlg,da7219"
+- reg: Specifies the I2C slave address
+
+Optional properties:
+- wakeup-source: Flag to indicate this device can wake system (suspend/resume).
+
+- clocks : phandle and clock specifier for codec MCLK.
+- clock-names : Clock name string for 'clocks' attribute, should be "mclk".
+
+- dlg,io-lvl : Expected voltage level range for digital IO
+	["2.5V_3.6V", "1.2V_2.8V"]
+- dlg,ldo-lvl : Required internal LDO voltage (mV) level
+	[<1050>, <1100>, <1200>, <1400>]
+- dlg,micbias-lvl : Voltage (mV) for Mic Bias
+	[<1800>, <2000>, <2200>, <2400>, <2600>, <2800>, <3000>]
+- dlg,mic-amp-in-sel : Mic input source type
+	["diff", "se_p", "se_n"]
+- dlg,cp-mchange : Charge pump voltage tracking mode
+	["largest_vol", "dac_vol", "sig_mag"]
+- dlg,cp-vol-thresh : Charge pump volume threshold value (6-bit value)
+	[ 0 - 0x3F ]
+
+======
+
+Child node - 'da7219_aad':
+
+Required properties:
+- interrupt-parent : Specifies the phandle of the interrupt controller to which
+  the IRQs from DA7219 AAD block are delivered to.
+- interrupts : IRQ line info for DA7219 AAD block.
+  (See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt for
+   further information relating to interrupt properties)
+
+Optional properties:
+- dlg,micbias-pulse-lvl : Mic bias higher voltage pulse level (mV).
+	[<2800>, <2900>]
+- dlg,micbias-pulse-time : Mic bias higher voltage pulse duration (ms)
+- dlg,btn-cfg : Periodic button press measurements for 4-pole jack (ms)
+	[<2>, <5>, <10>, <50>, <100>, <200>, <500>]
+- dlg,mic-det-thr : Impedance threshold for mic detection measurement (Ohms)
+	[<200>, <500>, <750>, <1000>]
+- dlg,jack-ins-deb : Debounce time for jack insertion (ms)
+	[<5>, <10>, <20>, <50>, <100>, <200>, <500>, <1000>]
+- dlg,jack-det-rate: Jack type detection latency (3/4 pole)
+	["32ms_64ms", "64ms_128ms", "128ms_256ms", "256ms_512ms"]
+- dlg,jack-rem-deb : Debounce time for jack removal (ms)
+	[<1>, <5>, <10>, <20>]
+- dlg,a-d-btn-thr : Impedance threshold between buttons A and D
+	[0x0 - 0xFF]
+- dlg,d-b-btn-thr : Impedance threshold between buttons D and B
+	[0x0 - 0xFF]
+- dlg,b-c-btn-thr : Impedance threshold between buttons B and C
+	[0x0 - 0xFF]
+- dlg,c-mic-btn-thr : Impedance threshold between button C and Mic
+	[0x0 - 0xFF]
+- dlg,btn-avg : Number of 8-bit readings for averaged button measurement
+	[<1>, <2>, <4>, <8>]
+- dlg,adc-1bit-rpt : Repeat count for 1-bit button measurement
+	[<1>, <2>, <4>, <8>]
+
+======
+
+Example:
+
+	codec: da7219@1a {
+		compatible = "dlg,da7219";
+		reg = <0x1a>;
+
+		clocks = <&clks 201>;
+		clock-names = "mclk";
+
+		dlg,io-lvl = "1.2V_2.8V";
+		dlg,ldo-lvl = <1200>;
+
+		dlg,micbias-lvl = <2600>;
+		dlg,mic-amp-in-sel = "diff";
+
+		dlg,cp-mchange = "sig_mag";
+		dlg,cp-vol-thresh = <0x34>;
+
+		da7219_aad {
+			interrupt-parent = <&gpio6>;
+			interrupts = <11 IRQ_TYPE_LEVEL_HIGH>;
+
+			dlg,btn-cfg = <50>;
+			dlg,mic-det-thr = <500>;
+			dlg,jack-ins-deb = <20>;
+			dlg,jack-det-rate = "32ms_64ms";
+			dlg,jack-rem-deb = <1>;
+
+			dlg,a-d-btn-thr = <0xa>;
+			dlg,d-b-btn-thr = <0x16>;
+			dlg,b-c-btn-thr = <0x21>;
+			dlg,c-mic-btn-thr = <0x3E>;
+
+			dlg,btn-avg = <4>;
+			dlg,adc-1bit-rpt = <1>;
+		};
+	};
Signature · 1 line
1.9.3
maintainer
#7 lore raw

Re: [PATCH 2/3] ASoC: da7219: Add bindings documentation for DA7219 audio codec

Documentation/devicetree/bindings/sound/da7219.txt line 18

Quoted 2 lines · Adam Thomson

+- dlg,io-lvl : Expected voltage level range for digital IO

Documentation/devicetree/bindings/sound/da7219.txt new file +1 -0
+	["2.5V_3.6V", "1.2V_2.8V"]

If the driver needs to read or set the voltage a supply is at it should do that via the regulator API.

Documentation/devicetree/bindings/sound/da7219.txt line 28

Quoted 4 lines

+- dlg,cp-mchange : Charge pump voltage tracking mode

Documentation/devicetree/bindings/sound/da7219.txt new file +3 -0
+	["largest_vol", "dac_vol", "sig_mag"]
+- dlg,cp-vol-thresh : Charge pump volume threshold value (6-bit value)
+	[ 0 - 0x3F ]

Why are these in the device tree rather than runtime parameters?

Documentation/devicetree/bindings/sound/da7219.txt line 39

Quoted 8 lines
Documentation/devicetree/bindings/sound/da7219.txt new file +8 -0
+Child node - 'da7219_aad':
+
+Required properties:
+- interrupt-parent : Specifies the phandle of the interrupt controller to which
+  the IRQs from DA7219 AAD block are delivered to.
+- interrupts : IRQ line info for DA7219 AAD block.
+  (See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt for
+   further information relating to interrupt properties)

Why is this not specified at the device level (the device does not appear to support other interrupts)?

#8 lore raw

RE: [PATCH 2/3] ASoC: da7219: Add bindings documentation for DA7219 audio codec

Quoted 5 lines · Mark Brown

Documentation/devicetree/bindings/sound/da7219.txt line 18

Quoted 2 lines

+- dlg,io-lvl : Expected voltage level range for digital IO

Documentation/devicetree/bindings/sound/da7219.txt new file +1 -0
+	["2.5V_3.6V", "1.2V_2.8V"]

If the driver needs to read or set the voltage a supply is at it should do that via the regulator API.

This would just be a read for the driver. However it's a fair point, so I'll look to add passing of the regulator information for VDDIO, so i can set this based on read voltage.

Quoted 8 lines

Documentation/devicetree/bindings/sound/da7219.txt line 28

Quoted 5 lines

+- dlg,cp-mchange : Charge pump voltage tracking mode

Documentation/devicetree/bindings/sound/da7219.txt new file +3 -0
+	["largest_vol", "dac_vol", "sig_mag"]
+- dlg,cp-vol-thresh : Charge pump volume threshold value (6-bit value)
+	[ 0 - 0x3F ]

Why are these in the device tree rather than runtime parameters?

From previous internal discussions, these seemed to be fire and forget parameters, hence their inclusion in the DT binding, rather than as controls. Personally didn't see either needing runtime updates.

Quoted 11 lines

Documentation/devicetree/bindings/sound/da7219.txt line 39

Quoted 8 lines
Documentation/devicetree/bindings/sound/da7219.txt new file +8 -0
+Child node - 'da7219_aad':
+
+Required properties:
+- interrupt-parent : Specifies the phandle of the interrupt controller to which
+  the IRQs from DA7219 AAD block are delivered to.
+- interrupts : IRQ line info for DA7219 AAD block.
+  (See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt for
+   further information relating to interrupt properties)

Why is this not specified at the device level (the device does not appear to support other interrupts)?

Given the way that the driver code was structured, and that the IRQ is only used for accessory detection, I added it to the child node. The other option would be to flatten out bindings, and remove the child node. Felt like keeping the accessory detect items separate though was a sensible approach. What is your feeling on this?

maintainer
#9 lore raw

Re: [PATCH 2/3] ASoC: da7219: Add bindings documentation for DA7219 audio codec

Quoted 9 lines · Opensource [Adam Thomson]
Quoted 6 lines · Mark Brown

Documentation/devicetree/bindings/sound/da7219.txt line 28

Quoted 4 lines

+- dlg,cp-mchange : Charge pump voltage tracking mode

Documentation/devicetree/bindings/sound/da7219.txt new file +3 -0
+	["largest_vol", "dac_vol", "sig_mag"]
+- dlg,cp-vol-thresh : Charge pump volume threshold value (6-bit value)
+	[ 0 - 0x3F ]

Why are these in the device tree rather than runtime parameters?

Quoted 3 lines

From previous internal discussions, these seemed to be fire and forget parameters, hence their inclusion in the DT binding, rather than as controls. Personally didn't see either needing runtime updates.

Make them runtime configurable. People can do an at boot runtime configuration if they like.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Documentation/devicetree/bindings/sound/da7219.txt new file +6 -0
+Required properties:
+- interrupt-parent : Specifies the phandle of the interrupt controller to which
+  the IRQs from DA7219 AAD block are delivered to.
+- interrupts : IRQ line info for DA7219 AAD block.
+  (See Documentation/devicetree/bindings/interrupt-controller/interrupts.txt for
+   further information relating to interrupt properties)
Quoted 8 lines
Quoted 2 lines

Why is this not specified at the device level (the device does not appear to support other interrupts)?

Given the way that the driver code was structured, and that the IRQ is only used for accessory detection, I added it to the child node. The other option would be to flatten out bindings, and remove the child node. Felt like keeping the accessory detect items separate though was a sensible approach. What is your feeling on this?

The child node is fine for collecting the parameters but the chip interrupt line should be at the chip level.

#10 lore raw

PATCH 3/3 MAINTAINERS: da7219: Add entry to cover DA7219 bindings document

In reply to Adam Thomson

This adds an entry to indicate the DA7219 bindings document (and other Dialog codecs bindings documents) are supported.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 7ba7ab7..a235822 100644
@@ -3361,6 +3361,7 @@ M:	Support Opensource <[email protected]>
 W:	http://www.dialog-semiconductor.com/products
 S:	Supported
 F:	Documentation/hwmon/da90??
+F:	Documentation/devicetree/bindings/sound/da[79]*.txt
 F:	drivers/gpio/gpio-da90??.c
 F:	drivers/hwmon/da90??-hwmon.c
 F:	drivers/iio/adc/da91??-*.c
Signature · 1 line
1.9.3
maintainer
#11 lore raw

Applied "ASoC: da7219: Add entry to cover DA7219 bindings document" to the asoc tree

The patch

ASoC: da7219: Add entry to cover DA7219 bindings document

has been applied to the asoc tree at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark

Quoted 1 line

From 7c93377244329552a72912c63fd7503a4e88d6a1 Mon Sep 17 00:00:00 2001

From: Adam Thomson <[email protected]>
Date: Tue, 29 Sep 2015 16:44:12 +0100
Subject: [PATCH] ASoC: da7219: Add entry to cover DA7219 bindings document

This adds an entry to indicate the DA7219 bindings document (and other Dialog codecs bindings documents) are supported.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index 7ba7ab7..a235822 100644
@@ -3361,6 +3361,7 @@ M:	Support Opensource <[email protected]>
 W:	http://www.dialog-semiconductor.com/products
 S:	Supported
 F:	Documentation/hwmon/da90??
+F:	Documentation/devicetree/bindings/sound/da[79]*.txt
 F:	drivers/gpio/gpio-da90??.c
 F:	drivers/hwmon/da90??-hwmon.c
 F:	drivers/iio/adc/da91??-*.c
Signature · 1 line
2.5.0