blob: b9c6d94b400206b8ae34830cfa9741ee95364d0c [file] [log] [blame]
Thomas Gleixner2b27bdc2019-05-29 16:57:50 -07001// SPDX-License-Identifier: GPL-2.0-only
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -05002/*
3 * MFD driver for TWL6040 audio device
4 *
5 * Authors: Misael Lopez Cruz <misael.lopez@ti.com>
6 * Jorge Eduardo Candelaria <jorge.candelaria@ti.com>
7 * Peter Ujfalusi <peter.ujfalusi@ti.com>
8 *
9 * Copyright: (C) 2011 Texas Instruments, Inc.
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050010 */
11
12#include <linux/module.h>
13#include <linux/types.h>
14#include <linux/slab.h>
15#include <linux/kernel.h>
Peter Ujfalusi5af7df62012-05-02 16:54:42 +030016#include <linux/err.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050017#include <linux/platform_device.h>
Peter Ujfalusi37e13ce2012-05-16 14:11:58 +030018#include <linux/of.h>
19#include <linux/of_irq.h>
20#include <linux/of_gpio.h>
21#include <linux/of_platform.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050022#include <linux/gpio.h>
23#include <linux/delay.h>
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +030024#include <linux/i2c.h>
25#include <linux/regmap.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050026#include <linux/mfd/core.h>
27#include <linux/mfd/twl6040.h>
Peter Ujfalusi5af7df62012-05-02 16:54:42 +030028#include <linux/regulator/consumer.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050029
Peter Ujfalusi31b402e2011-10-12 11:57:54 +030030#define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
Peter Ujfalusi5af7df62012-05-02 16:54:42 +030031#define TWL6040_NUM_SUPPLIES (2)
Peter Ujfalusi31b402e2011-10-12 11:57:54 +030032
Krzysztof Kozlowskide1e23f2015-01-05 10:01:33 +010033static const struct reg_default twl6040_defaults[] = {
Peter Ujfalusic7f91292013-11-29 16:03:45 +020034 { 0x01, 0x4B }, /* REG_ASICID (ro) */
35 { 0x02, 0x00 }, /* REG_ASICREV (ro) */
36 { 0x03, 0x00 }, /* REG_INTID */
37 { 0x04, 0x00 }, /* REG_INTMR */
38 { 0x05, 0x00 }, /* REG_NCPCTRL */
39 { 0x06, 0x00 }, /* REG_LDOCTL */
40 { 0x07, 0x60 }, /* REG_HPPLLCTL */
41 { 0x08, 0x00 }, /* REG_LPPLLCTL */
42 { 0x09, 0x4A }, /* REG_LPPLLDIV */
43 { 0x0A, 0x00 }, /* REG_AMICBCTL */
44 { 0x0B, 0x00 }, /* REG_DMICBCTL */
45 { 0x0C, 0x00 }, /* REG_MICLCTL */
46 { 0x0D, 0x00 }, /* REG_MICRCTL */
47 { 0x0E, 0x00 }, /* REG_MICGAIN */
48 { 0x0F, 0x1B }, /* REG_LINEGAIN */
49 { 0x10, 0x00 }, /* REG_HSLCTL */
50 { 0x11, 0x00 }, /* REG_HSRCTL */
51 { 0x12, 0x00 }, /* REG_HSGAIN */
52 { 0x13, 0x00 }, /* REG_EARCTL */
53 { 0x14, 0x00 }, /* REG_HFLCTL */
54 { 0x15, 0x00 }, /* REG_HFLGAIN */
55 { 0x16, 0x00 }, /* REG_HFRCTL */
56 { 0x17, 0x00 }, /* REG_HFRGAIN */
57 { 0x18, 0x00 }, /* REG_VIBCTLL */
58 { 0x19, 0x00 }, /* REG_VIBDATL */
59 { 0x1A, 0x00 }, /* REG_VIBCTLR */
60 { 0x1B, 0x00 }, /* REG_VIBDATR */
61 { 0x1C, 0x00 }, /* REG_HKCTL1 */
62 { 0x1D, 0x00 }, /* REG_HKCTL2 */
63 { 0x1E, 0x00 }, /* REG_GPOCTL */
64 { 0x1F, 0x00 }, /* REG_ALB */
65 { 0x20, 0x00 }, /* REG_DLB */
66 /* 0x28, REG_TRIM1 */
67 /* 0x29, REG_TRIM2 */
68 /* 0x2A, REG_TRIM3 */
69 /* 0x2B, REG_HSOTRIM */
70 /* 0x2C, REG_HFOTRIM */
71 { 0x2D, 0x08 }, /* REG_ACCCTL */
72 { 0x2E, 0x00 }, /* REG_STATUS (ro) */
73};
74
Nariman Poushin8019ff62015-07-16 16:36:21 +010075static struct reg_sequence twl6040_patch[] = {
Peter Ujfalusi11e38e12014-04-01 16:44:59 +030076 /*
77 * Select I2C bus access to dual access registers
78 * Interrupt register is cleared on read
79 * Select fast mode for i2c (400KHz)
80 */
81 { TWL6040_REG_ACCCTL,
82 TWL6040_I2CSEL | TWL6040_INTCLRMODE | TWL6040_I2CMODE(1) },
Peter Ujfalusic7f91292013-11-29 16:03:45 +020083};
84
85
Johan Hovold85e9b132017-11-11 16:38:44 +010086static bool twl6040_has_vibra(struct device_node *parent)
Samuel Ortizca2cad62012-05-23 16:23:21 +020087{
Johan Hovold85e9b132017-11-11 16:38:44 +010088 struct device_node *node;
89
90 node = of_get_child_by_name(parent, "vibra");
91 if (node) {
92 of_node_put(node);
Samuel Ortizca2cad62012-05-23 16:23:21 +020093 return true;
Johan Hovold85e9b132017-11-11 16:38:44 +010094 }
95
Samuel Ortizca2cad62012-05-23 16:23:21 +020096 return false;
97}
98
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050099int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
100{
101 int ret;
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300102 unsigned int val;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500103
Mark Brownc6f39252013-08-31 17:48:19 +0100104 ret = regmap_read(twl6040->regmap, reg, &val);
105 if (ret < 0)
106 return ret;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500107
108 return val;
109}
110EXPORT_SYMBOL(twl6040_reg_read);
111
112int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
113{
114 int ret;
115
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300116 ret = regmap_write(twl6040->regmap, reg, val);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500117
118 return ret;
119}
120EXPORT_SYMBOL(twl6040_reg_write);
121
122int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
123{
Axel Linc6000402012-07-11 10:06:34 +0800124 return regmap_update_bits(twl6040->regmap, reg, mask, mask);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500125}
126EXPORT_SYMBOL(twl6040_set_bits);
127
128int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
129{
Axel Linc6000402012-07-11 10:06:34 +0800130 return regmap_update_bits(twl6040->regmap, reg, mask, 0);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500131}
132EXPORT_SYMBOL(twl6040_clear_bits);
133
134/* twl6040 codec manual power-up sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200135static int twl6040_power_up_manual(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500136{
137 u8 ldoctl, ncpctl, lppllctl;
138 int ret;
139
140 /* enable high-side LDO, reference system and internal oscillator */
141 ldoctl = TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA;
142 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
143 if (ret)
144 return ret;
145 usleep_range(10000, 10500);
146
147 /* enable negative charge pump */
148 ncpctl = TWL6040_NCPENA;
149 ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
150 if (ret)
151 goto ncp_err;
152 usleep_range(1000, 1500);
153
154 /* enable low-side LDO */
155 ldoctl |= TWL6040_LSLDOENA;
156 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
157 if (ret)
158 goto lsldo_err;
159 usleep_range(1000, 1500);
160
161 /* enable low-power PLL */
162 lppllctl = TWL6040_LPLLENA;
163 ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
164 if (ret)
165 goto lppll_err;
166 usleep_range(5000, 5500);
167
168 /* disable internal oscillator */
169 ldoctl &= ~TWL6040_OSCENA;
170 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
171 if (ret)
172 goto osc_err;
173
174 return 0;
175
176osc_err:
177 lppllctl &= ~TWL6040_LPLLENA;
178 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
179lppll_err:
180 ldoctl &= ~TWL6040_LSLDOENA;
181 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
182lsldo_err:
183 ncpctl &= ~TWL6040_NCPENA;
184 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
185ncp_err:
186 ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
187 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
188
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200189 dev_err(twl6040->dev, "manual power-up failed\n");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500190 return ret;
191}
192
193/* twl6040 manual power-down sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200194static void twl6040_power_down_manual(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500195{
196 u8 ncpctl, ldoctl, lppllctl;
197
198 ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL);
199 ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL);
200 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
201
202 /* enable internal oscillator */
203 ldoctl |= TWL6040_OSCENA;
204 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
205 usleep_range(1000, 1500);
206
207 /* disable low-power PLL */
208 lppllctl &= ~TWL6040_LPLLENA;
209 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
210
211 /* disable low-side LDO */
212 ldoctl &= ~TWL6040_LSLDOENA;
213 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
214
215 /* disable negative charge pump */
216 ncpctl &= ~TWL6040_NCPENA;
217 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
218
219 /* disable high-side LDO, reference system and internal oscillator */
220 ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
221 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
222}
223
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200224static irqreturn_t twl6040_readyint_handler(int irq, void *data)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500225{
226 struct twl6040 *twl6040 = data;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500227
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200228 complete(&twl6040->ready);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500229
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200230 return IRQ_HANDLED;
231}
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500232
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200233static irqreturn_t twl6040_thint_handler(int irq, void *data)
234{
235 struct twl6040 *twl6040 = data;
236 u8 status;
237
238 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
239 if (status & TWL6040_TSHUTDET) {
240 dev_warn(twl6040->dev, "Thermal shutdown, powering-off");
241 twl6040_power(twl6040, 0);
242 } else {
243 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on");
244 twl6040_power(twl6040, 1);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500245 }
246
247 return IRQ_HANDLED;
248}
249
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200250static int twl6040_power_up_automatic(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500251{
252 int time_left;
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200253
254 gpio_set_value(twl6040->audpwron, 1);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500255
256 time_left = wait_for_completion_timeout(&twl6040->ready,
257 msecs_to_jiffies(144));
258 if (!time_left) {
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200259 u8 intid;
260
261 dev_warn(twl6040->dev, "timeout waiting for READYINT\n");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500262 intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
263 if (!(intid & TWL6040_READYINT)) {
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200264 dev_err(twl6040->dev, "automatic power-up failed\n");
265 gpio_set_value(twl6040->audpwron, 0);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500266 return -ETIMEDOUT;
267 }
268 }
269
270 return 0;
271}
272
273int twl6040_power(struct twl6040 *twl6040, int on)
274{
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500275 int ret = 0;
276
277 mutex_lock(&twl6040->mutex);
278
279 if (on) {
280 /* already powered-up */
281 if (twl6040->power_count++)
282 goto out;
283
Javier Martinez Canillas32852bc2016-04-20 11:16:38 -0400284 ret = clk_prepare_enable(twl6040->clk32k);
285 if (ret) {
286 twl6040->power_count = 0;
287 goto out;
288 }
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300289
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200290 /* Allow writes to the chip */
291 regcache_cache_only(twl6040->regmap, false);
292
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200293 if (gpio_is_valid(twl6040->audpwron)) {
294 /* use automatic power-up sequence */
295 ret = twl6040_power_up_automatic(twl6040);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500296 if (ret) {
Javier Martinez Canillasd6441dc2016-04-20 11:16:37 -0400297 clk_disable_unprepare(twl6040->clk32k);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500298 twl6040->power_count = 0;
299 goto out;
300 }
301 } else {
302 /* use manual power-up sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200303 ret = twl6040_power_up_manual(twl6040);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500304 if (ret) {
Javier Martinez Canillasd6441dc2016-04-20 11:16:37 -0400305 clk_disable_unprepare(twl6040->clk32k);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500306 twl6040->power_count = 0;
307 goto out;
308 }
309 }
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200310
Tony Lindgren48171d02019-02-14 08:03:45 -0800311 /*
312 * Register access can produce errors after power-up unless we
313 * wait at least 8ms based on measurements on duovero.
314 */
315 usleep_range(10000, 12000);
316
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200317 /* Sync with the HW */
Tony Lindgren48171d02019-02-14 08:03:45 -0800318 ret = regcache_sync(twl6040->regmap);
319 if (ret) {
320 dev_err(twl6040->dev, "Failed to sync with the HW: %i\n",
321 ret);
322 goto out;
323 }
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200324
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300325 /* Default PLL configuration after power up */
326 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL;
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300327 twl6040->sysclk_rate = 19200000;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500328 } else {
329 /* already powered-down */
330 if (!twl6040->power_count) {
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300331 dev_err(twl6040->dev,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500332 "device is already powered-off\n");
333 ret = -EPERM;
334 goto out;
335 }
336
337 if (--twl6040->power_count)
338 goto out;
339
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200340 if (gpio_is_valid(twl6040->audpwron)) {
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500341 /* use AUDPWRON line */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200342 gpio_set_value(twl6040->audpwron, 0);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500343
344 /* power-down sequence latency */
345 usleep_range(500, 700);
346 } else {
347 /* use manual power-down sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200348 twl6040_power_down_manual(twl6040);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500349 }
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200350
351 /* Set regmap to cache only and mark it as dirty */
352 regcache_cache_only(twl6040->regmap, true);
353 regcache_mark_dirty(twl6040->regmap);
354
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300355 twl6040->sysclk_rate = 0;
356
357 if (twl6040->pll == TWL6040_SYSCLK_SEL_HPPLL) {
358 clk_disable_unprepare(twl6040->mclk);
359 twl6040->mclk_rate = 0;
360 }
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300361
362 clk_disable_unprepare(twl6040->clk32k);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500363 }
364
365out:
366 mutex_unlock(&twl6040->mutex);
367 return ret;
368}
369EXPORT_SYMBOL(twl6040_power);
370
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300371int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500372 unsigned int freq_in, unsigned int freq_out)
373{
374 u8 hppllctl, lppllctl;
375 int ret = 0;
376
377 mutex_lock(&twl6040->mutex);
378
379 hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL);
380 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
381
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100382 /* Force full reconfiguration when switching between PLL */
383 if (pll_id != twl6040->pll) {
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300384 twl6040->sysclk_rate = 0;
385 twl6040->mclk_rate = 0;
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100386 }
387
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300388 switch (pll_id) {
389 case TWL6040_SYSCLK_SEL_LPPLL:
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500390 /* low-power PLL divider */
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100391 /* Change the sysclk configuration only if it has been canged */
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300392 if (twl6040->sysclk_rate != freq_out) {
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100393 switch (freq_out) {
394 case 17640000:
395 lppllctl |= TWL6040_LPLLFIN;
396 break;
397 case 19200000:
398 lppllctl &= ~TWL6040_LPLLFIN;
399 break;
400 default:
401 dev_err(twl6040->dev,
402 "freq_out %d not supported\n",
403 freq_out);
404 ret = -EINVAL;
405 goto pll_out;
406 }
407 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
408 lppllctl);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500409 }
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100410
411 /* The PLL in use has not been change, we can exit */
412 if (twl6040->pll == pll_id)
413 break;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500414
415 switch (freq_in) {
416 case 32768:
417 lppllctl |= TWL6040_LPLLENA;
418 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
419 lppllctl);
420 mdelay(5);
421 lppllctl &= ~TWL6040_HPLLSEL;
422 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
423 lppllctl);
424 hppllctl &= ~TWL6040_HPLLENA;
425 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
426 hppllctl);
427 break;
428 default:
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300429 dev_err(twl6040->dev,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500430 "freq_in %d not supported\n", freq_in);
431 ret = -EINVAL;
432 goto pll_out;
433 }
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300434
435 clk_disable_unprepare(twl6040->mclk);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500436 break;
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300437 case TWL6040_SYSCLK_SEL_HPPLL:
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500438 /* high-performance PLL can provide only 19.2 MHz */
439 if (freq_out != 19200000) {
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300440 dev_err(twl6040->dev,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500441 "freq_out %d not supported\n", freq_out);
442 ret = -EINVAL;
443 goto pll_out;
444 }
445
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300446 if (twl6040->mclk_rate != freq_in) {
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100447 hppllctl &= ~TWL6040_MCLK_MSK;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500448
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100449 switch (freq_in) {
450 case 12000000:
451 /* PLL enabled, active mode */
452 hppllctl |= TWL6040_MCLK_12000KHZ |
453 TWL6040_HPLLENA;
454 break;
455 case 19200000:
Peter Ujfalusiac8320c2014-05-06 11:46:10 +0300456 /* PLL enabled, bypass mode */
457 hppllctl |= TWL6040_MCLK_19200KHZ |
458 TWL6040_HPLLBP | TWL6040_HPLLENA;
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100459 break;
460 case 26000000:
461 /* PLL enabled, active mode */
462 hppllctl |= TWL6040_MCLK_26000KHZ |
463 TWL6040_HPLLENA;
464 break;
465 case 38400000:
Peter Ujfalusiac8320c2014-05-06 11:46:10 +0300466 /* PLL enabled, bypass mode */
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100467 hppllctl |= TWL6040_MCLK_38400KHZ |
Peter Ujfalusiac8320c2014-05-06 11:46:10 +0300468 TWL6040_HPLLBP | TWL6040_HPLLENA;
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100469 break;
470 default:
471 dev_err(twl6040->dev,
472 "freq_in %d not supported\n", freq_in);
473 ret = -EINVAL;
474 goto pll_out;
475 }
476
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300477 /* When switching to HPPLL, enable the mclk first */
478 if (pll_id != twl6040->pll)
479 clk_prepare_enable(twl6040->mclk);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500480 /*
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100481 * enable clock slicer to ensure input waveform is
482 * square
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500483 */
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100484 hppllctl |= TWL6040_HPLLSQRENA;
485
486 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
487 hppllctl);
488 usleep_range(500, 700);
489 lppllctl |= TWL6040_HPLLSEL;
490 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
491 lppllctl);
492 lppllctl &= ~TWL6040_LPLLENA;
493 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
494 lppllctl);
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300495
496 twl6040->mclk_rate = freq_in;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500497 }
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500498 break;
499 default:
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300500 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500501 ret = -EINVAL;
502 goto pll_out;
503 }
504
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300505 twl6040->sysclk_rate = freq_out;
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300506 twl6040->pll = pll_id;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500507
508pll_out:
509 mutex_unlock(&twl6040->mutex);
510 return ret;
511}
512EXPORT_SYMBOL(twl6040_set_pll);
513
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300514int twl6040_get_pll(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500515{
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300516 if (twl6040->power_count)
517 return twl6040->pll;
518 else
519 return -ENODEV;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500520}
521EXPORT_SYMBOL(twl6040_get_pll);
522
523unsigned int twl6040_get_sysclk(struct twl6040 *twl6040)
524{
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300525 return twl6040->sysclk_rate;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500526}
527EXPORT_SYMBOL(twl6040_get_sysclk);
528
Peter Ujfalusi70601ec2011-10-12 11:57:55 +0300529/* Get the combined status of the vibra control register */
530int twl6040_get_vibralr_status(struct twl6040 *twl6040)
531{
Mark Brownc6f39252013-08-31 17:48:19 +0100532 unsigned int reg;
533 int ret;
Peter Ujfalusi70601ec2011-10-12 11:57:55 +0300534 u8 status;
535
Mark Brownc6f39252013-08-31 17:48:19 +0100536 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, &reg);
537 if (ret != 0)
538 return ret;
539 status = reg;
540
541 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, &reg);
542 if (ret != 0)
543 return ret;
544 status |= reg;
545
Peter Ujfalusi70601ec2011-10-12 11:57:55 +0300546 status &= (TWL6040_VIBENA | TWL6040_VIBSEL);
547
548 return status;
549}
550EXPORT_SYMBOL(twl6040_get_vibralr_status);
551
Peter Ujfalusi0f962ae2011-07-05 11:40:33 +0300552static struct resource twl6040_vibra_rsrc[] = {
553 {
554 .flags = IORESOURCE_IRQ,
555 },
556};
557
558static struct resource twl6040_codec_rsrc[] = {
559 {
560 .flags = IORESOURCE_IRQ,
561 },
562};
563
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300564static bool twl6040_readable_reg(struct device *dev, unsigned int reg)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500565{
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300566 /* Register 0 is not readable */
567 if (!reg)
568 return false;
569 return true;
570}
571
Mark Brownc6f39252013-08-31 17:48:19 +0100572static bool twl6040_volatile_reg(struct device *dev, unsigned int reg)
573{
574 switch (reg) {
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200575 case TWL6040_REG_ASICID:
576 case TWL6040_REG_ASICREV:
577 case TWL6040_REG_INTID:
578 case TWL6040_REG_LPPLLCTL:
579 case TWL6040_REG_HPPLLCTL:
580 case TWL6040_REG_STATUS:
581 return true;
582 default:
583 return false;
584 }
585}
586
587static bool twl6040_writeable_reg(struct device *dev, unsigned int reg)
588{
589 switch (reg) {
590 case TWL6040_REG_ASICID:
591 case TWL6040_REG_ASICREV:
592 case TWL6040_REG_STATUS:
Mark Brownc6f39252013-08-31 17:48:19 +0100593 return false;
594 default:
595 return true;
596 }
597}
598
Krzysztof Kozlowskide1e23f2015-01-05 10:01:33 +0100599static const struct regmap_config twl6040_regmap_config = {
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300600 .reg_bits = 8,
601 .val_bits = 8,
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200602
603 .reg_defaults = twl6040_defaults,
604 .num_reg_defaults = ARRAY_SIZE(twl6040_defaults),
605
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300606 .max_register = TWL6040_REG_STATUS, /* 0x2e */
607
608 .readable_reg = twl6040_readable_reg,
Mark Brownc6f39252013-08-31 17:48:19 +0100609 .volatile_reg = twl6040_volatile_reg,
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200610 .writeable_reg = twl6040_writeable_reg,
Mark Brownc6f39252013-08-31 17:48:19 +0100611
612 .cache_type = REGCACHE_RBTREE,
David Frey1c96a2f2018-09-01 09:50:41 -0700613 .use_single_read = true,
614 .use_single_write = true,
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300615};
616
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200617static const struct regmap_irq twl6040_irqs[] = {
618 { .reg_offset = 0, .mask = TWL6040_THINT, },
619 { .reg_offset = 0, .mask = TWL6040_PLUGINT | TWL6040_UNPLUGINT, },
620 { .reg_offset = 0, .mask = TWL6040_HOOKINT, },
621 { .reg_offset = 0, .mask = TWL6040_HFINT, },
622 { .reg_offset = 0, .mask = TWL6040_VIBINT, },
623 { .reg_offset = 0, .mask = TWL6040_READYINT, },
624};
625
626static struct regmap_irq_chip twl6040_irq_chip = {
627 .name = "twl6040",
628 .irqs = twl6040_irqs,
629 .num_irqs = ARRAY_SIZE(twl6040_irqs),
630
631 .num_regs = 1,
632 .status_base = TWL6040_REG_INTID,
633 .mask_base = TWL6040_REG_INTMR,
634};
635
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800636static int twl6040_probe(struct i2c_client *client,
637 const struct i2c_device_id *id)
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300638{
Peter Ujfalusi37e13ce2012-05-16 14:11:58 +0300639 struct device_node *node = client->dev.of_node;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500640 struct twl6040 *twl6040;
641 struct mfd_cell *cell = NULL;
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300642 int irq, ret, children = 0;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500643
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200644 if (!node) {
645 dev_err(&client->dev, "of node is missing\n");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500646 return -EINVAL;
647 }
648
Peter Ujfalusid20e1d22011-07-04 20:15:19 +0300649 /* In order to operate correctly we need valid interrupt config */
Peter Ujfalusi67124192012-05-16 14:11:56 +0300650 if (!client->irq) {
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300651 dev_err(&client->dev, "Invalid IRQ configuration\n");
Peter Ujfalusid20e1d22011-07-04 20:15:19 +0300652 return -EINVAL;
653 }
654
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300655 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040),
656 GFP_KERNEL);
Peter Ujfalusiecc8fa12013-07-12 13:32:04 +0200657 if (!twl6040)
658 return -ENOMEM;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500659
Axel Linbbf6adc2012-04-25 10:09:46 +0800660 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config);
Peter Ujfalusiecc8fa12013-07-12 13:32:04 +0200661 if (IS_ERR(twl6040->regmap))
662 return PTR_ERR(twl6040->regmap);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500663
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300664 i2c_set_clientdata(client, twl6040);
665
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300666 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k");
667 if (IS_ERR(twl6040->clk32k)) {
Tony Lindgren75c08f12015-09-18 09:29:04 -0700668 if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER)
669 return -EPROBE_DEFER;
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300670 dev_dbg(&client->dev, "clk32k is not handled\n");
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300671 twl6040->clk32k = NULL;
672 }
673
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300674 twl6040->mclk = devm_clk_get(&client->dev, "mclk");
675 if (IS_ERR(twl6040->mclk)) {
676 if (PTR_ERR(twl6040->mclk) == -EPROBE_DEFER)
677 return -EPROBE_DEFER;
678 dev_dbg(&client->dev, "mclk is not handled\n");
679 twl6040->mclk = NULL;
680 }
681
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300682 twl6040->supplies[0].supply = "vio";
683 twl6040->supplies[1].supply = "v2v1";
Jingoo Han990810b2013-02-20 18:30:21 +0900684 ret = devm_regulator_bulk_get(&client->dev, TWL6040_NUM_SUPPLIES,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200685 twl6040->supplies);
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300686 if (ret != 0) {
687 dev_err(&client->dev, "Failed to get supplies: %d\n", ret);
Wolfram Sang501d6092013-10-13 18:06:12 +0200688 return ret;
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300689 }
690
691 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
692 if (ret != 0) {
693 dev_err(&client->dev, "Failed to enable supplies: %d\n", ret);
Wolfram Sang501d6092013-10-13 18:06:12 +0200694 return ret;
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300695 }
696
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300697 twl6040->dev = &client->dev;
698 twl6040->irq = client->irq;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500699
700 mutex_init(&twl6040->mutex);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500701 init_completion(&twl6040->ready);
702
Peter Ujfalusi006cea32014-04-01 16:45:00 +0300703 regmap_register_patch(twl6040->regmap, twl6040_patch,
704 ARRAY_SIZE(twl6040_patch));
705
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500706 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV);
Florian Vaussard89d68992014-02-25 14:28:19 +0100707 if (twl6040->rev < 0) {
708 dev_err(&client->dev, "Failed to read revision register: %d\n",
709 twl6040->rev);
Julia Lawallf2b86782014-08-06 22:12:15 +0200710 ret = twl6040->rev;
Florian Vaussard89d68992014-02-25 14:28:19 +0100711 goto gpio_err;
712 }
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500713
Peter Ujfalusi77f63e02011-09-15 15:39:26 +0300714 /* ERRATA: Automatic power-up is not possible in ES1.0 */
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200715 if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0)
716 twl6040->audpwron = of_get_named_gpio(node,
717 "ti,audpwron-gpio", 0);
718 else
Peter Ujfalusi77f63e02011-09-15 15:39:26 +0300719 twl6040->audpwron = -EINVAL;
720
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500721 if (gpio_is_valid(twl6040->audpwron)) {
Jingoo Han990810b2013-02-20 18:30:21 +0900722 ret = devm_gpio_request_one(&client->dev, twl6040->audpwron,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200723 GPIOF_OUT_INIT_LOW, "audpwron");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500724 if (ret)
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300725 goto gpio_err;
Peter Ujfalusi02d02722014-04-01 16:45:01 +0300726
727 /* Clear any pending interrupt */
728 twl6040_reg_read(twl6040, TWL6040_REG_INTID);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500729 }
730
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200731 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT,
Lee Jonesc06f3082014-07-21 13:13:48 +0100732 0, &twl6040_irq_chip, &twl6040->irq_data);
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200733 if (ret < 0)
Jingoo Han990810b2013-02-20 18:30:21 +0900734 goto gpio_err;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500735
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200736 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200737 TWL6040_IRQ_READY);
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200738 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200739 TWL6040_IRQ_TH);
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200740
Jingoo Han990810b2013-02-20 18:30:21 +0900741 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200742 twl6040_readyint_handler, IRQF_ONESHOT,
743 "twl6040_irq_ready", twl6040);
Peter Ujfalusid20e1d22011-07-04 20:15:19 +0300744 if (ret) {
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200745 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret);
746 goto readyirq_err;
747 }
748
Jingoo Han990810b2013-02-20 18:30:21 +0900749 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200750 twl6040_thint_handler, IRQF_ONESHOT,
751 "twl6040_irq_th", twl6040);
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200752 if (ret) {
753 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret);
Wei Yongjunfc5ee962013-09-25 15:37:15 +0800754 goto readyirq_err;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500755 }
756
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300757 /*
758 * The main functionality of twl6040 to provide audio on OMAP4+ systems.
759 * We can add the ASoC codec child whenever this driver has been loaded.
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300760 */
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200761 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG);
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300762 cell = &twl6040->cells[children];
763 cell->name = "twl6040-codec";
764 twl6040_codec_rsrc[0].start = irq;
765 twl6040_codec_rsrc[0].end = irq;
766 cell->resources = twl6040_codec_rsrc;
767 cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc);
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300768 children++;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500769
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200770 /* Vibra input driver support */
771 if (twl6040_has_vibra(node)) {
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200772 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB);
Peter Ujfalusi0f962ae2011-07-05 11:40:33 +0300773
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500774 cell = &twl6040->cells[children];
775 cell->name = "twl6040-vibra";
Peter Ujfalusi0f962ae2011-07-05 11:40:33 +0300776 twl6040_vibra_rsrc[0].start = irq;
777 twl6040_vibra_rsrc[0].end = irq;
778 cell->resources = twl6040_vibra_rsrc;
779 cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500780 children++;
781 }
782
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200783 /* GPO support */
784 cell = &twl6040->cells[children];
785 cell->name = "twl6040-gpo";
786 children++;
Peter Ujfalusi5cbe7862012-08-16 15:13:14 +0300787
Peter Ujfalusi0133d322016-08-31 14:46:21 +0300788 /* PDM clock support */
789 cell = &twl6040->cells[children];
790 cell->name = "twl6040-pdmclk";
791 children++;
792
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200793 /* The chip is powered down so mark regmap to cache only and dirty */
794 regcache_cache_only(twl6040->regmap, true);
795 regcache_mark_dirty(twl6040->regmap);
796
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300797 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
Mark Brown55692af2012-09-11 15:16:36 +0800798 NULL, 0, NULL);
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300799 if (ret)
Wei Yongjunfc5ee962013-09-25 15:37:15 +0800800 goto readyirq_err;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500801
802 return 0;
803
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200804readyirq_err:
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200805 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300806gpio_err:
807 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500808 return ret;
809}
810
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800811static int twl6040_remove(struct i2c_client *client)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500812{
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300813 struct twl6040 *twl6040 = i2c_get_clientdata(client);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500814
815 if (twl6040->power_count)
816 twl6040_power(twl6040, 0);
817
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200818 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500819
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300820 mfd_remove_devices(&client->dev);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500821
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300822 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300823
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500824 return 0;
825}
826
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300827static const struct i2c_device_id twl6040_i2c_id[] = {
828 { "twl6040", 0, },
Peter Ujfalusi1fc74ae2012-07-16 11:49:44 +0200829 { "twl6041", 0, },
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300830 { },
831};
832MODULE_DEVICE_TABLE(i2c, twl6040_i2c_id);
833
834static struct i2c_driver twl6040_driver = {
835 .driver = {
836 .name = "twl6040",
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300837 },
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500838 .probe = twl6040_probe,
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800839 .remove = twl6040_remove,
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300840 .id_table = twl6040_i2c_id,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500841};
842
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300843module_i2c_driver(twl6040_driver);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500844
845MODULE_DESCRIPTION("TWL6040 MFD");
846MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
847MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>");
848MODULE_LICENSE("GPL");