23 #include <linux/module.h>
24 #include <linux/errno.h>
25 #include <linux/device.h>
26 #include <linux/i2c.h>
29 #include <linux/slab.h>
53 static int tpa6130a2_i2c_read(
int reg)
59 data = i2c_get_clientdata(tpa6130a2_client);
65 dev_err(&tpa6130a2_client->
dev,
"Read failed\n");
75 static int tpa6130a2_i2c_write(
int reg,
u8 value)
81 data = i2c_get_clientdata(tpa6130a2_client);
86 dev_err(&tpa6130a2_client->
dev,
"Write failed\n");
97 static u8 tpa6130a2_read(
int reg)
102 data = i2c_get_clientdata(tpa6130a2_client);
107 static int tpa6130a2_initialize(
void)
113 data = i2c_get_clientdata(tpa6130a2_client);
116 ret = tpa6130a2_i2c_write(i, data->
regs[i]);
124 static int tpa6130a2_power(
u8 power)
131 data = i2c_get_clientdata(tpa6130a2_client);
141 "Failed to enable supply: %d\n", ret);
149 ret = tpa6130a2_initialize();
152 "Failed to initialize chip\n");
172 "Failed to disable supply: %d\n", ret);
184 static int tpa6130a2_get_volsw(
struct snd_kcontrol *kcontrol,
190 unsigned int reg = mc->
reg;
193 unsigned int mask = (1 << fls(
max)) - 1;
197 data = i2c_get_clientdata(tpa6130a2_client);
201 ucontrol->
value.integer.value[0] =
205 ucontrol->
value.integer.value[0] =
206 max - ucontrol->
value.integer.value[0];
212 static int tpa6130a2_put_volsw(
struct snd_kcontrol *kcontrol,
218 unsigned int reg = mc->
reg;
221 unsigned int mask = (1 << fls(
max)) - 1;
222 unsigned int invert = mc->
invert;
223 unsigned int val = (ucontrol->
value.integer.value[0] &
mask);
224 unsigned int val_reg;
227 data = i2c_get_clientdata(tpa6130a2_client);
234 val_reg = tpa6130a2_read(reg);
235 if (((val_reg >>
shift) &
mask) == val) {
240 val_reg &= ~(mask <<
shift);
241 val_reg |= val <<
shift;
242 tpa6130a2_i2c_write(reg, val_reg);
253 static const unsigned int tpa6130_tlv[] = {
270 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
274 static const unsigned int tpa6140_tlv[] = {
284 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
329 ret = tpa6130a2_power(1);
337 ret = tpa6130a2_power(0);
348 if (tpa6130a2_client ==
NULL)
351 data = i2c_get_clientdata(tpa6130a2_client);
373 if (client->
dev.platform_data ==
NULL) {
374 dev_err(dev,
"Platform data not set\n");
381 dev_err(dev,
"Can not allocate memory\n");
385 tpa6130a2_client =
client;
387 i2c_set_clientdata(tpa6130a2_client, data);
389 pdata = client->
dev.platform_data;
391 data->
id =
id->driver_data;
403 dev_err(dev,
"Failed to request power GPIO (%d)\n",
412 dev_warn(dev,
"Unknown TPA model (%d). Assuming 6130A2\n",
423 if (IS_ERR(data->
supply)) {
424 ret = PTR_ERR(data->
supply);
425 dev_err(dev,
"Failed to request supply: %d\n", ret);
429 ret = tpa6130a2_power(1);
435 ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
437 if ((ret != 1) && (ret != 2))
438 dev_warn(dev,
"UNTESTED version detected (%d)\n", ret);
441 ret = tpa6130a2_power(0);
453 tpa6130a2_client =
NULL;
468 tpa6130a2_client =
NULL;
480 static struct i2c_driver tpa6130a2_i2c_driver = {
485 .probe = tpa6130a2_probe,
487 .id_table = tpa6130a2_id,