Skip to contentSkip to conversation

ASoC: Add MediaTek MT6660 Speaker Amp Driver

PATCH Superseded Jeff Chang 3 participants 6 messages Dec 20, 2019 – Dec 25, 2019

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jeff Chang

author
#0 lore raw

PATCH 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 | 653 ++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/mt6660.h |  75 ++++++
 4 files changed, 741 insertions(+)
 create mode 100644 sound/soc/codecs/mt6660.c
 create mode 100644 sound/soc/codecs/mt6660.h

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 +652 -0

652 lines not on this page · raw message

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

75 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#1 lore raw

sound/soc/codecs/mt6660.c line 4

Quoted 6 lines · Jeff Chang

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

sound/soc/codecs/mt6660.c new file +4 -0
@@ -0,0 +1,653 @@
+// 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 41

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+	{ MT6660_REG_DEVID, 2},
+	{ MT6660_REG_TDM_CFG3, 2},
+	{ MT6660_REG_HCLIP_CTRL, 2},
+	{ MT6660_REG_DA_GAIN, 2},

Missing space before the } (the same thing happens in some of the other tables).

sound/soc/codecs/mt6660.c line 212

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -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")) {

Why would this be used on a different control?

Review line 20

Quoted 2 lines
(quoted diff) +2 -0
+	SOC_SINGLE_EXT("BoostMode", MT6660_REG_BST_CTRL, 0, 3, 0,
+		       snd_soc_get_volsw, snd_soc_put_volsw),

Boost Mode. You've also got a lot of these controls that are _EXT but you then just use standard operations so it's not clear why you're using _EXT.

Review line 22

Quoted 2 lines
(quoted diff) +2 -0
+	SOC_SINGLE_EXT("audio input selection", MT6660_REG_DATAO_SEL, 6, 3, 0,
+		       snd_soc_get_volsw, snd_soc_put_volsw),

Audio Input Selection, but this looks like it should be a DAPM control if it's controlling audio routing. A simple numerical setting definitely doesn't seem like the right thing.

Review line 24

Quoted 2 lines
(quoted diff) +2 -0
+	SOC_SINGLE_EXT("AUD LOOP BACK Switch", MT6660_REG_PATH_BYPASS, 4, 1, 0,
+		       snd_soc_get_volsw, snd_soc_put_volsw),

This sounds like it should be a DAPM thing too.

sound/soc/codecs/mt6660.c line 311

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+static int mt6660_component_probe(struct snd_soc_component *component)
+{
+	struct mt6660_chip *chip = snd_soc_component_get_drvdata(component);
+	int ret = 0;
+
+	dev_info(component->dev, "%s\n", __func__);

dev_dbg() at most but probably better to remove this and the other similar dev_info()s.

sound/soc/codecs/mt6660.c line 437

Quoted 12 lines
sound/soc/codecs/mt6660.c new file +12 -0
+static inline int _mt6660_chip_id_check(struct mt6660_chip *chip)
+{
+	u8 id[2] = {0};
+	int ret = 0;
+
+	ret = i2c_smbus_read_i2c_block_data(chip->i2c, MT6660_REG_DEVID, 2, id);
+	if (ret < 0)
+		return ret;
+	ret = (id[0] << 8) + id[1];
+	ret &= 0x0ff0;
+	if (ret != 0x00e0 && ret != 0x01e0)
+		return -ENODEV;

It'd be better to print an error message saying we don't recognize the device to help people doing debugging.

sound/soc/codecs/mt6660.c line 482

Quoted 3 lines
sound/soc/codecs/mt6660.c new file +3 -0
+	if (of_property_read_u32(np, "rt,init_setting_num", &val)) {
+		dev_info(dev, "no init setting\n");
+		chip->plat_data.init_setting_num = 0;

You should be adding a DT binding document for any new DT bindings.

#2 lore raw

Dear Mark:

Thanks for your replying.

I have a question about this

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,653 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2019 MediaTek Inc.
+ */

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

--> When I check other driver at sound/soc/codecs/ folder, I just follow what others do. It seems in .h --> /* SPDX-Liencese-Identifier: GPL-2.0 */
In .c --> // SPDK-Liencese-Identifier: GPL-2.0

Is it correct?

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: Mark Brown [mailto:[email protected]]
Sent: Friday, December 20, 2019 8:12 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

sound/soc/codecs/mt6660.c line 4

Quoted 6 lines · Jeff Chang
sound/soc/codecs/mt6660.c new file +5 -0
+++ b/sound/soc/codecs/mt6660.c
@@ -0,0 +1,653 @@
+// 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 41

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+{ MT6660_REG_DEVID, 2},
+{ MT6660_REG_TDM_CFG3, 2},
+{ MT6660_REG_HCLIP_CTRL, 2},
+{ MT6660_REG_DA_GAIN, 2},

Missing space before the } (the same thing happens in some of the other tables).

sound/soc/codecs/mt6660.c line 212

Quoted 9 lines
sound/soc/codecs/mt6660.c new file +9 -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")) {

Why would this be used on a different control?

Review line 19

Quoted 2 lines
(quoted diff) +2 -0
+SOC_SINGLE_EXT("BoostMode", MT6660_REG_BST_CTRL, 0, 3, 0,
+       snd_soc_get_volsw, snd_soc_put_volsw),

Boost Mode. You've also got a lot of these controls that are _EXT but you then just use standard operations so it's not clear why you're using _EXT.

Review line 21

Quoted 2 lines
(quoted diff) +2 -0
+SOC_SINGLE_EXT("audio input selection", MT6660_REG_DATAO_SEL, 6, 3, 0,
+       snd_soc_get_volsw, snd_soc_put_volsw),

Audio Input Selection, but this looks like it should be a DAPM control if it's controlling audio routing. A simple numerical setting definitely doesn't seem like the right thing.

Review line 23

Quoted 2 lines
(quoted diff) +2 -0
+SOC_SINGLE_EXT("AUD LOOP BACK Switch", MT6660_REG_PATH_BYPASS, 4, 1, 0,
+       snd_soc_get_volsw, snd_soc_put_volsw),

This sounds like it should be a DAPM thing too.

sound/soc/codecs/mt6660.c line 311

Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6 -0
+static int mt6660_component_probe(struct snd_soc_component
+*component) {
+struct mt6660_chip *chip = snd_soc_component_get_drvdata(component);
+int ret = 0;
+
+dev_info(component->dev, "%s\n", __func__);

dev_dbg() at most but probably better to remove this and the other similar dev_info()s.

sound/soc/codecs/mt6660.c line 437

Quoted 11 lines
sound/soc/codecs/mt6660.c new file +11 -0
+static inline int _mt6660_chip_id_check(struct mt6660_chip *chip) {
+u8 id[2] = {0};
+int ret = 0;
+
+ret = i2c_smbus_read_i2c_block_data(chip->i2c, MT6660_REG_DEVID, 2, id);
+if (ret < 0)
+return ret;
+ret = (id[0] << 8) + id[1];
+ret &= 0x0ff0;
+if (ret != 0x00e0 && ret != 0x01e0)
+return -ENODEV;

It'd be better to print an error message saying we don't recognize the device to help people doing debugging.

sound/soc/codecs/mt6660.c line 482

Quoted 3 lines
sound/soc/codecs/mt6660.c new file +3 -0
+if (of_property_read_u32(np, "rt,init_setting_num", &val)) {
+dev_info(dev, "no init setting\n");
+chip->plat_data.init_setting_num = 0;

You should be adding a DT binding document for any new DT bindings. ************* 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!

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

--> When I check other driver at sound/soc/codecs/ folder, I just follow what others do. It seems in .h --> /* SPDX-Liencese-Identifier: GPL-2.0 */
In .c --> // SPDK-Liencese-Identifier: GPL-2.0

Is it correct?

Yes, headers use C style comments and source files use C++ style.

#4 lore raw

Dear Mark:

I need to confirm it again.

This is adau1997 driver on upstream branch

@ sound/soc/codecs/adau1997.c

// SPDX-License-Identifier: GPL-2.0-only
/*
* ADAU1977/ADAU1978/ADAU1979 driver
*
* Copyright 2014 Analog Devices Inc.
* Author: Lars-Peter Clausen <[email protected]>
*/

@sound/soc/codecs/adau1997.h

/* SPDX-License-Identifier: GPL-2.0-only */
/*
* ADAU1977/ADAU1978/ADAU1979 driver
*
* Copyright 2014 Analog Devices Inc.
* Author: Lars-Peter Clausen <[email protected]>
*/

It seems not whole comment use c++. Only first line at source file, Right?

Thanks a lot.

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: Mark Brown [mailto:[email protected]]
Sent: Wednesday, December 25, 2019 7:52 AM
To: jeff_chang(張世佳) <[email protected]>
Cc: Jeff Chang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] ASoC: Add MediaTek MT6660 Speaker Amp Driver

Quoted 5 lines · jeff_chang(張世佳)

--> When I check other driver at sound/soc/codecs/ folder, I just follow what others do. It seems in .h --> /* SPDX-Liencese-Identifier: GPL-2.0 */
In .c --> // SPDK-Liencese-Identifier: GPL-2.0

Is it correct?

Yes, headers use C style comments and source files use C++ style. ************* 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!

maintainer
#5 lore raw
Quoted 7 lines · jeff_chang(張世佳)

This is adau1997 driver on upstream branch

@ sound/soc/codecs/adau1997.c

// SPDX-License-Identifier: GPL-2.0-only
/*
* ADAU1977/ADAU1978/ADAU1979 driver

This is the result of an automatic conversion which wasn't reviewed, it's not ideal.

Quoted 1 line

It seems not whole comment use c++. Only first line at source file, Right?

Please do it like this:

// SPDX-License-Identifier: GPL-2.0-only
//
// ADAU1977/ADAU1978/ADAU1979 driver

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