Skip to contentSkip to conversation

ASoC: CX2072X codec support (revised)

PATCH Superseded Takashi Iwai 3 participants 20 messages Apr 23, 2019 – May 8, 2019 2 messages not in the archive

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover ASoC: CX2072X codec support (revised)

Hi,

it's been long time ago the first version of CX2072X codec patch was submitted, and I hoped that it'd be resubmitted, but never happened, as the original author seems to have left, unfortunately.

Since I have such a laptop (ASUS E200HA), I took some time to cook and brush up the patches. The patches are for 5.2, should be applicable to ASoC tree for-next branch.

Will post the corresponding UCM profile patch once when this gets accepted.

thanks,

Takashi

===

Simon Ho (1):
ASoC: Add support for Conexant CX2072X CODEC

Takashi Iwai (1):
ASoC: Intel: Add machine driver for CX2072X on BYT/CHT platforms

 sound/soc/codecs/Kconfig                          |    7 +
 sound/soc/codecs/Makefile                         |    2 +
 sound/soc/codecs/cx2072x.c                        | 2197 +++++++++++++++++++++
 sound/soc/codecs/cx2072x.h                        |  317 +++
 sound/soc/intel/boards/Kconfig                    |   11 +
 sound/soc/intel/boards/Makefile                   |    2 +
 sound/soc/intel/boards/bytcht_cx2072x.c           |  285 +++
 sound/soc/intel/common/soc-acpi-intel-byt-match.c |    8 +
 sound/soc/intel/common/soc-acpi-intel-cht-match.c |    8 +
 9 files changed, 2837 insertions(+)
 create mode 100644 sound/soc/codecs/cx2072x.c
 create mode 100644 sound/soc/codecs/cx2072x.h
 create mode 100644 sound/soc/intel/boards/bytcht_cx2072x.c
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/2 ASoC: Add support for Conexant CX2072X CODEC

From: Simon Ho <[email protected]>

Initial commit of the Conexant CX2072X CODEC driver. Some features are not present.

The CX2072X is a ultra low power stereo audio codec supports I2S/TDM host interface with EQ, DRC features in playback mode.

Featues of CX2072X codec:

* Two 24 bits DACs and DACs.
* Stereo Headphone AMP.
* 2.8W per channel class-D output.
* Integrated seven bands per channel EQ and DRC.
* Fully integrated headset support with detect/switch.
* Stereo digital microphone for array applications.
* S/PDIF output.
* Bi-directional GPIOs.
* Support analog and digital PC Beeep.
* One headset button support.
* Supports a wide variety of host interfaces. -wide variety of I2S and similar bit-stream formats with word lengths of up to 24 bits.
-TDM stream supports up to 4 channels.
* AEC loopback support.

Further fixes by tiwai:
* Rebase to 5.1+
* Missing declarations of jack detection helpers
* Missing DAPM entry definitions
* Missing power hooks
* Workaround for the jack detection during cache-only
* Fix uninitialized variable warning
* Fix doubly clk disablement at cx2072x_set_bias_level()
* Plumbing jack detection code for Intel ASoC
* Code cleanups and minor refactoring

The OF code was dropped due to the lack of testability. It should be easy to re-add once if someone can test it.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=115531

---
 sound/soc/codecs/Kconfig   |    7 +
 sound/soc/codecs/Makefile  |    2 +
 sound/soc/codecs/cx2072x.c | 2197 ++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/cx2072x.h |  317 +++++++
 4 files changed, 2523 insertions(+)
 create mode 100644 sound/soc/codecs/cx2072x.c
 create mode 100644 sound/soc/codecs/cx2072x.h
sound/soc/codecs/Kconfig +7 -0
index 8f577258080b..472bde124ebe 100644
@@ -72,6 +72,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_CS47L24 if MFD_CS47L24
 	select SND_SOC_CS53L30 if I2C
 	select SND_SOC_CX20442 if TTY
+	select SND_SOC_CX2072X if I2C
 	select SND_SOC_DA7210 if SND_SOC_I2C_AND_SPI
 	select SND_SOC_DA7213 if I2C
 	select SND_SOC_DA7218 if I2C
@@ -584,6 +585,12 @@ config SND_SOC_CX20442
 	tristate
 	depends on TTY
 
+config SND_SOC_CX2072X
+	tristate "Conexant CX2072X CODEC"
+	depends on I2C
+	help
+	  Enable support for Conexant CX20721 and CX20723 codec chips.
+
 config SND_SOC_JZ4740_CODEC
 	depends on MIPS || COMPILE_TEST
 	select REGMAP_MMIO
sound/soc/codecs/Makefile +2 -0
index aa7720a7a0aa..454b8087a5bd 100644
@@ -67,6 +67,7 @@ snd-soc-cs4349-objs := cs4349.o
 snd-soc-cs47l24-objs := cs47l24.o
 snd-soc-cs53l30-objs := cs53l30.o
 snd-soc-cx20442-objs := cx20442.o
+snd-soc-cx2072x-objs := cx2072x.o
 snd-soc-da7210-objs := da7210.o
 snd-soc-da7213-objs := da7213.o
 snd-soc-da7218-objs := da7218.o
@@ -341,6 +342,7 @@ obj-$(CONFIG_SND_SOC_CS4349)	+= snd-soc-cs4349.o
 obj-$(CONFIG_SND_SOC_CS47L24)	+= snd-soc-cs47l24.o
 obj-$(CONFIG_SND_SOC_CS53L30)	+= snd-soc-cs53l30.o
 obj-$(CONFIG_SND_SOC_CX20442)	+= snd-soc-cx20442.o
+obj-$(CONFIG_SND_SOC_CX2072X)	+= snd-soc-cx2072x.o
 obj-$(CONFIG_SND_SOC_DA7210)	+= snd-soc-da7210.o
 obj-$(CONFIG_SND_SOC_DA7213)	+= snd-soc-da7213.o
 obj-$(CONFIG_SND_SOC_DA7218)	+= snd-soc-da7218.o
sound/soc/codecs/cx2072x.c new file +2197 -0

2,197 lines not on this page · raw message

sound/soc/codecs/cx2072x.h new file +317 -0

317 lines not on this page · raw message

Signature · 1 line
2.16.4
maintainer
#2 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 12 lines · Takashi Iwai
sound/soc/codecs/cx2072x.c new file +12 -0
+/*
+ * register patch.
+ */
+static const struct reg_sequence cx2072x_patch[] = {
+	{ 0x71A4, 0x080 }, /* DC offset Calibration		*/
+	{ 0x7328, 0x65f }, /* disable the PA			*/
+	{ 0x71a8, 0x289 }, /* Set the spkeaer output gain	*/
+	{ 0x7310, 0xf05 },
+	{ 0x7290, 0x380 },
+	{ 0x7328, 0xb90 },
+	{ 0x7124, 0x001 }, /* Enable 30 Hz High pass filter	*/
+	{ 0x718c, 0x300 }, /* Disable PCBEEP pad		*/

sound/soc/codecs/cx2072x.c line 267

Quoted 10 lines
sound/soc/codecs/cx2072x.c new file +10 -0
+	{ 0x731c, 0x100 }, /* Disable SnM mode			*/
+	{ 0x641c, 0x020 }, /* Enable PortD input		*/
+	{ 0x0458, 0x040 }, /* Enable GPIO7 pin for button	*/
+	{ 0x0464, 0x040 }, /* Enable UM for GPIO7		*/
+	{ 0x0420, 0x080 }, /* Enable button response		*/
+	{ 0x7230, 0x0c4 }, /* Enable headset button		*/
+	{ 0x7200, 0x415 }, /* Power down class-D during idle	*/
+	{ 0x6e04, 0x00f }, /* Enable I2S TX			*/
+	{ 0x6e08, 0x00f }, /* Enable I2S RX			*/
+};

This looks *very* much like board configuration rather than a patch - there's no kind of test bit and the comments talk specifically about things like gain settings and pad configuration which look very board specific. Register patches are supposed to be for things like early revisions of the chip which have different register defaults or magic sequences that vendors tell you to run on startup, usually to tune test registers.

sound/soc/codecs/cx2072x.c line 272

Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+/* return register size */
+static unsigned int cx2072x_register_size(struct device *dev, unsigned int reg)
+{
+	switch (reg) {

This is *not* going to play well with regmap...

Quoted 5 lines
sound/soc/codecs/cx2072x.c new file +5 -0
+static int cx2072x_reg_bulk_write(struct snd_soc_component *codec,
+				  unsigned int reg,
+				  const void *val, size_t val_count)
+{
+	struct i2c_client *client = to_i2c_client(codec->dev);

sound/soc/codecs/cx2072x.c line 385

Quoted 10 lines
sound/soc/codecs/cx2072x.c new file +10 -0
+	struct device *dev = &client->dev;
+	u8 buf[2 + CX2072X_MAX_EQ_COEFF];
+	int ret;
+
+	if (val_count > CX2072X_MAX_EQ_COEFF) {
+		dev_err(dev,
+			"cx2072x_reg_bulk_write failed, writing count = %d\n",
+			(int)val_count);
+		return -EINVAL;
+	}

So this only works for the EQ registers? If so there should be validation to confirm that it only gets used for them. If not there should be handling for register size variation issues.

Quoted 1 line

+#define cx2072x_plbk_eq_en_info snd_ctl_boolean_mono_info

Why not just use the function directly rather than hiding it?

sound/soc/codecs/cx2072x.c line 987

Quoted 3 lines
sound/soc/codecs/cx2072x.c new file +3 -0
+	/* do nothing if the value is the same */
+	if (memcmp(cache, param, CX2072X_PLBK_EQ_COEF_LEN))
+		goto unlock;

Is this test not inverted - shouldn't we be skipping if memcmp returns 0?

sound/soc/codecs/cx2072x.c line 1139

Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+	SOC_DOUBLE_R_TLV("DAC1 Volume", CX2072X_DAC1_AMP_GAIN_LEFT,
+			 CX2072X_DAC1_AMP_GAIN_RIGHT, 0, 0x4a, 0, dac_tlv),
+	SOC_DOUBLE_R("DAC1 Mute Switch", CX2072X_DAC1_AMP_GAIN_LEFT,
+		     CX2072X_DAC1_AMP_GAIN_RIGHT, 7,  1, 0),

Should just be DAC1 Switch so it gets joined up with DAC1 Volume in UIs and the "Mute" is redundant anyway.

sound/soc/codecs/cx2072x.c line 1179

Quoted 10 lines
sound/soc/codecs/cx2072x.c new file +10 -0
+int snd_soc_cx2072x_enable_jack_detect(struct snd_soc_component *codec)
+{
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(codec);
+
+	/* No-sticky input type */
+	regmap_write(cx2072x->regmap, CX2072X_GPIO_STICKY_MASK, 0x1f);
+
+	/* Use GPOI0 as interrupt pin */
+	regmap_write(cx2072x->regmap, CX2072X_UM_INTERRUPT_CRTL_E, 0x12 << 24);

This isn't board specific is it?

sound/soc/codecs/cx2072x.c line 1218

Quoted 11 lines
sound/soc/codecs/cx2072x.c new file +11 -0
+int snd_soc_cx2072x_get_jack_state(struct snd_soc_component *codec)
+{
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+	unsigned int jack;
+	unsigned int type = 0;
+	int state = 0;
+	bool need_cache_bypass =
+		snd_soc_component_get_bias_level(codec) == SND_SOC_BIAS_OFF;
+
+	if (need_cache_bypass)
+		regcache_cache_only(cx2072x->regmap, false);

This looks funky and racy - what's going on here? If the register map is live and usable why is it in cache only mode?

sound/soc/codecs/cx2072x.c line 1252

Quoted 5 lines
sound/soc/codecs/cx2072x.c new file +5 -0
+	dev_dbg(codec->dev, "CX2072X_HSDETECT type=0x%X,Jack state = %x\n",
+		type, state);
+	return state;
+}
+EXPORT_SYMBOL_GPL(snd_soc_cx2072x_get_jack_state);

Why is this symbol exported?

Quoted 9 lines
sound/soc/codecs/cx2072x.c new file +9 -0
+static void cx2072x_shutdown(struct snd_pcm_substream *substream,
+			     struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *codec = dai->component;
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+
+	/* shutdown codec */
+	regcache_cache_only(cx2072x->regmap, false);
+	regmap_write(cx2072x->regmap, CX2072X_PORTA_POWER_STATE, 3);

sound/soc/codecs/cx2072x.c line 1341

Quoted 10 lines
sound/soc/codecs/cx2072x.c new file +10 -0
+	regmap_write(cx2072x->regmap, CX2072X_PORTB_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTC_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTD_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTE_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTG_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_MIXER_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_ADC1_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_ADC2_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_DAC1_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_DAC2_POWER_STATE, 3);

Why isn't DAPM powering things off for us?

sound/soc/codecs/cx2072x.c line 1742

Quoted 7 lines
sound/soc/codecs/cx2072x.c new file +7 -0
+	/* use flat eq by default */
+	for (ch = 0 ; ch < 2 ; ch++) {
+		for (band = 0; band < CX2072X_PLBK_EQ_BAND_NUM; band++) {
+			cx2072x->plbk_eq[ch][band][1] = 64;
+			cx2072x->plbk_eq[ch][band][10] = 3;
+		}
+	}

Why not use the register defaults?

sound/soc/codecs/cx2072x.c line 1867

Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+static bool cx2072x_readable_register(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case CX2072X_VENDOR_ID:

It's weird that this is a long way away from the other regmap functions.

#3 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 26 lines · Mark Brown
Quoted 12 lines · Takashi Iwai
sound/soc/codecs/cx2072x.c new file +12 -0
+/*
+ * register patch.
+ */
+static const struct reg_sequence cx2072x_patch[] = {
+	{ 0x71A4, 0x080 }, /* DC offset Calibration		*/
+	{ 0x7328, 0x65f }, /* disable the PA			*/
+	{ 0x71a8, 0x289 }, /* Set the spkeaer output gain	*/
+	{ 0x7310, 0xf05 },
+	{ 0x7290, 0x380 },
+	{ 0x7328, 0xb90 },
+	{ 0x7124, 0x001 }, /* Enable 30 Hz High pass filter	*/
+	{ 0x718c, 0x300 }, /* Disable PCBEEP pad		*/

sound/soc/codecs/cx2072x.c line 267

Quoted 10 lines
sound/soc/codecs/cx2072x.c new file +10 -0
+	{ 0x731c, 0x100 }, /* Disable SnM mode			*/
+	{ 0x641c, 0x020 }, /* Enable PortD input		*/
+	{ 0x0458, 0x040 }, /* Enable GPIO7 pin for button	*/
+	{ 0x0464, 0x040 }, /* Enable UM for GPIO7		*/
+	{ 0x0420, 0x080 }, /* Enable button response		*/
+	{ 0x7230, 0x0c4 }, /* Enable headset button		*/
+	{ 0x7200, 0x415 }, /* Power down class-D during idle	*/
+	{ 0x6e04, 0x00f }, /* Enable I2S TX			*/
+	{ 0x6e08, 0x00f }, /* Enable I2S RX			*/
+};
Quoted 7 lines

This looks *very* much like board configuration rather than a patch - there's no kind of test bit and the comments talk specifically about things like gain settings and pad configuration which look very board specific. Register patches are supposed to be for things like early revisions of the chip which have different register defaults or magic sequences that vendors tell you to run on startup, usually to tune test registers.

OK, will replace with the straight regmap_multi_reg_write().

Quoted 6 lines

sound/soc/codecs/cx2072x.c line 272

Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+/* return register size */
+static unsigned int cx2072x_register_size(struct device *dev, unsigned int reg)
+{
+	switch (reg) {

This is *not* going to play well with regmap...

The code seems trying to unify the register access with the same width, while the register size differs depending on the register index. So the read/write ops adjust it by checking this register size *internally*. IOW, it's hiding the internal register size difference from the outside so that regmap can work.

(Actually the zero check in the caller side is bogus -- this function never returns an error.)

I'm going to rewrite the whole these tables. Maybe better to have a single register attribute table.

Quoted 9 lines
Quoted 9 lines
sound/soc/codecs/cx2072x.c new file +9 -0
+static int cx2072x_reg_bulk_write(struct snd_soc_component *codec,
+				  unsigned int reg,
+				  const void *val, size_t val_count)
+{
+	struct i2c_client *client = to_i2c_client(codec->dev);
+	struct device *dev = &client->dev;
+	u8 buf[2 + CX2072X_MAX_EQ_COEFF];
+	int ret;
+
Quoted 8 lines

sound/soc/codecs/cx2072x.c line 385

Quoted 6 lines
sound/soc/codecs/cx2072x.c new file +6 -0
+	if (val_count > CX2072X_MAX_EQ_COEFF) {
+		dev_err(dev,
+			"cx2072x_reg_bulk_write failed, writing count = %d\n",
+			(int)val_count);
+		return -EINVAL;
+	}

So this only works for the EQ registers?

I guess this was meant only as a sanity check. It's an internal function that is called from a few helper functions, and the check above is to assure not overflowing the temporary buffer on the stack. It can be simply WARN_ON() like

	if (WARN_ON(val_count + 2 > sizeof(buf)))
		return -EINVAL;
Quoted 7 lines

If so there should be
validation to confirm that it only gets used for them. If not there should be handling for register size variation issues.

Quoted 1 line

+#define cx2072x_plbk_eq_en_info snd_ctl_boolean_mono_info

Why not just use the function directly rather than hiding it?

Just a standard idiom. Can be replaced if preferred.

Quoted 6 lines

sound/soc/codecs/cx2072x.c line 987

Quoted 3 lines
sound/soc/codecs/cx2072x.c new file +3 -0
+	/* do nothing if the value is the same */
+	if (memcmp(cache, param, CX2072X_PLBK_EQ_COEF_LEN))
+		goto unlock;

Is this test not inverted - shouldn't we be skipping if memcmp returns 0?

Oh yeah, indeed, it looks like a real bug. This shows that I have never played with the EQ stuff :)

(IOW, I'm fine to drop the untested EQ stuff, but someone else might
play with it...)

Quoted 7 lines

sound/soc/codecs/cx2072x.c line 1139

Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+	SOC_DOUBLE_R_TLV("DAC1 Volume", CX2072X_DAC1_AMP_GAIN_LEFT,
+			 CX2072X_DAC1_AMP_GAIN_RIGHT, 0, 0x4a, 0, dac_tlv),
+	SOC_DOUBLE_R("DAC1 Mute Switch", CX2072X_DAC1_AMP_GAIN_LEFT,
+		     CX2072X_DAC1_AMP_GAIN_RIGHT, 7,  1, 0),

Should just be DAC1 Switch so it gets joined up with DAC1 Volume in UIs and the "Mute" is redundant anyway.

OK.

Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+int snd_soc_cx2072x_enable_jack_detect(struct snd_soc_component *codec)
+{
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(codec);
Quoted 8 lines

sound/soc/codecs/cx2072x.c line 1179

Quoted 6 lines
sound/soc/codecs/cx2072x.c new file +6 -0
+
+	/* No-sticky input type */
+	regmap_write(cx2072x->regmap, CX2072X_GPIO_STICKY_MASK, 0x1f);
+
+	/* Use GPOI0 as interrupt pin */
+	regmap_write(cx2072x->regmap, CX2072X_UM_INTERRUPT_CRTL_E, 0x12 << 24);

This isn't board specific is it?

I have no idea. It's been so from the original code, and there doesn't seem any other hardware implementations.

Quoted 6 lines
Quoted 6 lines
sound/soc/codecs/cx2072x.c new file +6 -0
+int snd_soc_cx2072x_get_jack_state(struct snd_soc_component *codec)
+{
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+	unsigned int jack;
+	unsigned int type = 0;
+	int state = 0;
Quoted 8 lines

sound/soc/codecs/cx2072x.c line 1218

Quoted 5 lines
sound/soc/codecs/cx2072x.c new file +5 -0
+	bool need_cache_bypass =
+		snd_soc_component_get_bias_level(codec) == SND_SOC_BIAS_OFF;
+
+	if (need_cache_bypass)
+		regcache_cache_only(cx2072x->regmap, false);

This looks funky and racy - what's going on here? If the register map is live and usable why is it in cache only mode?

Not to read the register while the chip is turned off, I suppose. The jack detection in ASoC is anyway a bit funky, especially when involved with PM...

Quoted 7 lines

sound/soc/codecs/cx2072x.c line 1252

Quoted 5 lines
sound/soc/codecs/cx2072x.c new file +5 -0
+	dev_dbg(codec->dev, "CX2072X_HSDETECT type=0x%X,Jack state = %x\n",
+		type, state);
+	return state;
+}
+EXPORT_SYMBOL_GPL(snd_soc_cx2072x_get_jack_state);

Why is this symbol exported?

It's called from the machine driver. snd_soc_jack_add_gpios() is called in the machine driver side, and it needs the jack_status_check callback that calls this function.

Quoted 13 lines
Quoted 13 lines
sound/soc/codecs/cx2072x.c new file +13 -0
+static void cx2072x_shutdown(struct snd_pcm_substream *substream,
+			     struct snd_soc_dai *dai)
+{
+	struct snd_soc_component *codec = dai->component;
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+
+	/* shutdown codec */
+	regcache_cache_only(cx2072x->regmap, false);
+	regmap_write(cx2072x->regmap, CX2072X_PORTA_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTB_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTC_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTD_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_PORTE_POWER_STATE, 3);
Quoted 8 lines

sound/soc/codecs/cx2072x.c line 1341

Quoted 6 lines
sound/soc/codecs/cx2072x.c new file +6 -0
+	regmap_write(cx2072x->regmap, CX2072X_PORTG_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_MIXER_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_ADC1_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_ADC2_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_DAC1_POWER_STATE, 3);
+	regmap_write(cx2072x->regmap, CX2072X_DAC2_POWER_STATE, 3);

Why isn't DAPM powering things off for us?

Honestly speaking, no idea. It seems to have been added some revision of the original code. Let's try to rip off.

Quoted 9 lines

sound/soc/codecs/cx2072x.c line 1742

Quoted 7 lines
sound/soc/codecs/cx2072x.c new file +7 -0
+	/* use flat eq by default */
+	for (ch = 0 ; ch < 2 ; ch++) {
+		for (band = 0; band < CX2072X_PLBK_EQ_BAND_NUM; band++) {
+			cx2072x->plbk_eq[ch][band][1] = 64;
+			cx2072x->plbk_eq[ch][band][10] = 3;
+		}
+	}

Why not use the register defaults?

Because it'll become too messy for put flatten array values? The initialization using loop makes more sense in such a case, IMO.

Quoted 6 lines

sound/soc/codecs/cx2072x.c line 1867

Quoted 4 lines
sound/soc/codecs/cx2072x.c new file +4 -0
+static bool cx2072x_readable_register(struct device *dev, unsigned int reg)
+{
+	switch (reg) {
+	case CX2072X_VENDOR_ID:

It's weird that this is a long way away from the other regmap functions.

Agreed, will move to a former place.

Thanks!

Takashi

#4 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 16 lines · Takashi Iwai
Quoted 15 lines

sound/soc/codecs/cx2072x.c line 1218

Quoted 12 lines
sound/soc/codecs/cx2072x.c new file +11 -0
+int snd_soc_cx2072x_get_jack_state(struct snd_soc_component *codec)
+{
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+	unsigned int jack;
+	unsigned int type = 0;
+	int state = 0;
+	bool need_cache_bypass =
+		snd_soc_component_get_bias_level(codec) == SND_SOC_BIAS_OFF;
+
+	if (need_cache_bypass)
+		regcache_cache_only(cx2072x->regmap, false);

This looks funky and racy - what's going on here? If the register map is live and usable why is it in cache only mode?

Quoted 1 line

Not to read the register while the chip is turned off, I suppose.

Actually other way round: the codec driver tries to avoid the whole register access while the chip is in BIAS_OFF state. OTOH, the jack state check is still required even in that state, so it flips the cache-only flag temporarily at reading the jack detect bit.

I guess we may remove the cache-only behavior, although this is a nice-to-have thing.

Takashi

maintainer
#5 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 11 lines · Takashi Iwai
Quoted 1 line · Takashi Iwai

Not to read the register while the chip is turned off, I suppose.

Actually other way round: the codec driver tries to avoid the whole register access while the chip is in BIAS_OFF state. OTOH, the jack state check is still required even in that state, so it flips the cache-only flag temporarily at reading the jack detect bit.

I guess we may remove the cache-only behavior, although this is a nice-to-have thing.

No, it should be removed - it's buggy and racy. Devices should only be going into cache only mode if they can't be physically accessed, otherwise you end up with incoherent things like this that create bugs. If the driver is actually able to access the register map, actively doing so and therefore needs to try flipping cache only mode on and off without coordinating with the rest of the device it isn't really in a cache only mode.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 13 lines · Mark Brown
Quoted 10 lines · Takashi Iwai
Quoted 9 lines · Mark Brown

On Tue, Apr 23, 2019 at 04:13:35PM +0200, Takashi Iwai wrote:

This looks *very* much like board configuration rather than a patch - there's no kind of test bit and the comments talk specifically about things like gain settings and pad configuration which look very board specific. Register patches are supposed to be for things like early revisions of the chip which have different register defaults or magic sequences that vendors tell you to run on startup, usually to tune test registers.

Quoted 4 lines
Quoted 1 line

OK, will replace with the straight regmap_multi_reg_write().

That's probably not addressing the issue, a lot of that stuff just doesn't seem like it should be in some fixed configuration table at all.

So what's your alternative suggestion?

Quoted 21 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

+#define cx2072x_plbk_eq_en_info snd_ctl_boolean_mono_info

Why not just use the function directly rather than hiding it?

Just a standard idiom. Can be replaced if preferred.

Please.

Quoted 12 lines
Quoted 12 lines

sound/soc/codecs/cx2072x.c line 1179

Quoted 10 lines
sound/soc/codecs/cx2072x.c new file +10 -0
+int snd_soc_cx2072x_enable_jack_detect(struct snd_soc_component *codec)
+{
+	struct cx2072x_priv *cx2072x = snd_soc_component_get_drvdata(codec);
+	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(codec);
+
+	/* No-sticky input type */
+	regmap_write(cx2072x->regmap, CX2072X_GPIO_STICKY_MASK, 0x1f);
+
+	/* Use GPOI0 as interrupt pin */
+	regmap_write(cx2072x->regmap, CX2072X_UM_INTERRUPT_CRTL_E, 0x12 << 24);

This isn't board specific is it?

Quoted 4 lines
Quoted 2 lines

I have no idea. It's been so from the original code, and there doesn't seem any other hardware implementations.

Oh, joy. What's the story here? Do you have a datasheet for the part?

Not at all. I just refreshed the already submitted patches since I have a laptop with the codec. I tried to contact Conexant, but in vain, so I decided to submit the renewed one.

Quoted 5 lines
Quoted 2 lines

The jack detection in ASoC is anyway a bit funky, especially when involved with PM...

What do you mean here? I'm not aware of any issues and the systems I've worked with seemed robust...

There are tons of different ways of implementation for jack controls, with different API usages. IOW, no consistency.

Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

sound/soc/codecs/cx2072x.c line 1252

Quoted 5 lines
sound/soc/codecs/cx2072x.c new file +5 -0
+	dev_dbg(codec->dev, "CX2072X_HSDETECT type=0x%X,Jack state = %x\n",
+		type, state);
+	return state;
+}
+EXPORT_SYMBOL_GPL(snd_soc_cx2072x_get_jack_state);

Why is this symbol exported?

Quoted 6 lines
Quoted 3 lines

It's called from the machine driver. snd_soc_jack_add_gpios() is called in the machine driver side, and it needs the jack_status_check callback that calls this function.

That code shouldn't be in the machine driver, the CODEC driver should request any interrupts it needs itself.

The similar things are done on many other Intel SST board drivers. The current patch just follows the pattern.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

sound/soc/codecs/cx2072x.c line 1742

Quoted 7 lines
sound/soc/codecs/cx2072x.c new file +7 -0
+	/* use flat eq by default */
+	for (ch = 0 ; ch < 2 ; ch++) {
+		for (band = 0; band < CX2072X_PLBK_EQ_BAND_NUM; band++) {
+			cx2072x->plbk_eq[ch][band][1] = 64;
+			cx2072x->plbk_eq[ch][band][10] = 3;
+		}
+	}

Why not use the register defaults?

Quoted 5 lines
Quoted 2 lines

Because it'll become too messy for put flatten array values? The initialization using loop makes more sense in such a case, IMO.

No, that's not the question. The question is why there is any initialization at all?

Again, no idea. These are likely no default values of the hardware registers, and we need to set up some. I *guess* ditto for the initial register table in the above, too.

thanks,

Takashi

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 26 lines · Mark Brown
Quoted 8 lines · Takashi Iwai
Quoted 5 lines · Mark Brown
Quoted 4 lines · Takashi Iwai
Quoted 2 lines · Mark Brown

This looks *very* much like board configuration rather than a patch - there's no kind of test bit and the comments talk specifically about

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

OK, will replace with the straight regmap_multi_reg_write().

That's probably not addressing the issue, a lot of that stuff just doesn't seem like it should be in some fixed configuration table at all.

So what's your alternative suggestion?

Make it either platform data or runtime controls depending on the specific thing being configured. Though...

Quoted 5 lines
Quoted 1 line

Oh, joy. What's the story here? Do you have a datasheet for the part?

Not at all. I just refreshed the already submitted patches since I have a laptop with the codec. I tried to contact Conexant, but in vain, so I decided to submit the renewed one.

Quoted 8 lines

...this is not going to help. At the very least it needs to be abundantly clear to anyone reading the code tht any magic register write sequences like this are being done the way they are due to a badly documented part from an unsupportive vendor rather than because it's a good idea in case someone decides to use the driver as an example. Some comments or something. For safety the bits that look board specific like the pinmuxing should ideally be behind DMI checks, though if nobody else ever bought the CODEC that's probably not so important.

Fair enough. I'm going to put more comments on that part.

Since this is the only code for this codec on the net and all existing platforms (Intel devices, RPi extensions and else) seem working with it -- i.e. all these depend on the same init sequence more or less, so splitting to platform data won't help much in practice.

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The jack detection in ASoC is anyway a bit funky, especially when involved with PM...

What do you mean here? I'm not aware of any issues and the systems I've worked with seemed robust...

There are tons of different ways of implementation for jack controls, with different API usages. IOW, no consistency.

Quoted 6 lines

The board registration interfaces do vary as the hardware isn't very standard so there's a bunch of things you can do for configuration (though there is a generic interface for the 90% case, the main limitation these days on using it is Intel's lack of any sensible firmware interface). I'm not aware of any issues with power management though?

Yeah, I understand the various use cases and coverage for a wide range of hardware implementations, but the lack of the documentation is... not a thing we can be proud of.

Regarding the PM, my statement wasn't straight, sorry. The fact is that ASoC manages so many different levels of (a sort of) "PM". We have the Linux device-object system and runtime PMs, and we have BIAS level control. The machine needed the jack handling via ACPI GPIO IRQ, that is outside the codec, which looks rather like a rare case, and I had hard time to look for the right choice of the API usage.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+EXPORT_SYMBOL_GPL(snd_soc_cx2072x_get_jack_state);

Why is this symbol exported?

It's called from the machine driver. snd_soc_jack_add_gpios() is called in the machine driver side, and it needs the jack_status_check callback that calls this function.

That code shouldn't be in the machine driver, the CODEC driver should request any interrupts it needs itself.

Quoted 7 lines
Quoted 2 lines

The similar things are done on many other Intel SST board drivers. The current patch just follows the pattern.

The only example I can find is the max98095 which it just plain buggy in this regard, that example shouldn't be followed - it looks like it's just plain an oversight in review. Frankly the export was done by me and looks like I was just rushing to fix up a build breakage.

This is rather a question how generic the codec driver should be written. I changed the code in v5 patchset to embed the jack_gpio stuff inside the codec driver side rather than the machine driver, so the whole exported functions can be reduced now. But, of course, it slightly gives more implicit assumption about the hardware implementations, too. Though, the existing code seems to have already fixed gpio / pin setups, so the other setups wouldn't have worked, in anyway.

Quoted 12 lines
Quoted 6 lines
Quoted 2 lines

No, that's not the question. The question is why there is any initialization at all?

Again, no idea. These are likely no default values of the hardware registers, and we need to set up some. I *guess* ditto for the initial register table in the above, too.

Or it's just a taste setting someone had for their particular system. With the earlier register default table an awful lot of it is fairly obvious board specific configuration, doing things like pinmuxing which will vary with the board.

Quoted 6 lines

It's unlikely there are *no* default values - you'd kind of have to try to have a specific register range like this with genuinely floating values. Given that the code for configuring the EQ was broken to IIRC never take effect I'd not be 100% surprisd if someone couldn't figure out why their settings weren't taking effect and just bodged something directly in the driver.

Actually I'm fine to drop the whole EQ stuff that brings lots of black magic. Certainly it'll benefit us for code simplification. Let's see.

thanks,

Takashi

maintainer
#10 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Mark Brown

On Fri, May 03, 2019 at 09:18:26AM +0200, Takashi Iwai wrote:

comments or something. For safety the bits that look board specific like the pinmuxing should ideally be behind DMI checks, though if nobody else ever bought the CODEC that's probably not so important.

Since this is the only code for this codec on the net and all existing platforms (Intel devices, RPi extensions and else) seem working with it -- i.e. all these depend on the same init sequence more or less, so splitting to platform data won't help much in practice.

Yeah, like I say that's a bit more nice to have given that it looks like there's basically one system using the thing.

Quoted 10 lines
Quoted 6 lines

The board registration interfaces do vary as the hardware isn't very standard so there's a bunch of things you can do for configuration (though there is a generic interface for the 90% case, the main limitation these days on using it is Intel's lack of any sensible firmware interface). I'm not aware of any issues with power management though?

Yeah, I understand the various use cases and coverage for a wide range of hardware implementations, but the lack of the documentation is... not a thing we can be proud of.

The bits that vary are driver specific interfaces so any sort of general documentation is pretty hard. The core stuff all at least has kerneldoc which is about average here.

Quoted 6 lines

Regarding the PM, my statement wasn't straight, sorry. The fact is that ASoC manages so many different levels of (a sort of) "PM". We have the Linux device-object system and runtime PMs, and we have BIAS level control. The machine needed the jack handling via ACPI GPIO IRQ, that is outside the codec, which looks rather like a rare case, and I had hard time to look for the right choice of the API usage.

The reason you're not finding much handling for interrupt GPIOs is that if something is an interrupt it should be going through the kernel interrupt interfaces, even if the pin that is providing the interrupt has GPIO support the code should just ignore that and let the frameworks deal with things. The only exception that comes up is that there's a few devices that manually emulate level triggered interrupts with GPIOs and edge triggered interrupts for cases where controllers only provide level triggers, unfortunately nobody had the time/enthusiasm to push that emulation into the interrupt core but fortunately few hardware designers are implementing edge triggered interrupt controllers these days.

Quoted 8 lines

This is rather a question how generic the codec driver should be written. I changed the code in v5 patchset to embed the jack_gpio stuff inside the codec driver side rather than the machine driver, so the whole exported functions can be reduced now. But, of course, it slightly gives more implicit assumption about the hardware implementations, too. Though, the existing code seems to have already fixed gpio / pin setups, so the other setups wouldn't have worked, in anyway.

Like I say if the device is using the fact that the pin is a GPIO there's quite likely something wrong - that shouldn't be something that the user of an interrupt should need to see.

Quoted 10 lines
Quoted 6 lines

It's unlikely there are *no* default values - you'd kind of have to try to have a specific register range like this with genuinely floating values. Given that the code for configuring the EQ was broken to IIRC never take effect I'd not be 100% surprisd if someone couldn't figure out why their settings weren't taking effect and just bodged something directly in the driver.

Actually I'm fine to drop the whole EQ stuff that brings lots of black magic. Certainly it'll benefit us for code simplification. Let's see.

Probably worth checking to make sure the default EQ setup isn't too awful (though I guess the EQ is just turned off by default so it'll just be an uncorrected speaker/headphone which should be fine if not ideal).

#11 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 10 lines · Mark Brown
Quoted 9 lines

This is rather a question how generic the codec driver should be written. I changed the code in v5 patchset to embed the jack_gpio stuff inside the codec driver side rather than the machine driver, so the whole exported functions can be reduced now. But, of course, it slightly gives more implicit assumption about the hardware implementations, too. Though, the existing code seems to have already fixed gpio / pin setups, so the other setups wouldn't have worked, in anyway.

Quoted 3 lines

Like I say if the device is using the fact that the pin is a GPIO there's quite likely something wrong - that shouldn't be something that the user of an interrupt should need to see.

Yeah, unfortunately we have no reference, so the only chance would be to test with another board that has a different setup.

Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

It's unlikely there are *no* default values - you'd kind of have to try to have a specific register range like this with genuinely floating values. Given that the code for configuring the EQ was broken to IIRC never take effect I'd not be 100% surprisd if someone couldn't figure out why their settings weren't taking effect and just bodged something directly in the driver.

Quoted 7 lines
Quoted 3 lines

Actually I'm fine to drop the whole EQ stuff that brings lots of black magic. Certainly it'll benefit us for code simplification. Let's see.

Probably worth checking to make sure the default EQ setup isn't too awful (though I guess the EQ is just turned off by default so it'll just be an uncorrected speaker/headphone which should be fine if not ideal).

A good point. I checked the status now, and found that actually the EQ and others won't appear in the normal playback / capture via HiFi route, but only through DSP. Since the normal usages with UCM profile goes only via HiFi, EQ/DRC don't play any role. So it's OK to remove them, at least, for normal PC usages, as well as RPi HiFi extensions, as it seems.

thanks,

Takashi

maintainer
#12 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 8 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

Like I say if the device is using the fact that the pin is a GPIO there's quite likely something wrong - that shouldn't be something that the user of an interrupt should need to see.

Yeah, unfortunately we have no reference, so the only chance would be to test with another board that has a different setup.

The GPIO/IRQ equivalence thing should just be a purely Linux internal thing - looking at the driver it appears that there's no need to look at the GPIO status, Linux can tell if something is plugged in purely by reading the chip registers so the jack status function could directly be the interrupt handler.

#13 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 8 lines · Mark Brown
Quoted 5 lines · Takashi Iwai
Quoted 3 lines · Mark Brown

Like I say if the device is using the fact that the pin is a GPIO there's quite likely something wrong - that shouldn't be something that the user of an interrupt should need to see.

Quoted 8 lines
Quoted 2 lines

Yeah, unfortunately we have no reference, so the only chance would be to test with another board that has a different setup.

The GPIO/IRQ equivalence thing should just be a purely Linux internal thing - looking at the driver it appears that there's no need to look at the GPIO status, Linux can tell if something is plugged in purely by reading the chip registers so the jack status function could directly be the interrupt handler.

But it can't see the button status or detect the headset type without reading the codec's magic registers... So some help from the codec side is required, and the irq handler isn't in the codec side because there is no i2c irq assigned but only ACPI gpio, as far as I checked.

thanks,

Takashi

maintainer
#14 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Mark Brown

The GPIO/IRQ equivalence thing should just be a purely Linux internal thing - looking at the driver it appears that there's no need to look at the GPIO status, Linux can tell if something is plugged in purely by reading the chip registers so the jack status function could directly be the interrupt handler.

But it can't see the button status or detect the headset type without reading the codec's magic registers... So some help from the codec side is required, and the irq handler isn't in the codec side because

The whole thing should be in the CODEC side.

Quoted 1 line

there is no i2c irq assigned but only ACPI gpio, as far as I checked.

You can map through an ACPI GPIO to an interrupt without worrying about the fact that it's mapped as a GPIO in ACPI IIRC - if you can't there's lots of other drivers are going to have issues.

#15 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 14 lines · Mark Brown
Quoted 11 lines · Takashi Iwai
Quoted 5 lines · Mark Brown

The GPIO/IRQ equivalence thing should just be a purely Linux internal thing - looking at the driver it appears that there's no need to look at the GPIO status, Linux can tell if something is plugged in purely by reading the chip registers so the jack status function could directly be the interrupt handler.

But it can't see the button status or detect the headset type without reading the codec's magic registers... So some help from the codec side is required, and the irq handler isn't in the codec side because

Quoted 7 lines

The whole thing should be in the CODEC side.

Quoted 1 line

there is no i2c irq assigned but only ACPI gpio, as far as I checked.

You can map through an ACPI GPIO to an interrupt without worrying about the fact that it's mapped as a GPIO in ACPI IIRC - if you can't there's lots of other drivers are going to have issues.

But what gives a benefit? It needs more plumbing between codec and machine driver. The i2c probe doesn't give the irq, so you'd need and extra stuff to enable the irq in a different route if you'd need to implement the handler in the codec driver.

Actually, my latest patchset already eliminates the exported stuff by moving to set_jack callback like some other drivers do. If you have an idea for further simplification / fixes, let me know.

I haven't submitted because of the merge window. The patch is found at topic/soc-cx2072x-5.2 branch, the commit is
https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/commit/?h=topic/soc-cx2072x-5.2&id=ca7f4eee5ecbefcf347f5a4984c0a17629360186

thanks,

Takashi

maintainer
#16 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

Quoted 4 lines · Takashi Iwai
Quoted 1 line · Mark Brown
Quoted 1 line

there is no i2c irq assigned but only ACPI gpio, as far as I checked.

Quoted 8 lines
Quoted 3 lines

You can map through an ACPI GPIO to an interrupt without worrying about the fact that it's mapped as a GPIO in ACPI IIRC - if you can't there's lots of other drivers are going to have issues.

But what gives a benefit? It needs more plumbing between codec and machine driver. The i2c probe doesn't give the irq, so you'd need and extra stuff to enable the irq in a different route if you'd need to implement the handler in the codec driver.

Handling the interrupt entirely within the CODEC driver *reduces* the coupling between the CODEC and machine drivers, making it more possible to use the standard set_jack() interface and generic machine drivers with the CODEC drivers.

Actually looking a little I think you may need some ACPI specific parsing code in the probe function to look up the GPIO but that should just be like all the other DMI quirking stuff, hidden in the CODEC driver. It's really sad how bad a job Intel have done of making firmware interfaces for their audio hardware. I had thought people had managed to hide all that stuff but I'm not seeing the code right now.

Quoted 7 lines

Actually, my latest patchset already eliminates the exported stuff by moving to set_jack callback like some other drivers do. If you have an idea for further simplification / fixes, let me know.

I haven't submitted because of the merge window. The patch is found at topic/soc-cx2072x-5.2 branch, the commit is
https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git/commit/?h=topic/soc-cx2072x-5.2&id=ca7f4eee5ecbefcf347f5a4984c0a17629360186

I'm on a train with intermittent network connectivity right now (and getting near to my destination too)...

#17 lore raw

Re: [PATCH 1/2] ASoC: Add support for Conexant CX2072X CODEC

In reply to a message not in the archive
Quoted 8 lines · Mark Brown
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

+#define cx2072x_plbk_eq_en_info snd_ctl_boolean_mono_info

Why not just use the function directly rather than hiding it?

Just a standard idiom. Can be replaced if preferred.

Please.

BTW, a good reason for the style above is that it makes code more undrestandable. For defining a ctl element, typically we define three callback functions, info, get and put, in that order:

static int foo_info()

{
	....
}

static int foo_get()

{
	....
}

static int foo_put()

{
	...
};

and often the actual snd_kcontrol_new table containing these callbacks appears much later, where you'd need to scroll down a few screens to read that point.

In the above, especially defining the info callback at the beginning is important. By reading foo_init() at first, readers can know which type (int, boolean, enum, etc) and the number of elements to be used in get/put callbacks beforehand. It's a commonly seen mistake, for example, that a wrong type (e.g. integer) is passed to info callback while enum type is used in the get/put.

The #define above keeps this foo_info() definition while optimizing with the standard helper. If we drop this and set snd_ctl_boolean_mono_info directly in the snd_kcontrol_new entry, you'll have to go and back the screen just to take a look at the info callback.

That's why I called it a standard idiom. It's not strictly necessary, but often help reading / reviewing the code. Though, it's just another bikeshed theme, so I'm not sticking with this style.

thanks,

Takashi

#18 lore raw

PATCH 2/2 ASoC: Intel: Add machine driver for CX2072X on BYT/CHT platforms

In reply to Takashi Iwai

This is an implementation of a machine driver needed for Conexant CX2072X codec on Intel Baytrail and Cherrytrail platforms. The current patch is based on the initial work by Pierre-Louis Bossart and the other Intel machine drivers.

The jack detection support (driven via the standard GPIO) was added on top of the original work.

No SOF support yet, so the corresponding entries are commented out.

Tested with ASUS E200HA laptop.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=115531

---
 sound/soc/intel/boards/Kconfig                    |  11 +
 sound/soc/intel/boards/Makefile                   |   2 +
 sound/soc/intel/boards/bytcht_cx2072x.c           | 285 ++++++++++++++++++++++
 sound/soc/intel/common/soc-acpi-intel-byt-match.c |   8 +
 sound/soc/intel/common/soc-acpi-intel-cht-match.c |   8 +
 5 files changed, 314 insertions(+)
 create mode 100644 sound/soc/intel/boards/bytcht_cx2072x.c
sound/soc/intel/boards/Kconfig +11 -0
index 12d6b73e9531..e8494ef96447 100644
@@ -136,6 +136,17 @@ config SND_SOC_INTEL_CHT_BSW_NAU8824_MACH
 	  Say Y or m if you have such a device. This is a recommended option.
 	  If unsure select "N".
 
+config SND_SOC_INTEL_BYT_CHT_CX2072X_MACH
+	tristate "Baytrail & Cherrytrail with CX2072X codec"
+	depends on X86_INTEL_LPSS && I2C && ACPI
+	select SND_SOC_ACPI
+	select SND_SOC_CX2072X
+	help
+	  This adds support for ASoC machine driver for Intel(R) Baytrail &
+	  Cherrytrail platforms with Conexant CX2072X audio codec.
+	  Say Y or m if you have such a device. This is a recommended option.
+	  If unsure select "N".
+
 config SND_SOC_INTEL_BYT_CHT_DA7213_MACH
 	tristate "Baytrail & Cherrytrail with DA7212/7213 codec"
 	depends on X86_INTEL_LPSS && I2C && ACPI
sound/soc/intel/boards/Makefile +2 -0
index bf072ea299b7..098ad7998b43 100644
@@ -13,6 +13,7 @@ snd-soc-sst-cht-bsw-rt5672-objs := cht_bsw_rt5672.o
 snd-soc-sst-cht-bsw-rt5645-objs := cht_bsw_rt5645.o
 snd-soc-sst-cht-bsw-max98090_ti-objs := cht_bsw_max98090_ti.o
 snd-soc-sst-cht-bsw-nau8824-objs := cht_bsw_nau8824.o
+snd-soc-sst-byt-cht-cx2072x-objs := bytcht_cx2072x.o
 snd-soc-sst-byt-cht-da7213-objs := bytcht_da7213.o
 snd-soc-sst-byt-cht-es8316-objs := bytcht_es8316.o
 snd-soc-sst-byt-cht-nocodec-objs := bytcht_nocodec.o
@@ -40,6 +41,7 @@ obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5672_MACH) += snd-soc-sst-cht-bsw-rt5672.o
 obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_RT5645_MACH) += snd-soc-sst-cht-bsw-rt5645.o
 obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_MAX98090_TI_MACH) += snd-soc-sst-cht-bsw-max98090_ti.o
 obj-$(CONFIG_SND_SOC_INTEL_CHT_BSW_NAU8824_MACH) += snd-soc-sst-cht-bsw-nau8824.o
+obj-$(CONFIG_SND_SOC_INTEL_BYT_CHT_CX2072X_MACH) += snd-soc-sst-byt-cht-cx2072x.o
 obj-$(CONFIG_SND_SOC_INTEL_BYT_CHT_DA7213_MACH) += snd-soc-sst-byt-cht-da7213.o
 obj-$(CONFIG_SND_SOC_INTEL_BYT_CHT_ES8316_MACH) += snd-soc-sst-byt-cht-es8316.o
 obj-$(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH) += snd-soc-sst-byt-cht-nocodec.o
sound/soc/intel/boards/bytcht_cx2072x.c new file +285 -0

285 lines not on this page · raw message

sound/soc/intel/common/soc-acpi-intel-byt-match.c +8 -0
index fe812a909db4..5387a82c2cf5 100644
@@ -211,6 +211,14 @@ struct snd_soc_acpi_mach  snd_soc_acpi_intel_baytrail_machines[] = {
 		.sof_fw_filename = "sof-byt.ri",
 		.sof_tplg_filename = "sof-byt-max98090.tplg",
 	},
+	{
+		.id = "14F10720",
+		.drv_name = "bytcht_cx2072x",
+		.fw_filename = "intel/fw_sst_0f28.bin",
+		.board = "bytcht_cx2072x",
+		/* .sof_fw_filename = "sof-byt.ri", */
+		/* .sof_tplg_filename = "sof-byt-cx2072x.tplg", */
+	},
 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
 	/*
 	 * This is always last in the table so that it is selected only when
sound/soc/intel/common/soc-acpi-intel-cht-match.c +8 -0
index deafd87cc764..69ecbb88c171 100644
@@ -169,6 +169,14 @@ struct snd_soc_acpi_mach  snd_soc_acpi_intel_cherrytrail_machines[] = {
 		.sof_fw_filename = "sof-cht.ri",
 		.sof_tplg_filename = "sof-cht-rt5651.tplg",
 	},
+	{
+		.id = "14F10720",
+		.drv_name = "bytcht_cx2072x",
+		.fw_filename = "intel/fw_sst_22a8.bin",
+		.board = "bytcht_cx2072x",
+		/* .sof_fw_filename = "sof-cht.ri", */
+		/* .sof_tplg_filename = "sof-cht-cx2072x.tplg", */
+	},
 #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
 	/*
 	 * This is always last in the table so that it is selected only when
Signature · 1 line
2.16.4
#19 lore raw

Re: [PATCH 2/2] ASoC: Intel: Add machine driver for CX2072X on BYT/CHT platforms

Quoted 9 lines · Takashi Iwai

This is an implementation of a machine driver needed for Conexant CX2072X codec on Intel Baytrail and Cherrytrail platforms. The current patch is based on the initial work by Pierre-Louis Bossart and the other Intel machine drivers.

The jack detection support (driven via the standard GPIO) was added on top of the original work.

No SOF support yet, so the corresponding entries are commented out.

SOF support is trivial to add, can we help you here?

sound/soc/intel/boards/Kconfig config SND_SOC_INTEL_CHT_BSW_NAU8824_MACH · line 141

Quoted 3 lines
sound/soc/intel/boards/Kconfig +3 -0
+config SND_SOC_INTEL_BYT_CHT_CX2072X_MACH
+	tristate "Baytrail & Cherrytrail with CX2072X codec"
+	depends on X86_INTEL_LPSS && I2C && ACPI

Didn't Mark recently split this in two, with X86_INTEL_LPSS || COMPILE_TEST?

Quoted 27 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +27 -0
+static int byt_cht_cx2072x_fixup(struct snd_soc_pcm_runtime *rtd,
+				 struct snd_pcm_hw_params *params)
+{
+	struct snd_interval *rate =
+		hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	struct snd_interval *channels =
+		hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+	int ret;
+
+	/* The DSP will covert the FE rate to 48k, stereo, 24bits */
+	rate->min = rate->max = 48000;
+	channels->min = channels->max = 2;
+
+	/* set SSP2 to 24-bit */
+	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
+
+	/*
+	 * Default mode for SSP configuration is TDM 4 slot, override config
+	 * with explicit setting to I2S 2ch 24-bit. The word length is set with
+	 * dai_set_tdm_slot() since there is no other API exposed
+	 */
+	ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
+				SND_SOC_DAIFMT_I2S     |
+				SND_SOC_DAIFMT_NB_NF   |
+				SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0) {
+		dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);

sound/soc/intel/boards/bytcht_cx2072x.c line 163

Quoted 10 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +10 -0
+		return ret;
+	}
+
+	ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
+	if (ret < 0) {
+		dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
+		return ret;
+	}
+
+	snd_soc_dai_set_bclk_ratio(rtd->codec_dai, 50);

that part would be problematic for SOF. IIRC we put all clock-related stuff in the init, and ignore the fixups to use topology-based information instead. If this call to _set_bclk_ratio can be moved to the init it's more future-proof. Is there a reason to do this here in the fixup?

Quoted 30 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +30 -0
+static struct snd_soc_dai_link byt_cht_cx2072x_dais[] = {
+	[MERR_DPCM_AUDIO] = {
+		.name = "Audio Port",
+		.stream_name = "Audio",
+		.cpu_dai_name = "media-cpu-dai",
+		.codec_dai_name = "snd-soc-dummy-dai",
+		.codec_name = "snd-soc-dummy",
+		.platform_name = "sst-mfld-platform",
+		.nonatomic = true,
+		.dynamic = 1,
+		.dpcm_playback = 1,
+		.dpcm_capture = 1,
+		.ops = &byt_cht_cx2072x_aif1_ops,
+	},
+	[MERR_DPCM_DEEP_BUFFER] = {
+		.name = "Deep-Buffer Audio Port",
+		.stream_name = "Deep-Buffer Audio",
+		.cpu_dai_name = "deepbuffer-cpu-dai",
+		.codec_dai_name = "snd-soc-dummy-dai",
+		.codec_name = "snd-soc-dummy",
+		.platform_name = "sst-mfld-platform",
+		.nonatomic = true,
+		.dynamic = 1,
+		.dpcm_playback = 1,
+		.ops = &byt_cht_cx2072x_aif1_ops,
+	},
+	/* back ends */
+	{
+		.name = "SSP2-Codec",
+		.id = 1,

sound/soc/intel/boards/bytcht_cx2072x.c line 216

Quoted 10 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +10 -0
+		.cpu_dai_name = "ssp2-port",
+		.platform_name = "sst-mfld-platform",
+		.no_pcm = 1,
+		.codec_dai_name = "cx2072x-hifi",
+		.codec_name = "i2c-14F10720:00",
+		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
+					      | SND_SOC_DAIFMT_CBS_CFS,
+		.init = byt_cht_cx2072x_init,
+		.be_hw_params_fixup = byt_cht_cx2072x_fixup,
+		.nonatomic = true,

I can't recall if this .atomic is needed or not for back-ends.

Quoted 17 lines
sound/soc/intel/common/soc-acpi-intel-byt-match.c +8 -0
+	{
+		.id = "14F10720",
+		.drv_name = "bytcht_cx2072x",
+		.fw_filename = "intel/fw_sst_0f28.bin",
+		.board = "bytcht_cx2072x",
+		/* .sof_fw_filename = "sof-byt.ri", */
+		/* .sof_tplg_filename = "sof-byt-cx2072x.tplg", */
+	},
  #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
  	/*
  	 * This is always last in the table so that it is selected only when
sound/soc/intel/common/soc-acpi-intel-cht-match.c +0 -0
index deafd87cc764..69ecbb88c171 100644
@@ -169,6 +169,14 @@ struct snd_soc_acpi_mach  snd_soc_acpi_intel_cherrytrail_machines[] = {
  		.sof_fw_filename = "sof-cht.ri",

sound/soc/intel/common/soc-acpi-intel-cht-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { · line 179

Quoted 10 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +8 -0
  		.sof_tplg_filename = "sof-cht-rt5651.tplg",
  	},
+	{
+		.id = "14F10720",
+		.drv_name = "bytcht_cx2072x",
+		.fw_filename = "intel/fw_sst_22a8.bin",
+		.board = "bytcht_cx2072x",
+		/* .sof_fw_filename = "sof-cht.ri", */
+		/* .sof_tplg_filename = "sof-cht-cx2072x.tplg", */
+	},

I'd uncomment those two ACPI machine parts. There is not risk unless SOF is actually enabled.

#20 lore raw

Re: [PATCH 2/2] ASoC: Intel: Add machine driver for CX2072X on BYT/CHT platforms

Quoted 7 lines · Pierre-Louis Bossart
Quoted 5 lines · Takashi Iwai

This is an implementation of a machine driver needed for Conexant CX2072X codec on Intel Baytrail and Cherrytrail platforms. The current patch is based on the initial work by Pierre-Louis Bossart and the other Intel machine drivers.

Quoted 6 lines
Quoted 4 lines

The jack detection support (driven via the standard GPIO) was added on top of the original work.

No SOF support yet, so the corresponding entries are commented out.

SOF support is trivial to add, can we help you here?

I just had no time to take a deeper look at that direction, so it's a thing I'd like to play at my next spare time.

Quoted 5 lines

sound/soc/intel/boards/Kconfig config SND_SOC_INTEL_CHT_BSW_NAU8824_MACH · line 141

Quoted 3 lines
sound/soc/intel/boards/Kconfig +3 -0
+config SND_SOC_INTEL_BYT_CHT_CX2072X_MACH
+	tristate "Baytrail & Cherrytrail with CX2072X codec"
+	depends on X86_INTEL_LPSS && I2C && ACPI

Didn't Mark recently split this in two, with X86_INTEL_LPSS || COMPILE_TEST?

The entry I just copied, CONFIG_SND_SOC_INTEL_BYT_CHT_ES8316_MACH, still has this style, so no, it doesn't seem applied.

Quoted 35 lines
Quoted 35 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +35 -0
+static int byt_cht_cx2072x_fixup(struct snd_soc_pcm_runtime *rtd,
+				 struct snd_pcm_hw_params *params)
+{
+	struct snd_interval *rate =
+		hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	struct snd_interval *channels =
+		hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+	int ret;
+
+	/* The DSP will covert the FE rate to 48k, stereo, 24bits */
+	rate->min = rate->max = 48000;
+	channels->min = channels->max = 2;
+
+	/* set SSP2 to 24-bit */
+	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
+
+	/*
+	 * Default mode for SSP configuration is TDM 4 slot, override config
+	 * with explicit setting to I2S 2ch 24-bit. The word length is set with
+	 * dai_set_tdm_slot() since there is no other API exposed
+	 */
+	ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
+				SND_SOC_DAIFMT_I2S     |
+				SND_SOC_DAIFMT_NB_NF   |
+				SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0) {
+		dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
+		return ret;
+	}
+
+	ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
+	if (ret < 0) {
+		dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
+		return ret;
+	}
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	snd_soc_dai_set_bclk_ratio(rtd->codec_dai, 50);

that part would be problematic for SOF. IIRC we put all clock-related stuff in the init, and ignore the fixups to use topology-based information instead. If this call to _set_bclk_ratio can be moved to the init it's more future-proof. Is there a reason to do this here in the fixup?

No particular reason from my side. I just took over your code ;)

That is, it'd be appreciated if you can give a fixup patch that can be applied on top.

Quoted 34 lines
Quoted 34 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +34 -0
+static struct snd_soc_dai_link byt_cht_cx2072x_dais[] = {
+	[MERR_DPCM_AUDIO] = {
+		.name = "Audio Port",
+		.stream_name = "Audio",
+		.cpu_dai_name = "media-cpu-dai",
+		.codec_dai_name = "snd-soc-dummy-dai",
+		.codec_name = "snd-soc-dummy",
+		.platform_name = "sst-mfld-platform",
+		.nonatomic = true,
+		.dynamic = 1,
+		.dpcm_playback = 1,
+		.dpcm_capture = 1,
+		.ops = &byt_cht_cx2072x_aif1_ops,
+	},
+	[MERR_DPCM_DEEP_BUFFER] = {
+		.name = "Deep-Buffer Audio Port",
+		.stream_name = "Deep-Buffer Audio",
+		.cpu_dai_name = "deepbuffer-cpu-dai",
+		.codec_dai_name = "snd-soc-dummy-dai",
+		.codec_name = "snd-soc-dummy",
+		.platform_name = "sst-mfld-platform",
+		.nonatomic = true,
+		.dynamic = 1,
+		.dpcm_playback = 1,
+		.ops = &byt_cht_cx2072x_aif1_ops,
+	},
+	/* back ends */
+	{
+		.name = "SSP2-Codec",
+		.id = 1,
+		.cpu_dai_name = "ssp2-port",
+		.platform_name = "sst-mfld-platform",
+		.no_pcm = 1,
+		.codec_dai_name = "cx2072x-hifi",
Quoted 8 lines

sound/soc/intel/boards/bytcht_cx2072x.c line 216

Quoted 6 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +6 -0
+		.codec_name = "i2c-14F10720:00",
+		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
+					      | SND_SOC_DAIFMT_CBS_CFS,
+		.init = byt_cht_cx2072x_init,
+		.be_hw_params_fixup = byt_cht_cx2072x_fixup,
+		.nonatomic = true,

I can't recall if this .atomic is needed or not for back-ends.

If FE requires it, BE must set it, too, in general.

Quoted 22 lines
Quoted 22 lines
sound/soc/intel/common/soc-acpi-intel-byt-match.c +8 -0
+	{
+		.id = "14F10720",
+		.drv_name = "bytcht_cx2072x",
+		.fw_filename = "intel/fw_sst_0f28.bin",
+		.board = "bytcht_cx2072x",
+		/* .sof_fw_filename = "sof-byt.ri", */
+		/* .sof_tplg_filename = "sof-byt-cx2072x.tplg", */
+	},
  #if IS_ENABLED(CONFIG_SND_SOC_INTEL_BYT_CHT_NOCODEC_MACH)
  	/*
  	 * This is always last in the table so that it is selected only when
sound/soc/intel/common/soc-acpi-intel-cht-match.c +3 -0
index deafd87cc764..69ecbb88c171 100644
@@ -169,6 +169,14 @@ struct snd_soc_acpi_mach  snd_soc_acpi_intel_cherrytrail_machines[] = {
  		.sof_fw_filename = "sof-cht.ri",
  		.sof_tplg_filename = "sof-cht-rt5651.tplg",
  	},
+	{
+		.id = "14F10720",
+		.drv_name = "bytcht_cx2072x",
Quoted 8 lines

sound/soc/intel/common/soc-acpi-intel-cht-match.c struct snd_soc_acpi_mach snd_soc_acpi_intel_cherrytrail_machines[] = { · line 179

Quoted 5 lines
sound/soc/intel/common/soc-acpi-intel-cht-match.c +5 -0
+		.fw_filename = "intel/fw_sst_22a8.bin",
+		.board = "bytcht_cx2072x",
+		/* .sof_fw_filename = "sof-cht.ri", */
+		/* .sof_tplg_filename = "sof-cht-cx2072x.tplg", */
+	},

I'd uncomment those two ACPI machine parts. There is not risk unless SOF is actually enabled.

OK, will do that.

Thanks for a quick review!

Takashi

#21 lore raw

Re: [PATCH 2/2] ASoC: Intel: Add machine driver for CX2072X on BYT/CHT platforms

Quoted 45 lines · Takashi Iwai
Quoted 36 lines
Quoted 36 lines
sound/soc/intel/boards/bytcht_cx2072x.c new file +35 -0
+static int byt_cht_cx2072x_fixup(struct snd_soc_pcm_runtime *rtd,
+				 struct snd_pcm_hw_params *params)
+{
+	struct snd_interval *rate =
+		hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
+	struct snd_interval *channels =
+		hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
+	int ret;
+
+	/* The DSP will covert the FE rate to 48k, stereo, 24bits */
+	rate->min = rate->max = 48000;
+	channels->min = channels->max = 2;
+
+	/* set SSP2 to 24-bit */
+	params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
+
+	/*
+	 * Default mode for SSP configuration is TDM 4 slot, override config
+	 * with explicit setting to I2S 2ch 24-bit. The word length is set with
+	 * dai_set_tdm_slot() since there is no other API exposed
+	 */
+	ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
+				SND_SOC_DAIFMT_I2S     |
+				SND_SOC_DAIFMT_NB_NF   |
+				SND_SOC_DAIFMT_CBS_CFS);
+	if (ret < 0) {
+		dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
+		return ret;
+	}
+
+	ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
+	if (ret < 0) {
+		dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
+		return ret;
+	}
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	snd_soc_dai_set_bclk_ratio(rtd->codec_dai, 50);

that part would be problematic for SOF. IIRC we put all clock-related stuff in the init, and ignore the fixups to use topology-based information instead. If this call to _set_bclk_ratio can be moved to the init it's more future-proof. Is there a reason to do this here in the fixup?

Quoted 4 lines

No particular reason from my side. I just took over your code ;)

That is, it'd be appreciated if you can give a fixup patch that can be applied on top.

OK, I tried just moving snd_soc_dai_set_bclk_ratio() into the init callback, and it seems working fine. The fix will be included in v2 patch.

thanks,

Takashi