Skip to contentSkip to conversation

ASoC: Add MediaTek MT6660 Speaker Amp Driver

PATCH In review Jeff Chang 3 participants 4 messages Dec 12, 2019 – Dec 13, 2019

Subsystems (3)
lore
Share & tools
lore

Jeff Chang

author
#0 lore raw

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

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

---

[PATCH v2] :
1. remove unnecessary space from commit message
2. add Signed-off-by info

---
 sound/soc/codecs/Kconfig  |   14 +
 sound/soc/codecs/Makefile |    2 +
 sound/soc/codecs/mt6660.c | 1063 +++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/mt6660.h |   95 ++++
 4 files changed, 1174 insertions(+)
 create mode 100644 sound/soc/codecs/mt6660.c
 create mode 100644 sound/soc/codecs/mt6660.h
sound/soc/codecs/Kconfig +14 -0
index 229cc89..806cd03 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,19 @@ 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
+	select CRC32
+	select CRYPTO_SHA256
+	select CRYTO_RSA
+	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 +1063 -0

1,063 lines not on this page · raw message

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

95 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 10 lines · Jeff Chang

sense, which are able to be monitored via DATAO through proper

---

[PATCH v2] :
1. remove unnecessary space from commit message
2. add Signed-off-by info

---

You should place the Signed-off-by before the first --- as covered by submitting-patches.rst. Please, slow down a bit before resending and make sure you've checked what you're doing thoroughly. Look at what you're sending and how it compares to what others are sending.

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

Quoted 7 lines
sound/soc/codecs/Kconfig +7 -0
+config SND_SOC_MT6660
+	tristate "Mediatek MT6660 Speaker Amplifier"
+	depends on I2C
+	select CRC32
+	select CRYPTO_SHA256
+	select CRYTO_RSA
+	help

These selects of crypto stuf appear entirely unrelated to anything in the driver?

sound/soc/codecs/mt6660.c line 4

Quoted 6 lines

+++ b/sound/soc/codecs/mt6660.c

sound/soc/codecs/mt6660.c new file +4 -0
@@ -0,0 +1,1063 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ */

Please make the entire comment a C++ one so things look more intentional.

sound/soc/codecs/mt6660.c line 84

Quoted 8 lines
sound/soc/codecs/mt6660.c new file +8 -0
+static int mt6660_dbg_io_write(void *drvdata, u16 reg,
+			       const void *val, u16 size)
+{
+	struct mt6660_chip *chip = (struct mt6660_chip *)drvdata;
+	int reg_size = mt6660_get_reg_size(reg);
+	int i = 0;
+	unsigned int regval = 0;
+	u8 *_val = (u8 *)val;

This is duplicating standard regmap functionality.

sound/soc/codecs/mt6660.c line 138

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static bool mt6660_volatile_reg(struct device *dev, unsigned int reg)
+{
+	return true;
+}

There's no need to do this, there's no cache configured.

sound/soc/codecs/mt6660.c line 160

Quoted 13 lines
sound/soc/codecs/mt6660.c new file +13 -0
+static unsigned int mt6660_component_io_read(
+	struct snd_soc_component *component, unsigned int reg)
+{
+	struct mt6660_chip *chip = snd_soc_component_get_drvdata(component);
+	unsigned int val;
+	int ret;
+
+	ret = regmap_read(chip->regmap, reg, &val);
+	if (ret < 0) /* ret success -> >= 0, fail -> < - */
+		return ret;
+	pr_err("%s val = 0x%x\n", __func__, val);
+	return val;
+}

This function appears to be redunddant, ASoC has wrappers for I/O on components, same for writes.

sound/soc/codecs/mt6660.c line 227

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static int data_debug_show(struct seq_file *s, void *data)
+{
+	struct dbg_info *di = s->private;
+	struct dbg_internal *d = &di->internal;

regmap has standard support for dumping the register map via debugfs, no need to write your own. You should be able to just remove all the debugfs code.

sound/soc/codecs/mt6660.c line 487

Quoted 8 lines
sound/soc/codecs/mt6660.c new file +8 -0
+/*
+ * MT6660 Generic Setting make this chip work normally.
+ * it is tuned by Richtek RDs.
+ */
+static const struct codec_reg_val generic_reg_inits[] = {
+	{ MT6660_REG_WDT_CTRL, 0x80, 0x00 },
+	{ MT6660_REG_SPS_CTRL, 0x01, 0x00 },
+	{ MT6660_REG_AUDIO_IN2_SEL, 0x1c, 0x04 },

The writes to reserved registers should be fine but things like this which looks like it's configuring the input path should just be left at the chip default, we don't want to be configuring for particular boards since the same driver will be used for every board with the chip.

sound/soc/codecs/mt6660.c line 504

Quoted 2 lines
sound/soc/codecs/mt6660.c new file +2 -0
+	{ MT6660_REG_HPF1_COEF, 0xffffffff, 0x7fdb7ffe },
+	{ MT6660_REG_HPF2_COEF, 0xffffffff, 0x7fdb7ffe },

Similarly here.

sound/soc/codecs/mt6660.c line 518

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+static int mt6660_component_init_setting(struct snd_soc_component *component)
+{
+	int i, len, ret;
+	const struct codec_reg_val *init_table;
+
+	pr_info("%s start\n", __func__);

These pr_info() calls are going to be too noisy.

sound/soc/codecs/mt6660.c line 547

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+	switch (level) {
+	case SND_SOC_BIAS_OFF:
+		ret = regmap_read(chip->regmap, MT6660_REG_IRQ_STATUS1, &val);
+		dev_info(component->dev,
+			"%s reg0x05 = 0x%x\n", __func__, val);
+		break;

This is just making noise, it looks like there's nothing to do in this function at all and the above is only for debugging. There's lots of these throughout the driver.

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

sound/soc/codecs/mt6660.c line 677

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+		snd_soc_kcontrol_component(kcontrol);
+	int put_ret = 0;
+
+	pm_runtime_get_sync(component->dev);
+	put_ret = snd_soc_put_volsw(kcontrol, ucontrol);
+	if (put_ret < 0)
+		return put_ret;
+	pm_runtime_put(component->dev);
+	return put_ret;
+}

It would be *much* better to just use a register cache here rather than open code like this, and given that the device is suspended via the register map it is more than a little surprising that there's any need to do anything special here.

#2 lore raw

Dear Mark:

Thanks for your replying. I consider that there was only one item I should modify. So I kept resending.

Please refer my red comment after your comment.

Thanks a lot!

Thanks & BRs

Jeff

-----Original Message-----
From: Mark Brown [mailto:[email protected]]
Sent: Thursday, December 12, 2019 10:54 PM
To: Jeff Chang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; jeff_chang(張世佳) <[email protected]>
Subject: Re: [PATCH] ASoC: Add MediaTek MT6660 Speaker Amp Driver

Quoted 12 lines · Jeff Chang

sense, which are able to be monitored via DATAO through proper

---

[PATCH v2] :

1. remove unnecessary space from commit message

Quoted 7 lines

2. add Signed-off-by info

---

You should place the Signed-off-by before the first --- as covered by submitting-patches.rst. Please, slow down a bit before resending and make sure you've checked what you're doing thoroughly. Look at what you're sending and how it compares to what others are sending.

OK! I will do it at next patch!

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

Quoted 13 lines
sound/soc/codecs/Kconfig +7 -0
+config SND_SOC_MT6660
 
+   tristate "Mediatek MT6660 Speaker Amplifier"
 
+   depends on I2C
 
+   select CRC32
 
+   select CRYPTO_SHA256
 
+   select CRYTO_RSA
 
+   help

These selects of crypto stuf appear entirely unrelated to anything in the driver?

I will remove it.

sound/soc/codecs/mt6660.c line 4

Quoted 11 lines

+++ b/sound/soc/codecs/mt6660.c

sound/soc/codecs/mt6660.c new file +4 -0
@@ -0,0 +1,1063 @@
 
+// SPDX-License-Identifier: GPL-2.0
 
+/*
 
+ * Copyright (c) 2019 MediaTek Inc.
 
+ */

Please make the entire comment a C++ one so things look more intentional.

        OK!
Quoted 5 lines
sound/soc/codecs/mt6660.c new file +3 -0
+static int mt6660_dbg_io_write(void *drvdata, u16 reg,
 
+                          const void *val, u16 size)
 
+{

sound/soc/codecs/mt6660.c line 84

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +5 -0
 
+   struct mt6660_chip *chip = (struct mt6660_chip *)drvdata;
 
+   int reg_size = mt6660_get_reg_size(reg);
 
+   int i = 0;
 
+   unsigned int regval = 0;
 
+   u8 *_val = (u8 *)val;

This is duplicating standard regmap functionality.

sound/soc/codecs/mt6660.c line 138

Quoted 7 lines
sound/soc/codecs/mt6660.c new file +4 -0
+static bool mt6660_volatile_reg(struct device *dev, unsigned int reg)
 
+{
 
+   return true;
 
+}

There's no need to do this, there's no cache configured.

        OK!
Quoted 13 lines
(quoted diff) +7 -0
+static unsigned int mt6660_component_io_read(
 
+   struct snd_soc_component *component, unsigned int reg) {
 
+   struct mt6660_chip *chip = snd_soc_component_get_drvdata(component);
 
+   unsigned int val;
 
+   int ret;
 
+
 
+   ret = regmap_read(chip->regmap, reg, &val);

Review

Quoted 10 lines
(quoted diff) +5 -0
 
+   if (ret < 0) /* ret success -> >= 0, fail -> < - */
 
+           return ret;
 
+   pr_err("%s val = 0x%x\n", __func__, val);
 
+   return val;
 
+}

This function appears to be redunddant, ASoC has wrappers for I/O on components, same for writes.

        OK!

Review

Quoted 5 lines
(quoted diff) +3 -0
+static int data_debug_show(struct seq_file *s, void *data) {
 
+   struct dbg_info *di = s->private;
 
+   struct dbg_internal *d = &di->internal;

regmap has standard support for dumping the register map via debugfs, no need to write your own. You should be able to just remove all the debugfs code.

Quoted 5 lines
sound/soc/codecs/mt6660.c new file +3 -0
+/*
 
+ * MT6660 Generic Setting make this chip work normally.
 
+ * it is tuned by Richtek RDs.

sound/soc/codecs/mt6660.c line 487

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +5 -0
 
+ */
 
+static const struct codec_reg_val generic_reg_inits[] = {
 
+   { MT6660_REG_WDT_CTRL, 0x80, 0x00 },
 
+   { MT6660_REG_SPS_CTRL, 0x01, 0x00 },
 
+   { MT6660_REG_AUDIO_IN2_SEL, 0x1c, 0x04 },

The writes to reserved registers should be fine but things like this which looks like it's configuring the input path should just be left at the chip default, we don't want to be configuring for particular boards since the same driver will be used for every board with the chip.

The chip default cannot be modified anymore. How can I do if I really need write these setting in our drivers?

sound/soc/codecs/mt6660.c line 504

Quoted 3 lines
sound/soc/codecs/mt6660.c new file +2 -0
+   { MT6660_REG_HPF1_COEF, 0xffffffff, 0x7fdb7ffe },
 
+   { MT6660_REG_HPF2_COEF, 0xffffffff, 0x7fdb7ffe },

Similarly here.

Review

Quoted 11 lines
(quoted diff) +6 -0
+static int mt6660_component_init_setting(struct snd_soc_component
 
+*component) {
 
+   int i, len, ret;
 
+   const struct codec_reg_val *init_table;
 
+
 
+   pr_info("%s start\n", __func__);

These pr_info() calls are going to be too noisy.

OK! I will remove it.

sound/soc/codecs/mt6660.c line 547

Quoted 11 lines
sound/soc/codecs/mt6660.c new file +6 -0
+   switch (level) {
 
+   case SND_SOC_BIAS_OFF:
 
+           ret = regmap_read(chip->regmap, MT6660_REG_IRQ_STATUS1, &val);
 
+           dev_info(component->dev,
 
+                   "%s reg0x05 = 0x%x\n", __func__, val);
 
+           break;

This is just making noise, it looks like there's nothing to do in this function at all and the above is only for debugging. There's lots of these throughout the driver.

It is prepare for more flexible using. Anyway, I will remove it.

Quoted 15 lines
(quoted diff) +8 -0
+static int mt6660_component_put_volsw(struct snd_kcontrol *kcontrol,
 
+                             struct snd_ctl_elem_value *ucontrol) {
 
+   struct snd_soc_component *component =
 
+           snd_soc_kcontrol_component(kcontrol);
 
+   int put_ret = 0;
 
+
 
+   pm_runtime_get_sync(component->dev);
 
+   put_ret = snd_soc_put_volsw(kcontrol, ucontrol);

Review

Quoted 10 lines
(quoted diff) +5 -0
 
+   if (put_ret < 0)
 
+           return put_ret;
 
+   pm_runtime_put(component->dev);
 
+   return put_ret;
 
+}

It would be *much* better to just use a register cache here rather than open code like this, and given that the device is suspended via the register map it is more than a little surprising that there's any need to do anything special here.

        Ok!

************* 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!
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

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

Dear Mark:

Thanks for your replying. I consider that there was only one item I should modify. So I kept resending.

Please refer my red comment after your comment.

I can't tell what's in red or not, kernel development gets done with plain text e-mail. Please fix your mail configuration, it is extremely difficult to read your messages for this and other reasons.

Quoted 5 lines

The writes to reserved registers should be fine but things like this which looks like it's configuring the input path should just be left at the chip default, we don't want to be configuring for particular boards since the same driver will be used for every board with the chip.

The chip default cannot be modified anymore. How can I do if I really need write these setting in our drivers?

Settings should be done through some combination of userspace configuration at runtime and device tree or ACPI properties.