David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1 | /* |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 2 | * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM |
| 3 | * and audio CODEC devices |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2005-2006 Texas Instruments, Inc. |
| 6 | * |
| 7 | * Modifications to defer interrupt handling to a kernel thread: |
| 8 | * Copyright (C) 2006 MontaVista Software, Inc. |
| 9 | * |
| 10 | * Based on tlv320aic23.c: |
| 11 | * Copyright (c) by Kai Svahn <kai.svahn@nokia.com> |
| 12 | * |
| 13 | * Code cleanup and modifications to IRQ handler. |
| 14 | * by syed khasim <x0khasim@ti.com> |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | */ |
| 30 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 31 | #include <linux/init.h> |
| 32 | #include <linux/mutex.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame] | 33 | #include <linux/module.h> |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/clk.h> |
David Brownell | a30d46c | 2008-10-20 23:46:28 +0200 | [diff] [blame] | 36 | #include <linux/err.h> |
Benoit Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 37 | #include <linux/device.h> |
| 38 | #include <linux/of.h> |
| 39 | #include <linux/of_irq.h> |
| 40 | #include <linux/of_platform.h> |
| 41 | #include <linux/irqdomain.h> |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 42 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 43 | #include <linux/regulator/machine.h> |
| 44 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 45 | #include <linux/i2c.h> |
Santosh Shilimkar | b07682b | 2009-12-13 20:05:51 +0100 | [diff] [blame] | 46 | #include <linux/i2c/twl.h> |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 47 | |
Mark Brown | a313d75 | 2009-02-04 21:26:07 +0100 | [diff] [blame] | 48 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 49 | #include <plat/cpu.h> |
Samuel Ortiz | b29c06a | 2009-01-11 01:21:48 +0100 | [diff] [blame] | 50 | #endif |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * The TWL4030 "Triton 2" is one of a family of a multi-function "Power |
| 54 | * Management and System Companion Device" chips originally designed for |
| 55 | * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C, |
| 56 | * often at around 3 Mbit/sec, including for interrupt handling. |
| 57 | * |
| 58 | * This driver core provides genirq support for the interrupts emitted, |
| 59 | * by the various modules, and exports register access primitives. |
| 60 | * |
| 61 | * FIXME this driver currently requires use of the first interrupt line |
| 62 | * (and associated registers). |
| 63 | */ |
| 64 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 65 | #define DRIVER_NAME "twl" |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 66 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 67 | #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 Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 79 | #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 Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 86 | #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 Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_TWL4030_POWER |
| 93 | #define twl_has_power() true |
| 94 | #else |
| 95 | #define twl_has_power() false |
| 96 | #endif |
| 97 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 98 | #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 HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 104 | #if defined(CONFIG_TWL4030_USB) || defined(CONFIG_TWL4030_USB_MODULE) ||\ |
| 105 | defined(CONFIG_TWL6030_USB) || defined(CONFIG_TWL6030_USB_MODULE) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 106 | #define twl_has_usb() true |
| 107 | #else |
| 108 | #define twl_has_usb() false |
| 109 | #endif |
| 110 | |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 111 | #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 Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 117 | |
Thomas Weber | f09ee04 | 2011-09-05 11:26:33 +0200 | [diff] [blame] | 118 | #if defined(CONFIG_MFD_TWL4030_AUDIO) || defined(CONFIG_MFD_TWL4030_AUDIO_MODULE) ||\ |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 119 | defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE) |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 120 | #define twl_has_codec() true |
| 121 | #else |
| 122 | #define twl_has_codec() false |
| 123 | #endif |
| 124 | |
Grazvydas Ignotas | 11c39c4 | 2010-10-01 13:17:50 +0300 | [diff] [blame] | 125 | #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 Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 131 | /* Triton Core internal information (BEGIN) */ |
| 132 | |
| 133 | /* Last - for index max*/ |
| 134 | #define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG |
| 135 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 136 | #define TWL_NUM_SLAVES 4 |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 137 | |
Felipe Balbi | 9c3664d | 2009-08-03 18:16:38 +0200 | [diff] [blame] | 138 | #if defined(CONFIG_INPUT_TWL4030_PWRBUTTON) \ |
Eduardo Valentin | 14e5c82 | 2010-02-11 13:47:09 +0100 | [diff] [blame] | 139 | || defined(CONFIG_INPUT_TWL4030_PWRBUTTON_MODULE) |
Felipe Balbi | 9c3664d | 2009-08-03 18:16:38 +0200 | [diff] [blame] | 140 | #define twl_has_pwrbutton() true |
| 141 | #else |
| 142 | #define twl_has_pwrbutton() false |
| 143 | #endif |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 144 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 145 | #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 Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 152 | #define TWL4030_NR_IRQS 8 |
| 153 | #define TWL6030_NR_IRQS 20 |
| 154 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 155 | /* 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 Koskinen | 1920a61 | 2009-11-10 17:26:15 +0200 | [diff] [blame] | 179 | #define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */ |
| 180 | #define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's |
| 181 | one */ |
| 182 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 183 | /* 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 K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 194 | /* 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 Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 210 | #define TWL6025_BASEADD_CHARGER 0x00DA |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 211 | |
| 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 K | fa0d976 | 2010-02-19 12:39:38 +0100 | [diff] [blame] | 218 | #define TWL6030_BASEADD_ZERO 0x0000 |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 219 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 220 | /* Few power values */ |
| 221 | #define R_CFG_BOOT 0x05 |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 222 | |
| 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 Koskinen | 38a6849 | 2009-10-22 14:14:09 +0300 | [diff] [blame] | 228 | #define CK32K_LOWPWR_EN (1 << 7) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 229 | |
| 230 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 231 | /* 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 Koskinen | 1920a61 | 2009-11-10 17:26:15 +0200 | [diff] [blame] | 234 | #define TWL5031 BIT(2) /* twl5031 has different registers */ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 235 | #define TWL6030_CLASS BIT(3) /* TWL6030 class */ |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 236 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 237 | /*----------------------------------------------------------------------*/ |
| 238 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 239 | /* is driver active, bound to a chip? */ |
| 240 | static bool inuse; |
| 241 | |
Lesly A M | ca972d1 | 2011-04-14 17:57:53 +0530 | [diff] [blame] | 242 | /* TWL IDCODE Register value */ |
| 243 | static u32 twl_idcode; |
| 244 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 245 | static unsigned int twl_id; |
| 246 | unsigned int twl_rev(void) |
| 247 | { |
| 248 | return twl_id; |
| 249 | } |
| 250 | EXPORT_SYMBOL(twl_rev); |
| 251 | |
| 252 | /* Structure for each TWL4030/TWL6030 Slave */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 253 | struct twl_client { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 254 | 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 K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 264 | static struct twl_client twl_modules[TWL_NUM_SLAVES]; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 265 | |
Benoit Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 266 | static struct irq_domain domain; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 267 | |
| 268 | /* mapping the module id to slave id and base address */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 269 | struct twl_mapping { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 270 | unsigned char sid; /* Slave ID */ |
| 271 | unsigned char base; /* base address */ |
| 272 | }; |
G, Manjunath Kondaiah | 2cfcce1 | 2010-09-21 15:31:17 +0530 | [diff] [blame] | 273 | static struct twl_mapping *twl_map; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 274 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 275 | static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 276 | /* |
| 277 | * NOTE: don't change this table without updating the |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 278 | * <linux/i2c/twl.h> defines for TWL4030_MODULE_* |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 279 | * 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 Koskinen | 1920a61 | 2009-11-10 17:26:15 +0200 | [diff] [blame] | 300 | { 2, TWL5031_BASEADD_ACCESSORY }, |
| 301 | { 2, TWL5031_BASEADD_INTERRUPTS }, |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 302 | |
| 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 K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 311 | static 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 K | fa0d976 | 2010-02-19 12:39:38 +0100 | [diff] [blame] | 332 | { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO }, |
| 333 | { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO }, |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 334 | |
Balaji T K | fa0d976 | 2010-02-19 12:39:38 +0100 | [diff] [blame] | 335 | { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, |
| 336 | { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 337 | { 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 Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 345 | { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER }, |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 346 | }; |
| 347 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 348 | /*----------------------------------------------------------------------*/ |
| 349 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 350 | /* Exported Functions */ |
| 351 | |
| 352 | /** |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 353 | * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0 |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 354 | * @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 K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 364 | int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 365 | { |
| 366 | int ret; |
| 367 | int sid; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 368 | struct twl_client *twl; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 369 | struct i2c_msg *msg; |
| 370 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 371 | if (unlikely(mod_no > TWL_MODULE_LAST)) { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 372 | pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); |
| 373 | return -EPERM; |
| 374 | } |
Ilya Yanok | 8653be1 | 2011-08-01 23:00:28 +0200 | [diff] [blame] | 375 | if (unlikely(!inuse)) { |
| 376 | pr_err("%s: not initialized\n", DRIVER_NAME); |
| 377 | return -EPERM; |
| 378 | } |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 379 | sid = twl_map[mod_no].sid; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 380 | twl = &twl_modules[sid]; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 381 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 382 | 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 K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 393 | *value = twl_map[mod_no].base + reg; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 394 | ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1); |
| 395 | mutex_unlock(&twl->xfer_lock); |
| 396 | |
Amit Kucheria | 147e084 | 2009-12-11 13:21:45 +0100 | [diff] [blame] | 397 | /* 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 Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 408 | } |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 409 | EXPORT_SYMBOL(twl_i2c_write); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 410 | |
| 411 | /** |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 412 | * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0 |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 413 | * @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 K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 420 | int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 421 | { |
| 422 | int ret; |
| 423 | u8 val; |
| 424 | int sid; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 425 | struct twl_client *twl; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 426 | struct i2c_msg *msg; |
| 427 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 428 | if (unlikely(mod_no > TWL_MODULE_LAST)) { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 429 | pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); |
| 430 | return -EPERM; |
| 431 | } |
Ilya Yanok | 8653be1 | 2011-08-01 23:00:28 +0200 | [diff] [blame] | 432 | if (unlikely(!inuse)) { |
| 433 | pr_err("%s: not initialized\n", DRIVER_NAME); |
| 434 | return -EPERM; |
| 435 | } |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 436 | sid = twl_map[mod_no].sid; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 437 | twl = &twl_modules[sid]; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 438 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 439 | mutex_lock(&twl->xfer_lock); |
| 440 | /* [MSG1] fill the register address data */ |
| 441 | msg = &twl->xfer_msg[0]; |
| 442 | msg->addr = twl->address; |
| 443 | msg->len = 1; |
| 444 | msg->flags = 0; /* Read the register value */ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 445 | val = twl_map[mod_no].base + reg; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 446 | msg->buf = &val; |
| 447 | /* [MSG2] fill the data rx buffer */ |
| 448 | msg = &twl->xfer_msg[1]; |
| 449 | msg->addr = twl->address; |
| 450 | msg->flags = I2C_M_RD; /* Read the register value */ |
| 451 | msg->len = num_bytes; /* only n bytes */ |
| 452 | msg->buf = value; |
| 453 | ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2); |
| 454 | mutex_unlock(&twl->xfer_lock); |
| 455 | |
Amit Kucheria | 147e084 | 2009-12-11 13:21:45 +0100 | [diff] [blame] | 456 | /* i2c_transfer returns number of messages transferred */ |
| 457 | if (ret != 2) { |
| 458 | pr_err("%s: i2c_read failed to transfer all messages\n", |
| 459 | DRIVER_NAME); |
| 460 | if (ret < 0) |
| 461 | return ret; |
| 462 | else |
| 463 | return -EIO; |
| 464 | } else { |
| 465 | return 0; |
| 466 | } |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 467 | } |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 468 | EXPORT_SYMBOL(twl_i2c_read); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 469 | |
| 470 | /** |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 471 | * twl_i2c_write_u8 - Writes a 8 bit register in TWL4030/TWL5030/TWL60X0 |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 472 | * @mod_no: module number |
| 473 | * @value: the value to be written 8 bit |
| 474 | * @reg: register address (just offset will do) |
| 475 | * |
| 476 | * Returns result of operation - 0 is success |
| 477 | */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 478 | int twl_i2c_write_u8(u8 mod_no, u8 value, u8 reg) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 479 | { |
| 480 | |
| 481 | /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */ |
| 482 | u8 temp_buffer[2] = { 0 }; |
| 483 | /* offset 1 contains the data */ |
| 484 | temp_buffer[1] = value; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 485 | return twl_i2c_write(mod_no, temp_buffer, reg, 1); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 486 | } |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 487 | EXPORT_SYMBOL(twl_i2c_write_u8); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 488 | |
| 489 | /** |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 490 | * twl_i2c_read_u8 - Reads a 8 bit register from TWL4030/TWL5030/TWL60X0 |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 491 | * @mod_no: module number |
| 492 | * @value: the value read 8 bit |
| 493 | * @reg: register address (just offset will do) |
| 494 | * |
| 495 | * Returns result of operation - 0 is success |
| 496 | */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 497 | int twl_i2c_read_u8(u8 mod_no, u8 *value, u8 reg) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 498 | { |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 499 | return twl_i2c_read(mod_no, value, reg, 1); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 500 | } |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 501 | EXPORT_SYMBOL(twl_i2c_read_u8); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 502 | |
| 503 | /*----------------------------------------------------------------------*/ |
| 504 | |
Lesly A M | ca972d1 | 2011-04-14 17:57:53 +0530 | [diff] [blame] | 505 | /** |
| 506 | * twl_read_idcode_register - API to read the IDCODE register. |
| 507 | * |
| 508 | * Unlocks the IDCODE register and read the 32 bit value. |
| 509 | */ |
| 510 | static int twl_read_idcode_register(void) |
| 511 | { |
| 512 | int err; |
| 513 | |
| 514 | err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK, |
| 515 | REG_UNLOCK_TEST_REG); |
| 516 | if (err) { |
| 517 | pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err); |
| 518 | goto fail; |
| 519 | } |
| 520 | |
| 521 | err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_idcode), |
| 522 | REG_IDCODE_7_0, 4); |
| 523 | if (err) { |
| 524 | pr_err("TWL4030: unable to read IDCODE -%d\n", err); |
| 525 | goto fail; |
| 526 | } |
| 527 | |
| 528 | err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG); |
| 529 | if (err) |
| 530 | pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err); |
| 531 | fail: |
| 532 | return err; |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * twl_get_type - API to get TWL Si type. |
| 537 | * |
| 538 | * Api to get the TWL Si type from IDCODE value. |
| 539 | */ |
| 540 | int twl_get_type(void) |
| 541 | { |
| 542 | return TWL_SIL_TYPE(twl_idcode); |
| 543 | } |
| 544 | EXPORT_SYMBOL_GPL(twl_get_type); |
| 545 | |
| 546 | /** |
| 547 | * twl_get_version - API to get TWL Si version. |
| 548 | * |
| 549 | * Api to get the TWL Si version from IDCODE value. |
| 550 | */ |
| 551 | int twl_get_version(void) |
| 552 | { |
| 553 | return TWL_SIL_REV(twl_idcode); |
| 554 | } |
| 555 | EXPORT_SYMBOL_GPL(twl_get_version); |
| 556 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 557 | static struct device * |
| 558 | add_numbered_child(unsigned chip, const char *name, int num, |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 559 | void *pdata, unsigned pdata_len, |
| 560 | bool can_wakeup, int irq0, int irq1) |
| 561 | { |
| 562 | struct platform_device *pdev; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 563 | struct twl_client *twl = &twl_modules[chip]; |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 564 | int status; |
| 565 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 566 | pdev = platform_device_alloc(name, num); |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 567 | 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 | |
| 599 | err: |
| 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 Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 608 | static 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 | |
| 616 | static struct device * |
| 617 | add_regulator_linked(int num, struct regulator_init_data *pdata, |
| 618 | struct regulator_consumer_supply *consumers, |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 619 | unsigned num_consumers, unsigned long features) |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 620 | { |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 621 | unsigned sub_chip_id; |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame^] | 622 | struct twl_regulator_driver_data drv_data; |
| 623 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 624 | /* regulator framework demands init_data ... */ |
| 625 | if (!pdata) |
| 626 | return NULL; |
| 627 | |
David Brownell | b73eac7 | 2008-12-07 19:10:58 +0100 | [diff] [blame] | 628 | if (consumers) { |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 629 | pdata->consumer_supplies = consumers; |
| 630 | pdata->num_consumer_supplies = num_consumers; |
| 631 | } |
| 632 | |
Tero Kristo | 63bfff4 | 2012-02-16 12:27:52 +0200 | [diff] [blame^] | 633 | if (pdata->driver_data) { |
| 634 | /* If we have existing drv_data, just add the flags */ |
| 635 | struct twl_regulator_driver_data *tmp; |
| 636 | tmp = pdata->driver_data; |
| 637 | tmp->features |= features; |
| 638 | } else { |
| 639 | /* add new driver data struct, used only during init */ |
| 640 | drv_data.features = features; |
| 641 | drv_data.set_voltage = NULL; |
| 642 | drv_data.get_voltage = NULL; |
| 643 | drv_data.data = NULL; |
| 644 | pdata->driver_data = &drv_data; |
| 645 | } |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 646 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 647 | /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 648 | sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid; |
| 649 | return add_numbered_child(sub_chip_id, "twl_reg", num, |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 650 | pdata, sizeof(*pdata), false, 0, 0); |
| 651 | } |
| 652 | |
| 653 | static struct device * |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 654 | add_regulator(int num, struct regulator_init_data *pdata, |
| 655 | unsigned long features) |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 656 | { |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 657 | return add_regulator_linked(num, pdata, NULL, 0, features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 658 | } |
| 659 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 660 | /* |
David Brownell | a30d46c | 2008-10-20 23:46:28 +0200 | [diff] [blame] | 661 | * NOTE: We know the first 8 IRQs after pdata->base_irq are |
| 662 | * for the PIH, and the next are for the PWR_INT SIH, since |
| 663 | * that's how twl_init_irq() sets things up. |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 664 | */ |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 665 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 666 | static int |
| 667 | add_children(struct twl4030_platform_data *pdata, unsigned long features) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 668 | { |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 669 | struct device *child; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 670 | unsigned sub_chip_id; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 671 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 672 | if (twl_has_gpio() && pdata->gpio) { |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 673 | child = add_child(SUB_CHIP_ID1, "twl4030_gpio", |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 674 | pdata->gpio, sizeof(*pdata->gpio), |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 675 | false, pdata->irq_base + GPIO_INTR_OFFSET, 0); |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 676 | if (IS_ERR(child)) |
| 677 | return PTR_ERR(child); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | if (twl_has_keypad() && pdata->keypad) { |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 681 | child = add_child(SUB_CHIP_ID2, "twl4030_keypad", |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 682 | pdata->keypad, sizeof(*pdata->keypad), |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 683 | true, pdata->irq_base + KEYPAD_INTR_OFFSET, 0); |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 684 | if (IS_ERR(child)) |
| 685 | return PTR_ERR(child); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | if (twl_has_madc() && pdata->madc) { |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 689 | child = add_child(2, "twl4030_madc", |
| 690 | pdata->madc, sizeof(*pdata->madc), |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 691 | true, pdata->irq_base + MADC_INTR_OFFSET, 0); |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 692 | if (IS_ERR(child)) |
| 693 | return PTR_ERR(child); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | if (twl_has_rtc()) { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 697 | /* |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 698 | * REVISIT platform_data here currently might expose the |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 699 | * "msecure" line ... but for now we just expect board |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 700 | * setup to tell the chip "it's always ok to SET_TIME". |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 701 | * Eventually, Linux might become more aware of such |
| 702 | * HW security concerns, and "least privilege". |
| 703 | */ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 704 | sub_chip_id = twl_map[TWL_MODULE_RTC].sid; |
| 705 | child = add_child(sub_chip_id, "twl_rtc", |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 706 | NULL, 0, |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 707 | true, pdata->irq_base + RTC_INTR_OFFSET, 0); |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 708 | if (IS_ERR(child)) |
| 709 | return PTR_ERR(child); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 710 | } |
| 711 | |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 712 | if (twl_has_usb() && pdata->usb && twl_class_is_4030()) { |
Roger Quadros | f8ebdff | 2009-09-30 18:26:37 +0300 | [diff] [blame] | 713 | |
| 714 | static struct regulator_consumer_supply usb1v5 = { |
| 715 | .supply = "usb1v5", |
| 716 | }; |
| 717 | static struct regulator_consumer_supply usb1v8 = { |
| 718 | .supply = "usb1v8", |
| 719 | }; |
| 720 | static struct regulator_consumer_supply usb3v1 = { |
| 721 | .supply = "usb3v1", |
| 722 | }; |
| 723 | |
| 724 | /* First add the regulators so that they can be used by transceiver */ |
| 725 | if (twl_has_regulator()) { |
| 726 | /* this is a template that gets copied */ |
| 727 | struct regulator_init_data usb_fixed = { |
| 728 | .constraints.valid_modes_mask = |
| 729 | REGULATOR_MODE_NORMAL |
| 730 | | REGULATOR_MODE_STANDBY, |
| 731 | .constraints.valid_ops_mask = |
| 732 | REGULATOR_CHANGE_MODE |
| 733 | | REGULATOR_CHANGE_STATUS, |
| 734 | }; |
| 735 | |
| 736 | child = add_regulator_linked(TWL4030_REG_VUSB1V5, |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 737 | &usb_fixed, &usb1v5, 1, |
| 738 | features); |
Roger Quadros | f8ebdff | 2009-09-30 18:26:37 +0300 | [diff] [blame] | 739 | if (IS_ERR(child)) |
| 740 | return PTR_ERR(child); |
| 741 | |
| 742 | child = add_regulator_linked(TWL4030_REG_VUSB1V8, |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 743 | &usb_fixed, &usb1v8, 1, |
| 744 | features); |
Roger Quadros | f8ebdff | 2009-09-30 18:26:37 +0300 | [diff] [blame] | 745 | if (IS_ERR(child)) |
| 746 | return PTR_ERR(child); |
| 747 | |
| 748 | child = add_regulator_linked(TWL4030_REG_VUSB3V1, |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 749 | &usb_fixed, &usb3v1, 1, |
| 750 | features); |
Roger Quadros | f8ebdff | 2009-09-30 18:26:37 +0300 | [diff] [blame] | 751 | if (IS_ERR(child)) |
| 752 | return PTR_ERR(child); |
| 753 | |
| 754 | } |
| 755 | |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 756 | child = add_child(0, "twl4030_usb", |
| 757 | pdata->usb, sizeof(*pdata->usb), |
| 758 | true, |
| 759 | /* irq0 = USB_PRES, irq1 = USB */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 760 | pdata->irq_base + USB_PRES_INTR_OFFSET, |
| 761 | pdata->irq_base + USB_INTR_OFFSET); |
Roger Quadros | f8ebdff | 2009-09-30 18:26:37 +0300 | [diff] [blame] | 762 | |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 763 | if (IS_ERR(child)) |
| 764 | return PTR_ERR(child); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 765 | |
| 766 | /* we need to connect regulators to this transceiver */ |
Roger Quadros | f8ebdff | 2009-09-30 18:26:37 +0300 | [diff] [blame] | 767 | if (twl_has_regulator() && child) { |
| 768 | usb1v5.dev = child; |
| 769 | usb1v8.dev = child; |
| 770 | usb3v1.dev = child; |
| 771 | } |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 772 | } |
Hema HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 773 | if (twl_has_usb() && pdata->usb && twl_class_is_6030()) { |
| 774 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 775 | static struct regulator_consumer_supply usb3v3; |
| 776 | int regulator; |
Hema HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 777 | |
| 778 | if (twl_has_regulator()) { |
| 779 | /* this is a template that gets copied */ |
| 780 | struct regulator_init_data usb_fixed = { |
| 781 | .constraints.valid_modes_mask = |
| 782 | REGULATOR_MODE_NORMAL |
| 783 | | REGULATOR_MODE_STANDBY, |
| 784 | .constraints.valid_ops_mask = |
| 785 | REGULATOR_CHANGE_MODE |
| 786 | | REGULATOR_CHANGE_STATUS, |
| 787 | }; |
| 788 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 789 | if (features & TWL6025_SUBCLASS) { |
| 790 | usb3v3.supply = "ldousb"; |
| 791 | regulator = TWL6025_REG_LDOUSB; |
| 792 | } else { |
| 793 | usb3v3.supply = "vusb"; |
| 794 | regulator = TWL6030_REG_VUSB; |
| 795 | } |
| 796 | child = add_regulator_linked(regulator, &usb_fixed, |
| 797 | &usb3v3, 1, |
| 798 | features); |
Hema HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 799 | if (IS_ERR(child)) |
| 800 | return PTR_ERR(child); |
| 801 | } |
| 802 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 803 | pdata->usb->features = features; |
| 804 | |
Hema HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 805 | child = add_child(0, "twl6030_usb", |
| 806 | pdata->usb, sizeof(*pdata->usb), |
| 807 | true, |
| 808 | /* irq1 = VBUS_PRES, irq0 = USB ID */ |
| 809 | pdata->irq_base + USBOTG_INTR_OFFSET, |
| 810 | pdata->irq_base + USB_PRES_INTR_OFFSET); |
| 811 | |
| 812 | if (IS_ERR(child)) |
| 813 | return PTR_ERR(child); |
| 814 | /* we need to connect regulators to this transceiver */ |
| 815 | if (twl_has_regulator() && child) |
| 816 | usb3v3.dev = child; |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 817 | } else if (twl_has_regulator() && twl_class_is_6030()) { |
| 818 | if (features & TWL6025_SUBCLASS) |
| 819 | child = add_regulator(TWL6025_REG_LDOUSB, |
| 820 | pdata->ldousb, features); |
| 821 | else |
| 822 | child = add_regulator(TWL6030_REG_VUSB, |
| 823 | pdata->vusb, features); |
Hema HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 824 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 825 | if (IS_ERR(child)) |
| 826 | return PTR_ERR(child); |
Hema HK | e70357e | 2010-12-10 18:09:52 +0530 | [diff] [blame] | 827 | } |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 828 | |
Keerthy | 153617f | 2011-02-23 16:26:54 +0530 | [diff] [blame] | 829 | if (twl_has_watchdog() && twl_class_is_4030()) { |
Timo Kokkonen | 80e45b1 | 2009-03-27 16:42:17 +0200 | [diff] [blame] | 830 | child = add_child(0, "twl4030_wdt", NULL, 0, false, 0, 0); |
| 831 | if (IS_ERR(child)) |
| 832 | return PTR_ERR(child); |
| 833 | } |
| 834 | |
Keerthy | 153617f | 2011-02-23 16:26:54 +0530 | [diff] [blame] | 835 | if (twl_has_pwrbutton() && twl_class_is_4030()) { |
Felipe Balbi | 9c3664d | 2009-08-03 18:16:38 +0200 | [diff] [blame] | 836 | child = add_child(1, "twl4030_pwrbutton", |
| 837 | NULL, 0, true, pdata->irq_base + 8 + 0, 0); |
| 838 | if (IS_ERR(child)) |
| 839 | return PTR_ERR(child); |
| 840 | } |
| 841 | |
Peter Ujfalusi | 4ae6df5 | 2011-05-31 15:21:13 +0300 | [diff] [blame] | 842 | if (twl_has_codec() && pdata->audio && twl_class_is_4030()) { |
Misael Lopez Cruz | d62abe5 | 2010-02-23 18:10:19 -0600 | [diff] [blame] | 843 | sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 844 | child = add_child(sub_chip_id, "twl4030-audio", |
Peter Ujfalusi | 4ae6df5 | 2011-05-31 15:21:13 +0300 | [diff] [blame] | 845 | pdata->audio, sizeof(*pdata->audio), |
Misael Lopez Cruz | d62abe5 | 2010-02-23 18:10:19 -0600 | [diff] [blame] | 846 | false, 0, 0); |
| 847 | if (IS_ERR(child)) |
| 848 | return PTR_ERR(child); |
| 849 | } |
| 850 | |
Peter Ujfalusi | 4ae6df5 | 2011-05-31 15:21:13 +0300 | [diff] [blame] | 851 | if (twl_has_codec() && pdata->audio && twl_class_is_6030()) { |
Misael Lopez Cruz | d62abe5 | 2010-02-23 18:10:19 -0600 | [diff] [blame] | 852 | sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid; |
Misael Lopez Cruz | f19b282 | 2011-04-27 02:14:07 -0500 | [diff] [blame] | 853 | child = add_child(sub_chip_id, "twl6040", |
Peter Ujfalusi | 4ae6df5 | 2011-05-31 15:21:13 +0300 | [diff] [blame] | 854 | pdata->audio, sizeof(*pdata->audio), |
Peter Ujfalusi | 0b83dde | 2009-10-22 13:26:45 +0300 | [diff] [blame] | 855 | false, 0, 0); |
| 856 | if (IS_ERR(child)) |
| 857 | return PTR_ERR(child); |
| 858 | } |
| 859 | |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 860 | /* twl4030 regulators */ |
| 861 | if (twl_has_regulator() && twl_class_is_4030()) { |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 862 | child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1, |
| 863 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 864 | if (IS_ERR(child)) |
| 865 | return PTR_ERR(child); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 866 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 867 | child = add_regulator(TWL4030_REG_VIO, pdata->vio, |
| 868 | features); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 869 | if (IS_ERR(child)) |
| 870 | return PTR_ERR(child); |
| 871 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 872 | child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1, |
| 873 | features); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 874 | if (IS_ERR(child)) |
| 875 | return PTR_ERR(child); |
| 876 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 877 | child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2, |
| 878 | features); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 879 | if (IS_ERR(child)) |
| 880 | return PTR_ERR(child); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 881 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 882 | child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1, |
| 883 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 884 | if (IS_ERR(child)) |
| 885 | return PTR_ERR(child); |
| 886 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 887 | child = add_regulator(TWL4030_REG_VDAC, pdata->vdac, |
| 888 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 889 | if (IS_ERR(child)) |
| 890 | return PTR_ERR(child); |
| 891 | |
| 892 | child = add_regulator((features & TWL4030_VAUX2) |
| 893 | ? TWL4030_REG_VAUX2_4030 |
| 894 | : TWL4030_REG_VAUX2, |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 895 | pdata->vaux2, features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 896 | if (IS_ERR(child)) |
| 897 | return PTR_ERR(child); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 898 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 899 | child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1, |
| 900 | features); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 901 | if (IS_ERR(child)) |
| 902 | return PTR_ERR(child); |
| 903 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 904 | child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2, |
| 905 | features); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 906 | if (IS_ERR(child)) |
| 907 | return PTR_ERR(child); |
| 908 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 909 | child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig, |
| 910 | features); |
Juha Keski-Saari | ab4abe05 | 2009-12-11 11:12:15 +0100 | [diff] [blame] | 911 | if (IS_ERR(child)) |
| 912 | return PTR_ERR(child); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 913 | } |
| 914 | |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 915 | /* maybe add LDOs that are omitted on cost-reduced parts */ |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 916 | if (twl_has_regulator() && !(features & TPS_SUBSET) |
| 917 | && twl_class_is_4030()) { |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 918 | child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2, |
| 919 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 920 | if (IS_ERR(child)) |
| 921 | return PTR_ERR(child); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 922 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 923 | child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2, |
| 924 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 925 | if (IS_ERR(child)) |
| 926 | return PTR_ERR(child); |
| 927 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 928 | child = add_regulator(TWL4030_REG_VSIM, pdata->vsim, |
| 929 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 930 | if (IS_ERR(child)) |
| 931 | return PTR_ERR(child); |
| 932 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 933 | child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1, |
| 934 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 935 | if (IS_ERR(child)) |
| 936 | return PTR_ERR(child); |
| 937 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 938 | child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3, |
| 939 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 940 | if (IS_ERR(child)) |
| 941 | return PTR_ERR(child); |
| 942 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 943 | child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4, |
| 944 | features); |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 945 | if (IS_ERR(child)) |
| 946 | return PTR_ERR(child); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 947 | } |
| 948 | |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 949 | /* twl6030 regulators */ |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 950 | if (twl_has_regulator() && twl_class_is_6030() && |
| 951 | !(features & TWL6025_SUBCLASS)) { |
| 952 | child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc, |
| 953 | features); |
| 954 | if (IS_ERR(child)) |
| 955 | return PTR_ERR(child); |
| 956 | |
| 957 | child = add_regulator(TWL6030_REG_VPP, pdata->vpp, |
| 958 | features); |
| 959 | if (IS_ERR(child)) |
| 960 | return PTR_ERR(child); |
| 961 | |
| 962 | child = add_regulator(TWL6030_REG_VUSIM, pdata->vusim, |
| 963 | features); |
| 964 | if (IS_ERR(child)) |
| 965 | return PTR_ERR(child); |
| 966 | |
| 967 | child = add_regulator(TWL6030_REG_VCXIO, pdata->vcxio, |
| 968 | features); |
| 969 | if (IS_ERR(child)) |
| 970 | return PTR_ERR(child); |
| 971 | |
| 972 | child = add_regulator(TWL6030_REG_VDAC, pdata->vdac, |
| 973 | features); |
| 974 | if (IS_ERR(child)) |
| 975 | return PTR_ERR(child); |
| 976 | |
| 977 | child = add_regulator(TWL6030_REG_VAUX1_6030, pdata->vaux1, |
| 978 | features); |
| 979 | if (IS_ERR(child)) |
| 980 | return PTR_ERR(child); |
| 981 | |
| 982 | child = add_regulator(TWL6030_REG_VAUX2_6030, pdata->vaux2, |
| 983 | features); |
| 984 | if (IS_ERR(child)) |
| 985 | return PTR_ERR(child); |
| 986 | |
| 987 | child = add_regulator(TWL6030_REG_VAUX3_6030, pdata->vaux3, |
| 988 | features); |
| 989 | if (IS_ERR(child)) |
| 990 | return PTR_ERR(child); |
| 991 | |
| 992 | child = add_regulator(TWL6030_REG_CLK32KG, pdata->clk32kg, |
| 993 | features); |
| 994 | if (IS_ERR(child)) |
| 995 | return PTR_ERR(child); |
| 996 | } |
| 997 | |
| 998 | /* 6030 and 6025 share this regulator */ |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 999 | if (twl_has_regulator() && twl_class_is_6030()) { |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1000 | child = add_regulator(TWL6030_REG_VANA, pdata->vana, |
| 1001 | features); |
| 1002 | if (IS_ERR(child)) |
| 1003 | return PTR_ERR(child); |
| 1004 | } |
| 1005 | |
| 1006 | /* twl6025 regulators */ |
| 1007 | if (twl_has_regulator() && twl_class_is_6030() && |
| 1008 | (features & TWL6025_SUBCLASS)) { |
| 1009 | child = add_regulator(TWL6025_REG_LDO5, pdata->ldo5, |
| 1010 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1011 | if (IS_ERR(child)) |
| 1012 | return PTR_ERR(child); |
| 1013 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1014 | child = add_regulator(TWL6025_REG_LDO1, pdata->ldo1, |
| 1015 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1016 | if (IS_ERR(child)) |
| 1017 | return PTR_ERR(child); |
| 1018 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1019 | child = add_regulator(TWL6025_REG_LDO7, pdata->ldo7, |
| 1020 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1021 | if (IS_ERR(child)) |
| 1022 | return PTR_ERR(child); |
| 1023 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1024 | child = add_regulator(TWL6025_REG_LDO6, pdata->ldo6, |
| 1025 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1026 | if (IS_ERR(child)) |
| 1027 | return PTR_ERR(child); |
| 1028 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1029 | child = add_regulator(TWL6025_REG_LDOLN, pdata->ldoln, |
| 1030 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1031 | if (IS_ERR(child)) |
| 1032 | return PTR_ERR(child); |
| 1033 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1034 | child = add_regulator(TWL6025_REG_LDO2, pdata->ldo2, |
| 1035 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1036 | if (IS_ERR(child)) |
| 1037 | return PTR_ERR(child); |
| 1038 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1039 | child = add_regulator(TWL6025_REG_LDO4, pdata->ldo4, |
| 1040 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1041 | if (IS_ERR(child)) |
| 1042 | return PTR_ERR(child); |
| 1043 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1044 | child = add_regulator(TWL6025_REG_LDO3, pdata->ldo3, |
| 1045 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1046 | if (IS_ERR(child)) |
| 1047 | return PTR_ERR(child); |
| 1048 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1049 | child = add_regulator(TWL6025_REG_SMPS3, pdata->smps3, |
| 1050 | features); |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1051 | if (IS_ERR(child)) |
| 1052 | return PTR_ERR(child); |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 1053 | |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1054 | child = add_regulator(TWL6025_REG_SMPS4, pdata->smps4, |
| 1055 | features); |
Balaji T K | 8e6de4a | 2011-02-10 18:44:50 +0530 | [diff] [blame] | 1056 | if (IS_ERR(child)) |
| 1057 | return PTR_ERR(child); |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1058 | |
| 1059 | child = add_regulator(TWL6025_REG_VIO, pdata->vio6025, |
| 1060 | features); |
| 1061 | if (IS_ERR(child)) |
| 1062 | return PTR_ERR(child); |
| 1063 | |
Rajendra Nayak | 9da6653 | 2009-12-13 22:29:47 +0100 | [diff] [blame] | 1064 | } |
| 1065 | |
Grazvydas Ignotas | 11c39c4 | 2010-10-01 13:17:50 +0300 | [diff] [blame] | 1066 | if (twl_has_bci() && pdata->bci && |
| 1067 | !(features & (TPS_SUBSET | TWL5031))) { |
| 1068 | child = add_child(3, "twl4030_bci", |
| 1069 | pdata->bci, sizeof(*pdata->bci), false, |
| 1070 | /* irq0 = CHG_PRES, irq1 = BCI */ |
| 1071 | pdata->irq_base + BCI_PRES_INTR_OFFSET, |
| 1072 | pdata->irq_base + BCI_INTR_OFFSET); |
| 1073 | if (IS_ERR(child)) |
| 1074 | return PTR_ERR(child); |
| 1075 | } |
| 1076 | |
David Brownell | 5725d66 | 2008-12-01 00:31:04 +0100 | [diff] [blame] | 1077 | return 0; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | /*----------------------------------------------------------------------*/ |
| 1081 | |
| 1082 | /* |
| 1083 | * These three functions initialize the on-chip clock framework, |
| 1084 | * letting it generate the right frequencies for USB, MADC, and |
| 1085 | * other purposes. |
| 1086 | */ |
| 1087 | static inline int __init protect_pm_master(void) |
| 1088 | { |
| 1089 | int e = 0; |
| 1090 | |
Felipe Balbi | 49e6f87 | 2010-08-18 09:19:35 +0300 | [diff] [blame] | 1091 | e = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, |
| 1092 | TWL4030_PM_MASTER_PROTECT_KEY); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1093 | return e; |
| 1094 | } |
| 1095 | |
| 1096 | static inline int __init unprotect_pm_master(void) |
| 1097 | { |
| 1098 | int e = 0; |
| 1099 | |
Felipe Balbi | 49e6f87 | 2010-08-18 09:19:35 +0300 | [diff] [blame] | 1100 | e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, |
| 1101 | TWL4030_PM_MASTER_KEY_CFG1, |
| 1102 | TWL4030_PM_MASTER_PROTECT_KEY); |
| 1103 | e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, |
| 1104 | TWL4030_PM_MASTER_KEY_CFG2, |
| 1105 | TWL4030_PM_MASTER_PROTECT_KEY); |
| 1106 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1107 | return e; |
| 1108 | } |
| 1109 | |
Ilkka Koskinen | 38a6849 | 2009-10-22 14:14:09 +0300 | [diff] [blame] | 1110 | static void clocks_init(struct device *dev, |
| 1111 | struct twl4030_clock_init_data *clock) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1112 | { |
| 1113 | int e = 0; |
| 1114 | struct clk *osc; |
| 1115 | u32 rate; |
| 1116 | u8 ctrl = HFCLK_FREQ_26_MHZ; |
| 1117 | |
| 1118 | #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) |
| 1119 | if (cpu_is_omap2430()) |
Russell King | e6b50c8 | 2009-01-10 10:40:42 +0000 | [diff] [blame] | 1120 | osc = clk_get(dev, "osc_ck"); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1121 | else |
Russell King | e6b50c8 | 2009-01-10 10:40:42 +0000 | [diff] [blame] | 1122 | osc = clk_get(dev, "osc_sys_ck"); |
Samuel Ortiz | 6354ab5c | 2008-12-07 20:50:25 +0100 | [diff] [blame] | 1123 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1124 | if (IS_ERR(osc)) { |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1125 | printk(KERN_WARNING "Skipping twl internal clock init and " |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1126 | "using bootloader value (unknown osc rate)\n"); |
| 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | rate = clk_get_rate(osc); |
| 1131 | clk_put(osc); |
| 1132 | |
Samuel Ortiz | 6354ab5c | 2008-12-07 20:50:25 +0100 | [diff] [blame] | 1133 | #else |
| 1134 | /* REVISIT for non-OMAP systems, pass the clock rate from |
| 1135 | * board init code, using platform_data. |
| 1136 | */ |
| 1137 | osc = ERR_PTR(-EIO); |
| 1138 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1139 | printk(KERN_WARNING "Skipping twl internal clock init and " |
Samuel Ortiz | 6354ab5c | 2008-12-07 20:50:25 +0100 | [diff] [blame] | 1140 | "using bootloader value (unknown osc rate)\n"); |
| 1141 | |
| 1142 | return; |
| 1143 | #endif |
| 1144 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1145 | switch (rate) { |
| 1146 | case 19200000: |
| 1147 | ctrl = HFCLK_FREQ_19p2_MHZ; |
| 1148 | break; |
| 1149 | case 26000000: |
| 1150 | ctrl = HFCLK_FREQ_26_MHZ; |
| 1151 | break; |
| 1152 | case 38400000: |
| 1153 | ctrl = HFCLK_FREQ_38p4_MHZ; |
| 1154 | break; |
| 1155 | } |
| 1156 | |
| 1157 | ctrl |= HIGH_PERF_SQ; |
Ilkka Koskinen | 38a6849 | 2009-10-22 14:14:09 +0300 | [diff] [blame] | 1158 | if (clock && clock->ck32k_lowpwr_enable) |
| 1159 | ctrl |= CK32K_LOWPWR_EN; |
| 1160 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1161 | e |= unprotect_pm_master(); |
| 1162 | /* effect->MADC+USB ck en */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1163 | e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1164 | e |= protect_pm_master(); |
| 1165 | |
| 1166 | if (e < 0) |
| 1167 | pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e); |
| 1168 | } |
| 1169 | |
| 1170 | /*----------------------------------------------------------------------*/ |
| 1171 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 1172 | int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end); |
| 1173 | int twl4030_exit_irq(void); |
| 1174 | int twl4030_init_chip_irq(const char *chip); |
| 1175 | int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end); |
| 1176 | int twl6030_exit_irq(void); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1177 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1178 | static int twl_remove(struct i2c_client *client) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1179 | { |
| 1180 | unsigned i; |
David Brownell | a30d46c | 2008-10-20 23:46:28 +0200 | [diff] [blame] | 1181 | int status; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1182 | |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 1183 | if (twl_class_is_4030()) |
| 1184 | status = twl4030_exit_irq(); |
| 1185 | else |
| 1186 | status = twl6030_exit_irq(); |
| 1187 | |
David Brownell | a30d46c | 2008-10-20 23:46:28 +0200 | [diff] [blame] | 1188 | if (status < 0) |
| 1189 | return status; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1190 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1191 | for (i = 0; i < TWL_NUM_SLAVES; i++) { |
| 1192 | struct twl_client *twl = &twl_modules[i]; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1193 | |
| 1194 | if (twl->client && twl->client != client) |
| 1195 | i2c_unregister_device(twl->client); |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1196 | twl_modules[i].client = NULL; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1197 | } |
| 1198 | inuse = false; |
| 1199 | return 0; |
| 1200 | } |
| 1201 | |
| 1202 | /* NOTE: this driver only handles a single twl4030/tps659x0 chip */ |
Bryan Wu | 5b9cecd | 2010-12-08 10:42:04 +0800 | [diff] [blame] | 1203 | static int __devinit |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1204 | twl_probe(struct i2c_client *client, const struct i2c_device_id *id) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1205 | { |
| 1206 | int status; |
| 1207 | unsigned i; |
| 1208 | struct twl4030_platform_data *pdata = client->dev.platform_data; |
Benoit Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 1209 | struct device_node *node = client->dev.of_node; |
Moiz Sonasath | a29aaf5 | 2010-02-16 18:57:21 -0600 | [diff] [blame] | 1210 | u8 temp; |
Lesly A M | ca972d1 | 2011-04-14 17:57:53 +0530 | [diff] [blame] | 1211 | int ret = 0; |
Benoit Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 1212 | int nr_irqs = TWL4030_NR_IRQS; |
| 1213 | |
| 1214 | if ((id->driver_data) & TWL6030_CLASS) |
| 1215 | nr_irqs = TWL6030_NR_IRQS; |
| 1216 | |
| 1217 | if (node && !pdata) { |
| 1218 | /* |
| 1219 | * XXX: Temporary pdata until the information is correctly |
| 1220 | * retrieved by every TWL modules from DT. |
| 1221 | */ |
| 1222 | pdata = devm_kzalloc(&client->dev, |
| 1223 | sizeof(struct twl4030_platform_data), |
| 1224 | GFP_KERNEL); |
| 1225 | if (!pdata) |
| 1226 | return -ENOMEM; |
| 1227 | } |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1228 | |
| 1229 | if (!pdata) { |
| 1230 | dev_dbg(&client->dev, "no platform data?\n"); |
| 1231 | return -EINVAL; |
| 1232 | } |
| 1233 | |
Benoit Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 1234 | status = irq_alloc_descs(-1, pdata->irq_base, nr_irqs, 0); |
| 1235 | if (IS_ERR_VALUE(status)) { |
| 1236 | dev_err(&client->dev, "Fail to allocate IRQ descs\n"); |
| 1237 | return status; |
| 1238 | } |
| 1239 | |
| 1240 | pdata->irq_base = status; |
| 1241 | pdata->irq_end = pdata->irq_base + nr_irqs; |
| 1242 | |
| 1243 | domain.irq_base = pdata->irq_base; |
| 1244 | domain.nr_irq = nr_irqs; |
| 1245 | #ifdef CONFIG_OF_IRQ |
| 1246 | domain.of_node = of_node_get(node); |
| 1247 | domain.ops = &irq_domain_simple_ops; |
| 1248 | #endif |
| 1249 | irq_domain_add(&domain); |
| 1250 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1251 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { |
| 1252 | dev_dbg(&client->dev, "can't talk I2C?\n"); |
| 1253 | return -EIO; |
| 1254 | } |
| 1255 | |
David Brownell | a30d46c | 2008-10-20 23:46:28 +0200 | [diff] [blame] | 1256 | if (inuse) { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1257 | dev_dbg(&client->dev, "driver is already in use\n"); |
| 1258 | return -EBUSY; |
| 1259 | } |
| 1260 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1261 | for (i = 0; i < TWL_NUM_SLAVES; i++) { |
| 1262 | struct twl_client *twl = &twl_modules[i]; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1263 | |
| 1264 | twl->address = client->addr + i; |
| 1265 | if (i == 0) |
| 1266 | twl->client = client; |
| 1267 | else { |
| 1268 | twl->client = i2c_new_dummy(client->adapter, |
| 1269 | twl->address); |
| 1270 | if (!twl->client) { |
Ilkka Koskinen | a864343 | 2009-10-20 16:22:52 +0300 | [diff] [blame] | 1271 | dev_err(&client->dev, |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1272 | "can't attach client %d\n", i); |
| 1273 | status = -ENOMEM; |
| 1274 | goto fail; |
| 1275 | } |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1276 | } |
| 1277 | mutex_init(&twl->xfer_lock); |
| 1278 | } |
| 1279 | inuse = true; |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 1280 | if ((id->driver_data) & TWL6030_CLASS) { |
| 1281 | twl_id = TWL6030_CLASS_ID; |
| 1282 | twl_map = &twl6030_map[0]; |
| 1283 | } else { |
| 1284 | twl_id = TWL4030_CLASS_ID; |
| 1285 | twl_map = &twl4030_map[0]; |
| 1286 | } |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1287 | |
| 1288 | /* setup clock framework */ |
Ilkka Koskinen | 38a6849 | 2009-10-22 14:14:09 +0300 | [diff] [blame] | 1289 | clocks_init(&client->dev, pdata->clock); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1290 | |
Lesly A M | ca972d1 | 2011-04-14 17:57:53 +0530 | [diff] [blame] | 1291 | /* read TWL IDCODE Register */ |
| 1292 | if (twl_id == TWL4030_CLASS_ID) { |
| 1293 | ret = twl_read_idcode_register(); |
| 1294 | WARN(ret < 0, "Error: reading twl_idcode register value\n"); |
| 1295 | } |
| 1296 | |
Amit Kucheria | ebf0bd3 | 2009-08-31 18:32:18 +0200 | [diff] [blame] | 1297 | /* load power event scripts */ |
| 1298 | if (twl_has_power() && pdata->power) |
| 1299 | twl4030_power_init(pdata->power); |
| 1300 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1301 | /* Maybe init the T2 Interrupt subsystem */ |
| 1302 | if (client->irq |
| 1303 | && pdata->irq_base |
| 1304 | && pdata->irq_end > pdata->irq_base) { |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 1305 | if (twl_class_is_4030()) { |
| 1306 | twl4030_init_chip_irq(id->name); |
| 1307 | status = twl4030_init_irq(client->irq, pdata->irq_base, |
| 1308 | pdata->irq_end); |
| 1309 | } else { |
| 1310 | status = twl6030_init_irq(client->irq, pdata->irq_base, |
| 1311 | pdata->irq_end); |
| 1312 | } |
| 1313 | |
David Brownell | a30d46c | 2008-10-20 23:46:28 +0200 | [diff] [blame] | 1314 | if (status < 0) |
| 1315 | goto fail; |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1316 | } |
| 1317 | |
Moiz Sonasath | a29aaf5 | 2010-02-16 18:57:21 -0600 | [diff] [blame] | 1318 | /* Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. |
| 1319 | * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0, |
| 1320 | * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0. |
| 1321 | */ |
| 1322 | |
| 1323 | if (twl_class_is_4030()) { |
| 1324 | twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1); |
| 1325 | temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \ |
| 1326 | I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU); |
| 1327 | twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); |
| 1328 | } |
| 1329 | |
Benoit Cousson | aeb5032 | 2011-08-29 16:20:23 +0200 | [diff] [blame] | 1330 | #ifdef CONFIG_OF_DEVICE |
| 1331 | if (node) |
| 1332 | status = of_platform_populate(node, NULL, NULL, &client->dev); |
| 1333 | else |
| 1334 | #endif |
| 1335 | status = add_children(pdata, id->driver_data); |
| 1336 | |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1337 | fail: |
| 1338 | if (status < 0) |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1339 | twl_remove(client); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1340 | return status; |
| 1341 | } |
| 1342 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1343 | static const struct i2c_device_id twl_ids[] = { |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 1344 | { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */ |
| 1345 | { "twl5030", 0 }, /* T2 updated */ |
Ilkka Koskinen | 1920a61 | 2009-11-10 17:26:15 +0200 | [diff] [blame] | 1346 | { "twl5031", TWL5031 }, /* TWL5030 updated */ |
David Brownell | dad759f | 2008-12-01 00:43:58 +0100 | [diff] [blame] | 1347 | { "tps65950", 0 }, /* catalog version of twl5030 */ |
| 1348 | { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */ |
| 1349 | { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */ |
Oleg Drokin | 59dead5 | 2011-07-01 13:34:13 +0200 | [diff] [blame] | 1350 | { "tps65921", TPS_SUBSET }, /* fewer LDOs; no codec, no LED |
| 1351 | and vibrator. Charger in USB module*/ |
Balaji T K | e8deb28 | 2009-12-14 00:25:31 +0100 | [diff] [blame] | 1352 | { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */ |
Graeme Gregory | 521d8ec | 2011-05-12 14:27:55 +0100 | [diff] [blame] | 1353 | { "twl6025", TWL6030_CLASS | TWL6025_SUBCLASS }, /* "Phoenix lite" */ |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1354 | { /* end of list */ }, |
| 1355 | }; |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1356 | MODULE_DEVICE_TABLE(i2c, twl_ids); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1357 | |
| 1358 | /* One Client Driver , 4 Clients */ |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1359 | static struct i2c_driver twl_driver = { |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1360 | .driver.name = DRIVER_NAME, |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1361 | .id_table = twl_ids, |
| 1362 | .probe = twl_probe, |
| 1363 | .remove = twl_remove, |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1364 | }; |
| 1365 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1366 | static int __init twl_init(void) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1367 | { |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1368 | return i2c_add_driver(&twl_driver); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1369 | } |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1370 | subsys_initcall(twl_init); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1371 | |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1372 | static void __exit twl_exit(void) |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1373 | { |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1374 | i2c_del_driver(&twl_driver); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1375 | } |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1376 | module_exit(twl_exit); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1377 | |
| 1378 | MODULE_AUTHOR("Texas Instruments, Inc."); |
Balaji T K | fc7b92f | 2009-12-13 21:23:33 +0100 | [diff] [blame] | 1379 | MODULE_DESCRIPTION("I2C Core interface for TWL"); |
David Brownell | a603a7f | 2008-10-15 12:15:39 +0200 | [diff] [blame] | 1380 | MODULE_LICENSE("GPL"); |