• Home
  • Raw
  • Download

Lines Matching refs:info

154 static int measure_12bit_voltage(struct pm860x_battery_info *info,  in measure_12bit_voltage()  argument
160 ret = pm860x_bulk_read(info->i2c, offset, 2, buf); in measure_12bit_voltage()
170 static int measure_vbatt(struct pm860x_battery_info *info, int state, in measure_vbatt() argument
178 ret = measure_12bit_voltage(info, PM8607_VBAT_MEAS1, data); in measure_vbatt()
194 ret = pm860x_bulk_read(info->i2c, PM8607_LDO5, 5, buf); in measure_vbatt()
213 static int measure_current(struct pm860x_battery_info *info, int *data) in measure_current() argument
219 ret = pm860x_bulk_read(info->i2c, PM8607_IBAT_MEAS1, 2, buf); in measure_current()
229 static int set_charger_current(struct pm860x_battery_info *info, int data, in set_charger_current() argument
238 *old = pm860x_reg_read(info->i2c, PM8607_CHG_CTRL2); in set_charger_current()
240 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL2, 0x1f, data); in set_charger_current()
246 static int read_ccnt(struct pm860x_battery_info *info, int offset, in read_ccnt() argument
252 ret = pm860x_set_bits(info->i2c, PM8607_CCNT, 7, offset & 7); in read_ccnt()
255 ret = pm860x_bulk_read(info->i2c, PM8607_CCNT_MEAS1, 2, buf); in read_ccnt()
264 static int calc_ccnt(struct pm860x_battery_info *info, struct ccnt *ccnt) in calc_ccnt() argument
270 ret = read_ccnt(info, CCNT_POS1, &data); in calc_ccnt()
274 ret = read_ccnt(info, CCNT_POS2, &data); in calc_ccnt()
280 ret = read_ccnt(info, CCNT_NEG1, &data); in calc_ccnt()
284 ret = read_ccnt(info, CCNT_NEG2, &data); in calc_ccnt()
291 ret = read_ccnt(info, CCNT_SPOS, &data); in calc_ccnt()
295 ret = read_ccnt(info, CCNT_SNEG, &data); in calc_ccnt()
311 static int clear_ccnt(struct pm860x_battery_info *info, struct ccnt *ccnt) in clear_ccnt() argument
317 read_ccnt(info, CCNT_POS1, &data); in clear_ccnt()
318 read_ccnt(info, CCNT_POS2, &data); in clear_ccnt()
319 read_ccnt(info, CCNT_NEG1, &data); in clear_ccnt()
320 read_ccnt(info, CCNT_NEG2, &data); in clear_ccnt()
321 read_ccnt(info, CCNT_SPOS, &data); in clear_ccnt()
322 read_ccnt(info, CCNT_SNEG, &data); in clear_ccnt()
327 static int calc_ocv(struct pm860x_battery_info *info, int *ocv) in calc_ocv() argument
341 ret = measure_vbatt(info, OCV_MODE_ACTIVE, &data); in calc_ocv()
345 ret = measure_current(info, &data); in calc_ocv()
353 mutex_lock(&info->lock); in calc_ocv()
354 if (info->present) in calc_ocv()
355 *ocv = vbatt_avg - ibatt_avg * info->resistor / 1000; in calc_ocv()
358 mutex_unlock(&info->lock); in calc_ocv()
359 dev_dbg(info->dev, "VBAT average:%d, OCV:%d\n", vbatt_avg, *ocv); in calc_ocv()
366 static int calc_soc(struct pm860x_battery_info *info, int state, int *soc) in calc_soc() argument
378 ret = calc_ocv(info, &ocv); in calc_soc()
381 ret = measure_vbatt(info, OCV_MODE_SLEEP, &ocv); in calc_soc()
404 struct pm860x_battery_info *info = data; in pm860x_coulomb_handler() local
406 calc_ccnt(info, &ccnt_data); in pm860x_coulomb_handler()
412 struct pm860x_battery_info *info = data; in pm860x_batt_handler() local
415 mutex_lock(&info->lock); in pm860x_batt_handler()
416 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2); in pm860x_batt_handler()
418 info->present = 1; in pm860x_batt_handler()
419 info->temp_type = PM860X_TEMP_TBAT; in pm860x_batt_handler()
421 info->present = 0; in pm860x_batt_handler()
422 info->temp_type = PM860X_TEMP_TINT; in pm860x_batt_handler()
424 mutex_unlock(&info->lock); in pm860x_batt_handler()
426 clear_ccnt(info, &ccnt_data); in pm860x_batt_handler()
430 static void pm860x_init_battery(struct pm860x_battery_info *info) in pm860x_init_battery() argument
440 if (info->temp_type == PM860X_TEMP_TINT) in pm860x_init_battery()
442 ret = pm860x_set_bits(info->i2c, PM8607_MEAS_EN1, data, data); in pm860x_init_battery()
448 ret = pm860x_set_bits(info->i2c, PM8607_MEAS_EN3, data, data); in pm860x_init_battery()
453 ret = pm860x_reg_write(info->i2c, PM8607_MEAS_OFF_TIME1, 0x82); in pm860x_init_battery()
456 ret = pm860x_reg_write(info->i2c, PM8607_MEAS_OFF_TIME2, 0x6c); in pm860x_init_battery()
461 ret = pm860x_set_bits(info->i2c, PM8607_GPADC_MISC1, in pm860x_init_battery()
467 ret = pm860x_set_bits(info->i2c, PM8607_CHG_CTRL6, in pm860x_init_battery()
472 ret = pm860x_set_bits(info->i2c, PM8607_CCNT, 7 << 3, in pm860x_init_battery()
478 ret = pm860x_set_bits(info->i2c, PM8607_GP_BIAS2, 0xF << 4, in pm860x_init_battery()
484 mutex_lock(&info->lock); in pm860x_init_battery()
485 ret = pm860x_reg_read(info->i2c, PM8607_STATUS_2); in pm860x_init_battery()
487 mutex_unlock(&info->lock); in pm860x_init_battery()
491 info->present = 1; in pm860x_init_battery()
492 info->temp_type = PM860X_TEMP_TBAT; in pm860x_init_battery()
494 info->present = 0; in pm860x_init_battery()
495 info->temp_type = PM860X_TEMP_TINT; in pm860x_init_battery()
497 mutex_unlock(&info->lock); in pm860x_init_battery()
499 ret = calc_soc(info, OCV_MODE_ACTIVE, &soc); in pm860x_init_battery()
503 data = pm860x_reg_read(info->i2c, PM8607_POWER_UP_LOG); in pm860x_init_battery()
506 dev_dbg(info->dev, "battery wake up? %s\n", in pm860x_init_battery()
511 buf[0] = pm860x_reg_read(info->i2c, PM8607_RTC_MISC2); in pm860x_init_battery()
512 buf[1] = pm860x_reg_read(info->i2c, PM8607_RTC1); in pm860x_init_battery()
515 info->start_soc = soc; in pm860x_init_battery()
517 info->start_soc = soc; in pm860x_init_battery()
519 info->start_soc = data; in pm860x_init_battery()
520 dev_dbg(info->dev, "soc_rtc %d, soc_ocv :%d\n", data, soc); in pm860x_init_battery()
522 pm860x_set_bits(info->i2c, PM8607_POWER_UP_LOG, in pm860x_init_battery()
524 info->start_soc = soc; in pm860x_init_battery()
526 info->last_capacity = info->start_soc; in pm860x_init_battery()
527 dev_dbg(info->dev, "init soc : %d\n", info->last_capacity); in pm860x_init_battery()
532 static void set_temp_threshold(struct pm860x_battery_info *info, in set_temp_threshold() argument
542 pm860x_reg_write(info->i2c, PM8607_GPADC1_HIGHTH, data); in set_temp_threshold()
543 dev_dbg(info->dev, "TEMP_HIGHTH : min: %d, 0x%x\n", min, data); in set_temp_threshold()
549 pm860x_reg_write(info->i2c, PM8607_GPADC1_LOWTH, data); in set_temp_threshold()
550 dev_dbg(info->dev, "TEMP_LOWTH:max : %d, 0x%x\n", max, data); in set_temp_threshold()
553 static int measure_temp(struct pm860x_battery_info *info, int *data) in measure_temp() argument
560 if (info->temp_type == PM860X_TEMP_TINT) { in measure_temp()
561 ret = measure_12bit_voltage(info, PM8607_TINT_MEAS1, data); in measure_temp()
566 ret = measure_12bit_voltage(info, PM8607_GPADC1_MEAS1, data); in measure_temp()
575 set_temp_threshold(info, 0, max); in measure_temp()
579 set_temp_threshold(info, 0, max); in measure_temp()
584 set_temp_threshold(info, min, max); in measure_temp()
589 set_temp_threshold(info, min, max); in measure_temp()
594 set_temp_threshold(info, min, max); in measure_temp()
599 set_temp_threshold(info, min, max); in measure_temp()
604 set_temp_threshold(info, min, max); in measure_temp()
607 set_temp_threshold(info, min, 0); in measure_temp()
611 dev_dbg(info->dev, "temp_C:%d C,temp_mv:%d mv\n", temp, *data); in measure_temp()
617 static int calc_resistor(struct pm860x_battery_info *info) in calc_resistor() argument
628 ret = measure_current(info, &data); in calc_resistor()
633 ret = measure_vbatt(info, OCV_MODE_ACTIVE, &data); in calc_resistor()
641 if (set_charger_current(info, 500, &chg_current)) in calc_resistor()
651 ret = measure_vbatt(info, OCV_MODE_ACTIVE, &data); in calc_resistor()
655 ret = measure_current(info, &data); in calc_resistor()
665 if (set_charger_current(info, 100, &ret)) in calc_resistor()
674 ret = measure_vbatt(info, OCV_MODE_ACTIVE, &data); in calc_resistor()
678 ret = measure_current(info, &data); in calc_resistor()
689 if (set_charger_current(info, chg_current, &ret)) in calc_resistor()
697 if ((data - info->resistor > 0) && in calc_resistor()
698 (data - info->resistor < info->resistor)) in calc_resistor()
699 info->resistor = data; in calc_resistor()
700 if ((info->resistor - data > 0) && in calc_resistor()
701 (info->resistor - data < data)) in calc_resistor()
702 info->resistor = data; in calc_resistor()
707 set_charger_current(info, chg_current, &ret); in calc_resistor()
712 static int calc_capacity(struct pm860x_battery_info *info, int *cap) in calc_capacity() argument
720 ret = calc_ccnt(info, &ccnt_data); in calc_capacity()
724 data = info->max_capacity * info->start_soc / 100; in calc_capacity()
729 clear_ccnt(info, &ccnt_data); in calc_capacity()
730 calc_soc(info, OCV_MODE_ACTIVE, &info->start_soc); in calc_capacity()
731 dev_dbg(info->dev, "restart soc = %d !\n", in calc_capacity()
732 info->start_soc); in calc_capacity()
736 cap_cc = cap_cc * 100 / info->max_capacity; in calc_capacity()
742 dev_dbg(info->dev, "%s, last cap : %d", __func__, in calc_capacity()
743 info->last_capacity); in calc_capacity()
745 ret = measure_current(info, &ibat); in calc_capacity()
750 ret = calc_soc(info, OCV_MODE_ACTIVE, &cap_ocv); in calc_capacity()
752 cap_ocv = info->last_capacity; in calc_capacity()
753 ret = measure_vbatt(info, OCV_MODE_ACTIVE, &data); in calc_capacity()
775 if (*cap > info->last_capacity) in calc_capacity()
776 *cap = info->last_capacity; in calc_capacity()
780 info->last_capacity = *cap; in calc_capacity()
782 dev_dbg(info->dev, "%s, cap_ocv:%d cap_cc:%d, cap:%d\n", in calc_capacity()
789 pm860x_set_bits(info->i2c, PM8607_RTC_MISC2, RTC_SOC_5LSB, in calc_capacity()
791 pm860x_set_bits(info->i2c, PM8607_RTC1, RTC_SOC_3MSB, in calc_capacity()
800 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent); in pm860x_external_power_changed() local
802 calc_resistor(info); in pm860x_external_power_changed()
809 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent); in pm860x_batt_get_prop() local
815 val->intval = info->present; in pm860x_batt_get_prop()
818 ret = calc_capacity(info, &data); in pm860x_batt_get_prop()
826 if (!info->present) in pm860x_batt_get_prop()
835 ret = measure_vbatt(info, OCV_MODE_ACTIVE, &data); in pm860x_batt_get_prop()
842 ret = calc_ocv(info, &data); in pm860x_batt_get_prop()
848 ret = measure_current(info, &data); in pm860x_batt_get_prop()
854 if (info->present) { in pm860x_batt_get_prop()
855 ret = measure_temp(info, &data); in pm860x_batt_get_prop()
875 struct pm860x_battery_info *info = dev_get_drvdata(psy->dev.parent); in pm860x_batt_set_prop() local
879 clear_ccnt(info, &ccnt_data); in pm860x_batt_set_prop()
880 info->start_soc = 100; in pm860x_batt_set_prop()
881 dev_dbg(info->dev, "chg done, update soc = %d\n", in pm860x_batt_set_prop()
882 info->start_soc); in pm860x_batt_set_prop()
915 struct pm860x_battery_info *info; in pm860x_battery_probe() local
919 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in pm860x_battery_probe()
920 if (!info) in pm860x_battery_probe()
923 info->irq_cc = platform_get_irq(pdev, 0); in pm860x_battery_probe()
924 if (info->irq_cc <= 0) in pm860x_battery_probe()
927 info->irq_batt = platform_get_irq(pdev, 1); in pm860x_battery_probe()
928 if (info->irq_batt <= 0) in pm860x_battery_probe()
931 info->chip = chip; in pm860x_battery_probe()
932 info->i2c = in pm860x_battery_probe()
934 info->dev = &pdev->dev; in pm860x_battery_probe()
935 info->status = POWER_SUPPLY_STATUS_UNKNOWN; in pm860x_battery_probe()
938 mutex_init(&info->lock); in pm860x_battery_probe()
939 platform_set_drvdata(pdev, info); in pm860x_battery_probe()
941 pm860x_init_battery(info); in pm860x_battery_probe()
944 info->max_capacity = pdata->max_capacity; in pm860x_battery_probe()
946 info->max_capacity = 1500; /* set default capacity */ in pm860x_battery_probe()
948 info->resistor = pdata->resistor; in pm860x_battery_probe()
950 info->resistor = 300; /* set default internal resistor */ in pm860x_battery_probe()
952 info->battery = devm_power_supply_register(&pdev->dev, in pm860x_battery_probe()
955 if (IS_ERR(info->battery)) in pm860x_battery_probe()
956 return PTR_ERR(info->battery); in pm860x_battery_probe()
957 info->battery->dev.parent = &pdev->dev; in pm860x_battery_probe()
959 ret = devm_request_threaded_irq(chip->dev, info->irq_cc, NULL, in pm860x_battery_probe()
961 "coulomb", info); in pm860x_battery_probe()
964 info->irq_cc, ret); in pm860x_battery_probe()
968 ret = devm_request_threaded_irq(chip->dev, info->irq_batt, NULL, in pm860x_battery_probe()
970 IRQF_ONESHOT, "battery", info); in pm860x_battery_probe()
973 info->irq_batt, ret); in pm860x_battery_probe()