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