Skip to contentSkip to conversation

ASoC: Add MediaTek MT6660 Speaker Amp Driver

PATCH Superseded Jeff Chang 3 participants 3 messages Jan 7, 2020 – Jan 9, 2020

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jeff Chang

author
#0 lore raw

PATCH v4 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

---
 Documentation/devicetree/bindings/sound/mt6660.txt |  53 ++
 sound/soc/codecs/Kconfig                           |  11 +
 sound/soc/codecs/Makefile                          |   2 +
 sound/soc/codecs/mt6660.c                          | 628 +++++++++++++++++++++
 sound/soc/codecs/mt6660.h                          |  75 +++
 5 files changed, 769 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/mt6660.txt
 create mode 100644 sound/soc/codecs/mt6660.c
 create mode 100644 sound/soc/codecs/mt6660.h

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

Documentation/devicetree/bindings/sound/mt6660.txt new file +53 -0
new file mode 100644
index 0000000..2a1736b
@@ -0,0 +1,53 @@
+MT6660 MediaTek Speaker Amplifier
+
+This device supports I2C mode only.
+
+Required properties:
+
+	- compatible : "mediatek,mt6660"
+	
+	- reg : The I2C slave address
+
+Optional properties:
+
+	- rt,init_setting_num : The initial register setting element number.
+
+	- rt,init_setting_addr : the addreses array for INIT Setting table.
+
+	- rt,init_setting_mask : the mask array for INIT Setting table.
+
+	- rt,init_setting_val : the value array for INIT Setting table.
+
+Example:
+
+	mt6660@34 {
+		status = "ok";
+		compatible = "mediatek,mt6660";
+		reg = <0x34>;
+		rt,init_setting_num = <26>;
+		rt,init_setting_addr =
+			<0x20 0x30 0x50 0xB1
+			 0xD3 0xE0 0x98 0xB9
+			 0xB7 0xB6 0x6B 0x07
+			 0xBB 0x69 0xBD 0x70
+			 0x7C 0x46 0x1A 0x1B
+			 0x51 0xA2 0x33 0x4C
+			 0x15 0x68>;
+		rt,init_setting_mask =
+			<0x80 0x01 0x1c 0x0c
+			 0x03 0x01 0x44 0xff
+			 0x7777 0x07 0xe0 0xff
+			 0xff 0xff 0xffff 0xff
+			 0xff 0xff 0xffffffff 0xffffffff
+			 0xff 0xff 0xffff 0xffff
+			 0x1800 0x1f>;
+		rt,init_setting_val =
+			<0x00 0x00 0x04 0x00
+			 0x03 0x00 0x04 0x82
+			 0x7273 0x03 0x20 0x70
+			 0x20 0x40 0x17f8 0x15
+			 0x00 0x1d 0x7fdb7ffe 0x7fdb7ffe
+			 0x58 0xce 0x7fff 0x0116
+			 0x0800 0x07>;
+	};
+
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 +628 -0

628 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
#1 lore raw
Quoted 16 lines · Jeff Chang

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/mt6660.c new file +0 -0
new file mode 100644
index 0000000..b8fc53b

sound/soc/codecs/mt6660.c line 23

Quoted 7 lines
sound/soc/codecs/mt6660.c new file +6 -0
@@ -0,0 +1,628 @@
 
+
+struct codec_reg_val {
+	u32 addr;
+	u32 mask;
+	u32 data;
+};

packed structures could have been better.

sound/soc/codecs/mt6660.c line 28

Quoted 5 lines
sound/soc/codecs/mt6660.c new file +5 -0
+
+struct reg_size_table {
+	u32 addr;
+	u8 size;
+};

here as well.

sound/soc/codecs/mt6660.c line 44

Quoted 3 lines
sound/soc/codecs/mt6660.c new file +3 -0
+static int mt6660_get_reg_size(uint32_t addr)
+{
+	int i = 0;

redundant initialization.

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+
+	for (i = 0; i < ARRAY_SIZE(mt6660_reg_size_table); i++) {
+		if (mt6660_reg_size_table[i].addr == addr)
+			return mt6660_reg_size_table[i].size;

sound/soc/codecs/mt6660.c line 58

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+	}
+	return 1;
+}
+
+static int mt6660_reg_write(void *context, unsigned int reg, unsigned int val)
+{
+	struct mt6660_chip *chip = context;
+	int size = mt6660_get_reg_size(reg);
+	u8 reg_data[4] = {0};
+	int i = 0, ret = 0;

redundant initialization.

sound/soc/codecs/mt6660.c line 66

Quoted 8 lines
sound/soc/codecs/mt6660.c new file +8 -0
+
+	for (i = 0; i < size; i++)
+		reg_data[size - i - 1] = (val >> (8 * i)) & 0xff;
+
+	ret = i2c_smbus_write_i2c_block_data(chip->i2c, reg, size, reg_data);
+	if (ret < 0)
+		return ret;
+	return 0;

one return can be removed.

sound/soc/codecs/mt6660.c line 73

Quoted 7 lines
sound/soc/codecs/mt6660.c new file +7 -0
+}
+
+static int mt6660_reg_read(void *context, unsigned int reg, unsigned int *val)
+{
+	struct mt6660_chip *chip = context;
+	int size = mt6660_get_reg_size(reg);
+	int i = 0, ret = 0;

redundant initialization.

sound/soc/codecs/mt6660.c line 102

Quoted 9 lines
sound/soc/codecs/mt6660.c new file +9 -0
+
+static int mt6660_codec_dac_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	switch (event) {
+	case SND_SOC_DAPM_POST_PMU:
+		usleep_range(1000, 1100);
+		break;
+	}

switch is redundant for one condition.

sound/soc/codecs/mt6660.c line 111

Quoted 9 lines
sound/soc/codecs/mt6660.c new file +9 -0
+	return 0;
+}
+
+static int mt6660_codec_classd_event(struct snd_soc_dapm_widget *w,
+	struct snd_kcontrol *kcontrol, int event)
+{
+	struct snd_soc_component *component =
+		snd_soc_dapm_to_component(w->dapm);
+	int ret = 0;

redundant intialization.

Quoted 1 line

+static inline int _mt6660_chip_power_on(struct mt6660_chip *chip, int on_off)

inline must here and other places also? Doesn't look like very small code.

sound/soc/codecs/mt6660.c line 241

Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4 -0
+{
+	u8 reg_data = 0;
+	int ret = 0;
+

redundant intialization.

sound/soc/codecs/mt6660.c line 259

Quoted 8 lines
sound/soc/codecs/mt6660.c new file +8 -0
+
+static int mt6660_apply_plat_data(struct mt6660_chip *chip,
+		struct snd_soc_component *component)
+{
+	size_t i = 0;
+	int num = chip->plat_data.init_setting_num;
+	int ret = 0;
+

redundant intialization and please take care of all places.

sound/soc/codecs/mt6660.c line 427

Quoted 9 lines
sound/soc/codecs/mt6660.c new file +9 -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);
+	if (ret < 0)
+		return ret;
+	ret = regmap_write(chip->regmap, MT6660_REG_SYSTEM_CTRL, 0x80);

error check not needed?

Quoted 18 lines
sound/soc/codecs/mt6660.c new file +18 -0
+static int mt6660_parse_dt(struct mt6660_chip *chip, struct device *dev)
+{
+	struct device_node *np = dev->of_node;
+	u32 val;
+	size_t i = 0;
+
+	if (!np) {
+		dev_err(dev, "no device node\n");
+		return -EINVAL;
+	}
+
+	if (of_property_read_u32(np, "rt,init_setting_num", &val)) {
+		dev_err(dev, "no init setting\n");
+		chip->plat_data.init_setting_num = 0;
+	} else {
+		chip->plat_data.init_setting_num = val;
+	}
+

sound/soc/codecs/mt6660.c line 474

Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10 -0
+	chip->plat_data.init_setting_addr =
+		devm_kzalloc(dev, sizeof(u32) *
+				chip->plat_data.init_setting_num, GFP_KERNEL);
+	chip->plat_data.init_setting_mask =
+		devm_kzalloc(dev, sizeof(u32) *
+				chip->plat_data.init_setting_num, GFP_KERNEL);
+	chip->plat_data.init_setting_val =
+		devm_kzalloc(dev, sizeof(u32) *
+				chip->plat_data.init_setting_num, GFP_KERNEL);
+

memory allocation failures not taken care of and if chip->plat_data.init_setting_num is 0, allocation required.

sound/soc/codecs/mt6660.h line 17

Quoted 12 lines
sound/soc/codecs/mt6660.h new file +7 -0
new file mode 100644
index 0000000..6c40b40
+
+struct mt6660_platform_data {
+	u8 init_setting_num;
+	u32 *init_setting_addr;
+	u32 *init_setting_mask;
+	u32 *init_setting_val;
+};

packed could have been better.

sound/soc/codecs/mt6660.h line 28

Quoted 11 lines
sound/soc/codecs/mt6660.h new file +11 -0
+
+struct mt6660_chip {
+	struct i2c_client *i2c;
+	struct device *dev;
+	struct platform_device *param_dev;
+	struct mt6660_platform_data plat_data;
+	struct mutex io_lock;
+	struct regmap *regmap;
+	u16 chip_rev;
+};
+

here as well.

Thanks,
Sriram.

#2 lore raw
Quoted 19 lines · Sriram Periyasamy
Quoted 16 lines · Jeff Chang

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/mt6660.c new file +0 -0
new file mode 100644
index 0000000..b8fc53b
@@ -0,0 +1,628 @@
Quoted 8 lines

sound/soc/codecs/mt6660.c line 23

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

packed structures could have been better.

It depends. Packing may break alignment and the performance may suffer from it. So, in general, __packed is recommended when the size matters (e.g. lots of objects / arrays are created) or it's about ABI that needs the fixed consistent size.

thanks,

Takashi