aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2014-01-03 08:27:46 -0500
committerLee Jones <lee.jones@linaro.org>2014-01-08 06:36:59 -0500
commit8daf3540659c22b4d3530512a3695728482ec23f (patch)
treeb2319d6ccc4098ee2891ce1bfff6b1b9c6dbf811
parentc7f9129d22940720141d1f1e958a51142eff9d21 (diff)
mfd: twl-core: Simplify IO wrapper functions by moving common code out
The new twl_get_regmap() function will return a pointer to the regmap needed for the given module. Since both read and write function were using the same code to do the lookup we can reuse this in both places to simplify the code. Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com> Acked-by: Mark Brown <broonie@kernel.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
-rw-r--r--drivers/mfd/twl-core.c58
1 files changed, 31 insertions, 27 deletions
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 29473c2c95ae..c91cb4367b9b 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -302,35 +302,50 @@ unsigned int twl_rev(void)
302EXPORT_SYMBOL(twl_rev); 302EXPORT_SYMBOL(twl_rev);
303 303
304/** 304/**
305 * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0 305 * twl_get_regmap - Get the regmap associated with the given module
306 * @mod_no: module number 306 * @mod_no: module number
307 * @value: an array of num_bytes+1 containing data to write
308 * @reg: register address (just offset will do)
309 * @num_bytes: number of bytes to transfer
310 * 307 *
311 * Returns the result of operation - 0 is success 308 * Returns the regmap pointer or NULL in case of failure.
312 */ 309 */
313int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) 310static struct regmap *twl_get_regmap(u8 mod_no)
314{ 311{
315 int ret;
316 int sid; 312 int sid;
317 struct twl_client *twl; 313 struct twl_client *twl;
318 314
319 if (unlikely(!twl_priv || !twl_priv->ready)) { 315 if (unlikely(!twl_priv || !twl_priv->ready)) {
320 pr_err("%s: not initialized\n", DRIVER_NAME); 316 pr_err("%s: not initialized\n", DRIVER_NAME);
321 return -EPERM; 317 return NULL;
322 } 318 }
323 if (unlikely(mod_no >= twl_get_last_module())) { 319 if (unlikely(mod_no >= twl_get_last_module())) {
324 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no); 320 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
325 return -EPERM; 321 return NULL;
326 } 322 }
327 323
328 sid = twl_priv->twl_map[mod_no].sid; 324 sid = twl_priv->twl_map[mod_no].sid;
329 twl = &twl_priv->twl_modules[sid]; 325 twl = &twl_priv->twl_modules[sid];
330 326
331 ret = regmap_bulk_write(twl->regmap, 327 return twl->regmap;
332 twl_priv->twl_map[mod_no].base + reg, value, 328}
333 num_bytes); 329
330/**
331 * twl_i2c_write - Writes a n bit register in TWL4030/TWL5030/TWL60X0
332 * @mod_no: module number
333 * @value: an array of num_bytes+1 containing data to write
334 * @reg: register address (just offset will do)
335 * @num_bytes: number of bytes to transfer
336 *
337 * Returns the result of operation - 0 is success
338 */
339int twl_i2c_write(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
340{
341 struct regmap *regmap = twl_get_regmap(mod_no);
342 int ret;
343
344 if (!regmap)
345 return -EPERM;
346
347 ret = regmap_bulk_write(regmap, twl_priv->twl_map[mod_no].base + reg,
348 value, num_bytes);
334 349
335 if (ret) 350 if (ret)
336 pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n", 351 pr_err("%s: Write failed (mod %d, reg 0x%02x count %d)\n",
@@ -351,25 +366,14 @@ EXPORT_SYMBOL(twl_i2c_write);
351 */ 366 */
352int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes) 367int twl_i2c_read(u8 mod_no, u8 *value, u8 reg, unsigned num_bytes)
353{ 368{
369 struct regmap *regmap = twl_get_regmap(mod_no);
354 int ret; 370 int ret;
355 int sid;
356 struct twl_client *twl;
357 371
358 if (unlikely(!twl_priv || !twl_priv->ready)) { 372 if (!regmap)
359 pr_err("%s: not initialized\n", DRIVER_NAME);
360 return -EPERM;
361 }
362 if (unlikely(mod_no >= twl_get_last_module())) {
363 pr_err("%s: invalid module number %d\n", DRIVER_NAME, mod_no);
364 return -EPERM; 373 return -EPERM;
365 }
366
367 sid = twl_priv->twl_map[mod_no].sid;
368 twl = &twl_priv->twl_modules[sid];
369 374
370 ret = regmap_bulk_read(twl->regmap, 375 ret = regmap_bulk_read(regmap, twl_priv->twl_map[mod_no].base + reg,
371 twl_priv->twl_map[mod_no].base + reg, value, 376 value, num_bytes);
372 num_bytes);
373 377
374 if (ret) 378 if (ret)
375 pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n", 379 pr_err("%s: Read failed (mod %d, reg 0x%02x count %d)\n",