2009-10-09 14:55:41 +02:00
|
|
|
/*
|
|
|
|
* ALSA SoC Texas Instruments TPA6130A2 headset stereo amplifier driver
|
|
|
|
*
|
|
|
|
* Copyright (C) Nokia Corporation
|
|
|
|
*
|
2011-05-03 17:12:41 +02:00
|
|
|
* Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
|
2009-10-09 14:55:41 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/gpio.h>
|
2009-12-09 11:05:50 +01:00
|
|
|
#include <linux/regulator/consumer.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 09:04:11 +01:00
|
|
|
#include <linux/slab.h>
|
2009-10-09 14:55:41 +02:00
|
|
|
#include <sound/tpa6130a2-plat.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
|
|
|
|
#include "tpa6130a2.h"
|
|
|
|
|
2009-10-09 20:13:47 +02:00
|
|
|
static struct i2c_client *tpa6130a2_client;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
/* This struct is used to save the context */
|
|
|
|
struct tpa6130a2_data {
|
|
|
|
struct mutex mutex;
|
|
|
|
unsigned char regs[TPA6130A2_CACHEREGNUM];
|
2010-05-19 09:52:28 +02:00
|
|
|
struct regulator *supply;
|
2009-10-09 14:55:41 +02:00
|
|
|
int power_gpio;
|
2010-11-30 15:00:00 +01:00
|
|
|
u8 power_state:1;
|
2010-05-04 10:08:18 +02:00
|
|
|
enum tpa_model id;
|
2009-10-09 14:55:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static int tpa6130a2_i2c_read(int reg)
|
|
|
|
{
|
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
BUG_ON(tpa6130a2_client == NULL);
|
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
|
|
|
/* If powered off, return the cached value */
|
|
|
|
if (data->power_state) {
|
|
|
|
val = i2c_smbus_read_byte_data(tpa6130a2_client, reg);
|
|
|
|
if (val < 0)
|
|
|
|
dev_err(&tpa6130a2_client->dev, "Read failed\n");
|
|
|
|
else
|
|
|
|
data->regs[reg] = val;
|
|
|
|
} else {
|
|
|
|
val = data->regs[reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-11-23 07:14:07 +01:00
|
|
|
if (val < 0) {
|
2009-10-09 14:55:41 +02:00
|
|
|
dev_err(&tpa6130a2_client->dev, "Write failed\n");
|
2010-11-23 07:14:07 +01:00
|
|
|
return val;
|
|
|
|
}
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Either powered on or off, we save the context */
|
|
|
|
data->regs[reg] = value;
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u8 tpa6130a2_read(int reg)
|
|
|
|
{
|
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
|
|
|
|
BUG_ON(tpa6130a2_client == NULL);
|
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
|
|
|
return data->regs[reg];
|
|
|
|
}
|
|
|
|
|
2010-10-21 14:03:03 +02:00
|
|
|
static int tpa6130a2_initialize(void)
|
2009-10-09 14:55:41 +02:00
|
|
|
{
|
|
|
|
struct tpa6130a2_data *data;
|
2010-10-21 14:03:03 +02:00
|
|
|
int i, ret = 0;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
BUG_ON(tpa6130a2_client == NULL);
|
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
2010-10-21 14:03:03 +02:00
|
|
|
for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
|
|
|
|
ret = tpa6130a2_i2c_write(i, data->regs[i]);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
2010-11-30 15:00:00 +01:00
|
|
|
static int tpa6130a2_power(u8 power)
|
2009-10-09 14:55:41 +02:00
|
|
|
{
|
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
u8 val;
|
2010-11-03 15:39:00 +01:00
|
|
|
int ret = 0;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
BUG_ON(tpa6130a2_client == NULL);
|
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
|
|
|
mutex_lock(&data->mutex);
|
2010-11-30 15:00:00 +01:00
|
|
|
if (power == data->power_state)
|
|
|
|
goto exit;
|
2009-12-09 11:05:50 +01:00
|
|
|
|
2010-11-30 15:00:00 +01:00
|
|
|
if (power) {
|
2010-05-19 09:52:28 +02:00
|
|
|
ret = regulator_enable(data->supply);
|
2009-12-09 11:05:50 +01:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&tpa6130a2_client->dev,
|
2010-05-19 09:52:28 +02:00
|
|
|
"Failed to enable supply: %d\n", ret);
|
2009-12-09 11:05:50 +01:00
|
|
|
goto exit;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
2010-11-08 09:57:57 +01:00
|
|
|
/* Power on */
|
|
|
|
if (data->power_gpio >= 0)
|
|
|
|
gpio_set_value(data->power_gpio, 1);
|
2009-12-09 11:05:50 +01:00
|
|
|
|
|
|
|
data->power_state = 1;
|
2010-10-21 14:03:03 +02:00
|
|
|
ret = tpa6130a2_initialize();
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&tpa6130a2_client->dev,
|
|
|
|
"Failed to initialize chip\n");
|
|
|
|
if (data->power_gpio >= 0)
|
|
|
|
gpio_set_value(data->power_gpio, 0);
|
|
|
|
regulator_disable(data->supply);
|
|
|
|
data->power_state = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
2010-11-30 15:00:00 +01:00
|
|
|
} else {
|
2009-10-09 14:55:41 +02:00
|
|
|
/* set SWS */
|
|
|
|
val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
|
|
|
|
val |= TPA6130A2_SWS;
|
|
|
|
tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
|
2009-12-09 11:05:50 +01:00
|
|
|
|
2009-10-09 14:55:41 +02:00
|
|
|
/* Power off */
|
2009-12-09 11:05:50 +01:00
|
|
|
if (data->power_gpio >= 0)
|
2009-10-09 14:55:41 +02:00
|
|
|
gpio_set_value(data->power_gpio, 0);
|
2009-12-09 11:05:50 +01:00
|
|
|
|
2010-05-19 09:52:28 +02:00
|
|
|
ret = regulator_disable(data->supply);
|
2009-12-09 11:05:50 +01:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&tpa6130a2_client->dev,
|
2010-05-19 09:52:28 +02:00
|
|
|
"Failed to disable supply: %d\n", ret);
|
2009-12-09 11:05:50 +01:00
|
|
|
goto exit;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
2009-12-09 11:05:50 +01:00
|
|
|
|
|
|
|
data->power_state = 0;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
2009-12-09 11:05:50 +01:00
|
|
|
|
|
|
|
exit:
|
2009-10-09 14:55:41 +02:00
|
|
|
mutex_unlock(&data->mutex);
|
2009-12-09 11:05:50 +01:00
|
|
|
return ret;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
|
|
|
|
2010-05-07 13:24:11 +02:00
|
|
|
static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
|
2009-10-09 14:55:41 +02:00
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
unsigned int reg = mc->reg;
|
|
|
|
unsigned int shift = mc->shift;
|
2010-05-07 13:24:11 +02:00
|
|
|
int max = mc->max;
|
|
|
|
unsigned int mask = (1 << fls(max)) - 1;
|
2009-10-09 14:55:41 +02:00
|
|
|
unsigned int invert = mc->invert;
|
|
|
|
|
|
|
|
BUG_ON(tpa6130a2_client == NULL);
|
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
|
|
|
mutex_lock(&data->mutex);
|
|
|
|
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
|
|
(tpa6130a2_read(reg) >> shift) & mask;
|
|
|
|
|
|
|
|
if (invert)
|
|
|
|
ucontrol->value.integer.value[0] =
|
2010-05-07 13:24:11 +02:00
|
|
|
max - ucontrol->value.integer.value[0];
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
mutex_unlock(&data->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-07 13:24:11 +02:00
|
|
|
static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
|
2009-10-09 14:55:41 +02:00
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
unsigned int reg = mc->reg;
|
|
|
|
unsigned int shift = mc->shift;
|
2010-05-07 13:24:11 +02:00
|
|
|
int max = mc->max;
|
|
|
|
unsigned int mask = (1 << fls(max)) - 1;
|
2009-10-09 14:55:41 +02:00
|
|
|
unsigned int invert = mc->invert;
|
|
|
|
unsigned int val = (ucontrol->value.integer.value[0] & mask);
|
|
|
|
unsigned int val_reg;
|
|
|
|
|
|
|
|
BUG_ON(tpa6130a2_client == NULL);
|
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
|
|
|
if (invert)
|
2010-05-07 13:24:11 +02:00
|
|
|
val = max - val;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
mutex_lock(&data->mutex);
|
|
|
|
|
|
|
|
val_reg = tpa6130a2_read(reg);
|
|
|
|
if (((val_reg >> shift) & mask) == val) {
|
|
|
|
mutex_unlock(&data->mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
val_reg &= ~(mask << shift);
|
|
|
|
val_reg |= val << shift;
|
|
|
|
tpa6130a2_i2c_write(reg, val_reg);
|
|
|
|
|
|
|
|
mutex_unlock(&data->mutex);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
|
|
|
|
* down in gain.
|
|
|
|
*/
|
|
|
|
static const unsigned int tpa6130_tlv[] = {
|
|
|
|
TLV_DB_RANGE_HEAD(10),
|
|
|
|
0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
|
|
|
|
2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
|
|
|
|
4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
|
|
|
|
6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
|
|
|
|
8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
|
|
|
|
10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
|
|
|
|
12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
|
|
|
|
14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
|
|
|
|
21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
|
|
|
|
38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new tpa6130a2_controls[] = {
|
|
|
|
SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
|
|
|
|
TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
|
2010-05-07 13:24:11 +02:00
|
|
|
tpa6130a2_get_volsw, tpa6130a2_put_volsw,
|
2009-10-09 14:55:41 +02:00
|
|
|
tpa6130_tlv),
|
|
|
|
};
|
|
|
|
|
2010-05-04 10:08:18 +02:00
|
|
|
static const unsigned int tpa6140_tlv[] = {
|
|
|
|
TLV_DB_RANGE_HEAD(3),
|
|
|
|
0, 8, TLV_DB_SCALE_ITEM(-5900, 400, 0),
|
|
|
|
9, 16, TLV_DB_SCALE_ITEM(-2500, 200, 0),
|
|
|
|
17, 31, TLV_DB_SCALE_ITEM(-1000, 100, 0),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new tpa6140a2_controls[] = {
|
2010-05-07 13:24:10 +02:00
|
|
|
SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
|
|
|
|
TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
|
2010-05-07 13:24:11 +02:00
|
|
|
tpa6130a2_get_volsw, tpa6130a2_put_volsw,
|
2010-05-07 13:24:10 +02:00
|
|
|
tpa6140_tlv),
|
2010-05-04 10:08:18 +02:00
|
|
|
};
|
|
|
|
|
2009-10-09 14:55:41 +02:00
|
|
|
/*
|
|
|
|
* Enable or disable channel (left or right)
|
|
|
|
* The bit number for mute and amplifier are the same per channel:
|
|
|
|
* bit 6: Right channel
|
|
|
|
* bit 7: Left channel
|
|
|
|
* in both registers.
|
|
|
|
*/
|
|
|
|
static void tpa6130a2_channel_enable(u8 channel, int enable)
|
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
/* Enable channel */
|
|
|
|
/* Enable amplifier */
|
|
|
|
val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
|
|
|
|
val |= channel;
|
2010-11-30 15:00:01 +01:00
|
|
|
val &= ~TPA6130A2_SWS;
|
2009-10-09 14:55:41 +02:00
|
|
|
tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
|
|
|
|
|
|
|
|
/* Unmute channel */
|
|
|
|
val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
|
|
|
|
val &= ~channel;
|
|
|
|
tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
|
|
|
|
} else {
|
|
|
|
/* Disable channel */
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-02 08:29:56 +01:00
|
|
|
int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable)
|
2009-10-09 14:55:41 +02:00
|
|
|
{
|
2009-12-09 11:05:50 +01:00
|
|
|
int ret = 0;
|
2010-12-02 08:29:56 +01:00
|
|
|
if (enable) {
|
2009-12-09 11:05:50 +01:00
|
|
|
ret = tpa6130a2_power(1);
|
2010-12-02 08:29:56 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
|
|
|
|
1);
|
|
|
|
} else {
|
|
|
|
tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
|
|
|
|
0);
|
2009-12-09 11:05:50 +01:00
|
|
|
ret = tpa6130a2_power(0);
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
2010-12-02 08:29:56 +01:00
|
|
|
|
2009-12-09 11:05:50 +01:00
|
|
|
return ret;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
2010-12-02 08:29:56 +01:00
|
|
|
EXPORT_SYMBOL_GPL(tpa6130a2_stereo_enable);
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
int tpa6130a2_add_controls(struct snd_soc_codec *codec)
|
|
|
|
{
|
2010-05-04 10:08:18 +02:00
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
|
2010-10-21 14:03:03 +02:00
|
|
|
if (tpa6130a2_client == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2010-05-04 10:08:18 +02:00
|
|
|
data = i2c_get_clientdata(tpa6130a2_client);
|
|
|
|
|
|
|
|
if (data->id == TPA6140A2)
|
|
|
|
return snd_soc_add_controls(codec, tpa6140a2_controls,
|
|
|
|
ARRAY_SIZE(tpa6140a2_controls));
|
|
|
|
else
|
|
|
|
return snd_soc_add_controls(codec, tpa6130a2_controls,
|
|
|
|
ARRAY_SIZE(tpa6130a2_controls));
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
|
|
|
|
|
2010-01-12 15:13:00 +01:00
|
|
|
static int __devinit tpa6130a2_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
2009-10-09 14:55:41 +02:00
|
|
|
{
|
|
|
|
struct device *dev;
|
|
|
|
struct tpa6130a2_data *data;
|
|
|
|
struct tpa6130a2_platform_data *pdata;
|
2010-05-19 09:52:28 +02:00
|
|
|
const char *regulator;
|
|
|
|
int ret;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
dev = &client->dev;
|
|
|
|
|
|
|
|
if (client->dev.platform_data == NULL) {
|
|
|
|
dev_err(dev, "Platform data not set\n");
|
|
|
|
dump_stack();
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
|
|
|
if (data == NULL) {
|
|
|
|
dev_err(dev, "Can not allocate memory\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
tpa6130a2_client = client;
|
|
|
|
|
|
|
|
i2c_set_clientdata(tpa6130a2_client, data);
|
|
|
|
|
2009-10-09 20:13:47 +02:00
|
|
|
pdata = client->dev.platform_data;
|
2009-10-09 14:55:41 +02:00
|
|
|
data->power_gpio = pdata->power_gpio;
|
2010-05-04 10:08:18 +02:00
|
|
|
data->id = pdata->id;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
mutex_init(&data->mutex);
|
|
|
|
|
|
|
|
/* Set default register values */
|
|
|
|
data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS;
|
|
|
|
data->regs[TPA6130A2_REG_VOL_MUTE] = TPA6130A2_MUTE_R |
|
|
|
|
TPA6130A2_MUTE_L;
|
|
|
|
|
|
|
|
if (data->power_gpio >= 0) {
|
|
|
|
ret = gpio_request(data->power_gpio, "tpa6130a2 enable");
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "Failed to request power GPIO (%d)\n",
|
|
|
|
data->power_gpio);
|
2009-12-09 11:05:50 +01:00
|
|
|
goto err_gpio;
|
2009-10-09 14:55:41 +02:00
|
|
|
}
|
|
|
|
gpio_direction_output(data->power_gpio, 0);
|
|
|
|
}
|
|
|
|
|
2010-05-04 10:08:18 +02:00
|
|
|
switch (data->id) {
|
2010-05-19 09:52:28 +02:00
|
|
|
default:
|
|
|
|
dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
|
|
|
|
pdata->id);
|
2010-01-08 16:48:31 +01:00
|
|
|
case TPA6130A2:
|
2010-05-19 09:52:28 +02:00
|
|
|
regulator = "Vdd";
|
2010-01-08 16:48:31 +01:00
|
|
|
break;
|
|
|
|
case TPA6140A2:
|
2010-05-19 09:52:28 +02:00
|
|
|
regulator = "AVdd";
|
2010-01-08 16:48:31 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-12-09 11:05:50 +01:00
|
|
|
|
2010-05-19 09:52:28 +02:00
|
|
|
data->supply = regulator_get(dev, regulator);
|
|
|
|
if (IS_ERR(data->supply)) {
|
|
|
|
ret = PTR_ERR(data->supply);
|
|
|
|
dev_err(dev, "Failed to request supply: %d\n", ret);
|
2009-12-09 11:05:50 +01:00
|
|
|
goto err_regulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = tpa6130a2_power(1);
|
|
|
|
if (ret != 0)
|
|
|
|
goto err_power;
|
|
|
|
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
/* Read version */
|
|
|
|
ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
|
|
|
|
TPA6130A2_VERSION_MASK;
|
|
|
|
if ((ret != 1) && (ret != 2))
|
|
|
|
dev_warn(dev, "UNTESTED version detected (%d)\n", ret);
|
|
|
|
|
|
|
|
/* Disable the chip */
|
2009-12-09 11:05:50 +01:00
|
|
|
ret = tpa6130a2_power(0);
|
|
|
|
if (ret != 0)
|
|
|
|
goto err_power;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
return 0;
|
2009-12-09 11:05:50 +01:00
|
|
|
|
|
|
|
err_power:
|
2010-05-19 09:52:28 +02:00
|
|
|
regulator_put(data->supply);
|
2009-12-09 11:05:50 +01:00
|
|
|
err_regulator:
|
|
|
|
if (data->power_gpio >= 0)
|
|
|
|
gpio_free(data->power_gpio);
|
|
|
|
err_gpio:
|
2009-10-09 14:55:41 +02:00
|
|
|
kfree(data);
|
|
|
|
i2c_set_clientdata(tpa6130a2_client, NULL);
|
2009-10-09 20:13:47 +02:00
|
|
|
tpa6130a2_client = NULL;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-12 15:13:00 +01:00
|
|
|
static int __devexit tpa6130a2_remove(struct i2c_client *client)
|
2009-10-09 14:55:41 +02:00
|
|
|
{
|
|
|
|
struct tpa6130a2_data *data = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
tpa6130a2_power(0);
|
|
|
|
|
|
|
|
if (data->power_gpio >= 0)
|
|
|
|
gpio_free(data->power_gpio);
|
2009-12-09 11:05:50 +01:00
|
|
|
|
2010-05-19 09:52:28 +02:00
|
|
|
regulator_put(data->supply);
|
2009-12-09 11:05:50 +01:00
|
|
|
|
2009-10-09 14:55:41 +02:00
|
|
|
kfree(data);
|
2009-10-09 20:13:47 +02:00
|
|
|
tpa6130a2_client = NULL;
|
2009-10-09 14:55:41 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id tpa6130a2_id[] = {
|
|
|
|
{ "tpa6130a2", 0 },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
|
|
|
|
|
|
|
|
static struct i2c_driver tpa6130a2_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "tpa6130a2",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = tpa6130a2_probe,
|
|
|
|
.remove = __devexit_p(tpa6130a2_remove),
|
|
|
|
.id_table = tpa6130a2_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init tpa6130a2_init(void)
|
|
|
|
{
|
|
|
|
return i2c_add_driver(&tpa6130a2_i2c_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit tpa6130a2_exit(void)
|
|
|
|
{
|
|
|
|
i2c_del_driver(&tpa6130a2_i2c_driver);
|
|
|
|
}
|
|
|
|
|
2011-05-03 17:12:41 +02:00
|
|
|
MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
|
2009-10-09 14:55:41 +02:00
|
|
|
MODULE_DESCRIPTION("TPA6130A2 Headphone amplifier driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_init(tpa6130a2_init);
|
|
|
|
module_exit(tpa6130a2_exit);
|