diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2013-01-16 08:53:50 -0500 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-02-13 18:22:49 -0500 |
commit | 5d4e9bd79a5ab5bd4695d3becaa71da447a76a94 (patch) | |
tree | 1135e16a579f105c9eabc259fe4e3afaf129cfd0 /drivers/mfd | |
parent | c6dc96467ad94e3fe848d883d3a5a7e18a387abd (diff) |
mfd: twl-core: Clean up module id lookup and definitions
Use enums for all module definitions:
twl_module_ids for common functionality among twl4030/twl6030
twl4030_module_ids for twl4030 specific ids
twl6030_module_ids for twl6030 specific ids
In this way the list can be managed easier when new functionality going to
be implemented.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r-- | drivers/mfd/twl-core.c | 105 |
1 files changed, 51 insertions, 54 deletions
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index 4f3baadd0038..b781cdd0629d 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c | |||
@@ -74,8 +74,6 @@ | |||
74 | #define SUB_CHIP_ID3 3 | 74 | #define SUB_CHIP_ID3 3 |
75 | #define SUB_CHIP_ID_INVAL 0xff | 75 | #define SUB_CHIP_ID_INVAL 0xff |
76 | 76 | ||
77 | #define TWL_MODULE_LAST TWL4030_MODULE_LAST | ||
78 | |||
79 | /* Base Address defns for twl4030_map[] */ | 77 | /* Base Address defns for twl4030_map[] */ |
80 | 78 | ||
81 | /* subchip/slave 0 - USB ID */ | 79 | /* subchip/slave 0 - USB ID */ |
@@ -94,10 +92,7 @@ | |||
94 | #define TWL4030_BASEADD_MADC 0x0000 | 92 | #define TWL4030_BASEADD_MADC 0x0000 |
95 | #define TWL4030_BASEADD_MAIN_CHARGE 0x0074 | 93 | #define TWL4030_BASEADD_MAIN_CHARGE 0x0074 |
96 | #define TWL4030_BASEADD_PRECHARGE 0x00AA | 94 | #define TWL4030_BASEADD_PRECHARGE 0x00AA |
97 | #define TWL4030_BASEADD_PWM0 0x00F8 | 95 | #define TWL4030_BASEADD_PWM 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 | 96 | #define TWL4030_BASEADD_KEYPAD 0x00D2 |
102 | 97 | ||
103 | #define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */ | 98 | #define TWL5031_BASEADD_ACCESSORY 0x0074 /* Replaces Main Charge */ |
@@ -117,7 +112,7 @@ | |||
117 | 112 | ||
118 | /* subchip/slave 0 0x48 - POWER */ | 113 | /* subchip/slave 0 0x48 - POWER */ |
119 | #define TWL6030_BASEADD_RTC 0x0000 | 114 | #define TWL6030_BASEADD_RTC 0x0000 |
120 | #define TWL6030_BASEADD_MEM 0x0017 | 115 | #define TWL6030_BASEADD_SECURED_REG 0x0017 |
121 | #define TWL6030_BASEADD_PM_MASTER 0x001F | 116 | #define TWL6030_BASEADD_PM_MASTER 0x001F |
122 | #define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */ | 117 | #define TWL6030_BASEADD_PM_SLAVE_MISC 0x0030 /* PM_RECEIVER */ |
123 | #define TWL6030_BASEADD_PM_MISC 0x00E2 | 118 | #define TWL6030_BASEADD_PM_MISC 0x00E2 |
@@ -132,6 +127,7 @@ | |||
132 | #define TWL6030_BASEADD_PIH 0x00D0 | 127 | #define TWL6030_BASEADD_PIH 0x00D0 |
133 | #define TWL6030_BASEADD_CHARGER 0x00E0 | 128 | #define TWL6030_BASEADD_CHARGER 0x00E0 |
134 | #define TWL6025_BASEADD_CHARGER 0x00DA | 129 | #define TWL6025_BASEADD_CHARGER 0x00DA |
130 | #define TWL6030_BASEADD_LED 0x00F4 | ||
135 | 131 | ||
136 | /* subchip/slave 2 0x4A - DFT */ | 132 | /* subchip/slave 2 0x4A - DFT */ |
137 | #define TWL6030_BASEADD_DIEID 0x00C0 | 133 | #define TWL6030_BASEADD_DIEID 0x00C0 |
@@ -188,34 +184,33 @@ static struct twl_mapping twl4030_map[] = { | |||
188 | * so they continue to match the order in this table. | 184 | * so they continue to match the order in this table. |
189 | */ | 185 | */ |
190 | 186 | ||
187 | /* Common IPs */ | ||
191 | { 0, TWL4030_BASEADD_USB }, | 188 | { 0, TWL4030_BASEADD_USB }, |
189 | { 1, TWL4030_BASEADD_PIH }, | ||
190 | { 2, TWL4030_BASEADD_MAIN_CHARGE }, | ||
191 | { 3, TWL4030_BASEADD_PM_MASTER }, | ||
192 | { 3, TWL4030_BASEADD_PM_RECEIVER }, | ||
193 | |||
194 | { 3, TWL4030_BASEADD_RTC }, | ||
195 | { 2, TWL4030_BASEADD_PWM }, | ||
196 | { 2, TWL4030_BASEADD_LED }, | ||
197 | { 3, TWL4030_BASEADD_SECURED_REG }, | ||
198 | |||
199 | /* TWL4030 specific IPs */ | ||
192 | { 1, TWL4030_BASEADD_AUDIO_VOICE }, | 200 | { 1, TWL4030_BASEADD_AUDIO_VOICE }, |
193 | { 1, TWL4030_BASEADD_GPIO }, | 201 | { 1, TWL4030_BASEADD_GPIO }, |
194 | { 1, TWL4030_BASEADD_INTBR }, | 202 | { 1, TWL4030_BASEADD_INTBR }, |
195 | { 1, TWL4030_BASEADD_PIH }, | ||
196 | |||
197 | { 1, TWL4030_BASEADD_TEST }, | 203 | { 1, TWL4030_BASEADD_TEST }, |
198 | { 2, TWL4030_BASEADD_KEYPAD }, | 204 | { 2, TWL4030_BASEADD_KEYPAD }, |
205 | |||
199 | { 2, TWL4030_BASEADD_MADC }, | 206 | { 2, TWL4030_BASEADD_MADC }, |
200 | { 2, TWL4030_BASEADD_INTERRUPTS }, | 207 | { 2, TWL4030_BASEADD_INTERRUPTS }, |
201 | { 2, TWL4030_BASEADD_LED }, | ||
202 | |||
203 | { 2, TWL4030_BASEADD_MAIN_CHARGE }, | ||
204 | { 2, TWL4030_BASEADD_PRECHARGE }, | 208 | { 2, TWL4030_BASEADD_PRECHARGE }, |
205 | { 2, TWL4030_BASEADD_PWM0 }, | ||
206 | { 2, TWL4030_BASEADD_PWM1 }, | ||
207 | { 2, TWL4030_BASEADD_PWMA }, | ||
208 | |||
209 | { 2, TWL4030_BASEADD_PWMB }, | ||
210 | { 2, TWL5031_BASEADD_ACCESSORY }, | ||
211 | { 2, TWL5031_BASEADD_INTERRUPTS }, | ||
212 | { 3, TWL4030_BASEADD_BACKUP }, | 209 | { 3, TWL4030_BASEADD_BACKUP }, |
213 | { 3, TWL4030_BASEADD_INT }, | 210 | { 3, TWL4030_BASEADD_INT }, |
214 | 211 | ||
215 | { 3, TWL4030_BASEADD_PM_MASTER }, | 212 | { 2, TWL5031_BASEADD_ACCESSORY }, |
216 | { 3, TWL4030_BASEADD_PM_RECEIVER }, | 213 | { 2, TWL5031_BASEADD_INTERRUPTS }, |
217 | { 3, TWL4030_BASEADD_RTC }, | ||
218 | { 3, TWL4030_BASEADD_SECURED_REG }, | ||
219 | }; | 214 | }; |
220 | 215 | ||
221 | static struct regmap_config twl4030_regmap_config[4] = { | 216 | static struct regmap_config twl4030_regmap_config[4] = { |
@@ -251,35 +246,25 @@ static struct twl_mapping twl6030_map[] = { | |||
251 | * <linux/i2c/twl.h> defines for TWL4030_MODULE_* | 246 | * <linux/i2c/twl.h> defines for TWL4030_MODULE_* |
252 | * so they continue to match the order in this table. | 247 | * so they continue to match the order in this table. |
253 | */ | 248 | */ |
254 | { SUB_CHIP_ID1, TWL6030_BASEADD_USB }, | 249 | |
255 | { SUB_CHIP_ID_INVAL, TWL6030_BASEADD_AUDIO }, | 250 | /* Common IPs */ |
256 | { SUB_CHIP_ID2, TWL6030_BASEADD_DIEID }, | 251 | { 1, TWL6030_BASEADD_USB }, |
257 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 252 | { 1, TWL6030_BASEADD_PIH }, |
258 | { SUB_CHIP_ID1, TWL6030_BASEADD_PIH }, | 253 | { 1, TWL6030_BASEADD_CHARGER }, |
259 | 254 | { 0, TWL6030_BASEADD_PM_MASTER }, | |
260 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 255 | { 0, TWL6030_BASEADD_PM_SLAVE_MISC }, |
261 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 256 | |
262 | { SUB_CHIP_ID1, TWL6030_BASEADD_GPADC_CTRL }, | 257 | { 0, TWL6030_BASEADD_RTC }, |
263 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 258 | { 1, TWL6030_BASEADD_PWM }, |
264 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | 259 | { 1, TWL6030_BASEADD_LED }, |
265 | 260 | { 0, TWL6030_BASEADD_SECURED_REG }, | |
266 | { SUB_CHIP_ID1, TWL6030_BASEADD_CHARGER }, | 261 | |
267 | { SUB_CHIP_ID1, TWL6030_BASEADD_GASGAUGE }, | 262 | /* TWL6030 specific IPs */ |
268 | { SUB_CHIP_ID1, TWL6030_BASEADD_PWM }, | 263 | { 0, TWL6030_BASEADD_ZERO }, |
269 | { SUB_CHIP_ID0, TWL6030_BASEADD_ZERO }, | 264 | { 1, TWL6030_BASEADD_ZERO }, |
270 | { SUB_CHIP_ID1, TWL6030_BASEADD_ZERO }, | 265 | { 2, TWL6030_BASEADD_ZERO }, |
271 | 266 | { 1, TWL6030_BASEADD_GPADC_CTRL }, | |
272 | { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, | 267 | { 1, TWL6030_BASEADD_GASGAUGE }, |
273 | { SUB_CHIP_ID2, TWL6030_BASEADD_ZERO }, | ||
274 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | ||
275 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | ||
276 | { SUB_CHIP_ID2, TWL6030_BASEADD_RSV }, | ||
277 | |||
278 | { SUB_CHIP_ID0, TWL6030_BASEADD_PM_MASTER }, | ||
279 | { SUB_CHIP_ID0, TWL6030_BASEADD_PM_SLAVE_MISC }, | ||
280 | { SUB_CHIP_ID0, TWL6030_BASEADD_RTC }, | ||
281 | { SUB_CHIP_ID0, TWL6030_BASEADD_MEM }, | ||
282 | { SUB_CHIP_ID1, TWL6025_BASEADD_CHARGER }, | ||
283 | }; | 268 | }; |
284 | 269 | ||
285 | static struct regmap_config twl6030_regmap_config[3] = { | 270 | static struct regmap_config twl6030_regmap_config[3] = { |
@@ -305,6 +290,14 @@ static struct regmap_config twl6030_regmap_config[3] = { | |||
305 | 290 | ||
306 | /*----------------------------------------------------------------------*/ | 291 | /*----------------------------------------------------------------------*/ |
307 | 292 | ||
293 | static inline int twl_get_last_module(void) | ||
294 | { | ||
295 | if (twl_class_is_4030()) | ||
296 | return TWL4030_MODULE_LAST; | ||
297 | else | ||
298 | return TWL6030_MODULE_LAST; | ||
299 | } | ||
300 | |||
308 | /* Exported Functions */ | 301 | /* Exported Functions */ |
309 | 302 | ||
310 | /** | 303 | /** |
@@ -325,7 +318,7 @@ int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) | |||
325 | int sid; | 318 | int sid; |
326 | struct twl_client *twl; | 319 | struct twl_client *twl; |
327 | 320 | ||
328 | if (unlikely(mod_no >= TWL_MODULE_LAST)) { | 321 | if (unlikely(mod_no >= twl_get_last_module())) { |
329 | pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); | 322 | pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); |
330 | return -EPERM; | 323 | return -EPERM; |
331 | } | 324 | } |
@@ -367,7 +360,7 @@ int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) | |||
367 | int sid; | 360 | int sid; |
368 | struct twl_client *twl; | 361 | struct twl_client *twl; |
369 | 362 | ||
370 | if (unlikely(mod_no >= TWL_MODULE_LAST)) { | 363 | if (unlikely(mod_no >= twl_get_last_module())) { |
371 | pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); | 364 | pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); |
372 | return -EPERM; | 365 | return -EPERM; |
373 | } | 366 | } |
@@ -1228,6 +1221,10 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1228 | if ((id->driver_data) & TWL6030_CLASS) { | 1221 | if ((id->driver_data) & TWL6030_CLASS) { |
1229 | twl_id = TWL6030_CLASS_ID; | 1222 | twl_id = TWL6030_CLASS_ID; |
1230 | twl_map = &twl6030_map[0]; | 1223 | twl_map = &twl6030_map[0]; |
1224 | /* The charger base address is different in twl6025 */ | ||
1225 | if ((id->driver_data) & TWL6025_SUBCLASS) | ||
1226 | twl_map[TWL_MODULE_MAIN_CHARGE].base = | ||
1227 | TWL6025_BASEADD_CHARGER; | ||
1231 | twl_regmap_config = twl6030_regmap_config; | 1228 | twl_regmap_config = twl6030_regmap_config; |
1232 | num_slaves = TWL_NUM_SLAVES - 1; | 1229 | num_slaves = TWL_NUM_SLAVES - 1; |
1233 | } else { | 1230 | } else { |