blob: 239e0c461068bebb2189a0d7aaff22f472fc8d78 [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
Mark Brownebab1b12009-10-09 19:13:47 +010036static struct i2c_client *tpa6130a2_client;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030037
38/* This struct is used to save the context */
39struct tpa6130a2_data {
40 struct mutex mutex;
41 unsigned char regs[TPA6130A2_CACHEREGNUM];
Jarkko Nikulaad8332c2010-05-19 10:52:28 +030042 struct regulator *supply;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030043 int power_gpio;
Peter Ujfalusid5876ce2010-11-30 16:00:00 +020044 u8 power_state:1;
Peter Ujfalusie5e5b312010-05-04 11:08:18 +030045 enum tpa_model id;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030046};
47
48static int tpa6130a2_i2c_read(int reg)
49{
50 struct tpa6130a2_data *data;
51 int val;
52
53 BUG_ON(tpa6130a2_client == NULL);
54 data = i2c_get_clientdata(tpa6130a2_client);
55
56 /* If powered off, return the cached value */
57 if (data->power_state) {
58 val = i2c_smbus_read_byte_data(tpa6130a2_client, reg);
59 if (val < 0)
60 dev_err(&tpa6130a2_client->dev, "Read failed\n");
61 else
62 data->regs[reg] = val;
63 } else {
64 val = data->regs[reg];
65 }
66
67 return val;
68}
69
70static int tpa6130a2_i2c_write(int reg, u8 value)
71{
72 struct tpa6130a2_data *data;
73 int val = 0;
74
75 BUG_ON(tpa6130a2_client == NULL);
76 data = i2c_get_clientdata(tpa6130a2_client);
77
78 if (data->power_state) {
79 val = i2c_smbus_write_byte_data(tpa6130a2_client, reg, value);
Axel Lin7a479b02010-11-23 14:14:07 +080080 if (val < 0) {
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030081 dev_err(&tpa6130a2_client->dev, "Write failed\n");
Axel Lin7a479b02010-11-23 14:14:07 +080082 return val;
83 }
Peter Ujfalusi493b67e2009-10-09 15:55:41 +030084 }
85
86 /* Either powered on or off, we save the context */
87 data->regs[reg] = value;
88
89 return val;
90}
91
92static u8 tpa6130a2_read(int reg)
93{
94 struct tpa6130a2_data *data;
95
96 BUG_ON(tpa6130a2_client == NULL);
97 data = i2c_get_clientdata(tpa6130a2_client);
98
99 return data->regs[reg];
100}
101
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300102static int tpa6130a2_initialize(void)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300103{
104 struct tpa6130a2_data *data;
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300105 int i, ret = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300106
107 BUG_ON(tpa6130a2_client == NULL);
108 data = i2c_get_clientdata(tpa6130a2_client);
109
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300110 for (i = 1; i < TPA6130A2_REG_VERSION; i++) {
111 ret = tpa6130a2_i2c_write(i, data->regs[i]);
112 if (ret < 0)
113 break;
114 }
115
116 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300117}
118
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200119static int tpa6130a2_power(u8 power)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300120{
121 struct tpa6130a2_data *data;
122 u8 val;
Jarkko Nikula75e3f312010-11-03 16:39:00 +0200123 int ret = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300124
125 BUG_ON(tpa6130a2_client == NULL);
126 data = i2c_get_clientdata(tpa6130a2_client);
127
128 mutex_lock(&data->mutex);
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200129 if (power == data->power_state)
130 goto exit;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200131
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200132 if (power) {
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300133 ret = regulator_enable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200134 if (ret != 0) {
135 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300136 "Failed to enable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200137 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300138 }
Jarkko Nikula0656f6c2010-11-08 10:57:57 +0200139 /* Power on */
140 if (data->power_gpio >= 0)
141 gpio_set_value(data->power_gpio, 1);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200142
143 data->power_state = 1;
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300144 ret = tpa6130a2_initialize();
145 if (ret < 0) {
146 dev_err(&tpa6130a2_client->dev,
147 "Failed to initialize chip\n");
148 if (data->power_gpio >= 0)
149 gpio_set_value(data->power_gpio, 0);
150 regulator_disable(data->supply);
151 data->power_state = 0;
152 goto exit;
153 }
Peter Ujfalusid5876ce2010-11-30 16:00:00 +0200154 } else {
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300155 /* set SWS */
156 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
157 val |= TPA6130A2_SWS;
158 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200159
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300160 /* Power off */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200161 if (data->power_gpio >= 0)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300162 gpio_set_value(data->power_gpio, 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200163
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300164 ret = regulator_disable(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200165 if (ret != 0) {
166 dev_err(&tpa6130a2_client->dev,
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300167 "Failed to disable supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200168 goto exit;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300169 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200170
171 data->power_state = 0;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300172 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200173
174exit:
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300175 mutex_unlock(&data->mutex);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200176 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300177}
178
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300179static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300180 struct snd_ctl_elem_value *ucontrol)
181{
182 struct soc_mixer_control *mc =
183 (struct soc_mixer_control *)kcontrol->private_value;
184 struct tpa6130a2_data *data;
185 unsigned int reg = mc->reg;
186 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300187 int max = mc->max;
188 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300189 unsigned int invert = mc->invert;
190
191 BUG_ON(tpa6130a2_client == NULL);
192 data = i2c_get_clientdata(tpa6130a2_client);
193
194 mutex_lock(&data->mutex);
195
196 ucontrol->value.integer.value[0] =
197 (tpa6130a2_read(reg) >> shift) & mask;
198
199 if (invert)
200 ucontrol->value.integer.value[0] =
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300201 max - ucontrol->value.integer.value[0];
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300202
203 mutex_unlock(&data->mutex);
204 return 0;
205}
206
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300207static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300208 struct snd_ctl_elem_value *ucontrol)
209{
210 struct soc_mixer_control *mc =
211 (struct soc_mixer_control *)kcontrol->private_value;
212 struct tpa6130a2_data *data;
213 unsigned int reg = mc->reg;
214 unsigned int shift = mc->shift;
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300215 int max = mc->max;
216 unsigned int mask = (1 << fls(max)) - 1;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300217 unsigned int invert = mc->invert;
218 unsigned int val = (ucontrol->value.integer.value[0] & mask);
219 unsigned int val_reg;
220
221 BUG_ON(tpa6130a2_client == NULL);
222 data = i2c_get_clientdata(tpa6130a2_client);
223
224 if (invert)
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300225 val = max - val;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300226
227 mutex_lock(&data->mutex);
228
229 val_reg = tpa6130a2_read(reg);
230 if (((val_reg >> shift) & mask) == val) {
231 mutex_unlock(&data->mutex);
232 return 0;
233 }
234
235 val_reg &= ~(mask << shift);
236 val_reg |= val << shift;
237 tpa6130a2_i2c_write(reg, val_reg);
238
239 mutex_unlock(&data->mutex);
240
241 return 1;
242}
243
244/*
245 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
246 * down in gain.
247 */
248static const unsigned int tpa6130_tlv[] = {
249 TLV_DB_RANGE_HEAD(10),
250 0, 1, TLV_DB_SCALE_ITEM(-5950, 600, 0),
251 2, 3, TLV_DB_SCALE_ITEM(-5000, 250, 0),
252 4, 5, TLV_DB_SCALE_ITEM(-4550, 160, 0),
253 6, 7, TLV_DB_SCALE_ITEM(-4140, 190, 0),
254 8, 9, TLV_DB_SCALE_ITEM(-3650, 120, 0),
255 10, 11, TLV_DB_SCALE_ITEM(-3330, 160, 0),
256 12, 13, TLV_DB_SCALE_ITEM(-3040, 180, 0),
257 14, 20, TLV_DB_SCALE_ITEM(-2710, 110, 0),
258 21, 37, TLV_DB_SCALE_ITEM(-1960, 74, 0),
259 38, 63, TLV_DB_SCALE_ITEM(-720, 45, 0),
260};
261
262static const struct snd_kcontrol_new tpa6130a2_controls[] = {
263 SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
264 TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300265 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300266 tpa6130_tlv),
267};
268
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300269static const unsigned int tpa6140_tlv[] = {
270 TLV_DB_RANGE_HEAD(3),
271 0, 8, TLV_DB_SCALE_ITEM(-5900, 400, 0),
272 9, 16, TLV_DB_SCALE_ITEM(-2500, 200, 0),
273 17, 31, TLV_DB_SCALE_ITEM(-1000, 100, 0),
274};
275
276static const struct snd_kcontrol_new tpa6140a2_controls[] = {
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300277 SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
278 TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
Peter Ujfalusibd843ed2010-05-07 14:24:11 +0300279 tpa6130a2_get_volsw, tpa6130a2_put_volsw,
Peter Ujfalusi826e9622010-05-07 14:24:10 +0300280 tpa6140_tlv),
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300281};
282
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300283/*
284 * Enable or disable channel (left or right)
285 * The bit number for mute and amplifier are the same per channel:
286 * bit 6: Right channel
287 * bit 7: Left channel
288 * in both registers.
289 */
290static void tpa6130a2_channel_enable(u8 channel, int enable)
291{
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300292 u8 val;
293
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300294 if (enable) {
295 /* Enable channel */
296 /* Enable amplifier */
297 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
298 val |= channel;
Peter Ujfalusid534bac2010-11-30 16:00:01 +0200299 val &= ~TPA6130A2_SWS;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300300 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
301
302 /* Unmute channel */
303 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
304 val &= ~channel;
305 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
306 } else {
307 /* Disable channel */
308 /* Mute channel */
309 val = tpa6130a2_read(TPA6130A2_REG_VOL_MUTE);
310 val |= channel;
311 tpa6130a2_i2c_write(TPA6130A2_REG_VOL_MUTE, val);
312
313 /* Disable amplifier */
314 val = tpa6130a2_read(TPA6130A2_REG_CONTROL);
315 val &= ~channel;
316 tpa6130a2_i2c_write(TPA6130A2_REG_CONTROL, val);
317 }
318}
319
Peter Ujfalusi39646872010-12-02 09:29:56 +0200320int tpa6130a2_stereo_enable(struct snd_soc_codec *codec, int enable)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300321{
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200322 int ret = 0;
Peter Ujfalusi39646872010-12-02 09:29:56 +0200323 if (enable) {
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200324 ret = tpa6130a2_power(1);
Peter Ujfalusi39646872010-12-02 09:29:56 +0200325 if (ret < 0)
326 return ret;
327 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
328 1);
329 } else {
330 tpa6130a2_channel_enable(TPA6130A2_HP_EN_R | TPA6130A2_HP_EN_L,
331 0);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200332 ret = tpa6130a2_power(0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300333 }
Peter Ujfalusi39646872010-12-02 09:29:56 +0200334
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200335 return ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300336}
Peter Ujfalusi39646872010-12-02 09:29:56 +0200337EXPORT_SYMBOL_GPL(tpa6130a2_stereo_enable);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300338
339int tpa6130a2_add_controls(struct snd_soc_codec *codec)
340{
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300341 struct tpa6130a2_data *data;
342
Peter Ujfalusi872a64d2010-10-21 15:03:03 +0300343 if (tpa6130a2_client == NULL)
344 return -ENODEV;
345
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300346 data = i2c_get_clientdata(tpa6130a2_client);
347
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300348 if (data->id == TPA6140A2)
349 return snd_soc_add_controls(codec, tpa6140a2_controls,
350 ARRAY_SIZE(tpa6140a2_controls));
351 else
352 return snd_soc_add_controls(codec, tpa6130a2_controls,
353 ARRAY_SIZE(tpa6130a2_controls));
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300354}
355EXPORT_SYMBOL_GPL(tpa6130a2_add_controls);
356
Mark Brown735fe4c2010-01-12 14:13:00 +0000357static int __devinit tpa6130a2_probe(struct i2c_client *client,
358 const struct i2c_device_id *id)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300359{
360 struct device *dev;
361 struct tpa6130a2_data *data;
362 struct tpa6130a2_platform_data *pdata;
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300363 const char *regulator;
364 int ret;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300365
366 dev = &client->dev;
367
368 if (client->dev.platform_data == NULL) {
369 dev_err(dev, "Platform data not set\n");
370 dump_stack();
371 return -ENODEV;
372 }
373
374 data = kzalloc(sizeof(*data), GFP_KERNEL);
375 if (data == NULL) {
376 dev_err(dev, "Can not allocate memory\n");
377 return -ENOMEM;
378 }
379
380 tpa6130a2_client = client;
381
382 i2c_set_clientdata(tpa6130a2_client, data);
383
Mark Brownebab1b12009-10-09 19:13:47 +0100384 pdata = client->dev.platform_data;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300385 data->power_gpio = pdata->power_gpio;
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300386 data->id = pdata->id;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300387
388 mutex_init(&data->mutex);
389
390 /* Set default register values */
391 data->regs[TPA6130A2_REG_CONTROL] = TPA6130A2_SWS;
392 data->regs[TPA6130A2_REG_VOL_MUTE] = TPA6130A2_MUTE_R |
393 TPA6130A2_MUTE_L;
394
395 if (data->power_gpio >= 0) {
396 ret = gpio_request(data->power_gpio, "tpa6130a2 enable");
397 if (ret < 0) {
398 dev_err(dev, "Failed to request power GPIO (%d)\n",
399 data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200400 goto err_gpio;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300401 }
402 gpio_direction_output(data->power_gpio, 0);
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300403 }
404
Peter Ujfalusie5e5b312010-05-04 11:08:18 +0300405 switch (data->id) {
Ilkka Koskinen21383012010-01-08 17:48:31 +0200406 default:
407 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
408 pdata->id);
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300409 case TPA6130A2:
410 regulator = "Vdd";
411 break;
412 case TPA6140A2:
413 regulator = "AVdd";
414 break;
Ilkka Koskinen21383012010-01-08 17:48:31 +0200415 }
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200416
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300417 data->supply = regulator_get(dev, regulator);
418 if (IS_ERR(data->supply)) {
419 ret = PTR_ERR(data->supply);
420 dev_err(dev, "Failed to request supply: %d\n", ret);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200421 goto err_regulator;
422 }
423
424 ret = tpa6130a2_power(1);
425 if (ret != 0)
426 goto err_power;
427
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300428
429 /* Read version */
430 ret = tpa6130a2_i2c_read(TPA6130A2_REG_VERSION) &
431 TPA6130A2_VERSION_MASK;
432 if ((ret != 1) && (ret != 2))
433 dev_warn(dev, "UNTESTED version detected (%d)\n", ret);
434
435 /* Disable the chip */
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200436 ret = tpa6130a2_power(0);
437 if (ret != 0)
438 goto err_power;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300439
440 return 0;
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200441
442err_power:
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300443 regulator_put(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200444err_regulator:
445 if (data->power_gpio >= 0)
446 gpio_free(data->power_gpio);
447err_gpio:
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300448 kfree(data);
449 i2c_set_clientdata(tpa6130a2_client, NULL);
Mark Brownebab1b12009-10-09 19:13:47 +0100450 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300451
452 return ret;
453}
454
Mark Brown735fe4c2010-01-12 14:13:00 +0000455static int __devexit tpa6130a2_remove(struct i2c_client *client)
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300456{
457 struct tpa6130a2_data *data = i2c_get_clientdata(client);
458
459 tpa6130a2_power(0);
460
461 if (data->power_gpio >= 0)
462 gpio_free(data->power_gpio);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200463
Jarkko Nikulaad8332c2010-05-19 10:52:28 +0300464 regulator_put(data->supply);
Ilkka Koskinen7c4e6492009-12-09 12:05:50 +0200465
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300466 kfree(data);
Mark Brownebab1b12009-10-09 19:13:47 +0100467 tpa6130a2_client = NULL;
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300468
469 return 0;
470}
471
472static const struct i2c_device_id tpa6130a2_id[] = {
473 { "tpa6130a2", 0 },
474 { }
475};
476MODULE_DEVICE_TABLE(i2c, tpa6130a2_id);
477
478static struct i2c_driver tpa6130a2_i2c_driver = {
479 .driver = {
480 .name = "tpa6130a2",
481 .owner = THIS_MODULE,
482 },
483 .probe = tpa6130a2_probe,
484 .remove = __devexit_p(tpa6130a2_remove),
485 .id_table = tpa6130a2_id,
486};
487
488static int __init tpa6130a2_init(void)
489{
490 return i2c_add_driver(&tpa6130a2_i2c_driver);
491}
492
493static void __exit tpa6130a2_exit(void)
494{
495 i2c_del_driver(&tpa6130a2_i2c_driver);
496}
497
Peter Ujfalusib4079ef2011-05-03 18:12:41 +0300498MODULE_AUTHOR("Peter Ujfalusi <peter.ujfalusi@ti.com>");
Peter Ujfalusi493b67e2009-10-09 15:55:41 +0300499MODULE_DESCRIPTION("TPA6130A2 Headphone amplifier driver");
500MODULE_LICENSE("GPL");
501
502module_init(tpa6130a2_init);
503module_exit(tpa6130a2_exit);