blob: 99b70e5978a2ee122e6799df5f27e20711a93976 [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 *
6 * Author: Peter Ujfalusi <peter.ujfalusi@nokia.com>
7 *
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>
32#include <sound/soc-dapm.h>
33#include <sound/tlv.h>
34
35#include "tpa6130a2.h"
36
Mark Brownebab1b12009-10-09 19:13:47 +010037static struct i2c_client *tpa6130a2_client;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030038
39/* This struct is used to save the context */
40struct tpa6130a2_data {
41 struct mutex mutex;
42 unsigned char regs[TPA6130A2_CACHEREGNUM];
Jarkko Nikulaad8332c2010-05-19 10:52:28 +030043 struct regulator *supply;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030044 int power_gpio;
45 unsigned char power_state;
Peter Ujfalusie5e5b312010-05-04 11:08:18 +030046 enum tpa_model id;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030047};
48
49static int tpa6130a2_i2c_read(int reg)
50{
51 struct tpa6130a2_data *data;
52 int val;
53
54 BUG_ON(tpa6130a2_client == NULL);
55 data = i2c_get_clientdata(tpa6130a2_client);
56
57 /* If powered off, return the cached value */
58 if (data->power_state) {
59 val = i2c_smbus_read_byte_data(tpa6130a2_client, reg);
60 if (val < 0)
61 dev_err(&tpa6130a2_client->dev, "Read failed\n");
62 else
63 data->regs[reg] = val;
64 } else {
65 val = data->regs[reg];
66 }
67
68 return val;
69}
70
71static int tpa6130a2_i2c_write(int reg, u8 value)
72{
73 struct tpa6130a2_data *data;
74 int val = 0;
75
76 BUG_ON(tpa6130a2_client == NULL);
77 data = i2c_get_clientdata(tpa6130a2_client);
78
79 if (data->power_state) {
80 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value);
81 if (val < 0)
82 dev_err(&tpa6130a2_client->dev, "Write failed\n");
83 }
84
85 /* Either powered on or off, we save the context */
86 data->regs[reg] = value;
87
88 return val;
89}
90
91static u8 tpa6130a2_read(int reg)
92{
93 struct tpa6130a2_data *data;
94
95 BUG_ON(tpa6130a2_client == NULL);
96 data = i2c_get_clientdata(tpa6130a2_client);
97
98 return data->regs[reg];
99}
100
101static void tpa6130a2_initialize(void)
102{
103 struct tpa6130a2_data *data;
104 int i;
105
106 BUG_ON(tpa6130a2_client == NULL);
107 data = i2c_get_clientdata(tpa6130a2_client);
108
109 for (i = 1; i < TPA6130A2_REG_VERSION; i++)
110 tpa6130a2_i2c_write(i, data->regs[i]);
111}
112
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200113static int tpa6130a2_power(int power)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300114{
115 struct tpa6130a2_data *data;
116 u8 val;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200117 int ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300118
119 BUG_ON(tpa6130a2_client == NULL);
120 data = i2c_get_clientdata(tpa6130a2_client);
121
122 mutex_lock(&data->mutex);
123 if (power) {
124 /* Power on */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200125 if (data->power_gpio >= 0)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300126 gpio_set_value(data->power_gpio, 1);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200127
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300128 ret = regulator_enable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200129 if (ret != 0) {
130 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300131 "Failed to enable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200132 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300133 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200134
135 data->power_state = 1;
136 tpa6130a2_initialize();
137
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300138 /* Clear SWS */
139 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
140 val &= ~TPA6130A2_SWS;
141 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
142 } else {
143 /* set SWS */
144 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
145 val |= TPA6130A2_SWS;
146 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200147
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300148 /* Power off */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200149 if (data->power_gpio >= 0)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300150 gpio_set_value(data->power_gpio, 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200151
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300152 ret = regulator_disable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200153 if (ret != 0) {
154 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300155 "Failed to disable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200156 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300157 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200158
159 data->power_state = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300160 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200161
162exit:
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300163 mutex_unlock(&data->mutex);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200164 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300165}
166
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300167static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300168 struct snd_ctl_elem_value *ucontrol)
169{
170 struct soc_mixer_control *mc =
171 (struct soc_mixer_control *)kcontrol->private_value;
172 struct tpa6130a2_data *data;
173 unsigned int reg = mc->reg;
174 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300175 int max = mc->max;
176 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300177 unsigned int invert = mc->invert;
178
179 BUG_ON(tpa6130a2_client == NULL);
180 data = i2c_get_clientdata(tpa6130a2_client);
181
182 mutex_lock(&data->mutex);
183
184 ucontrol->value.integer.value[0] =
185 (tpa6130a2_read(reg) >> shift) & mask;
186
187 if (invert)
188 ucontrol->value.integer.value[0] =
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300189 max - ucontrol->value.integer.value[0];
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300190
191 mutex_unlock(&data->mutex);
192 return 0;
193}
194
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300195static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300196 struct snd_ctl_elem_value *ucontrol)
197{
198 struct soc_mixer_control *mc =
199 (struct soc_mixer_control *)kcontrol->private_value;
200 struct tpa6130a2_data *data;
201 unsigned int reg = mc->reg;
202 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300203 int max = mc->max;
204 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300205 unsigned int invert = mc->invert;
206 unsigned int val = (ucontrol->value.integer.value[0] & mask);
207 unsigned int val_reg;
208
209 BUG_ON(tpa6130a2_client == NULL);
210 data = i2c_get_clientdata(tpa6130a2_client);
211
212 if (invert)
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300213 val = max - val;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300214
215 mutex_lock(&data->mutex);
216
217 val_reg = tpa6130a2_read(reg);
218 if (((val_reg >> shift) & mask) == val) {
219 mutex_unlock(&data->mutex);
220 return 0;
221 }
222
223 val_reg &= ~(mask << shift);
224 val_reg |= val << shift;
225 tpa6130a2_i2c_write(reg, val_reg);
226
227 mutex_unlock(&data->mutex);
228
229 return 1;
230}
231
232/*
233 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
234 * down in gain.
235 */
236static const unsigned int tpa6130_tlv[] = {
237 TLV_DB_RANGE_HEAD(10),
238 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
239 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
240 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
241 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
242 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
243 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
244 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
245 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
246 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
247 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
248};
249
250static const struct snd_kcontrol_new tpa6130a2_controls[] = {
251 SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
252 TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300253 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300254 tpa6130_tlv),
255};
256
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300257static const unsigned int tpa6140_tlv[] = {
258 TLV_DB_RANGE_HEAD(3),
259 0, 8, TLV_DB_SCALE_ITEM(-5900, 400, 0),
260 9, 16, TLV_DB_SCALE_ITEM(-2500, 200, 0),
261 17, 31, TLV_DB_SCALE_ITEM(-1000, 100, 0),
262};
263
264static const struct snd_kcontrol_new tpa6140a2_controls[] = {
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300265 SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
266 TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300267 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300268 tpa6140_tlv),
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300269};
270
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300271/*
272 * Enable or disable channel (left or right)
273 * The bit number for mute and amplifier are the same per channel:
274 * bit 6: Right channel
275 * bit 7: Left channel
276 * in both registers.
277 */
278static void tpa6130a2_channel_enable(u8 channel, int enable)
279{
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300280 u8 val;
281
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300282 if (enable) {
283 /* Enable channel */
284 /* Enable amplifier */
285 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
286 val |= channel;
287 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
288
289 /* Unmute channel */
290 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
291 val &= ~channel;
292 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
293 } else {
294 /* Disable channel */
295 /* Mute channel */
296 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
297 val |= channel;
298 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
299
300 /* Disable amplifier */
301 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
302 val &= ~channel;
303 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
304 }
305}
306
307static int tpa6130a2_left_event(struct snd_soc_dapm_widget *w,
308 struct snd_kcontrol *kcontrol, int event)
309{
310 switch (event) {
311 case SND_SOC_DAPM_POST_PMU:
312 tpa6130a2_channel_enable(TPA6130A2_HP_EN_L, 1);
313 break;
314 case SND_SOC_DAPM_POST_PMD:
315 tpa6130a2_channel_enable(TPA6130A2_HP_EN_L, 0);
316 break;
317 }
318 return 0;
319}
320
321static int tpa6130a2_right_event(struct snd_soc_dapm_widget *w,
322 struct snd_kcontrol *kcontrol, int event)
323{
324 switch (event) {
325 case SND_SOC_DAPM_POST_PMU:
326 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R, 1);
327 break;
328 case SND_SOC_DAPM_POST_PMD:
329 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R, 0);
330 break;
331 }
332 return 0;
333}
334
335static int tpa6130a2_supply_event(struct snd_soc_dapm_widget *w,
336 struct snd_kcontrol *kcontrol, int event)
337{
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200338 int ret = 0;
339
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300340 switch (event) {
341 case SND_SOC_DAPM_POST_PMU:
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200342 ret = tpa6130a2_power(1);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300343 break;
344 case SND_SOC_DAPM_POST_PMD:
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200345 ret = tpa6130a2_power(0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300346 break;
347 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200348 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300349}
350
351static const struct snd_soc_dapm_widget tpa6130a2_dapm_widgets[] = {
352 SND_SOC_DAPM_PGA_E("TPA6130A2 Left", SND_SOC_NOPM,
353 0, 0, NULL, 0, tpa6130a2_left_event,
354 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
355 SND_SOC_DAPM_PGA_E("TPA6130A2 Right", SND_SOC_NOPM,
356 0, 0, NULL, 0, tpa6130a2_right_event,
357 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
358 SND_SOC_DAPM_SUPPLY("TPA6130A2 Enable", SND_SOC_NOPM,
359 0, 0, tpa6130a2_supply_event,
360 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
361 /* Outputs */
Jarkko Nikula266d38c2010-05-19 13:55:26 +0300362 SND_SOC_DAPM_OUTPUT("TPA6130A2 Headphone Left"),
363 SND_SOC_DAPM_OUTPUT("TPA6130A2 Headphone Right"),
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300364};
365
366static const struct snd_soc_dapm_route audio_map[] = {
367 {"TPA6130A2 Headphone Left", NULL, "TPA6130A2 Left"},
368 {"TPA6130A2 Headphone Right", NULL, "TPA6130A2 Right"},
369
370 {"TPA6130A2 Headphone Left", NULL, "TPA6130A2 Enable"},
371 {"TPA6130A2 Headphone Right", NULL, "TPA6130A2 Enable"},
372};
373
374int tpa6130a2_add_controls(struct snd_soc_codec *codec)
375{
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300376 struct tpa6130a2_data *data;
377
378 BUG_ON(tpa6130a2_client == NULL);
379 data = i2c_get_clientdata(tpa6130a2_client);
380
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300381 snd_soc_dapm_new_controls(codec, tpa6130a2_dapm_widgets,
382 ARRAY_SIZE(tpa6130a2_dapm_widgets));
383
384 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
385
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300386 if (data->id == TPA6140A2)
387 return snd_soc_add_controls(codec, tpa6140a2_controls,
388 ARRAY_SIZE(tpa6140a2_controls));
389 else
390 return snd_soc_add_controls(codec, tpa6130a2_controls,
391 ARRAY_SIZE(tpa6130a2_controls));
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300392
393}
394EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
395
Mark Brown735fe4c2010-01-12 14:13:00 +0000396static int __devinit tpa6130a2_probe(struct i2c_client *client,
397 const struct i2c_device_id *id)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300398{
399 struct device *dev;
400 struct tpa6130a2_data *data;
401 struct tpa6130a2_platform_data *pdata;
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300402 const char *regulator;
403 int ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300404
405 dev = &client->dev;
406
407 if (client->dev.platform_data == NULL) {
408 dev_err(dev, "Platform data not set\n");
409 dump_stack();
410 return -ENODEV;
411 }
412
413 data = kzalloc(sizeof(*data), GFP_KERNEL);
414 if (data == NULL) {
415 dev_err(dev, "Can not allocate memory\n");
416 return -ENOMEM;
417 }
418
419 tpa6130a2_client = client;
420
421 i2c_set_clientdata(tpa6130a2_client, data);
422
Mark Brownebab1b12009-10-09 19:13:47 +0100423 pdata = client->dev.platform_data;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300424 data->power_gpio = pdata->power_gpio;
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300425 data->id = pdata->id;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300426
427 mutex_init(&data->mutex);
428
429 /* Set default register values */
430 data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS;
431 data->regs[TPA6130A2_REG_VOL_MUTE] = TPA6130A2_MUTE_R |
432 TPA6130A2_MUTE_L;
433
434 if (data->power_gpio >= 0) {
435 ret = gpio_request(data->power_gpio, "tpa6130a2 enable");
436 if (ret < 0) {
437 dev_err(dev, "Failed to request power GPIO (%d)\n",
438 data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200439 goto err_gpio;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300440 }
441 gpio_direction_output(data->power_gpio, 0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300442 }
443
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300444 switch (data->id) {
Ilkka Koskinen21383012010-01-08 17:48:31 +0200445 default:
446 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
447 pdata->id);
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300448 case TPA6130A2:
449 regulator = "Vdd";
450 break;
451 case TPA6140A2:
452 regulator = "AVdd";
453 break;
Ilkka Koskinen21383012010-01-08 17:48:31 +0200454 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200455
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300456 data->supply = regulator_get(dev, regulator);
457 if (IS_ERR(data->supply)) {
458 ret = PTR_ERR(data->supply);
459 dev_err(dev, "Failed to request supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200460 goto err_regulator;
461 }
462
463 ret = tpa6130a2_power(1);
464 if (ret != 0)
465 goto err_power;
466
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300467
468 /* Read version */
469 ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
470 TPA6130A2_VERSION_MASK;
471 if ((ret != 1) && (ret != 2))
472 dev_warn(dev, "UNTESTED version detected (%d)\n", ret);
473
474 /* Disable the chip */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200475 ret = tpa6130a2_power(0);
476 if (ret != 0)
477 goto err_power;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300478
479 return 0;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200480
481err_power:
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300482 regulator_put(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200483err_regulator:
484 if (data->power_gpio >= 0)
485 gpio_free(data->power_gpio);
486err_gpio:
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300487 kfree(data);
488 i2c_set_clientdata(tpa6130a2_client, NULL);
Mark Brownebab1b12009-10-09 19:13:47 +0100489 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300490
491 return ret;
492}
493
Mark Brown735fe4c2010-01-12 14:13:00 +0000494static int __devexit tpa6130a2_remove(struct i2c_client *client)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300495{
496 struct tpa6130a2_data *data = i2c_get_clientdata(client);
497
498 tpa6130a2_power(0);
499
500 if (data->power_gpio >= 0)
501 gpio_free(data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200502
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300503 regulator_put(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200504
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300505 kfree(data);
Mark Brownebab1b12009-10-09 19:13:47 +0100506 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300507
508 return 0;
509}
510
511static const struct i2c_device_id tpa6130a2_id[] = {
512 { "tpa6130a2", 0 },
513 { }
514};
515MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
516
517static struct i2c_driver tpa6130a2_i2c_driver = {
518 .driver = {
519 .name = "tpa6130a2",
520 .owner = THIS_MODULE,
521 },
522 .probe = tpa6130a2_probe,
523 .remove = __devexit_p(tpa6130a2_remove),
524 .id_table = tpa6130a2_id,
525};
526
527static int __init tpa6130a2_init(void)
528{
529 return i2c_add_driver(&tpa6130a2_i2c_driver);
530}
531
532static void __exit tpa6130a2_exit(void)
533{
534 i2c_del_driver(&tpa6130a2_i2c_driver);
535}
536
537MODULE_AUTHOR("Peter Ujfalusi");
538MODULE_DESCRIPTION("TPA6130A2 Headphone amplifier driver");
539MODULE_LICENSE("GPL");
540
541module_init(tpa6130a2_init);
542module_exit(tpa6130a2_exit);