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