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