dt-bindings: ASoC: Add tas2770 smart PA dt bindings
PATCH v4 1/1 dt-bindings: ASoC: Add tas2770 smart PA dt bindings
From: Frank Shi <[email protected]>
Add tas2770 smart PA dt bindings
--- .../devicetree/bindings/sound/tas2770.txt | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/tas2770.txt
Documentation/devicetree/bindings/sound/tas2770.txt new file +37 -0
@@ -0,0 +1,37 @@ +Texas Instruments TAS2770 Smart PA + +The TAS2770 is a mono, digital input Class-D audio amplifier optimized for +efficiently driving high peak power into small loudspeakers. +Integrated speaker voltage and current sense provides for +real time monitoring of loudspeaker behavior. + +Required properties: + + - compatible: - Should contain "ti,tas2770". + - reg: - The i2c address. Should contain <0x4c>, <0x4d>,<0x4e>, or <0x4f>. + - #address-cells - Should be <1>. + - #size-cells - Should be <0>. + - ti,asi-format: - Sets TDM RX capture edge. 0->Rising; 1->Falling. + - ti,imon-slot-no:- TDM TX current sense time slot. + - ti,vmon-slot-no:- TDM TX voltage sense time slot. + +Optional properties: + +- interrupt-parent: the phandle to the interrupt controller which provides + the interrupt. +- interrupts: interrupt specification for data-ready. + +Examples: + + tas2770@4c { + compatible = "ti,tas2770"; + reg = <0x4c>; + #address-cells = <1>; + #size-cells = <0>; + interrupt-parent = <&msm_gpio>; + interrupts = <97 0>; + ti,asi-format = <0>; + ti,imon-slot-no = <0>; + ti,vmon-slot-no = <2>; + }; +
Signature · 1 line
2.7.4
PATCH v4 1/1 tas2770: Add tas2770 smart PA kernel driver
From: Frank Shi <[email protected]>
Add tas2770 smart PA kernel driver
--- sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2770.c | 932 +++++++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/tas2770.h | 166 ++++++++ 4 files changed, 1105 insertions(+) create mode 100644 sound/soc/codecs/tas2770.c create mode 100644 sound/soc/codecs/tas2770.h
sound/soc/codecs/Kconfig +5 -0
@@ -111,6 +111,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_STAC9766 if SND_SOC_AC97_BUS select SND_SOC_STI_SAS select SND_SOC_TAS2552 if I2C + select SND_SOC_TAS2770 if I2C select SND_SOC_TAS5086 if I2C select SND_SOC_TAS571X if I2C select SND_SOC_TFA9879 if I2C
@@ -652,6 +653,10 @@ config SND_SOC_TAS2552 tristate "Texas Instruments TAS2552 Mono Audio amplifier" depends on I2C +config SND_SOC_TAS2770 + tristate "Texas Instruments TAS2770 speaker amplifier" + depends on I2C + config SND_SOC_TAS5086 tristate "Texas Instruments TAS5086 speaker amplifier" depends on I2C
sound/soc/codecs/Makefile +2 -0
@@ -116,6 +116,7 @@ snd-soc-stac9766-objs := stac9766.o snd-soc-sti-sas-objs := sti-sas.o snd-soc-tas5086-objs := tas5086.o snd-soc-tas571x-objs := tas571x.o +snd-soc-tas2770-objs := tas2770.o snd-soc-tfa9879-objs := tfa9879.o snd-soc-tlv320aic23-objs := tlv320aic23.o snd-soc-tlv320aic23-i2c-objs := tlv320aic23-i2c.o
@@ -332,6 +333,7 @@ obj-$(CONFIG_SND_SOC_STI_SAS) += snd-soc-sti-sas.o obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o obj-$(CONFIG_SND_SOC_TAS5086) += snd-soc-tas5086.o obj-$(CONFIG_SND_SOC_TAS571X) += snd-soc-tas571x.o +obj-$(CONFIG_SND_SOC_TAS2770) += snd-soc-tas2770.o obj-$(CONFIG_SND_SOC_TFA9879) += snd-soc-tfa9879.o obj-$(CONFIG_SND_SOC_TLV320AIC23) += snd-soc-tlv320aic23.o obj-$(CONFIG_SND_SOC_TLV320AIC23_I2C) += snd-soc-tlv320aic23-i2c.o
sound/soc/codecs/tas2770.c new file +932 -0
932 lines not on this page · raw message
sound/soc/codecs/tas2770.h new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.7.4
Mark Brown
maintainerRe: [PATCH v4] tas2770: Add tas2770 smart PA kernel driver
Quoted 3 lines · On Mon, Sep 16, 2019 at 09:38:01AM +0800, [email protected] wrote:
From: Frank Shi <[email protected]>
Add tas2770 smart PA kernel driver
This is a great improvement, thanks. There's still some issues though, including some confusion over the use of bias levels - it seems like there's fairly poor integration with standard power management, it's not clear what's going on there. We do also still have some code that resets the CODEC which is concerning.
Quoted 1 line
+#define
TAS2770_CHECK_PERIOD5000 /* 5 second */
We don't need this any more.
sound/soc/codecs/tas2770.c line 62
Quoted 6 lines
sound/soc/codecs/tas2770.c new file +6
-0+case SND_SOC_BIAS_STANDBY : +snd_soc_component_update_bits (component,TAS2770_PWR_CTRL , +TAS2770_PWR_CTRL_MASK , +TAS2770_PWR_CTRL_ACTIVE ); + tas2770->power_state =SND_SOC_BIAS_STANDBY ; +break ;
We already store the bias level in the component's dapm struct, no need to duplicate it.
sound/soc/codecs/tas2770.c line 67
Quoted 4 lines
sound/soc/codecs/tas2770.c new file +4
-0+case SND_SOC_BIAS_PREPARE : +snd_soc_component_update_bits (component,TAS2770_PWR_CTRL , +TAS2770_PWR_CTRL_MASK , +TAS2770_PWR_CTRL_MUTE );
We shouldn't be muting and unmuting here, leave this to the digital mute operation.
sound/soc/codecs/tas2770.c line 94
Quoted 8 lines
sound/soc/codecs/tas2770.c new file +8
-0+#ifdef CONFIG_PM +static int tas2770_codec_suspend (struct snd_soc_component *component) +{ +int ret; + + ret =tas2770_set_bias_level (component,SND_SOC_BIAS_OFF ); +if (ret) +return -EINVAL ;
Pass back error codes you get from functions, however it looks like you can just set the device as idle_bias_off and have the core do this for you anyway (plus more at runtime) - there's no appreciable delays I can see in power on and off.
Quoted 5 lines
sound/soc/codecs/tas2770.c new file +5
-0+static int tas2770_dac_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);
sound/soc/codecs/tas2770.c line 139
Quoted 10 lines
sound/soc/codecs/tas2770.c new file +10
-0+struct tas2770_priv *tas2770 = +snd_soc_component_get_drvdata (component); +int ret; + +switch (event) { +case SND_SOC_DAPM_POST_PMU : + ret =tas2770_set_bias_level (component, +SND_SOC_BIAS_PREPARE ); +if (ret) + goto end;
This is very, very bad - DAPM will control the bias level for the CODEC, you should not be trying to control it from within DAPM callbacks. This will only lead to breakage. What is this intended to do?
sound/soc/codecs/tas2770.c line 198
Quoted 12 lines
sound/soc/codecs/tas2770.c new file +12
-0+static int tas2770_mute (struct snd_soc_dai *dai,int mute) +{ +struct snd_soc_component *component = dai->component; +int ret; + +if (mute) + ret =tas2770_set_bias_level (component,SND_SOC_BIAS_PREPARE ); +else + ret =tas2770_set_bias_level (component,SND_SOC_BIAS_STANDBY ); + +return ret; +}
This is more bias level misuse, you are independently setting the bias level in multiple different ways from many different call sites. This can only need to problems, I am surprised this works well for you as things stand.
If the device doesn't have a mute operation it is fine to not have one.
sound/soc/codecs/tas2770.c line 405
Quoted 3 lines
sound/soc/codecs/tas2770.c new file +3
-0+switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) { +case (SND_SOC_DAIFMT_I2S ): + tdm_rx_start_slot =1 ;
These brackets around the case statements are not the normal Linux coding style (this isn't an issue in the rest of the driver...).
sound/soc/codecs/tas2770.c line 504
Quoted 4 lines
sound/soc/codecs/tas2770.c new file +4
-0+case 0 : +/* Do not change slot width */ + ret =0 ; +break ;
Please align the breaks and comments with the rest of the code inside the case.
sound/soc/codecs/tas2770.c line 570
Quoted 4 lines
sound/soc/codecs/tas2770.c new file +4
-0+static const struct snd_kcontrol_new tas2770_snd_controls[] = { +SOC_SINGLE_TLV ("Amp Output Gain" ,TAS2770_PLAY_CFG_REG0 , +0 ,0x14 ,0 , + tas2770_digital_tlv),
Volume controls should end in Volume - see control-names.rst
Quoted 11 lines
sound/soc/codecs/tas2770.c new file +11
-0+static irqreturn_t tas2770_irq_handler (int irq,void *dev_id) +{ +struct tas2770_priv *tas2770 = (struct tas2770_priv *)dev_id; +struct snd_soc_component *component = tas2770->component; +unsigned int device_status_1 =0 , device_status_2 =0 ; +int result; + +if (tas2770->runtime_suspend) + goto end; + +if (tas2770->power_state ==TAS2770_POWER_SHUTDOWN )
sound/soc/codecs/tas2770.c line 725
Quoted 10 lines
sound/soc/codecs/tas2770.c new file +10
-0+ goto end; + + result =snd_soc_component_write (component,TAS2770_INT_MASK_REG0 , +TAS2770_INT_MASK_REG0_DISABLE ); +if (result) + goto reload; + result =snd_soc_component_write (component,TAS2770_INT_MASK_REG1 , +TAS2770_INT_MASK_REG1_DISABLE ); +if (result) + goto reload;
The interrupt handler appears to be masking interrupts? Why?
sound/soc/codecs/tas2770.c line 729
Quoted 3 lines
sound/soc/codecs/tas2770.c new file +3
-0+ result =snd_soc_component_read (tas2770->component, +TAS2770_LAT_INT_REG0 , &device_status_1); +if (!result && (device_status_1 &0x3 )) {
If we fail to do I/O with the device we should report an error.
sound/soc/codecs/tas2770.c line 789
Quoted 3 lines
sound/soc/codecs/tas2770.c new file +3
-0+reload: +/* hardware reset and reload */ +tas2770_load_config (tas2770);
Why are we doing a hardware reset in the interrupt handler, and how is this coordinated with anything else that's going on.
sound/soc/codecs/tas2770.c line 793
Quoted 3 lines
sound/soc/codecs/tas2770.c new file +3
-0+end: +return IRQ_HANDLED ; +}
This unconditionally reports the interrupt as handled, this prevents the interrupt line being shared and stops the interrupt core from doing error handling if anything goes wrong.
sound/soc/codecs/tas2770.c line 838
Quoted 2 lines
sound/soc/codecs/tas2770.c new file +2
-0+ tas2770->dev = &client->dev; + tas2770->irq_gpio = client->irq;
This isn't a GPIO, it's an interrupt - calling this irq_gpio is very confusing.