blob: e208d88d2180c2a04fe5d18ae0f8dfcce8b06d9e [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
Benoit Cousson1b8f3332012-02-29 19:28:14 +010049#include "twl-core.h"
David Brownella603a7f2008-10-15 12:15:39 +020050
51/*
52 * The TWL4030 "Triton 2" is one of a family of a multi-function "Power
53 * Management and System Companion Device" chips originally designed for
54 * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C,
55 * often at around 3 Mbit/sec, including for interrupt handling.
56 *
57 * This driver core provides genirq support for the interrupts emitted,
58 * by the various modules, and exports register access primitives.
59 *
60 * FIXME this driver currently requires use of the first interrupt line
61 * (and associated registers).
62 */
63
Balaji T Kfc7b92f2009-12-13 21:23:33 +010064#define DRIVER_NAME "twl"
David Brownella603a7f2008-10-15 12:15:39 +020065
David Brownella603a7f2008-10-15 12:15:39 +020066/* Triton Core internal information (BEGIN) */
67
68/* Last - for index max*/
69#define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG
70
Balaji T Kfc7b92f2009-12-13 21:23:33 +010071#define TWL_NUM_SLAVES 4
David Brownella603a7f2008-10-15 12:15:39 +020072
Balaji T Kfc7b92f2009-12-13 21:23:33 +010073#define SUB_CHIP_ID0 0
74#define SUB_CHIP_ID1 1
75#define SUB_CHIP_ID2 2
76#define SUB_CHIP_ID3 3
Peter Ujfalusi364cedb2012-01-04 14:58:33 +020077#define SUB_CHIP_ID_INVAL 0xff
Balaji T Kfc7b92f2009-12-13 21:23:33 +010078
79#define TWL_MODULE_LAST TWL4030_MODULE_LAST
80
David Brownella603a7f2008-10-15 12:15:39 +020081/* Base Address defns for twl4030_map[] */
82
83/* subchip/slave 0 - USB ID */
84#define TWL4030_BASEADD_USB 0x0000
85
86/* subchip/slave 1 - AUD ID */
87#define TWL4030_BASEADD_AUDIO_VOICE 0x0000
88#define TWL4030_BASEADD_GPIO 0x0098
89#define TWL4030_BASEADD_INTBR 0x0085
90#define TWL4030_BASEADD_PIH 0x0080
91#define TWL4030_BASEADD_TEST 0x004C
92
93/* subchip/slave 2 - AUX ID */
94#define TWL4030_BASEADD_INTERRUPTS 0x00B9
95#define TWL4030_BASEADD_LED 0x00EE
96#define TWL4030_BASEADD_MADC 0x0000
97#define TWL4030_BASEADD_MAIN_CHARGE 0x0074
98#define TWL4030_BASEADD_PRECHARGE 0x00AA
99#define TWL4030_BASEADD_PWM0 0x00F8
100#define TWL4030_BASEADD_PWM1 0x00FB
101#define TWL4030_BASEADD_PWMA 0x00EF
102#define TWL4030_BASEADD_PWMB 0x00F1
103#define TWL4030_BASEADD_KEYPAD 0x00D2
104
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200105#define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */
106#define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's
107 one */
108
David Brownella603a7f2008-10-15 12:15:39 +0200109/* subchip/slave 3 - POWER ID */
110#define TWL4030_BASEADD_BACKUP 0x0014
111#define TWL4030_BASEADD_INT 0x002E
112#define TWL4030_BASEADD_PM_MASTER 0x0036
113#define TWL4030_BASEADD_PM_RECEIVER 0x005B
114#define TWL4030_BASEADD_RTC 0x001C
115#define TWL4030_BASEADD_SECURED_REG 0x0000
116
117/* Triton Core internal information (END) */
118
119
Balaji T Ke8deb282009-12-14 00:25:31 +0100120/* subchip/slave 0 0x48 - POWER */
121#define TWL6030_BASEADD_RTC 0x0000
122#define TWL6030_BASEADD_MEM 0x0017
123#define TWL6030_BASEADD_PM_MASTER 0x001F
124#define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */
125#define TWL6030_BASEADD_PM_MISC 0x00E2
126#define TWL6030_BASEADD_PM_PUPD 0x00F0
127
128/* subchip/slave 1 0x49 - FEATURE */
129#define TWL6030_BASEADD_USB 0x0000
130#define TWL6030_BASEADD_GPADC_CTRL 0x002E
131#define TWL6030_BASEADD_AUX 0x0090
132#define TWL6030_BASEADD_PWM 0x00BA
133#define TWL6030_BASEADD_GASGAUGE 0x00C0
134#define TWL6030_BASEADD_PIH 0x00D0
135#define TWL6030_BASEADD_CHARGER 0x00E0
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100136#define TWL6025_BASEADD_CHARGER 0x00DA
Balaji T Ke8deb282009-12-14 00:25:31 +0100137
138/* subchip/slave 2 0x4A - DFT */
139#define TWL6030_BASEADD_DIEID 0x00C0
140
141/* subchip/slave 3 0x4B - AUDIO */
142#define TWL6030_BASEADD_AUDIO 0x0000
143#define TWL6030_BASEADD_RSV 0x0000
Balaji T Kfa0d9762010-02-19 12:39:38 +0100144#define TWL6030_BASEADD_ZERO 0x0000
Balaji T Ke8deb282009-12-14 00:25:31 +0100145
David Brownella603a7f2008-10-15 12:15:39 +0200146/* Few power values */
147#define R_CFG_BOOT 0x05
David Brownella603a7f2008-10-15 12:15:39 +0200148
149/* some fields in R_CFG_BOOT */
150#define HFCLK_FREQ_19p2_MHZ (1 << 0)
151#define HFCLK_FREQ_26_MHZ (2 << 0)
152#define HFCLK_FREQ_38p4_MHZ (3 << 0)
153#define HIGH_PERF_SQ (1 << 3)
Ilkka Koskinen38a68492009-10-22 14:14:09 +0300154#define CK32K_LOWPWR_EN (1 << 7)
David Brownella603a7f2008-10-15 12:15:39 +0200155
David Brownella603a7f2008-10-15 12:15:39 +0200156/*----------------------------------------------------------------------*/
157
David Brownella603a7f2008-10-15 12:15:39 +0200158/* is driver active, bound to a chip? */
159static bool inuse;
160
Lesly A Mca972d12011-04-14 17:57:53 +0530161/* TWL IDCODE Register value */
162static u32 twl_idcode;
163
Balaji T Ke8deb282009-12-14 00:25:31 +0100164static unsigned int twl_id;
165unsigned int twl_rev(void)
166{
167 return twl_id;
168}
169EXPORT_SYMBOL(twl_rev);
170
171/* Structure for each TWL4030/TWL6030 Slave */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100172struct twl_client {
David Brownella603a7f2008-10-15 12:15:39 +0200173 struct i2c_client *client;
174 u8 address;
175
176 /* max numb of i2c_msg required is for read =2 */
177 struct i2c_msg xfer_msg[2];
178
179 /* To lock access to xfer_msg */
180 struct mutex xfer_lock;
181};
182
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100183static struct twl_client twl_modules[TWL_NUM_SLAVES];
David Brownella603a7f2008-10-15 12:15:39 +0200184
David Brownella603a7f2008-10-15 12:15:39 +0200185/* mapping the module id to slave id and base address */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100186struct twl_mapping {
David Brownella603a7f2008-10-15 12:15:39 +0200187 unsigned char sid; /* Slave ID */
188 unsigned char base; /* base address */
189};
G, Manjunath Kondaiah2cfcce12010-09-21 15:31:17 +0530190static struct twl_mapping *twl_map;
David Brownella603a7f2008-10-15 12:15:39 +0200191
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100192static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = {
David Brownella603a7f2008-10-15 12:15:39 +0200193 /*
194 * NOTE: don't change this table without updating the
Balaji T Ke8deb282009-12-14 00:25:31 +0100195 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
David Brownella603a7f2008-10-15 12:15:39 +0200196 * so they continue to match the order in this table.
197 */
198
199 { 0, TWL4030_BASEADD_USB },
200
201 { 1, TWL4030_BASEADD_AUDIO_VOICE },
202 { 1, TWL4030_BASEADD_GPIO },
203 { 1, TWL4030_BASEADD_INTBR },
204 { 1, TWL4030_BASEADD_PIH },
205 { 1, TWL4030_BASEADD_TEST },
206
207 { 2, TWL4030_BASEADD_KEYPAD },
208 { 2, TWL4030_BASEADD_MADC },
209 { 2, TWL4030_BASEADD_INTERRUPTS },
210 { 2, TWL4030_BASEADD_LED },
211 { 2, TWL4030_BASEADD_MAIN_CHARGE },
212 { 2, TWL4030_BASEADD_PRECHARGE },
213 { 2, TWL4030_BASEADD_PWM0 },
214 { 2, TWL4030_BASEADD_PWM1 },
215 { 2, TWL4030_BASEADD_PWMA },
216 { 2, TWL4030_BASEADD_PWMB },
Ilkka Koskinen1920a612009-11-10 17:26:15 +0200217 { 2, TWL5031_BASEADD_ACCESSORY },
218 { 2, TWL5031_BASEADD_INTERRUPTS },
David Brownella603a7f2008-10-15 12:15:39 +0200219
220 { 3, TWL4030_BASEADD_BACKUP },
221 { 3, TWL4030_BASEADD_INT },
222 { 3, TWL4030_BASEADD_PM_MASTER },
223 { 3, TWL4030_BASEADD_PM_RECEIVER },
224 { 3, TWL4030_BASEADD_RTC },
225 { 3, TWL4030_BASEADD_SECURED_REG },
226};
227
Balaji T Ke8deb282009-12-14 00:25:31 +0100228static struct twl_mapping twl6030_map[] = {
229 /*
230 * NOTE: don't change this table without updating the
231 * <linux/i2c/twl.h> defines for TWL4030_MODULE_*
232 * so they continue to match the order in this table.
233 */
234 { SUB_CHIP_ID1, TWL6030_BASEADD_USB },
Peter Ujfalusi364cedb2012-01-04 14:58:33 +0200235 { SUB_CHIP_ID_INVAL, TWL6030_BASEADD_AUDIO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100236 { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID },
237 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
238 { SUB_CHIP_ID1, TWL6030_BASEADD_PIH },
239
240 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
241 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
242 { SUB_CHIP_ID1, TWL6030_BASEADD_GPADC_CTRL },
243 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
244 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
245
246 { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER },
247 { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE },
248 { SUB_CHIP_ID1, TWL6030_BASEADD_PWM },
Balaji T Kfa0d9762010-02-19 12:39:38 +0100249 { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO },
250 { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100251
Balaji T Kfa0d9762010-02-19 12:39:38 +0100252 { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO },
253 { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO },
Balaji T Ke8deb282009-12-14 00:25:31 +0100254 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
255 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
256 { SUB_CHIP_ID2, TWL6030_BASEADD_RSV },
257 { SUB_CHIP_ID0, TWL6030_BASEADD_PM_MASTER },
258 { SUB_CHIP_ID0, TWL6030_BASEADD_PM_SLAVE_MISC },
259
260 { SUB_CHIP_ID0, TWL6030_BASEADD_RTC },
261 { SUB_CHIP_ID0, TWL6030_BASEADD_MEM },
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100262 { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER },
Balaji T Ke8deb282009-12-14 00:25:31 +0100263};
264
David Brownella603a7f2008-10-15 12:15:39 +0200265/*----------------------------------------------------------------------*/
266
David Brownella603a7f2008-10-15 12:15:39 +0200267/* Exported Functions */
268
269/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100270 * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200271 * @mod_no: module number
272 * @value: an array of num_bytes+1 containing data to write
273 * @reg: register address (just offset will do)
274 * @num_bytes: number of bytes to transfer
275 *
276 * IMPORTANT: for 'value' parameter: Allocate value num_bytes+1 and
277 * valid data starts at Offset 1.
278 *
279 * Returns the result of operation - 0 is success
280 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100281int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
David Brownella603a7f2008-10-15 12:15:39 +0200282{
283 int ret;
284 int sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100285 struct twl_client *twl;
David Brownella603a7f2008-10-15 12:15:39 +0200286 struct i2c_msg *msg;
287
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100288 if (unlikely(mod_no > TWL_MODULE_LAST)) {
David Brownella603a7f2008-10-15 12:15:39 +0200289 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
290 return -EPERM;
291 }
Ilya Yanok8653be12011-08-01 23:00:28 +0200292 if (unlikely(!inuse)) {
293 pr_err("%s: not initialized\n", DRIVER_NAME);
294 return -EPERM;
295 }
Balaji T Ke8deb282009-12-14 00:25:31 +0100296 sid = twl_map[mod_no].sid;
Peter Ujfalusi364cedb2012-01-04 14:58:33 +0200297 if (unlikely(sid == SUB_CHIP_ID_INVAL)) {
298 pr_err("%s: module %d is not part of the pmic\n",
299 DRIVER_NAME, mod_no);
300 return -EINVAL;
301 }
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100302 twl = &twl_modules[sid];
David Brownella603a7f2008-10-15 12:15:39 +0200303
David Brownella603a7f2008-10-15 12:15:39 +0200304 mutex_lock(&twl->xfer_lock);
305 /*
306 * [MSG1]: fill the register address data
307 * fill the data Tx buffer
308 */
309 msg = &twl->xfer_msg[0];
310 msg->addr = twl->address;
311 msg->len = num_bytes + 1;
312 msg->flags = 0;
313 msg->buf = value;
314 /* over write the first byte of buffer with the register address */
Balaji T Ke8deb282009-12-14 00:25:31 +0100315 *value = twl_map[mod_no].base + reg;
David Brownella603a7f2008-10-15 12:15:39 +0200316 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1);
317 mutex_unlock(&twl->xfer_lock);
318
Amit Kucheria147e0842009-12-11 13:21:45 +0100319 /* i2c_transfer returns number of messages transferred */
320 if (ret != 1) {
321 pr_err("%s: i2c_write failed to transfer all messages\n",
322 DRIVER_NAME);
323 if (ret < 0)
324 return ret;
325 else
326 return -EIO;
327 } else {
328 return 0;
329 }
David Brownella603a7f2008-10-15 12:15:39 +0200330}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100331EXPORT_SYMBOL(twl_i2c_write);
David Brownella603a7f2008-10-15 12:15:39 +0200332
333/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100334 * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200335 * @mod_no: module number
336 * @value: an array of num_bytes containing data to be read
337 * @reg: register address (just offset will do)
338 * @num_bytes: number of bytes to transfer
339 *
340 * Returns result of operation - num_bytes is success else failure.
341 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100342int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
David Brownella603a7f2008-10-15 12:15:39 +0200343{
344 int ret;
345 u8 val;
346 int sid;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100347 struct twl_client *twl;
David Brownella603a7f2008-10-15 12:15:39 +0200348 struct i2c_msg *msg;
349
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100350 if (unlikely(mod_no > TWL_MODULE_LAST)) {
David Brownella603a7f2008-10-15 12:15:39 +0200351 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
352 return -EPERM;
353 }
Ilya Yanok8653be12011-08-01 23:00:28 +0200354 if (unlikely(!inuse)) {
355 pr_err("%s: not initialized\n", DRIVER_NAME);
356 return -EPERM;
357 }
Balaji T Ke8deb282009-12-14 00:25:31 +0100358 sid = twl_map[mod_no].sid;
Peter Ujfalusi364cedb2012-01-04 14:58:33 +0200359 if (unlikely(sid == SUB_CHIP_ID_INVAL)) {
360 pr_err("%s: module %d is not part of the pmic\n",
361 DRIVER_NAME, mod_no);
362 return -EINVAL;
363 }
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100364 twl = &twl_modules[sid];
David Brownella603a7f2008-10-15 12:15:39 +0200365
David Brownella603a7f2008-10-15 12:15:39 +0200366 mutex_lock(&twl->xfer_lock);
367 /* [MSG1] fill the register address data */
368 msg = &twl->xfer_msg[0];
369 msg->addr = twl->address;
370 msg->len = 1;
371 msg->flags = 0; /* Read the register value */
Balaji T Ke8deb282009-12-14 00:25:31 +0100372 val = twl_map[mod_no].base + reg;
David Brownella603a7f2008-10-15 12:15:39 +0200373 msg->buf = &val;
374 /* [MSG2] fill the data rx buffer */
375 msg = &twl->xfer_msg[1];
376 msg->addr = twl->address;
377 msg->flags = I2C_M_RD; /* Read the register value */
378 msg->len = num_bytes; /* only n bytes */
379 msg->buf = value;
380 ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2);
381 mutex_unlock(&twl->xfer_lock);
382
Amit Kucheria147e0842009-12-11 13:21:45 +0100383 /* i2c_transfer returns number of messages transferred */
384 if (ret != 2) {
385 pr_err("%s: i2c_read failed to transfer all messages\n",
386 DRIVER_NAME);
387 if (ret < 0)
388 return ret;
389 else
390 return -EIO;
391 } else {
392 return 0;
393 }
David Brownella603a7f2008-10-15 12:15:39 +0200394}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100395EXPORT_SYMBOL(twl_i2c_read);
David Brownella603a7f2008-10-15 12:15:39 +0200396
397/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100398 * twl_i2c_write_u8 - Writes a 8 bit register in TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200399 * @mod_no: module number
400 * @value: the value to be written 8 bit
401 * @reg: register address (just offset will do)
402 *
403 * Returns result of operation - 0 is success
404 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100405int twl_i2c_write_u8(u8 mod_no, u8 value, u8 reg)
David Brownella603a7f2008-10-15 12:15:39 +0200406{
407
408 /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */
409 u8 temp_buffer[2] = { 0 };
410 /* offset 1 contains the data */
411 temp_buffer[1] = value;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100412 return twl_i2c_write(mod_no, temp_buffer, reg, 1);
David Brownella603a7f2008-10-15 12:15:39 +0200413}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100414EXPORT_SYMBOL(twl_i2c_write_u8);
David Brownella603a7f2008-10-15 12:15:39 +0200415
416/**
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100417 * twl_i2c_read_u8 - Reads a 8 bit register from TWL4030/TWL5030/TWL60X0
David Brownella603a7f2008-10-15 12:15:39 +0200418 * @mod_no: module number
419 * @value: the value read 8 bit
420 * @reg: register address (just offset will do)
421 *
422 * Returns result of operation - 0 is success
423 */
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100424int twl_i2c_read_u8(u8 mod_no, u8 *value, u8 reg)
David Brownella603a7f2008-10-15 12:15:39 +0200425{
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100426 return twl_i2c_read(mod_no, value, reg, 1);
David Brownella603a7f2008-10-15 12:15:39 +0200427}
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100428EXPORT_SYMBOL(twl_i2c_read_u8);
David Brownella603a7f2008-10-15 12:15:39 +0200429
430/*----------------------------------------------------------------------*/
431
Lesly A Mca972d12011-04-14 17:57:53 +0530432/**
433 * twl_read_idcode_register - API to read the IDCODE register.
434 *
435 * Unlocks the IDCODE register and read the 32 bit value.
436 */
437static int twl_read_idcode_register(void)
438{
439 int err;
440
441 err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK,
442 REG_UNLOCK_TEST_REG);
443 if (err) {
444 pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err);
445 goto fail;
446 }
447
448 err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_idcode),
449 REG_IDCODE_7_0, 4);
450 if (err) {
451 pr_err("TWL4030: unable to read IDCODE -%d\n", err);
452 goto fail;
453 }
454
455 err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG);
456 if (err)
457 pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err);
458fail:
459 return err;
460}
461
462/**
463 * twl_get_type - API to get TWL Si type.
464 *
465 * Api to get the TWL Si type from IDCODE value.
466 */
467int twl_get_type(void)
468{
469 return TWL_SIL_TYPE(twl_idcode);
470}
471EXPORT_SYMBOL_GPL(twl_get_type);
472
473/**
474 * twl_get_version - API to get TWL Si version.
475 *
476 * Api to get the TWL Si version from IDCODE value.
477 */
478int twl_get_version(void)
479{
480 return TWL_SIL_REV(twl_idcode);
481}
482EXPORT_SYMBOL_GPL(twl_get_version);
483
Peter Ujfalusi2275c542012-09-10 13:46:22 +0300484/**
485 * twl_get_hfclk_rate - API to get TWL external HFCLK clock rate.
486 *
487 * Api to get the TWL HFCLK rate based on BOOT_CFG register.
488 */
489int twl_get_hfclk_rate(void)
490{
491 u8 ctrl;
492 int rate;
493
494 twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &ctrl, R_CFG_BOOT);
495
496 switch (ctrl & 0x3) {
497 case HFCLK_FREQ_19p2_MHZ:
498 rate = 19200000;
499 break;
500 case HFCLK_FREQ_26_MHZ:
501 rate = 26000000;
502 break;
503 case HFCLK_FREQ_38p4_MHZ:
504 rate = 38400000;
505 break;
506 default:
507 pr_err("TWL4030: HFCLK is not configured\n");
508 rate = -EINVAL;
509 break;
510 }
511
512 return rate;
513}
514EXPORT_SYMBOL_GPL(twl_get_hfclk_rate);
515
David Brownelldad759f2008-12-01 00:43:58 +0100516static struct device *
517add_numbered_child(unsigned chip, const char *name, int num,
David Brownell5725d662008-12-01 00:31:04 +0100518 void *pdata, unsigned pdata_len,
519 bool can_wakeup, int irq0, int irq1)
520{
521 struct platform_device *pdev;
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100522 struct twl_client *twl = &twl_modules[chip];
David Brownell5725d662008-12-01 00:31:04 +0100523 int status;
524
David Brownelldad759f2008-12-01 00:43:58 +0100525 pdev = platform_device_alloc(name, num);
David Brownell5725d662008-12-01 00:31:04 +0100526 if (!pdev) {
527 dev_dbg(&twl->client->dev, "can't alloc dev\n");
528 status = -ENOMEM;
529 goto err;
530 }
531
David Brownell5725d662008-12-01 00:31:04 +0100532 pdev->dev.parent = &twl->client->dev;
533
534 if (pdata) {
535 status = platform_device_add_data(pdev, pdata, pdata_len);
536 if (status < 0) {
537 dev_dbg(&pdev->dev, "can't add platform_data\n");
538 goto err;
539 }
540 }
541
542 if (irq0) {
543 struct resource r[2] = {
544 { .start = irq0, .flags = IORESOURCE_IRQ, },
545 { .start = irq1, .flags = IORESOURCE_IRQ, },
546 };
547
548 status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1);
549 if (status < 0) {
550 dev_dbg(&pdev->dev, "can't add irqs\n");
551 goto err;
552 }
553 }
554
555 status = platform_device_add(pdev);
NeilBrown17ffba62012-07-07 08:51:03 +1000556 if (status == 0)
557 device_init_wakeup(&pdev->dev, can_wakeup);
David Brownell5725d662008-12-01 00:31:04 +0100558
559err:
560 if (status < 0) {
561 platform_device_put(pdev);
562 dev_err(&twl->client->dev, "can't add %s dev\n", name);
563 return ERR_PTR(status);
564 }
565 return &pdev->dev;
566}
567
David Brownelldad759f2008-12-01 00:43:58 +0100568static inline struct device *add_child(unsigned chip, const char *name,
569 void *pdata, unsigned pdata_len,
570 bool can_wakeup, int irq0, int irq1)
571{
572 return add_numbered_child(chip, name, -1, pdata, pdata_len,
573 can_wakeup, irq0, irq1);
574}
575
576static struct device *
577add_regulator_linked(int num, struct regulator_init_data *pdata,
578 struct regulator_consumer_supply *consumers,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100579 unsigned num_consumers, unsigned long features)
David Brownelldad759f2008-12-01 00:43:58 +0100580{
Balaji T Ke8deb282009-12-14 00:25:31 +0100581 unsigned sub_chip_id;
Tero Kristo63bfff42012-02-16 12:27:52 +0200582 struct twl_regulator_driver_data drv_data;
583
David Brownelldad759f2008-12-01 00:43:58 +0100584 /* regulator framework demands init_data ... */
585 if (!pdata)
586 return NULL;
587
David Brownellb73eac72008-12-07 19:10:58 +0100588 if (consumers) {
David Brownelldad759f2008-12-01 00:43:58 +0100589 pdata->consumer_supplies = consumers;
590 pdata->num_consumer_supplies = num_consumers;
591 }
592
Tero Kristo63bfff42012-02-16 12:27:52 +0200593 if (pdata->driver_data) {
594 /* If we have existing drv_data, just add the flags */
595 struct twl_regulator_driver_data *tmp;
596 tmp = pdata->driver_data;
597 tmp->features |= features;
598 } else {
599 /* add new driver data struct, used only during init */
600 drv_data.features = features;
601 drv_data.set_voltage = NULL;
602 drv_data.get_voltage = NULL;
603 drv_data.data = NULL;
604 pdata->driver_data = &drv_data;
605 }
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100606
David Brownelldad759f2008-12-01 00:43:58 +0100607 /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */
Balaji T Ke8deb282009-12-14 00:25:31 +0100608 sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid;
609 return add_numbered_child(sub_chip_id, "twl_reg", num,
David Brownelldad759f2008-12-01 00:43:58 +0100610 pdata, sizeof(*pdata), false, 0, 0);
611}
612
613static struct device *
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100614add_regulator(int num, struct regulator_init_data *pdata,
615 unsigned long features)
David Brownelldad759f2008-12-01 00:43:58 +0100616{
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100617 return add_regulator_linked(num, pdata, NULL, 0, features);
David Brownelldad759f2008-12-01 00:43:58 +0100618}
619
David Brownella603a7f2008-10-15 12:15:39 +0200620/*
David Brownella30d46c2008-10-20 23:46:28 +0200621 * NOTE: We know the first 8 IRQs after pdata->base_irq are
622 * for the PIH, and the next are for the PWR_INT SIH, since
623 * that's how twl_init_irq() sets things up.
David Brownella603a7f2008-10-15 12:15:39 +0200624 */
David Brownella603a7f2008-10-15 12:15:39 +0200625
David Brownelldad759f2008-12-01 00:43:58 +0100626static int
Felipe Balbi9e178622012-02-22 14:32:16 +0200627add_children(struct twl4030_platform_data *pdata, unsigned irq_base,
628 unsigned long features)
David Brownella603a7f2008-10-15 12:15:39 +0200629{
David Brownell5725d662008-12-01 00:31:04 +0100630 struct device *child;
Balaji T Ke8deb282009-12-14 00:25:31 +0100631 unsigned sub_chip_id;
David Brownella603a7f2008-10-15 12:15:39 +0200632
Thierry Redingf78959c2012-09-18 10:29:50 +0200633 if (IS_ENABLED(CONFIG_GPIO_TWL4030) && pdata->gpio) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100634 child = add_child(SUB_CHIP_ID1, "twl4030_gpio",
David Brownell5725d662008-12-01 00:31:04 +0100635 pdata->gpio, sizeof(*pdata->gpio),
Felipe Balbi9e178622012-02-22 14:32:16 +0200636 false, irq_base + GPIO_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100637 if (IS_ERR(child))
638 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200639 }
640
Thierry Redingf78959c2012-09-18 10:29:50 +0200641 if (IS_ENABLED(CONFIG_KEYBOARD_TWL4030) && pdata->keypad) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +0100642 child = add_child(SUB_CHIP_ID2, "twl4030_keypad",
David Brownell5725d662008-12-01 00:31:04 +0100643 pdata->keypad, sizeof(*pdata->keypad),
Felipe Balbi9e178622012-02-22 14:32:16 +0200644 true, irq_base + KEYPAD_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100645 if (IS_ERR(child))
646 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200647 }
648
Thierry Redingf78959c2012-09-18 10:29:50 +0200649 if (IS_ENABLED(CONFIG_TWL4030_MADC) && pdata->madc) {
David Brownell5725d662008-12-01 00:31:04 +0100650 child = add_child(2, "twl4030_madc",
651 pdata->madc, sizeof(*pdata->madc),
Felipe Balbi9e178622012-02-22 14:32:16 +0200652 true, irq_base + MADC_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100653 if (IS_ERR(child))
654 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200655 }
656
Thierry Redingf78959c2012-09-18 10:29:50 +0200657 if (IS_ENABLED(CONFIG_RTC_DRV_TWL4030)) {
David Brownella603a7f2008-10-15 12:15:39 +0200658 /*
David Brownell5725d662008-12-01 00:31:04 +0100659 * REVISIT platform_data here currently might expose the
David Brownella603a7f2008-10-15 12:15:39 +0200660 * "msecure" line ... but for now we just expect board
David Brownell5725d662008-12-01 00:31:04 +0100661 * setup to tell the chip "it's always ok to SET_TIME".
David Brownella603a7f2008-10-15 12:15:39 +0200662 * Eventually, Linux might become more aware of such
663 * HW security concerns, and "least privilege".
664 */
Balaji T Ke8deb282009-12-14 00:25:31 +0100665 sub_chip_id = twl_map[TWL_MODULE_RTC].sid;
666 child = add_child(sub_chip_id, "twl_rtc",
David Brownell5725d662008-12-01 00:31:04 +0100667 NULL, 0,
Felipe Balbi9e178622012-02-22 14:32:16 +0200668 true, irq_base + RTC_INTR_OFFSET, 0);
David Brownell5725d662008-12-01 00:31:04 +0100669 if (IS_ERR(child))
670 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200671 }
672
Thierry Redingf78959c2012-09-18 10:29:50 +0200673 if (IS_ENABLED(CONFIG_TWL4030_USB) && pdata->usb &&
674 twl_class_is_4030()) {
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300675
676 static struct regulator_consumer_supply usb1v5 = {
677 .supply = "usb1v5",
678 };
679 static struct regulator_consumer_supply usb1v8 = {
680 .supply = "usb1v8",
681 };
NeilBrownab378132012-05-09 07:40:40 +1000682 static struct regulator_consumer_supply usb3v1[] = {
683 { .supply = "usb3v1" },
684 { .supply = "bci3v1" },
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300685 };
686
687 /* First add the regulators so that they can be used by transceiver */
Thierry Redingf78959c2012-09-18 10:29:50 +0200688 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) {
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300689 /* this is a template that gets copied */
690 struct regulator_init_data usb_fixed = {
691 .constraints.valid_modes_mask =
692 REGULATOR_MODE_NORMAL
693 | REGULATOR_MODE_STANDBY,
694 .constraints.valid_ops_mask =
695 REGULATOR_CHANGE_MODE
696 | REGULATOR_CHANGE_STATUS,
697 };
698
699 child = add_regulator_linked(TWL4030_REG_VUSB1V5,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100700 &usb_fixed, &usb1v5, 1,
701 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300702 if (IS_ERR(child))
703 return PTR_ERR(child);
704
705 child = add_regulator_linked(TWL4030_REG_VUSB1V8,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100706 &usb_fixed, &usb1v8, 1,
707 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300708 if (IS_ERR(child))
709 return PTR_ERR(child);
710
711 child = add_regulator_linked(TWL4030_REG_VUSB3V1,
NeilBrownab378132012-05-09 07:40:40 +1000712 &usb_fixed, usb3v1, 2,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100713 features);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300714 if (IS_ERR(child))
715 return PTR_ERR(child);
716
717 }
718
David Brownell5725d662008-12-01 00:31:04 +0100719 child = add_child(0, "twl4030_usb",
720 pdata->usb, sizeof(*pdata->usb),
721 true,
722 /* irq0 = USB_PRES, irq1 = USB */
Felipe Balbi9e178622012-02-22 14:32:16 +0200723 irq_base + USB_PRES_INTR_OFFSET,
724 irq_base + USB_INTR_OFFSET);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300725
David Brownell5725d662008-12-01 00:31:04 +0100726 if (IS_ERR(child))
727 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100728
729 /* we need to connect regulators to this transceiver */
Thierry Redingf78959c2012-09-18 10:29:50 +0200730 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child) {
Mark Brown1b65fa82012-02-03 11:02:58 +0000731 usb1v5.dev_name = dev_name(child);
732 usb1v8.dev_name = dev_name(child);
NeilBrownab378132012-05-09 07:40:40 +1000733 usb3v1[0].dev_name = dev_name(child);
Roger Quadrosf8ebdff2009-09-30 18:26:37 +0300734 }
David Brownelldad759f2008-12-01 00:43:58 +0100735 }
Thierry Redingf78959c2012-09-18 10:29:50 +0200736 if (IS_ENABLED(CONFIG_TWL6030_USB) && pdata->usb &&
737 twl_class_is_6030()) {
Hema HKe70357e32010-12-10 18:09:52 +0530738
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100739 static struct regulator_consumer_supply usb3v3;
740 int regulator;
Hema HKe70357e32010-12-10 18:09:52 +0530741
Thierry Redingf78959c2012-09-18 10:29:50 +0200742 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030)) {
Hema HKe70357e32010-12-10 18:09:52 +0530743 /* this is a template that gets copied */
744 struct regulator_init_data usb_fixed = {
745 .constraints.valid_modes_mask =
746 REGULATOR_MODE_NORMAL
747 | REGULATOR_MODE_STANDBY,
748 .constraints.valid_ops_mask =
749 REGULATOR_CHANGE_MODE
750 | REGULATOR_CHANGE_STATUS,
751 };
752
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100753 if (features & TWL6025_SUBCLASS) {
754 usb3v3.supply = "ldousb";
755 regulator = TWL6025_REG_LDOUSB;
756 } else {
757 usb3v3.supply = "vusb";
758 regulator = TWL6030_REG_VUSB;
759 }
760 child = add_regulator_linked(regulator, &usb_fixed,
761 &usb3v3, 1,
762 features);
Hema HKe70357e32010-12-10 18:09:52 +0530763 if (IS_ERR(child))
764 return PTR_ERR(child);
765 }
766
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100767 pdata->usb->features = features;
768
Hema HKe70357e32010-12-10 18:09:52 +0530769 child = add_child(0, "twl6030_usb",
770 pdata->usb, sizeof(*pdata->usb),
771 true,
772 /* irq1 = VBUS_PRES, irq0 = USB ID */
Felipe Balbi9e178622012-02-22 14:32:16 +0200773 irq_base + USBOTG_INTR_OFFSET,
774 irq_base + USB_PRES_INTR_OFFSET);
Hema HKe70357e32010-12-10 18:09:52 +0530775
776 if (IS_ERR(child))
777 return PTR_ERR(child);
778 /* we need to connect regulators to this transceiver */
Thierry Redingf78959c2012-09-18 10:29:50 +0200779 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && child)
Mark Brown1b65fa82012-02-03 11:02:58 +0000780 usb3v3.dev_name = dev_name(child);
Thierry Redingf78959c2012-09-18 10:29:50 +0200781 } else if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) &&
782 twl_class_is_6030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100783 if (features & TWL6025_SUBCLASS)
784 child = add_regulator(TWL6025_REG_LDOUSB,
785 pdata->ldousb, features);
786 else
787 child = add_regulator(TWL6030_REG_VUSB,
788 pdata->vusb, features);
Hema HKe70357e32010-12-10 18:09:52 +0530789
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100790 if (IS_ERR(child))
791 return PTR_ERR(child);
Hema HKe70357e32010-12-10 18:09:52 +0530792 }
David Brownelldad759f2008-12-01 00:43:58 +0100793
Thierry Redingf78959c2012-09-18 10:29:50 +0200794 if (IS_ENABLED(CONFIG_TWL4030_WATCHDOG) && twl_class_is_4030()) {
Timo Kokkonen80e45b12009-03-27 16:42:17 +0200795 child = add_child(0, "twl4030_wdt", NULL, 0, false, 0, 0);
796 if (IS_ERR(child))
797 return PTR_ERR(child);
798 }
799
Thierry Redingf78959c2012-09-18 10:29:50 +0200800 if (IS_ENABLED(CONFIG_INPUT_TWL4030_PWRBUTTON) && twl_class_is_4030()) {
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200801 child = add_child(1, "twl4030_pwrbutton",
Felipe Balbi9e178622012-02-22 14:32:16 +0200802 NULL, 0, true, irq_base + 8 + 0, 0);
Felipe Balbi9c3664d2009-08-03 18:16:38 +0200803 if (IS_ERR(child))
804 return PTR_ERR(child);
805 }
806
Thierry Redingf78959c2012-09-18 10:29:50 +0200807 if (IS_ENABLED(CONFIG_MFD_TWL4030_AUDIO) && pdata->audio &&
808 twl_class_is_4030()) {
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600809 sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000810 child = add_child(sub_chip_id, "twl4030-audio",
Peter Ujfalusi4ae6df5e2011-05-31 15:21:13 +0300811 pdata->audio, sizeof(*pdata->audio),
Misael Lopez Cruzd62abe52010-02-23 18:10:19 -0600812 false, 0, 0);
813 if (IS_ERR(child))
814 return PTR_ERR(child);
815 }
816
Rajendra Nayak9da66532009-12-13 22:29:47 +0100817 /* twl4030 regulators */
Thierry Redingf78959c2012-09-18 10:29:50 +0200818 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_4030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100819 child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1,
820 features);
David Brownelldad759f2008-12-01 00:43:58 +0100821 if (IS_ERR(child))
822 return PTR_ERR(child);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100823
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100824 child = add_regulator(TWL4030_REG_VIO, pdata->vio,
825 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100826 if (IS_ERR(child))
827 return PTR_ERR(child);
828
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100829 child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1,
830 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100831 if (IS_ERR(child))
832 return PTR_ERR(child);
833
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100834 child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2,
835 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100836 if (IS_ERR(child))
837 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100838
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100839 child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1,
840 features);
David Brownelldad759f2008-12-01 00:43:58 +0100841 if (IS_ERR(child))
842 return PTR_ERR(child);
843
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100844 child = add_regulator(TWL4030_REG_VDAC, pdata->vdac,
845 features);
David Brownelldad759f2008-12-01 00:43:58 +0100846 if (IS_ERR(child))
847 return PTR_ERR(child);
848
849 child = add_regulator((features & TWL4030_VAUX2)
850 ? TWL4030_REG_VAUX2_4030
851 : TWL4030_REG_VAUX2,
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100852 pdata->vaux2, features);
David Brownelldad759f2008-12-01 00:43:58 +0100853 if (IS_ERR(child))
854 return PTR_ERR(child);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100855
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100856 child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1,
857 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100858 if (IS_ERR(child))
859 return PTR_ERR(child);
860
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100861 child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2,
862 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100863 if (IS_ERR(child))
864 return PTR_ERR(child);
865
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100866 child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig,
867 features);
Juha Keski-Saariab4abe052009-12-11 11:12:15 +0100868 if (IS_ERR(child))
869 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100870 }
871
David Brownelldad759f2008-12-01 00:43:58 +0100872 /* maybe add LDOs that are omitted on cost-reduced parts */
Thierry Redingf78959c2012-09-18 10:29:50 +0200873 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && !(features & TPS_SUBSET)
Rajendra Nayak9da66532009-12-13 22:29:47 +0100874 && twl_class_is_4030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100875 child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2,
876 features);
David Brownelldad759f2008-12-01 00:43:58 +0100877 if (IS_ERR(child))
878 return PTR_ERR(child);
David Brownelldad759f2008-12-01 00:43:58 +0100879
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100880 child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2,
881 features);
David Brownelldad759f2008-12-01 00:43:58 +0100882 if (IS_ERR(child))
883 return PTR_ERR(child);
884
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100885 child = add_regulator(TWL4030_REG_VSIM, pdata->vsim,
886 features);
David Brownelldad759f2008-12-01 00:43:58 +0100887 if (IS_ERR(child))
888 return PTR_ERR(child);
889
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100890 child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1,
891 features);
David Brownelldad759f2008-12-01 00:43:58 +0100892 if (IS_ERR(child))
893 return PTR_ERR(child);
894
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100895 child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3,
896 features);
David Brownelldad759f2008-12-01 00:43:58 +0100897 if (IS_ERR(child))
898 return PTR_ERR(child);
899
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100900 child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4,
901 features);
David Brownelldad759f2008-12-01 00:43:58 +0100902 if (IS_ERR(child))
903 return PTR_ERR(child);
David Brownella603a7f2008-10-15 12:15:39 +0200904 }
905
Rajendra Nayak9da66532009-12-13 22:29:47 +0100906 /* twl6030 regulators */
Thierry Redingf78959c2012-09-18 10:29:50 +0200907 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030() &&
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100908 !(features & TWL6025_SUBCLASS)) {
Tero Kristo34a38442012-02-28 15:09:10 +0530909 child = add_regulator(TWL6030_REG_VDD1, pdata->vdd1,
910 features);
911 if (IS_ERR(child))
912 return PTR_ERR(child);
913
914 child = add_regulator(TWL6030_REG_VDD2, pdata->vdd2,
915 features);
916 if (IS_ERR(child))
917 return PTR_ERR(child);
918
919 child = add_regulator(TWL6030_REG_VDD3, pdata->vdd3,
920 features);
921 if (IS_ERR(child))
922 return PTR_ERR(child);
923
Peter Ujfalusi46eda3e2012-02-28 15:09:13 +0530924 child = add_regulator(TWL6030_REG_V1V8, pdata->v1v8,
925 features);
926 if (IS_ERR(child))
927 return PTR_ERR(child);
928
929 child = add_regulator(TWL6030_REG_V2V1, pdata->v2v1,
930 features);
931 if (IS_ERR(child))
932 return PTR_ERR(child);
933
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100934 child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc,
935 features);
936 if (IS_ERR(child))
937 return PTR_ERR(child);
938
939 child = add_regulator(TWL6030_REG_VPP, pdata->vpp,
940 features);
941 if (IS_ERR(child))
942 return PTR_ERR(child);
943
944 child = add_regulator(TWL6030_REG_VUSIM, pdata->vusim,
945 features);
946 if (IS_ERR(child))
947 return PTR_ERR(child);
948
949 child = add_regulator(TWL6030_REG_VCXIO, pdata->vcxio,
950 features);
951 if (IS_ERR(child))
952 return PTR_ERR(child);
953
954 child = add_regulator(TWL6030_REG_VDAC, pdata->vdac,
955 features);
956 if (IS_ERR(child))
957 return PTR_ERR(child);
958
959 child = add_regulator(TWL6030_REG_VAUX1_6030, pdata->vaux1,
960 features);
961 if (IS_ERR(child))
962 return PTR_ERR(child);
963
964 child = add_regulator(TWL6030_REG_VAUX2_6030, pdata->vaux2,
965 features);
966 if (IS_ERR(child))
967 return PTR_ERR(child);
968
969 child = add_regulator(TWL6030_REG_VAUX3_6030, pdata->vaux3,
970 features);
971 if (IS_ERR(child))
972 return PTR_ERR(child);
973
974 child = add_regulator(TWL6030_REG_CLK32KG, pdata->clk32kg,
975 features);
976 if (IS_ERR(child))
977 return PTR_ERR(child);
978 }
979
980 /* 6030 and 6025 share this regulator */
Thierry Redingf78959c2012-09-18 10:29:50 +0200981 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030()) {
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100982 child = add_regulator(TWL6030_REG_VANA, pdata->vana,
983 features);
984 if (IS_ERR(child))
985 return PTR_ERR(child);
986 }
987
988 /* twl6025 regulators */
Thierry Redingf78959c2012-09-18 10:29:50 +0200989 if (IS_ENABLED(CONFIG_REGULATOR_TWL4030) && twl_class_is_6030() &&
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100990 (features & TWL6025_SUBCLASS)) {
991 child = add_regulator(TWL6025_REG_LDO5, pdata->ldo5,
992 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +0100993 if (IS_ERR(child))
994 return PTR_ERR(child);
995
Graeme Gregory521d8ec2011-05-12 14:27:55 +0100996 child = add_regulator(TWL6025_REG_LDO1, pdata->ldo1,
997 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +0100998 if (IS_ERR(child))
999 return PTR_ERR(child);
1000
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001001 child = add_regulator(TWL6025_REG_LDO7, pdata->ldo7,
1002 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001003 if (IS_ERR(child))
1004 return PTR_ERR(child);
1005
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001006 child = add_regulator(TWL6025_REG_LDO6, pdata->ldo6,
1007 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001008 if (IS_ERR(child))
1009 return PTR_ERR(child);
1010
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001011 child = add_regulator(TWL6025_REG_LDOLN, pdata->ldoln,
1012 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001013 if (IS_ERR(child))
1014 return PTR_ERR(child);
1015
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001016 child = add_regulator(TWL6025_REG_LDO2, pdata->ldo2,
1017 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001018 if (IS_ERR(child))
1019 return PTR_ERR(child);
1020
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001021 child = add_regulator(TWL6025_REG_LDO4, pdata->ldo4,
1022 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001023 if (IS_ERR(child))
1024 return PTR_ERR(child);
1025
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001026 child = add_regulator(TWL6025_REG_LDO3, pdata->ldo3,
1027 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001028 if (IS_ERR(child))
1029 return PTR_ERR(child);
1030
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001031 child = add_regulator(TWL6025_REG_SMPS3, pdata->smps3,
1032 features);
Rajendra Nayak9da66532009-12-13 22:29:47 +01001033 if (IS_ERR(child))
1034 return PTR_ERR(child);
Balaji T K8e6de4a2011-02-10 18:44:50 +05301035
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001036 child = add_regulator(TWL6025_REG_SMPS4, pdata->smps4,
1037 features);
Balaji T K8e6de4a2011-02-10 18:44:50 +05301038 if (IS_ERR(child))
1039 return PTR_ERR(child);
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001040
1041 child = add_regulator(TWL6025_REG_VIO, pdata->vio6025,
1042 features);
1043 if (IS_ERR(child))
1044 return PTR_ERR(child);
1045
Rajendra Nayak9da66532009-12-13 22:29:47 +01001046 }
1047
Thierry Redingf78959c2012-09-18 10:29:50 +02001048 if (IS_ENABLED(CONFIG_CHARGER_TWL4030) && pdata->bci &&
Grazvydas Ignotas11c39c42010-10-01 13:17:50 +03001049 !(features & (TPS_SUBSET | TWL5031))) {
1050 child = add_child(3, "twl4030_bci",
1051 pdata->bci, sizeof(*pdata->bci), false,
1052 /* irq0 = CHG_PRES, irq1 = BCI */
Felipe Balbi9e178622012-02-22 14:32:16 +02001053 irq_base + BCI_PRES_INTR_OFFSET,
1054 irq_base + BCI_INTR_OFFSET);
Grazvydas Ignotas11c39c42010-10-01 13:17:50 +03001055 if (IS_ERR(child))
1056 return PTR_ERR(child);
1057 }
1058
David Brownell5725d662008-12-01 00:31:04 +01001059 return 0;
David Brownella603a7f2008-10-15 12:15:39 +02001060}
1061
1062/*----------------------------------------------------------------------*/
1063
1064/*
1065 * These three functions initialize the on-chip clock framework,
1066 * letting it generate the right frequencies for USB, MADC, and
1067 * other purposes.
1068 */
1069static inline int __init protect_pm_master(void)
1070{
1071 int e = 0;
1072
Felipe Balbi49e6f872010-08-18 09:19:35 +03001073 e = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0,
1074 TWL4030_PM_MASTER_PROTECT_KEY);
David Brownella603a7f2008-10-15 12:15:39 +02001075 return e;
1076}
1077
1078static inline int __init unprotect_pm_master(void)
1079{
1080 int e = 0;
1081
Felipe Balbi49e6f872010-08-18 09:19:35 +03001082 e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
1083 TWL4030_PM_MASTER_KEY_CFG1,
1084 TWL4030_PM_MASTER_PROTECT_KEY);
1085 e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER,
1086 TWL4030_PM_MASTER_KEY_CFG2,
1087 TWL4030_PM_MASTER_PROTECT_KEY);
1088
David Brownella603a7f2008-10-15 12:15:39 +02001089 return e;
1090}
1091
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001092static void clocks_init(struct device *dev,
1093 struct twl4030_clock_init_data *clock)
David Brownella603a7f2008-10-15 12:15:39 +02001094{
1095 int e = 0;
1096 struct clk *osc;
1097 u32 rate;
1098 u8 ctrl = HFCLK_FREQ_26_MHZ;
1099
1100#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
1101 if (cpu_is_omap2430())
Russell Kinge6b50c82009-01-10 10:40:42 +00001102 osc = clk_get(dev, "osc_ck");
David Brownella603a7f2008-10-15 12:15:39 +02001103 else
Russell Kinge6b50c82009-01-10 10:40:42 +00001104 osc = clk_get(dev, "osc_sys_ck");
Samuel Ortiz6354ab5c2008-12-07 20:50:25 +01001105
David Brownella603a7f2008-10-15 12:15:39 +02001106 if (IS_ERR(osc)) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001107 printk(KERN_WARNING "Skipping twl internal clock init and "
David Brownella603a7f2008-10-15 12:15:39 +02001108 "using bootloader value (unknown osc rate)\n");
1109 return;
1110 }
1111
1112 rate = clk_get_rate(osc);
1113 clk_put(osc);
1114
Samuel Ortiz6354ab5c2008-12-07 20:50:25 +01001115#else
1116 /* REVISIT for non-OMAP systems, pass the clock rate from
1117 * board init code, using platform_data.
1118 */
1119 osc = ERR_PTR(-EIO);
1120
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001121 printk(KERN_WARNING "Skipping twl internal clock init and "
Samuel Ortiz6354ab5c2008-12-07 20:50:25 +01001122 "using bootloader value (unknown osc rate)\n");
1123
1124 return;
1125#endif
1126
David Brownella603a7f2008-10-15 12:15:39 +02001127 switch (rate) {
1128 case 19200000:
1129 ctrl = HFCLK_FREQ_19p2_MHZ;
1130 break;
1131 case 26000000:
1132 ctrl = HFCLK_FREQ_26_MHZ;
1133 break;
1134 case 38400000:
1135 ctrl = HFCLK_FREQ_38p4_MHZ;
1136 break;
1137 }
1138
1139 ctrl |= HIGH_PERF_SQ;
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001140 if (clock && clock->ck32k_lowpwr_enable)
1141 ctrl |= CK32K_LOWPWR_EN;
1142
David Brownella603a7f2008-10-15 12:15:39 +02001143 e |= unprotect_pm_master();
1144 /* effect->MADC+USB ck en */
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001145 e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT);
David Brownella603a7f2008-10-15 12:15:39 +02001146 e |= protect_pm_master();
1147
1148 if (e < 0)
1149 pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e);
1150}
1151
1152/*----------------------------------------------------------------------*/
1153
David Brownella603a7f2008-10-15 12:15:39 +02001154
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001155static int twl_remove(struct i2c_client *client)
David Brownella603a7f2008-10-15 12:15:39 +02001156{
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001157 unsigned i, num_slaves;
David Brownella30d46c2008-10-20 23:46:28 +02001158 int status;
David Brownella603a7f2008-10-15 12:15:39 +02001159
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001160 if (twl_class_is_4030()) {
Balaji T Ke8deb282009-12-14 00:25:31 +01001161 status = twl4030_exit_irq();
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001162 num_slaves = TWL_NUM_SLAVES;
1163 } else {
Balaji T Ke8deb282009-12-14 00:25:31 +01001164 status = twl6030_exit_irq();
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001165 num_slaves = TWL_NUM_SLAVES - 1;
1166 }
Balaji T Ke8deb282009-12-14 00:25:31 +01001167
David Brownella30d46c2008-10-20 23:46:28 +02001168 if (status < 0)
1169 return status;
David Brownella603a7f2008-10-15 12:15:39 +02001170
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001171 for (i = 0; i < num_slaves; i++) {
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001172 struct twl_client *twl = &twl_modules[i];
David Brownella603a7f2008-10-15 12:15:39 +02001173
1174 if (twl->client && twl->client != client)
1175 i2c_unregister_device(twl->client);
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001176 twl_modules[i].client = NULL;
David Brownella603a7f2008-10-15 12:15:39 +02001177 }
1178 inuse = false;
1179 return 0;
1180}
1181
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001182/* NOTE: This driver only handles a single twl4030/tps659x0 chip */
Bryan Wu5b9cecd2010-12-08 10:42:04 +08001183static int __devinit
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001184twl_probe(struct i2c_client *client, const struct i2c_device_id *id)
David Brownella603a7f2008-10-15 12:15:39 +02001185{
David Brownella603a7f2008-10-15 12:15:39 +02001186 struct twl4030_platform_data *pdata = client->dev.platform_data;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001187 struct device_node *node = client->dev.of_node;
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001188 int irq_base = 0;
1189 int status;
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001190 unsigned i, num_slaves;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001191
1192 if (node && !pdata) {
1193 /*
1194 * XXX: Temporary pdata until the information is correctly
1195 * retrieved by every TWL modules from DT.
1196 */
1197 pdata = devm_kzalloc(&client->dev,
1198 sizeof(struct twl4030_platform_data),
1199 GFP_KERNEL);
1200 if (!pdata)
1201 return -ENOMEM;
1202 }
David Brownella603a7f2008-10-15 12:15:39 +02001203
1204 if (!pdata) {
1205 dev_dbg(&client->dev, "no platform data?\n");
1206 return -EINVAL;
1207 }
1208
1209 if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) {
1210 dev_dbg(&client->dev, "can't talk I2C?\n");
1211 return -EIO;
1212 }
1213
David Brownella30d46c2008-10-20 23:46:28 +02001214 if (inuse) {
David Brownella603a7f2008-10-15 12:15:39 +02001215 dev_dbg(&client->dev, "driver is already in use\n");
1216 return -EBUSY;
1217 }
1218
Peter Ujfalusi364cedb2012-01-04 14:58:33 +02001219 if ((id->driver_data) & TWL6030_CLASS) {
1220 twl_id = TWL6030_CLASS_ID;
1221 twl_map = &twl6030_map[0];
1222 num_slaves = TWL_NUM_SLAVES - 1;
1223 } else {
1224 twl_id = TWL4030_CLASS_ID;
1225 twl_map = &twl4030_map[0];
1226 num_slaves = TWL_NUM_SLAVES;
1227 }
1228
1229 for (i = 0; i < num_slaves; i++) {
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001230 struct twl_client *twl = &twl_modules[i];
David Brownella603a7f2008-10-15 12:15:39 +02001231
1232 twl->address = client->addr + i;
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001233 if (i == 0) {
David Brownella603a7f2008-10-15 12:15:39 +02001234 twl->client = client;
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001235 } else {
David Brownella603a7f2008-10-15 12:15:39 +02001236 twl->client = i2c_new_dummy(client->adapter,
1237 twl->address);
1238 if (!twl->client) {
Ilkka Koskinena8643432009-10-20 16:22:52 +03001239 dev_err(&client->dev,
David Brownella603a7f2008-10-15 12:15:39 +02001240 "can't attach client %d\n", i);
1241 status = -ENOMEM;
1242 goto fail;
1243 }
David Brownella603a7f2008-10-15 12:15:39 +02001244 }
1245 mutex_init(&twl->xfer_lock);
1246 }
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001247
David Brownella603a7f2008-10-15 12:15:39 +02001248 inuse = true;
1249
1250 /* setup clock framework */
Ilkka Koskinen38a68492009-10-22 14:14:09 +03001251 clocks_init(&client->dev, pdata->clock);
David Brownella603a7f2008-10-15 12:15:39 +02001252
Lesly A Mca972d12011-04-14 17:57:53 +05301253 /* read TWL IDCODE Register */
1254 if (twl_id == TWL4030_CLASS_ID) {
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001255 status = twl_read_idcode_register();
1256 WARN(status < 0, "Error: reading twl_idcode register value\n");
Lesly A Mca972d12011-04-14 17:57:53 +05301257 }
1258
Amit Kucheriaebf0bd32009-08-31 18:32:18 +02001259 /* load power event scripts */
Thierry Redingf78959c2012-09-18 10:29:50 +02001260 if (IS_ENABLED(CONFIG_TWL4030_POWER) && pdata->power)
Amit Kucheriaebf0bd32009-08-31 18:32:18 +02001261 twl4030_power_init(pdata->power);
1262
David Brownella603a7f2008-10-15 12:15:39 +02001263 /* Maybe init the T2 Interrupt subsystem */
Felipe Balbi9e178622012-02-22 14:32:16 +02001264 if (client->irq) {
Balaji T Ke8deb282009-12-14 00:25:31 +01001265 if (twl_class_is_4030()) {
1266 twl4030_init_chip_irq(id->name);
Benoit Cousson78518ff2012-02-29 19:40:31 +01001267 irq_base = twl4030_init_irq(&client->dev, client->irq);
Balaji T Ke8deb282009-12-14 00:25:31 +01001268 } else {
Benoit Cousson78518ff2012-02-29 19:40:31 +01001269 irq_base = twl6030_init_irq(&client->dev, client->irq);
Balaji T Ke8deb282009-12-14 00:25:31 +01001270 }
1271
Benoit Cousson78518ff2012-02-29 19:40:31 +01001272 if (irq_base < 0) {
1273 status = irq_base;
David Brownella30d46c2008-10-20 23:46:28 +02001274 goto fail;
Benoit Cousson78518ff2012-02-29 19:40:31 +01001275 }
David Brownella603a7f2008-10-15 12:15:39 +02001276 }
1277
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001278 /*
1279 * Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface.
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001280 * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0,
1281 * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0.
1282 */
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001283 if (twl_class_is_4030()) {
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001284 u8 temp;
1285
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001286 twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1);
1287 temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001288 I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU);
Moiz Sonasatha29aaf52010-02-16 18:57:21 -06001289 twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1);
1290 }
1291
Grant Likely964dba22012-02-24 14:58:34 -07001292 status = -ENODEV;
Benoit Coussonaeb50322011-08-29 16:20:23 +02001293 if (node)
1294 status = of_platform_populate(node, NULL, NULL, &client->dev);
Grant Likely964dba22012-02-24 14:58:34 -07001295 if (status)
Felipe Balbi9e178622012-02-22 14:32:16 +02001296 status = add_children(pdata, irq_base, id->driver_data);
Benoit Coussonaeb50322011-08-29 16:20:23 +02001297
David Brownella603a7f2008-10-15 12:15:39 +02001298fail:
1299 if (status < 0)
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001300 twl_remove(client);
Benoit Coussonec1a07b2012-03-02 11:11:26 +01001301
David Brownella603a7f2008-10-15 12:15:39 +02001302 return status;
1303}
1304
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001305static const struct i2c_device_id twl_ids[] = {
David Brownelldad759f2008-12-01 00:43:58 +01001306 { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */
1307 { "twl5030", 0 }, /* T2 updated */
Ilkka Koskinen1920a612009-11-10 17:26:15 +02001308 { "twl5031", TWL5031 }, /* TWL5030 updated */
David Brownelldad759f2008-12-01 00:43:58 +01001309 { "tps65950", 0 }, /* catalog version of twl5030 */
1310 { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */
1311 { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */
Oleg Drokin59dead52011-07-01 13:34:13 +02001312 { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED
1313 and vibrator. Charger in USB module*/
Balaji T Ke8deb282009-12-14 00:25:31 +01001314 { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */
Graeme Gregory521d8ec2011-05-12 14:27:55 +01001315 { "twl6025", TWL6030_CLASS | TWL6025_SUBCLASS }, /* "Phoenix lite" */
David Brownella603a7f2008-10-15 12:15:39 +02001316 { /* end of list */ },
1317};
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001318MODULE_DEVICE_TABLE(i2c, twl_ids);
David Brownella603a7f2008-10-15 12:15:39 +02001319
1320/* One Client Driver , 4 Clients */
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001321static struct i2c_driver twl_driver = {
David Brownella603a7f2008-10-15 12:15:39 +02001322 .driver.name = DRIVER_NAME,
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001323 .id_table = twl_ids,
1324 .probe = twl_probe,
1325 .remove = twl_remove,
David Brownella603a7f2008-10-15 12:15:39 +02001326};
1327
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001328static int __init twl_init(void)
David Brownella603a7f2008-10-15 12:15:39 +02001329{
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001330 return i2c_add_driver(&twl_driver);
David Brownella603a7f2008-10-15 12:15:39 +02001331}
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001332subsys_initcall(twl_init);
David Brownella603a7f2008-10-15 12:15:39 +02001333
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001334static void __exit twl_exit(void)
David Brownella603a7f2008-10-15 12:15:39 +02001335{
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001336 i2c_del_driver(&twl_driver);
David Brownella603a7f2008-10-15 12:15:39 +02001337}
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001338module_exit(twl_exit);
David Brownella603a7f2008-10-15 12:15:39 +02001339
1340MODULE_AUTHOR("Texas Instruments, Inc.");
Balaji T Kfc7b92f2009-12-13 21:23:33 +01001341MODULE_DESCRIPTION("I2C Core interface for TWL");
David Brownella603a7f2008-10-15 12:15:39 +02001342MODULE_LICENSE("GPL");