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