blob: e04e04ddc15e41f933b2a58de5f3bc8d28e86c25 [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>
41#include <linux/irqdomain.h>
David Brownella603a7f2008-10-15 12:15:39 +020042
David Brownelldad759f2008-12-01 00:43:58 +010043#include <linux/regulator/machine.h>
44
David Brownella603a7f2008-10-15 12:15:39 +020045#include <linux/i2c.h>
Santosh Shilimkarb07682b2009-12-13 20:05:51 +010046#include <linux/i2c/twl.h>
David Brownella603a7f2008-10-15 12:15:39 +020047
Mark Browna313d752009-02-04 21:26:07 +010048#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
Tony Lindgrence491cf2009-10-20 09:40:47 -070049#include <plat/cpu.h>
Samuel Ortizb29c06a2009-01-11 01:21:48 +010050#endif
David Brownella603a7f2008-10-15 12:15:39 +020051
52/*
53 * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
54 * Management and System Companion Device" chips originally designed for
55 * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C,
56 * often at around 3 Mbit/sec, including for interrupt handling.
57 *
58 * This driver core provides genirq support for the interrupts emitted,
59 * by the various modules, and exports register access primitives.
60 *
61 * FIXME this driver currently requires use of the first interrupt line
62 * (and associated registers).
63 */
64
Balaji T Kfc7b92f2009-12-13 21:23:33 +010065#define DRIVER_NAME "twl"
David Brownella603a7f2008-10-15 12:15:39 +020066
David Brownella603a7f2008-10-15 12:15:39 +020067#if defined(CONFIG_KEYBOARD_TWL4030) || defined(CONFIG_KEYBOARD_TWL4030_MODULE)
68#define twl_has_keypad() true
69#else
70#define twl_has_keypad() false
71#endif
72
73#if defined(CONFIG_GPIO_TWL4030) || defined(CONFIG_GPIO_TWL4030_MODULE)
74#define twl_has_gpio() true
75#else
76#define twl_has_gpio() false
77#endif
78
David Brownelldad759f2008-12-01 00:43:58 +010079#if defined(CONFIG_REGULATOR_TWL4030) \
80 || defined(CONFIG_REGULATOR_TWL4030_MODULE)
81#define twl_has_regulator() true
82#else
83#define twl_has_regulator() false
84#endif
85
David Brownella603a7f2008-10-15 12:15:39 +020086#if defined(CONFIG_TWL4030_MADC) || defined(CONFIG_TWL4030_MADC_MODULE)
87#define twl_has_madc() true
88#else
89#define twl_has_madc() false
90#endif
91
Amit Kucheriaebf0bd32009-08-31 18:32:18 +020092#ifdef CONFIG_TWL4030_POWER
93#define twl_has_power() true
94#else
95#define twl_has_power() false
96#endif
97
David Brownella603a7f2008-10-15 12:15:39 +020098#if defined(CONFIG_RTC_DRV_TWL4030) || defined(CONFIG_RTC_DRV_TWL4030_MODULE)
99#define twl_has_rtc() true
100#else
101#define twl_has_rtc() false
102#endif
103
Hema HKe70357e2010-12-10 18:09:52 +0530104#if defined(CONFIG_TWL4030_USB) || defined(CONFIG_TWL4030_USB_MODULE) ||\
105 defined(CONFIG_TWL6030_USB) || defined(CONFIG_TWL6030_USB_MODULE)
David Brownella603a7f2008-10-15 12:15:39 +0200106#define twl_has_usb() true
107#else
108#define twl_has_usb() false
109#endif
110
Timo Kokkonen80e45b12009-03-27 16:42:17 +0200111#if defined(CONFIG_TWL4030_WATCHDOG) || \
112 defined(CONFIG_TWL4030_WATCHDOG_MODULE)
113#define twl_has_watchdog() true
114#else
115#define twl_has_watchdog() false
116#endif
David Brownella603a7f2008-10-15 12:15:39 +0200117
Thomas Weberf09ee042011-09-05 11:26:33 +0200118#if defined(CONFIG_MFD_TWL4030_AUDIO) || defined(CONFIG_MFD_TWL4030_AUDIO_MODULE) ||\
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500119 defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE)
Peter Ujfalusi0b83dde2009-10-22 13:26:45 +0300120#define twl_has_codec() true
121#else
122#define twl_has_codec() false
123#endif
124
Grazvydas Ignotas11c39c42010-10-01 13:17:50 +0300125#if defined(CONFIG_CHARGER_TWL4030) || defined(CONFIG_CHARGER_TWL4030_MODULE)
126#define twl_has_bci() true
127#else
128#define twl_has_bci() false
129#endif
130
David Brownella603a7f2008-10-15 12:15:39 +0200131/* Triton Core internal information (BEGIN) */
132
133/* Last - for index max*/
134#define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
135
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100136#define TWL_NUM_SLAVES 4
David Brownella603a7f2008-10-15 12:15:39 +0200137
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200138#if defined(CONFIG_INPUT_TWL4030_PWRBUTTON) \
Eduardo Valentin14e5c822010-02-11 13:47:09 +0100139 || defined(CONFIG_INPUT_TWL4030_PWRBUTTON_MODULE)
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200140#define twl_has_pwrbutton() true
141#else
142#define twl_has_pwrbutton() false
143#endif
David Brownella603a7f2008-10-15 12:15:39 +0200144
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100145#define SUB_CHIP_ID0 0
146#define SUB_CHIP_ID1 1
147#define SUB_CHIP_ID2 2
148#define SUB_CHIP_ID3 3
149
150#define TWL_MODULE_LAST TWL4030_MODULE_LAST
151
Benoit Coussonaeb50322011-08-29 16:20:23 +0200152#define TWL4030_NR_IRQS 8
153#define TWL6030_NR_IRQS 20
154
David Brownella603a7f2008-10-15 12:15:39 +0200155/* Base Address defns for twl4030_map[] */
156
157/* subchip/slave 0 - USB ID */
158#define TWL4030_BASEADD_USB 0x0000
159
160/* subchip/slave 1 - AUD ID */
161#define TWL4030_BASEADD_AUDIO_VOICE 0x0000
162#define TWL4030_BASEADD_GPIO 0x0098
163#define TWL4030_BASEADD_INTBR 0x0085
164#define TWL4030_BASEADD_PIH 0x0080
165#define TWL4030_BASEADD_TEST 0x004C
166
167/* subchip/slave 2 - AUX ID */
168#define TWL4030_BASEADD_INTERRUPTS 0x00B9
169#define TWL4030_BASEADD_LED 0x00EE
170#define TWL4030_BASEADD_MADC 0x0000
171#define TWL4030_BASEADD_MAIN_CHARGE 0x0074
172#define TWL4030_BASEADD_PRECHARGE 0x00AA
173#define TWL4030_BASEADD_PWM0 0x00F8
174#define TWL4030_BASEADD_PWM1 0x00FB
175#define TWL4030_BASEADD_PWMA 0x00EF
176#define TWL4030_BASEADD_PWMB 0x00F1
177#define TWL4030_BASEADD_KEYPAD 0x00D2
178
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200179#define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */
180#define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's
181 one */
182
David Brownella603a7f2008-10-15 12:15:39 +0200183/* subchip/slave 3 - POWER ID */
184#define TWL4030_BASEADD_BACKUP 0x0014
185#define TWL4030_BASEADD_INT 0x002E
186#define TWL4030_BASEADD_PM_MASTER 0x0036
187#define TWL4030_BASEADD_PM_RECEIVER 0x005B
188#define TWL4030_BASEADD_RTC 0x001C
189#define TWL4030_BASEADD_SECURED_REG 0x0000
190
191/* Triton Core internal information (END) */
192
193
Balaji T Ke8deb282009-12-14 00:25:31 +0100194/* subchip/slave 0 0x48 - POWER */
195#define TWL6030_BASEADD_RTC 0x0000
196#define TWL6030_BASEADD_MEM 0x0017
197#define TWL6030_BASEADD_PM_MASTER 0x001F
198#define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */
199#define TWL6030_BASEADD_PM_MISC 0x00E2
200#define TWL6030_BASEADD_PM_PUPD 0x00F0
201
202/* subchip/slave 1 0x49 - FEATURE */
203#define TWL6030_BASEADD_USB 0x0000
204#define TWL6030_BASEADD_GPADC_CTRL 0x002E
205#define TWL6030_BASEADD_AUX 0x0090
206#define TWL6030_BASEADD_PWM 0x00BA
207#define TWL6030_BASEADD_GASGAUGE 0x00C0
208#define TWL6030_BASEADD_PIH 0x00D0
209#define TWL6030_BASEADD_CHARGER 0x00E0
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100210#define TWL6025_BASEADD_CHARGER 0x00DA
Balaji T Ke8deb282009-12-14 00:25:31 +0100211
212/* subchip/slave 2 0x4A - DFT */
213#define TWL6030_BASEADD_DIEID 0x00C0
214
215/* subchip/slave 3 0x4B - AUDIO */
216#define TWL6030_BASEADD_AUDIO 0x0000
217#define TWL6030_BASEADD_RSV 0x0000
Balaji T Kfa0d9762010-02-19 12:39:38 +0100218#define TWL6030_BASEADD_ZERO 0x0000
Balaji T Ke8deb282009-12-14 00:25:31 +0100219
David Brownella603a7f2008-10-15 12:15:39 +0200220/* Few power values */
221#define R_CFG_BOOT 0x05
David Brownella603a7f2008-10-15 12:15:39 +0200222
223/* some fields in R_CFG_BOOT */
224#define HFCLK_FREQ_19p2_MHZ (1 << 0)
225#define HFCLK_FREQ_26_MHZ (2 << 0)
226#define HFCLK_FREQ_38p4_MHZ (3 << 0)
227#define HIGH_PERF_SQ (1 << 3)
Ilkka Koskinen38a68492009-10-22 14:14:09 +0300228#define CK32K_LOWPWR_EN (1 << 7)
David Brownella603a7f2008-10-15 12:15:39 +0200229
230
David Brownelldad759f2008-12-01 00:43:58 +0100231/* chip-specific feature flags, for i2c_device_id.driver_data */
232#define TWL4030_VAUX2 BIT(0) /* pre-5030 voltage ranges */
233#define TPS_SUBSET BIT(1) /* tps659[23]0 have fewer LDOs */
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200234#define TWL5031 BIT(2) /* twl5031 has different registers */
Balaji T Ke8deb282009-12-14 00:25:31 +0100235#define TWL6030_CLASS BIT(3) /* TWL6030 class */
David Brownelldad759f2008-12-01 00:43:58 +0100236
David Brownella603a7f2008-10-15 12:15:39 +0200237/*----------------------------------------------------------------------*/
238
David Brownella603a7f2008-10-15 12:15:39 +0200239/* is driver active, bound to a chip? */
240static bool inuse;
241
Lesly A Mca972d12011-04-14 17:57:53 +0530242/* TWL IDCODE Register value */
243static u32 twl_idcode;
244
Balaji T Ke8deb282009-12-14 00:25:31 +0100245static unsigned int twl_id;
246unsigned int twl_rev(void)
247{
248 return twl_id;
249}
250EXPORT_SYMBOL(twl_rev);
251
252/* Structure for each TWL4030/TWL6030 Slave */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100253struct twl_client {
David Brownella603a7f2008-10-15 12:15:39 +0200254 struct i2c_client *client;
255 u8 address;
256
257 /* max numb of i2c_msg required is for read =2 */
258 struct i2c_msg xfer_msg[2];
259
260 /* To lock access to xfer_msg */
261 struct mutex xfer_lock;
262};
263
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100264static struct twl_client twl_modules[TWL_NUM_SLAVES];
David Brownella603a7f2008-10-15 12:15:39 +0200265
Benoit Coussonaeb50322011-08-29 16:20:23 +0200266static struct irq_domain domain;
David Brownella603a7f2008-10-15 12:15:39 +0200267
268/* mapping the module id to slave id and base address */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100269struct twl_mapping {
David Brownella603a7f2008-10-15 12:15:39 +0200270 unsigned char sid; /* Slave ID */
271 unsigned char base; /* base address */
272};
G, Manjunath Kondaiah2cfcce12010-09-21 15:31:17 +0530273static struct twl_mapping *twl_map;
David Brownella603a7f2008-10-15 12:15:39 +0200274
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100275static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
David Brownella603a7f2008-10-15 12:15:39 +0200276 /*
277 * NOTE: don't change this table without updating the
Balaji T Ke8deb282009-12-14 00:25:31 +0100278 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
David Brownella603a7f2008-10-15 12:15:39 +0200279 * so they continue to match the order in this table.
280 */
281
282 { 0, TWL4030_BASEADD_USB },
283
284 { 1, TWL4030_BASEADD_AUDIO_VOICE },
285 { 1, TWL4030_BASEADD_GPIO },
286 { 1, TWL4030_BASEADD_INTBR },
287 { 1, TWL4030_BASEADD_PIH },
288 { 1, TWL4030_BASEADD_TEST },
289
290 { 2, TWL4030_BASEADD_KEYPAD },
291 { 2, TWL4030_BASEADD_MADC },
292 { 2, TWL4030_BASEADD_INTERRUPTS },
293 { 2, TWL4030_BASEADD_LED },
294 { 2, TWL4030_BASEADD_MAIN_CHARGE },
295 { 2, TWL4030_BASEADD_PRECHARGE },
296 { 2, TWL4030_BASEADD_PWM0 },
297 { 2, TWL4030_BASEADD_PWM1 },
298 { 2, TWL4030_BASEADD_PWMA },
299 { 2, TWL4030_BASEADD_PWMB },
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200300 { 2, TWL5031_BASEADD_ACCESSORY },
301 { 2, TWL5031_BASEADD_INTERRUPTS },
David Brownella603a7f2008-10-15 12:15:39 +0200302
303 { 3, TWL4030_BASEADD_BACKUP },
304 { 3, TWL4030_BASEADD_INT },
305 { 3, TWL4030_BASEADD_PM_MASTER },
306 { 3, TWL4030_BASEADD_PM_RECEIVER },
307 { 3, TWL4030_BASEADD_RTC },
308 { 3, TWL4030_BASEADD_SECURED_REG },
309};
310
Balaji T Ke8deb282009-12-14 00:25:31 +0100311static struct twl_mapping twl6030_map[] = {
312 /*
313 * NOTE: don't change this table without updating the
314 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
315 * so they continue to match the order in this table.
316 */
317 { SUB_CHIP_ID1, TWL6030_BASEADD_USB },
318 { SUB_CHIP_ID3, TWL6030_BASEADD_AUDIO },
319 { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID },
320 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
321 { SUB_CHIP_ID1, TWL6030_BASEADD_PIH },
322
323 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
324 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
325 { SUB_CHIP_ID1, TWL6030_BASEADD_GPADC_CTRL },
326 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
327 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
328
329 { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER },
330 { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE },
331 { SUB_CHIP_ID1, TWL6030_BASEADD_PWM },
Balaji T Kfa0d9762010-02-19 12:39:38 +0100332 { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO },
333 { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100334
Balaji T Kfa0d9762010-02-19 12:39:38 +0100335 { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO },
336 { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100337 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
338 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
339 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
340 { SUB_CHIP_ID0, TWL6030_BASEADD_PM_MASTER },
341 { SUB_CHIP_ID0, TWL6030_BASEADD_PM_SLAVE_MISC },
342
343 { SUB_CHIP_ID0, TWL6030_BASEADD_RTC },
344 { SUB_CHIP_ID0, TWL6030_BASEADD_MEM },
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100345 { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER },
Balaji T Ke8deb282009-12-14 00:25:31 +0100346};
347
David Brownella603a7f2008-10-15 12:15:39 +0200348/*----------------------------------------------------------------------*/
349
David Brownella603a7f2008-10-15 12:15:39 +0200350/* Exported Functions */
351
352/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100353 * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200354 * @mod_no: module number
355 * @value: an array of num_bytes+1 containing data to write
356 * @reg: register address (just offset will do)
357 * @num_bytes: number of bytes to transfer
358 *
359 * IMPORTANT: for 'value' parameter: Allocate value num_bytes+1 and
360 * valid data starts at Offset 1.
361 *
362 * Returns the result of operation - 0 is success
363 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100364int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
David Brownella603a7f2008-10-15 12:15:39 +0200365{
366 int ret;
367 int sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100368 struct twl_client *twl;
David Brownella603a7f2008-10-15 12:15:39 +0200369 struct i2c_msg *msg;
370
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100371 if (unlikely(mod_no > TWL_MODULE_LAST)) {
David Brownella603a7f2008-10-15 12:15:39 +0200372 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
373 return -EPERM;
374 }
Ilya Yanok8653be12011-08-01 23:00:28 +0200375 if (unlikely(!inuse)) {
376 pr_err("%s: not initialized\n", DRIVER_NAME);
377 return -EPERM;
378 }
Balaji T Ke8deb282009-12-14 00:25:31 +0100379 sid = twl_map[mod_no].sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100380 twl = &twl_modules[sid];
David Brownella603a7f2008-10-15 12:15:39 +0200381
David Brownella603a7f2008-10-15 12:15:39 +0200382 mutex_lock(&twl->xfer_lock);
383 /*
384 * [MSG1]: fill the register address data
385 * fill the data Tx buffer
386 */
387 msg = &twl->xfer_msg[0];
388 msg->addr = twl->address;
389 msg->len = num_bytes + 1;
390 msg->flags = 0;
391 msg->buf = value;
392 /* over write the first byte of buffer with the register address */
Balaji T Ke8deb282009-12-14 00:25:31 +0100393 *value = twl_map[mod_no].base + reg;
David Brownella603a7f2008-10-15 12:15:39 +0200394 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1);
395 mutex_unlock(&twl->xfer_lock);
396
Amit Kucheria147e0842009-12-11 13:21:45 +0100397 /* i2c_transfer returns number of messages transferred */
398 if (ret != 1) {
399 pr_err("%s: i2c_write failed to transfer all messages\n",
400 DRIVER_NAME);
401 if (ret < 0)
402 return ret;
403 else
404 return -EIO;
405 } else {
406 return 0;
407 }
David Brownella603a7f2008-10-15 12:15:39 +0200408}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100409EXPORT_SYMBOL(twl_i2c_write);
David Brownella603a7f2008-10-15 12:15:39 +0200410
411/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100412 * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200413 * @mod_no: module number
414 * @value: an array of num_bytes containing data to be read
415 * @reg: register address (just offset will do)
416 * @num_bytes: number of bytes to transfer
417 *
418 * Returns result of operation - num_bytes is success else failure.
419 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100420int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
David Brownella603a7f2008-10-15 12:15:39 +0200421{
422 int ret;
423 u8 val;
424 int sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100425 struct twl_client *twl;
David Brownella603a7f2008-10-15 12:15:39 +0200426 struct i2c_msg *msg;
427
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100428 if (unlikely(mod_no > TWL_MODULE_LAST)) {
David Brownella603a7f2008-10-15 12:15:39 +0200429 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
430 return -EPERM;
431 }
Ilya Yanok8653be12011-08-01 23:00:28 +0200432 if (unlikely(!inuse)) {
433 pr_err("%s: not initialized\n", DRIVER_NAME);
434 return -EPERM;
435 }
Balaji T Ke8deb282009-12-14 00:25:31 +0100436 sid = twl_map[mod_no].sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100437 twl = &twl_modules[sid];
David Brownella603a7f2008-10-15 12:15:39 +0200438
David Brownella603a7f2008-10-15 12:15:39 +0200439 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 */
Balaji T Ke8deb282009-12-14 00:25:31 +0100445 val = twl_map[mod_no].base + reg;
David Brownella603a7f2008-10-15 12:15:39 +0200446 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
Amit Kucheria147e0842009-12-11 13:21:45 +0100456 /* 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 }
David Brownella603a7f2008-10-15 12:15:39 +0200467}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100468EXPORT_SYMBOL(twl_i2c_read);
David Brownella603a7f2008-10-15 12:15:39 +0200469
470/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100471 * twl_i2c_write_u8 - Writes a 8 bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200472 * @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 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100478int twl_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
David Brownella603a7f2008-10-15 12:15:39 +0200479{
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;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100485 return twl_i2c_write(mod_no, temp_buffer, reg, 1);
David Brownella603a7f2008-10-15 12:15:39 +0200486}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100487EXPORT_SYMBOL(twl_i2c_write_u8);
David Brownella603a7f2008-10-15 12:15:39 +0200488
489/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100490 * twl_i2c_read_u8 - Reads a 8 bit register from TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200491 * @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 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100497int twl_i2c_read_u8(u8 mod_no, u8 *value, u8 reg)
David Brownella603a7f2008-10-15 12:15:39 +0200498{
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100499 return twl_i2c_read(mod_no, value, reg, 1);
David Brownella603a7f2008-10-15 12:15:39 +0200500}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100501EXPORT_SYMBOL(twl_i2c_read_u8);
David Brownella603a7f2008-10-15 12:15:39 +0200502
503/*----------------------------------------------------------------------*/
504
Lesly A Mca972d12011-04-14 17:57:53 +0530505/**
506 * twl_read_idcode_register - API to read the IDCODE register.
507 *
508 * Unlocks the IDCODE register and read the 32 bit value.
509 */
510static 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);
531fail:
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 */
540int twl_get_type(void)
541{
542 return TWL_SIL_TYPE(twl_idcode);
543}
544EXPORT_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 */
551int twl_get_version(void)
552{
553 return TWL_SIL_REV(twl_idcode);
554}
555EXPORT_SYMBOL_GPL(twl_get_version);
556
David Brownelldad759f2008-12-01 00:43:58 +0100557static struct device *
558add_numbered_child(unsigned chip, const char *name, int num,
David Brownell5725d662008-12-01 00:31:04 +0100559 void *pdata, unsigned pdata_len,
560 bool can_wakeup, int irq0, int irq1)
561{
562 struct platform_device *pdev;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100563 struct twl_client *twl = &twl_modules[chip];
David Brownell5725d662008-12-01 00:31:04 +0100564 int status;
565
David Brownelldad759f2008-12-01 00:43:58 +0100566 pdev = platform_device_alloc(name, num);
David Brownell5725d662008-12-01 00:31:04 +0100567 if (!pdev) {
568 dev_dbg(&twl->client->dev, "can't alloc dev\n");
569 status = -ENOMEM;
570 goto err;
571 }
572
573 device_init_wakeup(&pdev->dev, can_wakeup);
574 pdev->dev.parent = &twl->client->dev;
575
576 if (pdata) {
577 status = platform_device_add_data(pdev, pdata, pdata_len);
578 if (status < 0) {
579 dev_dbg(&pdev->dev, "can't add platform_data\n");
580 goto err;
581 }
582 }
583
584 if (irq0) {
585 struct resource r[2] = {
586 { .start = irq0, .flags = IORESOURCE_IRQ, },
587 { .start = irq1, .flags = IORESOURCE_IRQ, },
588 };
589
590 status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1);
591 if (status < 0) {
592 dev_dbg(&pdev->dev, "can't add irqs\n");
593 goto err;
594 }
595 }
596
597 status = platform_device_add(pdev);
598
599err:
600 if (status < 0) {
601 platform_device_put(pdev);
602 dev_err(&twl->client->dev, "can't add %s dev\n", name);
603 return ERR_PTR(status);
604 }
605 return &pdev->dev;
606}
607
David Brownelldad759f2008-12-01 00:43:58 +0100608static inline struct device *add_child(unsigned chip, const char *name,
609 void *pdata, unsigned pdata_len,
610 bool can_wakeup, int irq0, int irq1)
611{
612 return add_numbered_child(chip, name, -1, pdata, pdata_len,
613 can_wakeup, irq0, irq1);
614}
615
616static struct device *
617add_regulator_linked(int num, struct regulator_init_data *pdata,
618 struct regulator_consumer_supply *consumers,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100619 unsigned num_consumers, unsigned long features)
David Brownelldad759f2008-12-01 00:43:58 +0100620{
Balaji T Ke8deb282009-12-14 00:25:31 +0100621 unsigned sub_chip_id;
David Brownelldad759f2008-12-01 00:43:58 +0100622 /* regulator framework demands init_data ... */
623 if (!pdata)
624 return NULL;
625
David Brownellb73eac72008-12-07 19:10:58 +0100626 if (consumers) {
David Brownelldad759f2008-12-01 00:43:58 +0100627 pdata->consumer_supplies = consumers;
628 pdata->num_consumer_supplies = num_consumers;
629 }
630
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100631 pdata->driver_data = (void *)features;
632
David Brownelldad759f2008-12-01 00:43:58 +0100633 /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */
Balaji T Ke8deb282009-12-14 00:25:31 +0100634 sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid;
635 return add_numbered_child(sub_chip_id, "twl_reg", num,
David Brownelldad759f2008-12-01 00:43:58 +0100636 pdata, sizeof(*pdata), false, 0, 0);
637}
638
639static struct device *
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100640add_regulator(int num, struct regulator_init_data *pdata,
641 unsigned long features)
David Brownelldad759f2008-12-01 00:43:58 +0100642{
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100643 return add_regulator_linked(num, pdata, NULL, 0, features);
David Brownelldad759f2008-12-01 00:43:58 +0100644}
645
David Brownella603a7f2008-10-15 12:15:39 +0200646/*
David Brownella30d46c2008-10-20 23:46:28 +0200647 * NOTE: We know the first 8 IRQs after pdata->base_irq are
648 * for the PIH, and the next are for the PWR_INT SIH, since
649 * that's how twl_init_irq() sets things up.
David Brownella603a7f2008-10-15 12:15:39 +0200650 */
David Brownella603a7f2008-10-15 12:15:39 +0200651
David Brownelldad759f2008-12-01 00:43:58 +0100652static int
653add_children(struct twl4030_platform_data *pdata, unsigned long features)
David Brownella603a7f2008-10-15 12:15:39 +0200654{
David Brownell5725d662008-12-01 00:31:04 +0100655 struct device *child;
Balaji T Ke8deb282009-12-14 00:25:31 +0100656 unsigned sub_chip_id;
David Brownella603a7f2008-10-15 12:15:39 +0200657
David Brownella603a7f2008-10-15 12:15:39 +0200658 if (twl_has_gpio() && pdata->gpio) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100659 child = add_child(SUB_CHIP_ID1, "twl4030_gpio",
David Brownell5725d662008-12-01 00:31:04 +0100660 pdata->gpio, sizeof(*pdata->gpio),
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100661 false, pdata->irq_base + GPIO_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100662 if (IS_ERR(child))
663 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200664 }
665
666 if (twl_has_keypad() && pdata->keypad) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100667 child = add_child(SUB_CHIP_ID2, "twl4030_keypad",
David Brownell5725d662008-12-01 00:31:04 +0100668 pdata->keypad, sizeof(*pdata->keypad),
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100669 true, pdata->irq_base + KEYPAD_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100670 if (IS_ERR(child))
671 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200672 }
673
674 if (twl_has_madc() && pdata->madc) {
David Brownell5725d662008-12-01 00:31:04 +0100675 child = add_child(2, "twl4030_madc",
676 pdata->madc, sizeof(*pdata->madc),
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100677 true, pdata->irq_base + MADC_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100678 if (IS_ERR(child))
679 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200680 }
681
682 if (twl_has_rtc()) {
David Brownella603a7f2008-10-15 12:15:39 +0200683 /*
David Brownell5725d662008-12-01 00:31:04 +0100684 * REVISIT platform_data here currently might expose the
David Brownella603a7f2008-10-15 12:15:39 +0200685 * "msecure" line ... but for now we just expect board
David Brownell5725d662008-12-01 00:31:04 +0100686 * setup to tell the chip "it's always ok to SET_TIME".
David Brownella603a7f2008-10-15 12:15:39 +0200687 * Eventually, Linux might become more aware of such
688 * HW security concerns, and "least privilege".
689 */
Balaji T Ke8deb282009-12-14 00:25:31 +0100690 sub_chip_id = twl_map[TWL_MODULE_RTC].sid;
691 child = add_child(sub_chip_id, "twl_rtc",
David Brownell5725d662008-12-01 00:31:04 +0100692 NULL, 0,
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100693 true, pdata->irq_base + RTC_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100694 if (IS_ERR(child))
695 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200696 }
697
Rajendra Nayak9da66532009-12-13 22:29:47 +0100698 if (twl_has_usb() && pdata->usb && twl_class_is_4030()) {
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300699
700 static struct regulator_consumer_supply usb1v5 = {
701 .supply = "usb1v5",
702 };
703 static struct regulator_consumer_supply usb1v8 = {
704 .supply = "usb1v8",
705 };
706 static struct regulator_consumer_supply usb3v1 = {
707 .supply = "usb3v1",
708 };
709
710 /* First add the regulators so that they can be used by transceiver */
711 if (twl_has_regulator()) {
712 /* this is a template that gets copied */
713 struct regulator_init_data usb_fixed = {
714 .constraints.valid_modes_mask =
715 REGULATOR_MODE_NORMAL
716 | REGULATOR_MODE_STANDBY,
717 .constraints.valid_ops_mask =
718 REGULATOR_CHANGE_MODE
719 | REGULATOR_CHANGE_STATUS,
720 };
721
722 child = add_regulator_linked(TWL4030_REG_VUSB1V5,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100723 &usb_fixed, &usb1v5, 1,
724 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300725 if (IS_ERR(child))
726 return PTR_ERR(child);
727
728 child = add_regulator_linked(TWL4030_REG_VUSB1V8,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100729 &usb_fixed, &usb1v8, 1,
730 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300731 if (IS_ERR(child))
732 return PTR_ERR(child);
733
734 child = add_regulator_linked(TWL4030_REG_VUSB3V1,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100735 &usb_fixed, &usb3v1, 1,
736 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300737 if (IS_ERR(child))
738 return PTR_ERR(child);
739
740 }
741
David Brownell5725d662008-12-01 00:31:04 +0100742 child = add_child(0, "twl4030_usb",
743 pdata->usb, sizeof(*pdata->usb),
744 true,
745 /* irq0 = USB_PRES, irq1 = USB */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100746 pdata->irq_base + USB_PRES_INTR_OFFSET,
747 pdata->irq_base + USB_INTR_OFFSET);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300748
David Brownell5725d662008-12-01 00:31:04 +0100749 if (IS_ERR(child))
750 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100751
752 /* we need to connect regulators to this transceiver */
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300753 if (twl_has_regulator() && child) {
754 usb1v5.dev = child;
755 usb1v8.dev = child;
756 usb3v1.dev = child;
757 }
David Brownelldad759f2008-12-01 00:43:58 +0100758 }
Hema HKe70357e2010-12-10 18:09:52 +0530759 if (twl_has_usb() && pdata->usb && twl_class_is_6030()) {
760
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100761 static struct regulator_consumer_supply usb3v3;
762 int regulator;
Hema HKe70357e2010-12-10 18:09:52 +0530763
764 if (twl_has_regulator()) {
765 /* this is a template that gets copied */
766 struct regulator_init_data usb_fixed = {
767 .constraints.valid_modes_mask =
768 REGULATOR_MODE_NORMAL
769 | REGULATOR_MODE_STANDBY,
770 .constraints.valid_ops_mask =
771 REGULATOR_CHANGE_MODE
772 | REGULATOR_CHANGE_STATUS,
773 };
774
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100775 if (features & TWL6025_SUBCLASS) {
776 usb3v3.supply = "ldousb";
777 regulator = TWL6025_REG_LDOUSB;
778 } else {
779 usb3v3.supply = "vusb";
780 regulator = TWL6030_REG_VUSB;
781 }
782 child = add_regulator_linked(regulator, &usb_fixed,
783 &usb3v3, 1,
784 features);
Hema HKe70357e2010-12-10 18:09:52 +0530785 if (IS_ERR(child))
786 return PTR_ERR(child);
787 }
788
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100789 pdata->usb->features = features;
790
Hema HKe70357e2010-12-10 18:09:52 +0530791 child = add_child(0, "twl6030_usb",
792 pdata->usb, sizeof(*pdata->usb),
793 true,
794 /* irq1 = VBUS_PRES, irq0 = USB ID */
795 pdata->irq_base + USBOTG_INTR_OFFSET,
796 pdata->irq_base + USB_PRES_INTR_OFFSET);
797
798 if (IS_ERR(child))
799 return PTR_ERR(child);
800 /* we need to connect regulators to this transceiver */
801 if (twl_has_regulator() && child)
802 usb3v3.dev = child;
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100803 } else if (twl_has_regulator() && twl_class_is_6030()) {
804 if (features & TWL6025_SUBCLASS)
805 child = add_regulator(TWL6025_REG_LDOUSB,
806 pdata->ldousb, features);
807 else
808 child = add_regulator(TWL6030_REG_VUSB,
809 pdata->vusb, features);
Hema HKe70357e2010-12-10 18:09:52 +0530810
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100811 if (IS_ERR(child))
812 return PTR_ERR(child);
Hema HKe70357e2010-12-10 18:09:52 +0530813 }
David Brownelldad759f2008-12-01 00:43:58 +0100814
Keerthy153617f2011-02-23 16:26:54 +0530815 if (twl_has_watchdog() && twl_class_is_4030()) {
Timo Kokkonen80e45b12009-03-27 16:42:17 +0200816 child = add_child(0, "twl4030_wdt", NULL, 0, false, 0, 0);
817 if (IS_ERR(child))
818 return PTR_ERR(child);
819 }
820
Keerthy153617f2011-02-23 16:26:54 +0530821 if (twl_has_pwrbutton() && twl_class_is_4030()) {
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200822 child = add_child(1, "twl4030_pwrbutton",
823 NULL, 0, true, pdata->irq_base + 8 + 0, 0);
824 if (IS_ERR(child))
825 return PTR_ERR(child);
826 }
827
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300828 if (twl_has_codec() && pdata->audio && twl_class_is_4030()) {
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600829 sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000830 child = add_child(sub_chip_id, "twl4030-audio",
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300831 pdata->audio, sizeof(*pdata->audio),
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600832 false, 0, 0);
833 if (IS_ERR(child))
834 return PTR_ERR(child);
835 }
836
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300837 if (twl_has_codec() && pdata->audio && twl_class_is_6030()) {
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600838 sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
Misael Lopez Cruzf19b2822011-04-27 02:14:07 -0500839 child = add_child(sub_chip_id, "twl6040",
Peter Ujfalusi4ae6df52011-05-31 15:21:13 +0300840 pdata->audio, sizeof(*pdata->audio),
Peter Ujfalusi0b83dde2009-10-22 13:26:45 +0300841 false, 0, 0);
842 if (IS_ERR(child))
843 return PTR_ERR(child);
844 }
845
Rajendra Nayak9da66532009-12-13 22:29:47 +0100846 /* twl4030 regulators */
847 if (twl_has_regulator() && twl_class_is_4030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100848 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
849 features);
David Brownelldad759f2008-12-01 00:43:58 +0100850 if (IS_ERR(child))
851 return PTR_ERR(child);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100852
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100853 child = add_regulator(TWL4030_REG_VIO, pdata->vio,
854 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100855 if (IS_ERR(child))
856 return PTR_ERR(child);
857
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100858 child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1,
859 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100860 if (IS_ERR(child))
861 return PTR_ERR(child);
862
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100863 child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2,
864 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100865 if (IS_ERR(child))
866 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100867
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100868 child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1,
869 features);
David Brownelldad759f2008-12-01 00:43:58 +0100870 if (IS_ERR(child))
871 return PTR_ERR(child);
872
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100873 child = add_regulator(TWL4030_REG_VDAC, pdata->vdac,
874 features);
David Brownelldad759f2008-12-01 00:43:58 +0100875 if (IS_ERR(child))
876 return PTR_ERR(child);
877
878 child = add_regulator((features & TWL4030_VAUX2)
879 ? TWL4030_REG_VAUX2_4030
880 : TWL4030_REG_VAUX2,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100881 pdata->vaux2, features);
David Brownelldad759f2008-12-01 00:43:58 +0100882 if (IS_ERR(child))
883 return PTR_ERR(child);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100884
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100885 child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1,
886 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100887 if (IS_ERR(child))
888 return PTR_ERR(child);
889
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100890 child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2,
891 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100892 if (IS_ERR(child))
893 return PTR_ERR(child);
894
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100895 child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig,
896 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100897 if (IS_ERR(child))
898 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100899 }
900
David Brownelldad759f2008-12-01 00:43:58 +0100901 /* maybe add LDOs that are omitted on cost-reduced parts */
Rajendra Nayak9da66532009-12-13 22:29:47 +0100902 if (twl_has_regulator() && !(features & TPS_SUBSET)
903 && twl_class_is_4030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100904 child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2,
905 features);
David Brownelldad759f2008-12-01 00:43:58 +0100906 if (IS_ERR(child))
907 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100908
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100909 child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2,
910 features);
David Brownelldad759f2008-12-01 00:43:58 +0100911 if (IS_ERR(child))
912 return PTR_ERR(child);
913
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100914 child = add_regulator(TWL4030_REG_VSIM, pdata->vsim,
915 features);
David Brownelldad759f2008-12-01 00:43:58 +0100916 if (IS_ERR(child))
917 return PTR_ERR(child);
918
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100919 child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1,
920 features);
David Brownelldad759f2008-12-01 00:43:58 +0100921 if (IS_ERR(child))
922 return PTR_ERR(child);
923
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100924 child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3,
925 features);
David Brownelldad759f2008-12-01 00:43:58 +0100926 if (IS_ERR(child))
927 return PTR_ERR(child);
928
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100929 child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4,
930 features);
David Brownelldad759f2008-12-01 00:43:58 +0100931 if (IS_ERR(child))
932 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200933 }
934
Rajendra Nayak9da66532009-12-13 22:29:47 +0100935 /* twl6030 regulators */
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100936 if (twl_has_regulator() && twl_class_is_6030() &&
937 !(features & TWL6025_SUBCLASS)) {
938 child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc,
939 features);
940 if (IS_ERR(child))
941 return PTR_ERR(child);
942
943 child = add_regulator(TWL6030_REG_VPP, pdata->vpp,
944 features);
945 if (IS_ERR(child))
946 return PTR_ERR(child);
947
948 child = add_regulator(TWL6030_REG_VUSIM, pdata->vusim,
949 features);
950 if (IS_ERR(child))
951 return PTR_ERR(child);
952
953 child = add_regulator(TWL6030_REG_VCXIO, pdata->vcxio,
954 features);
955 if (IS_ERR(child))
956 return PTR_ERR(child);
957
958 child = add_regulator(TWL6030_REG_VDAC, pdata->vdac,
959 features);
960 if (IS_ERR(child))
961 return PTR_ERR(child);
962
963 child = add_regulator(TWL6030_REG_VAUX1_6030, pdata->vaux1,
964 features);
965 if (IS_ERR(child))
966 return PTR_ERR(child);
967
968 child = add_regulator(TWL6030_REG_VAUX2_6030, pdata->vaux2,
969 features);
970 if (IS_ERR(child))
971 return PTR_ERR(child);
972
973 child = add_regulator(TWL6030_REG_VAUX3_6030, pdata->vaux3,
974 features);
975 if (IS_ERR(child))
976 return PTR_ERR(child);
977
978 child = add_regulator(TWL6030_REG_CLK32KG, pdata->clk32kg,
979 features);
980 if (IS_ERR(child))
981 return PTR_ERR(child);
982 }
983
984 /* 6030 and 6025 share this regulator */
Rajendra Nayak9da66532009-12-13 22:29:47 +0100985 if (twl_has_regulator() && twl_class_is_6030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100986 child = add_regulator(TWL6030_REG_VANA, pdata->vana,
987 features);
988 if (IS_ERR(child))
989 return PTR_ERR(child);
990 }
991
992 /* twl6025 regulators */
993 if (twl_has_regulator() && twl_class_is_6030() &&
994 (features & TWL6025_SUBCLASS)) {
995 child = add_regulator(TWL6025_REG_LDO5, pdata->ldo5,
996 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +0100997 if (IS_ERR(child))
998 return PTR_ERR(child);
999
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001000 child = add_regulator(TWL6025_REG_LDO1, pdata->ldo1,
1001 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001002 if (IS_ERR(child))
1003 return PTR_ERR(child);
1004
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001005 child = add_regulator(TWL6025_REG_LDO7, pdata->ldo7,
1006 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001007 if (IS_ERR(child))
1008 return PTR_ERR(child);
1009
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001010 child = add_regulator(TWL6025_REG_LDO6, pdata->ldo6,
1011 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001012 if (IS_ERR(child))
1013 return PTR_ERR(child);
1014
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001015 child = add_regulator(TWL6025_REG_LDOLN, pdata->ldoln,
1016 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001017 if (IS_ERR(child))
1018 return PTR_ERR(child);
1019
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001020 child = add_regulator(TWL6025_REG_LDO2, pdata->ldo2,
1021 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001022 if (IS_ERR(child))
1023 return PTR_ERR(child);
1024
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001025 child = add_regulator(TWL6025_REG_LDO4, pdata->ldo4,
1026 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001027 if (IS_ERR(child))
1028 return PTR_ERR(child);
1029
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001030 child = add_regulator(TWL6025_REG_LDO3, pdata->ldo3,
1031 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001032 if (IS_ERR(child))
1033 return PTR_ERR(child);
1034
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001035 child = add_regulator(TWL6025_REG_SMPS3, pdata->smps3,
1036 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001037 if (IS_ERR(child))
1038 return PTR_ERR(child);
Balaji T K8e6de4a2011-02-10 18:44:50 +05301039
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001040 child = add_regulator(TWL6025_REG_SMPS4, pdata->smps4,
1041 features);
Balaji T K8e6de4a2011-02-10 18:44:50 +05301042 if (IS_ERR(child))
1043 return PTR_ERR(child);
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001044
1045 child = add_regulator(TWL6025_REG_VIO, pdata->vio6025,
1046 features);
1047 if (IS_ERR(child))
1048 return PTR_ERR(child);
1049
Rajendra Nayak9da66532009-12-13 22:29:47 +01001050 }
1051
Grazvydas Ignotas11c39c42010-10-01 13:17:50 +03001052 if (twl_has_bci() && pdata->bci &&
1053 !(features & (TPS_SUBSET | TWL5031))) {
1054 child = add_child(3, "twl4030_bci",
1055 pdata->bci, sizeof(*pdata->bci), false,
1056 /* irq0 = CHG_PRES, irq1 = BCI */
1057 pdata->irq_base + BCI_PRES_INTR_OFFSET,
1058 pdata->irq_base + BCI_INTR_OFFSET);
1059 if (IS_ERR(child))
1060 return PTR_ERR(child);
1061 }
1062
David Brownell5725d662008-12-01 00:31:04 +01001063 return 0;
David Brownella603a7f2008-10-15 12:15:39 +02001064}
1065
1066/*----------------------------------------------------------------------*/
1067
1068/*
1069 * These three functions initialize the on-chip clock framework,
1070 * letting it generate the right frequencies for USB, MADC, and
1071 * other purposes.
1072 */
1073static inline int __init protect_pm_master(void)
1074{
1075 int e = 0;
1076
Felipe Balbi49e6f872010-08-18 09:19:35 +03001077 e = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0,
1078 TWL4030_PM_MASTER_PROTECT_KEY);
David Brownella603a7f2008-10-15 12:15:39 +02001079 return e;
1080}
1081
1082static inline int __init unprotect_pm_master(void)
1083{
1084 int e = 0;
1085
Felipe Balbi49e6f872010-08-18 09:19:35 +03001086 e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
1087 TWL4030_PM_MASTER_KEY_CFG1,
1088 TWL4030_PM_MASTER_PROTECT_KEY);
1089 e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
1090 TWL4030_PM_MASTER_KEY_CFG2,
1091 TWL4030_PM_MASTER_PROTECT_KEY);
1092
David Brownella603a7f2008-10-15 12:15:39 +02001093 return e;
1094}
1095
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001096static void clocks_init(struct device *dev,
1097 struct twl4030_clock_init_data *clock)
David Brownella603a7f2008-10-15 12:15:39 +02001098{
1099 int e = 0;
1100 struct clk *osc;
1101 u32 rate;
1102 u8 ctrl = HFCLK_FREQ_26_MHZ;
1103
1104#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
1105 if (cpu_is_omap2430())
Russell Kinge6b50c82009-01-10 10:40:42 +00001106 osc = clk_get(dev, "osc_ck");
David Brownella603a7f2008-10-15 12:15:39 +02001107 else
Russell Kinge6b50c82009-01-10 10:40:42 +00001108 osc = clk_get(dev, "osc_sys_ck");
Samuel Ortiz6354ab52008-12-07 20:50:25 +01001109
David Brownella603a7f2008-10-15 12:15:39 +02001110 if (IS_ERR(osc)) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001111 printk(KERN_WARNING "Skipping twl internal clock init and "
David Brownella603a7f2008-10-15 12:15:39 +02001112 "using bootloader value (unknown osc rate)\n");
1113 return;
1114 }
1115
1116 rate = clk_get_rate(osc);
1117 clk_put(osc);
1118
Samuel Ortiz6354ab52008-12-07 20:50:25 +01001119#else
1120 /* REVISIT for non-OMAP systems, pass the clock rate from
1121 * board init code, using platform_data.
1122 */
1123 osc = ERR_PTR(-EIO);
1124
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001125 printk(KERN_WARNING "Skipping twl internal clock init and "
Samuel Ortiz6354ab52008-12-07 20:50:25 +01001126 "using bootloader value (unknown osc rate)\n");
1127
1128 return;
1129#endif
1130
David Brownella603a7f2008-10-15 12:15:39 +02001131 switch (rate) {
1132 case 19200000:
1133 ctrl = HFCLK_FREQ_19p2_MHZ;
1134 break;
1135 case 26000000:
1136 ctrl = HFCLK_FREQ_26_MHZ;
1137 break;
1138 case 38400000:
1139 ctrl = HFCLK_FREQ_38p4_MHZ;
1140 break;
1141 }
1142
1143 ctrl |= HIGH_PERF_SQ;
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001144 if (clock && clock->ck32k_lowpwr_enable)
1145 ctrl |= CK32K_LOWPWR_EN;
1146
David Brownella603a7f2008-10-15 12:15:39 +02001147 e |= unprotect_pm_master();
1148 /* effect->MADC+USB ck en */
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001149 e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
David Brownella603a7f2008-10-15 12:15:39 +02001150 e |= protect_pm_master();
1151
1152 if (e < 0)
1153 pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
1154}
1155
1156/*----------------------------------------------------------------------*/
1157
Balaji T Ke8deb282009-12-14 00:25:31 +01001158int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end);
1159int twl4030_exit_irq(void);
1160int twl4030_init_chip_irq(const char *chip);
1161int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end);
1162int twl6030_exit_irq(void);
David Brownella603a7f2008-10-15 12:15:39 +02001163
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001164static int twl_remove(struct i2c_client *client)
David Brownella603a7f2008-10-15 12:15:39 +02001165{
1166 unsigned i;
David Brownella30d46c2008-10-20 23:46:28 +02001167 int status;
David Brownella603a7f2008-10-15 12:15:39 +02001168
Balaji T Ke8deb282009-12-14 00:25:31 +01001169 if (twl_class_is_4030())
1170 status = twl4030_exit_irq();
1171 else
1172 status = twl6030_exit_irq();
1173
David Brownella30d46c2008-10-20 23:46:28 +02001174 if (status < 0)
1175 return status;
David Brownella603a7f2008-10-15 12:15:39 +02001176
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001177 for (i = 0; i < TWL_NUM_SLAVES; i++) {
1178 struct twl_client *twl = &twl_modules[i];
David Brownella603a7f2008-10-15 12:15:39 +02001179
1180 if (twl->client && twl->client != client)
1181 i2c_unregister_device(twl->client);
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001182 twl_modules[i].client = NULL;
David Brownella603a7f2008-10-15 12:15:39 +02001183 }
1184 inuse = false;
1185 return 0;
1186}
1187
1188/* NOTE: this driver only handles a single twl4030/tps659x0 chip */
Bryan Wu5b9cecd2010-12-08 10:42:04 +08001189static int __devinit
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001190twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
David Brownella603a7f2008-10-15 12:15:39 +02001191{
1192 int status;
1193 unsigned i;
1194 struct twl4030_platform_data *pdata = client->dev.platform_data;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001195 struct device_node *node = client->dev.of_node;
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001196 u8 temp;
Lesly A Mca972d12011-04-14 17:57:53 +05301197 int ret = 0;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001198 int nr_irqs = TWL4030_NR_IRQS;
1199
1200 if ((id->driver_data) & TWL6030_CLASS)
1201 nr_irqs = TWL6030_NR_IRQS;
1202
1203 if (node && !pdata) {
1204 /*
1205 * XXX: Temporary pdata until the information is correctly
1206 * retrieved by every TWL modules from DT.
1207 */
1208 pdata = devm_kzalloc(&client->dev,
1209 sizeof(struct twl4030_platform_data),
1210 GFP_KERNEL);
1211 if (!pdata)
1212 return -ENOMEM;
1213 }
David Brownella603a7f2008-10-15 12:15:39 +02001214
1215 if (!pdata) {
1216 dev_dbg(&client->dev, "no platform data?\n");
1217 return -EINVAL;
1218 }
1219
Benoit Coussonaeb50322011-08-29 16:20:23 +02001220 status = irq_alloc_descs(-1, pdata->irq_base, nr_irqs, 0);
1221 if (IS_ERR_VALUE(status)) {
1222 dev_err(&client->dev, "Fail to allocate IRQ descs\n");
1223 return status;
1224 }
1225
1226 pdata->irq_base = status;
1227 pdata->irq_end = pdata->irq_base + nr_irqs;
1228
1229 domain.irq_base = pdata->irq_base;
1230 domain.nr_irq = nr_irqs;
1231#ifdef CONFIG_OF_IRQ
1232 domain.of_node = of_node_get(node);
1233 domain.ops = &irq_domain_simple_ops;
1234#endif
1235 irq_domain_add(&domain);
1236
David Brownella603a7f2008-10-15 12:15:39 +02001237 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1238 dev_dbg(&client->dev, "can't talk I2C?\n");
1239 return -EIO;
1240 }
1241
David Brownella30d46c2008-10-20 23:46:28 +02001242 if (inuse) {
David Brownella603a7f2008-10-15 12:15:39 +02001243 dev_dbg(&client->dev, "driver is already in use\n");
1244 return -EBUSY;
1245 }
1246
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001247 for (i = 0; i < TWL_NUM_SLAVES; i++) {
1248 struct twl_client *twl = &twl_modules[i];
David Brownella603a7f2008-10-15 12:15:39 +02001249
1250 twl->address = client->addr + i;
1251 if (i == 0)
1252 twl->client = client;
1253 else {
1254 twl->client = i2c_new_dummy(client->adapter,
1255 twl->address);
1256 if (!twl->client) {
Ilkka Koskinena8643432009-10-20 16:22:52 +03001257 dev_err(&client->dev,
David Brownella603a7f2008-10-15 12:15:39 +02001258 "can't attach client %d\n", i);
1259 status = -ENOMEM;
1260 goto fail;
1261 }
David Brownella603a7f2008-10-15 12:15:39 +02001262 }
1263 mutex_init(&twl->xfer_lock);
1264 }
1265 inuse = true;
Balaji T Ke8deb282009-12-14 00:25:31 +01001266 if ((id->driver_data) & TWL6030_CLASS) {
1267 twl_id = TWL6030_CLASS_ID;
1268 twl_map = &twl6030_map[0];
1269 } else {
1270 twl_id = TWL4030_CLASS_ID;
1271 twl_map = &twl4030_map[0];
1272 }
David Brownella603a7f2008-10-15 12:15:39 +02001273
1274 /* setup clock framework */
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001275 clocks_init(&client->dev, pdata->clock);
David Brownella603a7f2008-10-15 12:15:39 +02001276
Lesly A Mca972d12011-04-14 17:57:53 +05301277 /* read TWL IDCODE Register */
1278 if (twl_id == TWL4030_CLASS_ID) {
1279 ret = twl_read_idcode_register();
1280 WARN(ret < 0, "Error: reading twl_idcode register value\n");
1281 }
1282
Amit Kucheriaebf0bd32009-08-31 18:32:18 +02001283 /* load power event scripts */
1284 if (twl_has_power() && pdata->power)
1285 twl4030_power_init(pdata->power);
1286
David Brownella603a7f2008-10-15 12:15:39 +02001287 /* Maybe init the T2 Interrupt subsystem */
1288 if (client->irq
1289 && pdata->irq_base
1290 && pdata->irq_end > pdata->irq_base) {
Balaji T Ke8deb282009-12-14 00:25:31 +01001291 if (twl_class_is_4030()) {
1292 twl4030_init_chip_irq(id->name);
1293 status = twl4030_init_irq(client->irq, pdata->irq_base,
1294 pdata->irq_end);
1295 } else {
1296 status = twl6030_init_irq(client->irq, pdata->irq_base,
1297 pdata->irq_end);
1298 }
1299
David Brownella30d46c2008-10-20 23:46:28 +02001300 if (status < 0)
1301 goto fail;
David Brownella603a7f2008-10-15 12:15:39 +02001302 }
1303
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001304 /* Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
1305 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
1306 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
1307 */
1308
1309 if (twl_class_is_4030()) {
1310 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
1311 temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
1312 I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
1313 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
1314 }
1315
Benoit Coussonaeb50322011-08-29 16:20:23 +02001316#ifdef CONFIG_OF_DEVICE
1317 if (node)
1318 status = of_platform_populate(node, NULL, NULL, &client->dev);
1319 else
1320#endif
1321 status = add_children(pdata, id->driver_data);
1322
David Brownella603a7f2008-10-15 12:15:39 +02001323fail:
1324 if (status < 0)
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001325 twl_remove(client);
David Brownella603a7f2008-10-15 12:15:39 +02001326 return status;
1327}
1328
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001329static const struct i2c_device_id twl_ids[] = {
David Brownelldad759f2008-12-01 00:43:58 +01001330 { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */
1331 { "twl5030", 0 }, /* T2 updated */
Ilkka Koskinen1920a612009-11-10 17:26:15 +02001332 { "twl5031", TWL5031 }, /* TWL5030 updated */
David Brownelldad759f2008-12-01 00:43:58 +01001333 { "tps65950", 0 }, /* catalog version of twl5030 */
1334 { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */
1335 { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */
Oleg Drokin59dead52011-07-01 13:34:13 +02001336 { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED
1337 and vibrator. Charger in USB module*/
Balaji T Ke8deb282009-12-14 00:25:31 +01001338 { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001339 { "twl6025", TWL6030_CLASS | TWL6025_SUBCLASS }, /* "Phoenix lite" */
David Brownella603a7f2008-10-15 12:15:39 +02001340 { /* end of list */ },
1341};
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001342MODULE_DEVICE_TABLE(i2c, twl_ids);
David Brownella603a7f2008-10-15 12:15:39 +02001343
1344/* One Client Driver , 4 Clients */
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001345static struct i2c_driver twl_driver = {
David Brownella603a7f2008-10-15 12:15:39 +02001346 .driver.name = DRIVER_NAME,
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001347 .id_table = twl_ids,
1348 .probe = twl_probe,
1349 .remove = twl_remove,
David Brownella603a7f2008-10-15 12:15:39 +02001350};
1351
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001352static int __init twl_init(void)
David Brownella603a7f2008-10-15 12:15:39 +02001353{
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001354 return i2c_add_driver(&twl_driver);
David Brownella603a7f2008-10-15 12:15:39 +02001355}
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001356subsys_initcall(twl_init);
David Brownella603a7f2008-10-15 12:15:39 +02001357
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001358static void __exit twl_exit(void)
David Brownella603a7f2008-10-15 12:15:39 +02001359{
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001360 i2c_del_driver(&twl_driver);
David Brownella603a7f2008-10-15 12:15:39 +02001361}
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001362module_exit(twl_exit);
David Brownella603a7f2008-10-15 12:15:39 +02001363
1364MODULE_AUTHOR("Texas Instruments, Inc.");
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001365MODULE_DESCRIPTION("I2C Core interface for TWL");
David Brownella603a7f2008-10-15 12:15:39 +02001366MODULE_LICENSE("GPL");