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