blob: 6fe4aa3ac54401da4210df65ead54e0a1fe537b2 [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>
33
34#include "tpa6130a2.h"
35
Peter Ujfalusi0722d052011-08-30 14:39:54 +030036enum tpa_model {
37 TPA6130A2,
38 TPA6140A2,
39};
40
Mark Brownebab1b12009-10-09 19:13:47 +010041static struct i2c_client *tpa6130a2_client;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030042
43/* This struct is used to save the context */
44struct tpa6130a2_data {
45 struct mutex mutex;
46 unsigned char regs[TPA6130A2_CACHEREGNUM];
Jarkko Nikulaad8332c2010-05-19 10:52:28 +030047 struct regulator *supply;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030048 int power_gpio;
Peter Ujfalusid5876ce2010-11-30 16:00:00 +020049 u8 power_state:1;
Peter Ujfalusie5e5b312010-05-04 11:08:18 +030050 enum tpa_model id;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030051};
52
53static int tpa6130a2_i2c_read(int reg)
54{
55 struct tpa6130a2_data *data;
56 int val;
57
58 BUG_ON(tpa6130a2_client == NULL);
59 data = i2c_get_clientdata(tpa6130a2_client);
60
61 /* If powered off, return the cached value */
62 if (data->power_state) {
63 val = i2c_smbus_read_byte_data(tpa6130a2_client, reg);
64 if (val < 0)
65 dev_err(&tpa6130a2_client->dev, "Read failed\n");
66 else
67 data->regs[reg] = val;
68 } else {
69 val = data->regs[reg];
70 }
71
72 return val;
73}
74
75static int tpa6130a2_i2c_write(int reg, u8 value)
76{
77 struct tpa6130a2_data *data;
78 int val = 0;
79
80 BUG_ON(tpa6130a2_client == NULL);
81 data = i2c_get_clientdata(tpa6130a2_client);
82
83 if (data->power_state) {
84 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value);
Axel Lin7a479b02010-11-23 14:14:07 +080085 if (val < 0) {
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030086 dev_err(&tpa6130a2_client->dev, "Write failed\n");
Axel Lin7a479b02010-11-23 14:14:07 +080087 return val;
88 }
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030089 }
90
91 /* Either powered on or off, we save the context */
92 data->regs[reg] = value;
93
94 return val;
95}
96
97static u8 tpa6130a2_read(int reg)
98{
99 struct tpa6130a2_data *data;
100
101 BUG_ON(tpa6130a2_client == NULL);
102 data = i2c_get_clientdata(tpa6130a2_client);
103
104 return data->regs[reg];
105}
106
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300107static int tpa6130a2_initialize(void)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300108{
109 struct tpa6130a2_data *data;
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300110 int i, ret = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300111
112 BUG_ON(tpa6130a2_client == NULL);
113 data = i2c_get_clientdata(tpa6130a2_client);
114
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300115 for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
116 ret = tpa6130a2_i2c_write(i, data->regs[i]);
117 if (ret < 0)
118 break;
119 }
120
121 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300122}
123
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200124static int tpa6130a2_power(u8 power)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300125{
126 struct tpa6130a2_data *data;
127 u8 val;
Jarkko Nikula75e3f312010-11-03 16:39:00 +0200128 int ret = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300129
130 BUG_ON(tpa6130a2_client == NULL);
131 data = i2c_get_clientdata(tpa6130a2_client);
132
133 mutex_lock(&data->mutex);
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200134 if (power == data->power_state)
135 goto exit;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200136
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200137 if (power) {
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300138 ret = regulator_enable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200139 if (ret != 0) {
140 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300141 "Failed to enable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200142 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300143 }
Jarkko Nikula0656f6c2010-11-08 10:57:57 +0200144 /* Power on */
145 if (data->power_gpio >= 0)
146 gpio_set_value(data->power_gpio, 1);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200147
148 data->power_state = 1;
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300149 ret = tpa6130a2_initialize();
150 if (ret < 0) {
151 dev_err(&tpa6130a2_client->dev,
152 "Failed to initialize chip\n");
153 if (data->power_gpio >= 0)
154 gpio_set_value(data->power_gpio, 0);
155 regulator_disable(data->supply);
156 data->power_state = 0;
157 goto exit;
158 }
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200159 } else {
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300160 /* set SWS */
161 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
162 val |= TPA6130A2_SWS;
163 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200164
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300165 /* Power off */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200166 if (data->power_gpio >= 0)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300167 gpio_set_value(data->power_gpio, 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200168
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300169 ret = regulator_disable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200170 if (ret != 0) {
171 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300172 "Failed to disable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200173 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300174 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200175
176 data->power_state = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300177 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200178
179exit:
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300180 mutex_unlock(&data->mutex);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200181 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300182}
183
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300184static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300185 struct snd_ctl_elem_value *ucontrol)
186{
187 struct soc_mixer_control *mc =
188 (struct soc_mixer_control *)kcontrol->private_value;
189 struct tpa6130a2_data *data;
190 unsigned int reg = mc->reg;
191 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300192 int max = mc->max;
193 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300194 unsigned int invert = mc->invert;
195
196 BUG_ON(tpa6130a2_client == NULL);
197 data = i2c_get_clientdata(tpa6130a2_client);
198
199 mutex_lock(&data->mutex);
200
201 ucontrol->value.integer.value[0] =
202 (tpa6130a2_read(reg) >> shift) & mask;
203
204 if (invert)
205 ucontrol->value.integer.value[0] =
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300206 max - ucontrol->value.integer.value[0];
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300207
208 mutex_unlock(&data->mutex);
209 return 0;
210}
211
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300212static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300213 struct snd_ctl_elem_value *ucontrol)
214{
215 struct soc_mixer_control *mc =
216 (struct soc_mixer_control *)kcontrol->private_value;
217 struct tpa6130a2_data *data;
218 unsigned int reg = mc->reg;
219 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300220 int max = mc->max;
221 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300222 unsigned int invert = mc->invert;
223 unsigned int val = (ucontrol->value.integer.value[0] & mask);
224 unsigned int val_reg;
225
226 BUG_ON(tpa6130a2_client == NULL);
227 data = i2c_get_clientdata(tpa6130a2_client);
228
229 if (invert)
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300230 val = max - val;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300231
232 mutex_lock(&data->mutex);
233
234 val_reg = tpa6130a2_read(reg);
235 if (((val_reg >> shift) & mask) == val) {
236 mutex_unlock(&data->mutex);
237 return 0;
238 }
239
240 val_reg &= ~(mask << shift);
241 val_reg |= val << shift;
242 tpa6130a2_i2c_write(reg, val_reg);
243
244 mutex_unlock(&data->mutex);
245
246 return 1;
247}
248
249/*
250 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
251 * down in gain.
252 */
253static const unsigned int tpa6130_tlv[] = {
254 TLV_DB_RANGE_HEAD(10),
255 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
256 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
257 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
258 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
259 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
260 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
261 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
262 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
263 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
264 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
265};
266
267static const struct snd_kcontrol_new tpa6130a2_controls[] = {
268 SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
269 TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300270 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300271 tpa6130_tlv),
272};
273
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300274static const unsigned int tpa6140_tlv[] = {
275 TLV_DB_RANGE_HEAD(3),
276 0, 8, TLV_DB_SCALE_ITEM(-5900, 400, 0),
277 9, 16, TLV_DB_SCALE_ITEM(-2500, 200, 0),
278 17, 31, TLV_DB_SCALE_ITEM(-1000, 100, 0),
279};
280
281static const struct snd_kcontrol_new tpa6140a2_controls[] = {
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300282 SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
283 TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300284 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300285 tpa6140_tlv),
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300286};
287
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300288/*
289 * Enable or disable channel (left or right)
290 * The bit number for mute and amplifier are the same per channel:
291 * bit 6: Right channel
292 * bit 7: Left channel
293 * in both registers.
294 */
295static void tpa6130a2_channel_enable(u8 channel, int enable)
296{
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300297 u8 val;
298
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300299 if (enable) {
300 /* Enable channel */
301 /* Enable amplifier */
302 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
303 val |= channel;
Peter Ujfalusid534bac2010-11-30 16:00:01 +0200304 val &= ~TPA6130A2_SWS;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300305 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
306
307 /* Unmute channel */
308 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
309 val &= ~channel;
310 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
311 } else {
312 /* Disable channel */
313 /* Mute channel */
314 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
315 val |= channel;
316 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
317
318 /* Disable amplifier */
319 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
320 val &= ~channel;
321 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
322 }
323}
324
Peter Ujfalusi39646872010-12-02 09:29:56 +0200325int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300326{
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200327 int ret = 0;
Peter Ujfalusi39646872010-12-02 09:29:56 +0200328 if (enable) {
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200329 ret = tpa6130a2_power(1);
Peter Ujfalusi39646872010-12-02 09:29:56 +0200330 if (ret < 0)
331 return ret;
332 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
333 1);
334 } else {
335 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
336 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200337 ret = tpa6130a2_power(0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300338 }
Peter Ujfalusi39646872010-12-02 09:29:56 +0200339
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200340 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300341}
Peter Ujfalusi39646872010-12-02 09:29:56 +0200342EXPORT_SYMBOL_GPL(tpa6130a2_stereo_enable);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300343
344int tpa6130a2_add_controls(struct snd_soc_codec *codec)
345{
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300346 struct tpa6130a2_data *data;
347
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300348 if (tpa6130a2_client == NULL)
349 return -ENODEV;
350
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300351 data = i2c_get_clientdata(tpa6130a2_client);
352
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300353 if (data->id == TPA6140A2)
Liam Girdwood022658b2012-02-03 17:43:09 +0000354 return snd_soc_add_codec_controls(codec, tpa6140a2_controls,
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300355 ARRAY_SIZE(tpa6140a2_controls));
356 else
Liam Girdwood022658b2012-02-03 17:43:09 +0000357 return snd_soc_add_codec_controls(codec, tpa6130a2_controls,
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300358 ARRAY_SIZE(tpa6130a2_controls));
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300359}
360EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
361
Mark Brown735fe4c2010-01-12 14:13:00 +0000362static int __devinit tpa6130a2_probe(struct i2c_client *client,
363 const struct i2c_device_id *id)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300364{
365 struct device *dev;
366 struct tpa6130a2_data *data;
367 struct tpa6130a2_platform_data *pdata;
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300368 const char *regulator;
369 int ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300370
371 dev = &client->dev;
372
373 if (client->dev.platform_data == NULL) {
374 dev_err(dev, "Platform data not set\n");
375 dump_stack();
376 return -ENODEV;
377 }
378
Axel Lin6945e9f2011-12-29 12:12:29 +0800379 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300380 if (data == NULL) {
381 dev_err(dev, "Can not allocate memory\n");
382 return -ENOMEM;
383 }
384
385 tpa6130a2_client = client;
386
387 i2c_set_clientdata(tpa6130a2_client, data);
388
Mark Brownebab1b12009-10-09 19:13:47 +0100389 pdata = client->dev.platform_data;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300390 data->power_gpio = pdata->power_gpio;
Peter Ujfalusi07441002011-08-30 14:39:52 +0300391 data->id = id->driver_data;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300392
393 mutex_init(&data->mutex);
394
395 /* Set default register values */
396 data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS;
397 data->regs[TPA6130A2_REG_VOL_MUTE] = TPA6130A2_MUTE_R |
398 TPA6130A2_MUTE_L;
399
400 if (data->power_gpio >= 0) {
401 ret = gpio_request(data->power_gpio, "tpa6130a2 enable");
402 if (ret < 0) {
403 dev_err(dev, "Failed to request power GPIO (%d)\n",
404 data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200405 goto err_gpio;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300406 }
407 gpio_direction_output(data->power_gpio, 0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300408 }
409
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300410 switch (data->id) {
Ilkka Koskinen21383012010-01-08 17:48:31 +0200411 default:
412 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
Peter Ujfalusi07441002011-08-30 14:39:52 +0300413 data->id);
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300414 case TPA6130A2:
415 regulator = "Vdd";
416 break;
417 case TPA6140A2:
418 regulator = "AVdd";
419 break;
Ilkka Koskinen21383012010-01-08 17:48:31 +0200420 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200421
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300422 data->supply = regulator_get(dev, regulator);
423 if (IS_ERR(data->supply)) {
424 ret = PTR_ERR(data->supply);
425 dev_err(dev, "Failed to request supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200426 goto err_regulator;
427 }
428
429 ret = tpa6130a2_power(1);
430 if (ret != 0)
431 goto err_power;
432
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300433
434 /* Read version */
435 ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
436 TPA6130A2_VERSION_MASK;
437 if ((ret != 1) && (ret != 2))
438 dev_warn(dev, "UNTESTED version detected (%d)\n", ret);
439
440 /* Disable the chip */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200441 ret = tpa6130a2_power(0);
442 if (ret != 0)
443 goto err_power;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300444
445 return 0;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200446
447err_power:
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300448 regulator_put(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200449err_regulator:
450 if (data->power_gpio >= 0)
451 gpio_free(data->power_gpio);
452err_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
Mark Brown735fe4c2010-01-12 14:13:00 +0000458static int __devexit tpa6130a2_remove(struct i2c_client *client)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300459{
460 struct tpa6130a2_data *data = i2c_get_clientdata(client);
461
462 tpa6130a2_power(0);
463
464 if (data->power_gpio >= 0)
465 gpio_free(data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200466
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300467 regulator_put(data->supply);
Mark Brownebab1b12009-10-09 19:13:47 +0100468 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300469
470 return 0;
471}
472
473static const struct i2c_device_id tpa6130a2_id[] = {
Peter Ujfalusi07441002011-08-30 14:39:52 +0300474 { "tpa6130a2", TPA6130A2 },
475 { "tpa6140a2", TPA6140A2 },
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300476 { }
477};
478MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
479
480static struct i2c_driver tpa6130a2_i2c_driver = {
481 .driver = {
482 .name = "tpa6130a2",
483 .owner = THIS_MODULE,
484 },
485 .probe = tpa6130a2_probe,
486 .remove = __devexit_p(tpa6130a2_remove),
487 .id_table = tpa6130a2_id,
488};
489
490static int __init tpa6130a2_init(void)
491{
492 return i2c_add_driver(&tpa6130a2_i2c_driver);
493}
494
495static void __exit tpa6130a2_exit(void)
496{
497 i2c_del_driver(&tpa6130a2_i2c_driver);
498}
499
Peter Ujfalusib4079ef2011-05-03 18:12:41 +0300500MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300501MODULE_DESCRIPTION("TPA6130A2 Headphone amplifier driver");
502MODULE_LICENSE("GPL");
503
504module_init(tpa6130a2_init);
505module_exit(tpa6130a2_exit);