blob: 806680d1bbb4ec84237eaea15dbe645122dd91ea [file] [log] [blame]
David Brownella603a7f2008-10-15 12:15:39 +02001/*
Balaji T Kfc7b92f2009-12-13 21:23:33 +01002 * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM
3 * and audio CODEC devices
David Brownella603a7f2008-10-15 12:15:39 +02004 *
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
David Brownella603a7f2008-10-15 12:15:39 +020031#include <linux/init.h>
32#include <linux/mutex.h>
Paul Gortmaker4e36dd32011-07-03 15:13:27 -040033#include <linux/module.h>
David Brownella603a7f2008-10-15 12:15:39 +020034#include <linux/platform_device.h>
35#include <linux/clk.h>
David Brownella30d46c2008-10-20 23:46:28 +020036#include <linux/err.h>
Benoit Coussonaeb50322011-08-29 16:20:23 +020037#include <linux/device.h>
38#include <linux/of.h>
39#include <linux/of_irq.h>
40#include <linux/of_platform.h>
Grant Likelye7cc3ac2012-03-02 21:05:31 -070041#include <linux/irq.h>
Benoit Coussonaeb50322011-08-29 16:20:23 +020042#include <linux/irqdomain.h>
David Brownella603a7f2008-10-15 12:15:39 +020043
David Brownelldad759f2008-12-01 00:43:58 +010044#include <linux/regulator/machine.h>
45
David Brownella603a7f2008-10-15 12:15:39 +020046#include <linux/i2c.h>
Santosh Shilimkarb07682b2009-12-13 20:05:51 +010047#include <linux/i2c/twl.h>
David Brownella603a7f2008-10-15 12:15:39 +020048
Mark Browna313d752009-02-04 21:26:07 +010049#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgrence491cf2009-10-20 09:40:47 -070050#include <plat/cpu.h>
Samuel Ortizb29c06a2009-01-11 01:21:48 +010051#endif
David Brownella603a7f2008-10-15 12:15:39 +020052
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
Balaji T Kfc7b92f2009-12-13 21:23:33 +010066#define DRIVER_NAME "twl"
David Brownella603a7f2008-10-15 12:15:39 +020067
David Brownella603a7f2008-10-15 12:15:39 +020068#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
David Brownelldad759f2008-12-01 00:43:58 +010080#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
David Brownella603a7f2008-10-15 12:15:39 +020087#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
Amit Kucheriaebf0bd32009-08-31 18:32:18 +020093#ifdef CONFIG_TWL4030_POWER
94#define twl_has_power() true
95#else
96#define twl_has_power() false
97#endif
98
David Brownella603a7f2008-10-15 12:15:39 +020099#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
Hema HKe70357e2010-12-10 18:09:52 +0530105#if defined(CONFIG_TWL4030_USB) || defined(CONFIG_TWL4030_USB_MODULE) ||\
106 defined(CONFIG_TWL6030_USB) || defined(CONFIG_TWL6030_USB_MODULE)
David Brownella603a7f2008-10-15 12:15:39 +0200107#define twl_has_usb() true
108#else
109#define twl_has_usb() false
110#endif
111
Timo Kokkonen80e45b12009-03-27 16:42:17 +0200112#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
David Brownella603a7f2008-10-15 12:15:39 +0200118
Thomas Weberf09ee042011-09-05 11:26:33 +0200119#if defined(CONFIG_MFD_TWL4030_AUDIO) || defined(CONFIG_MFD_TWL4030_AUDIO_MODULE) ||\
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500120 defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE)
Peter Ujfalusi0b83dde2009-10-22 13:26:45 +0300121#define twl_has_codec() true
122#else
123#define twl_has_codec() false
124#endif
125
Grazvydas Ignotas11c39c42010-10-01 13:17:50 +0300126#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
David Brownella603a7f2008-10-15 12:15:39 +0200132/* Triton Core internal information (BEGIN) */
133
134/* Last - for index max*/
135#define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
136
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100137#define TWL_NUM_SLAVES 4
David Brownella603a7f2008-10-15 12:15:39 +0200138
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200139#if defined(CONFIG_INPUT_TWL4030_PWRBUTTON) \
Eduardo Valentin14e5c822010-02-11 13:47:09 +0100140 || defined(CONFIG_INPUT_TWL4030_PWRBUTTON_MODULE)
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200141#define twl_has_pwrbutton() true
142#else
143#define twl_has_pwrbutton() false
144#endif
David Brownella603a7f2008-10-15 12:15:39 +0200145
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100146#define SUB_CHIP_ID0 0
147#define SUB_CHIP_ID1 1
148#define SUB_CHIP_ID2 2
149#define SUB_CHIP_ID3 3
150
151#define TWL_MODULE_LAST TWL4030_MODULE_LAST
152
Benoit Cousson57690892012-02-14 14:06:56 -0700153#define TWL4030_NR_IRQS 34 /* core:8, power:8, gpio: 18 */
Benoit Coussonaeb50322011-08-29 16:20:23 +0200154#define TWL6030_NR_IRQS 20
155
David Brownella603a7f2008-10-15 12:15:39 +0200156/* Base Address defns for twl4030_map[] */
157
158/* subchip/slave 0 - USB ID */
159#define TWL4030_BASEADD_USB 0x0000
160
161/* subchip/slave 1 - AUD ID */
162#define TWL4030_BASEADD_AUDIO_VOICE 0x0000
163#define TWL4030_BASEADD_GPIO 0x0098
164#define TWL4030_BASEADD_INTBR 0x0085
165#define TWL4030_BASEADD_PIH 0x0080
166#define TWL4030_BASEADD_TEST 0x004C
167
168/* subchip/slave 2 - AUX ID */
169#define TWL4030_BASEADD_INTERRUPTS 0x00B9
170#define TWL4030_BASEADD_LED 0x00EE
171#define TWL4030_BASEADD_MADC 0x0000
172#define TWL4030_BASEADD_MAIN_CHARGE 0x0074
173#define TWL4030_BASEADD_PRECHARGE 0x00AA
174#define TWL4030_BASEADD_PWM0 0x00F8
175#define TWL4030_BASEADD_PWM1 0x00FB
176#define TWL4030_BASEADD_PWMA 0x00EF
177#define TWL4030_BASEADD_PWMB 0x00F1
178#define TWL4030_BASEADD_KEYPAD 0x00D2
179
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200180#define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */
181#define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's
182 one */
183
David Brownella603a7f2008-10-15 12:15:39 +0200184/* subchip/slave 3 - POWER ID */
185#define TWL4030_BASEADD_BACKUP 0x0014
186#define TWL4030_BASEADD_INT 0x002E
187#define TWL4030_BASEADD_PM_MASTER 0x0036
188#define TWL4030_BASEADD_PM_RECEIVER 0x005B
189#define TWL4030_BASEADD_RTC 0x001C
190#define TWL4030_BASEADD_SECURED_REG 0x0000
191
192/* Triton Core internal information (END) */
193
194
Balaji T Ke8deb282009-12-14 00:25:31 +0100195/* subchip/slave 0 0x48 - POWER */
196#define TWL6030_BASEADD_RTC 0x0000
197#define TWL6030_BASEADD_MEM 0x0017
198#define TWL6030_BASEADD_PM_MASTER 0x001F
199#define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */
200#define TWL6030_BASEADD_PM_MISC 0x00E2
201#define TWL6030_BASEADD_PM_PUPD 0x00F0
202
203/* subchip/slave 1 0x49 - FEATURE */
204#define TWL6030_BASEADD_USB 0x0000
205#define TWL6030_BASEADD_GPADC_CTRL 0x002E
206#define TWL6030_BASEADD_AUX 0x0090
207#define TWL6030_BASEADD_PWM 0x00BA
208#define TWL6030_BASEADD_GASGAUGE 0x00C0
209#define TWL6030_BASEADD_PIH 0x00D0
210#define TWL6030_BASEADD_CHARGER 0x00E0
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100211#define TWL6025_BASEADD_CHARGER 0x00DA
Balaji T Ke8deb282009-12-14 00:25:31 +0100212
213/* subchip/slave 2 0x4A - DFT */
214#define TWL6030_BASEADD_DIEID 0x00C0
215
216/* subchip/slave 3 0x4B - AUDIO */
217#define TWL6030_BASEADD_AUDIO 0x0000
218#define TWL6030_BASEADD_RSV 0x0000
Balaji T Kfa0d9762010-02-19 12:39:38 +0100219#define TWL6030_BASEADD_ZERO 0x0000
Balaji T Ke8deb282009-12-14 00:25:31 +0100220
David Brownella603a7f2008-10-15 12:15:39 +0200221/* Few power values */
222#define R_CFG_BOOT 0x05
David Brownella603a7f2008-10-15 12:15:39 +0200223
224/* some fields in R_CFG_BOOT */
225#define HFCLK_FREQ_19p2_MHZ (1 << 0)
226#define HFCLK_FREQ_26_MHZ (2 << 0)
227#define HFCLK_FREQ_38p4_MHZ (3 << 0)
228#define HIGH_PERF_SQ (1 << 3)
Ilkka Koskinen38a68492009-10-22 14:14:09 +0300229#define CK32K_LOWPWR_EN (1 << 7)
David Brownella603a7f2008-10-15 12:15:39 +0200230
231
David Brownelldad759f2008-12-01 00:43:58 +0100232/* chip-specific feature flags, for i2c_device_id.driver_data */
233#define TWL4030_VAUX2 BIT(0) /* pre-5030 voltage ranges */
234#define TPS_SUBSET BIT(1) /* tps659[23]0 have fewer LDOs */
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200235#define TWL5031 BIT(2) /* twl5031 has different registers */
Balaji T Ke8deb282009-12-14 00:25:31 +0100236#define TWL6030_CLASS BIT(3) /* TWL6030 class */
David Brownelldad759f2008-12-01 00:43:58 +0100237
David Brownella603a7f2008-10-15 12:15:39 +0200238/*----------------------------------------------------------------------*/
239
David Brownella603a7f2008-10-15 12:15:39 +0200240/* is driver active, bound to a chip? */
241static bool inuse;
242
Lesly A Mca972d12011-04-14 17:57:53 +0530243/* TWL IDCODE Register value */
244static u32 twl_idcode;
245
Balaji T Ke8deb282009-12-14 00:25:31 +0100246static unsigned int twl_id;
247unsigned int twl_rev(void)
248{
249 return twl_id;
250}
251EXPORT_SYMBOL(twl_rev);
252
253/* Structure for each TWL4030/TWL6030 Slave */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100254struct twl_client {
David Brownella603a7f2008-10-15 12:15:39 +0200255 struct i2c_client *client;
256 u8 address;
257
258 /* max numb of i2c_msg required is for read =2 */
259 struct i2c_msg xfer_msg[2];
260
261 /* To lock access to xfer_msg */
262 struct mutex xfer_lock;
263};
264
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100265static struct twl_client twl_modules[TWL_NUM_SLAVES];
David Brownella603a7f2008-10-15 12:15:39 +0200266
David Brownella603a7f2008-10-15 12:15:39 +0200267/* mapping the module id to slave id and base address */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100268struct twl_mapping {
David Brownella603a7f2008-10-15 12:15:39 +0200269 unsigned char sid; /* Slave ID */
270 unsigned char base; /* base address */
271};
G, Manjunath Kondaiah2cfcce12010-09-21 15:31:17 +0530272static struct twl_mapping *twl_map;
David Brownella603a7f2008-10-15 12:15:39 +0200273
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100274static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
David Brownella603a7f2008-10-15 12:15:39 +0200275 /*
276 * NOTE: don't change this table without updating the
Balaji T Ke8deb282009-12-14 00:25:31 +0100277 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
David Brownella603a7f2008-10-15 12:15:39 +0200278 * so they continue to match the order in this table.
279 */
280
281 { 0, TWL4030_BASEADD_USB },
282
283 { 1, TWL4030_BASEADD_AUDIO_VOICE },
284 { 1, TWL4030_BASEADD_GPIO },
285 { 1, TWL4030_BASEADD_INTBR },
286 { 1, TWL4030_BASEADD_PIH },
287 { 1, TWL4030_BASEADD_TEST },
288
289 { 2, TWL4030_BASEADD_KEYPAD },
290 { 2, TWL4030_BASEADD_MADC },
291 { 2, TWL4030_BASEADD_INTERRUPTS },
292 { 2, TWL4030_BASEADD_LED },
293 { 2, TWL4030_BASEADD_MAIN_CHARGE },
294 { 2, TWL4030_BASEADD_PRECHARGE },
295 { 2, TWL4030_BASEADD_PWM0 },
296 { 2, TWL4030_BASEADD_PWM1 },
297 { 2, TWL4030_BASEADD_PWMA },
298 { 2, TWL4030_BASEADD_PWMB },
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200299 { 2, TWL5031_BASEADD_ACCESSORY },
300 { 2, TWL5031_BASEADD_INTERRUPTS },
David Brownella603a7f2008-10-15 12:15:39 +0200301
302 { 3, TWL4030_BASEADD_BACKUP },
303 { 3, TWL4030_BASEADD_INT },
304 { 3, TWL4030_BASEADD_PM_MASTER },
305 { 3, TWL4030_BASEADD_PM_RECEIVER },
306 { 3, TWL4030_BASEADD_RTC },
307 { 3, TWL4030_BASEADD_SECURED_REG },
308};
309
Balaji T Ke8deb282009-12-14 00:25:31 +0100310static struct twl_mapping twl6030_map[] = {
311 /*
312 * NOTE: don't change this table without updating the
313 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
314 * so they continue to match the order in this table.
315 */
316 { SUB_CHIP_ID1, TWL6030_BASEADD_USB },
317 { SUB_CHIP_ID3, TWL6030_BASEADD_AUDIO },
318 { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID },
319 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
320 { SUB_CHIP_ID1, TWL6030_BASEADD_PIH },
321
322 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
323 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
324 { SUB_CHIP_ID1, TWL6030_BASEADD_GPADC_CTRL },
325 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
326 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
327
328 { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER },
329 { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE },
330 { SUB_CHIP_ID1, TWL6030_BASEADD_PWM },
Balaji T Kfa0d9762010-02-19 12:39:38 +0100331 { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO },
332 { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100333
Balaji T Kfa0d9762010-02-19 12:39:38 +0100334 { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO },
335 { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100336 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
337 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
338 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
339 { SUB_CHIP_ID0, TWL6030_BASEADD_PM_MASTER },
340 { SUB_CHIP_ID0, TWL6030_BASEADD_PM_SLAVE_MISC },
341
342 { SUB_CHIP_ID0, TWL6030_BASEADD_RTC },
343 { SUB_CHIP_ID0, TWL6030_BASEADD_MEM },
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100344 { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER },
Balaji T Ke8deb282009-12-14 00:25:31 +0100345};
346
David Brownella603a7f2008-10-15 12:15:39 +0200347/*----------------------------------------------------------------------*/
348
David Brownella603a7f2008-10-15 12:15:39 +0200349/* Exported Functions */
350
351/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100352 * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200353 * @mod_no: module number
354 * @value: an array of num_bytes+1 containing data to write
355 * @reg: register address (just offset will do)
356 * @num_bytes: number of bytes to transfer
357 *
358 * IMPORTANT: for 'value' parameter: Allocate value num_bytes+1 and
359 * valid data starts at Offset 1.
360 *
361 * Returns the result of operation - 0 is success
362 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100363int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
David Brownella603a7f2008-10-15 12:15:39 +0200364{
365 int ret;
366 int sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100367 struct twl_client *twl;
David Brownella603a7f2008-10-15 12:15:39 +0200368 struct i2c_msg *msg;
369
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100370 if (unlikely(mod_no > TWL_MODULE_LAST)) {
David Brownella603a7f2008-10-15 12:15:39 +0200371 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
372 return -EPERM;
373 }
Ilya Yanok8653be12011-08-01 23:00:28 +0200374 if (unlikely(!inuse)) {
375 pr_err("%s: not initialized\n", DRIVER_NAME);
376 return -EPERM;
377 }
Balaji T Ke8deb282009-12-14 00:25:31 +0100378 sid = twl_map[mod_no].sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100379 twl = &twl_modules[sid];
David Brownella603a7f2008-10-15 12:15:39 +0200380
David Brownella603a7f2008-10-15 12:15:39 +0200381 mutex_lock(&twl->xfer_lock);
382 /*
383 * [MSG1]: fill the register address data
384 * fill the data Tx buffer
385 */
386 msg = &twl->xfer_msg[0];
387 msg->addr = twl->address;
388 msg->len = num_bytes + 1;
389 msg->flags = 0;
390 msg->buf = value;
391 /* over write the first byte of buffer with the register address */
Balaji T Ke8deb282009-12-14 00:25:31 +0100392 *value = twl_map[mod_no].base + reg;
David Brownella603a7f2008-10-15 12:15:39 +0200393 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1);
394 mutex_unlock(&twl->xfer_lock);
395
Amit Kucheria147e0842009-12-11 13:21:45 +0100396 /* i2c_transfer returns number of messages transferred */
397 if (ret != 1) {
398 pr_err("%s: i2c_write failed to transfer all messages\n",
399 DRIVER_NAME);
400 if (ret < 0)
401 return ret;
402 else
403 return -EIO;
404 } else {
405 return 0;
406 }
David Brownella603a7f2008-10-15 12:15:39 +0200407}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100408EXPORT_SYMBOL(twl_i2c_write);
David Brownella603a7f2008-10-15 12:15:39 +0200409
410/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100411 * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200412 * @mod_no: module number
413 * @value: an array of num_bytes containing data to be read
414 * @reg: register address (just offset will do)
415 * @num_bytes: number of bytes to transfer
416 *
417 * Returns result of operation - num_bytes is success else failure.
418 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100419int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
David Brownella603a7f2008-10-15 12:15:39 +0200420{
421 int ret;
422 u8 val;
423 int sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100424 struct twl_client *twl;
David Brownella603a7f2008-10-15 12:15:39 +0200425 struct i2c_msg *msg;
426
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100427 if (unlikely(mod_no > TWL_MODULE_LAST)) {
David Brownella603a7f2008-10-15 12:15:39 +0200428 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
429 return -EPERM;
430 }
Ilya Yanok8653be12011-08-01 23:00:28 +0200431 if (unlikely(!inuse)) {
432 pr_err("%s: not initialized\n", DRIVER_NAME);
433 return -EPERM;
434 }
Balaji T Ke8deb282009-12-14 00:25:31 +0100435 sid = twl_map[mod_no].sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100436 twl = &twl_modules[sid];
David Brownella603a7f2008-10-15 12:15:39 +0200437
David Brownella603a7f2008-10-15 12:15:39 +0200438 mutex_lock(&twl->xfer_lock);
439 /* [MSG1] fill the register address data */
440 msg = &twl->xfer_msg[0];
441 msg->addr = twl->address;
442 msg->len = 1;
443 msg->flags = 0; /* Read the register value */
Balaji T Ke8deb282009-12-14 00:25:31 +0100444 val = twl_map[mod_no].base + reg;
David Brownella603a7f2008-10-15 12:15:39 +0200445 msg->buf = &val;
446 /* [MSG2] fill the data rx buffer */
447 msg = &twl->xfer_msg[1];
448 msg->addr = twl->address;
449 msg->flags = I2C_M_RD; /* Read the register value */
450 msg->len = num_bytes; /* only n bytes */
451 msg->buf = value;
452 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2);
453 mutex_unlock(&twl->xfer_lock);
454
Amit Kucheria147e0842009-12-11 13:21:45 +0100455 /* i2c_transfer returns number of messages transferred */
456 if (ret != 2) {
457 pr_err("%s: i2c_read failed to transfer all messages\n",
458 DRIVER_NAME);
459 if (ret < 0)
460 return ret;
461 else
462 return -EIO;
463 } else {
464 return 0;
465 }
David Brownella603a7f2008-10-15 12:15:39 +0200466}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100467EXPORT_SYMBOL(twl_i2c_read);
David Brownella603a7f2008-10-15 12:15:39 +0200468
469/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100470 * twl_i2c_write_u8 - Writes a 8 bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200471 * @mod_no: module number
472 * @value: the value to be written 8 bit
473 * @reg: register address (just offset will do)
474 *
475 * Returns result of operation - 0 is success
476 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100477int twl_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
David Brownella603a7f2008-10-15 12:15:39 +0200478{
479
480 /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
481 u8 temp_buffer[2] = { 0 };
482 /* offset 1 contains the data */
483 temp_buffer[1] = value;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100484 return twl_i2c_write(mod_no, temp_buffer, reg, 1);
David Brownella603a7f2008-10-15 12:15:39 +0200485}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100486EXPORT_SYMBOL(twl_i2c_write_u8);
David Brownella603a7f2008-10-15 12:15:39 +0200487
488/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100489 * twl_i2c_read_u8 - Reads a 8 bit register from TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200490 * @mod_no: module number
491 * @value: the value read 8 bit
492 * @reg: register address (just offset will do)
493 *
494 * Returns result of operation - 0 is success
495 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100496int twl_i2c_read_u8(u8 mod_no, u8 *value, u8 reg)
David Brownella603a7f2008-10-15 12:15:39 +0200497{
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100498 return twl_i2c_read(mod_no, value, reg, 1);
David Brownella603a7f2008-10-15 12:15:39 +0200499}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100500EXPORT_SYMBOL(twl_i2c_read_u8);
David Brownella603a7f2008-10-15 12:15:39 +0200501
502/*----------------------------------------------------------------------*/
503
Lesly A Mca972d12011-04-14 17:57:53 +0530504/**
505 * twl_read_idcode_register - API to read the IDCODE register.
506 *
507 * Unlocks the IDCODE register and read the 32 bit value.
508 */
509static int twl_read_idcode_register(void)
510{
511 int err;
512
513 err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK,
514 REG_UNLOCK_TEST_REG);
515 if (err) {
516 pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err);
517 goto fail;
518 }
519
520 err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_idcode),
521 REG_IDCODE_7_0, 4);
522 if (err) {
523 pr_err("TWL4030: unable to read IDCODE -%d\n", err);
524 goto fail;
525 }
526
527 err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG);
528 if (err)
529 pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err);
530fail:
531 return err;
532}
533
534/**
535 * twl_get_type - API to get TWL Si type.
536 *
537 * Api to get the TWL Si type from IDCODE value.
538 */
539int twl_get_type(void)
540{
541 return TWL_SIL_TYPE(twl_idcode);
542}
543EXPORT_SYMBOL_GPL(twl_get_type);
544
545/**
546 * twl_get_version - API to get TWL Si version.
547 *
548 * Api to get the TWL Si version from IDCODE value.
549 */
550int twl_get_version(void)
551{
552 return TWL_SIL_REV(twl_idcode);
553}
554EXPORT_SYMBOL_GPL(twl_get_version);
555
David Brownelldad759f2008-12-01 00:43:58 +0100556static struct device *
557add_numbered_child(unsigned chip, const char *name, int num,
David Brownell5725d662008-12-01 00:31:04 +0100558 void *pdata, unsigned pdata_len,
559 bool can_wakeup, int irq0, int irq1)
560{
561 struct platform_device *pdev;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100562 struct twl_client *twl = &twl_modules[chip];
David Brownell5725d662008-12-01 00:31:04 +0100563 int status;
564
David Brownelldad759f2008-12-01 00:43:58 +0100565 pdev = platform_device_alloc(name, num);
David Brownell5725d662008-12-01 00:31:04 +0100566 if (!pdev) {
567 dev_dbg(&twl->client->dev, "can't alloc dev\n");
568 status = -ENOMEM;
569 goto err;
570 }
571
572 device_init_wakeup(&pdev->dev, can_wakeup);
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
598err:
599 if (status < 0) {
600 platform_device_put(pdev);
601 dev_err(&twl->client->dev, "can't add %s dev\n", name);
602 return ERR_PTR(status);
603 }
604 return &pdev->dev;
605}
606
David Brownelldad759f2008-12-01 00:43:58 +0100607static inline struct device *add_child(unsigned chip, const char *name,
608 void *pdata, unsigned pdata_len,
609 bool can_wakeup, int irq0, int irq1)
610{
611 return add_numbered_child(chip, name, -1, pdata, pdata_len,
612 can_wakeup, irq0, irq1);
613}
614
615static struct device *
616add_regulator_linked(int num, struct regulator_init_data *pdata,
617 struct regulator_consumer_supply *consumers,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100618 unsigned num_consumers, unsigned long features)
David Brownelldad759f2008-12-01 00:43:58 +0100619{
Balaji T Ke8deb282009-12-14 00:25:31 +0100620 unsigned sub_chip_id;
Tero Kristo63bfff42012-02-16 12:27:52 +0200621 struct twl_regulator_driver_data drv_data;
622
David Brownelldad759f2008-12-01 00:43:58 +0100623 /* regulator framework demands init_data ... */
624 if (!pdata)
625 return NULL;
626
David Brownellb73eac72008-12-07 19:10:58 +0100627 if (consumers) {
David Brownelldad759f2008-12-01 00:43:58 +0100628 pdata->consumer_supplies = consumers;
629 pdata->num_consumer_supplies = num_consumers;
630 }
631
Tero Kristo63bfff42012-02-16 12:27:52 +0200632 if (pdata->driver_data) {
633 /* If we have existing drv_data, just add the flags */
634 struct twl_regulator_driver_data *tmp;
635 tmp = pdata->driver_data;
636 tmp->features |= features;
637 } else {
638 /* add new driver data struct, used only during init */
639 drv_data.features = features;
640 drv_data.set_voltage = NULL;
641 drv_data.get_voltage = NULL;
642 drv_data.data = NULL;
643 pdata->driver_data = &drv_data;
644 }
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100645
David Brownelldad759f2008-12-01 00:43:58 +0100646 /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */
Balaji T Ke8deb282009-12-14 00:25:31 +0100647 sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid;
648 return add_numbered_child(sub_chip_id, "twl_reg", num,
David Brownelldad759f2008-12-01 00:43:58 +0100649 pdata, sizeof(*pdata), false, 0, 0);
650}
651
652static struct device *
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100653add_regulator(int num, struct regulator_init_data *pdata,
654 unsigned long features)
David Brownelldad759f2008-12-01 00:43:58 +0100655{
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100656 return add_regulator_linked(num, pdata, NULL, 0, features);
David Brownelldad759f2008-12-01 00:43:58 +0100657}
658
David Brownella603a7f2008-10-15 12:15:39 +0200659/*
David Brownella30d46c2008-10-20 23:46:28 +0200660 * NOTE: We know the first 8 IRQs after pdata->base_irq are
661 * for the PIH, and the next are for the PWR_INT SIH, since
662 * that's how twl_init_irq() sets things up.
David Brownella603a7f2008-10-15 12:15:39 +0200663 */
David Brownella603a7f2008-10-15 12:15:39 +0200664
David Brownelldad759f2008-12-01 00:43:58 +0100665static int
666add_children(struct twl4030_platform_data *pdata, unsigned long features)
David Brownella603a7f2008-10-15 12:15:39 +0200667{
David Brownell5725d662008-12-01 00:31:04 +0100668 struct device *child;
Balaji T Ke8deb282009-12-14 00:25:31 +0100669 unsigned sub_chip_id;
David Brownella603a7f2008-10-15 12:15:39 +0200670
David Brownella603a7f2008-10-15 12:15:39 +0200671 if (twl_has_gpio() && pdata->gpio) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100672 child = add_child(SUB_CHIP_ID1, "twl4030_gpio",
David Brownell5725d662008-12-01 00:31:04 +0100673 pdata->gpio, sizeof(*pdata->gpio),
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100674 false, pdata->irq_base + GPIO_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100675 if (IS_ERR(child))
676 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200677 }
678
679 if (twl_has_keypad() && pdata->keypad) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100680 child = add_child(SUB_CHIP_ID2, "twl4030_keypad",
David Brownell5725d662008-12-01 00:31:04 +0100681 pdata->keypad, sizeof(*pdata->keypad),
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100682 true, pdata->irq_base + KEYPAD_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100683 if (IS_ERR(child))
684 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200685 }
686
687 if (twl_has_madc() && pdata->madc) {
David Brownell5725d662008-12-01 00:31:04 +0100688 child = add_child(2, "twl4030_madc",
689 pdata->madc, sizeof(*pdata->madc),
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100690 true, pdata->irq_base + MADC_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100691 if (IS_ERR(child))
692 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200693 }
694
695 if (twl_has_rtc()) {
David Brownella603a7f2008-10-15 12:15:39 +0200696 /*
David Brownell5725d662008-12-01 00:31:04 +0100697 * REVISIT platform_data here currently might expose the
David Brownella603a7f2008-10-15 12:15:39 +0200698 * "msecure" line ... but for now we just expect board
David Brownell5725d662008-12-01 00:31:04 +0100699 * setup to tell the chip "it's always ok to SET_TIME".
David Brownella603a7f2008-10-15 12:15:39 +0200700 * Eventually, Linux might become more aware of such
701 * HW security concerns, and "least privilege".
702 */
Balaji T Ke8deb282009-12-14 00:25:31 +0100703 sub_chip_id = twl_map[TWL_MODULE_RTC].sid;
704 child = add_child(sub_chip_id, "twl_rtc",
David Brownell5725d662008-12-01 00:31:04 +0100705 NULL, 0,
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100706 true, pdata->irq_base + RTC_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100707 if (IS_ERR(child))
708 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200709 }
710
Rajendra Nayak9da66532009-12-13 22:29:47 +0100711 if (twl_has_usb() && pdata->usb && twl_class_is_4030()) {
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300712
713 static struct regulator_consumer_supply usb1v5 = {
714 .supply = "usb1v5",
715 };
716 static struct regulator_consumer_supply usb1v8 = {
717 .supply = "usb1v8",
718 };
719 static struct regulator_consumer_supply usb3v1 = {
720 .supply = "usb3v1",
721 };
722
723 /* First add the regulators so that they can be used by transceiver */
724 if (twl_has_regulator()) {
725 /* this is a template that gets copied */
726 struct regulator_init_data usb_fixed = {
727 .constraints.valid_modes_mask =
728 REGULATOR_MODE_NORMAL
729 | REGULATOR_MODE_STANDBY,
730 .constraints.valid_ops_mask =
731 REGULATOR_CHANGE_MODE
732 | REGULATOR_CHANGE_STATUS,
733 };
734
735 child = add_regulator_linked(TWL4030_REG_VUSB1V5,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100736 &usb_fixed, &usb1v5, 1,
737 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300738 if (IS_ERR(child))
739 return PTR_ERR(child);
740
741 child = add_regulator_linked(TWL4030_REG_VUSB1V8,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100742 &usb_fixed, &usb1v8, 1,
743 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300744 if (IS_ERR(child))
745 return PTR_ERR(child);
746
747 child = add_regulator_linked(TWL4030_REG_VUSB3V1,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100748 &usb_fixed, &usb3v1, 1,
749 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300750 if (IS_ERR(child))
751 return PTR_ERR(child);
752
753 }
754
David Brownell5725d662008-12-01 00:31:04 +0100755 child = add_child(0, "twl4030_usb",
756 pdata->usb, sizeof(*pdata->usb),
757 true,
758 /* irq0 = USB_PRES, irq1 = USB */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100759 pdata->irq_base + USB_PRES_INTR_OFFSET,
760 pdata->irq_base + USB_INTR_OFFSET);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300761
David Brownell5725d662008-12-01 00:31:04 +0100762 if (IS_ERR(child))
763 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100764
765 /* we need to connect regulators to this transceiver */
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300766 if (twl_has_regulator() && child) {
Mark Brown1b65fa82012-02-03 11:02:58 +0000767 usb1v5.dev_name = dev_name(child);
768 usb1v8.dev_name = dev_name(child);
769 usb3v1.dev_name = dev_name(child);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300770 }
David Brownelldad759f2008-12-01 00:43:58 +0100771 }
Hema HKe70357e2010-12-10 18:09:52 +0530772 if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {
773
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100774 static struct regulator_consumer_supply usb3v3;
775 int regulator;
Hema HKe70357e2010-12-10 18:09:52 +0530776
777 if (twl_has_regulator()) {
778 /* this is a template that gets copied */
779 struct regulator_init_data usb_fixed = {
780 .constraints.valid_modes_mask =
781 REGULATOR_MODE_NORMAL
782 | REGULATOR_MODE_STANDBY,
783 .constraints.valid_ops_mask =
784 REGULATOR_CHANGE_MODE
785 | REGULATOR_CHANGE_STATUS,
786 };
787
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100788 if (features & TWL6025_SUBCLASS) {
789 usb3v3.supply = "ldousb";
790 regulator = TWL6025_REG_LDOUSB;
791 } else {
792 usb3v3.supply = "vusb";
793 regulator = TWL6030_REG_VUSB;
794 }
795 child = add_regulator_linked(regulator, &usb_fixed,
796 &usb3v3, 1,
797 features);
Hema HKe70357e2010-12-10 18:09:52 +0530798 if (IS_ERR(child))
799 return PTR_ERR(child);
800 }
801
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100802 pdata->usb->features = features;
803
Hema HKe70357e2010-12-10 18:09:52 +0530804 child = add_child(0, "twl6030_usb",
805 pdata->usb, sizeof(*pdata->usb),
806 true,
807 /* irq1 = VBUS_PRES, irq0 = USB ID */
808 pdata->irq_base + USBOTG_INTR_OFFSET,
809 pdata->irq_base + USB_PRES_INTR_OFFSET);
810
811 if (IS_ERR(child))
812 return PTR_ERR(child);
813 /* we need to connect regulators to this transceiver */
814 if (twl_has_regulator() && child)
Mark Brown1b65fa82012-02-03 11:02:58 +0000815 usb3v3.dev_name = dev_name(child);
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100816 } else if (twl_has_regulator() && twl_class_is_6030()) {
817 if (features & TWL6025_SUBCLASS)
818 child = add_regulator(TWL6025_REG_LDOUSB,
819 pdata->ldousb, features);
820 else
821 child = add_regulator(TWL6030_REG_VUSB,
822 pdata->vusb, features);
Hema HKe70357e2010-12-10 18:09:52 +0530823
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100824 if (IS_ERR(child))
825 return PTR_ERR(child);
Hema HKe70357e2010-12-10 18:09:52 +0530826 }
David Brownelldad759f2008-12-01 00:43:58 +0100827
Keerthy153617f2011-02-23 16:26:54 +0530828 if (twl_has_watchdog() && twl_class_is_4030()) {
Timo Kokkonen80e45b12009-03-27 16:42:17 +0200829 child = add_child(0, "twl4030_wdt", NULL, 0, false, 0, 0);
830 if (IS_ERR(child))
831 return PTR_ERR(child);
832 }
833
Keerthy153617f2011-02-23 16:26:54 +0530834 if (twl_has_pwrbutton() && twl_class_is_4030()) {
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200835 child = add_child(1, "twl4030_pwrbutton",
836 NULL, 0, true, pdata->irq_base + 8 + 0, 0);
837 if (IS_ERR(child))
838 return PTR_ERR(child);
839 }
840
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300841 if (twl_has_codec() && pdata->audio && twl_class_is_4030()) {
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600842 sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000843 child = add_child(sub_chip_id, "twl4030-audio",
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300844 pdata->audio, sizeof(*pdata->audio),
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600845 false, 0, 0);
846 if (IS_ERR(child))
847 return PTR_ERR(child);
848 }
849
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300850 if (twl_has_codec() && pdata->audio && twl_class_is_6030()) {
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600851 sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500852 child = add_child(sub_chip_id, "twl6040",
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300853 pdata->audio, sizeof(*pdata->audio),
Peter Ujfalusi0b83dde2009-10-22 13:26:45 +0300854 false, 0, 0);
855 if (IS_ERR(child))
856 return PTR_ERR(child);
857 }
858
Rajendra Nayak9da66532009-12-13 22:29:47 +0100859 /* twl4030 regulators */
860 if (twl_has_regulator() && twl_class_is_4030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100861 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
862 features);
David Brownelldad759f2008-12-01 00:43:58 +0100863 if (IS_ERR(child))
864 return PTR_ERR(child);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100865
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100866 child = add_regulator(TWL4030_REG_VIO, pdata->vio,
867 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100868 if (IS_ERR(child))
869 return PTR_ERR(child);
870
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100871 child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1,
872 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100873 if (IS_ERR(child))
874 return PTR_ERR(child);
875
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100876 child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2,
877 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100878 if (IS_ERR(child))
879 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100880
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100881 child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1,
882 features);
David Brownelldad759f2008-12-01 00:43:58 +0100883 if (IS_ERR(child))
884 return PTR_ERR(child);
885
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100886 child = add_regulator(TWL4030_REG_VDAC, pdata->vdac,
887 features);
David Brownelldad759f2008-12-01 00:43:58 +0100888 if (IS_ERR(child))
889 return PTR_ERR(child);
890
891 child = add_regulator((features & TWL4030_VAUX2)
892 ? TWL4030_REG_VAUX2_4030
893 : TWL4030_REG_VAUX2,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100894 pdata->vaux2, features);
David Brownelldad759f2008-12-01 00:43:58 +0100895 if (IS_ERR(child))
896 return PTR_ERR(child);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100897
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100898 child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1,
899 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100900 if (IS_ERR(child))
901 return PTR_ERR(child);
902
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100903 child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2,
904 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100905 if (IS_ERR(child))
906 return PTR_ERR(child);
907
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100908 child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig,
909 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100910 if (IS_ERR(child))
911 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100912 }
913
David Brownelldad759f2008-12-01 00:43:58 +0100914 /* maybe add LDOs that are omitted on cost-reduced parts */
Rajendra Nayak9da66532009-12-13 22:29:47 +0100915 if (twl_has_regulator() && !(features & TPS_SUBSET)
916 && twl_class_is_4030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100917 child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2,
918 features);
David Brownelldad759f2008-12-01 00:43:58 +0100919 if (IS_ERR(child))
920 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100921
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100922 child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2,
923 features);
David Brownelldad759f2008-12-01 00:43:58 +0100924 if (IS_ERR(child))
925 return PTR_ERR(child);
926
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100927 child = add_regulator(TWL4030_REG_VSIM, pdata->vsim,
928 features);
David Brownelldad759f2008-12-01 00:43:58 +0100929 if (IS_ERR(child))
930 return PTR_ERR(child);
931
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100932 child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1,
933 features);
David Brownelldad759f2008-12-01 00:43:58 +0100934 if (IS_ERR(child))
935 return PTR_ERR(child);
936
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100937 child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3,
938 features);
David Brownelldad759f2008-12-01 00:43:58 +0100939 if (IS_ERR(child))
940 return PTR_ERR(child);
941
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100942 child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4,
943 features);
David Brownelldad759f2008-12-01 00:43:58 +0100944 if (IS_ERR(child))
945 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200946 }
947
Rajendra Nayak9da66532009-12-13 22:29:47 +0100948 /* twl6030 regulators */
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100949 if (twl_has_regulator() && twl_class_is_6030() &&
950 !(features & TWL6025_SUBCLASS)) {
Tero Kristo34a38442012-02-28 15:09:10 +0530951 child = add_regulator(TWL6030_REG_VDD1, pdata->vdd1,
952 features);
953 if (IS_ERR(child))
954 return PTR_ERR(child);
955
956 child = add_regulator(TWL6030_REG_VDD2, pdata->vdd2,
957 features);
958 if (IS_ERR(child))
959 return PTR_ERR(child);
960
961 child = add_regulator(TWL6030_REG_VDD3, pdata->vdd3,
962 features);
963 if (IS_ERR(child))
964 return PTR_ERR(child);
965
Peter Ujfalusi46eda3e2012-02-28 15:09:13 +0530966 child = add_regulator(TWL6030_REG_V1V8, pdata->v1v8,
967 features);
968 if (IS_ERR(child))
969 return PTR_ERR(child);
970
971 child = add_regulator(TWL6030_REG_V2V1, pdata->v2v1,
972 features);
973 if (IS_ERR(child))
974 return PTR_ERR(child);
975
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100976 child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc,
977 features);
978 if (IS_ERR(child))
979 return PTR_ERR(child);
980
981 child = add_regulator(TWL6030_REG_VPP, pdata->vpp,
982 features);
983 if (IS_ERR(child))
984 return PTR_ERR(child);
985
986 child = add_regulator(TWL6030_REG_VUSIM, pdata->vusim,
987 features);
988 if (IS_ERR(child))
989 return PTR_ERR(child);
990
991 child = add_regulator(TWL6030_REG_VCXIO, pdata->vcxio,
992 features);
993 if (IS_ERR(child))
994 return PTR_ERR(child);
995
996 child = add_regulator(TWL6030_REG_VDAC, pdata->vdac,
997 features);
998 if (IS_ERR(child))
999 return PTR_ERR(child);
1000
1001 child = add_regulator(TWL6030_REG_VAUX1_6030, pdata->vaux1,
1002 features);
1003 if (IS_ERR(child))
1004 return PTR_ERR(child);
1005
1006 child = add_regulator(TWL6030_REG_VAUX2_6030, pdata->vaux2,
1007 features);
1008 if (IS_ERR(child))
1009 return PTR_ERR(child);
1010
1011 child = add_regulator(TWL6030_REG_VAUX3_6030, pdata->vaux3,
1012 features);
1013 if (IS_ERR(child))
1014 return PTR_ERR(child);
1015
1016 child = add_regulator(TWL6030_REG_CLK32KG, pdata->clk32kg,
1017 features);
1018 if (IS_ERR(child))
1019 return PTR_ERR(child);
1020 }
1021
1022 /* 6030 and 6025 share this regulator */
Rajendra Nayak9da66532009-12-13 22:29:47 +01001023 if (twl_has_regulator() && twl_class_is_6030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001024 child = add_regulator(TWL6030_REG_VANA, pdata->vana,
1025 features);
1026 if (IS_ERR(child))
1027 return PTR_ERR(child);
1028 }
1029
1030 /* twl6025 regulators */
1031 if (twl_has_regulator() && twl_class_is_6030() &&
1032 (features & TWL6025_SUBCLASS)) {
1033 child = add_regulator(TWL6025_REG_LDO5, pdata->ldo5,
1034 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001035 if (IS_ERR(child))
1036 return PTR_ERR(child);
1037
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001038 child = add_regulator(TWL6025_REG_LDO1, pdata->ldo1,
1039 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001040 if (IS_ERR(child))
1041 return PTR_ERR(child);
1042
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001043 child = add_regulator(TWL6025_REG_LDO7, pdata->ldo7,
1044 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001045 if (IS_ERR(child))
1046 return PTR_ERR(child);
1047
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001048 child = add_regulator(TWL6025_REG_LDO6, pdata->ldo6,
1049 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001050 if (IS_ERR(child))
1051 return PTR_ERR(child);
1052
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001053 child = add_regulator(TWL6025_REG_LDOLN, pdata->ldoln,
1054 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001055 if (IS_ERR(child))
1056 return PTR_ERR(child);
1057
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001058 child = add_regulator(TWL6025_REG_LDO2, pdata->ldo2,
1059 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001060 if (IS_ERR(child))
1061 return PTR_ERR(child);
1062
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001063 child = add_regulator(TWL6025_REG_LDO4, pdata->ldo4,
1064 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001065 if (IS_ERR(child))
1066 return PTR_ERR(child);
1067
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001068 child = add_regulator(TWL6025_REG_LDO3, pdata->ldo3,
1069 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001070 if (IS_ERR(child))
1071 return PTR_ERR(child);
1072
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001073 child = add_regulator(TWL6025_REG_SMPS3, pdata->smps3,
1074 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001075 if (IS_ERR(child))
1076 return PTR_ERR(child);
Balaji T K8e6de4a2011-02-10 18:44:50 +05301077
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001078 child = add_regulator(TWL6025_REG_SMPS4, pdata->smps4,
1079 features);
Balaji T K8e6de4a2011-02-10 18:44:50 +05301080 if (IS_ERR(child))
1081 return PTR_ERR(child);
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001082
1083 child = add_regulator(TWL6025_REG_VIO, pdata->vio6025,
1084 features);
1085 if (IS_ERR(child))
1086 return PTR_ERR(child);
1087
Rajendra Nayak9da66532009-12-13 22:29:47 +01001088 }
1089
Grazvydas Ignotas11c39c42010-10-01 13:17:50 +03001090 if (twl_has_bci() && pdata->bci &&
1091 !(features & (TPS_SUBSET | TWL5031))) {
1092 child = add_child(3, "twl4030_bci",
1093 pdata->bci, sizeof(*pdata->bci), false,
1094 /* irq0 = CHG_PRES, irq1 = BCI */
1095 pdata->irq_base + BCI_PRES_INTR_OFFSET,
1096 pdata->irq_base + BCI_INTR_OFFSET);
1097 if (IS_ERR(child))
1098 return PTR_ERR(child);
1099 }
1100
David Brownell5725d662008-12-01 00:31:04 +01001101 return 0;
David Brownella603a7f2008-10-15 12:15:39 +02001102}
1103
1104/*----------------------------------------------------------------------*/
1105
1106/*
1107 * These three functions initialize the on-chip clock framework,
1108 * letting it generate the right frequencies for USB, MADC, and
1109 * other purposes.
1110 */
1111static inline int __init protect_pm_master(void)
1112{
1113 int e = 0;
1114
Felipe Balbi49e6f872010-08-18 09:19:35 +03001115 e = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0,
1116 TWL4030_PM_MASTER_PROTECT_KEY);
David Brownella603a7f2008-10-15 12:15:39 +02001117 return e;
1118}
1119
1120static inline int __init unprotect_pm_master(void)
1121{
1122 int e = 0;
1123
Felipe Balbi49e6f872010-08-18 09:19:35 +03001124 e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
1125 TWL4030_PM_MASTER_KEY_CFG1,
1126 TWL4030_PM_MASTER_PROTECT_KEY);
1127 e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
1128 TWL4030_PM_MASTER_KEY_CFG2,
1129 TWL4030_PM_MASTER_PROTECT_KEY);
1130
David Brownella603a7f2008-10-15 12:15:39 +02001131 return e;
1132}
1133
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001134static void clocks_init(struct device *dev,
1135 struct twl4030_clock_init_data *clock)
David Brownella603a7f2008-10-15 12:15:39 +02001136{
1137 int e = 0;
1138 struct clk *osc;
1139 u32 rate;
1140 u8 ctrl = HFCLK_FREQ_26_MHZ;
1141
1142#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
1143 if (cpu_is_omap2430())
Russell Kinge6b50c82009-01-10 10:40:42 +00001144 osc = clk_get(dev, "osc_ck");
David Brownella603a7f2008-10-15 12:15:39 +02001145 else
Russell Kinge6b50c82009-01-10 10:40:42 +00001146 osc = clk_get(dev, "osc_sys_ck");
Samuel Ortiz6354ab52008-12-07 20:50:25 +01001147
David Brownella603a7f2008-10-15 12:15:39 +02001148 if (IS_ERR(osc)) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001149 printk(KERN_WARNING "Skipping twl internal clock init and "
David Brownella603a7f2008-10-15 12:15:39 +02001150 "using bootloader value (unknown osc rate)\n");
1151 return;
1152 }
1153
1154 rate = clk_get_rate(osc);
1155 clk_put(osc);
1156
Samuel Ortiz6354ab52008-12-07 20:50:25 +01001157#else
1158 /* REVISIT for non-OMAP systems, pass the clock rate from
1159 * board init code, using platform_data.
1160 */
1161 osc = ERR_PTR(-EIO);
1162
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001163 printk(KERN_WARNING "Skipping twl internal clock init and "
Samuel Ortiz6354ab52008-12-07 20:50:25 +01001164 "using bootloader value (unknown osc rate)\n");
1165
1166 return;
1167#endif
1168
David Brownella603a7f2008-10-15 12:15:39 +02001169 switch (rate) {
1170 case 19200000:
1171 ctrl = HFCLK_FREQ_19p2_MHZ;
1172 break;
1173 case 26000000:
1174 ctrl = HFCLK_FREQ_26_MHZ;
1175 break;
1176 case 38400000:
1177 ctrl = HFCLK_FREQ_38p4_MHZ;
1178 break;
1179 }
1180
1181 ctrl |= HIGH_PERF_SQ;
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001182 if (clock && clock->ck32k_lowpwr_enable)
1183 ctrl |= CK32K_LOWPWR_EN;
1184
David Brownella603a7f2008-10-15 12:15:39 +02001185 e |= unprotect_pm_master();
1186 /* effect->MADC+USB ck en */
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001187 e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
David Brownella603a7f2008-10-15 12:15:39 +02001188 e |= protect_pm_master();
1189
1190 if (e < 0)
1191 pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
1192}
1193
1194/*----------------------------------------------------------------------*/
1195
Balaji T Ke8deb282009-12-14 00:25:31 +01001196int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end);
1197int twl4030_exit_irq(void);
1198int twl4030_init_chip_irq(const char *chip);
1199int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end);
1200int twl6030_exit_irq(void);
David Brownella603a7f2008-10-15 12:15:39 +02001201
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001202static int twl_remove(struct i2c_client *client)
David Brownella603a7f2008-10-15 12:15:39 +02001203{
1204 unsigned i;
David Brownella30d46c2008-10-20 23:46:28 +02001205 int status;
David Brownella603a7f2008-10-15 12:15:39 +02001206
Balaji T Ke8deb282009-12-14 00:25:31 +01001207 if (twl_class_is_4030())
1208 status = twl4030_exit_irq();
1209 else
1210 status = twl6030_exit_irq();
1211
David Brownella30d46c2008-10-20 23:46:28 +02001212 if (status < 0)
1213 return status;
David Brownella603a7f2008-10-15 12:15:39 +02001214
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001215 for (i = 0; i < TWL_NUM_SLAVES; i++) {
1216 struct twl_client *twl = &twl_modules[i];
David Brownella603a7f2008-10-15 12:15:39 +02001217
1218 if (twl->client && twl->client != client)
1219 i2c_unregister_device(twl->client);
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001220 twl_modules[i].client = NULL;
David Brownella603a7f2008-10-15 12:15:39 +02001221 }
1222 inuse = false;
1223 return 0;
1224}
1225
1226/* NOTE: this driver only handles a single twl4030/tps659x0 chip */
Bryan Wu5b9cecd2010-12-08 10:42:04 +08001227static int __devinit
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001228twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
David Brownella603a7f2008-10-15 12:15:39 +02001229{
1230 int status;
1231 unsigned i;
1232 struct twl4030_platform_data *pdata = client->dev.platform_data;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001233 struct device_node *node = client->dev.of_node;
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001234 u8 temp;
Lesly A Mca972d12011-04-14 17:57:53 +05301235 int ret = 0;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001236 int nr_irqs = TWL4030_NR_IRQS;
1237
1238 if ((id->driver_data) & TWL6030_CLASS)
1239 nr_irqs = TWL6030_NR_IRQS;
1240
1241 if (node && !pdata) {
1242 /*
1243 * XXX: Temporary pdata until the information is correctly
1244 * retrieved by every TWL modules from DT.
1245 */
1246 pdata = devm_kzalloc(&client->dev,
1247 sizeof(struct twl4030_platform_data),
1248 GFP_KERNEL);
1249 if (!pdata)
1250 return -ENOMEM;
1251 }
David Brownella603a7f2008-10-15 12:15:39 +02001252
1253 if (!pdata) {
1254 dev_dbg(&client->dev, "no platform data?\n");
1255 return -EINVAL;
1256 }
1257
Benoit Coussonaeb50322011-08-29 16:20:23 +02001258 status = irq_alloc_descs(-1, pdata->irq_base, nr_irqs, 0);
1259 if (IS_ERR_VALUE(status)) {
1260 dev_err(&client->dev, "Fail to allocate IRQ descs\n");
1261 return status;
1262 }
1263
1264 pdata->irq_base = status;
1265 pdata->irq_end = pdata->irq_base + nr_irqs;
Grant Likely75294952012-02-14 14:06:57 -07001266 irq_domain_add_legacy(node, nr_irqs, pdata->irq_base, 0,
1267 &irq_domain_simple_ops, NULL);
Benoit Coussonaeb50322011-08-29 16:20:23 +02001268
David Brownella603a7f2008-10-15 12:15:39 +02001269 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1270 dev_dbg(&client->dev, "can't talk I2C?\n");
1271 return -EIO;
1272 }
1273
David Brownella30d46c2008-10-20 23:46:28 +02001274 if (inuse) {
David Brownella603a7f2008-10-15 12:15:39 +02001275 dev_dbg(&client->dev, "driver is already in use\n");
1276 return -EBUSY;
1277 }
1278
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001279 for (i = 0; i < TWL_NUM_SLAVES; i++) {
1280 struct twl_client *twl = &twl_modules[i];
David Brownella603a7f2008-10-15 12:15:39 +02001281
1282 twl->address = client->addr + i;
1283 if (i == 0)
1284 twl->client = client;
1285 else {
1286 twl->client = i2c_new_dummy(client->adapter,
1287 twl->address);
1288 if (!twl->client) {
Ilkka Koskinena8643432009-10-20 16:22:52 +03001289 dev_err(&client->dev,
David Brownella603a7f2008-10-15 12:15:39 +02001290 "can't attach client %d\n", i);
1291 status = -ENOMEM;
1292 goto fail;
1293 }
David Brownella603a7f2008-10-15 12:15:39 +02001294 }
1295 mutex_init(&twl->xfer_lock);
1296 }
1297 inuse = true;
Balaji T Ke8deb282009-12-14 00:25:31 +01001298 if ((id->driver_data) & TWL6030_CLASS) {
1299 twl_id = TWL6030_CLASS_ID;
1300 twl_map = &twl6030_map[0];
1301 } else {
1302 twl_id = TWL4030_CLASS_ID;
1303 twl_map = &twl4030_map[0];
1304 }
David Brownella603a7f2008-10-15 12:15:39 +02001305
1306 /* setup clock framework */
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001307 clocks_init(&client->dev, pdata->clock);
David Brownella603a7f2008-10-15 12:15:39 +02001308
Lesly A Mca972d12011-04-14 17:57:53 +05301309 /* read TWL IDCODE Register */
1310 if (twl_id == TWL4030_CLASS_ID) {
1311 ret = twl_read_idcode_register();
1312 WARN(ret < 0, "Error: reading twl_idcode register value\n");
1313 }
1314
Amit Kucheriaebf0bd32009-08-31 18:32:18 +02001315 /* load power event scripts */
1316 if (twl_has_power() && pdata->power)
1317 twl4030_power_init(pdata->power);
1318
David Brownella603a7f2008-10-15 12:15:39 +02001319 /* Maybe init the T2 Interrupt subsystem */
1320 if (client->irq
1321 && pdata->irq_base
1322 && pdata->irq_end > pdata->irq_base) {
Balaji T Ke8deb282009-12-14 00:25:31 +01001323 if (twl_class_is_4030()) {
1324 twl4030_init_chip_irq(id->name);
1325 status = twl4030_init_irq(client->irq, pdata->irq_base,
1326 pdata->irq_end);
1327 } else {
1328 status = twl6030_init_irq(client->irq, pdata->irq_base,
1329 pdata->irq_end);
1330 }
1331
David Brownella30d46c2008-10-20 23:46:28 +02001332 if (status < 0)
1333 goto fail;
David Brownella603a7f2008-10-15 12:15:39 +02001334 }
1335
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001336 /* Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
1337 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
1338 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
1339 */
1340
1341 if (twl_class_is_4030()) {
1342 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
1343 temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
1344 I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
1345 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
1346 }
1347
Grant Likely964dba22012-02-24 14:58:34 -07001348 status = -ENODEV;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001349 if (node)
1350 status = of_platform_populate(node, NULL, NULL, &client->dev);
Grant Likely964dba22012-02-24 14:58:34 -07001351 if (status)
Benoit Coussonaeb50322011-08-29 16:20:23 +02001352 status = add_children(pdata, id->driver_data);
1353
David Brownella603a7f2008-10-15 12:15:39 +02001354fail:
1355 if (status < 0)
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001356 twl_remove(client);
David Brownella603a7f2008-10-15 12:15:39 +02001357 return status;
1358}
1359
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001360static const struct i2c_device_id twl_ids[] = {
David Brownelldad759f2008-12-01 00:43:58 +01001361 { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */
1362 { "twl5030", 0 }, /* T2 updated */
Ilkka Koskinen1920a612009-11-10 17:26:15 +02001363 { "twl5031", TWL5031 }, /* TWL5030 updated */
David Brownelldad759f2008-12-01 00:43:58 +01001364 { "tps65950", 0 }, /* catalog version of twl5030 */
1365 { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */
1366 { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */
Oleg Drokin59dead52011-07-01 13:34:13 +02001367 { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED
1368 and vibrator. Charger in USB module*/
Balaji T Ke8deb282009-12-14 00:25:31 +01001369 { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001370 { "twl6025", TWL6030_CLASS | TWL6025_SUBCLASS }, /* "Phoenix lite" */
David Brownella603a7f2008-10-15 12:15:39 +02001371 { /* end of list */ },
1372};
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001373MODULE_DEVICE_TABLE(i2c, twl_ids);
David Brownella603a7f2008-10-15 12:15:39 +02001374
1375/* One Client Driver , 4 Clients */
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001376static struct i2c_driver twl_driver = {
David Brownella603a7f2008-10-15 12:15:39 +02001377 .driver.name = DRIVER_NAME,
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001378 .id_table = twl_ids,
1379 .probe = twl_probe,
1380 .remove = twl_remove,
David Brownella603a7f2008-10-15 12:15:39 +02001381};
1382
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001383static int __init twl_init(void)
David Brownella603a7f2008-10-15 12:15:39 +02001384{
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001385 return i2c_add_driver(&twl_driver);
David Brownella603a7f2008-10-15 12:15:39 +02001386}
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001387subsys_initcall(twl_init);
David Brownella603a7f2008-10-15 12:15:39 +02001388
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001389static void __exit twl_exit(void)
David Brownella603a7f2008-10-15 12:15:39 +02001390{
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001391 i2c_del_driver(&twl_driver);
David Brownella603a7f2008-10-15 12:15:39 +02001392}
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001393module_exit(twl_exit);
David Brownella603a7f2008-10-15 12:15:39 +02001394
1395MODULE_AUTHOR("Texas Instruments, Inc.");
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001396MODULE_DESCRIPTION("I2C Core interface for TWL");
David Brownella603a7f2008-10-15 12:15:39 +02001397MODULE_LICENSE("GPL");