Mediatek Smart Amplifier Driver
Subsystems (3)
PATCH 1/1 Mediatek Smart Amplifier Driver
From: Richtek Jeff Chang <[email protected]>
--- sound/soc/codecs/Kconfig | 13 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/mt6660.c | 802 ++++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/mt6660.h | 68 ++++ 4 files changed, 885 insertions(+) create mode 100644 sound/soc/codecs/mt6660.c create mode 100644 sound/soc/codecs/mt6660.h
sound/soc/codecs/Kconfig +13 -0
@@ -120,6 +120,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
@@ -1444,6 +1445,18 @@ 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 CRYPTO_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
@@ -117,6 +117,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
@@ -398,6 +399,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 +802 -0
802 lines not on this page · raw message
sound/soc/codecs/mt6660.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.7.4
Mark Brown
maintainersound/soc/codecs/mt6660.c line 4
Quoted 7 lines · On Tue, Sep 03, 2019 at 03:08:21PM +0800, [email protected] wrote:
sound/soc/codecs/mt6660.c new file +4
-0@@ -0,0 +1,802 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019 MediaTek Inc. +*/
Please make the entire comment block a C++ comment so things look more consistent.
Quoted 7 lines
sound/soc/codecs/mt6660.c new file +6
-0+struct reg_size_table { +u32 addr; +u8 size; +}; +static const struct reg_size_table mt6660_reg_size_table[] = { + {MT6660_REG_HPF1_COEF ,4 },
sound/soc/codecs/mt6660.c line 48
Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10
-0+ { MT6660_REG_HPF2_COEF, 4 }, + { MT6660_REG_TDM_CFG3, 2 }, + { MT6660_REG_RESV17, 2 }, + { MT6660_REG_RESV23, 2 }, + { MT6660_REG_SIGMAX, 2 }, + { MT6660_REG_DEVID, 2}, + { MT6660_REG_TDM_CFG3, 2}, + { MT6660_REG_HCLIP_CTRL, 2}, + { MT6660_REG_DA_GAIN, 2}, +};
Please talk to your hardware designers about the benefits of consistent register sizes :/
sound/soc/codecs/mt6660.c line 63
Quoted 3 lines
sound/soc/codecs/mt6660.c new file +3
-0+static int32_t mt6660_i2c_update_bits (struct mt6660_chip *chip, +uint32_t addr,uint32_t mask,uint32_t data) +{
It would be good to implement a regmap rather than open coding *everything* - it'd give you things like this without needing to open code them. Providing you don't use the cache code it should cope fine with variable register sizes.
Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4
-0+ +static int mt6660_i2c_init_setting (struct mt6660_chip *chip) +{ +int i, len, ret;
sound/soc/codecs/mt6660.c line 237
Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10
-0+const struct codec_reg_val *init_table; + + init_table = e4_reg_inits; + len =ARRAY_SIZE (e4_reg_inits); + +for (i =0 ; i < len; i++) { + ret =mt6660_i2c_update_bits (chip, init_table[i].addr, + init_table[i].mask, init_table[i].data); +if (ret <0 ) +return ret;
Why are we not using the chip defaults here?
Quoted 9 lines
sound/soc/codecs/mt6660.c new file +9
-0+static int mt6660_chip_power_on ( +struct snd_soc_component *component,int on_off) +{ +struct mt6660_chip *chip = (struct mt6660_chip *) +snd_soc_component_get_drvdata (component); +int ret =0 ; +unsigned int val; + +dev_dbg (component->dev,"%s: on_off = %d\n" , __func__, on_off);
sound/soc/codecs/mt6660.c line 260
Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10
-0+mutex_lock (&chip->var_lock); +if (on_off) { +if (chip->pwr_cnt ==0 ) { + ret =mt6660_i2c_update_bits (chip, +MT6660_REG_SYSTEM_CTRL ,0x01 ,0x00 ); + val =mt6660_i2c_read (chip,MT6660_REG_IRQ_STATUS1 ); +dev_info (chip->dev, +"%s reg0x05 = 0x%x\n" , __func__, val); + } + chip->pwr_cnt++;
This looks like you're open coding runtime PM stuff? AFAICT the issue is that you need to write to this register to do any I/O. Just implement this via the standard runtime PM framework, you'll need to do something about the register I/O in the controls (ideally in the framework, it'd be a lot easier if you did have a cache) but you could cut out this bit.
sound/soc/codecs/mt6660.c line 288
Quoted 11 lines
sound/soc/codecs/mt6660.c new file +11
-0+static int mt6660_component_set_bias_level (struct snd_soc_component *component, +enum snd_soc_bias_level level) +{ +struct snd_soc_dapm_context *dapm = +snd_soc_component_get_dapm (component); +int ret; +unsigned int val; +struct mt6660_chip *chip =snd_soc_component_get_drvdata (component); + +if (dapm->bias_level == level) { +dev_warn (component->dev,"%s: repeat level change\n" , __func__);
This shouldn't be a warning.
sound/soc/codecs/mt6660.c line 497
Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6
-0+static const struct snd_kcontrol_new mt6660_component_snd_controls[] = { +SOC_SINGLE_EXT_TLV ("Volume_Ctrl" ,MT6660_REG_VOL_CTRL ,0 ,255 , +1 , snd_soc_get_volsw, mt6660_component_put_volsw, + vol_ctl_tlv), +SOC_SINGLE_EXT ("WDT_Enable" ,MT6660_REG_WDT_CTRL ,7 ,1 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw),
These control names should all use standard ALSA control names - on/off switches should end in Switch, volume controls in Volume.
sound/soc/codecs/mt6660.c line 514
Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6
-0+SOC_SINGLE_EXT ("I2SLRS" ,MT6660_REG_DATAO_SEL ,6 ,3 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw), +SOC_SINGLE_EXT ("I2SDOLS" ,MT6660_REG_DATAO_SEL ,3 ,7 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw), +SOC_SINGLE_EXT ("I2SDORS" ,MT6660_REG_DATAO_SEL ,0 ,7 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw),
What do these controls do?
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Dear Mark:
Thanks for your reply.
I have some questions for your comment. Please check the red comment.
Mark Brown 於 2019/9/4 上午12:38 寫道:
Quoted 22 lines · On Tue, Sep 03, 2019 at 03:08:21PM +0800, [email protected] wrote:
sound/soc/codecs/mt6660.c line 4
Quoted 8 lines
sound/soc/codecs/mt6660.c new file +4
-0@@ -0,0 +1,802 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2019 MediaTek Inc. +*/ Please make the entire comment block a C++ comment so things look more consistent.
Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10
-0+struct reg_size_table { +u32 addr; +u8 size; +}; +static const struct reg_size_table mt6660_reg_size_table[] = { + {MT6660_REG_HPF1_COEF ,4 }, + {MT6660_REG_HPF2_COEF ,4 }, + {MT6660_REG_TDM_CFG3 ,2 }, + {MT6660_REG_RESV17 ,2 }, + {MT6660_REG_RESV23 ,2 },
Quoted 8 lines
sound/soc/codecs/mt6660.c line 48
Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6
-0+ { MT6660_REG_SIGMAX, 2 }, + { MT6660_REG_DEVID, 2}, + { MT6660_REG_TDM_CFG3, 2}, + { MT6660_REG_HCLIP_CTRL, 2}, + { MT6660_REG_DA_GAIN, 2}, +};Please talk to your hardware designers about the benefits of consistent register sizes :/
Actually this is our hardware Design for MT6660. We cannot modify hardware this time.
We will design well in next chip.
Quoted 8 lines
sound/soc/codecs/mt6660.c line 63
Quoted 4 lines
sound/soc/codecs/mt6660.c new file +3
-0+static int32_t mt6660_i2c_update_bits (struct mt6660_chip *chip, +uint32_t addr,uint32_t mask,uint32_t data) +{It would be good to implement a regmap rather than open coding *everything* - it'd give you things like this without needing to open code them. Providing you don't use the cache code it should cope fine with variable register sizes.
Due to our hardware design, it is hard to implement regmap for MT6660.
Quoted 16 lines
Quoted 5 lines
sound/soc/codecs/mt6660.c new file +4
-0+ +static int mt6660_i2c_init_setting (struct mt6660_chip *chip) +{ +int i, len, ret;sound/soc/codecs/mt6660.c line 237
Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10
-0+const struct codec_reg_val *init_table; + + init_table = e4_reg_inits; + len =ARRAY_SIZE (e4_reg_inits); + +for (i =0 ; i < len; i++) { + ret =mt6660_i2c_update_bits (chip, init_table[i].addr, + init_table[i].mask, init_table[i].data); +if (ret <0 ) +return ret;Why are we not using the chip defaults here?
Because MT6660 needs this initial setting for working well.
Quoted 17 lines
Quoted 17 lines
sound/soc/codecs/mt6660.c new file +17
-0+static int mt6660_chip_power_on ( +struct snd_soc_component *component,int on_off) +{ +struct mt6660_chip *chip = (struct mt6660_chip *) +snd_soc_component_get_drvdata (component); +int ret =0 ; +unsigned int val; + +dev_dbg (component->dev,"%s: on_off = %d\n" , __func__, on_off); +mutex_lock (&chip->var_lock); +if (on_off) { +if (chip->pwr_cnt ==0 ) { + ret =mt6660_i2c_update_bits (chip, +MT6660_REG_SYSTEM_CTRL ,0x01 ,0x00 ); + val =mt6660_i2c_read (chip,MT6660_REG_IRQ_STATUS1 ); +dev_info (chip->dev, +"%s reg0x05 = 0x%x\n" , __func__, val);
Quoted 8 lines
sound/soc/codecs/mt6660.c line 56
Quoted 2 lines
sound/soc/codecs/mt6660.c new file +2
-0+ } + chip->pwr_cnt++;This looks like you're open coding runtime PM stuff? AFAICT the issue is that you need to write to this register to do any I/O. Just implement this via the standard runtime PM framework, you'll need to do something about the register I/O in the controls (ideally in the framework, it'd be a lot easier if you did have a cache) but you could cut out this bit.
In our experience, some Customer platform doesn't support runtime PM.
Do you have any suggestion about a compatible driver for support and not support runtime PM platform?
Quoted 4 lines
Quoted 4 lines
sound/soc/codecs/mt6660.c new file +4
-0+static int mt6660_component_set_bias_level (struct snd_soc_component *component, +enum snd_soc_bias_level level) +{ + struct snd_soc_dapm_context *dapm =
Quoted 8 lines
sound/soc/codecs/mt6660.c line 288
Quoted 7 lines
sound/soc/codecs/mt6660.c new file +7
-0+snd_soc_component_get_dapm (component); +int ret; +unsigned int val; +struct mt6660_chip *chip =snd_soc_component_get_drvdata (component); + +if (dapm->bias_level == level) { +dev_warn (component->dev,"%s: repeat level change\n" , __func__);This shouldn't be a warning.
I will modify it for a error message.
Quoted 9 lines
sound/soc/codecs/mt6660.c line 497
Quoted 7 lines
sound/soc/codecs/mt6660.c new file +6
-0+static const struct snd_kcontrol_new mt6660_component_snd_controls[] = { +SOC_SINGLE_EXT_TLV ("Volume_Ctrl" ,MT6660_REG_VOL_CTRL ,0 ,255 , +1 , snd_soc_get_volsw, mt6660_component_put_volsw, + vol_ctl_tlv), +SOC_SINGLE_EXT ("WDT_Enable" ,MT6660_REG_WDT_CTRL ,7 ,1 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw),These control names should all use standard ALSA control names - on/off switches should end in Switch, volume controls in Volume.
I will modify it.
Quoted 8 lines
sound/soc/codecs/mt6660.c line 514
Quoted 7 lines
sound/soc/codecs/mt6660.c new file +6
-0+SOC_SINGLE_EXT ("I2SLRS" ,MT6660_REG_DATAO_SEL ,6 ,3 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw), +SOC_SINGLE_EXT ("I2SDOLS" ,MT6660_REG_DATAO_SEL ,3 ,7 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw), +SOC_SINGLE_EXT ("I2SDORS" ,MT6660_REG_DATAO_SEL ,0 ,7 ,0 , + snd_soc_get_volsw, mt6660_component_put_volsw),What do these controls do?
i will modify kcontrol names for more detail description.
Thanks & BRs
Richtek Jeff Chang.
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainerQuoted 10 lines · Richtek Jeff Chang
Quoted 8 lines
sound/soc/codecs/mt6660.c line 63
Quoted 3 lines
sound/soc/codecs/mt6660.c new file +3
-0+static int32_t mt6660_i2c_update_bits (struct mt6660_chip *chip, +uint32_t addr,uint32_t mask,uint32_t data) +{It would be good to implement a regmap rather than open coding *everything* - it'd give you things like this without needing to open code them. Providing you don't use the cache code it should cope fine with variable register sizes.
Due to our hardware design, it is hard to implement regmap for MT6660.
You definitely can't use all the functionality due to the variable register sizes but using reg_write() and reg_read() should get you most of it.
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/mt6660.c new file +7
-0+static int mt6660_i2c_init_setting (struct mt6660_chip *chip) +{ +int i, len, ret; +const struct codec_reg_val *init_table; + + init_table = e4_reg_inits; + len =ARRAY_SIZE (e4_reg_inits);Quoted 8 lines
sound/soc/codecs/mt6660.c line 237
Quoted 6 lines
sound/soc/codecs/mt6660.c new file +6
-0+ +for (i =0 ; i < len; i++) { + ret =mt6660_i2c_update_bits (chip, init_table[i].addr, + init_table[i].mask, init_table[i].data); +if (ret <0 ) +return ret;Why are we not using the chip defaults here?
Quoted 1 line
Because MT6660 needs this initial setting for working well.
What are these settings? Are you sure they are generic settings and not board specific?
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/codecs/mt6660.c new file +8
-0+if (on_off) { +if (chip->pwr_cnt ==0 ) { + ret =mt6660_i2c_update_bits (chip, +MT6660_REG_SYSTEM_CTRL ,0x01 ,0x00 ); + val =mt6660_i2c_read (chip,MT6660_REG_IRQ_STATUS1 ); +dev_info (chip->dev, +"%s reg0x05 = 0x%x\n" , __func__, val); + }Quoted 8 lines
sound/soc/codecs/mt6660.c line 260
Quoted 1 line
sound/soc/codecs/mt6660.c new file +1
-0+ chip->pwr_cnt++;This looks like you're open coding runtime PM stuff? AFAICT the issue is that you need to write to this register to do any I/O. Just implement this via the standard runtime PM framework, you'll need to do something about the register I/O in the controls (ideally in the framework, it'd be a lot easier if you did have a cache) but you could cut out this bit.
Quoted 1 line
In our experience, some Customer platform doesn't support runtime PM.
Tell your customers to turn it on, it's a standard kernel framework and there's really no excuse for open coding it. If there's some reason why runtime PM can't work for them then we should get that fixed but it really is *very* widely deployed.
Dear Mark:
Thanks for your reply.
But I still have some questions. please check the red comment.
Mark Brown 於 2019/9/4 下午7:56 寫道:
Quoted 9 lines · Richtek Jeff Chang
Quoted 8 lines
Quoted 8 lines
sound/soc/codecs/mt6660.c line 63
Quoted 4 lines
sound/soc/codecs/mt6660.c new file +3
-0+static int32_t mt6660_i2c_update_bits (struct mt6660_chip *chip, +uint32_t addr,uint32_t mask,uint32_t data) +{It would be good to implement a regmap rather than open coding *everything* - it'd give you things like this without needing to open code them. Providing you don't use the cache code it should cope fine with variable register sizes.
Quoted 4 lines
Quoted 1 line
Due to our hardware design, it is hard to implement regmap for MT6660.
You definitely can't use all the functionality due to the variable register sizes but using
reg_write()andreg_read()should get you most of it.
How can I fill the val_bits for variable register size?
I try to use all 32 bits val_bits, but our chip some registers are overlap...
Do you have any suggestion for this issue? Thank you very much!
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
sound/soc/codecs/mt6660.c new file +3
-0+static int mt6660_i2c_init_setting (struct mt6660_chip *chip) +{ +int i, len, ret;sound/soc/codecs/mt6660.c line 237
Quoted 10 lines
sound/soc/codecs/mt6660.c new file +10
-0+const struct codec_reg_val *init_table; + + init_table = e4_reg_inits; + len =ARRAY_SIZE (e4_reg_inits); + +for (i =0 ; i < len; i++) { + ret =mt6660_i2c_update_bits (chip, init_table[i].addr, + init_table[i].mask, init_table[i].data); +if (ret <0 ) +return ret;Why are we not using the chip defaults here?
Quoted 3 lines
Quoted 1 line
Because MT6660 needs this initial setting for working well.
What are these settings? Are you sure they are generic settings and not board specific?
Yes, they are generic setting. It comes from our hardware designers.
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
sound/soc/codecs/mt6660.c line 260
Quoted 9 lines
sound/soc/codecs/mt6660.c new file +9
-0+if (on_off) { +if (chip->pwr_cnt ==0 ) { + ret =mt6660_i2c_update_bits (chip, +MT6660_REG_SYSTEM_CTRL ,0x01 ,0x00 ); + val =mt6660_i2c_read (chip,MT6660_REG_IRQ_STATUS1 ); +dev_info (chip->dev, +"%s reg0x05 = 0x%x\n" , __func__, val); + } + chip->pwr_cnt++;This looks like you're open coding runtime PM stuff? AFAICT the issue is that you need to write to this register to do any I/O. Just implement this via the standard runtime PM framework, you'll need to do something about the register I/O in the controls (ideally in the framework, it'd be a lot easier if you did have a cache) but you could cut out this bit.
Quoted 5 lines
Quoted 1 line
In our experience, some Customer platform doesn't support runtime PM.
Tell your customers to turn it on, it's a standard kernel framework and there's really no excuse for open coding it. If there's some reason why runtime PM can't work for them then we should get that fixed but it really is *very* widely deployed.
We already implement it in runtime PM.
For all your comment, regmap is a hard thing to modify. I also survey others driver about variable register size. But it seems no one like our MT6660 chip...
Should I send new patch file to you in this mail loop, or I should send new patch via new Email Loop?
Thanks a lot.
Richtek Jeff Chang
_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainerQuoted 13 lines · Richtek Jeff Chang
Mark Brown 於 2019/9/4 下午7:56 寫道:
Quoted 11 lines · Richtek Jeff Chang
Quoted 7 lines
Quoted 5 lines
It would be good to implement a regmap rather than open coding *everything* - it'd give you things like this without needing to open code them. Providing you don't use the cache code it should cope fine with variable register sizes.
Due to our hardware design, it is hard to implement regmap for MT6660.
You definitely can't use all the functionality due to the variable register sizes but using
reg_write()andreg_read()should get you most of it.
Quoted 6 lines
How can I fill the
val_bitsfor variable register size?I try to use all 32 bits
val_bits, but our chip some registers are overlap...Do you have any suggestion for this issue? Thank you very much!
If you use reg_read() and reg_write() operations you can hide the register size within them - the rest of the code thinks the registers are all the 32 bits but when doing I/O it can use the appropriate size for a given register.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
sound/soc/codecs/mt6660.c line 237
Quoted 5 lines
sound/soc/codecs/mt6660.c new file +5
-0+for (i =0 ; i < len; i++) { + ret =mt6660_i2c_update_bits (chip, init_table[i].addr, + init_table[i].mask, init_table[i].data); +if (ret <0 ) +return ret;Why are we not using the chip defaults here?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Because MT6660 needs this initial setting for working well.
What are these settings? Are you sure they are generic settings and not board specific?
Yes, they are generic setting. It comes from our hardware designers.
You should probably be using the regmap register patch feature, it's for things like this where the chip should always be used with a different set of defaults to the silicon.
Quoted 2 lines
Should I send new patch file to you in this mail loop, or I should send new patch via new Email Loop?
A new one please.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel