1b07682b6SSantosh Shilimkar /* 2fc7b92fcSBalaji T K * twl_core.c - driver for TWL4030/TWL5030/TWL60X0/TPS659x0 PM 3fc7b92fcSBalaji T K * and audio CODEC devices 4b07682b6SSantosh Shilimkar * 5b07682b6SSantosh Shilimkar * Copyright (C) 2005-2006 Texas Instruments, Inc. 6b07682b6SSantosh Shilimkar * 7b07682b6SSantosh Shilimkar * Modifications to defer interrupt handling to a kernel thread: 8b07682b6SSantosh Shilimkar * Copyright (C) 2006 MontaVista Software, Inc. 9b07682b6SSantosh Shilimkar * 10b07682b6SSantosh Shilimkar * Based on tlv320aic23.c: 11b07682b6SSantosh Shilimkar * Copyright (c) by Kai Svahn <kai.svahn@nokia.com> 12b07682b6SSantosh Shilimkar * 13b07682b6SSantosh Shilimkar * Code cleanup and modifications to IRQ handler. 14b07682b6SSantosh Shilimkar * by syed khasim <x0khasim@ti.com> 15b07682b6SSantosh Shilimkar * 16b07682b6SSantosh Shilimkar * This program is free software; you can redistribute it and/or modify 17b07682b6SSantosh Shilimkar * it under the terms of the GNU General Public License as published by 18b07682b6SSantosh Shilimkar * the Free Software Foundation; either version 2 of the License, or 19b07682b6SSantosh Shilimkar * (at your option) any later version. 20b07682b6SSantosh Shilimkar * 21b07682b6SSantosh Shilimkar * This program is distributed in the hope that it will be useful, 22b07682b6SSantosh Shilimkar * but WITHOUT ANY WARRANTY; without even the implied warranty of 23b07682b6SSantosh Shilimkar * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24b07682b6SSantosh Shilimkar * GNU General Public License for more details. 25b07682b6SSantosh Shilimkar * 26b07682b6SSantosh Shilimkar * You should have received a copy of the GNU General Public License 27b07682b6SSantosh Shilimkar * along with this program; if not, write to the Free Software 28b07682b6SSantosh Shilimkar * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29b07682b6SSantosh Shilimkar */ 30b07682b6SSantosh Shilimkar 31b07682b6SSantosh Shilimkar #include <linux/init.h> 32b07682b6SSantosh Shilimkar #include <linux/mutex.h> 33b07682b6SSantosh Shilimkar #include <linux/platform_device.h> 34b07682b6SSantosh Shilimkar #include <linux/clk.h> 35b07682b6SSantosh Shilimkar #include <linux/err.h> 36b07682b6SSantosh Shilimkar 37b07682b6SSantosh Shilimkar #include <linux/regulator/machine.h> 38b07682b6SSantosh Shilimkar 39b07682b6SSantosh Shilimkar #include <linux/i2c.h> 40b07682b6SSantosh Shilimkar #include <linux/i2c/twl.h> 41b07682b6SSantosh Shilimkar 42b07682b6SSantosh Shilimkar #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) 43b07682b6SSantosh Shilimkar #include <plat/cpu.h> 44b07682b6SSantosh Shilimkar #endif 45b07682b6SSantosh Shilimkar 46b07682b6SSantosh Shilimkar /* 47b07682b6SSantosh Shilimkar * The TWL4030 "Triton 2" is one of a family of a multi-function "Power 48b07682b6SSantosh Shilimkar * Management and System Companion Device" chips originally designed for 49b07682b6SSantosh Shilimkar * use in OMAP2 and OMAP 3 based systems. Its control interfaces use I2C, 50b07682b6SSantosh Shilimkar * often at around 3 Mbit/sec, including for interrupt handling. 51b07682b6SSantosh Shilimkar * 52b07682b6SSantosh Shilimkar * This driver core provides genirq support for the interrupts emitted, 53b07682b6SSantosh Shilimkar * by the various modules, and exports register access primitives. 54b07682b6SSantosh Shilimkar * 55b07682b6SSantosh Shilimkar * FIXME this driver currently requires use of the first interrupt line 56b07682b6SSantosh Shilimkar * (and associated registers). 57b07682b6SSantosh Shilimkar */ 58b07682b6SSantosh Shilimkar 59fc7b92fcSBalaji T K #define DRIVER_NAME "twl" 60b07682b6SSantosh Shilimkar 61b07682b6SSantosh Shilimkar #if defined(CONFIG_KEYBOARD_TWL4030) || defined(CONFIG_KEYBOARD_TWL4030_MODULE) 62b07682b6SSantosh Shilimkar #define twl_has_keypad() true 63b07682b6SSantosh Shilimkar #else 64b07682b6SSantosh Shilimkar #define twl_has_keypad() false 65b07682b6SSantosh Shilimkar #endif 66b07682b6SSantosh Shilimkar 67b07682b6SSantosh Shilimkar #if defined(CONFIG_GPIO_TWL4030) || defined(CONFIG_GPIO_TWL4030_MODULE) 68b07682b6SSantosh Shilimkar #define twl_has_gpio() true 69b07682b6SSantosh Shilimkar #else 70b07682b6SSantosh Shilimkar #define twl_has_gpio() false 71b07682b6SSantosh Shilimkar #endif 72b07682b6SSantosh Shilimkar 73b07682b6SSantosh Shilimkar #if defined(CONFIG_REGULATOR_TWL4030) \ 74b07682b6SSantosh Shilimkar || defined(CONFIG_REGULATOR_TWL4030_MODULE) 75b07682b6SSantosh Shilimkar #define twl_has_regulator() true 76b07682b6SSantosh Shilimkar #else 77b07682b6SSantosh Shilimkar #define twl_has_regulator() false 78b07682b6SSantosh Shilimkar #endif 79b07682b6SSantosh Shilimkar 80b07682b6SSantosh Shilimkar #if defined(CONFIG_TWL4030_MADC) || defined(CONFIG_TWL4030_MADC_MODULE) 81b07682b6SSantosh Shilimkar #define twl_has_madc() true 82b07682b6SSantosh Shilimkar #else 83b07682b6SSantosh Shilimkar #define twl_has_madc() false 84b07682b6SSantosh Shilimkar #endif 85b07682b6SSantosh Shilimkar 86b07682b6SSantosh Shilimkar #ifdef CONFIG_TWL4030_POWER 87b07682b6SSantosh Shilimkar #define twl_has_power() true 88b07682b6SSantosh Shilimkar #else 89b07682b6SSantosh Shilimkar #define twl_has_power() false 90b07682b6SSantosh Shilimkar #endif 91b07682b6SSantosh Shilimkar 92b07682b6SSantosh Shilimkar #if defined(CONFIG_RTC_DRV_TWL4030) || defined(CONFIG_RTC_DRV_TWL4030_MODULE) 93b07682b6SSantosh Shilimkar #define twl_has_rtc() true 94b07682b6SSantosh Shilimkar #else 95b07682b6SSantosh Shilimkar #define twl_has_rtc() false 96b07682b6SSantosh Shilimkar #endif 97b07682b6SSantosh Shilimkar 98e70357e3SHema HK #if defined(CONFIG_TWL4030_USB) || defined(CONFIG_TWL4030_USB_MODULE) ||\ 99e70357e3SHema HK defined(CONFIG_TWL6030_USB) || defined(CONFIG_TWL6030_USB_MODULE) 100b07682b6SSantosh Shilimkar #define twl_has_usb() true 101b07682b6SSantosh Shilimkar #else 102b07682b6SSantosh Shilimkar #define twl_has_usb() false 103b07682b6SSantosh Shilimkar #endif 104b07682b6SSantosh Shilimkar 105b07682b6SSantosh Shilimkar #if defined(CONFIG_TWL4030_WATCHDOG) || \ 106b07682b6SSantosh Shilimkar defined(CONFIG_TWL4030_WATCHDOG_MODULE) 107b07682b6SSantosh Shilimkar #define twl_has_watchdog() true 108b07682b6SSantosh Shilimkar #else 109b07682b6SSantosh Shilimkar #define twl_has_watchdog() false 110b07682b6SSantosh Shilimkar #endif 111b07682b6SSantosh Shilimkar 112d62abe56SMisael Lopez Cruz #if defined(CONFIG_TWL4030_CODEC) || defined(CONFIG_TWL4030_CODEC_MODULE) ||\ 113f19b2823SMisael Lopez Cruz defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE) 114b07682b6SSantosh Shilimkar #define twl_has_codec() true 115b07682b6SSantosh Shilimkar #else 116b07682b6SSantosh Shilimkar #define twl_has_codec() false 117b07682b6SSantosh Shilimkar #endif 118b07682b6SSantosh Shilimkar 11911c39c4bSGrazvydas Ignotas #if defined(CONFIG_CHARGER_TWL4030) || defined(CONFIG_CHARGER_TWL4030_MODULE) 12011c39c4bSGrazvydas Ignotas #define twl_has_bci() true 12111c39c4bSGrazvydas Ignotas #else 12211c39c4bSGrazvydas Ignotas #define twl_has_bci() false 12311c39c4bSGrazvydas Ignotas #endif 12411c39c4bSGrazvydas Ignotas 125b07682b6SSantosh Shilimkar /* Triton Core internal information (BEGIN) */ 126b07682b6SSantosh Shilimkar 127b07682b6SSantosh Shilimkar /* Last - for index max*/ 128b07682b6SSantosh Shilimkar #define TWL4030_MODULE_LAST TWL4030_MODULE_SECURED_REG 129b07682b6SSantosh Shilimkar 130fc7b92fcSBalaji T K #define TWL_NUM_SLAVES 4 131b07682b6SSantosh Shilimkar 132b07682b6SSantosh Shilimkar #if defined(CONFIG_INPUT_TWL4030_PWRBUTTON) \ 13314e5c82cSEduardo Valentin || defined(CONFIG_INPUT_TWL4030_PWRBUTTON_MODULE) 134b07682b6SSantosh Shilimkar #define twl_has_pwrbutton() true 135b07682b6SSantosh Shilimkar #else 136b07682b6SSantosh Shilimkar #define twl_has_pwrbutton() false 137b07682b6SSantosh Shilimkar #endif 138b07682b6SSantosh Shilimkar 139fc7b92fcSBalaji T K #define SUB_CHIP_ID0 0 140fc7b92fcSBalaji T K #define SUB_CHIP_ID1 1 141fc7b92fcSBalaji T K #define SUB_CHIP_ID2 2 142fc7b92fcSBalaji T K #define SUB_CHIP_ID3 3 143fc7b92fcSBalaji T K 144fc7b92fcSBalaji T K #define TWL_MODULE_LAST TWL4030_MODULE_LAST 145fc7b92fcSBalaji T K 146b07682b6SSantosh Shilimkar /* Base Address defns for twl4030_map[] */ 147b07682b6SSantosh Shilimkar 148b07682b6SSantosh Shilimkar /* subchip/slave 0 - USB ID */ 149b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_USB 0x0000 150b07682b6SSantosh Shilimkar 151b07682b6SSantosh Shilimkar /* subchip/slave 1 - AUD ID */ 152b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_AUDIO_VOICE 0x0000 153b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_GPIO 0x0098 154b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_INTBR 0x0085 155b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PIH 0x0080 156b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_TEST 0x004C 157b07682b6SSantosh Shilimkar 158b07682b6SSantosh Shilimkar /* subchip/slave 2 - AUX ID */ 159b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_INTERRUPTS 0x00B9 160b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_LED 0x00EE 161b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_MADC 0x0000 162b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_MAIN_CHARGE 0x0074 163b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PRECHARGE 0x00AA 164b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PWM0 0x00F8 165b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PWM1 0x00FB 166b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PWMA 0x00EF 167b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PWMB 0x00F1 168b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_KEYPAD 0x00D2 169b07682b6SSantosh Shilimkar 170b07682b6SSantosh Shilimkar #define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */ 171b07682b6SSantosh Shilimkar #define TWL5031_BASEADD_INTERRUPTS 0x00B9 /* Different than TWL4030's 172b07682b6SSantosh Shilimkar one */ 173b07682b6SSantosh Shilimkar 174b07682b6SSantosh Shilimkar /* subchip/slave 3 - POWER ID */ 175b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_BACKUP 0x0014 176b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_INT 0x002E 177b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PM_MASTER 0x0036 178b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_PM_RECEIVER 0x005B 179b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_RTC 0x001C 180b07682b6SSantosh Shilimkar #define TWL4030_BASEADD_SECURED_REG 0x0000 181b07682b6SSantosh Shilimkar 182b07682b6SSantosh Shilimkar /* Triton Core internal information (END) */ 183b07682b6SSantosh Shilimkar 184b07682b6SSantosh Shilimkar 185e8deb28cSBalaji T K /* subchip/slave 0 0x48 - POWER */ 186e8deb28cSBalaji T K #define TWL6030_BASEADD_RTC 0x0000 187e8deb28cSBalaji T K #define TWL6030_BASEADD_MEM 0x0017 188e8deb28cSBalaji T K #define TWL6030_BASEADD_PM_MASTER 0x001F 189e8deb28cSBalaji T K #define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */ 190e8deb28cSBalaji T K #define TWL6030_BASEADD_PM_MISC 0x00E2 191e8deb28cSBalaji T K #define TWL6030_BASEADD_PM_PUPD 0x00F0 192e8deb28cSBalaji T K 193e8deb28cSBalaji T K /* subchip/slave 1 0x49 - FEATURE */ 194e8deb28cSBalaji T K #define TWL6030_BASEADD_USB 0x0000 195e8deb28cSBalaji T K #define TWL6030_BASEADD_GPADC_CTRL 0x002E 196e8deb28cSBalaji T K #define TWL6030_BASEADD_AUX 0x0090 197e8deb28cSBalaji T K #define TWL6030_BASEADD_PWM 0x00BA 198e8deb28cSBalaji T K #define TWL6030_BASEADD_GASGAUGE 0x00C0 199e8deb28cSBalaji T K #define TWL6030_BASEADD_PIH 0x00D0 200e8deb28cSBalaji T K #define TWL6030_BASEADD_CHARGER 0x00E0 201521d8ec3SGraeme Gregory #define TWL6025_BASEADD_CHARGER 0x00DA 202e8deb28cSBalaji T K 203e8deb28cSBalaji T K /* subchip/slave 2 0x4A - DFT */ 204e8deb28cSBalaji T K #define TWL6030_BASEADD_DIEID 0x00C0 205e8deb28cSBalaji T K 206e8deb28cSBalaji T K /* subchip/slave 3 0x4B - AUDIO */ 207e8deb28cSBalaji T K #define TWL6030_BASEADD_AUDIO 0x0000 208e8deb28cSBalaji T K #define TWL6030_BASEADD_RSV 0x0000 209fa0d9762SBalaji T K #define TWL6030_BASEADD_ZERO 0x0000 210e8deb28cSBalaji T K 211b07682b6SSantosh Shilimkar /* Few power values */ 212b07682b6SSantosh Shilimkar #define R_CFG_BOOT 0x05 213b07682b6SSantosh Shilimkar 214b07682b6SSantosh Shilimkar /* some fields in R_CFG_BOOT */ 215b07682b6SSantosh Shilimkar #define HFCLK_FREQ_19p2_MHZ (1 << 0) 216b07682b6SSantosh Shilimkar #define HFCLK_FREQ_26_MHZ (2 << 0) 217b07682b6SSantosh Shilimkar #define HFCLK_FREQ_38p4_MHZ (3 << 0) 218b07682b6SSantosh Shilimkar #define HIGH_PERF_SQ (1 << 3) 219b07682b6SSantosh Shilimkar #define CK32K_LOWPWR_EN (1 << 7) 220b07682b6SSantosh Shilimkar 221b07682b6SSantosh Shilimkar 222b07682b6SSantosh Shilimkar /* chip-specific feature flags, for i2c_device_id.driver_data */ 223b07682b6SSantosh Shilimkar #define TWL4030_VAUX2 BIT(0) /* pre-5030 voltage ranges */ 224b07682b6SSantosh Shilimkar #define TPS_SUBSET BIT(1) /* tps659[23]0 have fewer LDOs */ 225b07682b6SSantosh Shilimkar #define TWL5031 BIT(2) /* twl5031 has different registers */ 226e8deb28cSBalaji T K #define TWL6030_CLASS BIT(3) /* TWL6030 class */ 227b07682b6SSantosh Shilimkar 228b07682b6SSantosh Shilimkar /*----------------------------------------------------------------------*/ 229b07682b6SSantosh Shilimkar 230b07682b6SSantosh Shilimkar /* is driver active, bound to a chip? */ 231b07682b6SSantosh Shilimkar static bool inuse; 232b07682b6SSantosh Shilimkar 233ca972d13SLesly A M /* TWL IDCODE Register value */ 234ca972d13SLesly A M static u32 twl_idcode; 235ca972d13SLesly A M 236e8deb28cSBalaji T K static unsigned int twl_id; 237e8deb28cSBalaji T K unsigned int twl_rev(void) 238e8deb28cSBalaji T K { 239e8deb28cSBalaji T K return twl_id; 240e8deb28cSBalaji T K } 241e8deb28cSBalaji T K EXPORT_SYMBOL(twl_rev); 242e8deb28cSBalaji T K 243e8deb28cSBalaji T K /* Structure for each TWL4030/TWL6030 Slave */ 244fc7b92fcSBalaji T K struct twl_client { 245b07682b6SSantosh Shilimkar struct i2c_client *client; 246b07682b6SSantosh Shilimkar u8 address; 247b07682b6SSantosh Shilimkar 248b07682b6SSantosh Shilimkar /* max numb of i2c_msg required is for read =2 */ 249b07682b6SSantosh Shilimkar struct i2c_msg xfer_msg[2]; 250b07682b6SSantosh Shilimkar 251b07682b6SSantosh Shilimkar /* To lock access to xfer_msg */ 252b07682b6SSantosh Shilimkar struct mutex xfer_lock; 253b07682b6SSantosh Shilimkar }; 254b07682b6SSantosh Shilimkar 255fc7b92fcSBalaji T K static struct twl_client twl_modules[TWL_NUM_SLAVES]; 256b07682b6SSantosh Shilimkar 257b07682b6SSantosh Shilimkar 258b07682b6SSantosh Shilimkar /* mapping the module id to slave id and base address */ 259fc7b92fcSBalaji T K struct twl_mapping { 260b07682b6SSantosh Shilimkar unsigned char sid; /* Slave ID */ 261b07682b6SSantosh Shilimkar unsigned char base; /* base address */ 262b07682b6SSantosh Shilimkar }; 2632cfcce18SG, Manjunath Kondaiah static struct twl_mapping *twl_map; 264b07682b6SSantosh Shilimkar 265fc7b92fcSBalaji T K static struct twl_mapping twl4030_map[TWL4030_MODULE_LAST + 1] = { 266b07682b6SSantosh Shilimkar /* 267b07682b6SSantosh Shilimkar * NOTE: don't change this table without updating the 268e8deb28cSBalaji T K * <linux/i2c/twl.h> defines for TWL4030_MODULE_* 269b07682b6SSantosh Shilimkar * so they continue to match the order in this table. 270b07682b6SSantosh Shilimkar */ 271b07682b6SSantosh Shilimkar 272b07682b6SSantosh Shilimkar { 0, TWL4030_BASEADD_USB }, 273b07682b6SSantosh Shilimkar 274b07682b6SSantosh Shilimkar { 1, TWL4030_BASEADD_AUDIO_VOICE }, 275b07682b6SSantosh Shilimkar { 1, TWL4030_BASEADD_GPIO }, 276b07682b6SSantosh Shilimkar { 1, TWL4030_BASEADD_INTBR }, 277b07682b6SSantosh Shilimkar { 1, TWL4030_BASEADD_PIH }, 278b07682b6SSantosh Shilimkar { 1, TWL4030_BASEADD_TEST }, 279b07682b6SSantosh Shilimkar 280b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_KEYPAD }, 281b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_MADC }, 282b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_INTERRUPTS }, 283b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_LED }, 284b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_MAIN_CHARGE }, 285b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_PRECHARGE }, 286b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_PWM0 }, 287b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_PWM1 }, 288b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_PWMA }, 289b07682b6SSantosh Shilimkar { 2, TWL4030_BASEADD_PWMB }, 290b07682b6SSantosh Shilimkar { 2, TWL5031_BASEADD_ACCESSORY }, 291b07682b6SSantosh Shilimkar { 2, TWL5031_BASEADD_INTERRUPTS }, 292b07682b6SSantosh Shilimkar 293b07682b6SSantosh Shilimkar { 3, TWL4030_BASEADD_BACKUP }, 294b07682b6SSantosh Shilimkar { 3, TWL4030_BASEADD_INT }, 295b07682b6SSantosh Shilimkar { 3, TWL4030_BASEADD_PM_MASTER }, 296b07682b6SSantosh Shilimkar { 3, TWL4030_BASEADD_PM_RECEIVER }, 297b07682b6SSantosh Shilimkar { 3, TWL4030_BASEADD_RTC }, 298b07682b6SSantosh Shilimkar { 3, TWL4030_BASEADD_SECURED_REG }, 299b07682b6SSantosh Shilimkar }; 300b07682b6SSantosh Shilimkar 301e8deb28cSBalaji T K static struct twl_mapping twl6030_map[] = { 302e8deb28cSBalaji T K /* 303e8deb28cSBalaji T K * NOTE: don't change this table without updating the 304e8deb28cSBalaji T K * <linux/i2c/twl.h> defines for TWL4030_MODULE_* 305e8deb28cSBalaji T K * so they continue to match the order in this table. 306e8deb28cSBalaji T K */ 307e8deb28cSBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_USB }, 308e8deb28cSBalaji T K { SUB_CHIP_ID3, TWL6030_BASEADD_AUDIO }, 309e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID }, 310e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 311e8deb28cSBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_PIH }, 312e8deb28cSBalaji T K 313e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 314e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 315e8deb28cSBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_GPADC_CTRL }, 316e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 317e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 318e8deb28cSBalaji T K 319e8deb28cSBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER }, 320e8deb28cSBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE }, 321e8deb28cSBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_PWM }, 322fa0d9762SBalaji T K { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO }, 323fa0d9762SBalaji T K { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO }, 324e8deb28cSBalaji T K 325fa0d9762SBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, 326fa0d9762SBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, 327e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 328e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 329e8deb28cSBalaji T K { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, 330e8deb28cSBalaji T K { SUB_CHIP_ID0, TWL6030_BASEADD_PM_MASTER }, 331e8deb28cSBalaji T K { SUB_CHIP_ID0, TWL6030_BASEADD_PM_SLAVE_MISC }, 332e8deb28cSBalaji T K 333e8deb28cSBalaji T K { SUB_CHIP_ID0, TWL6030_BASEADD_RTC }, 334e8deb28cSBalaji T K { SUB_CHIP_ID0, TWL6030_BASEADD_MEM }, 335521d8ec3SGraeme Gregory { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER }, 336e8deb28cSBalaji T K }; 337e8deb28cSBalaji T K 338b07682b6SSantosh Shilimkar /*----------------------------------------------------------------------*/ 339b07682b6SSantosh Shilimkar 340b07682b6SSantosh Shilimkar /* Exported Functions */ 341b07682b6SSantosh Shilimkar 342b07682b6SSantosh Shilimkar /** 343fc7b92fcSBalaji T K * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0 344b07682b6SSantosh Shilimkar * @mod_no: module number 345b07682b6SSantosh Shilimkar * @value: an array of num_bytes+1 containing data to write 346b07682b6SSantosh Shilimkar * @reg: register address (just offset will do) 347b07682b6SSantosh Shilimkar * @num_bytes: number of bytes to transfer 348b07682b6SSantosh Shilimkar * 349b07682b6SSantosh Shilimkar * IMPORTANT: for 'value' parameter: Allocate value num_bytes+1 and 350b07682b6SSantosh Shilimkar * valid data starts at Offset 1. 351b07682b6SSantosh Shilimkar * 352b07682b6SSantosh Shilimkar * Returns the result of operation - 0 is success 353b07682b6SSantosh Shilimkar */ 354fc7b92fcSBalaji T K int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) 355b07682b6SSantosh Shilimkar { 356b07682b6SSantosh Shilimkar int ret; 357b07682b6SSantosh Shilimkar int sid; 358fc7b92fcSBalaji T K struct twl_client *twl; 359b07682b6SSantosh Shilimkar struct i2c_msg *msg; 360b07682b6SSantosh Shilimkar 361fc7b92fcSBalaji T K if (unlikely(mod_no > TWL_MODULE_LAST)) { 362b07682b6SSantosh Shilimkar pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); 363b07682b6SSantosh Shilimkar return -EPERM; 364b07682b6SSantosh Shilimkar } 365e8deb28cSBalaji T K sid = twl_map[mod_no].sid; 366fc7b92fcSBalaji T K twl = &twl_modules[sid]; 367b07682b6SSantosh Shilimkar 368b07682b6SSantosh Shilimkar if (unlikely(!inuse)) { 369b07682b6SSantosh Shilimkar pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid); 370b07682b6SSantosh Shilimkar return -EPERM; 371b07682b6SSantosh Shilimkar } 372b07682b6SSantosh Shilimkar mutex_lock(&twl->xfer_lock); 373b07682b6SSantosh Shilimkar /* 374b07682b6SSantosh Shilimkar * [MSG1]: fill the register address data 375b07682b6SSantosh Shilimkar * fill the data Tx buffer 376b07682b6SSantosh Shilimkar */ 377b07682b6SSantosh Shilimkar msg = &twl->xfer_msg[0]; 378b07682b6SSantosh Shilimkar msg->addr = twl->address; 379b07682b6SSantosh Shilimkar msg->len = num_bytes + 1; 380b07682b6SSantosh Shilimkar msg->flags = 0; 381b07682b6SSantosh Shilimkar msg->buf = value; 382b07682b6SSantosh Shilimkar /* over write the first byte of buffer with the register address */ 383e8deb28cSBalaji T K *value = twl_map[mod_no].base + reg; 384b07682b6SSantosh Shilimkar ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 1); 385b07682b6SSantosh Shilimkar mutex_unlock(&twl->xfer_lock); 386b07682b6SSantosh Shilimkar 387b07682b6SSantosh Shilimkar /* i2c_transfer returns number of messages transferred */ 388b07682b6SSantosh Shilimkar if (ret != 1) { 389b07682b6SSantosh Shilimkar pr_err("%s: i2c_write failed to transfer all messages\n", 390b07682b6SSantosh Shilimkar DRIVER_NAME); 391b07682b6SSantosh Shilimkar if (ret < 0) 392b07682b6SSantosh Shilimkar return ret; 393b07682b6SSantosh Shilimkar else 394b07682b6SSantosh Shilimkar return -EIO; 395b07682b6SSantosh Shilimkar } else { 396b07682b6SSantosh Shilimkar return 0; 397b07682b6SSantosh Shilimkar } 398b07682b6SSantosh Shilimkar } 399fc7b92fcSBalaji T K EXPORT_SYMBOL(twl_i2c_write); 400b07682b6SSantosh Shilimkar 401b07682b6SSantosh Shilimkar /** 402fc7b92fcSBalaji T K * twl_i2c_read - Reads a n bit register in TWL4030/TWL5030/TWL60X0 403b07682b6SSantosh Shilimkar * @mod_no: module number 404b07682b6SSantosh Shilimkar * @value: an array of num_bytes containing data to be read 405b07682b6SSantosh Shilimkar * @reg: register address (just offset will do) 406b07682b6SSantosh Shilimkar * @num_bytes: number of bytes to transfer 407b07682b6SSantosh Shilimkar * 408b07682b6SSantosh Shilimkar * Returns result of operation - num_bytes is success else failure. 409b07682b6SSantosh Shilimkar */ 410fc7b92fcSBalaji T K int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) 411b07682b6SSantosh Shilimkar { 412b07682b6SSantosh Shilimkar int ret; 413b07682b6SSantosh Shilimkar u8 val; 414b07682b6SSantosh Shilimkar int sid; 415fc7b92fcSBalaji T K struct twl_client *twl; 416b07682b6SSantosh Shilimkar struct i2c_msg *msg; 417b07682b6SSantosh Shilimkar 418fc7b92fcSBalaji T K if (unlikely(mod_no > TWL_MODULE_LAST)) { 419b07682b6SSantosh Shilimkar pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); 420b07682b6SSantosh Shilimkar return -EPERM; 421b07682b6SSantosh Shilimkar } 422e8deb28cSBalaji T K sid = twl_map[mod_no].sid; 423fc7b92fcSBalaji T K twl = &twl_modules[sid]; 424b07682b6SSantosh Shilimkar 425b07682b6SSantosh Shilimkar if (unlikely(!inuse)) { 426b07682b6SSantosh Shilimkar pr_err("%s: client %d is not initialized\n", DRIVER_NAME, sid); 427b07682b6SSantosh Shilimkar return -EPERM; 428b07682b6SSantosh Shilimkar } 429b07682b6SSantosh Shilimkar mutex_lock(&twl->xfer_lock); 430b07682b6SSantosh Shilimkar /* [MSG1] fill the register address data */ 431b07682b6SSantosh Shilimkar msg = &twl->xfer_msg[0]; 432b07682b6SSantosh Shilimkar msg->addr = twl->address; 433b07682b6SSantosh Shilimkar msg->len = 1; 434b07682b6SSantosh Shilimkar msg->flags = 0; /* Read the register value */ 435e8deb28cSBalaji T K val = twl_map[mod_no].base + reg; 436b07682b6SSantosh Shilimkar msg->buf = &val; 437b07682b6SSantosh Shilimkar /* [MSG2] fill the data rx buffer */ 438b07682b6SSantosh Shilimkar msg = &twl->xfer_msg[1]; 439b07682b6SSantosh Shilimkar msg->addr = twl->address; 440b07682b6SSantosh Shilimkar msg->flags = I2C_M_RD; /* Read the register value */ 441b07682b6SSantosh Shilimkar msg->len = num_bytes; /* only n bytes */ 442b07682b6SSantosh Shilimkar msg->buf = value; 443b07682b6SSantosh Shilimkar ret = i2c_transfer(twl->client->adapter, twl->xfer_msg, 2); 444b07682b6SSantosh Shilimkar mutex_unlock(&twl->xfer_lock); 445b07682b6SSantosh Shilimkar 446b07682b6SSantosh Shilimkar /* i2c_transfer returns number of messages transferred */ 447b07682b6SSantosh Shilimkar if (ret != 2) { 448b07682b6SSantosh Shilimkar pr_err("%s: i2c_read failed to transfer all messages\n", 449b07682b6SSantosh Shilimkar DRIVER_NAME); 450b07682b6SSantosh Shilimkar if (ret < 0) 451b07682b6SSantosh Shilimkar return ret; 452b07682b6SSantosh Shilimkar else 453b07682b6SSantosh Shilimkar return -EIO; 454b07682b6SSantosh Shilimkar } else { 455b07682b6SSantosh Shilimkar return 0; 456b07682b6SSantosh Shilimkar } 457b07682b6SSantosh Shilimkar } 458fc7b92fcSBalaji T K EXPORT_SYMBOL(twl_i2c_read); 459b07682b6SSantosh Shilimkar 460b07682b6SSantosh Shilimkar /** 461fc7b92fcSBalaji T K * twl_i2c_write_u8 - Writes a 8 bit register in TWL4030/TWL5030/TWL60X0 462b07682b6SSantosh Shilimkar * @mod_no: module number 463b07682b6SSantosh Shilimkar * @value: the value to be written 8 bit 464b07682b6SSantosh Shilimkar * @reg: register address (just offset will do) 465b07682b6SSantosh Shilimkar * 466b07682b6SSantosh Shilimkar * Returns result of operation - 0 is success 467b07682b6SSantosh Shilimkar */ 468fc7b92fcSBalaji T K int twl_i2c_write_u8(u8 mod_no, u8 value, u8 reg) 469b07682b6SSantosh Shilimkar { 470b07682b6SSantosh Shilimkar 471b07682b6SSantosh Shilimkar /* 2 bytes offset 1 contains the data offset 0 is used by i2c_write */ 472b07682b6SSantosh Shilimkar u8 temp_buffer[2] = { 0 }; 473b07682b6SSantosh Shilimkar /* offset 1 contains the data */ 474b07682b6SSantosh Shilimkar temp_buffer[1] = value; 475fc7b92fcSBalaji T K return twl_i2c_write(mod_no, temp_buffer, reg, 1); 476b07682b6SSantosh Shilimkar } 477fc7b92fcSBalaji T K EXPORT_SYMBOL(twl_i2c_write_u8); 478b07682b6SSantosh Shilimkar 479b07682b6SSantosh Shilimkar /** 480fc7b92fcSBalaji T K * twl_i2c_read_u8 - Reads a 8 bit register from TWL4030/TWL5030/TWL60X0 481b07682b6SSantosh Shilimkar * @mod_no: module number 482b07682b6SSantosh Shilimkar * @value: the value read 8 bit 483b07682b6SSantosh Shilimkar * @reg: register address (just offset will do) 484b07682b6SSantosh Shilimkar * 485b07682b6SSantosh Shilimkar * Returns result of operation - 0 is success 486b07682b6SSantosh Shilimkar */ 487fc7b92fcSBalaji T K int twl_i2c_read_u8(u8 mod_no, u8 *value, u8 reg) 488b07682b6SSantosh Shilimkar { 489fc7b92fcSBalaji T K return twl_i2c_read(mod_no, value, reg, 1); 490b07682b6SSantosh Shilimkar } 491fc7b92fcSBalaji T K EXPORT_SYMBOL(twl_i2c_read_u8); 492b07682b6SSantosh Shilimkar 493b07682b6SSantosh Shilimkar /*----------------------------------------------------------------------*/ 494b07682b6SSantosh Shilimkar 495ca972d13SLesly A M /** 496ca972d13SLesly A M * twl_read_idcode_register - API to read the IDCODE register. 497ca972d13SLesly A M * 498ca972d13SLesly A M * Unlocks the IDCODE register and read the 32 bit value. 499ca972d13SLesly A M */ 500ca972d13SLesly A M static int twl_read_idcode_register(void) 501ca972d13SLesly A M { 502ca972d13SLesly A M int err; 503ca972d13SLesly A M 504ca972d13SLesly A M err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, TWL_EEPROM_R_UNLOCK, 505ca972d13SLesly A M REG_UNLOCK_TEST_REG); 506ca972d13SLesly A M if (err) { 507ca972d13SLesly A M pr_err("TWL4030 Unable to unlock IDCODE registers -%d\n", err); 508ca972d13SLesly A M goto fail; 509ca972d13SLesly A M } 510ca972d13SLesly A M 511ca972d13SLesly A M err = twl_i2c_read(TWL4030_MODULE_INTBR, (u8 *)(&twl_idcode), 512ca972d13SLesly A M REG_IDCODE_7_0, 4); 513ca972d13SLesly A M if (err) { 514ca972d13SLesly A M pr_err("TWL4030: unable to read IDCODE -%d\n", err); 515ca972d13SLesly A M goto fail; 516ca972d13SLesly A M } 517ca972d13SLesly A M 518ca972d13SLesly A M err = twl_i2c_write_u8(TWL4030_MODULE_INTBR, 0x0, REG_UNLOCK_TEST_REG); 519ca972d13SLesly A M if (err) 520ca972d13SLesly A M pr_err("TWL4030 Unable to relock IDCODE registers -%d\n", err); 521ca972d13SLesly A M fail: 522ca972d13SLesly A M return err; 523ca972d13SLesly A M } 524ca972d13SLesly A M 525ca972d13SLesly A M /** 526ca972d13SLesly A M * twl_get_type - API to get TWL Si type. 527ca972d13SLesly A M * 528ca972d13SLesly A M * Api to get the TWL Si type from IDCODE value. 529ca972d13SLesly A M */ 530ca972d13SLesly A M int twl_get_type(void) 531ca972d13SLesly A M { 532ca972d13SLesly A M return TWL_SIL_TYPE(twl_idcode); 533ca972d13SLesly A M } 534ca972d13SLesly A M EXPORT_SYMBOL_GPL(twl_get_type); 535ca972d13SLesly A M 536ca972d13SLesly A M /** 537ca972d13SLesly A M * twl_get_version - API to get TWL Si version. 538ca972d13SLesly A M * 539ca972d13SLesly A M * Api to get the TWL Si version from IDCODE value. 540ca972d13SLesly A M */ 541ca972d13SLesly A M int twl_get_version(void) 542ca972d13SLesly A M { 543ca972d13SLesly A M return TWL_SIL_REV(twl_idcode); 544ca972d13SLesly A M } 545ca972d13SLesly A M EXPORT_SYMBOL_GPL(twl_get_version); 546ca972d13SLesly A M 547b07682b6SSantosh Shilimkar static struct device * 548b07682b6SSantosh Shilimkar add_numbered_child(unsigned chip, const char *name, int num, 549b07682b6SSantosh Shilimkar void *pdata, unsigned pdata_len, 550b07682b6SSantosh Shilimkar bool can_wakeup, int irq0, int irq1) 551b07682b6SSantosh Shilimkar { 552b07682b6SSantosh Shilimkar struct platform_device *pdev; 553fc7b92fcSBalaji T K struct twl_client *twl = &twl_modules[chip]; 554b07682b6SSantosh Shilimkar int status; 555b07682b6SSantosh Shilimkar 556b07682b6SSantosh Shilimkar pdev = platform_device_alloc(name, num); 557b07682b6SSantosh Shilimkar if (!pdev) { 558b07682b6SSantosh Shilimkar dev_dbg(&twl->client->dev, "can't alloc dev\n"); 559b07682b6SSantosh Shilimkar status = -ENOMEM; 560b07682b6SSantosh Shilimkar goto err; 561b07682b6SSantosh Shilimkar } 562b07682b6SSantosh Shilimkar 563b07682b6SSantosh Shilimkar device_init_wakeup(&pdev->dev, can_wakeup); 564b07682b6SSantosh Shilimkar pdev->dev.parent = &twl->client->dev; 565b07682b6SSantosh Shilimkar 566b07682b6SSantosh Shilimkar if (pdata) { 567b07682b6SSantosh Shilimkar status = platform_device_add_data(pdev, pdata, pdata_len); 568b07682b6SSantosh Shilimkar if (status < 0) { 569b07682b6SSantosh Shilimkar dev_dbg(&pdev->dev, "can't add platform_data\n"); 570b07682b6SSantosh Shilimkar goto err; 571b07682b6SSantosh Shilimkar } 572b07682b6SSantosh Shilimkar } 573b07682b6SSantosh Shilimkar 574b07682b6SSantosh Shilimkar if (irq0) { 575b07682b6SSantosh Shilimkar struct resource r[2] = { 576b07682b6SSantosh Shilimkar { .start = irq0, .flags = IORESOURCE_IRQ, }, 577b07682b6SSantosh Shilimkar { .start = irq1, .flags = IORESOURCE_IRQ, }, 578b07682b6SSantosh Shilimkar }; 579b07682b6SSantosh Shilimkar 580b07682b6SSantosh Shilimkar status = platform_device_add_resources(pdev, r, irq1 ? 2 : 1); 581b07682b6SSantosh Shilimkar if (status < 0) { 582b07682b6SSantosh Shilimkar dev_dbg(&pdev->dev, "can't add irqs\n"); 583b07682b6SSantosh Shilimkar goto err; 584b07682b6SSantosh Shilimkar } 585b07682b6SSantosh Shilimkar } 586b07682b6SSantosh Shilimkar 587b07682b6SSantosh Shilimkar status = platform_device_add(pdev); 588b07682b6SSantosh Shilimkar 589b07682b6SSantosh Shilimkar err: 590b07682b6SSantosh Shilimkar if (status < 0) { 591b07682b6SSantosh Shilimkar platform_device_put(pdev); 592b07682b6SSantosh Shilimkar dev_err(&twl->client->dev, "can't add %s dev\n", name); 593b07682b6SSantosh Shilimkar return ERR_PTR(status); 594b07682b6SSantosh Shilimkar } 595b07682b6SSantosh Shilimkar return &pdev->dev; 596b07682b6SSantosh Shilimkar } 597b07682b6SSantosh Shilimkar 598b07682b6SSantosh Shilimkar static inline struct device *add_child(unsigned chip, const char *name, 599b07682b6SSantosh Shilimkar void *pdata, unsigned pdata_len, 600b07682b6SSantosh Shilimkar bool can_wakeup, int irq0, int irq1) 601b07682b6SSantosh Shilimkar { 602b07682b6SSantosh Shilimkar return add_numbered_child(chip, name, -1, pdata, pdata_len, 603b07682b6SSantosh Shilimkar can_wakeup, irq0, irq1); 604b07682b6SSantosh Shilimkar } 605b07682b6SSantosh Shilimkar 606b07682b6SSantosh Shilimkar static struct device * 607b07682b6SSantosh Shilimkar add_regulator_linked(int num, struct regulator_init_data *pdata, 608b07682b6SSantosh Shilimkar struct regulator_consumer_supply *consumers, 609521d8ec3SGraeme Gregory unsigned num_consumers, unsigned long features) 610b07682b6SSantosh Shilimkar { 611e8deb28cSBalaji T K unsigned sub_chip_id; 612b07682b6SSantosh Shilimkar /* regulator framework demands init_data ... */ 613b07682b6SSantosh Shilimkar if (!pdata) 614b07682b6SSantosh Shilimkar return NULL; 615b07682b6SSantosh Shilimkar 616b07682b6SSantosh Shilimkar if (consumers) { 617b07682b6SSantosh Shilimkar pdata->consumer_supplies = consumers; 618b07682b6SSantosh Shilimkar pdata->num_consumer_supplies = num_consumers; 619b07682b6SSantosh Shilimkar } 620b07682b6SSantosh Shilimkar 621521d8ec3SGraeme Gregory pdata->driver_data = (void *)features; 622521d8ec3SGraeme Gregory 623b07682b6SSantosh Shilimkar /* NOTE: we currently ignore regulator IRQs, e.g. for short circuits */ 624e8deb28cSBalaji T K sub_chip_id = twl_map[TWL_MODULE_PM_MASTER].sid; 625e8deb28cSBalaji T K return add_numbered_child(sub_chip_id, "twl_reg", num, 626b07682b6SSantosh Shilimkar pdata, sizeof(*pdata), false, 0, 0); 627b07682b6SSantosh Shilimkar } 628b07682b6SSantosh Shilimkar 629b07682b6SSantosh Shilimkar static struct device * 630521d8ec3SGraeme Gregory add_regulator(int num, struct regulator_init_data *pdata, 631521d8ec3SGraeme Gregory unsigned long features) 632b07682b6SSantosh Shilimkar { 633521d8ec3SGraeme Gregory return add_regulator_linked(num, pdata, NULL, 0, features); 634b07682b6SSantosh Shilimkar } 635b07682b6SSantosh Shilimkar 636b07682b6SSantosh Shilimkar /* 637b07682b6SSantosh Shilimkar * NOTE: We know the first 8 IRQs after pdata->base_irq are 638b07682b6SSantosh Shilimkar * for the PIH, and the next are for the PWR_INT SIH, since 639b07682b6SSantosh Shilimkar * that's how twl_init_irq() sets things up. 640b07682b6SSantosh Shilimkar */ 641b07682b6SSantosh Shilimkar 642b07682b6SSantosh Shilimkar static int 643b07682b6SSantosh Shilimkar add_children(struct twl4030_platform_data *pdata, unsigned long features) 644b07682b6SSantosh Shilimkar { 645b07682b6SSantosh Shilimkar struct device *child; 646e8deb28cSBalaji T K unsigned sub_chip_id; 647b07682b6SSantosh Shilimkar 648b07682b6SSantosh Shilimkar if (twl_has_gpio() && pdata->gpio) { 649fc7b92fcSBalaji T K child = add_child(SUB_CHIP_ID1, "twl4030_gpio", 650b07682b6SSantosh Shilimkar pdata->gpio, sizeof(*pdata->gpio), 651fc7b92fcSBalaji T K false, pdata->irq_base + GPIO_INTR_OFFSET, 0); 652b07682b6SSantosh Shilimkar if (IS_ERR(child)) 653b07682b6SSantosh Shilimkar return PTR_ERR(child); 654b07682b6SSantosh Shilimkar } 655b07682b6SSantosh Shilimkar 656b07682b6SSantosh Shilimkar if (twl_has_keypad() && pdata->keypad) { 657fc7b92fcSBalaji T K child = add_child(SUB_CHIP_ID2, "twl4030_keypad", 658b07682b6SSantosh Shilimkar pdata->keypad, sizeof(*pdata->keypad), 659fc7b92fcSBalaji T K true, pdata->irq_base + KEYPAD_INTR_OFFSET, 0); 660b07682b6SSantosh Shilimkar if (IS_ERR(child)) 661b07682b6SSantosh Shilimkar return PTR_ERR(child); 662b07682b6SSantosh Shilimkar } 663b07682b6SSantosh Shilimkar 664b07682b6SSantosh Shilimkar if (twl_has_madc() && pdata->madc) { 665b07682b6SSantosh Shilimkar child = add_child(2, "twl4030_madc", 666b07682b6SSantosh Shilimkar pdata->madc, sizeof(*pdata->madc), 667fc7b92fcSBalaji T K true, pdata->irq_base + MADC_INTR_OFFSET, 0); 668b07682b6SSantosh Shilimkar if (IS_ERR(child)) 669b07682b6SSantosh Shilimkar return PTR_ERR(child); 670b07682b6SSantosh Shilimkar } 671b07682b6SSantosh Shilimkar 672b07682b6SSantosh Shilimkar if (twl_has_rtc()) { 673b07682b6SSantosh Shilimkar /* 674b07682b6SSantosh Shilimkar * REVISIT platform_data here currently might expose the 675b07682b6SSantosh Shilimkar * "msecure" line ... but for now we just expect board 676b07682b6SSantosh Shilimkar * setup to tell the chip "it's always ok to SET_TIME". 677b07682b6SSantosh Shilimkar * Eventually, Linux might become more aware of such 678b07682b6SSantosh Shilimkar * HW security concerns, and "least privilege". 679b07682b6SSantosh Shilimkar */ 680e8deb28cSBalaji T K sub_chip_id = twl_map[TWL_MODULE_RTC].sid; 681e8deb28cSBalaji T K child = add_child(sub_chip_id, "twl_rtc", 682b07682b6SSantosh Shilimkar NULL, 0, 683fc7b92fcSBalaji T K true, pdata->irq_base + RTC_INTR_OFFSET, 0); 684b07682b6SSantosh Shilimkar if (IS_ERR(child)) 685b07682b6SSantosh Shilimkar return PTR_ERR(child); 686b07682b6SSantosh Shilimkar } 687b07682b6SSantosh Shilimkar 6889da66539SRajendra Nayak if (twl_has_usb() && pdata->usb && twl_class_is_4030()) { 689b07682b6SSantosh Shilimkar 690b07682b6SSantosh Shilimkar static struct regulator_consumer_supply usb1v5 = { 691b07682b6SSantosh Shilimkar .supply = "usb1v5", 692b07682b6SSantosh Shilimkar }; 693b07682b6SSantosh Shilimkar static struct regulator_consumer_supply usb1v8 = { 694b07682b6SSantosh Shilimkar .supply = "usb1v8", 695b07682b6SSantosh Shilimkar }; 696b07682b6SSantosh Shilimkar static struct regulator_consumer_supply usb3v1 = { 697b07682b6SSantosh Shilimkar .supply = "usb3v1", 698b07682b6SSantosh Shilimkar }; 699b07682b6SSantosh Shilimkar 700b07682b6SSantosh Shilimkar /* First add the regulators so that they can be used by transceiver */ 701b07682b6SSantosh Shilimkar if (twl_has_regulator()) { 702b07682b6SSantosh Shilimkar /* this is a template that gets copied */ 703b07682b6SSantosh Shilimkar struct regulator_init_data usb_fixed = { 704b07682b6SSantosh Shilimkar .constraints.valid_modes_mask = 705b07682b6SSantosh Shilimkar REGULATOR_MODE_NORMAL 706b07682b6SSantosh Shilimkar | REGULATOR_MODE_STANDBY, 707b07682b6SSantosh Shilimkar .constraints.valid_ops_mask = 708b07682b6SSantosh Shilimkar REGULATOR_CHANGE_MODE 709b07682b6SSantosh Shilimkar | REGULATOR_CHANGE_STATUS, 710b07682b6SSantosh Shilimkar }; 711b07682b6SSantosh Shilimkar 712b07682b6SSantosh Shilimkar child = add_regulator_linked(TWL4030_REG_VUSB1V5, 713521d8ec3SGraeme Gregory &usb_fixed, &usb1v5, 1, 714521d8ec3SGraeme Gregory features); 715b07682b6SSantosh Shilimkar if (IS_ERR(child)) 716b07682b6SSantosh Shilimkar return PTR_ERR(child); 717b07682b6SSantosh Shilimkar 718b07682b6SSantosh Shilimkar child = add_regulator_linked(TWL4030_REG_VUSB1V8, 719521d8ec3SGraeme Gregory &usb_fixed, &usb1v8, 1, 720521d8ec3SGraeme Gregory features); 721b07682b6SSantosh Shilimkar if (IS_ERR(child)) 722b07682b6SSantosh Shilimkar return PTR_ERR(child); 723b07682b6SSantosh Shilimkar 724b07682b6SSantosh Shilimkar child = add_regulator_linked(TWL4030_REG_VUSB3V1, 725521d8ec3SGraeme Gregory &usb_fixed, &usb3v1, 1, 726521d8ec3SGraeme Gregory features); 727b07682b6SSantosh Shilimkar if (IS_ERR(child)) 728b07682b6SSantosh Shilimkar return PTR_ERR(child); 729b07682b6SSantosh Shilimkar 730b07682b6SSantosh Shilimkar } 731b07682b6SSantosh Shilimkar 732b07682b6SSantosh Shilimkar child = add_child(0, "twl4030_usb", 733b07682b6SSantosh Shilimkar pdata->usb, sizeof(*pdata->usb), 734b07682b6SSantosh Shilimkar true, 735b07682b6SSantosh Shilimkar /* irq0 = USB_PRES, irq1 = USB */ 736fc7b92fcSBalaji T K pdata->irq_base + USB_PRES_INTR_OFFSET, 737fc7b92fcSBalaji T K pdata->irq_base + USB_INTR_OFFSET); 738b07682b6SSantosh Shilimkar 739b07682b6SSantosh Shilimkar if (IS_ERR(child)) 740b07682b6SSantosh Shilimkar return PTR_ERR(child); 741b07682b6SSantosh Shilimkar 742b07682b6SSantosh Shilimkar /* we need to connect regulators to this transceiver */ 743b07682b6SSantosh Shilimkar if (twl_has_regulator() && child) { 744b07682b6SSantosh Shilimkar usb1v5.dev = child; 745b07682b6SSantosh Shilimkar usb1v8.dev = child; 746b07682b6SSantosh Shilimkar usb3v1.dev = child; 747b07682b6SSantosh Shilimkar } 748b07682b6SSantosh Shilimkar } 749e70357e3SHema HK if (twl_has_usb() && pdata->usb && twl_class_is_6030()) { 750e70357e3SHema HK 751521d8ec3SGraeme Gregory static struct regulator_consumer_supply usb3v3; 752521d8ec3SGraeme Gregory int regulator; 753e70357e3SHema HK 754e70357e3SHema HK if (twl_has_regulator()) { 755e70357e3SHema HK /* this is a template that gets copied */ 756e70357e3SHema HK struct regulator_init_data usb_fixed = { 757e70357e3SHema HK .constraints.valid_modes_mask = 758e70357e3SHema HK REGULATOR_MODE_NORMAL 759e70357e3SHema HK | REGULATOR_MODE_STANDBY, 760e70357e3SHema HK .constraints.valid_ops_mask = 761e70357e3SHema HK REGULATOR_CHANGE_MODE 762e70357e3SHema HK | REGULATOR_CHANGE_STATUS, 763e70357e3SHema HK }; 764e70357e3SHema HK 765521d8ec3SGraeme Gregory if (features & TWL6025_SUBCLASS) { 766521d8ec3SGraeme Gregory usb3v3.supply = "ldousb"; 767521d8ec3SGraeme Gregory regulator = TWL6025_REG_LDOUSB; 768521d8ec3SGraeme Gregory } else { 769521d8ec3SGraeme Gregory usb3v3.supply = "vusb"; 770521d8ec3SGraeme Gregory regulator = TWL6030_REG_VUSB; 771521d8ec3SGraeme Gregory } 772521d8ec3SGraeme Gregory child = add_regulator_linked(regulator, &usb_fixed, 773521d8ec3SGraeme Gregory &usb3v3, 1, 774521d8ec3SGraeme Gregory features); 775e70357e3SHema HK if (IS_ERR(child)) 776e70357e3SHema HK return PTR_ERR(child); 777e70357e3SHema HK } 778e70357e3SHema HK 779521d8ec3SGraeme Gregory pdata->usb->features = features; 780521d8ec3SGraeme Gregory 781e70357e3SHema HK child = add_child(0, "twl6030_usb", 782e70357e3SHema HK pdata->usb, sizeof(*pdata->usb), 783e70357e3SHema HK true, 784e70357e3SHema HK /* irq1 = VBUS_PRES, irq0 = USB ID */ 785e70357e3SHema HK pdata->irq_base + USBOTG_INTR_OFFSET, 786e70357e3SHema HK pdata->irq_base + USB_PRES_INTR_OFFSET); 787e70357e3SHema HK 788e70357e3SHema HK if (IS_ERR(child)) 789e70357e3SHema HK return PTR_ERR(child); 790e70357e3SHema HK /* we need to connect regulators to this transceiver */ 791e70357e3SHema HK if (twl_has_regulator() && child) 792e70357e3SHema HK usb3v3.dev = child; 793521d8ec3SGraeme Gregory } else if (twl_has_regulator() && twl_class_is_6030()) { 794521d8ec3SGraeme Gregory if (features & TWL6025_SUBCLASS) 795521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDOUSB, 796521d8ec3SGraeme Gregory pdata->ldousb, features); 797521d8ec3SGraeme Gregory else 798521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VUSB, 799521d8ec3SGraeme Gregory pdata->vusb, features); 800e70357e3SHema HK 801521d8ec3SGraeme Gregory if (IS_ERR(child)) 802521d8ec3SGraeme Gregory return PTR_ERR(child); 803e70357e3SHema HK } 804b07682b6SSantosh Shilimkar 805153617fdSKeerthy if (twl_has_watchdog() && twl_class_is_4030()) { 806b07682b6SSantosh Shilimkar child = add_child(0, "twl4030_wdt", NULL, 0, false, 0, 0); 807b07682b6SSantosh Shilimkar if (IS_ERR(child)) 808b07682b6SSantosh Shilimkar return PTR_ERR(child); 809b07682b6SSantosh Shilimkar } 810b07682b6SSantosh Shilimkar 811153617fdSKeerthy if (twl_has_pwrbutton() && twl_class_is_4030()) { 812b07682b6SSantosh Shilimkar child = add_child(1, "twl4030_pwrbutton", 813b07682b6SSantosh Shilimkar NULL, 0, true, pdata->irq_base + 8 + 0, 0); 814b07682b6SSantosh Shilimkar if (IS_ERR(child)) 815b07682b6SSantosh Shilimkar return PTR_ERR(child); 816b07682b6SSantosh Shilimkar } 817b07682b6SSantosh Shilimkar 8184ae6df5eSPeter Ujfalusi if (twl_has_codec() && pdata->audio && twl_class_is_4030()) { 819d62abe56SMisael Lopez Cruz sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid; 820f0fba2adSLiam Girdwood child = add_child(sub_chip_id, "twl4030-audio", 8214ae6df5eSPeter Ujfalusi pdata->audio, sizeof(*pdata->audio), 822d62abe56SMisael Lopez Cruz false, 0, 0); 823d62abe56SMisael Lopez Cruz if (IS_ERR(child)) 824d62abe56SMisael Lopez Cruz return PTR_ERR(child); 825d62abe56SMisael Lopez Cruz } 826d62abe56SMisael Lopez Cruz 8274ae6df5eSPeter Ujfalusi if (twl_has_codec() && pdata->audio && twl_class_is_6030()) { 828d62abe56SMisael Lopez Cruz sub_chip_id = twl_map[TWL_MODULE_AUDIO_VOICE].sid; 829f19b2823SMisael Lopez Cruz child = add_child(sub_chip_id, "twl6040", 8304ae6df5eSPeter Ujfalusi pdata->audio, sizeof(*pdata->audio), 831b07682b6SSantosh Shilimkar false, 0, 0); 832b07682b6SSantosh Shilimkar if (IS_ERR(child)) 833b07682b6SSantosh Shilimkar return PTR_ERR(child); 834b07682b6SSantosh Shilimkar } 835b07682b6SSantosh Shilimkar 8369da66539SRajendra Nayak /* twl4030 regulators */ 8379da66539SRajendra Nayak if (twl_has_regulator() && twl_class_is_4030()) { 838521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VPLL1, pdata->vpll1, 839521d8ec3SGraeme Gregory features); 840b07682b6SSantosh Shilimkar if (IS_ERR(child)) 841b07682b6SSantosh Shilimkar return PTR_ERR(child); 842b07682b6SSantosh Shilimkar 843521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VIO, pdata->vio, 844521d8ec3SGraeme Gregory features); 845b07682b6SSantosh Shilimkar if (IS_ERR(child)) 846b07682b6SSantosh Shilimkar return PTR_ERR(child); 847b07682b6SSantosh Shilimkar 848521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VDD1, pdata->vdd1, 849521d8ec3SGraeme Gregory features); 850b07682b6SSantosh Shilimkar if (IS_ERR(child)) 851b07682b6SSantosh Shilimkar return PTR_ERR(child); 852b07682b6SSantosh Shilimkar 853521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VDD2, pdata->vdd2, 854521d8ec3SGraeme Gregory features); 855b07682b6SSantosh Shilimkar if (IS_ERR(child)) 856b07682b6SSantosh Shilimkar return PTR_ERR(child); 857b07682b6SSantosh Shilimkar 858521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VMMC1, pdata->vmmc1, 859521d8ec3SGraeme Gregory features); 860b07682b6SSantosh Shilimkar if (IS_ERR(child)) 861b07682b6SSantosh Shilimkar return PTR_ERR(child); 862b07682b6SSantosh Shilimkar 863521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VDAC, pdata->vdac, 864521d8ec3SGraeme Gregory features); 865b07682b6SSantosh Shilimkar if (IS_ERR(child)) 866b07682b6SSantosh Shilimkar return PTR_ERR(child); 867b07682b6SSantosh Shilimkar 868b07682b6SSantosh Shilimkar child = add_regulator((features & TWL4030_VAUX2) 869b07682b6SSantosh Shilimkar ? TWL4030_REG_VAUX2_4030 870b07682b6SSantosh Shilimkar : TWL4030_REG_VAUX2, 871521d8ec3SGraeme Gregory pdata->vaux2, features); 872b07682b6SSantosh Shilimkar if (IS_ERR(child)) 873b07682b6SSantosh Shilimkar return PTR_ERR(child); 874b07682b6SSantosh Shilimkar 875521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VINTANA1, pdata->vintana1, 876521d8ec3SGraeme Gregory features); 877b07682b6SSantosh Shilimkar if (IS_ERR(child)) 878b07682b6SSantosh Shilimkar return PTR_ERR(child); 879b07682b6SSantosh Shilimkar 880521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VINTANA2, pdata->vintana2, 881521d8ec3SGraeme Gregory features); 882b07682b6SSantosh Shilimkar if (IS_ERR(child)) 883b07682b6SSantosh Shilimkar return PTR_ERR(child); 884b07682b6SSantosh Shilimkar 885521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VINTDIG, pdata->vintdig, 886521d8ec3SGraeme Gregory features); 887b07682b6SSantosh Shilimkar if (IS_ERR(child)) 888b07682b6SSantosh Shilimkar return PTR_ERR(child); 889b07682b6SSantosh Shilimkar } 890b07682b6SSantosh Shilimkar 891b07682b6SSantosh Shilimkar /* maybe add LDOs that are omitted on cost-reduced parts */ 8929da66539SRajendra Nayak if (twl_has_regulator() && !(features & TPS_SUBSET) 8939da66539SRajendra Nayak && twl_class_is_4030()) { 894521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VPLL2, pdata->vpll2, 895521d8ec3SGraeme Gregory features); 896b07682b6SSantosh Shilimkar if (IS_ERR(child)) 897b07682b6SSantosh Shilimkar return PTR_ERR(child); 898b07682b6SSantosh Shilimkar 899521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VMMC2, pdata->vmmc2, 900521d8ec3SGraeme Gregory features); 901b07682b6SSantosh Shilimkar if (IS_ERR(child)) 902b07682b6SSantosh Shilimkar return PTR_ERR(child); 903b07682b6SSantosh Shilimkar 904521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VSIM, pdata->vsim, 905521d8ec3SGraeme Gregory features); 906b07682b6SSantosh Shilimkar if (IS_ERR(child)) 907b07682b6SSantosh Shilimkar return PTR_ERR(child); 908b07682b6SSantosh Shilimkar 909521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VAUX1, pdata->vaux1, 910521d8ec3SGraeme Gregory features); 911b07682b6SSantosh Shilimkar if (IS_ERR(child)) 912b07682b6SSantosh Shilimkar return PTR_ERR(child); 913b07682b6SSantosh Shilimkar 914521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VAUX3, pdata->vaux3, 915521d8ec3SGraeme Gregory features); 916b07682b6SSantosh Shilimkar if (IS_ERR(child)) 917b07682b6SSantosh Shilimkar return PTR_ERR(child); 918b07682b6SSantosh Shilimkar 919521d8ec3SGraeme Gregory child = add_regulator(TWL4030_REG_VAUX4, pdata->vaux4, 920521d8ec3SGraeme Gregory features); 921b07682b6SSantosh Shilimkar if (IS_ERR(child)) 922b07682b6SSantosh Shilimkar return PTR_ERR(child); 923b07682b6SSantosh Shilimkar } 924b07682b6SSantosh Shilimkar 9259da66539SRajendra Nayak /* twl6030 regulators */ 926521d8ec3SGraeme Gregory if (twl_has_regulator() && twl_class_is_6030() && 927521d8ec3SGraeme Gregory !(features & TWL6025_SUBCLASS)) { 928521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VMMC, pdata->vmmc, 929521d8ec3SGraeme Gregory features); 930521d8ec3SGraeme Gregory if (IS_ERR(child)) 931521d8ec3SGraeme Gregory return PTR_ERR(child); 932521d8ec3SGraeme Gregory 933521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VPP, pdata->vpp, 934521d8ec3SGraeme Gregory features); 935521d8ec3SGraeme Gregory if (IS_ERR(child)) 936521d8ec3SGraeme Gregory return PTR_ERR(child); 937521d8ec3SGraeme Gregory 938521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VUSIM, pdata->vusim, 939521d8ec3SGraeme Gregory features); 940521d8ec3SGraeme Gregory if (IS_ERR(child)) 941521d8ec3SGraeme Gregory return PTR_ERR(child); 942521d8ec3SGraeme Gregory 943521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VCXIO, pdata->vcxio, 944521d8ec3SGraeme Gregory features); 945521d8ec3SGraeme Gregory if (IS_ERR(child)) 946521d8ec3SGraeme Gregory return PTR_ERR(child); 947521d8ec3SGraeme Gregory 948521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VDAC, pdata->vdac, 949521d8ec3SGraeme Gregory features); 950521d8ec3SGraeme Gregory if (IS_ERR(child)) 951521d8ec3SGraeme Gregory return PTR_ERR(child); 952521d8ec3SGraeme Gregory 953521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VAUX1_6030, pdata->vaux1, 954521d8ec3SGraeme Gregory features); 955521d8ec3SGraeme Gregory if (IS_ERR(child)) 956521d8ec3SGraeme Gregory return PTR_ERR(child); 957521d8ec3SGraeme Gregory 958521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VAUX2_6030, pdata->vaux2, 959521d8ec3SGraeme Gregory features); 960521d8ec3SGraeme Gregory if (IS_ERR(child)) 961521d8ec3SGraeme Gregory return PTR_ERR(child); 962521d8ec3SGraeme Gregory 963521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VAUX3_6030, pdata->vaux3, 964521d8ec3SGraeme Gregory features); 965521d8ec3SGraeme Gregory if (IS_ERR(child)) 966521d8ec3SGraeme Gregory return PTR_ERR(child); 967521d8ec3SGraeme Gregory 968521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_CLK32KG, pdata->clk32kg, 969521d8ec3SGraeme Gregory features); 970521d8ec3SGraeme Gregory if (IS_ERR(child)) 971521d8ec3SGraeme Gregory return PTR_ERR(child); 972521d8ec3SGraeme Gregory } 973521d8ec3SGraeme Gregory 974521d8ec3SGraeme Gregory /* 6030 and 6025 share this regulator */ 9759da66539SRajendra Nayak if (twl_has_regulator() && twl_class_is_6030()) { 976521d8ec3SGraeme Gregory child = add_regulator(TWL6030_REG_VANA, pdata->vana, 977521d8ec3SGraeme Gregory features); 978521d8ec3SGraeme Gregory if (IS_ERR(child)) 979521d8ec3SGraeme Gregory return PTR_ERR(child); 980521d8ec3SGraeme Gregory } 981521d8ec3SGraeme Gregory 982521d8ec3SGraeme Gregory /* twl6025 regulators */ 983521d8ec3SGraeme Gregory if (twl_has_regulator() && twl_class_is_6030() && 984521d8ec3SGraeme Gregory (features & TWL6025_SUBCLASS)) { 985521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO5, pdata->ldo5, 986521d8ec3SGraeme Gregory features); 9879da66539SRajendra Nayak if (IS_ERR(child)) 9889da66539SRajendra Nayak return PTR_ERR(child); 9899da66539SRajendra Nayak 990521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO1, pdata->ldo1, 991521d8ec3SGraeme Gregory features); 9929da66539SRajendra Nayak if (IS_ERR(child)) 9939da66539SRajendra Nayak return PTR_ERR(child); 9949da66539SRajendra Nayak 995521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO7, pdata->ldo7, 996521d8ec3SGraeme Gregory features); 9979da66539SRajendra Nayak if (IS_ERR(child)) 9989da66539SRajendra Nayak return PTR_ERR(child); 9999da66539SRajendra Nayak 1000521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO6, pdata->ldo6, 1001521d8ec3SGraeme Gregory features); 10029da66539SRajendra Nayak if (IS_ERR(child)) 10039da66539SRajendra Nayak return PTR_ERR(child); 10049da66539SRajendra Nayak 1005521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDOLN, pdata->ldoln, 1006521d8ec3SGraeme Gregory features); 10079da66539SRajendra Nayak if (IS_ERR(child)) 10089da66539SRajendra Nayak return PTR_ERR(child); 10099da66539SRajendra Nayak 1010521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO2, pdata->ldo2, 1011521d8ec3SGraeme Gregory features); 10129da66539SRajendra Nayak if (IS_ERR(child)) 10139da66539SRajendra Nayak return PTR_ERR(child); 10149da66539SRajendra Nayak 1015521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO4, pdata->ldo4, 1016521d8ec3SGraeme Gregory features); 10179da66539SRajendra Nayak if (IS_ERR(child)) 10189da66539SRajendra Nayak return PTR_ERR(child); 10199da66539SRajendra Nayak 1020521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_LDO3, pdata->ldo3, 1021521d8ec3SGraeme Gregory features); 10229da66539SRajendra Nayak if (IS_ERR(child)) 10239da66539SRajendra Nayak return PTR_ERR(child); 10249da66539SRajendra Nayak 1025521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_SMPS3, pdata->smps3, 1026521d8ec3SGraeme Gregory features); 10279da66539SRajendra Nayak if (IS_ERR(child)) 10289da66539SRajendra Nayak return PTR_ERR(child); 10298e6de4a3SBalaji T K 1030521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_SMPS4, pdata->smps4, 1031521d8ec3SGraeme Gregory features); 10328e6de4a3SBalaji T K if (IS_ERR(child)) 10338e6de4a3SBalaji T K return PTR_ERR(child); 1034521d8ec3SGraeme Gregory 1035521d8ec3SGraeme Gregory child = add_regulator(TWL6025_REG_VIO, pdata->vio6025, 1036521d8ec3SGraeme Gregory features); 1037521d8ec3SGraeme Gregory if (IS_ERR(child)) 1038521d8ec3SGraeme Gregory return PTR_ERR(child); 1039521d8ec3SGraeme Gregory 10409da66539SRajendra Nayak } 10419da66539SRajendra Nayak 104211c39c4bSGrazvydas Ignotas if (twl_has_bci() && pdata->bci && 104311c39c4bSGrazvydas Ignotas !(features & (TPS_SUBSET | TWL5031))) { 104411c39c4bSGrazvydas Ignotas child = add_child(3, "twl4030_bci", 104511c39c4bSGrazvydas Ignotas pdata->bci, sizeof(*pdata->bci), false, 104611c39c4bSGrazvydas Ignotas /* irq0 = CHG_PRES, irq1 = BCI */ 104711c39c4bSGrazvydas Ignotas pdata->irq_base + BCI_PRES_INTR_OFFSET, 104811c39c4bSGrazvydas Ignotas pdata->irq_base + BCI_INTR_OFFSET); 104911c39c4bSGrazvydas Ignotas if (IS_ERR(child)) 105011c39c4bSGrazvydas Ignotas return PTR_ERR(child); 105111c39c4bSGrazvydas Ignotas } 105211c39c4bSGrazvydas Ignotas 1053b07682b6SSantosh Shilimkar return 0; 1054b07682b6SSantosh Shilimkar } 1055b07682b6SSantosh Shilimkar 1056b07682b6SSantosh Shilimkar /*----------------------------------------------------------------------*/ 1057b07682b6SSantosh Shilimkar 1058b07682b6SSantosh Shilimkar /* 1059b07682b6SSantosh Shilimkar * These three functions initialize the on-chip clock framework, 1060b07682b6SSantosh Shilimkar * letting it generate the right frequencies for USB, MADC, and 1061b07682b6SSantosh Shilimkar * other purposes. 1062b07682b6SSantosh Shilimkar */ 1063b07682b6SSantosh Shilimkar static inline int __init protect_pm_master(void) 1064b07682b6SSantosh Shilimkar { 1065b07682b6SSantosh Shilimkar int e = 0; 1066b07682b6SSantosh Shilimkar 106749e6f87eSFelipe Balbi e = twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, 106849e6f87eSFelipe Balbi TWL4030_PM_MASTER_PROTECT_KEY); 1069b07682b6SSantosh Shilimkar return e; 1070b07682b6SSantosh Shilimkar } 1071b07682b6SSantosh Shilimkar 1072b07682b6SSantosh Shilimkar static inline int __init unprotect_pm_master(void) 1073b07682b6SSantosh Shilimkar { 1074b07682b6SSantosh Shilimkar int e = 0; 1075b07682b6SSantosh Shilimkar 107649e6f87eSFelipe Balbi e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 107749e6f87eSFelipe Balbi TWL4030_PM_MASTER_KEY_CFG1, 107849e6f87eSFelipe Balbi TWL4030_PM_MASTER_PROTECT_KEY); 107949e6f87eSFelipe Balbi e |= twl_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 108049e6f87eSFelipe Balbi TWL4030_PM_MASTER_KEY_CFG2, 108149e6f87eSFelipe Balbi TWL4030_PM_MASTER_PROTECT_KEY); 108249e6f87eSFelipe Balbi 1083b07682b6SSantosh Shilimkar return e; 1084b07682b6SSantosh Shilimkar } 1085b07682b6SSantosh Shilimkar 1086b07682b6SSantosh Shilimkar static void clocks_init(struct device *dev, 1087b07682b6SSantosh Shilimkar struct twl4030_clock_init_data *clock) 1088b07682b6SSantosh Shilimkar { 1089b07682b6SSantosh Shilimkar int e = 0; 1090b07682b6SSantosh Shilimkar struct clk *osc; 1091b07682b6SSantosh Shilimkar u32 rate; 1092b07682b6SSantosh Shilimkar u8 ctrl = HFCLK_FREQ_26_MHZ; 1093b07682b6SSantosh Shilimkar 1094b07682b6SSantosh Shilimkar #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) 1095b07682b6SSantosh Shilimkar if (cpu_is_omap2430()) 1096b07682b6SSantosh Shilimkar osc = clk_get(dev, "osc_ck"); 1097b07682b6SSantosh Shilimkar else 1098b07682b6SSantosh Shilimkar osc = clk_get(dev, "osc_sys_ck"); 1099b07682b6SSantosh Shilimkar 1100b07682b6SSantosh Shilimkar if (IS_ERR(osc)) { 1101fc7b92fcSBalaji T K printk(KERN_WARNING "Skipping twl internal clock init and " 1102b07682b6SSantosh Shilimkar "using bootloader value (unknown osc rate)\n"); 1103b07682b6SSantosh Shilimkar return; 1104b07682b6SSantosh Shilimkar } 1105b07682b6SSantosh Shilimkar 1106b07682b6SSantosh Shilimkar rate = clk_get_rate(osc); 1107b07682b6SSantosh Shilimkar clk_put(osc); 1108b07682b6SSantosh Shilimkar 1109b07682b6SSantosh Shilimkar #else 1110b07682b6SSantosh Shilimkar /* REVISIT for non-OMAP systems, pass the clock rate from 1111b07682b6SSantosh Shilimkar * board init code, using platform_data. 1112b07682b6SSantosh Shilimkar */ 1113b07682b6SSantosh Shilimkar osc = ERR_PTR(-EIO); 1114b07682b6SSantosh Shilimkar 1115fc7b92fcSBalaji T K printk(KERN_WARNING "Skipping twl internal clock init and " 1116b07682b6SSantosh Shilimkar "using bootloader value (unknown osc rate)\n"); 1117b07682b6SSantosh Shilimkar 1118b07682b6SSantosh Shilimkar return; 1119b07682b6SSantosh Shilimkar #endif 1120b07682b6SSantosh Shilimkar 1121b07682b6SSantosh Shilimkar switch (rate) { 1122b07682b6SSantosh Shilimkar case 19200000: 1123b07682b6SSantosh Shilimkar ctrl = HFCLK_FREQ_19p2_MHZ; 1124b07682b6SSantosh Shilimkar break; 1125b07682b6SSantosh Shilimkar case 26000000: 1126b07682b6SSantosh Shilimkar ctrl = HFCLK_FREQ_26_MHZ; 1127b07682b6SSantosh Shilimkar break; 1128b07682b6SSantosh Shilimkar case 38400000: 1129b07682b6SSantosh Shilimkar ctrl = HFCLK_FREQ_38p4_MHZ; 1130b07682b6SSantosh Shilimkar break; 1131b07682b6SSantosh Shilimkar } 1132b07682b6SSantosh Shilimkar 1133b07682b6SSantosh Shilimkar ctrl |= HIGH_PERF_SQ; 1134b07682b6SSantosh Shilimkar if (clock && clock->ck32k_lowpwr_enable) 1135b07682b6SSantosh Shilimkar ctrl |= CK32K_LOWPWR_EN; 1136b07682b6SSantosh Shilimkar 1137b07682b6SSantosh Shilimkar e |= unprotect_pm_master(); 1138b07682b6SSantosh Shilimkar /* effect->MADC+USB ck en */ 1139fc7b92fcSBalaji T K e |= twl_i2c_write_u8(TWL_MODULE_PM_MASTER, ctrl, R_CFG_BOOT); 1140b07682b6SSantosh Shilimkar e |= protect_pm_master(); 1141b07682b6SSantosh Shilimkar 1142b07682b6SSantosh Shilimkar if (e < 0) 1143b07682b6SSantosh Shilimkar pr_err("%s: clock init err [%d]\n", DRIVER_NAME, e); 1144b07682b6SSantosh Shilimkar } 1145b07682b6SSantosh Shilimkar 1146b07682b6SSantosh Shilimkar /*----------------------------------------------------------------------*/ 1147b07682b6SSantosh Shilimkar 1148e8deb28cSBalaji T K int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end); 1149e8deb28cSBalaji T K int twl4030_exit_irq(void); 1150e8deb28cSBalaji T K int twl4030_init_chip_irq(const char *chip); 1151e8deb28cSBalaji T K int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end); 1152e8deb28cSBalaji T K int twl6030_exit_irq(void); 1153b07682b6SSantosh Shilimkar 1154fc7b92fcSBalaji T K static int twl_remove(struct i2c_client *client) 1155b07682b6SSantosh Shilimkar { 1156b07682b6SSantosh Shilimkar unsigned i; 1157b07682b6SSantosh Shilimkar int status; 1158b07682b6SSantosh Shilimkar 1159e8deb28cSBalaji T K if (twl_class_is_4030()) 1160e8deb28cSBalaji T K status = twl4030_exit_irq(); 1161e8deb28cSBalaji T K else 1162e8deb28cSBalaji T K status = twl6030_exit_irq(); 1163e8deb28cSBalaji T K 1164b07682b6SSantosh Shilimkar if (status < 0) 1165b07682b6SSantosh Shilimkar return status; 1166b07682b6SSantosh Shilimkar 1167fc7b92fcSBalaji T K for (i = 0; i < TWL_NUM_SLAVES; i++) { 1168fc7b92fcSBalaji T K struct twl_client *twl = &twl_modules[i]; 1169b07682b6SSantosh Shilimkar 1170b07682b6SSantosh Shilimkar if (twl->client && twl->client != client) 1171b07682b6SSantosh Shilimkar i2c_unregister_device(twl->client); 1172fc7b92fcSBalaji T K twl_modules[i].client = NULL; 1173b07682b6SSantosh Shilimkar } 1174b07682b6SSantosh Shilimkar inuse = false; 1175b07682b6SSantosh Shilimkar return 0; 1176b07682b6SSantosh Shilimkar } 1177b07682b6SSantosh Shilimkar 1178b07682b6SSantosh Shilimkar /* NOTE: this driver only handles a single twl4030/tps659x0 chip */ 11795b9cecd6SBryan Wu static int __devinit 1180fc7b92fcSBalaji T K twl_probe(struct i2c_client *client, const struct i2c_device_id *id) 1181b07682b6SSantosh Shilimkar { 1182b07682b6SSantosh Shilimkar int status; 1183b07682b6SSantosh Shilimkar unsigned i; 1184b07682b6SSantosh Shilimkar struct twl4030_platform_data *pdata = client->dev.platform_data; 1185a29aaf55SMoiz Sonasath u8 temp; 1186ca972d13SLesly A M int ret = 0; 1187b07682b6SSantosh Shilimkar 1188b07682b6SSantosh Shilimkar if (!pdata) { 1189b07682b6SSantosh Shilimkar dev_dbg(&client->dev, "no platform data?\n"); 1190b07682b6SSantosh Shilimkar return -EINVAL; 1191b07682b6SSantosh Shilimkar } 1192b07682b6SSantosh Shilimkar 1193b07682b6SSantosh Shilimkar if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { 1194b07682b6SSantosh Shilimkar dev_dbg(&client->dev, "can't talk I2C?\n"); 1195b07682b6SSantosh Shilimkar return -EIO; 1196b07682b6SSantosh Shilimkar } 1197b07682b6SSantosh Shilimkar 1198b07682b6SSantosh Shilimkar if (inuse) { 1199b07682b6SSantosh Shilimkar dev_dbg(&client->dev, "driver is already in use\n"); 1200b07682b6SSantosh Shilimkar return -EBUSY; 1201b07682b6SSantosh Shilimkar } 1202b07682b6SSantosh Shilimkar 1203fc7b92fcSBalaji T K for (i = 0; i < TWL_NUM_SLAVES; i++) { 1204fc7b92fcSBalaji T K struct twl_client *twl = &twl_modules[i]; 1205b07682b6SSantosh Shilimkar 1206b07682b6SSantosh Shilimkar twl->address = client->addr + i; 1207b07682b6SSantosh Shilimkar if (i == 0) 1208b07682b6SSantosh Shilimkar twl->client = client; 1209b07682b6SSantosh Shilimkar else { 1210b07682b6SSantosh Shilimkar twl->client = i2c_new_dummy(client->adapter, 1211b07682b6SSantosh Shilimkar twl->address); 1212b07682b6SSantosh Shilimkar if (!twl->client) { 1213b07682b6SSantosh Shilimkar dev_err(&client->dev, 1214b07682b6SSantosh Shilimkar "can't attach client %d\n", i); 1215b07682b6SSantosh Shilimkar status = -ENOMEM; 1216b07682b6SSantosh Shilimkar goto fail; 1217b07682b6SSantosh Shilimkar } 1218b07682b6SSantosh Shilimkar } 1219b07682b6SSantosh Shilimkar mutex_init(&twl->xfer_lock); 1220b07682b6SSantosh Shilimkar } 1221b07682b6SSantosh Shilimkar inuse = true; 1222e8deb28cSBalaji T K if ((id->driver_data) & TWL6030_CLASS) { 1223e8deb28cSBalaji T K twl_id = TWL6030_CLASS_ID; 1224e8deb28cSBalaji T K twl_map = &twl6030_map[0]; 1225e8deb28cSBalaji T K } else { 1226e8deb28cSBalaji T K twl_id = TWL4030_CLASS_ID; 1227e8deb28cSBalaji T K twl_map = &twl4030_map[0]; 1228e8deb28cSBalaji T K } 1229b07682b6SSantosh Shilimkar 1230b07682b6SSantosh Shilimkar /* setup clock framework */ 1231b07682b6SSantosh Shilimkar clocks_init(&client->dev, pdata->clock); 1232b07682b6SSantosh Shilimkar 1233ca972d13SLesly A M /* read TWL IDCODE Register */ 1234ca972d13SLesly A M if (twl_id == TWL4030_CLASS_ID) { 1235ca972d13SLesly A M ret = twl_read_idcode_register(); 1236ca972d13SLesly A M WARN(ret < 0, "Error: reading twl_idcode register value\n"); 1237ca972d13SLesly A M } 1238ca972d13SLesly A M 1239b07682b6SSantosh Shilimkar /* load power event scripts */ 1240b07682b6SSantosh Shilimkar if (twl_has_power() && pdata->power) 1241b07682b6SSantosh Shilimkar twl4030_power_init(pdata->power); 1242b07682b6SSantosh Shilimkar 1243b07682b6SSantosh Shilimkar /* Maybe init the T2 Interrupt subsystem */ 1244b07682b6SSantosh Shilimkar if (client->irq 1245b07682b6SSantosh Shilimkar && pdata->irq_base 1246b07682b6SSantosh Shilimkar && pdata->irq_end > pdata->irq_base) { 1247e8deb28cSBalaji T K if (twl_class_is_4030()) { 1248e8deb28cSBalaji T K twl4030_init_chip_irq(id->name); 1249e8deb28cSBalaji T K status = twl4030_init_irq(client->irq, pdata->irq_base, 1250e8deb28cSBalaji T K pdata->irq_end); 1251e8deb28cSBalaji T K } else { 1252e8deb28cSBalaji T K status = twl6030_init_irq(client->irq, pdata->irq_base, 1253e8deb28cSBalaji T K pdata->irq_end); 1254e8deb28cSBalaji T K } 1255e8deb28cSBalaji T K 1256b07682b6SSantosh Shilimkar if (status < 0) 1257b07682b6SSantosh Shilimkar goto fail; 1258b07682b6SSantosh Shilimkar } 1259b07682b6SSantosh Shilimkar 1260a29aaf55SMoiz Sonasath /* Disable TWL4030/TWL5030 I2C Pull-up on I2C1 and I2C4(SR) interface. 1261a29aaf55SMoiz Sonasath * Program I2C_SCL_CTRL_PU(bit 0)=0, I2C_SDA_CTRL_PU (bit 2)=0, 1262a29aaf55SMoiz Sonasath * SR_I2C_SCL_CTRL_PU(bit 4)=0 and SR_I2C_SDA_CTRL_PU(bit 6)=0. 1263a29aaf55SMoiz Sonasath */ 1264a29aaf55SMoiz Sonasath 1265a29aaf55SMoiz Sonasath if (twl_class_is_4030()) { 1266a29aaf55SMoiz Sonasath twl_i2c_read_u8(TWL4030_MODULE_INTBR, &temp, REG_GPPUPDCTR1); 1267a29aaf55SMoiz Sonasath temp &= ~(SR_I2C_SDA_CTRL_PU | SR_I2C_SCL_CTRL_PU | \ 1268a29aaf55SMoiz Sonasath I2C_SDA_CTRL_PU | I2C_SCL_CTRL_PU); 1269a29aaf55SMoiz Sonasath twl_i2c_write_u8(TWL4030_MODULE_INTBR, temp, REG_GPPUPDCTR1); 1270a29aaf55SMoiz Sonasath } 1271a29aaf55SMoiz Sonasath 1272b07682b6SSantosh Shilimkar status = add_children(pdata, id->driver_data); 1273b07682b6SSantosh Shilimkar fail: 1274b07682b6SSantosh Shilimkar if (status < 0) 1275fc7b92fcSBalaji T K twl_remove(client); 1276b07682b6SSantosh Shilimkar return status; 1277b07682b6SSantosh Shilimkar } 1278b07682b6SSantosh Shilimkar 1279fc7b92fcSBalaji T K static const struct i2c_device_id twl_ids[] = { 1280b07682b6SSantosh Shilimkar { "twl4030", TWL4030_VAUX2 }, /* "Triton 2" */ 1281b07682b6SSantosh Shilimkar { "twl5030", 0 }, /* T2 updated */ 1282b07682b6SSantosh Shilimkar { "twl5031", TWL5031 }, /* TWL5030 updated */ 1283b07682b6SSantosh Shilimkar { "tps65950", 0 }, /* catalog version of twl5030 */ 1284b07682b6SSantosh Shilimkar { "tps65930", TPS_SUBSET }, /* fewer LDOs and DACs; no charger */ 1285b07682b6SSantosh Shilimkar { "tps65920", TPS_SUBSET }, /* fewer LDOs; no codec or charger */ 1286e8deb28cSBalaji T K { "twl6030", TWL6030_CLASS }, /* "Phoenix power chip" */ 1287521d8ec3SGraeme Gregory { "twl6025", TWL6030_CLASS | TWL6025_SUBCLASS }, /* "Phoenix lite" */ 1288b07682b6SSantosh Shilimkar { /* end of list */ }, 1289b07682b6SSantosh Shilimkar }; 1290fc7b92fcSBalaji T K MODULE_DEVICE_TABLE(i2c, twl_ids); 1291b07682b6SSantosh Shilimkar 1292b07682b6SSantosh Shilimkar /* One Client Driver , 4 Clients */ 1293fc7b92fcSBalaji T K static struct i2c_driver twl_driver = { 1294b07682b6SSantosh Shilimkar .driver.name = DRIVER_NAME, 1295fc7b92fcSBalaji T K .id_table = twl_ids, 1296fc7b92fcSBalaji T K .probe = twl_probe, 1297fc7b92fcSBalaji T K .remove = twl_remove, 1298b07682b6SSantosh Shilimkar }; 1299b07682b6SSantosh Shilimkar 1300fc7b92fcSBalaji T K static int __init twl_init(void) 1301b07682b6SSantosh Shilimkar { 1302fc7b92fcSBalaji T K return i2c_add_driver(&twl_driver); 1303b07682b6SSantosh Shilimkar } 1304fc7b92fcSBalaji T K subsys_initcall(twl_init); 1305b07682b6SSantosh Shilimkar 1306fc7b92fcSBalaji T K static void __exit twl_exit(void) 1307b07682b6SSantosh Shilimkar { 1308fc7b92fcSBalaji T K i2c_del_driver(&twl_driver); 1309b07682b6SSantosh Shilimkar } 1310fc7b92fcSBalaji T K module_exit(twl_exit); 1311b07682b6SSantosh Shilimkar 1312b07682b6SSantosh Shilimkar MODULE_AUTHOR("Texas Instruments, Inc."); 1313fc7b92fcSBalaji T K MODULE_DESCRIPTION("I2C Core interface for TWL"); 1314b07682b6SSantosh Shilimkar MODULE_LICENSE("GPL"); 1315