aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/88pm800.c
diff options
context:
space:
mode:
authorChao Xie <chao.xie@marvell.com>2013-06-14 01:21:50 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2013-06-18 03:40:57 -0400
commit52705344d00512f0bb48c66478582bd10eb1750f (patch)
tree40848be952a730db87f30a546dc64edc658f3a39 /drivers/mfd/88pm800.c
parentc750d8e053c08ccb82d814d695e64d1eb602a91a (diff)
mfd: 88pm800: Enhance error handling for sub pages probe/remove
pm800_pages_init and pm800_pages_exit are called by pm800_probe. Change the code to enhance error handling and remove unused code at pm800_pages_init/exit and pm800_probe. Signed-off-by: Yi Zhang <yizhang@marvell.com> Signed-off-by: Chao Xie <chao.xie@marvell.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd/88pm800.c')
-rw-r--r--drivers/mfd/88pm800.c81
1 files changed, 48 insertions, 33 deletions
diff --git a/drivers/mfd/88pm800.c b/drivers/mfd/88pm800.c
index 6b607adebce1..4ebb2e215bac 100644
--- a/drivers/mfd/88pm800.c
+++ b/drivers/mfd/88pm800.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/err.h>
25#include <linux/i2c.h> 26#include <linux/i2c.h>
26#include <linux/mfd/core.h> 27#include <linux/mfd/core.h>
27#include <linux/mfd/88pm80x.h> 28#include <linux/mfd/88pm80x.h>
@@ -370,50 +371,64 @@ static int pm800_pages_init(struct pm80x_chip *chip)
370 struct pm80x_subchip *subchip; 371 struct pm80x_subchip *subchip;
371 struct i2c_client *client = chip->client; 372 struct i2c_client *client = chip->client;
372 373
374 int ret = 0;
375
373 subchip = chip->subchip; 376 subchip = chip->subchip;
374 /* PM800 block power: i2c addr 0x31 */ 377 if (!subchip || !subchip->power_page_addr || !subchip->gpadc_page_addr)
375 if (subchip->power_page_addr) { 378 return -ENODEV;
376 subchip->power_page = 379
377 i2c_new_dummy(client->adapter, subchip->power_page_addr); 380 /* PM800 block power page */
378 subchip->regmap_power = 381 subchip->power_page = i2c_new_dummy(client->adapter,
379 devm_regmap_init_i2c(subchip->power_page, 382 subchip->power_page_addr);
380 &pm80x_regmap_config); 383 if (subchip->power_page == NULL) {
381 i2c_set_clientdata(subchip->power_page, chip); 384 ret = -ENODEV;
382 } else 385 goto out;
383 dev_info(chip->dev, 386 }
384 "PM800 block power 0x31: No power_page_addr\n");
385
386 /* PM800 block GPADC: i2c addr 0x32 */
387 if (subchip->gpadc_page_addr) {
388 subchip->gpadc_page = i2c_new_dummy(client->adapter,
389 subchip->gpadc_page_addr);
390 subchip->regmap_gpadc =
391 devm_regmap_init_i2c(subchip->gpadc_page,
392 &pm80x_regmap_config);
393 i2c_set_clientdata(subchip->gpadc_page, chip);
394 } else
395 dev_info(chip->dev,
396 "PM800 block GPADC 0x32: No gpadc_page_addr\n");
397 387
398 return 0; 388 subchip->regmap_power = devm_regmap_init_i2c(subchip->power_page,
389 &pm80x_regmap_config);
390 if (IS_ERR(subchip->regmap_power)) {
391 ret = PTR_ERR(subchip->regmap_power);
392 dev_err(chip->dev,
393 "Failed to allocate regmap_power: %d\n", ret);
394 goto out;
395 }
396
397 i2c_set_clientdata(subchip->power_page, chip);
398
399 /* PM800 block GPADC */
400 subchip->gpadc_page = i2c_new_dummy(client->adapter,
401 subchip->gpadc_page_addr);
402 if (subchip->gpadc_page == NULL) {
403 ret = -ENODEV;
404 goto out;
405 }
406
407 subchip->regmap_gpadc = devm_regmap_init_i2c(subchip->gpadc_page,
408 &pm80x_regmap_config);
409 if (IS_ERR(subchip->regmap_gpadc)) {
410 ret = PTR_ERR(subchip->regmap_gpadc);
411 dev_err(chip->dev,
412 "Failed to allocate regmap_gpadc: %d\n", ret);
413 goto out;
414 }
415 i2c_set_clientdata(subchip->gpadc_page, chip);
416
417out:
418 return ret;
399} 419}
400 420
401static void pm800_pages_exit(struct pm80x_chip *chip) 421static void pm800_pages_exit(struct pm80x_chip *chip)
402{ 422{
403 struct pm80x_subchip *subchip; 423 struct pm80x_subchip *subchip;
404 424
405 regmap_exit(chip->regmap);
406 i2c_unregister_device(chip->client);
407
408 subchip = chip->subchip; 425 subchip = chip->subchip;
409 if (subchip->power_page) { 426
410 regmap_exit(subchip->regmap_power); 427 if (subchip && subchip->power_page)
411 i2c_unregister_device(subchip->power_page); 428 i2c_unregister_device(subchip->power_page);
412 } 429
413 if (subchip->gpadc_page) { 430 if (subchip && subchip->gpadc_page)
414 regmap_exit(subchip->regmap_gpadc);
415 i2c_unregister_device(subchip->gpadc_page); 431 i2c_unregister_device(subchip->gpadc_page);
416 }
417} 432}
418 433
419static int device_800_init(struct pm80x_chip *chip, 434static int device_800_init(struct pm80x_chip *chip,