Skip to contentSkip to conversation

ASoC: Add MediaTek MT6660 Speaker Amp Driver

PATCH Superseded Jeff Chang 4 participants 7 messages Jan 14, 2020

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jeff Chang

author
#0 lore raw

PATCH v6 1/1 ASoC: Add MediaTek MT6660 Speaker Amp Driver

From: Jeff Chang <[email protected]>

The MT6660 is a boosted BTL class-D amplifier with V/I sensing. A built-in DC-DC step-up converter is used to provide efficient power for class-D amplifier with multi-level class-G operation. The digital audio interface supports I2S, left-justified, right-justified, TDM and DSP A/B format for audio in with a data out used for chip information like voltage sense and current sense, which are able to be monitored via DATAO through proper

---
 sound/soc/codecs/Kconfig  |  11 +
 sound/soc/codecs/Makefile |   2 +
 sound/soc/codecs/mt6660.c | 533 ++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/mt6660.h |  77 +++++++
 4 files changed, 623 insertions(+)
 create mode 100644 sound/soc/codecs/mt6660.c
 create mode 100644 sound/soc/codecs/mt6660.h

changelogs between v6 & v5
- remove parse DT and apply function about Chip INIT SETTING.
- remove DT binding Documentation.

changelogs between v5 & v4
- remove redundant initialization.
- use packed structures.
- remove useless switch case.
- take care of memory allocation failures.

changelogs between v4 & v3
- remove unnecessary kcontrols.
- modify copy right header.
- use dev_dbg instead of dev_info.
- add necessary debug message.
- add DT binding documentation.
- add space before } at every table.

changelogs between v3 & v2

- modify MT6660 Kconfig, remove unnecessary selection.
- remove my own debug io interface. use standard regmap for debugging.
- remove regmap volatile ops, we do not use cache.
- remove component io read/write function, use snd_soc_component_init_regmap.
- remove init setting write code. Using parsing dts to set them.
- remove unnecessary pr_info log message.
- remove mt6660_component_put_volsw. Using snd_soc_get_volsw.

sound/soc/codecs/Kconfig +11 -0
index 229cc89..f135fbb 100644
@@ -122,6 +122,7 @@ config SND_SOC_ALL_CODECS
 	select SND_SOC_ML26124 if I2C
 	select SND_SOC_MT6351 if MTK_PMIC_WRAP
 	select SND_SOC_MT6358 if MTK_PMIC_WRAP
+	select SND_SOC_MT6660 if I2C
 	select SND_SOC_NAU8540 if I2C
 	select SND_SOC_NAU8810 if I2C
 	select SND_SOC_NAU8822 if I2C
@@ -1465,6 +1466,16 @@ config SND_SOC_MT6358
 	  Enable support for the platform which uses MT6358 as
 	  external codec device.
 
+config SND_SOC_MT6660
+	tristate "Mediatek MT6660 Speaker Amplifier"
+	depends on I2C
+	help
+	  MediaTek MT6660 is a smart power amplifier which contain
+	  speaker protection, multi-band DRC, equalizer functions.
+	  Select N if you don't have MT6660 on board.
+	  Select M to build this as module.
+
+
 config SND_SOC_NAU8540
        tristate "Nuvoton Technology Corporation NAU85L40 CODEC"
        depends on I2C
sound/soc/codecs/Makefile +2 -0
index c498373..2b6814c 100644
@@ -119,6 +119,7 @@ snd-soc-msm8916-analog-objs := msm8916-wcd-analog.o
 snd-soc-msm8916-digital-objs := msm8916-wcd-digital.o
 snd-soc-mt6351-objs := mt6351.o
 snd-soc-mt6358-objs := mt6358.o
+snd-soc-mt6660-objs := mt6660.o
 snd-soc-nau8540-objs := nau8540.o
 snd-soc-nau8810-objs := nau8810.o
 snd-soc-nau8822-objs := nau8822.o
@@ -403,6 +404,7 @@ obj-$(CONFIG_SND_SOC_MSM8916_WCD_ANALOG) +=snd-soc-msm8916-analog.o
 obj-$(CONFIG_SND_SOC_MSM8916_WCD_DIGITAL) +=snd-soc-msm8916-digital.o
 obj-$(CONFIG_SND_SOC_MT6351)	+= snd-soc-mt6351.o
 obj-$(CONFIG_SND_SOC_MT6358)	+= snd-soc-mt6358.o
+obj-$(CONFIG_SND_SOC_MT6660)	+= snd-soc-mt6660.o
 obj-$(CONFIG_SND_SOC_NAU8540)   += snd-soc-nau8540.o
 obj-$(CONFIG_SND_SOC_NAU8810)   += snd-soc-nau8810.o
 obj-$(CONFIG_SND_SOC_NAU8822)   += snd-soc-nau8822.o
sound/soc/codecs/mt6660.c new file +533 -0

533 lines not on this page · raw message

sound/soc/codecs/mt6660.h new file +77 -0

77 lines not on this page · raw message

Signature · 1 line
2.7.4
#1 lore raw
Quoted 8 lines · Jeff Chang
sound/soc/codecs/Kconfig +0 -0
index 229cc89..f135fbb 100644
@@ -1465,6 +1466,16 @@ config SND_SOC_MT6358
 	  Enable support for the platform which uses MT6358 as
 	  external codec device.
 

sound/soc/codecs/Kconfig config SND_SOC_MT6358 · line 1478

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+config SND_SOC_MT6660
+	tristate "Mediatek MT6660 Speaker Amplifier"
+	depends on I2C
+	help
+	  MediaTek MT6660 is a smart power amplifier which contain
+	  speaker protection, multi-band DRC, equalizer functions.
+	  Select N if you don't have MT6660 on board.
+	  Select M to build this as module.
+
+

One blank line too much here.

Quoted 8 lines
sound/soc/codecs/mt6660.c new file +5 -0
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0 //
+
+// Copyright (c) 2019 MediaTek Inc.
+
+#include <linux/module.h>

sound/soc/codecs/mt6660.c line 15

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/pm_runtime.h>
+#include <linux/delay.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include <sound/pcm_params.h>
+#include <linux/debugfs.h>

Move linux/*.h above sound/*.h inclusion.

sound/soc/codecs/mt6660.c line 19

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+
+#include "mt6660.h"
+
+#pragma pack(push, 1)

Actually packing makes little sense for those use cases. As I mentioned earlier, packing is useful only for either saving some memory (e.g. for a large array) or a strict size definition like ABI.

sound/soc/codecs/mt6660.c line 24

Quoted 5 lines
sound/soc/codecs/mt6660.c new file +5 -0
+struct codec_reg_val {
+	u32 addr;
+	u32 mask;
+	u32 data;
+};

Is this struct used anywhere? If not, kill it.

sound/soc/codecs/mt6660.c line 88

Quoted 1 line
sound/soc/codecs/mt6660.c new file +1 -0
+static struct regmap_config mt6660_regmap_config = {

This can be const.

sound/soc/codecs/mt6660.c line 98

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static int mt6660_codec_dac_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+

A superfluous blank line.

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static int mt6660_component_get_volsw(struct snd_kcontrol *kcontrol,
+				  struct snd_ctl_elem_value *ucontrol)
+{
+	struct snd_soc_component *component =

sound/soc/codecs/mt6660.c line 212

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+		snd_soc_kcontrol_component(kcontrol);
+	struct mt6660_chip *chip = (struct mt6660_chip *)
+		snd_soc_component_get_drvdata(component);
+	int ret = -EINVAL;
+
+	if (!strcmp(kcontrol->id.name, "Chip Rev")) {
+		ucontrol->value.integer.value[0] = chip->chip_rev & 0x0f;
+		ret = 0;
+	}
+	return ret;

So, "T0 SEL" control gets always an error when reading? Then can't we pass simply NULL for get ops instead?

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static int _mt6660_chip_power_on(struct mt6660_chip *chip, int on_off)
+{
+	u8 reg_data;
+	int ret;

sound/soc/codecs/mt6660.c line 248

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+
+	ret = i2c_smbus_read_byte_data(chip->i2c, MT6660_REG_SYSTEM_CTRL);
+	if (ret < 0)
+		return ret;
+	reg_data = (u8)ret;
+	if (on_off)
+		reg_data &= (~0x01);
+	else
+		reg_data |= 0x01;
+	return regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, reg_data);

Hm, this looks like an open-code of forced update bits via regmap. But interestingly there is no corresponding standard helper for that. Essentially it should be regmap_update_bits_base() with force=1.

Mark?

Quoted 5 lines
sound/soc/codecs/mt6660.c new file +5 -0
+static int mt6660_component_aif_hw_params(struct snd_pcm_substream *substream,
+	struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai)
+{
+	int word_len = params_physical_width(hw_params);
+	int aud_bit = params_width(hw_params);

....

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+	switch (aud_bit) {
+	case 16:
+		reg_data = 3;
+		break;

sound/soc/codecs/mt6660.c line 310

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+	case 18:
+		reg_data = 2;
+		break;
+	case 20:
+		reg_data = 1;
+		break;
+	case 24:
+	case 32:
+		reg_data = 0;
+		break;

So here both 24 and 32 bits data are handled equally, and...

....

sound/soc/codecs/mt6660.c

Quoted 2 lines
sound/soc/codecs/mt6660.c new file +2 -0
+	ret = snd_soc_component_update_bits(dai->component,
+		MT6660_REG_TDM_CFG3, 0x3f0, word_len << 4);

... word_len is same for both S32 and S24 formats, so there can be no difference between S24 and S32 format handling in the code. Meanwhile, the supported formats are:

sound/soc/codecs/mt6660.c line 340

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+#define STUB_FORMATS	(SNDRV_PCM_FMTBIT_S16_LE | \
+			SNDRV_PCM_FMTBIT_U16_LE | \
+			SNDRV_PCM_FMTBIT_S24_LE | \
+			SNDRV_PCM_FMTBIT_U24_LE | \
+			SNDRV_PCM_FMTBIT_S32_LE | \
+			SNDRV_PCM_FMTBIT_U32_LE)

Are you sure that S24_* formats really work properly?

Also, the code has no check / setup of the format signedness. Do unsigned formats (U16, U24, etc) really work as expected, too?

Quoted 1 line

+static inline int _mt6660_chip_id_check(struct mt6660_chip *chip)

Drop unnecessary inline (here and other places).
Compiler optimizes well by itself.

sound/soc/codecs/mt6660.c line 388

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+static inline int _mt6660_chip_sw_reset(struct mt6660_chip *chip)
+{
+	int ret;
+
+	/* turn on main pll first, then trigger reset */
+	ret = regmap_write(chip->regmap, 0x03, 0x00);

It's MT6660_REG_SYSTEM_CTRL, right?

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+	if (ret < 0)
+		return ret;
+	ret = regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, 0x80);
+	if (ret < 0)
+		return ret;
+	msleep(30);

sound/soc/codecs/mt6660.c line 404

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+	return 0;
+}
+
+static inline int _mt6660_read_chip_revision(struct mt6660_chip *chip)
+{
+	u8 reg_data[2];
+	int ret;
+
+	ret = i2c_smbus_read_i2c_block_data(
+		chip->i2c, MT6660_REG_DEVID, 2, reg_data);

Why avoiding regmap here? This and chip_id_check() use the raw access by some reason...

thanks,

Takashi

#2 lore raw

Dear Takashi:

Thank for your replying.

1.> +static int mt6660_component_get_volsw(struct snd_kcontrol *kcontrol,

sound/soc/codecs/mt6660.c line 212

Quoted 12 lines
sound/soc/codecs/mt6660.c new file +12 -0
+  struct snd_ctl_elem_value *ucontrol) {
+struct snd_soc_component *component =
+snd_soc_kcontrol_component(kcontrol);
+struct mt6660_chip *chip = (struct mt6660_chip *)
+snd_soc_component_get_drvdata(component);
+int ret = -EINVAL;
+
+if (!strcmp(kcontrol->id.name, "Chip Rev")) {
+ucontrol->value.integer.value[0] = chip->chip_rev & 0x0f;
+ret = 0;
+}
+return ret;

So, "T0 SEL" control gets always an error when reading? Then can't we pass simply NULL for get ops instead?

Jeff : T0 SEL use snd_soc_get_volsw, it will not use this function.

2. So here both 24 and 32 bits data are handled equally, and...

....

Review

Quoted 2 lines
(quoted diff) +2 -0
+ret = snd_soc_component_update_bits(dai->component,
+MT6660_REG_TDM_CFG3, 0x3f0, word_len << 4);

... word_len is same for both S32 and S24 formats, so there can be no difference between S24 and S32 format handling in the code. Meanwhile, the supported formats are:

sound/soc/codecs/mt6660.c line 340

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+#define STUB_FORMATS(SNDRV_PCM_FMTBIT_S16_LE | \
+SNDRV_PCM_FMTBIT_U16_LE | \
+SNDRV_PCM_FMTBIT_S24_LE | \
+SNDRV_PCM_FMTBIT_U24_LE | \
+SNDRV_PCM_FMTBIT_S32_LE | \
+SNDRV_PCM_FMTBIT_U32_LE)

Are you sure that S24_* formats really work properly?

Also, the code has no check / setup of the format signedness. Do unsigned formats (U16, U24, etc) really work as expected, too?

Jeff : Yes, it works.

I will create a new patch later.

Thanks & BRs
Jeff Chang
Tel 886-3-5526789 Ext 2357
14F, No. 8, Taiyuen 1st st., Zhubei City,
Hsinchu County, Taiwan 30288

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Tuesday, January 14, 2020 3:44 PM
To: Jeff Chang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; jeff_chang(張世佳) <[email protected]>
Subject: Re: [PATCH v6] ASoC: Add MediaTek MT6660 Speaker Amp Driver

Quoted 8 lines · Jeff Chang
sound/soc/codecs/Kconfig index renamed from sound/soc/codecs/Kconfig +0 -0

229cc89..f135fbb 100644

sound/soc/codecs/Kconfig +0 -0
@@ -1465,6 +1466,16 @@ config SND_SOC_MT6358
   Enable support for the platform which uses MT6358 as
   external codec device.
 

sound/soc/codecs/Kconfig config SND_SOC_MT6358 · line 1478

Quoted 10 lines
sound/soc/codecs/Kconfig +10 -0
+config SND_SOC_MT6660
+tristate "Mediatek MT6660 Speaker Amplifier"
+depends on I2C
+help
+  MediaTek MT6660 is a smart power amplifier which contain
+  speaker protection, multi-band DRC, equalizer functions.
+  Select N if you don't have MT6660 on board.
+  Select M to build this as module.
+
+

One blank line too much here.

Quoted 8 lines
sound/soc/codecs/mt6660.c new file +5 -0
@@ -0,0 +1,533 @@
+// SPDX-License-Identifier: GPL-2.0 //
+
+// Copyright (c) 2019 MediaTek Inc.
+
+#include <linux/module.h>

sound/soc/codecs/mt6660.c line 15

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+#include <linux/kernel.h>
+#include <linux/version.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/pm_runtime.h>
+#include <linux/delay.h>
+#include <sound/soc.h>
+#include <sound/tlv.h>
+#include <sound/pcm_params.h>
+#include <linux/debugfs.h>

Move linux/*.h above sound/*.h inclusion.

sound/soc/codecs/mt6660.c line 19

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+
+#include "mt6660.h"
+
+#pragma pack(push, 1)

Actually packing makes little sense for those use cases.
As I mentioned earlier, packing is useful only for either saving some memory (e.g. for a large array) or a strict size definition like ABI.

sound/soc/codecs/mt6660.c line 24

Quoted 5 lines
sound/soc/codecs/mt6660.c new file +5 -0
+struct codec_reg_val {
+u32 addr;
+u32 mask;
+u32 data;
+};

Is this struct used anywhere? If not, kill it.

sound/soc/codecs/mt6660.c line 88

Quoted 1 line
sound/soc/codecs/mt6660.c new file +1 -0
+static struct regmap_config mt6660_regmap_config = {

This can be const.

sound/soc/codecs/mt6660.c line 98

Quoted 3 lines
sound/soc/codecs/mt6660.c new file +3 -0
+static int mt6660_codec_dac_event(struct snd_soc_dapm_widget *w,
+struct snd_kcontrol *kcontrol, int event) {
+

A superfluous blank line.

sound/soc/codecs/mt6660.c line 212

Quoted 13 lines
sound/soc/codecs/mt6660.c new file +13 -0
+static int mt6660_component_get_volsw(struct snd_kcontrol *kcontrol,
+  struct snd_ctl_elem_value *ucontrol) {
+struct snd_soc_component *component =
+snd_soc_kcontrol_component(kcontrol);
+struct mt6660_chip *chip = (struct mt6660_chip *)
+snd_soc_component_get_drvdata(component);
+int ret = -EINVAL;
+
+if (!strcmp(kcontrol->id.name, "Chip Rev")) {
+ucontrol->value.integer.value[0] = chip->chip_rev & 0x0f;
+ret = 0;
+}
+return ret;

So, "T0 SEL" control gets always an error when reading? Then can't we pass simply NULL for get ops instead?

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static int _mt6660_chip_power_on(struct mt6660_chip *chip, int
+on_off) {
+u8 reg_data;
+int ret;

sound/soc/codecs/mt6660.c line 248

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+
+ret = i2c_smbus_read_byte_data(chip->i2c, MT6660_REG_SYSTEM_CTRL);
+if (ret < 0)
+return ret;
+reg_data = (u8)ret;
+if (on_off)
+reg_data &= (~0x01);
+else
+reg_data |= 0x01;
+return regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, reg_data);

Hm, this looks like an open-code of forced update bits via regmap. But interestingly there is no corresponding standard helper for that. Essentially it should be regmap_update_bits_base() with force=1.

Mark?

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static int mt6660_component_aif_hw_params(struct snd_pcm_substream *substream,
+struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) {
+int word_len = params_physical_width(hw_params);
+int aud_bit = params_width(hw_params);

....

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+switch (aud_bit) {
+case 16:
+reg_data = 3;
+break;

sound/soc/codecs/mt6660.c line 310

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+case 18:
+reg_data = 2;
+break;
+case 20:
+reg_data = 1;
+break;
+case 24:
+case 32:
+reg_data = 0;
+break;

So here both 24 and 32 bits data are handled equally, and...

....

sound/soc/codecs/mt6660.c

Quoted 2 lines
sound/soc/codecs/mt6660.c new file +2 -0
+ret = snd_soc_component_update_bits(dai->component,
+MT6660_REG_TDM_CFG3, 0x3f0, word_len << 4);

... word_len is same for both S32 and S24 formats, so there can be no difference between S24 and S32 format handling in the code. Meanwhile, the supported formats are:

sound/soc/codecs/mt6660.c line 340

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+#define STUB_FORMATS(SNDRV_PCM_FMTBIT_S16_LE | \
+SNDRV_PCM_FMTBIT_U16_LE | \
+SNDRV_PCM_FMTBIT_S24_LE | \
+SNDRV_PCM_FMTBIT_U24_LE | \
+SNDRV_PCM_FMTBIT_S32_LE | \
+SNDRV_PCM_FMTBIT_U32_LE)

Are you sure that S24_* formats really work properly?

Also, the code has no check / setup of the format signedness. Do unsigned formats (U16, U24, etc) really work as expected, too?

Quoted 1 line

+static inline int _mt6660_chip_id_check(struct mt6660_chip *chip)

Drop unnecessary inline (here and other places).
Compiler optimizes well by itself.

sound/soc/codecs/mt6660.c line 388

Quoted 5 lines
sound/soc/codecs/mt6660.c new file +5 -0
+static inline int _mt6660_chip_sw_reset(struct mt6660_chip *chip) {
+int ret;
+
+/* turn on main pll first, then trigger reset */
+ret = regmap_write(chip->regmap, 0x03, 0x00);

It's MT6660_REG_SYSTEM_CTRL, right?

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+if (ret < 0)
+return ret;
+ret = regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, 0x80);
+if (ret < 0)
+return ret;
+msleep(30);

sound/soc/codecs/mt6660.c line 404

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+return 0;
+}
+
+static inline int _mt6660_read_chip_revision(struct mt6660_chip
+*chip) {
+u8 reg_data[2];
+int ret;
+
+ret = i2c_smbus_read_i2c_block_data(
+chip->i2c, MT6660_REG_DEVID, 2, reg_data);

Why avoiding regmap here? This and chip_id_check() use the raw access by some reason...

thanks,

Takashi
************* Email Confidentiality Notice ********************

The information contained in this e-mail message (including any attachments) may be confidential, proprietary, privileged, or otherwise exempt from disclosure under applicable laws. It is intended to be conveyed only to the designated recipient(s). Any use, dissemination, distribution, printing, retaining or copying of this e-mail (including its attachments) by unintended recipient(s) is strictly prohibited and may be unlawful. If you are not an intended recipient of this e-mail, or believe that you have received this e-mail in error, please notify the sender immediately (by replying to this e-mail), delete any and all copies of this e-mail (including any attachments) from your system, and do not disclose the content of this e-mail to any other person. Thank you!

#3 lore raw
Quoted 22 lines · jeff_chang(張世佳)

Dear Takashi:

Thank for your replying.

1.> +static int mt6660_component_get_volsw(struct snd_kcontrol *kcontrol,

sound/soc/codecs/mt6660.c line 212

Quoted 12 lines
sound/soc/codecs/mt6660.c new file +12 -0
+  struct snd_ctl_elem_value *ucontrol) {
+struct snd_soc_component *component =
+snd_soc_kcontrol_component(kcontrol);
+struct mt6660_chip *chip = (struct mt6660_chip *)
+snd_soc_component_get_drvdata(component);
+int ret = -EINVAL;
+
+if (!strcmp(kcontrol->id.name, "Chip Rev")) {
+ucontrol->value.integer.value[0] = chip->chip_rev & 0x0f;
+ret = 0;
+}
+return ret;

So, "T0 SEL" control gets always an error when reading? Then can't we pass simply NULL for get ops instead?

Quoted 1 line

Jeff : T0 SEL use snd_soc_get_volsw, it will not use this function.

Then what's the reason of this hackish check?

Quoted 18 lines

2. So here both 24 and 32 bits data are handled equally, and...

....

Review

Quoted 2 lines
(quoted diff) +2 -0
+ret = snd_soc_component_update_bits(dai->component,
+MT6660_REG_TDM_CFG3, 0x3f0, word_len << 4);

... word_len is same for both S32 and S24 formats, so there can be no difference between S24 and S32 format handling in the code. Meanwhile, the supported formats are:

sound/soc/codecs/mt6660.c line 340

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+#define STUB_FORMATS(SNDRV_PCM_FMTBIT_S16_LE | \
+SNDRV_PCM_FMTBIT_U16_LE | \
+SNDRV_PCM_FMTBIT_S24_LE | \
+SNDRV_PCM_FMTBIT_U24_LE | \
+SNDRV_PCM_FMTBIT_S32_LE | \
+SNDRV_PCM_FMTBIT_U32_LE)

Are you sure that S24_* formats really work properly?

Quoted 5 lines

Also, the code has no check / setup of the format signedness. Do unsigned formats (U16, U24, etc) really work as expected, too?

Jeff : Yes, it works.

So, for the codec, it doesn't matter at all about the signedness and the alingment of 32bit / 24bit of the incoming signals, but magically handled as is? Interesting...

thanks,

Takashi

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#4 lore raw
Quoted 3 lines · Takashi Iwai

So, for the codec, it doesn't matter at all about the signedness and the alingment of 32bit / 24bit of the incoming signals, but magically handled as is? Interesting...

On the playback side CODECs sometimes don't care that much, they clock data in and if it stops early they just go on to the next sample with the width being used to configure filters or something.

The signedness is a bit more surprising I have to say :/

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#5 lore raw
In reply to Takashi Iwai
Quoted 15 lines · Takashi Iwai

sound/soc/codecs/mt6660.c line 248

Quoted 8 lines · Jeff Chang
sound/soc/codecs/mt6660.c new file +8 -0
+	if (ret < 0)
+		return ret;
+	reg_data = (u8)ret;
+	if (on_off)
+		reg_data &= (~0x01);
+	else
+		reg_data |= 0x01;
+	return regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, reg_data);

Hm, this looks like an open-code of forced update bits via regmap. But interestingly there is no corresponding standard helper for that. Essentially it should be regmap_update_bits_base() with force=1.

Quoted 1 line

Mark?

regmap_write_bits().

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#6 lore raw
Quoted 17 lines · Mark Brown
Quoted 14 lines · Takashi Iwai

sound/soc/codecs/mt6660.c line 248

Quoted 8 lines · Jeff Chang
sound/soc/codecs/mt6660.c new file +8 -0
+	if (ret < 0)
+		return ret;
+	reg_data = (u8)ret;
+	if (on_off)
+		reg_data &= (~0x01);
+	else
+		reg_data |= 0x01;
+	return regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, reg_data);

Hm, this looks like an open-code of forced update bits via regmap. But interestingly there is no corresponding standard helper for that. Essentially it should be regmap_update_bits_base() with force=1.

Quoted 3 lines
Quoted 1 line

Mark?

regmap_write_bits().

Oh that obvious one, thanks :)

Takashi