Lines Matching refs:bq2515x

274 static int bq2515x_wake_up(struct bq2515x_device *bq2515x)  in bq2515x_wake_up()  argument
283 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &val); in bq2515x_wake_up()
291 gpiod_set_value_cansleep(bq2515x->powerdown_gpio, 0); in bq2515x_wake_up()
293 gpiod_set_value_cansleep(bq2515x->reset_gpio, 0); in bq2515x_wake_up()
295 gpiod_set_value_cansleep(bq2515x->reset_gpio, 1); in bq2515x_wake_up()
297 return regmap_write(bq2515x->regmap, BQ2515X_ADC_READ_EN, in bq2515x_wake_up()
301 static int bq2515x_update_ps_status(struct bq2515x_device *bq2515x) in bq2515x_update_ps_status() argument
307 if (bq2515x->ac_detect_gpio) in bq2515x_update_ps_status()
308 val = gpiod_get_value_cansleep(bq2515x->ac_detect_gpio); in bq2515x_update_ps_status()
310 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &val); in bq2515x_update_ps_status()
317 ret = bq2515x->mains_online != dc; in bq2515x_update_ps_status()
319 bq2515x->mains_online = dc; in bq2515x_update_ps_status()
324 static int bq2515x_disable_watchdog_timers(struct bq2515x_device *bq2515x) in bq2515x_disable_watchdog_timers() argument
328 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_CHARGERCTRL0, in bq2515x_disable_watchdog_timers()
333 return regmap_update_bits(bq2515x->regmap, BQ2515X_ICCTRL2, in bq2515x_disable_watchdog_timers()
337 static int bq2515x_get_battery_voltage_now(struct bq2515x_device *bq2515x) in bq2515x_get_battery_voltage_now() argument
344 if (!bq2515x->mains_online) in bq2515x_get_battery_voltage_now()
345 bq2515x_wake_up(bq2515x); in bq2515x_get_battery_voltage_now()
347 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_VBAT_M, &vbat_msb); in bq2515x_get_battery_voltage_now()
351 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_VBAT_L, &vbat_lsb); in bq2515x_get_battery_voltage_now()
361 static int bq2515x_get_battery_current_now(struct bq2515x_device *bq2515x) in bq2515x_get_battery_current_now() argument
372 if (!bq2515x->mains_online) in bq2515x_get_battery_current_now()
375 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_ICHG_M, &ichg_msb); in bq2515x_get_battery_current_now()
379 ret = regmap_read(bq2515x->regmap, BQ2515X_ADC_ICHG_L, &ichg_lsb); in bq2515x_get_battery_current_now()
385 ret = regmap_read(bq2515x->regmap, BQ2515X_BUVLO, &buvlo); in bq2515x_get_battery_current_now()
394 if (bq2515x_get_battery_voltage_now(bq2515x) < vlowv) { in bq2515x_get_battery_current_now()
395 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_get_battery_current_now()
402 ret = regmap_read(bq2515x->regmap, BQ2515X_ICHG_CTRL, in bq2515x_get_battery_current_now()
410 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_battery_current_now()
423 static bool bq2515x_get_charge_disable(struct bq2515x_device *bq2515x) in bq2515x_get_charge_disable() argument
430 ce_pin = gpiod_get_value_cansleep(bq2515x->ce_gpio); in bq2515x_get_charge_disable()
432 ret = regmap_read(bq2515x->regmap, BQ2515X_ICCTRL2, &icctrl2); in bq2515x_get_charge_disable()
444 static int bq2515x_set_charge_disable(struct bq2515x_device *bq2515x, int val) in bq2515x_set_charge_disable() argument
446 gpiod_set_value_cansleep(bq2515x->ce_gpio, val); in bq2515x_set_charge_disable()
448 return regmap_update_bits(bq2515x->regmap, BQ2515X_ICCTRL2, in bq2515x_set_charge_disable()
452 static int bq2515x_get_const_charge_current(struct bq2515x_device *bq2515x) in bq2515x_get_const_charge_current() argument
460 ret = regmap_read(bq2515x->regmap, BQ2515X_ICHG_CTRL, &ichg_reg_code); in bq2515x_get_const_charge_current()
464 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_const_charge_current()
476 static int bq2515x_set_const_charge_current(struct bq2515x_device *bq2515x, in bq2515x_set_const_charge_current() argument
492 bq2515x_set_charge_disable(bq2515x, 1); in bq2515x_set_const_charge_current()
494 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_set_const_charge_current()
501 ret = regmap_write(bq2515x->regmap, BQ2515X_ICHG_CTRL, ichg_reg_code); in bq2515x_set_const_charge_current()
505 return bq2515x_set_charge_disable(bq2515x, 0); in bq2515x_set_const_charge_current()
508 static int bq2515x_get_precharge_current(struct bq2515x_device *bq2515x) in bq2515x_get_precharge_current() argument
516 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_get_precharge_current()
530 static int bq2515x_set_precharge_current(struct bq2515x_device *bq2515x, in bq2515x_set_precharge_current() argument
540 ret = regmap_read(bq2515x->regmap, BQ2515X_PCHRGCTRL, &pchrgctrl); in bq2515x_set_precharge_current()
558 ret = bq2515x_set_charge_disable(bq2515x, 1); in bq2515x_set_precharge_current()
562 ret = regmap_update_bits(bq2515x->regmap, BQ2515X_PCHRGCTRL, in bq2515x_set_precharge_current()
567 return bq2515x_set_charge_disable(bq2515x, 0); in bq2515x_set_precharge_current()
570 static int bq2515x_charging_status(struct bq2515x_device *bq2515x, in bq2515x_charging_status() argument
580 if (!bq2515x->mains_online) { in bq2515x_charging_status()
585 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT0, &status); in bq2515x_charging_status()
606 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT1, &status); in bq2515x_charging_status()
618 ce_status = (!bq2515x_get_charge_disable(bq2515x)); in bq2515x_charging_status()
636 static int bq2515x_get_batt_reg(struct bq2515x_device *bq2515x) in bq2515x_get_batt_reg() argument
641 ret = regmap_read(bq2515x->regmap, BQ2515X_VBAT_CTRL, &vbat_reg_code); in bq2515x_get_batt_reg()
648 static int bq2515x_set_batt_reg(struct bq2515x_device *bq2515x, int val) in bq2515x_set_batt_reg() argument
657 return regmap_write(bq2515x->regmap, BQ2515X_VBAT_CTRL, vbat_reg_code); in bq2515x_set_batt_reg()
660 static int bq2515x_get_ilim_lvl(struct bq2515x_device *bq2515x) in bq2515x_get_ilim_lvl() argument
665 ret = regmap_read(bq2515x->regmap, BQ2515X_ILIMCTRL, &ilimctrl); in bq2515x_get_ilim_lvl()
672 static int bq2515x_set_ilim_lvl(struct bq2515x_device *bq2515x, int val) in bq2515x_set_ilim_lvl() argument
681 return regmap_write(bq2515x->regmap, BQ2515X_ILIMCTRL, i); in bq2515x_set_ilim_lvl()
698 static int bq2515x_charger_get_health(struct bq2515x_device *bq2515x, in bq2515x_charger_get_health() argument
706 if (!bq2515x->mains_online) in bq2515x_charger_get_health()
707 bq2515x_wake_up(bq2515x); in bq2515x_charger_get_health()
709 ret = regmap_read(bq2515x->regmap, BQ2515X_FLAG3, &flag3); in bq2515x_charger_get_health()
713 ret = regmap_read(bq2515x->regmap, BQ2515X_STAT1, &stat1); in bq2515x_charger_get_health()
751 struct bq2515x_device *bq2515x = power_supply_get_drvdata(psy); in bq2515x_mains_set_property() local
756 ret = bq2515x_set_batt_reg(bq2515x, val->intval); in bq2515x_mains_set_property()
760 ret = bq2515x_set_const_charge_current(bq2515x, val->intval); in bq2515x_mains_set_property()
764 ret = bq2515x_set_ilim_lvl(bq2515x, val->intval); in bq2515x_mains_set_property()
768 ret = bq2515x_set_precharge_current(bq2515x, val->intval); in bq2515x_mains_set_property()
782 struct bq2515x_device *bq2515x = power_supply_get_drvdata(psy); in bq2515x_mains_get_property() local
788 ret = bq2515x_get_const_charge_current(bq2515x); in bq2515x_mains_get_property()
796 ret = bq2515x_get_batt_reg(bq2515x); in bq2515x_mains_get_property()
803 ret = bq2515x_get_precharge_current(bq2515x); in bq2515x_mains_get_property()
810 val->intval = bq2515x->mains_online; in bq2515x_mains_get_property()
814 ret = bq2515x_charger_get_health(bq2515x, val); in bq2515x_mains_get_property()
820 ret = bq2515x_get_ilim_lvl(bq2515x); in bq2515x_mains_get_property()
827 val->strval = bq2515x->model_name; in bq2515x_mains_get_property()
835 ret = bq2515x_charging_status(bq2515x, val); in bq2515x_mains_get_property()
851 struct bq2515x_device *bq2515x = power_supply_get_drvdata(psy); in bq2515x_battery_get_property() local
854 ret = bq2515x_update_ps_status(bq2515x); in bq2515x_battery_get_property()
861 ret = bq2515x->init_data.vbatreg; in bq2515x_battery_get_property()
868 ret = bq2515x->init_data.ichg; in bq2515x_battery_get_property()
875 ret = bq2515x_get_battery_voltage_now(bq2515x); in bq2515x_battery_get_property()
882 ret = bq2515x_get_battery_current_now(bq2515x); in bq2515x_battery_get_property()
932 static int bq2515x_power_supply_register(struct bq2515x_device *bq2515x, in bq2515x_power_supply_register() argument
935 bq2515x->mains = devm_power_supply_register(bq2515x->dev, in bq2515x_power_supply_register()
938 if (IS_ERR(bq2515x->mains)) in bq2515x_power_supply_register()
941 bq2515x->battery = devm_power_supply_register(bq2515x->dev, in bq2515x_power_supply_register()
944 if (IS_ERR(bq2515x->battery)) in bq2515x_power_supply_register()
950 static int bq2515x_hw_init(struct bq2515x_device *bq2515x) in bq2515x_hw_init() argument
955 ret = bq2515x_disable_watchdog_timers(bq2515x); in bq2515x_hw_init()
959 if (bq2515x->init_data.ilim) { in bq2515x_hw_init()
960 ret = bq2515x_set_ilim_lvl(bq2515x, bq2515x->init_data.ilim); in bq2515x_hw_init()
965 ret = power_supply_get_battery_info(bq2515x->mains, &bat_info); in bq2515x_hw_init()
967 dev_warn(bq2515x->dev, "battery info missing, default values will be applied\n"); in bq2515x_hw_init()
969 bq2515x->init_data.ichg = BQ2515X_DEFAULT_ICHG_UA; in bq2515x_hw_init()
971 bq2515x->init_data.vbatreg = BQ2515X_DEFAULT_VBAT_REG_UV; in bq2515x_hw_init()
973 bq2515x->init_data.iprechg = BQ2515X_DEFAULT_IPRECHARGE_UA; in bq2515x_hw_init()
976 bq2515x->init_data.ichg = in bq2515x_hw_init()
979 bq2515x->init_data.vbatreg = in bq2515x_hw_init()
982 bq2515x->init_data.iprechg = in bq2515x_hw_init()
986 ret = bq2515x_set_const_charge_current(bq2515x, in bq2515x_hw_init()
987 bq2515x->init_data.ichg); in bq2515x_hw_init()
991 ret = bq2515x_set_batt_reg(bq2515x, bq2515x->init_data.vbatreg); in bq2515x_hw_init()
995 return bq2515x_set_precharge_current(bq2515x, in bq2515x_hw_init()
996 bq2515x->init_data.iprechg); in bq2515x_hw_init()
999 static int bq2515x_read_properties(struct bq2515x_device *bq2515x) in bq2515x_read_properties() argument
1003 ret = device_property_read_u32(bq2515x->dev, in bq2515x_read_properties()
1005 &bq2515x->init_data.ilim); in bq2515x_read_properties()
1007 bq2515x->init_data.ilim = bq2515x->info->ilim; in bq2515x_read_properties()
1009 bq2515x->ac_detect_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1011 if (IS_ERR(bq2515x->ac_detect_gpio)) { in bq2515x_read_properties()
1012 ret = PTR_ERR(bq2515x->ac_detect_gpio); in bq2515x_read_properties()
1013 dev_err(bq2515x->dev, "Failed to get ac detect"); in bq2515x_read_properties()
1017 bq2515x->reset_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1019 if (IS_ERR(bq2515x->reset_gpio)) { in bq2515x_read_properties()
1020 ret = PTR_ERR(bq2515x->reset_gpio); in bq2515x_read_properties()
1021 dev_err(bq2515x->dev, "Failed to get reset"); in bq2515x_read_properties()
1025 bq2515x->powerdown_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1027 if (IS_ERR(bq2515x->powerdown_gpio)) { in bq2515x_read_properties()
1028 ret = PTR_ERR(bq2515x->powerdown_gpio); in bq2515x_read_properties()
1029 dev_err(bq2515x->dev, "Failed to get powerdown"); in bq2515x_read_properties()
1033 bq2515x->ce_gpio = devm_gpiod_get_optional(bq2515x->dev, in bq2515x_read_properties()
1036 if (IS_ERR(bq2515x->ce_gpio)) { in bq2515x_read_properties()
1037 ret = PTR_ERR(bq2515x->ce_gpio); in bq2515x_read_properties()
1038 dev_err(bq2515x->dev, "Failed to get ce"); in bq2515x_read_properties()
1082 struct bq2515x_device *bq2515x; in bq2515x_probe() local
1086 bq2515x = devm_kzalloc(dev, sizeof(*bq2515x), GFP_KERNEL); in bq2515x_probe()
1087 if (!bq2515x) in bq2515x_probe()
1090 bq2515x->dev = dev; in bq2515x_probe()
1092 strscpy(bq2515x->model_name, id->name, sizeof(bq2515x->model_name)); in bq2515x_probe()
1094 bq2515x->info = i2c_get_match_data(client); in bq2515x_probe()
1095 bq2515x->regmap = devm_regmap_init_i2c(client, in bq2515x_probe()
1096 bq2515x->info->regmap_config); in bq2515x_probe()
1097 if (IS_ERR(bq2515x->regmap)) { in bq2515x_probe()
1099 return PTR_ERR(bq2515x->regmap); in bq2515x_probe()
1102 i2c_set_clientdata(client, bq2515x); in bq2515x_probe()
1104 charger_cfg.drv_data = bq2515x; in bq2515x_probe()
1107 ret = bq2515x_read_properties(bq2515x); in bq2515x_probe()
1114 ret = bq2515x_power_supply_register(bq2515x, dev, charger_cfg); in bq2515x_probe()
1120 ret = bq2515x_hw_init(bq2515x); in bq2515x_probe()