• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * MFD driver for TWL6040 audio device
3  *
4  * Authors:	Misael Lopez Cruz <misael.lopez@ti.com>
5  *		Jorge Eduardo Candelaria <jorge.candelaria@ti.com>
6  *		Peter Ujfalusi <peter.ujfalusi@ti.com>
7  *
8  * Copyright:	(C) 2011 Texas Instruments, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  *
24  */
25 
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/slab.h>
29 #include <linux/kernel.h>
30 #include <linux/platform_device.h>
31 #include <linux/gpio.h>
32 #include <linux/delay.h>
33 #include <linux/i2c.h>
34 #include <linux/regmap.h>
35 #include <linux/err.h>
36 #include <linux/mfd/core.h>
37 #include <linux/mfd/twl6040.h>
38 
39 #define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
40 
twl6040_reg_read(struct twl6040 * twl6040,unsigned int reg)41 int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
42 {
43 	int ret;
44 	unsigned int val;
45 
46 	mutex_lock(&twl6040->io_mutex);
47 	/* Vibra control registers from cache */
48 	if (unlikely(reg == TWL6040_REG_VIBCTLL ||
49 		     reg == TWL6040_REG_VIBCTLR)) {
50 		val = twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)];
51 	} else {
52 		ret = regmap_read(twl6040->regmap, reg, &val);
53 		if (ret < 0) {
54 			mutex_unlock(&twl6040->io_mutex);
55 			return ret;
56 		}
57 	}
58 	mutex_unlock(&twl6040->io_mutex);
59 
60 	return val;
61 }
62 EXPORT_SYMBOL(twl6040_reg_read);
63 
twl6040_reg_write(struct twl6040 * twl6040,unsigned int reg,u8 val)64 int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
65 {
66 	int ret;
67 
68 	mutex_lock(&twl6040->io_mutex);
69 	ret = regmap_write(twl6040->regmap, reg, val);
70 	/* Cache the vibra control registers */
71 	if (reg == TWL6040_REG_VIBCTLL || reg == TWL6040_REG_VIBCTLR)
72 		twl6040->vibra_ctrl_cache[VIBRACTRL_MEMBER(reg)] = val;
73 	mutex_unlock(&twl6040->io_mutex);
74 
75 	return ret;
76 }
77 EXPORT_SYMBOL(twl6040_reg_write);
78 
twl6040_set_bits(struct twl6040 * twl6040,unsigned int reg,u8 mask)79 int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
80 {
81 	int ret;
82 
83 	mutex_lock(&twl6040->io_mutex);
84 	ret = regmap_update_bits(twl6040->regmap, reg, mask, mask);
85 	mutex_unlock(&twl6040->io_mutex);
86 	return ret;
87 }
88 EXPORT_SYMBOL(twl6040_set_bits);
89 
twl6040_clear_bits(struct twl6040 * twl6040,unsigned int reg,u8 mask)90 int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
91 {
92 	int ret;
93 
94 	mutex_lock(&twl6040->io_mutex);
95 	ret = regmap_update_bits(twl6040->regmap, reg, mask, 0);
96 	mutex_unlock(&twl6040->io_mutex);
97 	return ret;
98 }
99 EXPORT_SYMBOL(twl6040_clear_bits);
100 
101 /* twl6040 codec manual power-up sequence */
twl6040_power_up(struct twl6040 * twl6040)102 static int twl6040_power_up(struct twl6040 *twl6040)
103 {
104 	u8 ldoctl, ncpctl, lppllctl;
105 	int ret;
106 
107 	/* enable high-side LDO, reference system and internal oscillator */
108 	ldoctl = TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA;
109 	ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
110 	if (ret)
111 		return ret;
112 	usleep_range(10000, 10500);
113 
114 	/* enable negative charge pump */
115 	ncpctl = TWL6040_NCPENA;
116 	ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
117 	if (ret)
118 		goto ncp_err;
119 	usleep_range(1000, 1500);
120 
121 	/* enable low-side LDO */
122 	ldoctl |= TWL6040_LSLDOENA;
123 	ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
124 	if (ret)
125 		goto lsldo_err;
126 	usleep_range(1000, 1500);
127 
128 	/* enable low-power PLL */
129 	lppllctl = TWL6040_LPLLENA;
130 	ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
131 	if (ret)
132 		goto lppll_err;
133 	usleep_range(5000, 5500);
134 
135 	/* disable internal oscillator */
136 	ldoctl &= ~TWL6040_OSCENA;
137 	ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
138 	if (ret)
139 		goto osc_err;
140 
141 	return 0;
142 
143 osc_err:
144 	lppllctl &= ~TWL6040_LPLLENA;
145 	twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
146 lppll_err:
147 	ldoctl &= ~TWL6040_LSLDOENA;
148 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
149 lsldo_err:
150 	ncpctl &= ~TWL6040_NCPENA;
151 	twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
152 ncp_err:
153 	ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
154 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
155 
156 	return ret;
157 }
158 
159 /* twl6040 manual power-down sequence */
twl6040_power_down(struct twl6040 * twl6040)160 static void twl6040_power_down(struct twl6040 *twl6040)
161 {
162 	u8 ncpctl, ldoctl, lppllctl;
163 
164 	ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL);
165 	ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL);
166 	lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
167 
168 	/* enable internal oscillator */
169 	ldoctl |= TWL6040_OSCENA;
170 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
171 	usleep_range(1000, 1500);
172 
173 	/* disable low-power PLL */
174 	lppllctl &= ~TWL6040_LPLLENA;
175 	twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
176 
177 	/* disable low-side LDO */
178 	ldoctl &= ~TWL6040_LSLDOENA;
179 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
180 
181 	/* disable negative charge pump */
182 	ncpctl &= ~TWL6040_NCPENA;
183 	twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
184 
185 	/* disable high-side LDO, reference system and internal oscillator */
186 	ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
187 	twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
188 }
189 
twl6040_naudint_handler(int irq,void * data)190 static irqreturn_t twl6040_naudint_handler(int irq, void *data)
191 {
192 	struct twl6040 *twl6040 = data;
193 	u8 intid, status;
194 
195 	intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
196 
197 	if (intid & TWL6040_READYINT)
198 		complete(&twl6040->ready);
199 
200 	if (intid & TWL6040_THINT) {
201 		status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
202 		if (status & TWL6040_TSHUTDET) {
203 			dev_warn(twl6040->dev,
204 				 "Thermal shutdown, powering-off");
205 			twl6040_power(twl6040, 0);
206 		} else {
207 			dev_warn(twl6040->dev,
208 				 "Leaving thermal shutdown, powering-on");
209 			twl6040_power(twl6040, 1);
210 		}
211 	}
212 
213 	return IRQ_HANDLED;
214 }
215 
twl6040_power_up_completion(struct twl6040 * twl6040,int naudint)216 static int twl6040_power_up_completion(struct twl6040 *twl6040,
217 				       int naudint)
218 {
219 	int time_left;
220 	u8 intid;
221 
222 	time_left = wait_for_completion_timeout(&twl6040->ready,
223 						msecs_to_jiffies(144));
224 	if (!time_left) {
225 		intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
226 		if (!(intid & TWL6040_READYINT)) {
227 			dev_err(twl6040->dev,
228 				"timeout waiting for READYINT\n");
229 			return -ETIMEDOUT;
230 		}
231 	}
232 
233 	return 0;
234 }
235 
twl6040_power(struct twl6040 * twl6040,int on)236 int twl6040_power(struct twl6040 *twl6040, int on)
237 {
238 	int audpwron = twl6040->audpwron;
239 	int naudint = twl6040->irq;
240 	int ret = 0;
241 
242 	mutex_lock(&twl6040->mutex);
243 
244 	if (on) {
245 		/* already powered-up */
246 		if (twl6040->power_count++)
247 			goto out;
248 
249 		if (gpio_is_valid(audpwron)) {
250 			/* use AUDPWRON line */
251 			gpio_set_value(audpwron, 1);
252 			/* wait for power-up completion */
253 			ret = twl6040_power_up_completion(twl6040, naudint);
254 			if (ret) {
255 				dev_err(twl6040->dev,
256 					"automatic power-down failed\n");
257 				twl6040->power_count = 0;
258 				goto out;
259 			}
260 		} else {
261 			/* use manual power-up sequence */
262 			ret = twl6040_power_up(twl6040);
263 			if (ret) {
264 				dev_err(twl6040->dev,
265 					"manual power-up failed\n");
266 				twl6040->power_count = 0;
267 				goto out;
268 			}
269 		}
270 		/* Default PLL configuration after power up */
271 		twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL;
272 		twl6040->sysclk = 19200000;
273 		twl6040->mclk = 32768;
274 	} else {
275 		/* already powered-down */
276 		if (!twl6040->power_count) {
277 			dev_err(twl6040->dev,
278 				"device is already powered-off\n");
279 			ret = -EPERM;
280 			goto out;
281 		}
282 
283 		if (--twl6040->power_count)
284 			goto out;
285 
286 		if (gpio_is_valid(audpwron)) {
287 			/* use AUDPWRON line */
288 			gpio_set_value(audpwron, 0);
289 
290 			/* power-down sequence latency */
291 			usleep_range(500, 700);
292 		} else {
293 			/* use manual power-down sequence */
294 			twl6040_power_down(twl6040);
295 		}
296 		twl6040->sysclk = 0;
297 		twl6040->mclk = 0;
298 	}
299 
300 out:
301 	mutex_unlock(&twl6040->mutex);
302 	return ret;
303 }
304 EXPORT_SYMBOL(twl6040_power);
305 
twl6040_set_pll(struct twl6040 * twl6040,int pll_id,unsigned int freq_in,unsigned int freq_out)306 int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
307 		    unsigned int freq_in, unsigned int freq_out)
308 {
309 	u8 hppllctl, lppllctl;
310 	int ret = 0;
311 
312 	mutex_lock(&twl6040->mutex);
313 
314 	hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL);
315 	lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
316 
317 	/* Force full reconfiguration when switching between PLL */
318 	if (pll_id != twl6040->pll) {
319 		twl6040->sysclk = 0;
320 		twl6040->mclk = 0;
321 	}
322 
323 	switch (pll_id) {
324 	case TWL6040_SYSCLK_SEL_LPPLL:
325 		/* low-power PLL divider */
326 		/* Change the sysclk configuration only if it has been canged */
327 		if (twl6040->sysclk != freq_out) {
328 			switch (freq_out) {
329 			case 17640000:
330 				lppllctl |= TWL6040_LPLLFIN;
331 				break;
332 			case 19200000:
333 				lppllctl &= ~TWL6040_LPLLFIN;
334 				break;
335 			default:
336 				dev_err(twl6040->dev,
337 					"freq_out %d not supported\n",
338 					freq_out);
339 				ret = -EINVAL;
340 				goto pll_out;
341 			}
342 			twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
343 					  lppllctl);
344 		}
345 
346 		/* The PLL in use has not been change, we can exit */
347 		if (twl6040->pll == pll_id)
348 			break;
349 
350 		switch (freq_in) {
351 		case 32768:
352 			lppllctl |= TWL6040_LPLLENA;
353 			twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
354 					  lppllctl);
355 			mdelay(5);
356 			lppllctl &= ~TWL6040_HPLLSEL;
357 			twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
358 					  lppllctl);
359 			hppllctl &= ~TWL6040_HPLLENA;
360 			twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
361 					  hppllctl);
362 			break;
363 		default:
364 			dev_err(twl6040->dev,
365 				"freq_in %d not supported\n", freq_in);
366 			ret = -EINVAL;
367 			goto pll_out;
368 		}
369 		break;
370 	case TWL6040_SYSCLK_SEL_HPPLL:
371 		/* high-performance PLL can provide only 19.2 MHz */
372 		if (freq_out != 19200000) {
373 			dev_err(twl6040->dev,
374 				"freq_out %d not supported\n", freq_out);
375 			ret = -EINVAL;
376 			goto pll_out;
377 		}
378 
379 		if (twl6040->mclk != freq_in) {
380 			hppllctl &= ~TWL6040_MCLK_MSK;
381 
382 			switch (freq_in) {
383 			case 12000000:
384 				/* PLL enabled, active mode */
385 				hppllctl |= TWL6040_MCLK_12000KHZ |
386 					    TWL6040_HPLLENA;
387 				break;
388 			case 19200000:
389 				/*
390 				* PLL disabled
391 				* (enable PLL if MCLK jitter quality
392 				*  doesn't meet specification)
393 				*/
394 				hppllctl |= TWL6040_MCLK_19200KHZ;
395 				break;
396 			case 26000000:
397 				/* PLL enabled, active mode */
398 				hppllctl |= TWL6040_MCLK_26000KHZ |
399 					    TWL6040_HPLLENA;
400 				break;
401 			case 38400000:
402 				/* PLL enabled, active mode */
403 				hppllctl |= TWL6040_MCLK_38400KHZ |
404 					    TWL6040_HPLLENA;
405 				break;
406 			default:
407 				dev_err(twl6040->dev,
408 					"freq_in %d not supported\n", freq_in);
409 				ret = -EINVAL;
410 				goto pll_out;
411 			}
412 
413 			/*
414 			 * enable clock slicer to ensure input waveform is
415 			 * square
416 			 */
417 			hppllctl |= TWL6040_HPLLSQRENA;
418 
419 			twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
420 					  hppllctl);
421 			usleep_range(500, 700);
422 			lppllctl |= TWL6040_HPLLSEL;
423 			twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
424 					  lppllctl);
425 			lppllctl &= ~TWL6040_LPLLENA;
426 			twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
427 					  lppllctl);
428 		}
429 		break;
430 	default:
431 		dev_err(twl6040->dev, "unknown pll id %d\n", pll_id);
432 		ret = -EINVAL;
433 		goto pll_out;
434 	}
435 
436 	twl6040->sysclk = freq_out;
437 	twl6040->mclk = freq_in;
438 	twl6040->pll = pll_id;
439 
440 pll_out:
441 	mutex_unlock(&twl6040->mutex);
442 	return ret;
443 }
444 EXPORT_SYMBOL(twl6040_set_pll);
445 
twl6040_get_pll(struct twl6040 * twl6040)446 int twl6040_get_pll(struct twl6040 *twl6040)
447 {
448 	if (twl6040->power_count)
449 		return twl6040->pll;
450 	else
451 		return -ENODEV;
452 }
453 EXPORT_SYMBOL(twl6040_get_pll);
454 
twl6040_get_sysclk(struct twl6040 * twl6040)455 unsigned int twl6040_get_sysclk(struct twl6040 *twl6040)
456 {
457 	return twl6040->sysclk;
458 }
459 EXPORT_SYMBOL(twl6040_get_sysclk);
460 
461 /* Get the combined status of the vibra control register */
twl6040_get_vibralr_status(struct twl6040 * twl6040)462 int twl6040_get_vibralr_status(struct twl6040 *twl6040)
463 {
464 	u8 status;
465 
466 	status = twl6040->vibra_ctrl_cache[0] | twl6040->vibra_ctrl_cache[1];
467 	status &= (TWL6040_VIBENA | TWL6040_VIBSEL);
468 
469 	return status;
470 }
471 EXPORT_SYMBOL(twl6040_get_vibralr_status);
472 
473 static struct resource twl6040_vibra_rsrc[] = {
474 	{
475 		.flags = IORESOURCE_IRQ,
476 	},
477 };
478 
479 static struct resource twl6040_codec_rsrc[] = {
480 	{
481 		.flags = IORESOURCE_IRQ,
482 	},
483 };
484 
twl6040_readable_reg(struct device * dev,unsigned int reg)485 static bool twl6040_readable_reg(struct device *dev, unsigned int reg)
486 {
487 	/* Register 0 is not readable */
488 	if (!reg)
489 		return false;
490 	return true;
491 }
492 
493 static struct regmap_config twl6040_regmap_config = {
494 	.reg_bits = 8,
495 	.val_bits = 8,
496 	.max_register = TWL6040_REG_STATUS, /* 0x2e */
497 
498 	.readable_reg = twl6040_readable_reg,
499 };
500 
twl6040_probe(struct i2c_client * client,const struct i2c_device_id * id)501 static int __devinit twl6040_probe(struct i2c_client *client,
502 				     const struct i2c_device_id *id)
503 {
504 	struct twl6040_platform_data *pdata = client->dev.platform_data;
505 	struct twl6040 *twl6040;
506 	struct mfd_cell *cell = NULL;
507 	int ret, children = 0;
508 
509 	if (!pdata) {
510 		dev_err(&client->dev, "Platform data is missing\n");
511 		return -EINVAL;
512 	}
513 
514 	/* In order to operate correctly we need valid interrupt config */
515 	if (!client->irq || !pdata->irq_base) {
516 		dev_err(&client->dev, "Invalid IRQ configuration\n");
517 		return -EINVAL;
518 	}
519 
520 	twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040),
521 			       GFP_KERNEL);
522 	if (!twl6040) {
523 		ret = -ENOMEM;
524 		goto err;
525 	}
526 
527 	twl6040->regmap = regmap_init_i2c(client, &twl6040_regmap_config);
528 	if (IS_ERR(twl6040->regmap)) {
529 		ret = PTR_ERR(twl6040->regmap);
530 		goto err;
531 	}
532 
533 	i2c_set_clientdata(client, twl6040);
534 
535 	twl6040->dev = &client->dev;
536 	twl6040->irq = client->irq;
537 	twl6040->irq_base = pdata->irq_base;
538 
539 	mutex_init(&twl6040->mutex);
540 	mutex_init(&twl6040->io_mutex);
541 	init_completion(&twl6040->ready);
542 
543 	twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV);
544 
545 	/* ERRATA: Automatic power-up is not possible in ES1.0 */
546 	if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0)
547 		twl6040->audpwron = pdata->audpwron_gpio;
548 	else
549 		twl6040->audpwron = -EINVAL;
550 
551 	if (gpio_is_valid(twl6040->audpwron)) {
552 		ret = gpio_request_one(twl6040->audpwron, GPIOF_OUT_INIT_LOW,
553 				       "audpwron");
554 		if (ret)
555 			goto gpio1_err;
556 	}
557 
558 	/* codec interrupt */
559 	ret = twl6040_irq_init(twl6040);
560 	if (ret)
561 		goto gpio2_err;
562 
563 	ret = request_threaded_irq(twl6040->irq_base + TWL6040_IRQ_READY,
564 				   NULL, twl6040_naudint_handler, 0,
565 				   "twl6040_irq_ready", twl6040);
566 	if (ret) {
567 		dev_err(twl6040->dev, "READY IRQ request failed: %d\n",
568 			ret);
569 		goto irq_err;
570 	}
571 
572 	/* dual-access registers controlled by I2C only */
573 	twl6040_set_bits(twl6040, TWL6040_REG_ACCCTL, TWL6040_I2CSEL);
574 
575 	if (pdata->codec) {
576 		int irq = twl6040->irq_base + TWL6040_IRQ_PLUG;
577 
578 		cell = &twl6040->cells[children];
579 		cell->name = "twl6040-codec";
580 		twl6040_codec_rsrc[0].start = irq;
581 		twl6040_codec_rsrc[0].end = irq;
582 		cell->resources = twl6040_codec_rsrc;
583 		cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc);
584 		cell->platform_data = pdata->codec;
585 		cell->pdata_size = sizeof(*pdata->codec);
586 		children++;
587 	}
588 
589 	if (pdata->vibra) {
590 		int irq = twl6040->irq_base + TWL6040_IRQ_VIB;
591 
592 		cell = &twl6040->cells[children];
593 		cell->name = "twl6040-vibra";
594 		twl6040_vibra_rsrc[0].start = irq;
595 		twl6040_vibra_rsrc[0].end = irq;
596 		cell->resources = twl6040_vibra_rsrc;
597 		cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc);
598 
599 		cell->platform_data = pdata->vibra;
600 		cell->pdata_size = sizeof(*pdata->vibra);
601 		children++;
602 	}
603 
604 	if (children) {
605 		ret = mfd_add_devices(&client->dev, -1, twl6040->cells,
606 				      children, NULL, 0);
607 		if (ret)
608 			goto mfd_err;
609 	} else {
610 		dev_err(&client->dev, "No platform data found for children\n");
611 		ret = -ENODEV;
612 		goto mfd_err;
613 	}
614 
615 	return 0;
616 
617 mfd_err:
618 	free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040);
619 irq_err:
620 	twl6040_irq_exit(twl6040);
621 gpio2_err:
622 	if (gpio_is_valid(twl6040->audpwron))
623 		gpio_free(twl6040->audpwron);
624 gpio1_err:
625 	i2c_set_clientdata(client, NULL);
626 	regmap_exit(twl6040->regmap);
627 err:
628 	return ret;
629 }
630 
twl6040_remove(struct i2c_client * client)631 static int __devexit twl6040_remove(struct i2c_client *client)
632 {
633 	struct twl6040 *twl6040 = i2c_get_clientdata(client);
634 
635 	if (twl6040->power_count)
636 		twl6040_power(twl6040, 0);
637 
638 	if (gpio_is_valid(twl6040->audpwron))
639 		gpio_free(twl6040->audpwron);
640 
641 	free_irq(twl6040->irq_base + TWL6040_IRQ_READY, twl6040);
642 	twl6040_irq_exit(twl6040);
643 
644 	mfd_remove_devices(&client->dev);
645 	i2c_set_clientdata(client, NULL);
646 	regmap_exit(twl6040->regmap);
647 
648 	return 0;
649 }
650 
651 static const struct i2c_device_id twl6040_i2c_id[] = {
652 	{ "twl6040", 0, },
653 	{ },
654 };
655 MODULE_DEVICE_TABLE(i2c, twl6040_i2c_id);
656 
657 static struct i2c_driver twl6040_driver = {
658 	.driver = {
659 		.name = "twl6040",
660 		.owner = THIS_MODULE,
661 	},
662 	.probe		= twl6040_probe,
663 	.remove		= __devexit_p(twl6040_remove),
664 	.id_table	= twl6040_i2c_id,
665 };
666 
667 module_i2c_driver(twl6040_driver);
668 
669 MODULE_DESCRIPTION("TWL6040 MFD");
670 MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
671 MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>");
672 MODULE_LICENSE("GPL");
673 MODULE_ALIAS("platform:twl6040");
674