ASoC: TPA6130A2 amplifier driver
Subsystems (3)
PATCH 1/1 ASoC: TPA6130A2 amplifier driver
Driver for Texas Instruments TPA6130A2 stereo headphone amplifier.
The driver provides playback gain control and also pre-defined DAPM_HP widgets and DAPM routings for power management.
The DAPM_HP widget names are:
"TPA6130A2 Headphone Left"
"TPA6130A2 Headphone Right"
Quoted 1 line
From soc machine drivers to use with the tpa6130a2 amplifier,
the tpa6130a2_add_controls has to be called, which adds the alsa controls and the DAPM routing needed for the tpa6130a2. After that the machine driver can connect the codec's output with 'TPA6130A2 Left' and 'TPA6130A2 Right':
{"TPA6130A2 Left", NULL, "CODEC LEFT OUT"},
{"TPA6130A2 Right", NULL, "CODEC RIGHT OUT"},Internally the left and right channels are powered separately. When none of the channels are needed the amplifier is powered down:
hard power: valid GPIO number is passed within platform data soft power: Using the software shutdown of the amplifier
---
The previous version of the tpa6130a2 driver was part of Eduardo's series, to add audio support for RX-51.
We decided, that I'll send the tpa amplifier driver as separate patch to speed up the process.
Comments from Mark has been addressed with this patch:set_power is replaced by GPIO number.
DAPM routing added with per channel power management
Only warning is printed, when using the driver on untested version of the chip
include/sound/tpa6130a2-plat.h | 30 +++ sound/soc/codecs/Kconfig | 4 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/tpa6130a2.c | 463 ++++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/tpa6130a2.h | 62 ++++++ 5 files changed, 561 insertions(+), 0 deletions(-) create mode 100644 include/sound/tpa6130a2-plat.h create mode 100644 sound/soc/codecs/tpa6130a2.c create mode 100644 sound/soc/codecs/tpa6130a2.h
include/sound/tpa6130a2-plat.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* TPA6130A2 driver platform header +* +* Copyright (C) Nokia Corporation +* +* Written by Peter Ujfalusi <[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 TPA6130A2_PLAT_H +#define TPA6130A2_PLAT_H + +struct tpa6130a2_platform_data { +int power_gpio; +}; + +#endif
sound/soc/codecs/Kconfig +4 -0
@@ -29,6 +29,7 @@ config SND_SOC_ALL_CODECS select SND_SOC_TLV320AIC23 if I2C select SND_SOC_TLV320AIC26 if SPI_MASTER select SND_SOC_TLV320AIC3X if I2C + select SND_SOC_TPA6130A2 if I2C select SND_SOC_TWL4030 if TWL4030_CORE select SND_SOC_UDA134X select SND_SOC_UDA1380 if I2C
@@ -228,3 +229,6 @@ config SND_SOC_WM9713 # Amp config SND_SOC_MAX9877 tristate + +config SND_SOC_TPA6130A2 + tristate
sound/soc/codecs/Makefile +2 -0
@@ -49,6 +49,7 @@ snd-soc-wm-hubs-objs := wm_hubs.o # Amp snd-soc-max9877-objs := max9877.o +snd-soc-tpa6130a2-objs := tpa6130a2.o obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o obj-$(CONFIG_SND_SOC_AD1836) += snd-soc-ad1836.o
@@ -101,3 +102,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
sound/soc/codecs/tpa6130a2.c new file +463 -0
463 lines not on this page · raw message
sound/soc/codecs/tpa6130a2.h new file +62 -0
62 lines not on this page · raw message
--
1.6.5.rc2
Quoted 20 lines · Ujfalusi Peter (Nokia-D/Tampere)
sound/soc/codecs/tpa6130a2.c new file +20
-0+static int tpa6130a2_i2c_write (int reg,u8 value) +{ +struct tpa6130a2_data *data; +int val =0 ; + +BUG_ON (tpa6130a2_client ==NULL ); + data =i2c_get_clientdata (tpa6130a2_client); + +if (data->power_state) { + val =i2c_smbus_write_byte_data (tpa6130a2_client, reg, value); +if (val <0 ) +dev_err (&tpa6130a2_client->dev,"Write failed\n" ); + } + +/* Either powered on or off, we save the context */ + data->regs[reg] = value; + +return val; +} +
<snip>
sound/soc/codecs/tpa6130a2.c line 245
Quoted 8 lines
sound/soc/codecs/tpa6130a2.c new file +8
-0+static void tpa6130a2_channel_enable (u8 channel,int enable) +{ +struct tpa6130a2_data *data; +u8 val; + +BUG_ON (tpa6130a2_client ==NULL ); + data =i2c_get_clientdata (tpa6130a2_client); +
mutex_lock()
sound/soc/codecs/tpa6130a2.c line 251
Quoted 6 lines
sound/soc/codecs/tpa6130a2.c new file +6
-0+if (enable) { +/* Enable channel */ +/* Enable amplifier */ + val =tpa6130a2_read (TPA6130A2_REG_CONTROL ); + val |= channel; +tpa6130a2_i2c_write (TPA6130A2_REG_CONTROL , val);
During the tpa6130a2_i2c_write, you read the data->power_state, that may change it's state meanwhile (preempted). Thus, I suggest you using the mutex to cover all i2c writes. (and all tpa read <-> write cycles, so that things are consistent?)
A call to tpa6130a2_power() -> preemted over somewhere here, you may have i2c accesses to a chip that's not powered up?
Quoted 7 lines
sound/soc/codecs/tpa6130a2.c new file +7
-0+ +/* Unmute channel */ + val =tpa6130a2_read (TPA6130A2_REG_VOL_MUTE ); + val &= ~channel; +tpa6130a2_i2c_write (TPA6130A2_REG_VOL_MUTE , val); + }else { +/* Disable channel */
sound/soc/codecs/tpa6130a2.c line 268
Quoted 10 lines
sound/soc/codecs/tpa6130a2.c new file +10
-0+/* Mute channel */ + val =tpa6130a2_read (TPA6130A2_REG_VOL_MUTE ); + val |= channel; +tpa6130a2_i2c_write (TPA6130A2_REG_VOL_MUTE , val); + +/* Disable amplifier */ + val =tpa6130a2_read (TPA6130A2_REG_CONTROL ); + val &= ~channel; +tpa6130a2_i2c_write (TPA6130A2_REG_CONTROL , val); + }
mutex_unlock() ?
Quoted 2 lines
(quoted diff) +2
-0+} +
Quoted 10 lines · On Friday 09 October 2009 16:10:31 Nurkkala Eero.An (EXT-Offcode/Oulu) wrote:
On Fri, 2009-10-09 at 14:55 +0200, Ujfalusi Peter (Nokia-D/Tampere)
During the
tpa6130a2_i2c_write, you read thedata->power_state, that may change it's state meanwhile (preempted). Thus, I suggest you using the mutex to cover all i2c writes. (and all tpa read <-> write cycles, so that things are consistent?)A call to
tpa6130a2_power()-> preemted over somewhere here, you may have i2c accesses to a chip that's not powered up?
Well it is very unlikely that something like this could ever happen since the tpa6130a2_channel_enable and the tpa6130a2_power is called when DAPM is enabling/disabling the path. I think in a middle of enable or disable there should not be any opposite operation running in DAPM...
But better to be safe: I can add the mutex_lock, unlock pair.
I'll wait for more comments and address this one as well.
Signature · 1 line
Péter
Quoted 14 lines
Quoted 8 lines
During the
tpa6130a2_i2c_write, you read thedata->power_state, that may change it's state meanwhile (preempted). Thus, I suggest you using the mutex to cover all i2c writes. (and all tpa read <-> write cycles, so that things are consistent?)A call to
tpa6130a2_power()-> preemted over somewhere here, you may have i2c accesses to a chip that's not powered up?Well it is very unlikely that something like this could ever happen since the
tpa6130a2_channel_enableand thetpa6130a2_poweris called when DAPM is enabling/disabling the path. I think in a middle of enable or disable there should not be any opposite operation running in DAPM...
Quoted 6 lines
But better to be safe: I can add the
mutex_lock, unlock pair.I'll wait for more comments and address this one as well.
--
Péter
Right, sorry I read the patch too fast =) So I guess it's ok like it was. However, I'll put sleep(n)'s in the problematic places and verify it's 100% ok one of these weeks.
- Eero
Quoted 4 lines · Peter Ujfalusi
Well it is very unlikely that something like this could ever happen since the
tpa6130a2_channel_enableand thetpa6130a2_poweris called when DAPM is enabling/disabling the path. I think in a middle of enable or disable there should not be any opposite operation running in DAPM...
DAPM guarantees single threadedness - DAPM itself would get confused if there were more than one power update in progress at once.
Quoted 9 lines · ext Mark Brown
Quoted 4 lines · Peter Ujfalusi
Well it is very unlikely that something like this could ever happen since the
tpa6130a2_channel_enableand thetpa6130a2_poweris called when DAPM is enabling/disabling the path. I think in a middle of enable or disable there should not be any opposite operation running in DAPM...DAPM guarantees single threadedness - DAPM itself would get confused if there were more than one power update in progress at once.
I guess there's (or may be) an exception though. I think I've seen some strangeness with the close_delayed_work() -> and simultaneous mixer tweaking:
http://mailman.alsa-project.org/pipermail/alsa-devel/2009-October/021671.html
This is just an example:
Userspace thread:snd_soc_dapm_put_volsw() -> mutex_lock(&widget->codec->mutex); -> dapm_mixer_update_power() -> dapm_power_widgets() -> PRE_EMTED in damp_power_widgets()
Workqueue thread:close_delayed_work()snd_soc_dapm_stream_event() mutex_lock(&widget->codec->mutex); mutex_unlock(&widget->codec->mutex); dapm_power_widgets() -> PRE_EMTED back to Userspace thread
So there can and does run two dapm_power_widgets() when stars point to the right direction. That's when delayed work is at damp_power_widgets, and then preempted to
the userspace thread. May that isn't related to this TPA though, but I think I'll silently review the code so that the "stars are forced to point to the right direction".
(but yeah, these are just my observations, don't worry about them)
Quoted 2 lines · On Fri, Oct 09, 2009 at 08:24:49PM +0200, [email protected] wrote:
I guess there's (or may be) an exception though. I think I've seen some strangeness with the
close_delayed_work()-> and simultaneous mixer tweaking:
As I said when you posted previously that's a problem anyway and close_delayed_work() needs to be fixed. You had a half-posted patch, did you manage to test it properly (even in normal operation)? I'd been expecting a proper posting of it to appear at some point.
Quoted 6 lines
So there can and does run two
dapm_power_widgets()when stars point to the right direction. That's when delayed work is atdamp_power_widgets, and then preempted to
the userspace thread. May that isn't related to this TPA though, but I think I'll silently review the code so that the "stars are forced to point to the right direction".
This is completely unrelated to driver code, the core's data is much more of a problem than the register cache which will generally fix itself the next time DAPM does anything.
Quoted 9 lines · ext Mark Brown
Quoted 2 lines · On Fri, Oct 09, 2009 at 08:24:49PM +0200, [email protected] wrote:
I guess there's (or may be) an exception though. I think I've seen some strangeness with the
close_delayed_work()-> and simultaneous mixer tweaking:As I said when you posted previously that's a problem anyway and
close_delayed_work()needs to be fixed. You had a half-posted patch, did you manage to test it properly (even in normal operation)? I'd been expecting a proper posting of it to appear at some point.
Yes I did test it immediatelly. No apparent problems with that. However, now I use kernel 2.6.28 - and I'm about to update it next week. I wish to take the time with that patch, rather than taking the blame =) Lockdep doesn't seem to find dependencies with the mutex - until the code faces it. (I wish not to make other codecs unusable, locked up)..
Quoted 10 lines
Quoted 6 lines
So there can and does run two
dapm_power_widgets()when stars point to the right direction. That's when delayed work is atdamp_power_widgets, and then preempted to
the userspace thread. May that isn't related to this TPA though, but I think I'll silently review the code so that the "stars are forced to point to the right direction".This is completely unrelated to driver code, the core's data is much more of a problem than the register cache which will generally fix itself the next time DAPM does anything.
Yeah, agreed.
Quoted 2 lines · On Friday 09 October 2009 15:55:41 Ujfalusi Peter (Nokia-D/Tampere) wrote:
Driver for Texas Instruments TPA6130A2 stereo headphone amplifier.
The patch applies on top of sound-2.6 topic/asoc:
commit 0cce1cfa5c3cc262d9261b59dd7fa6d878775ac9
Merge: 9a6fda9 6f775ba
Author: Takashi Iwai <[email protected]>
Date: Thu Oct 8 11:50:07 2009 +0200
Merge branch 'fix/asoc'
Signature · 1 line
Péter
Quoted 1 line · Peter Ujfalusi
+struct
i2c_client*tpa6130a2_client;
This should be static.
Review
Quoted 2 lines
(quoted diff) +2
-0+void tpa6130a2_power(int power) +{
This should either be static or have an EXPORT_SYMBOL_GPL() - I'd expect the former since this is being managed via DAPM.
sound/soc/codecs/tpa6130a2.c line 375
Quoted 1 line
sound/soc/codecs/tpa6130a2.c new file +1
-0+ pdata = (struct tpa6130a2_platform_data *)client->dev.platform_data;
You should never need to cast away from void, and doing so can mask actual errors.
sound/soc/codecs/tpa6130a2.c line 413
Quoted 4 lines
sound/soc/codecs/tpa6130a2.c new file +4
-0+fail: +kfree (data); +i2c_set_clientdata (tpa6130a2_client,NULL ); + tpa6130a2_client =0 ;
The kernel coding style is to use an explict NULL.
Other than that everything looks good so I've applied this with the fixes I noted above. If you could send a followup patch for the tpa6130a2_power export/static thing that'd be good.
Thanks!
Quoted 4 lines · On Friday 09 October 2009 21:15:38 ext Mark Brown wrote:
Quoted 1 line · Peter Ujfalusi
+struct
i2c_client*tpa6130a2_client;This should be static.
Yes, it should
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+void tpa6130a2_power(int power) +{This should either be static or have an
EXPORT_SYMBOL_GPL()- I'd expect the former since this is being managed via DAPM.
Will be static, since it should be handled by the tpa6130a2 driver internally.
Quoted 5 lines
sound/soc/codecs/tpa6130a2.c line 375
Quoted 2 lines
sound/soc/codecs/tpa6130a2.c new file +1
-0+ pdata = (struct tpa6130a2_platform_data *)client->dev.platform_data;You should never need to cast away from void, and doing so can mask actual errors.
Yes.
Quoted 7 lines
sound/soc/codecs/tpa6130a2.c line 413
Quoted 5 lines
sound/soc/codecs/tpa6130a2.c new file +4
-0+fail: +kfree (data); +i2c_set_clientdata (tpa6130a2_client,NULL ); + tpa6130a2_client =0 ;The kernel coding style is to use an explict NULL.
Correct.
Quoted 4 lines
Other than that everything looks good so I've applied this with the fixes I noted above. If you could send a followup patch for the
tpa6130a2_powerexport/static thing that'd be good.
I'll send a patch to make the tpa6130a2_power static.
Quoted 3 lines
Thanks!
Thanks,
Péter