ASoC: tas2552: Support TI TAS2552 Amplifier
PATCH v4 1/1 ASoC: tas2552: Support TI TAS2552 Amplifier
Support the TI TAS2552 Class D amplifier.
The TAS2552 is a high efficiency Class-D audio power amplifier with advanced battery current management and an integrated Class-G boost The device constantly measures the
current and voltage across the load and provides a digital stream of this information.
---
v4 - Added pm_runtime support, removed magical numbers, added regulator support, changed from legacy gpio to new gpiod calls, fixed default register values, flipped on battery tracking support and
added suspend/resume support - https://patchwork.kernel.org/patch/4465611/
.../devicetree/bindings/sound/tas2552.txt | 25 + include/sound/tas2552-plat.h | 25 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2552.c | 574 ++++++++++++++++++++ sound/soc/codecs/tas2552.h | 119 ++++ 6 files changed, 750 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/tas2552.txt create mode 100644 include/sound/tas2552-plat.h create mode 100644 sound/soc/codecs/tas2552.c create mode 100644 sound/soc/codecs/tas2552.h
Documentation/devicetree/bindings/sound/tas2552.txt new file +25 -0
@@ -0,0 +1,25 @@ +Texas Instruments - tas2552 Codec module + +The tas2552 serial control bus communicates through I2C protocols + +Required properties: + +- compatible - One of: + "ti,tas2552" - TAS2552 + +- reg - I2C slave address + +Optional properties: + +- enable-gpio - gpio pin to enable/disable the device + +Example: + +tas2552: tas2552@41 { + compatible = "ti,tas2552"; + reg = <0x41>; + enable-gpio = <&gpio4 2 GPIO_ACTIVE_HIGH>; +}; + +For more product information please see the link below: +http://www.ti.com/product/TAS2552
include/sound/tas2552-plat.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* TAS2552 driver platform header +* +* Copyright (C) 2014 Texas Instruments Inc. +* +* Author: Dan Murphy <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +*/ + +#ifndef TAS2552_PLAT_H +#define TAS2552_PLAT_H + +struct tas2552_platform_data { +int enable_gpio; +}; + +#endif
sound/soc/codecs/Kconfig +5 -0
@@ -99,6 +99,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_TLV320AIC32X4 if I2C select SND_SOC_TLV320AIC3X if I2C select SND_SOC_TPA6130A2 if I2C + select SND_SOC_TAS2552 if I2C select SND_SOC_TLV320DAC33 if I2C select SND_SOC_TWL4030 if TWL4030_CORE select SND_SOC_TWL6040 if TWL6040_CORE
@@ -754,4 +755,8 @@ config SND_SOC_TPA6130A2 tristate "Texas Instruments TPA6130A2 headphone amplifier" depends on I2C +config SND_SOC_TAS2552 + tristate "Texas Instruments TAS2552 Mono Audio amplifier" + depends on I2C + endmenu
sound/soc/codecs/Makefile +2 -0
@@ -162,6 +162,7 @@ snd-soc-wm-hubs-objs := wm_hubs.o # Amp snd-soc-max9877-objs := max9877.o snd-soc-tpa6130a2-objs := tpa6130a2.o +snd-soc-tas2552-objs := tas2552.o obj-$(CONFIG_SND_SOC_88PM860X) += snd-soc-88pm860x.o obj-$(CONFIG_SND_SOC_AB8500_CODEC) += snd-soc-ab8500-codec.o
@@ -325,3 +326,4 @@ obj-$(CONFIG_SND_SOC_WM_HUBS) += snd-soc-wm-hubs.o # Amp obj-$(CONFIG_SND_SOC_MAX9877) += snd-soc-max9877.o obj-$(CONFIG_SND_SOC_TPA6130A2) += snd-soc-tpa6130a2.o +obj-$(CONFIG_SND_SOC_TAS2552) += snd-soc-tas2552.o
sound/soc/codecs/tas2552.c new file +574 -0
574 lines not on this page · raw message
sound/soc/codecs/tas2552.h new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Hi,
Quoted 19 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +19
-0+static int tas2552_set_dai_fmt (struct snd_soc_dai *dai,unsigned int fmt) +{ +u8 serial_format; +struct snd_soc_codec *codec = dai->codec; + +switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBS_CFS : + serial_format =0x00 ; +break ; +case SND_SOC_DAIFMT_CBS_CFM : + serial_format =TAS2552_WORD_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + serial_format =TAS2552_BIT_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : + serial_format = (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ); +break ; +default :
sound/soc/codecs/tas2552.c line 191
Quoted 10 lines
sound/soc/codecs/tas2552.c new file +10
-0+return -EINVAL ; + } + +pm_runtime_get_sync (codec->dev); + +snd_soc_update_bits (codec,TAS2552_SER_CTRL_1 , + (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ), + serial_format); + +pm_runtime_put (codec->dev);
I have a feeling it's better to just put at the end of the function. Remember your pm_runtime_put() will issue i2c transfers which can take a looooooong time ;-)
other than that, looks ok to me:
Signature · 1 line
balbi
Quoted 27 lines · Felipe Balbi
Hi,
Quoted 24 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +24
-0+static int tas2552_set_dai_fmt (struct snd_soc_dai *dai,unsigned int fmt) +{ +u8 serial_format; +struct snd_soc_codec *codec = dai->codec; + +switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBS_CFS : + serial_format =0x00 ; +break ; +case SND_SOC_DAIFMT_CBS_CFM : + serial_format =TAS2552_WORD_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + serial_format =TAS2552_BIT_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : + serial_format = (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ); +break ; +default : +return -EINVAL ; + } + +pm_runtime_get_sync (codec->dev); +
Quoted 8 lines
sound/soc/codecs/tas2552.c line 191
Quoted 5 lines
sound/soc/codecs/tas2552.c new file +5
-0+snd_soc_update_bits (codec,TAS2552_SER_CTRL_1 , + (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ), + serial_format); + +pm_runtime_put (codec->dev);I have a feeling it's better to just put at the end of the function. Remember your
pm_runtime_put()will issue i2c transfers which can take a looooooong time ;-)
I thought about that but the next switch case could return if the format mask is invalid which means the runtime calls would not be balanced.
So I decided to wrap the snd_soc calls with the pm_runtime calls to keep it balanced.
Dan
Quoted 5 lines
other than that, looks ok to me:
Reviewed-by Felipe Balbi <[email protected]>
Signature · 2 lines
------------------ Dan Murphy
Hi,
Quoted 37 lines · Dan Murphy
Quoted 27 lines · Felipe Balbi
Hi,
Quoted 24 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +24
-0+static int tas2552_set_dai_fmt (struct snd_soc_dai *dai,unsigned int fmt) +{ +u8 serial_format; +struct snd_soc_codec *codec = dai->codec; + +switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBS_CFS : + serial_format =0x00 ; +break ; +case SND_SOC_DAIFMT_CBS_CFM : + serial_format =TAS2552_WORD_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + serial_format =TAS2552_BIT_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : + serial_format = (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ); +break ; +default : +return -EINVAL ; + } + +pm_runtime_get_sync (codec->dev); +Quoted 8 lines
sound/soc/codecs/tas2552.c line 191
Quoted 5 lines
sound/soc/codecs/tas2552.c new file +5
-0+snd_soc_update_bits (codec,TAS2552_SER_CTRL_1 , + (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ), + serial_format); + +pm_runtime_put (codec->dev);I have a feeling it's better to just put at the end of the function. Remember your
pm_runtime_put()will issue i2c transfers which can take a looooooong time ;-)
Quoted 5 lines
I thought about that but the next switch case could return if the format mask is invalid which means the runtime calls would not be balanced.
So I decided to wrap the
snd_soccalls with thepm_runtimecalls to keep it balanced.
it looks like you can do both switch statements outside of the pm_runtime region and cache results on serial_format and do a single write to CTRL_1 register (?). If not, then just use two local variables.
Signature · 1 line
balbi
Hi
Quoted 39 lines · Felipe Balbi
Hi,
Quoted 36 lines · Dan Murphy
Quoted 35 lines · Felipe Balbi
Hi,
Quoted 19 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +19
-0+static int tas2552_set_dai_fmt (struct snd_soc_dai *dai,unsigned int fmt) +{ +u8 serial_format; +struct snd_soc_codec *codec = dai->codec; + +switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBS_CFS : + serial_format =0x00 ; +break ; +case SND_SOC_DAIFMT_CBS_CFM : + serial_format =TAS2552_WORD_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + serial_format =TAS2552_BIT_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : + serial_format = (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ); +break ; +default :sound/soc/codecs/tas2552.c line 191
Quoted 10 lines
sound/soc/codecs/tas2552.c new file +10
-0+return -EINVAL ; + } + +pm_runtime_get_sync (codec->dev); + +snd_soc_update_bits (codec,TAS2552_SER_CTRL_1 , + (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ), + serial_format); + +pm_runtime_put (codec->dev);I have a feeling it's better to just put at the end of the function. Remember your
pm_runtime_put()will issue i2c transfers which can take a looooooong time ;-)
Quoted 9 lines
Quoted 5 lines
I thought about that but the next switch case could return if the format mask is invalid which means the runtime calls would not be balanced.
So I decided to wrap the
snd_soccalls with thepm_runtimecalls to keep it balanced.it looks like you can do both switch statements outside of the
pm_runtimeregion and cache results onserial_formatand do a single write toCTRL_1register (?). If not, then just use two local variables.
Yeah I could probably consolidate these into a single call. And throw a debug statement in the default case to why the format was not set.
Dan
Signature · 2 lines
------------------ Dan Murphy
Quoted 47 lines · Dan Murphy
Hi
Quoted 44 lines · Felipe Balbi
Hi,
Quoted 41 lines · Dan Murphy
Quoted 27 lines · Felipe Balbi
Hi,
Quoted 24 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +24
-0+static int tas2552_set_dai_fmt (struct snd_soc_dai *dai,unsigned int fmt) +{ +u8 serial_format; +struct snd_soc_codec *codec = dai->codec; + +switch (fmt &SND_SOC_DAIFMT_MASTER_MASK ) { +case SND_SOC_DAIFMT_CBS_CFS : + serial_format =0x00 ; +break ; +case SND_SOC_DAIFMT_CBS_CFM : + serial_format =TAS2552_WORD_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFS : + serial_format =TAS2552_BIT_CLK_MASK ; +break ; +case SND_SOC_DAIFMT_CBM_CFM : + serial_format = (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ); +break ; +default : +return -EINVAL ; + } + +pm_runtime_get_sync (codec->dev); +Quoted 8 lines
sound/soc/codecs/tas2552.c line 191
Quoted 5 lines
sound/soc/codecs/tas2552.c new file +5
-0+snd_soc_update_bits (codec,TAS2552_SER_CTRL_1 , + (TAS2552_BIT_CLK_MASK |TAS2552_WORD_CLK_MASK ), + serial_format); + +pm_runtime_put (codec->dev);I have a feeling it's better to just put at the end of the function. Remember your
pm_runtime_put()will issue i2c transfers which can take a looooooong time ;-)I thought about that but the next switch case could return if the format mask is invalid which means the runtime calls would not be balanced.
So I decided to wrap the
snd_soccalls with thepm_runtimecalls to keep it balanced.
Quoted 7 lines
Quoted 4 lines
it looks like you can do both switch statements outside of the
pm_runtimeregion and cache results onserial_formatand do a single write toCTRL_1register (?). If not, then just use two local variables.Yeah I could probably consolidate these into a single call. And throw a debug statement in the default case to why the format was not set.
that'd be cool.
Signature · 1 line
balbi