blob: 998555f2a8aab99d19b0e9eaf2d0186662fa0fb1 [file] [log] [blame]
Peter Ujfalusi493b67e2009-10-09 15:55:41 +03001/*
2 * ALSA SoC Texas Instruments TPA6130A2 headset stereo amplifier driver
3 *
4 * Copyright (C) Nokia Corporation
5 *
Peter Ujfalusib4079ef2011-05-03 18:12:41 +03006 * Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
Peter Ujfalusi493b67e2009-10-09 15:55:41 +03007 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 */
22
23#include <linux/module.h>
24#include <linux/errno.h>
25#include <linux/device.h>
26#include <linux/i2c.h>
27#include <linux/gpio.h>
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +020028#include <linux/regulator/consumer.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030030#include <sound/tpa6130a2-plat.h>
31#include <sound/soc.h>
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030032#include <sound/tlv.h>
Sebastian Reichelf95a4882013-10-23 14:03:28 +020033#include <linux/of_gpio.h>
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030034
35#include "tpa6130a2.h"
36
Peter Ujfalusi0722d052011-08-30 14:39:54 +030037enum tpa_model {
38 TPA6130A2,
39 TPA6140A2,
40};
41
Mark Brownebab1b12009-10-09 19:13:47 +010042static struct i2c_client *tpa6130a2_client;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030043
44/* This struct is used to save the context */
45struct tpa6130a2_data {
46 struct mutex mutex;
47 unsigned char regs[TPA6130A2_CACHEREGNUM];
Jarkko Nikulaad8332c2010-05-19 10:52:28 +030048 struct regulator *supply;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030049 int power_gpio;
Peter Ujfalusid5876ce2010-11-30 16:00:00 +020050 u8 power_state:1;
Peter Ujfalusie5e5b312010-05-04 11:08:18 +030051 enum tpa_model id;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030052};
53
54static int tpa6130a2_i2c_read(int reg)
55{
56 struct tpa6130a2_data *data;
57 int val;
58
59 BUG_ON(tpa6130a2_client == NULL);
60 data = i2c_get_clientdata(tpa6130a2_client);
61
62 /* If powered off, return the cached value */
63 if (data->power_state) {
64 val = i2c_smbus_read_byte_data(tpa6130a2_client, reg);
65 if (val < 0)
66 dev_err(&tpa6130a2_client->dev, "Read failed\n");
67 else
68 data->regs[reg] = val;
69 } else {
70 val = data->regs[reg];
71 }
72
73 return val;
74}
75
76static int tpa6130a2_i2c_write(int reg, u8 value)
77{
78 struct tpa6130a2_data *data;
79 int val = 0;
80
81 BUG_ON(tpa6130a2_client == NULL);
82 data = i2c_get_clientdata(tpa6130a2_client);
83
84 if (data->power_state) {
85 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value);
Axel Lin7a479b02010-11-23 14:14:07 +080086 if (val < 0) {
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030087 dev_err(&tpa6130a2_client->dev, "Write failed\n");
Axel Lin7a479b02010-11-23 14:14:07 +080088 return val;
89 }
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030090 }
91
92 /* Either powered on or off, we save the context */
93 data->regs[reg] = value;
94
95 return val;
96}
97
98static u8 tpa6130a2_read(int reg)
99{
100 struct tpa6130a2_data *data;
101
102 BUG_ON(tpa6130a2_client == NULL);
103 data = i2c_get_clientdata(tpa6130a2_client);
104
105 return data->regs[reg];
106}
107
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300108static int tpa6130a2_initialize(void)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300109{
110 struct tpa6130a2_data *data;
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300111 int i, ret = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300112
113 BUG_ON(tpa6130a2_client == NULL);
114 data = i2c_get_clientdata(tpa6130a2_client);
115
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300116 for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
117 ret = tpa6130a2_i2c_write(i, data->regs[i]);
118 if (ret < 0)
119 break;
120 }
121
122 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300123}
124
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200125static int tpa6130a2_power(u8 power)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300126{
127 struct tpa6130a2_data *data;
128 u8 val;
Jarkko Nikula75e3f312010-11-03 16:39:00 +0200129 int ret = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300130
131 BUG_ON(tpa6130a2_client == NULL);
132 data = i2c_get_clientdata(tpa6130a2_client);
133
134 mutex_lock(&data->mutex);
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200135 if (power == data->power_state)
136 goto exit;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200137
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200138 if (power) {
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300139 ret = regulator_enable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200140 if (ret != 0) {
141 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300142 "Failed to enable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200143 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300144 }
Jarkko Nikula0656f6c2010-11-08 10:57:57 +0200145 /* Power on */
146 if (data->power_gpio >= 0)
147 gpio_set_value(data->power_gpio, 1);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200148
149 data->power_state = 1;
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300150 ret = tpa6130a2_initialize();
151 if (ret < 0) {
152 dev_err(&tpa6130a2_client->dev,
153 "Failed to initialize chip\n");
154 if (data->power_gpio >= 0)
155 gpio_set_value(data->power_gpio, 0);
156 regulator_disable(data->supply);
157 data->power_state = 0;
158 goto exit;
159 }
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200160 } else {
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300161 /* set SWS */
162 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
163 val |= TPA6130A2_SWS;
164 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200165
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300166 /* Power off */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200167 if (data->power_gpio >= 0)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300168 gpio_set_value(data->power_gpio, 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200169
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300170 ret = regulator_disable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200171 if (ret != 0) {
172 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300173 "Failed to disable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200174 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300175 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200176
177 data->power_state = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300178 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200179
180exit:
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300181 mutex_unlock(&data->mutex);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200182 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300183}
184
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300185static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300186 struct snd_ctl_elem_value *ucontrol)
187{
188 struct soc_mixer_control *mc =
189 (struct soc_mixer_control *)kcontrol->private_value;
190 struct tpa6130a2_data *data;
191 unsigned int reg = mc->reg;
192 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300193 int max = mc->max;
194 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300195 unsigned int invert = mc->invert;
196
197 BUG_ON(tpa6130a2_client == NULL);
198 data = i2c_get_clientdata(tpa6130a2_client);
199
200 mutex_lock(&data->mutex);
201
202 ucontrol->value.integer.value[0] =
203 (tpa6130a2_read(reg) >> shift) & mask;
204
205 if (invert)
206 ucontrol->value.integer.value[0] =
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300207 max - ucontrol->value.integer.value[0];
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300208
209 mutex_unlock(&data->mutex);
210 return 0;
211}
212
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300213static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300214 struct snd_ctl_elem_value *ucontrol)
215{
216 struct soc_mixer_control *mc =
217 (struct soc_mixer_control *)kcontrol->private_value;
218 struct tpa6130a2_data *data;
219 unsigned int reg = mc->reg;
220 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300221 int max = mc->max;
222 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300223 unsigned int invert = mc->invert;
224 unsigned int val = (ucontrol->value.integer.value[0] & mask);
225 unsigned int val_reg;
226
227 BUG_ON(tpa6130a2_client == NULL);
228 data = i2c_get_clientdata(tpa6130a2_client);
229
230 if (invert)
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300231 val = max - val;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300232
233 mutex_lock(&data->mutex);
234
235 val_reg = tpa6130a2_read(reg);
236 if (((val_reg >> shift) & mask) == val) {
237 mutex_unlock(&data->mutex);
238 return 0;
239 }
240
241 val_reg &= ~(mask << shift);
242 val_reg |= val << shift;
243 tpa6130a2_i2c_write(reg, val_reg);
244
245 mutex_unlock(&data->mutex);
246
247 return 1;
248}
249
250/*
251 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
252 * down in gain.
253 */
254static const unsigned int tpa6130_tlv[] = {
255 TLV_DB_RANGE_HEAD(10),
256 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
257 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
258 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
259 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
260 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
261 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
262 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
263 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
264 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
265 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
266};
267
268static const struct snd_kcontrol_new tpa6130a2_controls[] = {
269 SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
270 TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300271 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300272 tpa6130_tlv),
273};
274
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300275static const unsigned int tpa6140_tlv[] = {
276 TLV_DB_RANGE_HEAD(3),
277 0, 8, TLV_DB_SCALE_ITEM(-5900, 400, 0),
278 9, 16, TLV_DB_SCALE_ITEM(-2500, 200, 0),
279 17, 31, TLV_DB_SCALE_ITEM(-1000, 100, 0),
280};
281
282static const struct snd_kcontrol_new tpa6140a2_controls[] = {
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300283 SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
284 TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300285 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300286 tpa6140_tlv),
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300287};
288
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300289/*
290 * Enable or disable channel (left or right)
291 * The bit number for mute and amplifier are the same per channel:
292 * bit 6: Right channel
293 * bit 7: Left channel
294 * in both registers.
295 */
296static void tpa6130a2_channel_enable(u8 channel, int enable)
297{
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300298 u8 val;
299
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300300 if (enable) {
301 /* Enable channel */
302 /* Enable amplifier */
303 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
304 val |= channel;
Peter Ujfalusid534bac2010-11-30 16:00:01 +0200305 val &= ~TPA6130A2_SWS;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300306 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
307
308 /* Unmute channel */
309 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
310 val &= ~channel;
311 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
312 } else {
313 /* Disable channel */
314 /* Mute channel */
315 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
316 val |= channel;
317 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
318
319 /* Disable amplifier */
320 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
321 val &= ~channel;
322 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
323 }
324}
325
Peter Ujfalusi39646872010-12-02 09:29:56 +0200326int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300327{
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200328 int ret = 0;
Peter Ujfalusi39646872010-12-02 09:29:56 +0200329 if (enable) {
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200330 ret = tpa6130a2_power(1);
Peter Ujfalusi39646872010-12-02 09:29:56 +0200331 if (ret < 0)
332 return ret;
333 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
334 1);
335 } else {
336 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
337 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200338 ret = tpa6130a2_power(0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300339 }
Peter Ujfalusi39646872010-12-02 09:29:56 +0200340
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200341 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300342}
Peter Ujfalusi39646872010-12-02 09:29:56 +0200343EXPORT_SYMBOL_GPL(tpa6130a2_stereo_enable);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300344
345int tpa6130a2_add_controls(struct snd_soc_codec *codec)
346{
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300347 struct tpa6130a2_data *data;
348
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300349 if (tpa6130a2_client == NULL)
350 return -ENODEV;
351
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300352 data = i2c_get_clientdata(tpa6130a2_client);
353
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300354 if (data->id == TPA6140A2)
Liam Girdwood022658b2012-02-03 17:43:09 +0000355 return snd_soc_add_codec_controls(codec, tpa6140a2_controls,
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300356 ARRAY_SIZE(tpa6140a2_controls));
357 else
Liam Girdwood022658b2012-02-03 17:43:09 +0000358 return snd_soc_add_codec_controls(codec, tpa6130a2_controls,
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300359 ARRAY_SIZE(tpa6130a2_controls));
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300360}
361EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
362
Bill Pemberton7a79e942012-12-07 09:26:37 -0500363static int tpa6130a2_probe(struct i2c_client *client,
364 const struct i2c_device_id *id)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300365{
366 struct device *dev;
367 struct tpa6130a2_data *data;
Sebastian Reichelf95a4882013-10-23 14:03:28 +0200368 struct tpa6130a2_platform_data *pdata = client->dev.platform_data;
369 struct device_node *np = client->dev.of_node;
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300370 const char *regulator;
371 int ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300372
373 dev = &client->dev;
374
Axel Lin6945e9f2011-12-29 12:12:29 +0800375 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300376 if (data == NULL) {
377 dev_err(dev, "Can not allocate memory\n");
378 return -ENOMEM;
379 }
380
Sebastian Reichelf95a4882013-10-23 14:03:28 +0200381 if (pdata) {
382 data->power_gpio = pdata->power_gpio;
383 } else if (np) {
384 data->power_gpio = of_get_named_gpio(np, "power-gpio", 0);
385 } else {
386 dev_err(dev, "Platform data not set\n");
387 dump_stack();
388 return -ENODEV;
389 }
390
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300391 tpa6130a2_client = client;
392
393 i2c_set_clientdata(tpa6130a2_client, data);
394
Peter Ujfalusi07441002011-08-30 14:39:52 +0300395 data->id = id->driver_data;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300396
397 mutex_init(&data->mutex);
398
399 /* Set default register values */
400 data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS;
401 data->regs[TPA6130A2_REG_VOL_MUTE] = TPA6130A2_MUTE_R |
402 TPA6130A2_MUTE_L;
403
404 if (data->power_gpio >= 0) {
Sachin Kamatd06080c2012-12-07 16:32:26 +0530405 ret = devm_gpio_request(dev, data->power_gpio,
406 "tpa6130a2 enable");
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300407 if (ret < 0) {
408 dev_err(dev, "Failed to request power GPIO (%d)\n",
409 data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200410 goto err_gpio;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300411 }
412 gpio_direction_output(data->power_gpio, 0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300413 }
414
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300415 switch (data->id) {
Ilkka Koskinen21383012010-01-08 17:48:31 +0200416 default:
417 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
Peter Ujfalusi07441002011-08-30 14:39:52 +0300418 data->id);
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300419 case TPA6130A2:
420 regulator = "Vdd";
421 break;
422 case TPA6140A2:
423 regulator = "AVdd";
424 break;
Ilkka Koskinen21383012010-01-08 17:48:31 +0200425 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200426
Sachin Kamatd06080c2012-12-07 16:32:26 +0530427 data->supply = devm_regulator_get(dev, regulator);
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300428 if (IS_ERR(data->supply)) {
429 ret = PTR_ERR(data->supply);
430 dev_err(dev, "Failed to request supply: %d\n", ret);
Sachin Kamatd06080c2012-12-07 16:32:26 +0530431 goto err_gpio;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200432 }
433
434 ret = tpa6130a2_power(1);
435 if (ret != 0)
Sachin Kamatd06080c2012-12-07 16:32:26 +0530436 goto err_gpio;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200437
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300438
439 /* Read version */
440 ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
441 TPA6130A2_VERSION_MASK;
442 if ((ret != 1) && (ret != 2))
443 dev_warn(dev, "UNTESTED version detected (%d)\n", ret);
444
445 /* Disable the chip */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200446 ret = tpa6130a2_power(0);
447 if (ret != 0)
Sachin Kamatd06080c2012-12-07 16:32:26 +0530448 goto err_gpio;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300449
450 return 0;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200451
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200452err_gpio:
Mark Brownebab1b12009-10-09 19:13:47 +0100453 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300454
455 return ret;
456}
457
Bill Pemberton7a79e942012-12-07 09:26:37 -0500458static int tpa6130a2_remove(struct i2c_client *client)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300459{
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300460 tpa6130a2_power(0);
Mark Brownebab1b12009-10-09 19:13:47 +0100461 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300462
463 return 0;
464}
465
466static const struct i2c_device_id tpa6130a2_id[] = {
Peter Ujfalusi07441002011-08-30 14:39:52 +0300467 { "tpa6130a2", TPA6130A2 },
468 { "tpa6140a2", TPA6140A2 },
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300469 { }
470};
471MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
472
Sebastian Reichelf95a4882013-10-23 14:03:28 +0200473#if IS_ENABLED(CONFIG_OF)
474static const struct of_device_id tpa6130a2_of_match[] = {
475 { .compatible = "ti,tpa6130a2", },
476 { .compatible = "ti,tpa6140a2" },
477 {},
478};
479MODULE_DEVICE_TABLE(of, tpa6130a2_of_match);
480#endif
481
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300482static struct i2c_driver tpa6130a2_i2c_driver = {
483 .driver = {
484 .name = "tpa6130a2",
485 .owner = THIS_MODULE,
Sebastian Reichelf95a4882013-10-23 14:03:28 +0200486 .of_match_table = of_match_ptr(tpa6130a2_of_match),
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300487 },
488 .probe = tpa6130a2_probe,
Bill Pemberton7a79e942012-12-07 09:26:37 -0500489 .remove = tpa6130a2_remove,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300490 .id_table = tpa6130a2_id,
491};
492
Sachin Kamatf062e2b2012-08-06 17:25:38 +0530493module_i2c_driver(tpa6130a2_i2c_driver);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300494
Peter Ujfalusib4079ef2011-05-03 18:12:41 +0300495MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300496MODULE_DESCRIPTION("TPA6130A2 Headphone amplifier driver");
497MODULE_LICENSE("GPL");