diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2013-01-16 08:53:53 -0500 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-02-13 18:22:50 -0500 |
commit | 6dd810b5e6fa688010dcb6d386c61589e850aaaa (patch) | |
tree | b56a34b5de9e7f42c93e4ddf851e3d3af1586f7a /drivers/mfd/twl-core.c | |
parent | 3c3302794cc79b363779a762051ebe8670812791 (diff) |
mfd: twl-core: Allocate twl_modules dynamically
At boot time we can allocate the twl_modules array dynamically based on the
twl class we are using with devm_kzalloc() instead of the static
twl_modules[] array.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/twl-core.c')
-rw-r--r-- | drivers/mfd/twl-core.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c index f07317b35e4a..fbff8301dfca 100644 --- a/drivers/mfd/twl-core.c +++ b/drivers/mfd/twl-core.c | |||
@@ -66,8 +66,6 @@ | |||
66 | 66 | ||
67 | /* Triton Core internal information (BEGIN) */ | 67 | /* Triton Core internal information (BEGIN) */ |
68 | 68 | ||
69 | #define TWL_NUM_SLAVES 4 | ||
70 | |||
71 | /* Base Address defns for twl4030_map[] */ | 69 | /* Base Address defns for twl4030_map[] */ |
72 | 70 | ||
73 | /* subchip/slave 0 - USB ID */ | 71 | /* subchip/slave 0 - USB ID */ |
@@ -162,7 +160,7 @@ struct twl_client { | |||
162 | struct regmap *regmap; | 160 | struct regmap *regmap; |
163 | }; | 161 | }; |
164 | 162 | ||
165 | static struct twl_client twl_modules[TWL_NUM_SLAVES]; | 163 | static struct twl_client *twl_modules; |
166 | 164 | ||
167 | /* mapping the module id to slave id and base address */ | 165 | /* mapping the module id to slave id and base address */ |
168 | struct twl_mapping { | 166 | struct twl_mapping { |
@@ -284,6 +282,14 @@ static struct regmap_config twl6030_regmap_config[3] = { | |||
284 | 282 | ||
285 | /*----------------------------------------------------------------------*/ | 283 | /*----------------------------------------------------------------------*/ |
286 | 284 | ||
285 | static inline int twl_get_num_slaves(void) | ||
286 | { | ||
287 | if (twl_class_is_4030()) | ||
288 | return 4; /* TWL4030 class have four slave address */ | ||
289 | else | ||
290 | return 3; /* TWL6030 class have three slave address */ | ||
291 | } | ||
292 | |||
287 | static inline int twl_get_last_module(void) | 293 | static inline int twl_get_last_module(void) |
288 | { | 294 | { |
289 | if (twl_class_is_4030()) | 295 | if (twl_class_is_4030()) |
@@ -1127,17 +1133,15 @@ static int twl_remove(struct i2c_client *client) | |||
1127 | unsigned i, num_slaves; | 1133 | unsigned i, num_slaves; |
1128 | int status; | 1134 | int status; |
1129 | 1135 | ||
1130 | if (twl_class_is_4030()) { | 1136 | if (twl_class_is_4030()) |
1131 | status = twl4030_exit_irq(); | 1137 | status = twl4030_exit_irq(); |
1132 | num_slaves = TWL_NUM_SLAVES; | 1138 | else |
1133 | } else { | ||
1134 | status = twl6030_exit_irq(); | 1139 | status = twl6030_exit_irq(); |
1135 | num_slaves = TWL_NUM_SLAVES - 1; | ||
1136 | } | ||
1137 | 1140 | ||
1138 | if (status < 0) | 1141 | if (status < 0) |
1139 | return status; | 1142 | return status; |
1140 | 1143 | ||
1144 | num_slaves = twl_get_num_slaves(); | ||
1141 | for (i = 0; i < num_slaves; i++) { | 1145 | for (i = 0; i < num_slaves; i++) { |
1142 | struct twl_client *twl = &twl_modules[i]; | 1146 | struct twl_client *twl = &twl_modules[i]; |
1143 | 1147 | ||
@@ -1215,12 +1219,19 @@ twl_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
1215 | twl_map[TWL_MODULE_MAIN_CHARGE].base = | 1219 | twl_map[TWL_MODULE_MAIN_CHARGE].base = |
1216 | TWL6025_BASEADD_CHARGER; | 1220 | TWL6025_BASEADD_CHARGER; |
1217 | twl_regmap_config = twl6030_regmap_config; | 1221 | twl_regmap_config = twl6030_regmap_config; |
1218 | num_slaves = TWL_NUM_SLAVES - 1; | ||
1219 | } else { | 1222 | } else { |
1220 | twl_id = TWL4030_CLASS_ID; | 1223 | twl_id = TWL4030_CLASS_ID; |
1221 | twl_map = &twl4030_map[0]; | 1224 | twl_map = &twl4030_map[0]; |
1222 | twl_regmap_config = twl4030_regmap_config; | 1225 | twl_regmap_config = twl4030_regmap_config; |
1223 | num_slaves = TWL_NUM_SLAVES; | 1226 | } |
1227 | |||
1228 | num_slaves = twl_get_num_slaves(); | ||
1229 | twl_modules = devm_kzalloc(&client->dev, | ||
1230 | sizeof(struct twl_client) * num_slaves, | ||
1231 | GFP_KERNEL); | ||
1232 | if (!twl_modules) { | ||
1233 | status = -ENOMEM; | ||
1234 | goto free; | ||
1224 | } | 1235 | } |
1225 | 1236 | ||
1226 | for (i = 0; i < num_slaves; i++) { | 1237 | for (i = 0; i < num_slaves; i++) { |