blob: 2b8c479dbfa6e1edb5db688bc0f7fe2112ea1738 [file] [log] [blame]
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -05001/*
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>
Peter Ujfalusi5af7df62012-05-02 16:54:42 +030030#include <linux/err.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050031#include <linux/platform_device.h>
Peter Ujfalusi37e13ce2012-05-16 14:11:58 +030032#include <linux/of.h>
33#include <linux/of_irq.h>
34#include <linux/of_gpio.h>
35#include <linux/of_platform.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050036#include <linux/gpio.h>
37#include <linux/delay.h>
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +030038#include <linux/i2c.h>
39#include <linux/regmap.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050040#include <linux/mfd/core.h>
41#include <linux/mfd/twl6040.h>
Peter Ujfalusi5af7df62012-05-02 16:54:42 +030042#include <linux/regulator/consumer.h>
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -050043
Peter Ujfalusi31b402e2011-10-12 11:57:54 +030044#define VIBRACTRL_MEMBER(reg) ((reg == TWL6040_REG_VIBCTLL) ? 0 : 1)
Peter Ujfalusi5af7df62012-05-02 16:54:42 +030045#define TWL6040_NUM_SUPPLIES (2)
Peter Ujfalusi31b402e2011-10-12 11:57:54 +030046
Krzysztof Kozlowskide1e23f2015-01-05 10:01:33 +010047static const struct reg_default twl6040_defaults[] = {
Peter Ujfalusic7f91292013-11-29 16:03:45 +020048 { 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 */
80 /* 0x28, REG_TRIM1 */
81 /* 0x29, REG_TRIM2 */
82 /* 0x2A, REG_TRIM3 */
83 /* 0x2B, REG_HSOTRIM */
84 /* 0x2C, REG_HFOTRIM */
85 { 0x2D, 0x08 }, /* REG_ACCCTL */
86 { 0x2E, 0x00 }, /* REG_STATUS (ro) */
87};
88
Nariman Poushin8019ff62015-07-16 16:36:21 +010089static struct reg_sequence twl6040_patch[] = {
Peter Ujfalusi11e38e12014-04-01 16:44:59 +030090 /*
91 * Select I2C bus access to dual access registers
92 * Interrupt register is cleared on read
93 * Select fast mode for i2c (400KHz)
94 */
95 { TWL6040_REG_ACCCTL,
96 TWL6040_I2CSEL | TWL6040_INTCLRMODE | TWL6040_I2CMODE(1) },
Peter Ujfalusic7f91292013-11-29 16:03:45 +020097};
98
99
Johan Hovoldbecf7d82017-11-11 16:38:44 +0100100static bool twl6040_has_vibra(struct device_node *parent)
Samuel Ortizca2cad62012-05-23 16:23:21 +0200101{
Johan Hovoldbecf7d82017-11-11 16:38:44 +0100102 struct device_node *node;
103
104 node = of_get_child_by_name(parent, "vibra");
105 if (node) {
106 of_node_put(node);
Samuel Ortizca2cad62012-05-23 16:23:21 +0200107 return true;
Johan Hovoldbecf7d82017-11-11 16:38:44 +0100108 }
109
Samuel Ortizca2cad62012-05-23 16:23:21 +0200110 return false;
111}
112
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500113int twl6040_reg_read(struct twl6040 *twl6040, unsigned int reg)
114{
115 int ret;
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300116 unsigned int val;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500117
Mark Brownc6f39252013-08-31 17:48:19 +0100118 ret = regmap_read(twl6040->regmap, reg, &val);
119 if (ret < 0)
120 return ret;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500121
122 return val;
123}
124EXPORT_SYMBOL(twl6040_reg_read);
125
126int twl6040_reg_write(struct twl6040 *twl6040, unsigned int reg, u8 val)
127{
128 int ret;
129
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300130 ret = regmap_write(twl6040->regmap, reg, val);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500131
132 return ret;
133}
134EXPORT_SYMBOL(twl6040_reg_write);
135
136int twl6040_set_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
137{
Axel Linc6000402012-07-11 10:06:34 +0800138 return regmap_update_bits(twl6040->regmap, reg, mask, mask);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500139}
140EXPORT_SYMBOL(twl6040_set_bits);
141
142int twl6040_clear_bits(struct twl6040 *twl6040, unsigned int reg, u8 mask)
143{
Axel Linc6000402012-07-11 10:06:34 +0800144 return regmap_update_bits(twl6040->regmap, reg, mask, 0);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500145}
146EXPORT_SYMBOL(twl6040_clear_bits);
147
148/* twl6040 codec manual power-up sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200149static int twl6040_power_up_manual(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500150{
151 u8 ldoctl, ncpctl, lppllctl;
152 int ret;
153
154 /* enable high-side LDO, reference system and internal oscillator */
155 ldoctl = TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA;
156 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
157 if (ret)
158 return ret;
159 usleep_range(10000, 10500);
160
161 /* enable negative charge pump */
162 ncpctl = TWL6040_NCPENA;
163 ret = twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
164 if (ret)
165 goto ncp_err;
166 usleep_range(1000, 1500);
167
168 /* enable low-side LDO */
169 ldoctl |= TWL6040_LSLDOENA;
170 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
171 if (ret)
172 goto lsldo_err;
173 usleep_range(1000, 1500);
174
175 /* enable low-power PLL */
176 lppllctl = TWL6040_LPLLENA;
177 ret = twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
178 if (ret)
179 goto lppll_err;
180 usleep_range(5000, 5500);
181
182 /* disable internal oscillator */
183 ldoctl &= ~TWL6040_OSCENA;
184 ret = twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
185 if (ret)
186 goto osc_err;
187
188 return 0;
189
190osc_err:
191 lppllctl &= ~TWL6040_LPLLENA;
192 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
193lppll_err:
194 ldoctl &= ~TWL6040_LSLDOENA;
195 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
196lsldo_err:
197 ncpctl &= ~TWL6040_NCPENA;
198 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
199ncp_err:
200 ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
201 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
202
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200203 dev_err(twl6040->dev, "manual power-up failed\n");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500204 return ret;
205}
206
207/* twl6040 manual power-down sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200208static void twl6040_power_down_manual(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500209{
210 u8 ncpctl, ldoctl, lppllctl;
211
212 ncpctl = twl6040_reg_read(twl6040, TWL6040_REG_NCPCTL);
213 ldoctl = twl6040_reg_read(twl6040, TWL6040_REG_LDOCTL);
214 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
215
216 /* enable internal oscillator */
217 ldoctl |= TWL6040_OSCENA;
218 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
219 usleep_range(1000, 1500);
220
221 /* disable low-power PLL */
222 lppllctl &= ~TWL6040_LPLLENA;
223 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL, lppllctl);
224
225 /* disable low-side LDO */
226 ldoctl &= ~TWL6040_LSLDOENA;
227 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
228
229 /* disable negative charge pump */
230 ncpctl &= ~TWL6040_NCPENA;
231 twl6040_reg_write(twl6040, TWL6040_REG_NCPCTL, ncpctl);
232
233 /* disable high-side LDO, reference system and internal oscillator */
234 ldoctl &= ~(TWL6040_HSLDOENA | TWL6040_REFENA | TWL6040_OSCENA);
235 twl6040_reg_write(twl6040, TWL6040_REG_LDOCTL, ldoctl);
236}
237
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200238static irqreturn_t twl6040_readyint_handler(int irq, void *data)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500239{
240 struct twl6040 *twl6040 = data;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500241
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200242 complete(&twl6040->ready);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500243
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200244 return IRQ_HANDLED;
245}
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500246
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200247static irqreturn_t twl6040_thint_handler(int irq, void *data)
248{
249 struct twl6040 *twl6040 = data;
250 u8 status;
251
252 status = twl6040_reg_read(twl6040, TWL6040_REG_STATUS);
253 if (status & TWL6040_TSHUTDET) {
254 dev_warn(twl6040->dev, "Thermal shutdown, powering-off");
255 twl6040_power(twl6040, 0);
256 } else {
257 dev_warn(twl6040->dev, "Leaving thermal shutdown, powering-on");
258 twl6040_power(twl6040, 1);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500259 }
260
261 return IRQ_HANDLED;
262}
263
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200264static int twl6040_power_up_automatic(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500265{
266 int time_left;
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200267
268 gpio_set_value(twl6040->audpwron, 1);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500269
270 time_left = wait_for_completion_timeout(&twl6040->ready,
271 msecs_to_jiffies(144));
272 if (!time_left) {
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200273 u8 intid;
274
275 dev_warn(twl6040->dev, "timeout waiting for READYINT\n");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500276 intid = twl6040_reg_read(twl6040, TWL6040_REG_INTID);
277 if (!(intid & TWL6040_READYINT)) {
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200278 dev_err(twl6040->dev, "automatic power-up failed\n");
279 gpio_set_value(twl6040->audpwron, 0);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500280 return -ETIMEDOUT;
281 }
282 }
283
284 return 0;
285}
286
287int twl6040_power(struct twl6040 *twl6040, int on)
288{
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500289 int ret = 0;
290
291 mutex_lock(&twl6040->mutex);
292
293 if (on) {
294 /* already powered-up */
295 if (twl6040->power_count++)
296 goto out;
297
Javier Martinez Canillas32852bc2016-04-20 11:16:38 -0400298 ret = clk_prepare_enable(twl6040->clk32k);
299 if (ret) {
300 twl6040->power_count = 0;
301 goto out;
302 }
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300303
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200304 /* Allow writes to the chip */
305 regcache_cache_only(twl6040->regmap, false);
306
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200307 if (gpio_is_valid(twl6040->audpwron)) {
308 /* use automatic power-up sequence */
309 ret = twl6040_power_up_automatic(twl6040);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500310 if (ret) {
Javier Martinez Canillasd6441dc2016-04-20 11:16:37 -0400311 clk_disable_unprepare(twl6040->clk32k);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500312 twl6040->power_count = 0;
313 goto out;
314 }
315 } else {
316 /* use manual power-up sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200317 ret = twl6040_power_up_manual(twl6040);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500318 if (ret) {
Javier Martinez Canillasd6441dc2016-04-20 11:16:37 -0400319 clk_disable_unprepare(twl6040->clk32k);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500320 twl6040->power_count = 0;
321 goto out;
322 }
323 }
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200324
Tony Lindgren59e1b232019-02-14 08:03:45 -0800325 /*
326 * Register access can produce errors after power-up unless we
327 * wait at least 8ms based on measurements on duovero.
328 */
329 usleep_range(10000, 12000);
330
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200331 /* Sync with the HW */
Tony Lindgren59e1b232019-02-14 08:03:45 -0800332 ret = regcache_sync(twl6040->regmap);
333 if (ret) {
334 dev_err(twl6040->dev, "Failed to sync with the HW: %i\n",
335 ret);
336 goto out;
337 }
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200338
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300339 /* Default PLL configuration after power up */
340 twl6040->pll = TWL6040_SYSCLK_SEL_LPPLL;
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300341 twl6040->sysclk_rate = 19200000;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500342 } else {
343 /* already powered-down */
344 if (!twl6040->power_count) {
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300345 dev_err(twl6040->dev,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500346 "device is already powered-off\n");
347 ret = -EPERM;
348 goto out;
349 }
350
351 if (--twl6040->power_count)
352 goto out;
353
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200354 if (gpio_is_valid(twl6040->audpwron)) {
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500355 /* use AUDPWRON line */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200356 gpio_set_value(twl6040->audpwron, 0);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500357
358 /* power-down sequence latency */
359 usleep_range(500, 700);
360 } else {
361 /* use manual power-down sequence */
Peter Ujfalusif9be1342012-10-11 13:55:30 +0200362 twl6040_power_down_manual(twl6040);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500363 }
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200364
365 /* Set regmap to cache only and mark it as dirty */
366 regcache_cache_only(twl6040->regmap, true);
367 regcache_mark_dirty(twl6040->regmap);
368
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300369 twl6040->sysclk_rate = 0;
370
371 if (twl6040->pll == TWL6040_SYSCLK_SEL_HPPLL) {
372 clk_disable_unprepare(twl6040->mclk);
373 twl6040->mclk_rate = 0;
374 }
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300375
376 clk_disable_unprepare(twl6040->clk32k);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500377 }
378
379out:
380 mutex_unlock(&twl6040->mutex);
381 return ret;
382}
383EXPORT_SYMBOL(twl6040_power);
384
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300385int twl6040_set_pll(struct twl6040 *twl6040, int pll_id,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500386 unsigned int freq_in, unsigned int freq_out)
387{
388 u8 hppllctl, lppllctl;
389 int ret = 0;
390
391 mutex_lock(&twl6040->mutex);
392
393 hppllctl = twl6040_reg_read(twl6040, TWL6040_REG_HPPLLCTL);
394 lppllctl = twl6040_reg_read(twl6040, TWL6040_REG_LPPLLCTL);
395
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100396 /* Force full reconfiguration when switching between PLL */
397 if (pll_id != twl6040->pll) {
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300398 twl6040->sysclk_rate = 0;
399 twl6040->mclk_rate = 0;
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100400 }
401
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300402 switch (pll_id) {
403 case TWL6040_SYSCLK_SEL_LPPLL:
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500404 /* low-power PLL divider */
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100405 /* Change the sysclk configuration only if it has been canged */
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300406 if (twl6040->sysclk_rate != freq_out) {
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100407 switch (freq_out) {
408 case 17640000:
409 lppllctl |= TWL6040_LPLLFIN;
410 break;
411 case 19200000:
412 lppllctl &= ~TWL6040_LPLLFIN;
413 break;
414 default:
415 dev_err(twl6040->dev,
416 "freq_out %d not supported\n",
417 freq_out);
418 ret = -EINVAL;
419 goto pll_out;
420 }
421 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
422 lppllctl);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500423 }
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100424
425 /* The PLL in use has not been change, we can exit */
426 if (twl6040->pll == pll_id)
427 break;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500428
429 switch (freq_in) {
430 case 32768:
431 lppllctl |= TWL6040_LPLLENA;
432 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
433 lppllctl);
434 mdelay(5);
435 lppllctl &= ~TWL6040_HPLLSEL;
436 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
437 lppllctl);
438 hppllctl &= ~TWL6040_HPLLENA;
439 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
440 hppllctl);
441 break;
442 default:
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300443 dev_err(twl6040->dev,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500444 "freq_in %d not supported\n", freq_in);
445 ret = -EINVAL;
446 goto pll_out;
447 }
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300448
449 clk_disable_unprepare(twl6040->mclk);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500450 break;
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300451 case TWL6040_SYSCLK_SEL_HPPLL:
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500452 /* high-performance PLL can provide only 19.2 MHz */
453 if (freq_out != 19200000) {
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300454 dev_err(twl6040->dev,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500455 "freq_out %d not supported\n", freq_out);
456 ret = -EINVAL;
457 goto pll_out;
458 }
459
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300460 if (twl6040->mclk_rate != freq_in) {
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100461 hppllctl &= ~TWL6040_MCLK_MSK;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500462
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100463 switch (freq_in) {
464 case 12000000:
465 /* PLL enabled, active mode */
466 hppllctl |= TWL6040_MCLK_12000KHZ |
467 TWL6040_HPLLENA;
468 break;
469 case 19200000:
Peter Ujfalusiac8320c2014-05-06 11:46:10 +0300470 /* PLL enabled, bypass mode */
471 hppllctl |= TWL6040_MCLK_19200KHZ |
472 TWL6040_HPLLBP | TWL6040_HPLLENA;
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100473 break;
474 case 26000000:
475 /* PLL enabled, active mode */
476 hppllctl |= TWL6040_MCLK_26000KHZ |
477 TWL6040_HPLLENA;
478 break;
479 case 38400000:
Peter Ujfalusiac8320c2014-05-06 11:46:10 +0300480 /* PLL enabled, bypass mode */
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100481 hppllctl |= TWL6040_MCLK_38400KHZ |
Peter Ujfalusiac8320c2014-05-06 11:46:10 +0300482 TWL6040_HPLLBP | TWL6040_HPLLENA;
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100483 break;
484 default:
485 dev_err(twl6040->dev,
486 "freq_in %d not supported\n", freq_in);
487 ret = -EINVAL;
488 goto pll_out;
489 }
490
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300491 /* When switching to HPPLL, enable the mclk first */
492 if (pll_id != twl6040->pll)
493 clk_prepare_enable(twl6040->mclk);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500494 /*
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100495 * enable clock slicer to ensure input waveform is
496 * square
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500497 */
Peter Ujfalusi2bd05db2012-01-14 20:58:44 +0100498 hppllctl |= TWL6040_HPLLSQRENA;
499
500 twl6040_reg_write(twl6040, TWL6040_REG_HPPLLCTL,
501 hppllctl);
502 usleep_range(500, 700);
503 lppllctl |= TWL6040_HPLLSEL;
504 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
505 lppllctl);
506 lppllctl &= ~TWL6040_LPLLENA;
507 twl6040_reg_write(twl6040, TWL6040_REG_LPPLLCTL,
508 lppllctl);
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300509
510 twl6040->mclk_rate = freq_in;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500511 }
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500512 break;
513 default:
Peter Ujfalusi2d7c9572011-09-15 15:39:23 +0300514 dev_err(twl6040->dev, "unknown pll id %d\n", pll_id);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500515 ret = -EINVAL;
516 goto pll_out;
517 }
518
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300519 twl6040->sysclk_rate = freq_out;
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300520 twl6040->pll = pll_id;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500521
522pll_out:
523 mutex_unlock(&twl6040->mutex);
524 return ret;
525}
526EXPORT_SYMBOL(twl6040_set_pll);
527
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300528int twl6040_get_pll(struct twl6040 *twl6040)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500529{
Peter Ujfalusicfb7a332011-07-04 10:28:28 +0300530 if (twl6040->power_count)
531 return twl6040->pll;
532 else
533 return -ENODEV;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500534}
535EXPORT_SYMBOL(twl6040_get_pll);
536
537unsigned int twl6040_get_sysclk(struct twl6040 *twl6040)
538{
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300539 return twl6040->sysclk_rate;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500540}
541EXPORT_SYMBOL(twl6040_get_sysclk);
542
Peter Ujfalusi70601ec2011-10-12 11:57:55 +0300543/* Get the combined status of the vibra control register */
544int twl6040_get_vibralr_status(struct twl6040 *twl6040)
545{
Mark Brownc6f39252013-08-31 17:48:19 +0100546 unsigned int reg;
547 int ret;
Peter Ujfalusi70601ec2011-10-12 11:57:55 +0300548 u8 status;
549
Mark Brownc6f39252013-08-31 17:48:19 +0100550 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLL, &reg);
551 if (ret != 0)
552 return ret;
553 status = reg;
554
555 ret = regmap_read(twl6040->regmap, TWL6040_REG_VIBCTLR, &reg);
556 if (ret != 0)
557 return ret;
558 status |= reg;
559
Peter Ujfalusi70601ec2011-10-12 11:57:55 +0300560 status &= (TWL6040_VIBENA | TWL6040_VIBSEL);
561
562 return status;
563}
564EXPORT_SYMBOL(twl6040_get_vibralr_status);
565
Peter Ujfalusi0f962ae2011-07-05 11:40:33 +0300566static struct resource twl6040_vibra_rsrc[] = {
567 {
568 .flags = IORESOURCE_IRQ,
569 },
570};
571
572static struct resource twl6040_codec_rsrc[] = {
573 {
574 .flags = IORESOURCE_IRQ,
575 },
576};
577
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300578static bool twl6040_readable_reg(struct device *dev, unsigned int reg)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500579{
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300580 /* Register 0 is not readable */
581 if (!reg)
582 return false;
583 return true;
584}
585
Mark Brownc6f39252013-08-31 17:48:19 +0100586static bool twl6040_volatile_reg(struct device *dev, unsigned int reg)
587{
588 switch (reg) {
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200589 case TWL6040_REG_ASICID:
590 case TWL6040_REG_ASICREV:
591 case TWL6040_REG_INTID:
592 case TWL6040_REG_LPPLLCTL:
593 case TWL6040_REG_HPPLLCTL:
594 case TWL6040_REG_STATUS:
595 return true;
596 default:
597 return false;
598 }
599}
600
601static bool twl6040_writeable_reg(struct device *dev, unsigned int reg)
602{
603 switch (reg) {
604 case TWL6040_REG_ASICID:
605 case TWL6040_REG_ASICREV:
606 case TWL6040_REG_STATUS:
Mark Brownc6f39252013-08-31 17:48:19 +0100607 return false;
608 default:
609 return true;
610 }
611}
612
Krzysztof Kozlowskide1e23f2015-01-05 10:01:33 +0100613static const struct regmap_config twl6040_regmap_config = {
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300614 .reg_bits = 8,
615 .val_bits = 8,
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200616
617 .reg_defaults = twl6040_defaults,
618 .num_reg_defaults = ARRAY_SIZE(twl6040_defaults),
619
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300620 .max_register = TWL6040_REG_STATUS, /* 0x2e */
621
622 .readable_reg = twl6040_readable_reg,
Mark Brownc6f39252013-08-31 17:48:19 +0100623 .volatile_reg = twl6040_volatile_reg,
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200624 .writeable_reg = twl6040_writeable_reg,
Mark Brownc6f39252013-08-31 17:48:19 +0100625
626 .cache_type = REGCACHE_RBTREE,
Peter Ujfalusic78cb172016-08-31 14:46:20 +0300627 .use_single_rw = true,
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300628};
629
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200630static const struct regmap_irq twl6040_irqs[] = {
631 { .reg_offset = 0, .mask = TWL6040_THINT, },
632 { .reg_offset = 0, .mask = TWL6040_PLUGINT | TWL6040_UNPLUGINT, },
633 { .reg_offset = 0, .mask = TWL6040_HOOKINT, },
634 { .reg_offset = 0, .mask = TWL6040_HFINT, },
635 { .reg_offset = 0, .mask = TWL6040_VIBINT, },
636 { .reg_offset = 0, .mask = TWL6040_READYINT, },
637};
638
639static struct regmap_irq_chip twl6040_irq_chip = {
640 .name = "twl6040",
641 .irqs = twl6040_irqs,
642 .num_irqs = ARRAY_SIZE(twl6040_irqs),
643
644 .num_regs = 1,
645 .status_base = TWL6040_REG_INTID,
646 .mask_base = TWL6040_REG_INTMR,
647};
648
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800649static int twl6040_probe(struct i2c_client *client,
650 const struct i2c_device_id *id)
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300651{
Peter Ujfalusi37e13ce2012-05-16 14:11:58 +0300652 struct device_node *node = client->dev.of_node;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500653 struct twl6040 *twl6040;
654 struct mfd_cell *cell = NULL;
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300655 int irq, ret, children = 0;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500656
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200657 if (!node) {
658 dev_err(&client->dev, "of node is missing\n");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500659 return -EINVAL;
660 }
661
Peter Ujfalusid20e1d22011-07-04 20:15:19 +0300662 /* In order to operate correctly we need valid interrupt config */
Peter Ujfalusi67124192012-05-16 14:11:56 +0300663 if (!client->irq) {
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300664 dev_err(&client->dev, "Invalid IRQ configuration\n");
Peter Ujfalusid20e1d22011-07-04 20:15:19 +0300665 return -EINVAL;
666 }
667
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300668 twl6040 = devm_kzalloc(&client->dev, sizeof(struct twl6040),
669 GFP_KERNEL);
Peter Ujfalusiecc8fa12013-07-12 13:32:04 +0200670 if (!twl6040)
671 return -ENOMEM;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500672
Axel Linbbf6adc2012-04-25 10:09:46 +0800673 twl6040->regmap = devm_regmap_init_i2c(client, &twl6040_regmap_config);
Peter Ujfalusiecc8fa12013-07-12 13:32:04 +0200674 if (IS_ERR(twl6040->regmap))
675 return PTR_ERR(twl6040->regmap);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500676
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300677 i2c_set_clientdata(client, twl6040);
678
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300679 twl6040->clk32k = devm_clk_get(&client->dev, "clk32k");
680 if (IS_ERR(twl6040->clk32k)) {
Tony Lindgren75c08f12015-09-18 09:29:04 -0700681 if (PTR_ERR(twl6040->clk32k) == -EPROBE_DEFER)
682 return -EPROBE_DEFER;
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300683 dev_dbg(&client->dev, "clk32k is not handled\n");
Peter Ujfalusi68bab862014-04-03 13:54:41 +0300684 twl6040->clk32k = NULL;
685 }
686
Peter Ujfalusi0a58da12016-06-20 17:07:18 +0300687 twl6040->mclk = devm_clk_get(&client->dev, "mclk");
688 if (IS_ERR(twl6040->mclk)) {
689 if (PTR_ERR(twl6040->mclk) == -EPROBE_DEFER)
690 return -EPROBE_DEFER;
691 dev_dbg(&client->dev, "mclk is not handled\n");
692 twl6040->mclk = NULL;
693 }
694
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300695 twl6040->supplies[0].supply = "vio";
696 twl6040->supplies[1].supply = "v2v1";
Jingoo Han990810b2013-02-20 18:30:21 +0900697 ret = devm_regulator_bulk_get(&client->dev, TWL6040_NUM_SUPPLIES,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200698 twl6040->supplies);
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300699 if (ret != 0) {
700 dev_err(&client->dev, "Failed to get supplies: %d\n", ret);
Wolfram Sang501d6092013-10-13 18:06:12 +0200701 return ret;
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300702 }
703
704 ret = regulator_bulk_enable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
705 if (ret != 0) {
706 dev_err(&client->dev, "Failed to enable supplies: %d\n", ret);
Wolfram Sang501d6092013-10-13 18:06:12 +0200707 return ret;
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300708 }
709
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300710 twl6040->dev = &client->dev;
711 twl6040->irq = client->irq;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500712
713 mutex_init(&twl6040->mutex);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500714 init_completion(&twl6040->ready);
715
Peter Ujfalusi006cea32014-04-01 16:45:00 +0300716 regmap_register_patch(twl6040->regmap, twl6040_patch,
717 ARRAY_SIZE(twl6040_patch));
718
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500719 twl6040->rev = twl6040_reg_read(twl6040, TWL6040_REG_ASICREV);
Florian Vaussard89d68992014-02-25 14:28:19 +0100720 if (twl6040->rev < 0) {
721 dev_err(&client->dev, "Failed to read revision register: %d\n",
722 twl6040->rev);
Julia Lawallf2b86782014-08-06 22:12:15 +0200723 ret = twl6040->rev;
Florian Vaussard89d68992014-02-25 14:28:19 +0100724 goto gpio_err;
725 }
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500726
Peter Ujfalusi77f63e02011-09-15 15:39:26 +0300727 /* ERRATA: Automatic power-up is not possible in ES1.0 */
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200728 if (twl6040_get_revid(twl6040) > TWL6040_REV_ES1_0)
729 twl6040->audpwron = of_get_named_gpio(node,
730 "ti,audpwron-gpio", 0);
731 else
Peter Ujfalusi77f63e02011-09-15 15:39:26 +0300732 twl6040->audpwron = -EINVAL;
733
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500734 if (gpio_is_valid(twl6040->audpwron)) {
Jingoo Han990810b2013-02-20 18:30:21 +0900735 ret = devm_gpio_request_one(&client->dev, twl6040->audpwron,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200736 GPIOF_OUT_INIT_LOW, "audpwron");
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500737 if (ret)
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300738 goto gpio_err;
Peter Ujfalusi02d02722014-04-01 16:45:01 +0300739
740 /* Clear any pending interrupt */
741 twl6040_reg_read(twl6040, TWL6040_REG_INTID);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500742 }
743
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200744 ret = regmap_add_irq_chip(twl6040->regmap, twl6040->irq, IRQF_ONESHOT,
Lee Jonesc06f3082014-07-21 13:13:48 +0100745 0, &twl6040_irq_chip, &twl6040->irq_data);
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200746 if (ret < 0)
Jingoo Han990810b2013-02-20 18:30:21 +0900747 goto gpio_err;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500748
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200749 twl6040->irq_ready = regmap_irq_get_virq(twl6040->irq_data,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200750 TWL6040_IRQ_READY);
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200751 twl6040->irq_th = regmap_irq_get_virq(twl6040->irq_data,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200752 TWL6040_IRQ_TH);
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200753
Jingoo Han990810b2013-02-20 18:30:21 +0900754 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_ready, NULL,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200755 twl6040_readyint_handler, IRQF_ONESHOT,
756 "twl6040_irq_ready", twl6040);
Peter Ujfalusid20e1d22011-07-04 20:15:19 +0300757 if (ret) {
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200758 dev_err(twl6040->dev, "READY IRQ request failed: %d\n", ret);
759 goto readyirq_err;
760 }
761
Jingoo Han990810b2013-02-20 18:30:21 +0900762 ret = devm_request_threaded_irq(twl6040->dev, twl6040->irq_th, NULL,
Peter Ujfalusi37aefe92013-07-12 13:32:03 +0200763 twl6040_thint_handler, IRQF_ONESHOT,
764 "twl6040_irq_th", twl6040);
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200765 if (ret) {
766 dev_err(twl6040->dev, "Thermal IRQ request failed: %d\n", ret);
Wei Yongjunfc5ee962013-09-25 15:37:15 +0800767 goto readyirq_err;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500768 }
769
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300770 /*
771 * The main functionality of twl6040 to provide audio on OMAP4+ systems.
772 * We can add the ASoC codec child whenever this driver has been loaded.
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300773 */
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200774 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_PLUG);
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300775 cell = &twl6040->cells[children];
776 cell->name = "twl6040-codec";
777 twl6040_codec_rsrc[0].start = irq;
778 twl6040_codec_rsrc[0].end = irq;
779 cell->resources = twl6040_codec_rsrc;
780 cell->num_resources = ARRAY_SIZE(twl6040_codec_rsrc);
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300781 children++;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500782
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200783 /* Vibra input driver support */
784 if (twl6040_has_vibra(node)) {
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200785 irq = regmap_irq_get_virq(twl6040->irq_data, TWL6040_IRQ_VIB);
Peter Ujfalusi0f962ae2011-07-05 11:40:33 +0300786
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500787 cell = &twl6040->cells[children];
788 cell->name = "twl6040-vibra";
Peter Ujfalusi0f962ae2011-07-05 11:40:33 +0300789 twl6040_vibra_rsrc[0].start = irq;
790 twl6040_vibra_rsrc[0].end = irq;
791 cell->resources = twl6040_vibra_rsrc;
792 cell->num_resources = ARRAY_SIZE(twl6040_vibra_rsrc);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500793 children++;
794 }
795
Peter Ujfalusidf04b622013-07-12 13:32:02 +0200796 /* GPO support */
797 cell = &twl6040->cells[children];
798 cell->name = "twl6040-gpo";
799 children++;
Peter Ujfalusi5cbe7862012-08-16 15:13:14 +0300800
Peter Ujfalusi0133d322016-08-31 14:46:21 +0300801 /* PDM clock support */
802 cell = &twl6040->cells[children];
803 cell->name = "twl6040-pdmclk";
804 children++;
805
Peter Ujfalusic7f91292013-11-29 16:03:45 +0200806 /* The chip is powered down so mark regmap to cache only and dirty */
807 regcache_cache_only(twl6040->regmap, true);
808 regcache_mark_dirty(twl6040->regmap);
809
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300810 ret = mfd_add_devices(&client->dev, -1, twl6040->cells, children,
Mark Brown55692af2012-09-11 15:16:36 +0800811 NULL, 0, NULL);
Peter Ujfalusi1f01d602012-05-16 14:11:57 +0300812 if (ret)
Wei Yongjunfc5ee962013-09-25 15:37:15 +0800813 goto readyirq_err;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500814
815 return 0;
816
Peter Ujfalusi1ac96262012-10-11 13:55:31 +0200817readyirq_err:
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200818 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300819gpio_err:
820 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500821 return ret;
822}
823
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800824static int twl6040_remove(struct i2c_client *client)
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500825{
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300826 struct twl6040 *twl6040 = i2c_get_clientdata(client);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500827
828 if (twl6040->power_count)
829 twl6040_power(twl6040, 0);
830
Peter Ujfalusiab7edb12012-10-11 13:55:32 +0200831 regmap_del_irq_chip(twl6040->irq, twl6040->irq_data);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500832
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300833 mfd_remove_devices(&client->dev);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500834
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300835 regulator_bulk_disable(TWL6040_NUM_SUPPLIES, twl6040->supplies);
Peter Ujfalusi5af7df62012-05-02 16:54:42 +0300836
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500837 return 0;
838}
839
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300840static const struct i2c_device_id twl6040_i2c_id[] = {
841 { "twl6040", 0, },
Peter Ujfalusi1fc74ae2012-07-16 11:49:44 +0200842 { "twl6041", 0, },
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300843 { },
844};
845MODULE_DEVICE_TABLE(i2c, twl6040_i2c_id);
846
847static struct i2c_driver twl6040_driver = {
848 .driver = {
849 .name = "twl6040",
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300850 },
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500851 .probe = twl6040_probe,
Greg Kroah-Hartman612b95c2012-12-21 15:03:15 -0800852 .remove = twl6040_remove,
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300853 .id_table = twl6040_i2c_id,
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500854};
855
Peter Ujfalusi8eaeb932012-04-03 11:56:51 +0300856module_i2c_driver(twl6040_driver);
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500857
858MODULE_DESCRIPTION("TWL6040 MFD");
859MODULE_AUTHOR("Misael Lopez Cruz <misael.lopez@ti.com>");
860MODULE_AUTHOR("Jorge Eduardo Candelaria <jorge.candelaria@ti.com>");
861MODULE_LICENSE("GPL");