Lines Matching refs:info

149 static int fuel_gauge_reg_readb(struct axp288_fg_info *info, int reg)  in fuel_gauge_reg_readb()  argument
154 ret = regmap_read(info->regmap, reg, &val); in fuel_gauge_reg_readb()
156 dev_err(info->dev, "Error reading reg 0x%02x err: %d\n", reg, ret); in fuel_gauge_reg_readb()
163 static int fuel_gauge_reg_writeb(struct axp288_fg_info *info, int reg, u8 val) in fuel_gauge_reg_writeb() argument
167 ret = regmap_write(info->regmap, reg, (unsigned int)val); in fuel_gauge_reg_writeb()
170 dev_err(info->dev, "Error writing reg 0x%02x err: %d\n", reg, ret); in fuel_gauge_reg_writeb()
175 static int fuel_gauge_read_15bit_word(struct axp288_fg_info *info, int reg) in fuel_gauge_read_15bit_word() argument
180 ret = regmap_bulk_read(info->regmap, reg, buf, 2); in fuel_gauge_read_15bit_word()
182 dev_err(info->dev, "Error reading reg 0x%02x err: %d\n", reg, ret); in fuel_gauge_read_15bit_word()
188 dev_err(info->dev, "Error reg 0x%02x contents not valid\n", reg); in fuel_gauge_read_15bit_word()
195 static int fuel_gauge_read_12bit_word(struct axp288_fg_info *info, int reg) in fuel_gauge_read_12bit_word() argument
200 ret = regmap_bulk_read(info->regmap, reg, buf, 2); in fuel_gauge_read_12bit_word()
202 dev_err(info->dev, "Error reading reg 0x%02x err: %d\n", reg, ret); in fuel_gauge_read_12bit_word()
210 static int fuel_gauge_update_registers(struct axp288_fg_info *info) in fuel_gauge_update_registers() argument
214 if (info->valid && time_before(jiffies, info->last_updated + AXP288_REG_UPDATE_INTERVAL)) in fuel_gauge_update_registers()
217 dev_dbg(info->dev, "Fuel Gauge updating register values...\n"); in fuel_gauge_update_registers()
223 ret = fuel_gauge_reg_readb(info, AXP20X_PWR_INPUT_STATUS); in fuel_gauge_update_registers()
226 info->pwr_stat = ret; in fuel_gauge_update_registers()
228 ret = fuel_gauge_reg_readb(info, AXP20X_FG_RES); in fuel_gauge_update_registers()
231 info->fg_res = ret; in fuel_gauge_update_registers()
233 ret = iio_read_channel_raw(info->iio_channel[BAT_VOLT], &info->bat_volt); in fuel_gauge_update_registers()
237 if (info->pwr_stat & PS_STAT_BAT_CHRG_DIR) { in fuel_gauge_update_registers()
238 info->d_curr = 0; in fuel_gauge_update_registers()
239 ret = iio_read_channel_raw(info->iio_channel[BAT_CHRG_CURR], &info->c_curr); in fuel_gauge_update_registers()
243 info->c_curr = 0; in fuel_gauge_update_registers()
244 ret = iio_read_channel_raw(info->iio_channel[BAT_D_CURR], &info->d_curr); in fuel_gauge_update_registers()
249 ret = fuel_gauge_read_12bit_word(info, AXP288_FG_OCVH_REG); in fuel_gauge_update_registers()
252 info->ocv = ret; in fuel_gauge_update_registers()
254 ret = fuel_gauge_read_15bit_word(info, AXP288_FG_CC_MTR1_REG); in fuel_gauge_update_registers()
257 info->fg_cc_mtr1 = ret; in fuel_gauge_update_registers()
259 ret = fuel_gauge_read_15bit_word(info, AXP288_FG_DES_CAP1_REG); in fuel_gauge_update_registers()
262 info->fg_des_cap1 = ret; in fuel_gauge_update_registers()
264 info->last_updated = jiffies; in fuel_gauge_update_registers()
265 info->valid = 1; in fuel_gauge_update_registers()
272 static void fuel_gauge_get_status(struct axp288_fg_info *info) in fuel_gauge_get_status() argument
274 int pwr_stat = info->pwr_stat; in fuel_gauge_get_status()
275 int fg_res = info->fg_res; in fuel_gauge_get_status()
276 int curr = info->d_curr; in fuel_gauge_get_status()
287 info->status = POWER_SUPPLY_STATUS_FULL; in fuel_gauge_get_status()
300 info->status = POWER_SUPPLY_STATUS_FULL; in fuel_gauge_get_status()
306 info->status = POWER_SUPPLY_STATUS_CHARGING; in fuel_gauge_get_status()
308 info->status = POWER_SUPPLY_STATUS_DISCHARGING; in fuel_gauge_get_status()
311 static int fuel_gauge_battery_health(struct axp288_fg_info *info) in fuel_gauge_battery_health() argument
313 int vocv = VOLTAGE_FROM_ADC(info->ocv); in fuel_gauge_battery_health()
316 if (vocv > info->max_volt) in fuel_gauge_battery_health()
328 struct axp288_fg_info *info = power_supply_get_drvdata(ps); in fuel_gauge_get_property() local
331 mutex_lock(&info->lock); in fuel_gauge_get_property()
333 ret = fuel_gauge_update_registers(info); in fuel_gauge_get_property()
339 fuel_gauge_get_status(info); in fuel_gauge_get_property()
340 val->intval = info->status; in fuel_gauge_get_property()
343 val->intval = fuel_gauge_battery_health(info); in fuel_gauge_get_property()
346 value = VOLTAGE_FROM_ADC(info->bat_volt); in fuel_gauge_get_property()
350 value = VOLTAGE_FROM_ADC(info->ocv); in fuel_gauge_get_property()
354 if (info->d_curr > 0) in fuel_gauge_get_property()
355 value = -1 * info->d_curr; in fuel_gauge_get_property()
357 value = info->c_curr; in fuel_gauge_get_property()
362 if (info->pwr_op & CHRG_STAT_BAT_PRESENT) in fuel_gauge_get_property()
368 if (!(info->fg_res & FG_REP_CAP_VALID)) in fuel_gauge_get_property()
369 dev_err(info->dev, "capacity measurement not valid\n"); in fuel_gauge_get_property()
370 val->intval = (info->fg_res & FG_REP_CAP_VAL_MASK); in fuel_gauge_get_property()
373 val->intval = (info->low_cap & 0x0f); in fuel_gauge_get_property()
379 val->intval = info->fg_cc_mtr1 * FG_DES_CAP_RES_LSB; in fuel_gauge_get_property()
382 val->intval = info->fg_des_cap1 * FG_DES_CAP_RES_LSB; in fuel_gauge_get_property()
385 val->intval = PROP_VOLT(info->max_volt); in fuel_gauge_get_property()
392 mutex_unlock(&info->lock); in fuel_gauge_get_property()
400 struct axp288_fg_info *info = power_supply_get_drvdata(ps); in fuel_gauge_set_property() local
403 mutex_lock(&info->lock); in fuel_gauge_set_property()
410 new_low_cap = info->low_cap; in fuel_gauge_set_property()
413 ret = fuel_gauge_reg_writeb(info, AXP288_FG_LOW_CAP_REG, new_low_cap); in fuel_gauge_set_property()
415 info->low_cap = new_low_cap; in fuel_gauge_set_property()
422 mutex_unlock(&info->lock); in fuel_gauge_set_property()
444 struct axp288_fg_info *info = dev; in fuel_gauge_thread_handler() local
448 if (info->irq[i] == irq) in fuel_gauge_thread_handler()
453 dev_warn(info->dev, "spurious interrupt!!\n"); in fuel_gauge_thread_handler()
459 dev_info(info->dev, "Quit Battery under temperature in work mode IRQ (QWBTU)\n"); in fuel_gauge_thread_handler()
462 dev_info(info->dev, "Battery under temperature in work mode IRQ (WBTU)\n"); in fuel_gauge_thread_handler()
465 dev_info(info->dev, "Quit Battery over temperature in work mode IRQ (QWBTO)\n"); in fuel_gauge_thread_handler()
468 dev_info(info->dev, "Battery over temperature in work mode IRQ (WBTO)\n"); in fuel_gauge_thread_handler()
471 dev_info(info->dev, "Low Batt Warning(2) INTR\n"); in fuel_gauge_thread_handler()
474 dev_info(info->dev, "Low Batt Warning(1) INTR\n"); in fuel_gauge_thread_handler()
477 dev_warn(info->dev, "Spurious Interrupt!!!\n"); in fuel_gauge_thread_handler()
480 info->valid = 0; /* Force updating of the cached registers */ in fuel_gauge_thread_handler()
482 power_supply_changed(info->bat); in fuel_gauge_thread_handler()
488 struct axp288_fg_info *info = power_supply_get_drvdata(psy); in fuel_gauge_external_power_changed() local
490 info->valid = 0; /* Force updating of the cached registers */ in fuel_gauge_external_power_changed()
491 power_supply_changed(info->bat); in fuel_gauge_external_power_changed()
505 static void fuel_gauge_init_irq(struct axp288_fg_info *info, struct platform_device *pdev) in fuel_gauge_init_irq() argument
511 info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq); in fuel_gauge_init_irq()
512 if (info->irq[i] < 0) { in fuel_gauge_init_irq()
513 dev_warn(info->dev, "regmap_irq get virq failed for IRQ %d: %d\n", in fuel_gauge_init_irq()
514 pirq, info->irq[i]); in fuel_gauge_init_irq()
515 info->irq[i] = -1; in fuel_gauge_init_irq()
518 ret = request_threaded_irq(info->irq[i], in fuel_gauge_init_irq()
520 IRQF_ONESHOT, DEV_NAME, info); in fuel_gauge_init_irq()
522 dev_warn(info->dev, "request irq failed for IRQ %d: %d\n", in fuel_gauge_init_irq()
523 pirq, info->irq[i]); in fuel_gauge_init_irq()
524 info->irq[i] = -1; in fuel_gauge_init_irq()
532 free_irq(info->irq[i - 1], info); in fuel_gauge_init_irq()
533 info->irq[i - 1] = -1; in fuel_gauge_init_irq()
617 struct axp288_fg_info *info; in axp288_fuel_gauge_probe() local
630 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in axp288_fuel_gauge_probe()
631 if (!info) in axp288_fuel_gauge_probe()
634 info->dev = &pdev->dev; in axp288_fuel_gauge_probe()
635 info->regmap = axp20x->regmap; in axp288_fuel_gauge_probe()
636 info->regmap_irqc = axp20x->regmap_irqc; in axp288_fuel_gauge_probe()
637 info->status = POWER_SUPPLY_STATUS_UNKNOWN; in axp288_fuel_gauge_probe()
638 info->valid = 0; in axp288_fuel_gauge_probe()
640 platform_set_drvdata(pdev, info); in axp288_fuel_gauge_probe()
642 mutex_init(&info->lock); in axp288_fuel_gauge_probe()
650 info->iio_channel[i] = in axp288_fuel_gauge_probe()
652 if (IS_ERR(info->iio_channel[i])) { in axp288_fuel_gauge_probe()
653 ret = PTR_ERR(info->iio_channel[i]); in axp288_fuel_gauge_probe()
680 ret = fuel_gauge_reg_readb(info, AXP288_FG_DES_CAP1_REG); in axp288_fuel_gauge_probe()
690 ret = fuel_gauge_reg_readb(info, AXP20X_CHRG_CTRL1); in axp288_fuel_gauge_probe()
695 info->max_volt = 4100; in axp288_fuel_gauge_probe()
698 info->max_volt = 4150; in axp288_fuel_gauge_probe()
701 info->max_volt = 4200; in axp288_fuel_gauge_probe()
704 info->max_volt = 4350; in axp288_fuel_gauge_probe()
708 ret = fuel_gauge_reg_readb(info, AXP20X_PWR_OP_MODE); in axp288_fuel_gauge_probe()
711 info->pwr_op = ret; in axp288_fuel_gauge_probe()
713 ret = fuel_gauge_reg_readb(info, AXP288_FG_LOW_CAP_REG); in axp288_fuel_gauge_probe()
716 info->low_cap = ret; in axp288_fuel_gauge_probe()
724 psy_cfg.drv_data = info; in axp288_fuel_gauge_probe()
725 info->bat = power_supply_register(&pdev->dev, &fuel_gauge_desc, &psy_cfg); in axp288_fuel_gauge_probe()
726 if (IS_ERR(info->bat)) { in axp288_fuel_gauge_probe()
727 ret = PTR_ERR(info->bat); in axp288_fuel_gauge_probe()
732 fuel_gauge_init_irq(info, pdev); in axp288_fuel_gauge_probe()
738 if (!IS_ERR_OR_NULL(info->iio_channel[i])) in axp288_fuel_gauge_probe()
739 iio_channel_release(info->iio_channel[i]); in axp288_fuel_gauge_probe()
752 struct axp288_fg_info *info = platform_get_drvdata(pdev); in axp288_fuel_gauge_remove() local
755 power_supply_unregister(info->bat); in axp288_fuel_gauge_remove()
758 if (info->irq[i] >= 0) in axp288_fuel_gauge_remove()
759 free_irq(info->irq[i], info); in axp288_fuel_gauge_remove()
762 iio_channel_release(info->iio_channel[i]); in axp288_fuel_gauge_remove()