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