Lines Matching refs:bd

182 static int bd9995x_get_prop_batt_health(struct bd9995x_device *bd)  in bd9995x_get_prop_batt_health()  argument
186 ret = regmap_field_read(bd->rmap_fields[F_BATTEMP], &tmp); in bd9995x_get_prop_batt_health()
209 static int bd9995x_get_prop_charge_type(struct bd9995x_device *bd) in bd9995x_get_prop_charge_type() argument
213 ret = regmap_field_read(bd->rmap_fields[F_CHGSTM_STATE], &tmp); in bd9995x_get_prop_charge_type()
232 static bool bd9995x_get_prop_batt_present(struct bd9995x_device *bd) in bd9995x_get_prop_batt_present() argument
236 ret = regmap_field_read(bd->rmap_fields[F_BATTEMP], &tmp); in bd9995x_get_prop_batt_present()
243 static int bd9995x_get_prop_batt_voltage(struct bd9995x_device *bd) in bd9995x_get_prop_batt_voltage() argument
247 ret = regmap_field_read(bd->rmap_fields[F_VBAT_VAL], &tmp); in bd9995x_get_prop_batt_voltage()
256 static int bd9995x_get_prop_batt_current(struct bd9995x_device *bd) in bd9995x_get_prop_batt_current() argument
260 ret = regmap_field_read(bd->rmap_fields[F_IBATP_VAL], &tmp); in bd9995x_get_prop_batt_current()
269 static int bd9995x_get_prop_batt_temp(struct bd9995x_device *bd) in bd9995x_get_prop_batt_temp() argument
273 ret = regmap_field_read(bd->rmap_fields[F_THERM_VAL], &tmp); in bd9995x_get_prop_batt_temp()
285 struct bd9995x_device *bd = power_supply_get_drvdata(psy); in bd9995x_power_supply_get_property() local
288 mutex_lock(&bd->lock); in bd9995x_power_supply_get_property()
289 state = bd->state; in bd9995x_power_supply_get_property()
290 mutex_unlock(&bd->lock); in bd9995x_power_supply_get_property()
340 ret = regmap_field_read(bd->rmap_fields[F_IBATP_VAL], &tmp); in bd9995x_power_supply_get_property()
347 ret = regmap_field_read(bd->rmap_fields[F_IBATP_AVE_VAL], &tmp); in bd9995x_power_supply_get_property()
366 ret = regmap_field_read(bd->rmap_fields[F_SEL_ILIM_VAL], &tmp); in bd9995x_power_supply_get_property()
378 ret = regmap_field_read(bd->rmap_fields[F_VFASTCHG_REG_SET1], in bd9995x_power_supply_get_property()
392 ret = regmap_field_read(bd->rmap_fields[F_ITERM_SET], &tmp); in bd9995x_power_supply_get_property()
404 val->intval = bd9995x_get_prop_batt_present(bd); in bd9995x_power_supply_get_property()
408 val->intval = bd9995x_get_prop_batt_voltage(bd); in bd9995x_power_supply_get_property()
412 val->intval = bd9995x_get_prop_batt_current(bd); in bd9995x_power_supply_get_property()
416 val->intval = bd9995x_get_prop_charge_type(bd); in bd9995x_power_supply_get_property()
420 val->intval = bd9995x_get_prop_batt_health(bd); in bd9995x_power_supply_get_property()
424 val->intval = bd9995x_get_prop_batt_temp(bd); in bd9995x_power_supply_get_property()
443 static int bd9995x_get_chip_state(struct bd9995x_device *bd, in bd9995x_get_chip_state() argument
452 bd->rmap_fields[F_CHGSTM_STATE], &state->chgstm_status, in bd9995x_get_chip_state()
454 bd->rmap_fields[F_VBAT_VSYS_STATUS], in bd9995x_get_chip_state()
457 bd->rmap_fields[F_VBUS_VCC_STATUS], in bd9995x_get_chip_state()
482 struct bd9995x_device *bd = private; in bd9995x_irq_handler_thread() local
503 ret = regmap_read(bd->rmap, INT0_STATUS, &status); in bd9995x_irq_handler_thread()
505 dev_err(bd->dev, "Failed to read IRQ status\n"); in bd9995x_irq_handler_thread()
509 ret = regmap_field_read(bd->rmap_fields[F_INT0_SET], &mask); in bd9995x_irq_handler_thread()
511 dev_err(bd->dev, "Failed to read IRQ mask\n"); in bd9995x_irq_handler_thread()
525 ret = regmap_field_write(bd->rmap_fields[F_INT0_SET], 0); in bd9995x_irq_handler_thread()
527 dev_err(bd->dev, "Failed to mask F_INT0\n"); in bd9995x_irq_handler_thread()
531 ret = regmap_write(bd->rmap, INT0_STATUS, status); in bd9995x_irq_handler_thread()
533 dev_err(bd->dev, "Failed to ack F_INT0\n"); in bd9995x_irq_handler_thread()
544 bd->rmap_fields[F_INT1_SET], in bd9995x_irq_handler_thread()
545 bd->rmap_fields[F_INT2_SET], in bd9995x_irq_handler_thread()
546 bd->rmap_fields[F_INT3_SET], in bd9995x_irq_handler_thread()
547 bd->rmap_fields[F_INT4_SET], in bd9995x_irq_handler_thread()
548 bd->rmap_fields[F_INT5_SET], in bd9995x_irq_handler_thread()
549 bd->rmap_fields[F_INT6_SET], in bd9995x_irq_handler_thread()
550 bd->rmap_fields[F_INT7_SET], in bd9995x_irq_handler_thread()
554 ret = regmap_read(bd->rmap, sub_status_reg[i], &sub_status); in bd9995x_irq_handler_thread()
556 dev_err(bd->dev, "Failed to read IRQ sub-status\n"); in bd9995x_irq_handler_thread()
562 dev_err(bd->dev, "Failed to read IRQ sub-mask\n"); in bd9995x_irq_handler_thread()
569 ret = regmap_write(bd->rmap, sub_status_reg[i], sub_status); in bd9995x_irq_handler_thread()
571 dev_err(bd->dev, "Failed to ack sub-IRQ\n"); in bd9995x_irq_handler_thread()
576 ret = regmap_field_write(bd->rmap_fields[F_INT0_SET], mask); in bd9995x_irq_handler_thread()
582 ret = bd9995x_get_chip_state(bd, &state); in bd9995x_irq_handler_thread()
584 dev_err(bd->dev, "Failed to read chip state\n"); in bd9995x_irq_handler_thread()
586 mutex_lock(&bd->lock); in bd9995x_irq_handler_thread()
587 bd->state = state; in bd9995x_irq_handler_thread()
588 mutex_unlock(&bd->lock); in bd9995x_irq_handler_thread()
590 power_supply_changed(bd->charger); in bd9995x_irq_handler_thread()
596 ret = regmap_field_write(bd->rmap_fields[F_INT0_SET], mask); in bd9995x_irq_handler_thread()
598 dev_err(bd->dev, in bd9995x_irq_handler_thread()
604 static int __bd9995x_chip_reset(struct bd9995x_device *bd) in __bd9995x_chip_reset() argument
610 ret = regmap_raw_write(bd->rmap, SYSTEM_CTRL_SET, &tmp, 2); in __bd9995x_chip_reset()
615 ret = regmap_field_read(bd->rmap_fields[F_OTPLD_STATE], &state); in __bd9995x_chip_reset()
623 dev_err(bd->dev, "chip reset not completed\n"); in __bd9995x_chip_reset()
628 ret = regmap_raw_write(bd->rmap, SYSTEM_CTRL_SET, &tmp, 2); in __bd9995x_chip_reset()
633 static int bd9995x_hw_init(struct bd9995x_device *bd) in bd9995x_hw_init() argument
638 struct bd9995x_init_data *id = &bd->init_data; in bd9995x_hw_init()
707 ret = __bd9995x_chip_reset(bd); in bd9995x_hw_init()
713 ret = regmap_field_write(bd->rmap_fields[init_data[i].id], in bd9995x_hw_init()
716 dev_err(bd->dev, "failed to initialize charger (%d)\n", in bd9995x_hw_init()
722 ret = bd9995x_get_chip_state(bd, &state); in bd9995x_hw_init()
726 mutex_lock(&bd->lock); in bd9995x_hw_init()
727 bd->state = state; in bd9995x_hw_init()
728 mutex_unlock(&bd->lock); in bd9995x_hw_init()
824 static int bd9995x_fw_probe(struct bd9995x_device *bd) in bd9995x_fw_probe() argument
832 struct bd9995x_init_data *init = &bd->init_data; in bd9995x_fw_probe()
899 ret = power_supply_get_battery_info(bd->charger, &info); in bd9995x_fw_probe()
924 dev_err(bd->dev, "Unsupported value for %s\n", in bd9995x_fw_probe()
927 power_supply_put_battery_info(bd->charger, info); in bd9995x_fw_probe()
931 dev_warn(bd->dev, in bd9995x_fw_probe()
938 power_supply_put_battery_info(bd->charger, info); in bd9995x_fw_probe()
941 ret = device_property_read_u32(bd->dev, props[i].prop, in bd9995x_fw_probe()
944 dev_err(bd->dev, "failed to read %s", props[i].prop); in bd9995x_fw_probe()
954 dev_err(bd->dev, "Unsupported value for '%s'\n", in bd9995x_fw_probe()
961 dev_warn(bd->dev, in bd9995x_fw_probe()
972 static void bd9995x_chip_reset(void *bd) in bd9995x_chip_reset() argument
974 __bd9995x_chip_reset(bd); in bd9995x_chip_reset()
980 struct bd9995x_device *bd; in bd9995x_probe() local
985 bd = devm_kzalloc(dev, sizeof(*bd), GFP_KERNEL); in bd9995x_probe()
986 if (!bd) in bd9995x_probe()
989 bd->client = client; in bd9995x_probe()
990 bd->dev = dev; in bd9995x_probe()
991 psy_cfg.drv_data = bd; in bd9995x_probe()
994 mutex_init(&bd->lock); in bd9995x_probe()
996 bd->rmap = devm_regmap_init_i2c(client, &bd9995x_regmap_config); in bd9995x_probe()
997 if (IS_ERR(bd->rmap)) { in bd9995x_probe()
999 return PTR_ERR(bd->rmap); in bd9995x_probe()
1005 bd->rmap_fields[i] = devm_regmap_field_alloc(dev, bd->rmap, in bd9995x_probe()
1007 if (IS_ERR(bd->rmap_fields[i])) { in bd9995x_probe()
1009 return PTR_ERR(bd->rmap_fields[i]); in bd9995x_probe()
1013 i2c_set_clientdata(client, bd); in bd9995x_probe()
1015 ret = regmap_field_read(bd->rmap_fields[F_CHIP_ID], &bd->chip_id); in bd9995x_probe()
1021 if (bd->chip_id != BD99954_ID) { in bd9995x_probe()
1023 bd->chip_id); in bd9995x_probe()
1027 ret = regmap_field_read(bd->rmap_fields[F_CHIP_REV], &bd->chip_rev); in bd9995x_probe()
1033 dev_info(bd->dev, "Found BD99954 chip rev %d\n", bd->chip_rev); in bd9995x_probe()
1039 bd->charger = devm_power_supply_register(bd->dev, in bd9995x_probe()
1042 if (IS_ERR(bd->charger)) { in bd9995x_probe()
1044 return PTR_ERR(bd->charger); in bd9995x_probe()
1047 ret = bd9995x_fw_probe(bd); in bd9995x_probe()
1053 ret = bd9995x_hw_init(bd); in bd9995x_probe()
1059 ret = devm_add_action_or_reset(dev, bd9995x_chip_reset, bd); in bd9995x_probe()
1066 BD9995X_IRQ_PIN, bd); in bd9995x_probe()