2 * MFD driver for TWL6040 audio device
4 * Authors: Misael Lopez Cruz <misael.lopez@ti.com>
5 * Jorge Eduardo Candelaria <jorge.candelaria@ti.com>
6 * Peter Ujfalusi <peter.ujfalusi@ti.com>
8 * Copyright: (C) 2011 Texas Instruments, Inc.
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.
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.
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
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/slab.h>
29 #include <linux/kernel.h>
30 #include <linux/err.h>
31 #include <linux/platform_device.h>
33 #include <linux/of_irq.h>
34 #include <linux/of_gpio.h>
35 #include <linux/of_platform.h>
36 #include <linux/gpio.h>
37 #include <linux/delay.h>
38 #include <linux/i2c.h>
39 #include <linux/regmap.h>
40 #include <linux/mfd/core.h>
41 #include <linux/mfd/twl6040.h>
42 #include <linux/regulator/consumer.h>
44 #define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
45 #define TWL6040_NUM_SUPPLIES (2)
47 static const struct reg_default twl6040_defaults
[] = {
48 { 0x01, 0x4B }, /* REG_ASICID (ro) */
49 { 0x02, 0x00 }, /* REG_ASICREV (ro) */
50 { 0x03, 0x00 }, /* REG_INTID */
51 { 0x04, 0x00 }, /* REG_INTMR */
52 { 0x05, 0x00 }, /* REG_NCPCTRL */
53 { 0x06, 0x00 }, /* REG_LDOCTL */
54 { 0x07, 0x60 }, /* REG_HPPLLCTL */
55 { 0x08, 0x00 }, /* REG_LPPLLCTL */
56 { 0x09, 0x4A }, /* REG_LPPLLDIV */
57 { 0x0A, 0x00 }, /* REG_AMICBCTL */
58 { 0x0B, 0x00 }, /* REG_DMICBCTL */
59 { 0x0C, 0x00 }, /* REG_MICLCTL */
60 { 0x0D, 0x00 }, /* REG_MICRCTL */
61 { 0x0E, 0x00 }, /* REG_MICGAIN */
62 { 0x0F, 0x1B }, /* REG_LINEGAIN */
63 { 0x10, 0x00 }, /* REG_HSLCTL */
64 { 0x11, 0x00 }, /* REG_HSRCTL */
65 { 0x12, 0x00 }, /* REG_HSGAIN */
66 { 0x13, 0x00 }, /* REG_EARCTL */
67 { 0x14, 0x00 }, /* REG_HFLCTL */
68 { 0x15, 0x00 }, /* REG_HFLGAIN */
69 { 0x16, 0x00 }, /* REG_HFRCTL */
70 { 0x17, 0x00 }, /* REG_HFRGAIN */
71 { 0x18, 0x00 }, /* REG_VIBCTLL */
72 { 0x19, 0x00 }, /* REG_VIBDATL */
73 { 0x1A, 0x00 }, /* REG_VIBCTLR */
74 { 0x1B, 0x00 }, /* REG_VIBDATR */
75 { 0x1C, 0x00 }, /* REG_HKCTL1 */
76 { 0x1D, 0x00 }, /* REG_HKCTL2 */
77 { 0x1E, 0x00 }, /* REG_GPOCTL */
78 { 0x1F, 0x00 }, /* REG_ALB */
79 { 0x20, 0x00 }, /* REG_DLB */
83 /* 0x2B, REG_HSOTRIM */
84 /* 0x2C, REG_HFOTRIM */
85 { 0x2D, 0x08 }, /* REG_ACCCTL */
86 { 0x2E, 0x00 }, /* REG_STATUS (ro) */
89 static struct reg_sequence twl6040_patch
[] = {
91 * Select I2C bus access to dual access registers
92 * Interrupt register is cleared on read
93 * Select fast mode for i2c (400KHz)
96 TWL6040_I2CSEL
| TWL6040_INTCLRMODE
| TWL6040_I2CMODE(1) },
100 static bool twl6040_has_vibra(struct device_node
*node
)
103 if (of_find_node_by_name(node
, "vibra"))
109 int twl6040_reg_read(struct twl6040
*twl6040
, unsigned int reg
)
114 ret
= regmap_read(twl6040
->regmap
, reg
, &val
);
120 EXPORT_SYMBOL(twl6040_reg_read
);
122 int twl6040_reg_write(struct twl6040
*twl6040
, unsigned int reg
, u8 val
)
126 ret
= regmap_write(twl6040
->regmap
, reg
, val
);
130 EXPORT_SYMBOL(twl6040_reg_write
);
132 int twl6040_set_bits(struct twl6040
*twl6040
, unsigned int reg
, u8 mask
)
134 return regmap_update_bits(twl6040
->regmap
, reg
, mask
, mask
);
136 EXPORT_SYMBOL(twl6040_set_bits
);
138 int twl6040_clear_bits(struct twl6040
*twl6040
, unsigned int reg
, u8 mask
)
140 return regmap_update_bits(twl6040
->regmap
, reg
, mask
, 0);
142 EXPORT_SYMBOL(twl6040_clear_bits
);
144 /* twl6040 codec manual power-up sequence */
145 static int twl6040_power_up_manual(struct twl6040
*twl6040
)
147 u8 ldoctl
, ncpctl
, lppllctl
;
150 /* enable high-side LDO, reference system and internal oscillator */
151 ldoctl
= TWL6040_HSLDOENA
| TWL6040_REFENA
| TWL6040_OSCENA
;
152 ret
= twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
155 usleep_range(10000, 10500);
157 /* enable negative charge pump */
158 ncpctl
= TWL6040_NCPENA
;
159 ret
= twl6040_reg_write(twl6040
, TWL6040_REG_NCPCTL
, ncpctl
);
162 usleep_range(1000, 1500);
164 /* enable low-side LDO */
165 ldoctl
|= TWL6040_LSLDOENA
;
166 ret
= twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
169 usleep_range(1000, 1500);
171 /* enable low-power PLL */
172 lppllctl
= TWL6040_LPLLENA
;
173 ret
= twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
, lppllctl
);
176 usleep_range(5000, 5500);
178 /* disable internal oscillator */
179 ldoctl
&= ~TWL6040_OSCENA
;
180 ret
= twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
187 lppllctl
&= ~TWL6040_LPLLENA
;
188 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
, lppllctl
);
190 ldoctl
&= ~TWL6040_LSLDOENA
;
191 twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
193 ncpctl
&= ~TWL6040_NCPENA
;
194 twl6040_reg_write(twl6040
, TWL6040_REG_NCPCTL
, ncpctl
);
196 ldoctl
&= ~(TWL6040_HSLDOENA
| TWL6040_REFENA
| TWL6040_OSCENA
);
197 twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
199 dev_err(twl6040
->dev
, "manual power-up failed\n");
203 /* twl6040 manual power-down sequence */
204 static void twl6040_power_down_manual(struct twl6040
*twl6040
)
206 u8 ncpctl
, ldoctl
, lppllctl
;
208 ncpctl
= twl6040_reg_read(twl6040
, TWL6040_REG_NCPCTL
);
209 ldoctl
= twl6040_reg_read(twl6040
, TWL6040_REG_LDOCTL
);
210 lppllctl
= twl6040_reg_read(twl6040
, TWL6040_REG_LPPLLCTL
);
212 /* enable internal oscillator */
213 ldoctl
|= TWL6040_OSCENA
;
214 twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
215 usleep_range(1000, 1500);
217 /* disable low-power PLL */
218 lppllctl
&= ~TWL6040_LPLLENA
;
219 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
, lppllctl
);
221 /* disable low-side LDO */
222 ldoctl
&= ~TWL6040_LSLDOENA
;
223 twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
225 /* disable negative charge pump */
226 ncpctl
&= ~TWL6040_NCPENA
;
227 twl6040_reg_write(twl6040
, TWL6040_REG_NCPCTL
, ncpctl
);
229 /* disable high-side LDO, reference system and internal oscillator */
230 ldoctl
&= ~(TWL6040_HSLDOENA
| TWL6040_REFENA
| TWL6040_OSCENA
);
231 twl6040_reg_write(twl6040
, TWL6040_REG_LDOCTL
, ldoctl
);
234 static irqreturn_t
twl6040_readyint_handler(int irq
, void *data
)
236 struct twl6040
*twl6040
= data
;
238 complete(&twl6040
->ready
);
243 static irqreturn_t
twl6040_thint_handler(int irq
, void *data
)
245 struct twl6040
*twl6040
= data
;
248 status
= twl6040_reg_read(twl6040
, TWL6040_REG_STATUS
);
249 if (status
& TWL6040_TSHUTDET
) {
250 dev_warn(twl6040
->dev
, "Thermal shutdown, powering-off");
251 twl6040_power(twl6040
, 0);
253 dev_warn(twl6040
->dev
, "Leaving thermal shutdown, powering-on");
254 twl6040_power(twl6040
, 1);
260 static int twl6040_power_up_automatic(struct twl6040
*twl6040
)
264 gpio_set_value(twl6040
->audpwron
, 1);
266 time_left
= wait_for_completion_timeout(&twl6040
->ready
,
267 msecs_to_jiffies(144));
271 dev_warn(twl6040
->dev
, "timeout waiting for READYINT\n");
272 intid
= twl6040_reg_read(twl6040
, TWL6040_REG_INTID
);
273 if (!(intid
& TWL6040_READYINT
)) {
274 dev_err(twl6040
->dev
, "automatic power-up failed\n");
275 gpio_set_value(twl6040
->audpwron
, 0);
283 int twl6040_power(struct twl6040
*twl6040
, int on
)
287 mutex_lock(&twl6040
->mutex
);
290 /* already powered-up */
291 if (twl6040
->power_count
++)
294 ret
= clk_prepare_enable(twl6040
->clk32k
);
296 twl6040
->power_count
= 0;
300 /* Allow writes to the chip */
301 regcache_cache_only(twl6040
->regmap
, false);
303 if (gpio_is_valid(twl6040
->audpwron
)) {
304 /* use automatic power-up sequence */
305 ret
= twl6040_power_up_automatic(twl6040
);
307 clk_disable_unprepare(twl6040
->clk32k
);
308 twl6040
->power_count
= 0;
312 /* use manual power-up sequence */
313 ret
= twl6040_power_up_manual(twl6040
);
315 clk_disable_unprepare(twl6040
->clk32k
);
316 twl6040
->power_count
= 0;
321 /* Sync with the HW */
322 regcache_sync(twl6040
->regmap
);
324 /* Default PLL configuration after power up */
325 twl6040
->pll
= TWL6040_SYSCLK_SEL_LPPLL
;
326 twl6040
->sysclk_rate
= 19200000;
328 /* already powered-down */
329 if (!twl6040
->power_count
) {
330 dev_err(twl6040
->dev
,
331 "device is already powered-off\n");
336 if (--twl6040
->power_count
)
339 if (gpio_is_valid(twl6040
->audpwron
)) {
340 /* use AUDPWRON line */
341 gpio_set_value(twl6040
->audpwron
, 0);
343 /* power-down sequence latency */
344 usleep_range(500, 700);
346 /* use manual power-down sequence */
347 twl6040_power_down_manual(twl6040
);
350 /* Set regmap to cache only and mark it as dirty */
351 regcache_cache_only(twl6040
->regmap
, true);
352 regcache_mark_dirty(twl6040
->regmap
);
354 twl6040
->sysclk_rate
= 0;
356 if (twl6040
->pll
== TWL6040_SYSCLK_SEL_HPPLL
) {
357 clk_disable_unprepare(twl6040
->mclk
);
358 twl6040
->mclk_rate
= 0;
361 clk_disable_unprepare(twl6040
->clk32k
);
365 mutex_unlock(&twl6040
->mutex
);
368 EXPORT_SYMBOL(twl6040_power
);
370 int twl6040_set_pll(struct twl6040
*twl6040
, int pll_id
,
371 unsigned int freq_in
, unsigned int freq_out
)
373 u8 hppllctl
, lppllctl
;
376 mutex_lock(&twl6040
->mutex
);
378 hppllctl
= twl6040_reg_read(twl6040
, TWL6040_REG_HPPLLCTL
);
379 lppllctl
= twl6040_reg_read(twl6040
, TWL6040_REG_LPPLLCTL
);
381 /* Force full reconfiguration when switching between PLL */
382 if (pll_id
!= twl6040
->pll
) {
383 twl6040
->sysclk_rate
= 0;
384 twl6040
->mclk_rate
= 0;
388 case TWL6040_SYSCLK_SEL_LPPLL
:
389 /* low-power PLL divider */
390 /* Change the sysclk configuration only if it has been canged */
391 if (twl6040
->sysclk_rate
!= freq_out
) {
394 lppllctl
|= TWL6040_LPLLFIN
;
397 lppllctl
&= ~TWL6040_LPLLFIN
;
400 dev_err(twl6040
->dev
,
401 "freq_out %d not supported\n",
406 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
,
410 /* The PLL in use has not been change, we can exit */
411 if (twl6040
->pll
== pll_id
)
416 lppllctl
|= TWL6040_LPLLENA
;
417 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
,
420 lppllctl
&= ~TWL6040_HPLLSEL
;
421 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
,
423 hppllctl
&= ~TWL6040_HPLLENA
;
424 twl6040_reg_write(twl6040
, TWL6040_REG_HPPLLCTL
,
428 dev_err(twl6040
->dev
,
429 "freq_in %d not supported\n", freq_in
);
434 clk_disable_unprepare(twl6040
->mclk
);
436 case TWL6040_SYSCLK_SEL_HPPLL
:
437 /* high-performance PLL can provide only 19.2 MHz */
438 if (freq_out
!= 19200000) {
439 dev_err(twl6040
->dev
,
440 "freq_out %d not supported\n", freq_out
);
445 if (twl6040
->mclk_rate
!= freq_in
) {
446 hppllctl
&= ~TWL6040_MCLK_MSK
;
450 /* PLL enabled, active mode */
451 hppllctl
|= TWL6040_MCLK_12000KHZ
|
455 /* PLL enabled, bypass mode */
456 hppllctl
|= TWL6040_MCLK_19200KHZ
|
457 TWL6040_HPLLBP
| TWL6040_HPLLENA
;
460 /* PLL enabled, active mode */
461 hppllctl
|= TWL6040_MCLK_26000KHZ
|
465 /* PLL enabled, bypass mode */
466 hppllctl
|= TWL6040_MCLK_38400KHZ
|
467 TWL6040_HPLLBP
| TWL6040_HPLLENA
;
470 dev_err(twl6040
->dev
,
471 "freq_in %d not supported\n", freq_in
);
476 /* When switching to HPPLL, enable the mclk first */
477 if (pll_id
!= twl6040
->pll
)
478 clk_prepare_enable(twl6040
->mclk
);
480 * enable clock slicer to ensure input waveform is
483 hppllctl
|= TWL6040_HPLLSQRENA
;
485 twl6040_reg_write(twl6040
, TWL6040_REG_HPPLLCTL
,
487 usleep_range(500, 700);
488 lppllctl
|= TWL6040_HPLLSEL
;
489 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
,
491 lppllctl
&= ~TWL6040_LPLLENA
;
492 twl6040_reg_write(twl6040
, TWL6040_REG_LPPLLCTL
,
495 twl6040
->mclk_rate
= freq_in
;
499 dev_err(twl6040
->dev
, "unknown pll id %d\n", pll_id
);
504 twl6040
->sysclk_rate
= freq_out
;
505 twl6040
->pll
= pll_id
;
508 mutex_unlock(&twl6040
->mutex
);
511 EXPORT_SYMBOL(twl6040_set_pll
);
513 int twl6040_get_pll(struct twl6040
*twl6040
)
515 if (twl6040
->power_count
)
520 EXPORT_SYMBOL(twl6040_get_pll
);
522 unsigned int twl6040_get_sysclk(struct twl6040
*twl6040
)
524 return twl6040
->sysclk_rate
;
526 EXPORT_SYMBOL(twl6040_get_sysclk
);
528 /* Get the combined status of the vibra control register */
529 int twl6040_get_vibralr_status(struct twl6040
*twl6040
)
535 ret
= regmap_read(twl6040
->regmap
, TWL6040_REG_VIBCTLL
, ®
);
540 ret
= regmap_read(twl6040
->regmap
, TWL6040_REG_VIBCTLR
, ®
);
545 status
&= (TWL6040_VIBENA
| TWL6040_VIBSEL
);
549 EXPORT_SYMBOL(twl6040_get_vibralr_status
);
551 static struct resource twl6040_vibra_rsrc
[] = {
553 .flags
= IORESOURCE_IRQ
,
557 static struct resource twl6040_codec_rsrc
[] = {
559 .flags
= IORESOURCE_IRQ
,
563 static bool twl6040_readable_reg(struct device
*dev
, unsigned int reg
)
565 /* Register 0 is not readable */
571 static bool twl6040_volatile_reg(struct device
*dev
, unsigned int reg
)
574 case TWL6040_REG_ASICID
:
575 case TWL6040_REG_ASICREV
:
576 case TWL6040_REG_INTID
:
577 case TWL6040_REG_LPPLLCTL
:
578 case TWL6040_REG_HPPLLCTL
:
579 case TWL6040_REG_STATUS
:
586 static bool twl6040_writeable_reg(struct device
*dev
, unsigned int reg
)
589 case TWL6040_REG_ASICID
:
590 case TWL6040_REG_ASICREV
:
591 case TWL6040_REG_STATUS
:
598 static const struct regmap_config twl6040_regmap_config
= {
602 .reg_defaults
= twl6040_defaults
,
603 .num_reg_defaults
= ARRAY_SIZE(twl6040_defaults
),
605 .max_register
= TWL6040_REG_STATUS
, /* 0x2e */
607 .readable_reg
= twl6040_readable_reg
,
608 .volatile_reg
= twl6040_volatile_reg
,
609 .writeable_reg
= twl6040_writeable_reg
,
611 .cache_type
= REGCACHE_RBTREE
,
612 .use_single_rw
= true,
615 static const struct regmap_irq twl6040_irqs
[] = {
616 { .reg_offset
= 0, .mask
= TWL6040_THINT
, },
617 { .reg_offset
= 0, .mask
= TWL6040_PLUGINT
| TWL6040_UNPLUGINT
, },
618 { .reg_offset
= 0, .mask
= TWL6040_HOOKINT
, },
619 { .reg_offset
= 0, .mask
= TWL6040_HFINT
, },
620 { .reg_offset
= 0, .mask
= TWL6040_VIBINT
, },
621 { .reg_offset
= 0, .mask
= TWL6040_READYINT
, },
624 static struct regmap_irq_chip twl6040_irq_chip
= {
626 .irqs
= twl6040_irqs
,
627 .num_irqs
= ARRAY_SIZE(twl6040_irqs
),
630 .status_base
= TWL6040_REG_INTID
,
631 .mask_base
= TWL6040_REG_INTMR
,
634 static int twl6040_probe(struct i2c_client
*client
,
635 const struct i2c_device_id
*id
)
637 struct device_node
*node
= client
->dev
.of_node
;
638 struct twl6040
*twl6040
;
639 struct mfd_cell
*cell
= NULL
;
640 int irq
, ret
, children
= 0;
643 dev_err(&client
->dev
, "of node is missing\n");
647 /* In order to operate correctly we need valid interrupt config */
649 dev_err(&client
->dev
, "Invalid IRQ configuration\n");
653 twl6040
= devm_kzalloc(&client
->dev
, sizeof(struct twl6040
),
658 twl6040
->regmap
= devm_regmap_init_i2c(client
, &twl6040_regmap_config
);
659 if (IS_ERR(twl6040
->regmap
))
660 return PTR_ERR(twl6040
->regmap
);
662 i2c_set_clientdata(client
, twl6040
);
664 twl6040
->clk32k
= devm_clk_get(&client
->dev
, "clk32k");
665 if (IS_ERR(twl6040
->clk32k
)) {
666 if (PTR_ERR(twl6040
->clk32k
) == -EPROBE_DEFER
)
667 return -EPROBE_DEFER
;
668 dev_dbg(&client
->dev
, "clk32k is not handled\n");
669 twl6040
->clk32k
= NULL
;
672 twl6040
->mclk
= devm_clk_get(&client
->dev
, "mclk");
673 if (IS_ERR(twl6040
->mclk
)) {
674 if (PTR_ERR(twl6040
->mclk
) == -EPROBE_DEFER
)
675 return -EPROBE_DEFER
;
676 dev_dbg(&client
->dev
, "mclk is not handled\n");
677 twl6040
->mclk
= NULL
;
680 twl6040
->supplies
[0].supply
= "vio";
681 twl6040
->supplies
[1].supply
= "v2v1";
682 ret
= devm_regulator_bulk_get(&client
->dev
, TWL6040_NUM_SUPPLIES
,
685 dev_err(&client
->dev
, "Failed to get supplies: %d\n", ret
);
689 ret
= regulator_bulk_enable(TWL6040_NUM_SUPPLIES
, twl6040
->supplies
);
691 dev_err(&client
->dev
, "Failed to enable supplies: %d\n", ret
);
695 twl6040
->dev
= &client
->dev
;
696 twl6040
->irq
= client
->irq
;
698 mutex_init(&twl6040
->mutex
);
699 init_completion(&twl6040
->ready
);
701 regmap_register_patch(twl6040
->regmap
, twl6040_patch
,
702 ARRAY_SIZE(twl6040_patch
));
704 twl6040
->rev
= twl6040_reg_read(twl6040
, TWL6040_REG_ASICREV
);
705 if (twl6040
->rev
< 0) {
706 dev_err(&client
->dev
, "Failed to read revision register: %d\n",
712 /* ERRATA: Automatic power-up is not possible in ES1.0 */
713 if (twl6040_get_revid(twl6040
) > TWL6040_REV_ES1_0
)
714 twl6040
->audpwron
= of_get_named_gpio(node
,
715 "ti,audpwron-gpio", 0);
717 twl6040
->audpwron
= -EINVAL
;
719 if (gpio_is_valid(twl6040
->audpwron
)) {
720 ret
= devm_gpio_request_one(&client
->dev
, twl6040
->audpwron
,
721 GPIOF_OUT_INIT_LOW
, "audpwron");
725 /* Clear any pending interrupt */
726 twl6040_reg_read(twl6040
, TWL6040_REG_INTID
);
729 ret
= regmap_add_irq_chip(twl6040
->regmap
, twl6040
->irq
, IRQF_ONESHOT
,
730 0, &twl6040_irq_chip
, &twl6040
->irq_data
);
734 twl6040
->irq_ready
= regmap_irq_get_virq(twl6040
->irq_data
,
736 twl6040
->irq_th
= regmap_irq_get_virq(twl6040
->irq_data
,
739 ret
= devm_request_threaded_irq(twl6040
->dev
, twl6040
->irq_ready
, NULL
,
740 twl6040_readyint_handler
, IRQF_ONESHOT
,
741 "twl6040_irq_ready", twl6040
);
743 dev_err(twl6040
->dev
, "READY IRQ request failed: %d\n", ret
);
747 ret
= devm_request_threaded_irq(twl6040
->dev
, twl6040
->irq_th
, NULL
,
748 twl6040_thint_handler
, IRQF_ONESHOT
,
749 "twl6040_irq_th", twl6040
);
751 dev_err(twl6040
->dev
, "Thermal IRQ request failed: %d\n", ret
);
756 * The main functionality of twl6040 to provide audio on OMAP4+ systems.
757 * We can add the ASoC codec child whenever this driver has been loaded.
759 irq
= regmap_irq_get_virq(twl6040
->irq_data
, TWL6040_IRQ_PLUG
);
760 cell
= &twl6040
->cells
[children
];
761 cell
->name
= "twl6040-codec";
762 twl6040_codec_rsrc
[0].start
= irq
;
763 twl6040_codec_rsrc
[0].end
= irq
;
764 cell
->resources
= twl6040_codec_rsrc
;
765 cell
->num_resources
= ARRAY_SIZE(twl6040_codec_rsrc
);
768 /* Vibra input driver support */
769 if (twl6040_has_vibra(node
)) {
770 irq
= regmap_irq_get_virq(twl6040
->irq_data
, TWL6040_IRQ_VIB
);
772 cell
= &twl6040
->cells
[children
];
773 cell
->name
= "twl6040-vibra";
774 twl6040_vibra_rsrc
[0].start
= irq
;
775 twl6040_vibra_rsrc
[0].end
= irq
;
776 cell
->resources
= twl6040_vibra_rsrc
;
777 cell
->num_resources
= ARRAY_SIZE(twl6040_vibra_rsrc
);
782 cell
= &twl6040
->cells
[children
];
783 cell
->name
= "twl6040-gpo";
786 /* PDM clock support */
787 cell
= &twl6040
->cells
[children
];
788 cell
->name
= "twl6040-pdmclk";
791 /* The chip is powered down so mark regmap to cache only and dirty */
792 regcache_cache_only(twl6040
->regmap
, true);
793 regcache_mark_dirty(twl6040
->regmap
);
795 ret
= mfd_add_devices(&client
->dev
, -1, twl6040
->cells
, children
,
803 regmap_del_irq_chip(twl6040
->irq
, twl6040
->irq_data
);
805 regulator_bulk_disable(TWL6040_NUM_SUPPLIES
, twl6040
->supplies
);
809 static int twl6040_remove(struct i2c_client
*client
)
811 struct twl6040
*twl6040
= i2c_get_clientdata(client
);
813 if (twl6040
->power_count
)
814 twl6040_power(twl6040
, 0);
816 regmap_del_irq_chip(twl6040
->irq
, twl6040
->irq_data
);
818 mfd_remove_devices(&client
->dev
);
820 regulator_bulk_disable(TWL6040_NUM_SUPPLIES
, twl6040
->supplies
);
825 static const struct i2c_device_id twl6040_i2c_id
[] = {
830 MODULE_DEVICE_TABLE(i2c
, twl6040_i2c_id
);
832 static struct i2c_driver twl6040_driver
= {
836 .probe
= twl6040_probe
,
837 .remove
= twl6040_remove
,
838 .id_table
= twl6040_i2c_id
,
841 module_i2c_driver(twl6040_driver
);
843 MODULE_DESCRIPTION("TWL6040 MFD");
844 MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
845 MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>");
846 MODULE_LICENSE("GPL");