xref: /openbmc/linux/drivers/mfd/twl-core.c (revision 3def927e)
1 /*
2  * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM
3  * and audio CODEC devices
4  *
5  * Copyright (C) 2005-2006 Texas Instruments, Inc.
6  *
7  * Modifications to defer interrupt handling to a kernel thread:
8  * Copyright (C) 2006 MontaVista Software, Inc.
9  *
10  * Based on tlv320aic23.c:
11  * Copyright (c) by Kai Svahn <kai.svahn@nokia.com>
12  *
13  * Code cleanup and modifications to IRQ handler.
14  * by syed khasim <x0khasim@ti.com>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
29  */
30 
31 #include <linux/init.h>
32 #include <linux/mutex.h>
33 #include <linux/module.h>
34 #include <linux/platform_device.h>
35 #include <linux/regmap.h>
36 #include <linux/clk.h>
37 #include <linux/err.h>
38 #include <linux/device.h>
39 #include <linux/of.h>
40 #include <linux/of_irq.h>
41 #include <linux/of_platform.h>
42 #include <linux/irq.h>
43 #include <linux/irqdomain.h>
44 
45 #include <linux/regulator/machine.h>
46 
47 #include <linux/i2c.h>
48 #include <linux/i2c/twl.h>
49 
50 #include "twl-core.h"
51 
52 /*
53  * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
54  * Management and System Companion Device" chips originally designed for
55  * use in OMAP2 and OMAP 3 based systems.  Its control interfaces use I2C,
56  * often at around 3 Mbit/sec, including for interrupt handling.
57  *
58  * This driver core provides genirq support for the interrupts emitted,
59  * by the various modules, and exports register access primitives.
60  *
61  * FIXME this driver currently requires use of the first interrupt line
62  * (and associated registers).
63  */
64 
65 #define DRIVER_NAME			"twl"
66 
67 /* Triton Core internal information (BEGIN) */
68 
69 /* Base Address defns for twl4030_map[] */
70 
71 /* subchip/slave 0 - USB ID */
72 #define TWL4030_BASEADD_USB		0x0000
73 
74 /* subchip/slave 1 - AUD ID */
75 #define TWL4030_BASEADD_AUDIO_VOICE	0x0000
76 #define TWL4030_BASEADD_GPIO		0x0098
77 #define TWL4030_BASEADD_INTBR		0x0085
78 #define TWL4030_BASEADD_PIH		0x0080
79 #define TWL4030_BASEADD_TEST		0x004C
80 
81 /* subchip/slave 2 - AUX ID */
82 #define TWL4030_BASEADD_INTERRUPTS	0x00B9
83 #define TWL4030_BASEADD_LED		0x00EE
84 #define TWL4030_BASEADD_MADC		0x0000
85 #define TWL4030_BASEADD_MAIN_CHARGE	0x0074
86 #define TWL4030_BASEADD_PRECHARGE	0x00AA
87 #define TWL4030_BASEADD_PWM		0x00F8
88 #define TWL4030_BASEADD_KEYPAD		0x00D2
89 
90 #define TWL5031_BASEADD_ACCESSORY	0x0074 /* Replaces Main Charge */
91 #define TWL5031_BASEADD_INTERRUPTS	0x00B9 /* Different than TWL4030's
92 						  one */
93 
94 /* subchip/slave 3 - POWER ID */
95 #define TWL4030_BASEADD_BACKUP		0x0014
96 #define TWL4030_BASEADD_INT		0x002E
97 #define TWL4030_BASEADD_PM_MASTER	0x0036
98 #define TWL4030_BASEADD_PM_RECEIVER	0x005B
99 #define TWL4030_BASEADD_RTC		0x001C
100 #define TWL4030_BASEADD_SECURED_REG	0x0000
101 
102 /* Triton Core internal information (END) */
103 
104 
105 /* subchip/slave 0 0x48 - POWER */
106 #define TWL6030_BASEADD_RTC		0x0000
107 #define TWL6030_BASEADD_SECURED_REG	0x0017
108 #define TWL6030_BASEADD_PM_MASTER	0x001F
109 #define TWL6030_BASEADD_PM_SLAVE_MISC	0x0030 /* PM_RECEIVER */
110 #define TWL6030_BASEADD_PM_MISC		0x00E2
111 #define TWL6030_BASEADD_PM_PUPD		0x00F0
112 
113 /* subchip/slave 1 0x49 - FEATURE */
114 #define TWL6030_BASEADD_USB		0x0000
115 #define TWL6030_BASEADD_GPADC_CTRL	0x002E
116 #define TWL6030_BASEADD_AUX		0x0090
117 #define TWL6030_BASEADD_PWM		0x00BA
118 #define TWL6030_BASEADD_GASGAUGE	0x00C0
119 #define TWL6030_BASEADD_PIH		0x00D0
120 #define TWL6030_BASEADD_CHARGER		0x00E0
121 #define TWL6032_BASEADD_CHARGER		0x00DA
122 #define TWL6030_BASEADD_LED		0x00F4
123 
124 /* subchip/slave 2 0x4A - DFT */
125 #define TWL6030_BASEADD_DIEID		0x00C0
126 
127 /* subchip/slave 3 0x4B - AUDIO */
128 #define TWL6030_BASEADD_AUDIO		0x0000
129 #define TWL6030_BASEADD_RSV		0x0000
130 #define TWL6030_BASEADD_ZERO		0x0000
131 
132 /* Few power values */
133 #define R_CFG_BOOT			0x05
134 
135 /* some fields in R_CFG_BOOT */
136 #define HFCLK_FREQ_19p2_MHZ		(1 << 0)
137 #define HFCLK_FREQ_26_MHZ		(2 << 0)
138 #define HFCLK_FREQ_38p4_MHZ		(3 << 0)
139 #define HIGH_PERF_SQ			(1 << 3)
140 #define CK32K_LOWPWR_EN			(1 << 7)
141 
142 /*----------------------------------------------------------------------*/
143 
144 /* Structure for each TWL4030/TWL6030 Slave */
145 struct twl_client {
146 	struct i2c_client *client;
147 	struct regmap *regmap;
148 };
149 
150 /* mapping the module id to slave id and base address */
151 struct twl_mapping {
152 	unsigned char sid;	/* Slave ID */
153 	unsigned char base;	/* base address */
154 };
155 
156 struct twl_private {
157 	bool ready; /* The core driver is ready to be used */
158 	u32 twl_idcode; /* TWL IDCODE Register value */
159 	unsigned int twl_id;
160 
161 	struct twl_mapping *twl_map;
162 	struct twl_client *twl_modules;
163 };
164 
165 static struct twl_private *twl_priv;
166 
167 static struct twl_mapping twl4030_map[] = {
168 	/*
169 	 * NOTE:  don't change this table without updating the
170 	 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
171 	 * so they continue to match the order in this table.
172 	 */
173 
174 	/* Common IPs */
175 	{ 0, TWL4030_BASEADD_USB },
176 	{ 1, TWL4030_BASEADD_PIH },
177 	{ 2, TWL4030_BASEADD_MAIN_CHARGE },
178 	{ 3, TWL4030_BASEADD_PM_MASTER },
179 	{ 3, TWL4030_BASEADD_PM_RECEIVER },
180 
181 	{ 3, TWL4030_BASEADD_RTC },
182 	{ 2, TWL4030_BASEADD_PWM },
183 	{ 2, TWL4030_BASEADD_LED },
184 	{ 3, TWL4030_BASEADD_SECURED_REG },
185 
186 	/* TWL4030 specific IPs */
187 	{ 1, TWL4030_BASEADD_AUDIO_VOICE },
188 	{ 1, TWL4030_BASEADD_GPIO },
189 	{ 1, TWL4030_BASEADD_INTBR },
190 	{ 1, TWL4030_BASEADD_TEST },
191 	{ 2, TWL4030_BASEADD_KEYPAD },
192 
193 	{ 2, TWL4030_BASEADD_MADC },
194 	{ 2, TWL4030_BASEADD_INTERRUPTS },
195 	{ 2, TWL4030_BASEADD_PRECHARGE },
196 	{ 3, TWL4030_BASEADD_BACKUP },
197 	{ 3, TWL4030_BASEADD_INT },
198 
199 	{ 2, TWL5031_BASEADD_ACCESSORY },
200 	{ 2, TWL5031_BASEADD_INTERRUPTS },
201 };
202 
203 static struct regmap_config twl4030_regmap_config[4] = {
204 	{
205 		/* Address 0x48 */
206 		.reg_bits = 8,
207 		.val_bits = 8,
208 		.max_register = 0xff,
209 	},
210 	{
211 		/* Address 0x49 */
212 		.reg_bits = 8,
213 		.val_bits = 8,
214 		.max_register = 0xff,
215 	},
216 	{
217 		/* Address 0x4a */
218 		.reg_bits = 8,
219 		.val_bits = 8,
220 		.max_register = 0xff,
221 	},
222 	{
223 		/* Address 0x4b */
224 		.reg_bits = 8,
225 		.val_bits = 8,
226 		.max_register = 0xff,
227 	},
228 };
229 
230 static struct twl_mapping twl6030_map[] = {
231 	/*
232 	 * NOTE:  don't change this table without updating the
233 	 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
234 	 * so they continue to match the order in this table.
235 	 */
236 
237 	/* Common IPs */
238 	{ 1, TWL6030_BASEADD_USB },
239 	{ 1, TWL6030_BASEADD_PIH },
240 	{ 1, TWL6030_BASEADD_CHARGER },
241 	{ 0, TWL6030_BASEADD_PM_MASTER },
242 	{ 0, TWL6030_BASEADD_PM_SLAVE_MISC },
243 
244 	{ 0, TWL6030_BASEADD_RTC },
245 	{ 1, TWL6030_BASEADD_PWM },
246 	{ 1, TWL6030_BASEADD_LED },
247 	{ 0, TWL6030_BASEADD_SECURED_REG },
248 
249 	/* TWL6030 specific IPs */
250 	{ 0, TWL6030_BASEADD_ZERO },
251 	{ 1, TWL6030_BASEADD_ZERO },
252 	{ 2, TWL6030_BASEADD_ZERO },
253 	{ 1, TWL6030_BASEADD_GPADC_CTRL },
254 	{ 1, TWL6030_BASEADD_GASGAUGE },
255 };
256 
257 static struct regmap_config twl6030_regmap_config[3] = {
258 	{
259 		/* Address 0x48 */
260 		.reg_bits = 8,
261 		.val_bits = 8,
262 		.max_register = 0xff,
263 	},
264 	{
265 		/* Address 0x49 */
266 		.reg_bits = 8,
267 		.val_bits = 8,
268 		.max_register = 0xff,
269 	},
270 	{
271 		/* Address 0x4a */
272 		.reg_bits = 8,
273 		.val_bits = 8,
274 		.max_register = 0xff,
275 	},
276 };
277 
278 /*----------------------------------------------------------------------*/
279 
280 static inline int twl_get_num_slaves(void)
281 {
282 	if (twl_class_is_4030())
283 		return 4; /* TWL4030 class have four slave address */
284 	else
285 		return 3; /* TWL6030 class have three slave address */
286 }
287 
288 static inline int twl_get_last_module(void)
289 {
290 	if (twl_class_is_4030())
291 		return TWL4030_MODULE_LAST;
292 	else
293 		return TWL6030_MODULE_LAST;
294 }
295 
296 /* Exported Functions */
297 
298 unsigned int twl_rev(void)
299 {
300 	return twl_priv ? twl_priv->twl_id : 0;
301 }
302 EXPORT_SYMBOL(twl_rev);
303 
304 /**
305  * twl_get_regmap - Get the regmap associated with the given module
306  * @mod_no: module number
307  *
308  * Returns the regmap pointer or NULL in case of failure.
309  */
310 static struct regmap *twl_get_regmap(u8 mod_no)
311 {
312 	int sid;
313 	struct twl_client *twl;
314 
315 	if (unlikely(!twl_priv || !twl_priv->ready)) {
316 		pr_err("%s: not initialized\n", DRIVER_NAME);
317 		return NULL;
318 	}
319 	if (unlikely(mod_no >= twl_get_last_module())) {
320 		pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
321 		return NULL;
322 	}
323 
324 	sid = twl_priv->twl_map[mod_no].sid;
325 	twl = &twl_priv->twl_modules[sid];
326 
327 	return twl->regmap;
328 }
329 
330 /**
331  * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
332  * @mod_no: module number
333  * @value: an array of num_bytes+1 containing data to write
334  * @reg: register address (just offset will do)
335  * @num_bytes: number of bytes to transfer
336  *
337  * Returns the result of operation - 0 is success
338  */
339 int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
340 {
341 	struct regmap *regmap = twl_get_regmap(mod_no);
342 	int ret;
343 
344 	if (!regmap)
345 		return -EPERM;
346 
347 	ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg,
348 				value, num_bytes);
349 
350 	if (ret)
351 		pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n",
352 		       DRIVER_NAME, mod_no, reg, num_bytes);
353 
354 	return ret;
355 }
356 EXPORT_SYMBOL(twl_i2c_write);
357 
358 /**
359  * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
360  * @mod_no: module number
361  * @value: an array of num_bytes containing data to be read
362  * @reg: register address (just offset will do)
363  * @num_bytes: number of bytes to transfer
364  *
365  * Returns result of operation - num_bytes is success else failure.
366  */
367 int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
368 {
369 	struct regmap *regmap = twl_get_regmap(mod_no);
370 	int ret;
371 
372 	if (!regmap)
373 		return -EPERM;
374 
375 	ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg,
376 			       value, num_bytes);
377 
378 	if (ret)
379 		pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n",
380 		       DRIVER_NAME, mod_no, reg, num_bytes);
381 
382 	return ret;
383 }
384 EXPORT_SYMBOL(twl_i2c_read);
385 
386 /**
387  * twl_regcache_bypass - Configure the regcache bypass for the regmap associated
388  *			 with the module
389  * @mod_no: module number
390  * @enable: Regcache bypass state
391  *
392  * Returns 0 else failure.
393  */
394 int twl_set_regcache_bypass(u8 mod_no, bool enable)
395 {
396 	struct regmap *regmap = twl_get_regmap(mod_no);
397 
398 	if (!regmap)
399 		return -EPERM;
400 
401 	regcache_cache_bypass(regmap, enable);
402 
403 	return 0;
404 }
405 EXPORT_SYMBOL(twl_set_regcache_bypass);
406 
407 /*----------------------------------------------------------------------*/
408 
409 /**
410  * twl_read_idcode_register - API to read the IDCODE register.
411  *
412  * Unlocks the IDCODE register and read the 32 bit value.
413  */
414 static int twl_read_idcode_register(void)
415 {
416 	int err;
417 
418 	err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK,
419 						REG_UNLOCK_TEST_REG);
420 	if (err) {
421 		pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err);
422 		goto fail;
423 	}
424 
425 	err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_priv->twl_idcode),
426 						REG_IDCODE_7_0, 4);
427 	if (err) {
428 		pr_err("TWL4030: unable to read IDCODE -%d\n", err);
429 		goto fail;
430 	}
431 
432 	err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG);
433 	if (err)
434 		pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err);
435 fail:
436 	return err;
437 }
438 
439 /**
440  * twl_get_type - API to get TWL Si type.
441  *
442  * Api to get the TWL Si type from IDCODE value.
443  */
444 int twl_get_type(void)
445 {
446 	return TWL_SIL_TYPE(twl_priv->twl_idcode);
447 }
448 EXPORT_SYMBOL_GPL(twl_get_type);
449 
450 /**
451  * twl_get_version - API to get TWL Si version.
452  *
453  * Api to get the TWL Si version from IDCODE value.
454  */
455 int twl_get_version(void)
456 {
457 	return TWL_SIL_REV(twl_priv->twl_idcode);
458 }
459 EXPORT_SYMBOL_GPL(twl_get_version);
460 
461 /**
462  * twl_get_hfclk_rate - API to get TWL external HFCLK clock rate.
463  *
464  * Api to get the TWL HFCLK rate based on BOOT_CFG register.
465  */
466 int twl_get_hfclk_rate(void)
467 {
468 	u8 ctrl;
469 	int rate;
470 
471 	twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &ctrl, R_CFG_BOOT);
472 
473 	switch (ctrl & 0x3) {
474 	case HFCLK_FREQ_19p2_MHZ:
475 		rate = 19200000;
476 		break;
477 	case HFCLK_FREQ_26_MHZ:
478 		rate = 26000000;
479 		break;
480 	case HFCLK_FREQ_38p4_MHZ:
481 		rate = 38400000;
482 		break;
483 	default:
484 		pr_err("TWL4030: HFCLK is not configured\n");
485 		rate = -EINVAL;
486 		break;
487 	}
488 
489 	return rate;
490 }
491 EXPORT_SYMBOL_GPL(twl_get_hfclk_rate);
492 
493 static struct device *
494 add_numbered_child(unsigned mod_no, const char *name, int num,
495 		void *pdata, unsigned pdata_len,
496 		bool can_wakeup, int irq0, int irq1)
497 {
498 	struct platform_device	*pdev;
499 	struct twl_client	*twl;
500 	int			status, sid;
501 
502 	if (unlikely(mod_no >= twl_get_last_module())) {
503 		pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
504 		return ERR_PTR(-EPERM);
505 	}
506 	sid = twl_priv->twl_map[mod_no].sid;
507 	twl = &twl_priv->twl_modules[sid];
508 
509 	pdev = platform_device_alloc(name, num);
510 	if (!pdev) {
511 		dev_dbg(&twl->client->dev, "can't alloc dev\n");
512 		status = -ENOMEM;
513 		goto err;
514 	}
515 
516 	pdev->dev.parent = &twl->client->dev;
517 
518 	if (pdata) {
519 		status = platform_device_add_data(pdev, pdata, pdata_len);
520 		if (status < 0) {
521 			dev_dbg(&pdev->dev, "can't add platform_data\n");
522 			goto err;
523 		}
524 	}
525 
526 	if (irq0) {
527 		struct resource r[2] = {
528 			{ .start = irq0, .flags = IORESOURCE_IRQ, },
529 			{ .start = irq1, .flags = IORESOURCE_IRQ, },
530 		};
531 
532 		status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1);
533 		if (status < 0) {
534 			dev_dbg(&pdev->dev, "can't add irqs\n");
535 			goto err;
536 		}
537 	}
538 
539 	status = platform_device_add(pdev);
540 	if (status == 0)
541 		device_init_wakeup(&pdev->dev, can_wakeup);
542 
543 err:
544 	if (status < 0) {
545 		platform_device_put(pdev);
546 		dev_err(&twl->client->dev, "can't add %s dev\n", name);
547 		return ERR_PTR(status);
548 	}
549 	return &pdev->dev;
550 }
551 
552 static inline struct device *add_child(unsigned mod_no, const char *name,
553 		void *pdata, unsigned pdata_len,
554 		bool can_wakeup, int irq0, int irq1)
555 {
556 	return add_numbered_child(mod_no, name, -1, pdata, pdata_len,
557 		can_wakeup, irq0, irq1);
558 }
559 
560 static struct device *
561 add_regulator_linked(int num, struct regulator_init_data *pdata,
562 		struct regulator_consumer_supply *consumers,
563 		unsigned num_consumers, unsigned long features)
564 {
565 	struct twl_regulator_driver_data drv_data;
566 
567 	/* regulator framework demands init_data ... */
568 	if (!pdata)
569 		return NULL;
570 
571 	if (consumers) {
572 		pdata->consumer_supplies = consumers;
573 		pdata->num_consumer_supplies = num_consumers;
574 	}
575 
576 	if (pdata->driver_data) {
577 		/* If we have existing drv_data, just add the flags */
578 		struct twl_regulator_driver_data *tmp;
579 		tmp = pdata->driver_data;
580 		tmp->features |= features;
581 	} else {
582 		/* add new driver data struct, used only during init */
583 		drv_data.features = features;
584 		drv_data.set_voltage = NULL;
585 		drv_data.get_voltage = NULL;
586 		drv_data.data = NULL;
587 		pdata->driver_data = &drv_data;
588 	}
589 
590 	/* NOTE:  we currently ignore regulator IRQs, e.g. for short circuits */
591 	return add_numbered_child(TWL_MODULE_PM_MASTER, "twl_reg", num,
592 		pdata, sizeof(*pdata), false, 0, 0);
593 }
594 
595 static struct device *
596 add_regulator(int num, struct regulator_init_data *pdata,
597 		unsigned long features)
598 {
599 	return add_regulator_linked(num, pdata, NULL, 0, features);
600 }
601 
602 /*
603  * NOTE:  We know the first 8 IRQs after pdata->base_irq are
604  * for the PIH, and the next are for the PWR_INT SIH, since
605  * that's how twl_init_irq() sets things up.
606  */
607 
608 static int
609 add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
610 		unsigned long features)
611 {
612 	struct device	*child;
613 
614 	if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) {
615 		child = add_child(TWL4030_MODULE_GPIO, "twl4030_gpio",
616 				pdata->gpio, sizeof(*pdata->gpio),
617 				false, irq_base + GPIO_INTR_OFFSET, 0);
618 		if (IS_ERR(child))
619 			return PTR_ERR(child);
620 	}
621 
622 	if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) {
623 		child = add_child(TWL4030_MODULE_KEYPAD, "twl4030_keypad",
624 				pdata->keypad, sizeof(*pdata->keypad),
625 				true, irq_base + KEYPAD_INTR_OFFSET, 0);
626 		if (IS_ERR(child))
627 			return PTR_ERR(child);
628 	}
629 
630 	if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc &&
631 	    twl_class_is_4030()) {
632 		child = add_child(TWL4030_MODULE_MADC, "twl4030_madc",
633 				pdata->madc, sizeof(*pdata->madc),
634 				true, irq_base + MADC_INTR_OFFSET, 0);
635 		if (IS_ERR(child))
636 			return PTR_ERR(child);
637 	}
638 
639 	if (IS_ENABLED(CONFIG_RTC_DRV_TWL4030)) {
640 		/*
641 		 * REVISIT platform_data here currently might expose the
642 		 * "msecure" line ... but for now we just expect board
643 		 * setup to tell the chip "it's always ok to SET_TIME".
644 		 * Eventually, Linux might become more aware of such
645 		 * HW security concerns, and "least privilege".
646 		 */
647 		child = add_child(TWL_MODULE_RTC, "twl_rtc", NULL, 0,
648 				true, irq_base + RTC_INTR_OFFSET, 0);
649 		if (IS_ERR(child))
650 			return PTR_ERR(child);
651 	}
652 
653 	if (IS_ENABLED(CONFIG_PWM_TWL)) {
654 		child = add_child(TWL_MODULE_PWM, "twl-pwm", NULL, 0,
655 				  false, 0, 0);
656 		if (IS_ERR(child))
657 			return PTR_ERR(child);
658 	}
659 
660 	if (IS_ENABLED(CONFIG_PWM_TWL_LED)) {
661 		child = add_child(TWL_MODULE_LED, "twl-pwmled", NULL, 0,
662 				  false, 0, 0);
663 		if (IS_ERR(child))
664 			return PTR_ERR(child);
665 	}
666 
667 	if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb &&
668 	    twl_class_is_4030()) {
669 
670 		static struct regulator_consumer_supply usb1v5 = {
671 			.supply =	"usb1v5",
672 		};
673 		static struct regulator_consumer_supply usb1v8 = {
674 			.supply =	"usb1v8",
675 		};
676 		static struct regulator_consumer_supply usb3v1[] = {
677 			{ .supply =	"usb3v1" },
678 			{ .supply =	"bci3v1" },
679 		};
680 
681 	/* First add the regulators so that they can be used by transceiver */
682 		if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) {
683 			/* this is a template that gets copied */
684 			struct regulator_init_data usb_fixed = {
685 				.constraints.valid_modes_mask =
686 					REGULATOR_MODE_NORMAL
687 					| REGULATOR_MODE_STANDBY,
688 				.constraints.valid_ops_mask =
689 					REGULATOR_CHANGE_MODE
690 					| REGULATOR_CHANGE_STATUS,
691 			};
692 
693 			child = add_regulator_linked(TWL4030_REG_VUSB1V5,
694 						      &usb_fixed, &usb1v5, 1,
695 						      features);
696 			if (IS_ERR(child))
697 				return PTR_ERR(child);
698 
699 			child = add_regulator_linked(TWL4030_REG_VUSB1V8,
700 						      &usb_fixed, &usb1v8, 1,
701 						      features);
702 			if (IS_ERR(child))
703 				return PTR_ERR(child);
704 
705 			child = add_regulator_linked(TWL4030_REG_VUSB3V1,
706 						      &usb_fixed, usb3v1, 2,
707 						      features);
708 			if (IS_ERR(child))
709 				return PTR_ERR(child);
710 
711 		}
712 
713 		child = add_child(TWL_MODULE_USB, "twl4030_usb",
714 				pdata->usb, sizeof(*pdata->usb), true,
715 				/* irq0 = USB_PRES, irq1 = USB */
716 				irq_base + USB_PRES_INTR_OFFSET,
717 				irq_base + USB_INTR_OFFSET);
718 
719 		if (IS_ERR(child))
720 			return PTR_ERR(child);
721 
722 		/* we need to connect regulators to this transceiver */
723 		if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) {
724 			usb1v5.dev_name = dev_name(child);
725 			usb1v8.dev_name = dev_name(child);
726 			usb3v1[0].dev_name = dev_name(child);
727 		}
728 	}
729 	if (IS_ENABLED(CONFIG_TWL6030_USB) && pdata->usb &&
730 	    twl_class_is_6030()) {
731 
732 		static struct regulator_consumer_supply usb3v3;
733 		int regulator;
734 
735 		if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) {
736 			/* this is a template that gets copied */
737 			struct regulator_init_data usb_fixed = {
738 				.constraints.valid_modes_mask =
739 					REGULATOR_MODE_NORMAL
740 					| REGULATOR_MODE_STANDBY,
741 				.constraints.valid_ops_mask =
742 					REGULATOR_CHANGE_MODE
743 					| REGULATOR_CHANGE_STATUS,
744 			};
745 
746 			if (features & TWL6032_SUBCLASS) {
747 				usb3v3.supply =	"ldousb";
748 				regulator = TWL6032_REG_LDOUSB;
749 			} else {
750 				usb3v3.supply = "vusb";
751 				regulator = TWL6030_REG_VUSB;
752 			}
753 			child = add_regulator_linked(regulator, &usb_fixed,
754 							&usb3v3, 1,
755 							features);
756 			if (IS_ERR(child))
757 				return PTR_ERR(child);
758 		}
759 
760 		pdata->usb->features = features;
761 
762 		child = add_child(TWL_MODULE_USB, "twl6030_usb",
763 			pdata->usb, sizeof(*pdata->usb), true,
764 			/* irq1 = VBUS_PRES, irq0 = USB ID */
765 			irq_base + USBOTG_INTR_OFFSET,
766 			irq_base + USB_PRES_INTR_OFFSET);
767 
768 		if (IS_ERR(child))
769 			return PTR_ERR(child);
770 		/* we need to connect regulators to this transceiver */
771 		if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child)
772 			usb3v3.dev_name = dev_name(child);
773 	} else if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) &&
774 		   twl_class_is_6030()) {
775 		if (features & TWL6032_SUBCLASS)
776 			child = add_regulator(TWL6032_REG_LDOUSB,
777 						pdata->ldousb, features);
778 		else
779 			child = add_regulator(TWL6030_REG_VUSB,
780 						pdata->vusb, features);
781 
782 			if (IS_ERR(child))
783 					return PTR_ERR(child);
784 	}
785 
786 	if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) {
787 		child = add_child(TWL_MODULE_PM_RECEIVER, "twl4030_wdt", NULL,
788 				  0, false, 0, 0);
789 		if (IS_ERR(child))
790 			return PTR_ERR(child);
791 	}
792 
793 	if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) {
794 		child = add_child(TWL_MODULE_PM_MASTER, "twl4030_pwrbutton",
795 				  NULL, 0, true, irq_base + 8 + 0, 0);
796 		if (IS_ERR(child))
797 			return PTR_ERR(child);
798 	}
799 
800 	if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio &&
801 	    twl_class_is_4030()) {
802 		child = add_child(TWL4030_MODULE_AUDIO_VOICE, "twl4030-audio",
803 				pdata->audio, sizeof(*pdata->audio),
804 				false, 0, 0);
805 		if (IS_ERR(child))
806 			return PTR_ERR(child);
807 	}
808 
809 	/* twl4030 regulators */
810 	if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_4030()) {
811 		child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
812 					features);
813 		if (IS_ERR(child))
814 			return PTR_ERR(child);
815 
816 		child = add_regulator(TWL4030_REG_VIO, pdata->vio,
817 					features);
818 		if (IS_ERR(child))
819 			return PTR_ERR(child);
820 
821 		child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1,
822 					features);
823 		if (IS_ERR(child))
824 			return PTR_ERR(child);
825 
826 		child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2,
827 					features);
828 		if (IS_ERR(child))
829 			return PTR_ERR(child);
830 
831 		child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1,
832 					features);
833 		if (IS_ERR(child))
834 			return PTR_ERR(child);
835 
836 		child = add_regulator(TWL4030_REG_VDAC, pdata->vdac,
837 					features);
838 		if (IS_ERR(child))
839 			return PTR_ERR(child);
840 
841 		child = add_regulator((features & TWL4030_VAUX2)
842 					? TWL4030_REG_VAUX2_4030
843 					: TWL4030_REG_VAUX2,
844 				pdata->vaux2, features);
845 		if (IS_ERR(child))
846 			return PTR_ERR(child);
847 
848 		child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1,
849 					features);
850 		if (IS_ERR(child))
851 			return PTR_ERR(child);
852 
853 		child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2,
854 					features);
855 		if (IS_ERR(child))
856 			return PTR_ERR(child);
857 
858 		child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig,
859 					features);
860 		if (IS_ERR(child))
861 			return PTR_ERR(child);
862 	}
863 
864 	/* maybe add LDOs that are omitted on cost-reduced parts */
865 	if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && !(features & TPS_SUBSET)
866 	  && twl_class_is_4030()) {
867 		child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2,
868 					features);
869 		if (IS_ERR(child))
870 			return PTR_ERR(child);
871 
872 		child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2,
873 					features);
874 		if (IS_ERR(child))
875 			return PTR_ERR(child);
876 
877 		child = add_regulator(TWL4030_REG_VSIM, pdata->vsim,
878 					features);
879 		if (IS_ERR(child))
880 			return PTR_ERR(child);
881 
882 		child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1,
883 					features);
884 		if (IS_ERR(child))
885 			return PTR_ERR(child);
886 
887 		child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3,
888 					features);
889 		if (IS_ERR(child))
890 			return PTR_ERR(child);
891 
892 		child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4,
893 					features);
894 		if (IS_ERR(child))
895 			return PTR_ERR(child);
896 	}
897 
898 	/* twl6030 regulators */
899 	if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030() &&
900 			!(features & TWL6032_SUBCLASS)) {
901 		child = add_regulator(TWL6030_REG_VDD1, pdata->vdd1,
902 					features);
903 		if (IS_ERR(child))
904 			return PTR_ERR(child);
905 
906 		child = add_regulator(TWL6030_REG_VDD2, pdata->vdd2,
907 					features);
908 		if (IS_ERR(child))
909 			return PTR_ERR(child);
910 
911 		child = add_regulator(TWL6030_REG_VDD3, pdata->vdd3,
912 					features);
913 		if (IS_ERR(child))
914 			return PTR_ERR(child);
915 
916 		child = add_regulator(TWL6030_REG_V1V8, pdata->v1v8,
917 					features);
918 		if (IS_ERR(child))
919 			return PTR_ERR(child);
920 
921 		child = add_regulator(TWL6030_REG_V2V1, pdata->v2v1,
922 					features);
923 		if (IS_ERR(child))
924 			return PTR_ERR(child);
925 
926 		child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc,
927 					features);
928 		if (IS_ERR(child))
929 			return PTR_ERR(child);
930 
931 		child = add_regulator(TWL6030_REG_VPP, pdata->vpp,
932 					features);
933 		if (IS_ERR(child))
934 			return PTR_ERR(child);
935 
936 		child = add_regulator(TWL6030_REG_VUSIM, pdata->vusim,
937 					features);
938 		if (IS_ERR(child))
939 			return PTR_ERR(child);
940 
941 		child = add_regulator(TWL6030_REG_VCXIO, pdata->vcxio,
942 					features);
943 		if (IS_ERR(child))
944 			return PTR_ERR(child);
945 
946 		child = add_regulator(TWL6030_REG_VDAC, pdata->vdac,
947 					features);
948 		if (IS_ERR(child))
949 			return PTR_ERR(child);
950 
951 		child = add_regulator(TWL6030_REG_VAUX1_6030, pdata->vaux1,
952 					features);
953 		if (IS_ERR(child))
954 			return PTR_ERR(child);
955 
956 		child = add_regulator(TWL6030_REG_VAUX2_6030, pdata->vaux2,
957 					features);
958 		if (IS_ERR(child))
959 			return PTR_ERR(child);
960 
961 		child = add_regulator(TWL6030_REG_VAUX3_6030, pdata->vaux3,
962 					features);
963 		if (IS_ERR(child))
964 			return PTR_ERR(child);
965 
966 		child = add_regulator(TWL6030_REG_CLK32KG, pdata->clk32kg,
967 					features);
968 		if (IS_ERR(child))
969 			return PTR_ERR(child);
970 	}
971 
972 	/* 6030 and 6025 share this regulator */
973 	if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030()) {
974 		child = add_regulator(TWL6030_REG_VANA, pdata->vana,
975 					features);
976 		if (IS_ERR(child))
977 			return PTR_ERR(child);
978 	}
979 
980 	/* twl6032 regulators */
981 	if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030() &&
982 			(features & TWL6032_SUBCLASS)) {
983 		child = add_regulator(TWL6032_REG_LDO5, pdata->ldo5,
984 					features);
985 		if (IS_ERR(child))
986 			return PTR_ERR(child);
987 
988 		child = add_regulator(TWL6032_REG_LDO1, pdata->ldo1,
989 					features);
990 		if (IS_ERR(child))
991 			return PTR_ERR(child);
992 
993 		child = add_regulator(TWL6032_REG_LDO7, pdata->ldo7,
994 					features);
995 		if (IS_ERR(child))
996 			return PTR_ERR(child);
997 
998 		child = add_regulator(TWL6032_REG_LDO6, pdata->ldo6,
999 					features);
1000 		if (IS_ERR(child))
1001 			return PTR_ERR(child);
1002 
1003 		child = add_regulator(TWL6032_REG_LDOLN, pdata->ldoln,
1004 					features);
1005 		if (IS_ERR(child))
1006 			return PTR_ERR(child);
1007 
1008 		child = add_regulator(TWL6032_REG_LDO2, pdata->ldo2,
1009 					features);
1010 		if (IS_ERR(child))
1011 			return PTR_ERR(child);
1012 
1013 		child = add_regulator(TWL6032_REG_LDO4, pdata->ldo4,
1014 					features);
1015 		if (IS_ERR(child))
1016 			return PTR_ERR(child);
1017 
1018 		child = add_regulator(TWL6032_REG_LDO3, pdata->ldo3,
1019 					features);
1020 		if (IS_ERR(child))
1021 			return PTR_ERR(child);
1022 
1023 		child = add_regulator(TWL6032_REG_SMPS3, pdata->smps3,
1024 					features);
1025 		if (IS_ERR(child))
1026 			return PTR_ERR(child);
1027 
1028 		child = add_regulator(TWL6032_REG_SMPS4, pdata->smps4,
1029 					features);
1030 		if (IS_ERR(child))
1031 			return PTR_ERR(child);
1032 
1033 		child = add_regulator(TWL6032_REG_VIO, pdata->vio6025,
1034 					features);
1035 		if (IS_ERR(child))
1036 			return PTR_ERR(child);
1037 
1038 	}
1039 
1040 	if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci &&
1041 			!(features & (TPS_SUBSET | TWL5031))) {
1042 		child = add_child(TWL_MODULE_MAIN_CHARGE, "twl4030_bci",
1043 				pdata->bci, sizeof(*pdata->bci), false,
1044 				/* irq0 = CHG_PRES, irq1 = BCI */
1045 				irq_base + BCI_PRES_INTR_OFFSET,
1046 				irq_base + BCI_INTR_OFFSET);
1047 		if (IS_ERR(child))
1048 			return PTR_ERR(child);
1049 	}
1050 
1051 	if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power) {
1052 		child = add_child(TWL_MODULE_PM_MASTER, "twl4030_power",
1053 				  pdata->power, sizeof(*pdata->power), false,
1054 				  0, 0);
1055 		if (IS_ERR(child))
1056 			return PTR_ERR(child);
1057 	}
1058 
1059 	return 0;
1060 }
1061 
1062 /*----------------------------------------------------------------------*/
1063 
1064 /*
1065  * These three functions initialize the on-chip clock framework,
1066  * letting it generate the right frequencies for USB, MADC, and
1067  * other purposes.
1068  */
1069 static inline int __init protect_pm_master(void)
1070 {
1071 	int e = 0;
1072 
1073 	e = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
1074 			     TWL4030_PM_MASTER_PROTECT_KEY);
1075 	return e;
1076 }
1077 
1078 static inline int __init unprotect_pm_master(void)
1079 {
1080 	int e = 0;
1081 
1082 	e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
1083 			      TWL4030_PM_MASTER_PROTECT_KEY);
1084 	e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG2,
1085 			      TWL4030_PM_MASTER_PROTECT_KEY);
1086 
1087 	return e;
1088 }
1089 
1090 static void clocks_init(struct device *dev,
1091 			struct twl4030_clock_init_data *clock)
1092 {
1093 	int e = 0;
1094 	struct clk *osc;
1095 	u32 rate;
1096 	u8 ctrl = HFCLK_FREQ_26_MHZ;
1097 
1098 	osc = clk_get(dev, "fck");
1099 	if (IS_ERR(osc)) {
1100 		printk(KERN_WARNING "Skipping twl internal clock init and "
1101 				"using bootloader value (unknown osc rate)\n");
1102 		return;
1103 	}
1104 
1105 	rate = clk_get_rate(osc);
1106 	clk_put(osc);
1107 
1108 	switch (rate) {
1109 	case 19200000:
1110 		ctrl = HFCLK_FREQ_19p2_MHZ;
1111 		break;
1112 	case 26000000:
1113 		ctrl = HFCLK_FREQ_26_MHZ;
1114 		break;
1115 	case 38400000:
1116 		ctrl = HFCLK_FREQ_38p4_MHZ;
1117 		break;
1118 	}
1119 
1120 	ctrl |= HIGH_PERF_SQ;
1121 	if (clock && clock->ck32k_lowpwr_enable)
1122 		ctrl |= CK32K_LOWPWR_EN;
1123 
1124 	e |= unprotect_pm_master();
1125 	/* effect->MADC+USB ck en */
1126 	e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
1127 	e |= protect_pm_master();
1128 
1129 	if (e < 0)
1130 		pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
1131 }
1132 
1133 /*----------------------------------------------------------------------*/
1134 
1135 
1136 static int twl_remove(struct i2c_client *client)
1137 {
1138 	unsigned i, num_slaves;
1139 	int status;
1140 
1141 	if (twl_class_is_4030())
1142 		status = twl4030_exit_irq();
1143 	else
1144 		status = twl6030_exit_irq();
1145 
1146 	if (status < 0)
1147 		return status;
1148 
1149 	num_slaves = twl_get_num_slaves();
1150 	for (i = 0; i < num_slaves; i++) {
1151 		struct twl_client	*twl = &twl_priv->twl_modules[i];
1152 
1153 		if (twl->client && twl->client != client)
1154 			i2c_unregister_device(twl->client);
1155 		twl->client = NULL;
1156 	}
1157 	twl_priv->ready = false;
1158 	return 0;
1159 }
1160 
1161 /* NOTE: This driver only handles a single twl4030/tps659x0 chip */
1162 static int
1163 twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
1164 {
1165 	struct twl4030_platform_data	*pdata = dev_get_platdata(&client->dev);
1166 	struct device_node		*node = client->dev.of_node;
1167 	struct platform_device		*pdev;
1168 	struct regmap_config		*twl_regmap_config;
1169 	int				irq_base = 0;
1170 	int				status;
1171 	unsigned			i, num_slaves;
1172 
1173 	if (!node && !pdata) {
1174 		dev_err(&client->dev, "no platform data\n");
1175 		return -EINVAL;
1176 	}
1177 
1178 	if (twl_priv) {
1179 		dev_dbg(&client->dev, "only one instance of %s allowed\n",
1180 			DRIVER_NAME);
1181 		return -EBUSY;
1182 	}
1183 
1184 	pdev = platform_device_alloc(DRIVER_NAME, -1);
1185 	if (!pdev) {
1186 		dev_err(&client->dev, "can't alloc pdev\n");
1187 		return -ENOMEM;
1188 	}
1189 
1190 	status = platform_device_add(pdev);
1191 	if (status) {
1192 		platform_device_put(pdev);
1193 		return status;
1194 	}
1195 
1196 	if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1197 		dev_dbg(&client->dev, "can't talk I2C?\n");
1198 		status = -EIO;
1199 		goto free;
1200 	}
1201 
1202 	twl_priv = devm_kzalloc(&client->dev, sizeof(struct twl_private),
1203 				GFP_KERNEL);
1204 	if (!twl_priv) {
1205 		status = -ENOMEM;
1206 		goto free;
1207 	}
1208 
1209 	if ((id->driver_data) & TWL6030_CLASS) {
1210 		twl_priv->twl_id = TWL6030_CLASS_ID;
1211 		twl_priv->twl_map = &twl6030_map[0];
1212 		/* The charger base address is different in twl6032 */
1213 		if ((id->driver_data) & TWL6032_SUBCLASS)
1214 			twl_priv->twl_map[TWL_MODULE_MAIN_CHARGE].base =
1215 							TWL6032_BASEADD_CHARGER;
1216 		twl_regmap_config = twl6030_regmap_config;
1217 	} else {
1218 		twl_priv->twl_id = TWL4030_CLASS_ID;
1219 		twl_priv->twl_map = &twl4030_map[0];
1220 		twl_regmap_config = twl4030_regmap_config;
1221 	}
1222 
1223 	num_slaves = twl_get_num_slaves();
1224 	twl_priv->twl_modules = devm_kzalloc(&client->dev,
1225 					 sizeof(struct twl_client) * num_slaves,
1226 					 GFP_KERNEL);
1227 	if (!twl_priv->twl_modules) {
1228 		status = -ENOMEM;
1229 		goto free;
1230 	}
1231 
1232 	for (i = 0; i < num_slaves; i++) {
1233 		struct twl_client *twl = &twl_priv->twl_modules[i];
1234 
1235 		if (i == 0) {
1236 			twl->client = client;
1237 		} else {
1238 			twl->client = i2c_new_dummy(client->adapter,
1239 						    client->addr + i);
1240 			if (!twl->client) {
1241 				dev_err(&client->dev,
1242 					"can't attach client %d\n", i);
1243 				status = -ENOMEM;
1244 				goto fail;
1245 			}
1246 		}
1247 
1248 		twl->regmap = devm_regmap_init_i2c(twl->client,
1249 						   &twl_regmap_config[i]);
1250 		if (IS_ERR(twl->regmap)) {
1251 			status = PTR_ERR(twl->regmap);
1252 			dev_err(&client->dev,
1253 				"Failed to allocate regmap %d, err: %d\n", i,
1254 				status);
1255 			goto fail;
1256 		}
1257 	}
1258 
1259 	twl_priv->ready = true;
1260 
1261 	/* setup clock framework */
1262 	clocks_init(&pdev->dev, pdata ? pdata->clock : NULL);
1263 
1264 	/* read TWL IDCODE Register */
1265 	if (twl_class_is_4030()) {
1266 		status = twl_read_idcode_register();
1267 		WARN(status < 0, "Error: reading twl_idcode register value\n");
1268 	}
1269 
1270 	/* Maybe init the T2 Interrupt subsystem */
1271 	if (client->irq) {
1272 		if (twl_class_is_4030()) {
1273 			twl4030_init_chip_irq(id->name);
1274 			irq_base = twl4030_init_irq(&client->dev, client->irq);
1275 		} else {
1276 			irq_base = twl6030_init_irq(&client->dev, client->irq);
1277 		}
1278 
1279 		if (irq_base < 0) {
1280 			status = irq_base;
1281 			goto fail;
1282 		}
1283 	}
1284 
1285 	/*
1286 	 * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
1287 	 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
1288 	 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
1289 	 */
1290 	if (twl_class_is_4030()) {
1291 		u8 temp;
1292 
1293 		twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
1294 		temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
1295 			I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
1296 		twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
1297 	}
1298 
1299 	if (node)
1300 		status = of_platform_populate(node, NULL, NULL, &client->dev);
1301 	else
1302 		status = add_children(pdata, irq_base, id->driver_data);
1303 
1304 fail:
1305 	if (status < 0)
1306 		twl_remove(client);
1307 free:
1308 	if (status < 0)
1309 		platform_device_unregister(pdev);
1310 
1311 	return status;
1312 }
1313 
1314 static const struct i2c_device_id twl_ids[] = {
1315 	{ "twl4030", TWL4030_VAUX2 },	/* "Triton 2" */
1316 	{ "twl5030", 0 },		/* T2 updated */
1317 	{ "twl5031", TWL5031 },		/* TWL5030 updated */
1318 	{ "tps65950", 0 },		/* catalog version of twl5030 */
1319 	{ "tps65930", TPS_SUBSET },	/* fewer LDOs and DACs; no charger */
1320 	{ "tps65920", TPS_SUBSET },	/* fewer LDOs; no codec or charger */
1321 	{ "tps65921", TPS_SUBSET },	/* fewer LDOs; no codec, no LED
1322 					   and vibrator. Charger in USB module*/
1323 	{ "twl6030", TWL6030_CLASS },	/* "Phoenix power chip" */
1324 	{ "twl6032", TWL6030_CLASS | TWL6032_SUBCLASS }, /* "Phoenix lite" */
1325 	{ /* end of list */ },
1326 };
1327 MODULE_DEVICE_TABLE(i2c, twl_ids);
1328 
1329 /* One Client Driver , 4 Clients */
1330 static struct i2c_driver twl_driver = {
1331 	.driver.name	= DRIVER_NAME,
1332 	.id_table	= twl_ids,
1333 	.probe		= twl_probe,
1334 	.remove		= twl_remove,
1335 };
1336 
1337 module_i2c_driver(twl_driver);
1338 
1339 MODULE_AUTHOR("Texas Instruments, Inc.");
1340 MODULE_DESCRIPTION("I2C Core interface for TWL");
1341 MODULE_LICENSE("GPL");
1342