ASoC: tas2552: Support TI TAS2552 Amplifier
RFC PATCH 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.
--- .../devicetree/bindings/sound/tas2552.txt | 22 + include/sound/tas2552-plat.h | 30 + sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tas2552.c | 631 ++++++++++++++++++++ sound/soc/codecs/tas2552.h | 79 +++ 6 files changed, 769 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 +22 -0
@@ -0,0 +1,22 @@ +Texas Instruments - tas2552 Codec module + +The tas2552 serial control bus communicates through I2C protocols + +Required properties: + +- compatible - "string" - One of: + "ti,tas2552" - TAS2552 + +- reg - <int> - I2C slave address + +Optional properties: + +- power-gpio - gpio pin to enable/disable the device + +Example: + +tas2552: tas2552@41 { + compatible = "ti,tas2552"; + reg = <0x41>; + power-gpio = <&gpio4 2 GPIO_ACTIVE_HIGH>; +};
include/sound/tas2552-plat.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA +*/ + +#ifndef TAS2552_PLAT_H +#define TAS2552_PLAT_H + +struct tas2552_platform_data { +int power_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
@@ -746,4 +747,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
@@ -160,6 +160,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
@@ -321,3 +322,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 +631 -0
631 lines not on this page · raw message
sound/soc/codecs/tas2552.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Mark Brown
maintainersound/soc/codecs/tas2552.c line 64
Quoted 11 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +11
-0+static int tas2552_i2c_read (struct tas2552_data *tas_data,int reg) +{ +int val; + +if (WARN_ON (!tas_data->tas2552_client)) +return -EINVAL ; + +/* If powered off, return the cached value */ +mutex_lock (&tas_data->mutex); +if (tas_data->power_state) { + val =i2c_smbus_read_byte_data (tas_data->tas2552_client, reg);
Don't open code your I/O, use regmap like any other CODEC driver. This will remove a very large proportion of the code in the driver which replicates features of the regmap framework.
sound/soc/codecs/tas2552.c line 435
Quoted 11 lines
sound/soc/codecs/tas2552.c new file +11
-0+static int tas2552_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_soc_codec *codec = dai->codec; +struct tas2552_data *tas2552 =snd_soc_codec_get_drvdata (codec); + +tas2552_sw_shutdown (tas2552,1 ); +tas2552_power (tas2552,1 ); +/* Turn on Class D amplifier */ +tas2552_i2c_write (tas2552,TAS2552_CFG_2 ,0x80 ); +tas2552_sw_shutdown (tas2552,0 );
I'd expect this to be done using DAPM.
sound/soc/codecs/tas2552.c line 521
Quoted 7 lines
sound/soc/codecs/tas2552.c new file +7
-0+static const struct regmap_config tas2552_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + + .max_register =TAS2552_MAX_REG , + .reg_defaults =NULL , + .num_reg_defaults =0 ,
No need to set things to zero or NULL in static variables, that's the default.
sound/soc/codecs/tas2552.c line 537
Quoted 4 lines
sound/soc/codecs/tas2552.c new file +4
-0+ dev = &client->dev; + data =devm_kzalloc (&client->dev,sizeof (*data),GFP_KERNEL ); +if (data ==NULL ) { +dev_err (dev,"Can not allocate memory\n" );
No need to print an error, OOM messages are already quite noisy.
Mark
Thanks for the comments
Quoted 16 lines · Mark Brown
sound/soc/codecs/tas2552.c line 64
Quoted 11 lines · Dan Murphy
sound/soc/codecs/tas2552.c new file +11
-0+static int tas2552_i2c_read (struct tas2552_data *tas_data,int reg) +{ +int val; + +if (WARN_ON (!tas_data->tas2552_client)) +return -EINVAL ; + +/* If powered off, return the cached value */ +mutex_lock (&tas_data->mutex); +if (tas_data->power_state) { + val =i2c_smbus_read_byte_data (tas_data->tas2552_client, reg);Don't open code your I/O, use regmap like any other CODEC driver. This will remove a very large proportion of the code in the driver which replicates features of the regmap framework.
My initial implementation was with regmap but it gave me heart ache. Which could have been wonky HW.
I will attempt regmap again and see if it was just a HW issue.
Quoted 13 lines
sound/soc/codecs/tas2552.c line 435
Quoted 12 lines
sound/soc/codecs/tas2552.c new file +11
-0+static int tas2552_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *dai) +{ +struct snd_soc_codec *codec = dai->codec; +struct tas2552_data *tas2552 =snd_soc_codec_get_drvdata (codec); + +tas2552_sw_shutdown (tas2552,1 ); +tas2552_power (tas2552,1 ); +/* Turn on Class D amplifier */ +tas2552_i2c_write (tas2552,TAS2552_CFG_2 ,0x80 ); +tas2552_sw_shutdown (tas2552,0 );I'd expect this to be done using DAPM.
Will take a look at it for V2.
Quoted 10 lines
sound/soc/codecs/tas2552.c line 521
Quoted 8 lines
sound/soc/codecs/tas2552.c new file +7
-0+static const struct regmap_config tas2552_regmap_config = { + .reg_bits =8 , + .val_bits =8 , + + .max_register =TAS2552_MAX_REG , + .reg_defaults =NULL , + .num_reg_defaults =0 ,No need to set things to zero or NULL in static variables, that's the default.
This was an artifact from my regmap implementation. This will be populated when I re-implement the regmap code.
Quoted 5 lines
sound/soc/codecs/tas2552.c line 537
Quoted 4 lines
sound/soc/codecs/tas2552.c new file +4
-0+ dev = &client->dev; + data =devm_kzalloc (&client->dev,sizeof (*data),GFP_KERNEL ); +if (data ==NULL ) { +dev_err (dev,"Can not allocate memory\n" );No need to print an error, OOM messages are already quite noisy.
Will remove.
Dan
Signature · 2 lines
------------------ Dan Murphy