Skip to content

Commit 55af7b9

Browse files
Dzmitry Sankouskisre
authored andcommitted
power: supply: max77705_charger: return error when config fails
Handle error, returned from register writes in init function. Signed-off-by: Dzmitry Sankouski <dsankouski@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent ef1e734 commit 55af7b9

1 file changed

Lines changed: 70 additions & 20 deletions

File tree

drivers/power/supply/max77705_charger.c

Lines changed: 70 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -400,43 +400,72 @@ static void max77705_chgin_isr_work(struct work_struct *work)
400400
power_supply_changed(chg->psy_chg);
401401
}
402402

403-
static void max77705_charger_initialize(struct max77705_charger_data *chg)
403+
static int max77705_charger_initialize(struct max77705_charger_data *chg)
404404
{
405405
struct power_supply_battery_info *info;
406406
struct regmap *regmap = chg->regmap;
407+
int err;
407408

408-
if (power_supply_get_battery_info(chg->psy_chg, &info) < 0)
409-
return;
409+
err = power_supply_get_battery_info(chg->psy_chg, &info);
410+
if (err)
411+
return dev_err_probe(chg->dev, err, "error on getting battery info");
410412

411413
chg->bat_info = info;
412414

413415
/* unlock charger setting protect */
414416
/* slowest LX slope */
415-
regmap_field_write(chg->rfield[MAX77705_CHGPROT], MAX77705_CHGPROT_UNLOCKED);
416-
regmap_field_write(chg->rfield[MAX77705_LX_SLOPE], MAX77705_SLOWEST_LX_SLOPE);
417+
err = regmap_field_write(chg->rfield[MAX77705_CHGPROT], MAX77705_CHGPROT_UNLOCKED);
418+
if (err)
419+
goto err;
420+
421+
err = regmap_field_write(chg->rfield[MAX77705_LX_SLOPE], MAX77705_SLOWEST_LX_SLOPE);
422+
if (err)
423+
goto err;
417424

418425
/* fast charge timer disable */
419426
/* restart threshold disable */
420427
/* pre-qual charge disable */
421-
regmap_field_write(chg->rfield[MAX77705_FCHGTIME], MAX77705_FCHGTIME_DISABLE);
422-
regmap_field_write(chg->rfield[MAX77705_CHG_RSTRT], MAX77705_CHG_RSTRT_DISABLE);
423-
regmap_field_write(chg->rfield[MAX77705_CHG_PQEN], MAX77705_CHG_PQEN_DISABLE);
428+
err = regmap_field_write(chg->rfield[MAX77705_FCHGTIME], MAX77705_FCHGTIME_DISABLE);
429+
if (err)
430+
goto err;
431+
432+
err = regmap_field_write(chg->rfield[MAX77705_CHG_RSTRT], MAX77705_CHG_RSTRT_DISABLE);
433+
if (err)
434+
goto err;
424435

425-
regmap_field_write(chg->rfield[MAX77705_MODE],
436+
err = regmap_field_write(chg->rfield[MAX77705_CHG_PQEN], MAX77705_CHG_PQEN_DISABLE);
437+
if (err)
438+
goto err;
439+
440+
err = regmap_field_write(chg->rfield[MAX77705_MODE],
426441
MAX77705_CHG_MASK | MAX77705_BUCK_MASK);
442+
if (err)
443+
goto err;
427444

428445
/* charge current 450mA(default) */
429446
/* otg current limit 900mA */
430-
regmap_field_write(chg->rfield[MAX77705_OTG_ILIM], MAX77705_OTG_ILIM_900);
447+
err = regmap_field_write(chg->rfield[MAX77705_OTG_ILIM], MAX77705_OTG_ILIM_900);
448+
if (err)
449+
goto err;
431450

432451
/* BAT to SYS OCP 4.80A */
433-
regmap_field_write(chg->rfield[MAX77705_REG_B2SOVRC], MAX77705_B2SOVRC_4_8A);
452+
err = regmap_field_write(chg->rfield[MAX77705_REG_B2SOVRC], MAX77705_B2SOVRC_4_8A);
453+
if (err)
454+
goto err;
434455

435456
/* top off current 150mA */
436457
/* top off timer 30min */
437-
regmap_field_write(chg->rfield[MAX77705_TO], MAX77705_TO_ITH_150MA);
438-
regmap_field_write(chg->rfield[MAX77705_TO_TIME], MAX77705_TO_TIME_30M);
439-
regmap_field_write(chg->rfield[MAX77705_SYS_TRACK], MAX77705_SYS_TRACK_DISABLE);
458+
err = regmap_field_write(chg->rfield[MAX77705_TO], MAX77705_TO_ITH_150MA);
459+
if (err)
460+
goto err;
461+
462+
err = regmap_field_write(chg->rfield[MAX77705_TO_TIME], MAX77705_TO_TIME_30M);
463+
if (err)
464+
goto err;
465+
466+
err = regmap_field_write(chg->rfield[MAX77705_SYS_TRACK], MAX77705_SYS_TRACK_DISABLE);
467+
if (err)
468+
goto err;
440469

441470
/* cv voltage 4.2V or 4.35V */
442471
/* MINVSYS 3.6V(default) */
@@ -447,21 +476,38 @@ static void max77705_charger_initialize(struct max77705_charger_data *chg)
447476
max77705_set_float_voltage(chg, info->voltage_max_design_uv);
448477
}
449478

450-
regmap_field_write(chg->rfield[MAX77705_VCHGIN], MAX77705_VCHGIN_4_5);
451-
regmap_field_write(chg->rfield[MAX77705_WCIN], MAX77705_WCIN_4_5);
479+
err = regmap_field_write(chg->rfield[MAX77705_VCHGIN], MAX77705_VCHGIN_4_5);
480+
if (err)
481+
goto err;
482+
483+
err = regmap_field_write(chg->rfield[MAX77705_WCIN], MAX77705_WCIN_4_5);
484+
if (err)
485+
goto err;
452486

453487
/* Watchdog timer */
454488
regmap_update_bits(regmap, MAX77705_CHG_REG_CNFG_00,
455489
MAX77705_WDTEN_MASK, 0);
456490

457491
/* VBYPSET=5.0V */
458-
regmap_field_write(chg->rfield[MAX77705_VBYPSET], 0);
492+
err = regmap_field_write(chg->rfield[MAX77705_VBYPSET], 0);
493+
if (err)
494+
goto err;
459495

460496
/* Switching Frequency : 1.5MHz */
461-
regmap_field_write(chg->rfield[MAX77705_REG_FSW], MAX77705_CHG_FSW_1_5MHz);
497+
err = regmap_field_write(chg->rfield[MAX77705_REG_FSW], MAX77705_CHG_FSW_1_5MHz);
498+
if (err)
499+
goto err;
462500

463501
/* Auto skip mode */
464-
regmap_field_write(chg->rfield[MAX77705_REG_DISKIP], MAX77705_AUTO_SKIP);
502+
err = regmap_field_write(chg->rfield[MAX77705_REG_DISKIP], MAX77705_AUTO_SKIP);
503+
if (err)
504+
goto err;
505+
506+
return 0;
507+
508+
err:
509+
return dev_err_probe(chg->dev, err, "error while configuring");
510+
465511
}
466512

467513
static int max77705_charger_probe(struct i2c_client *i2c)
@@ -524,7 +570,11 @@ static int max77705_charger_probe(struct i2c_client *i2c)
524570
goto destroy_wq;
525571
}
526572

527-
max77705_charger_initialize(chg);
573+
ret = max77705_charger_initialize(chg);
574+
if (ret) {
575+
dev_err_probe(dev, ret, "failed to initialize charger IC\n");
576+
goto destroy_wq;
577+
}
528578

529579
ret = max77705_charger_enable(chg);
530580
if (ret) {

0 commit comments

Comments
 (0)