Lines Matching +full:charger +full:- +full:sense +full:- +full:resistor +full:- +full:ohms

1 // SPDX-License-Identifier: GPL-2.0+
3 * Charger Driver for Rockchip rk817
12 #include <linux/devm-helpers.h>
68 * soc - state of charge - like the BSP this is stored as a percentage,
143 return -EINVAL; in rk817_chg_cur_to_reg()
166 return -EINVAL; in rk817_chg_cur_from_reg()
170 static void rk817_bat_calib_vol(struct rk817_charger *charger) in rk817_bat_calib_vol() argument
177 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_VCALIB0_H, in rk817_bat_calib_vol()
181 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_VCALIB1_H, in rk817_bat_calib_vol()
186 charger->voltage_k = (4025 - 2300) * 1000 / in rk817_bat_calib_vol()
187 ((vcalib1 - vcalib0) ? (vcalib1 - vcalib0) : 1); in rk817_bat_calib_vol()
188 charger->voltage_b = 4025 - (charger->voltage_k * vcalib1) / 1000; in rk817_bat_calib_vol()
191 static void rk817_bat_calib_cur(struct rk817_charger *charger) in rk817_bat_calib_cur() argument
196 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_IOFFSET_H, in rk817_bat_calib_cur()
198 regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_CAL_OFFSET_H, in rk817_bat_calib_cur()
206 static int rk817_record_battery_nvram_values(struct rk817_charger *charger) in rk817_record_battery_nvram_values() argument
215 put_unaligned_le24(charger->soc, bulk_reg); in rk817_record_battery_nvram_values()
216 ret = regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_BAT_R1, in rk817_record_battery_nvram_values()
224 rsoc = (charger->soc * charger->fcc_mah) / 100000; in rk817_record_battery_nvram_values()
226 ret = regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_DATA0, in rk817_record_battery_nvram_values()
231 put_unaligned_le24(charger->fcc_mah, bulk_reg); in rk817_record_battery_nvram_values()
232 ret = regmap_bulk_write(charger->rk808->regmap, RK817_GAS_GAUGE_DATA3, in rk817_record_battery_nvram_values()
240 static int rk817_bat_calib_cap(struct rk817_charger *charger) in rk817_bat_calib_cap() argument
242 struct rk808 *rk808 = charger->rk808; in rk817_bat_calib_cap()
248 if (charger->charge_status == CHARGE_FINISH && (!charger->soc_cal)) { in rk817_bat_calib_cap()
260 charger->soc = 100000; in rk817_bat_calib_cap()
261 charge_now_adc = CHARGE_TO_ADC(charger->fcc_mah, in rk817_bat_calib_cap()
262 charger->res_div); in rk817_bat_calib_cap()
264 regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_Q_INIT_H3, in rk817_bat_calib_cap()
267 charger->soc_cal = 1; in rk817_bat_calib_cap()
268 dev_dbg(charger->dev, in rk817_bat_calib_cap()
270 charger->soc, charger->fcc_mah * 1000); in rk817_bat_calib_cap()
277 if (charger->charge_status == CHARGE_FINISH && charger->soc_cal) { in rk817_bat_calib_cap()
278 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3, in rk817_bat_calib_cap()
284 charger->res_div); in rk817_bat_calib_cap()
287 * Re-init columb counter with updated values to correct drift. in rk817_bat_calib_cap()
289 if (charge_now / 1000 > charger->fcc_mah) { in rk817_bat_calib_cap()
290 dev_dbg(charger->dev, in rk817_bat_calib_cap()
298 charge_now_adc = CHARGE_TO_ADC(charger->fcc_mah, in rk817_bat_calib_cap()
299 charger->res_div); in rk817_bat_calib_cap()
301 regmap_bulk_write(rk808->regmap, in rk817_bat_calib_cap()
315 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_BAT_VOL_H, in rk817_bat_calib_cap()
318 volt_avg = (charger->voltage_k * tmp) + 1000 * charger->voltage_b; in rk817_bat_calib_cap()
319 if (volt_avg <= charger->bat_voltage_min_design_uv && in rk817_bat_calib_cap()
320 charger->soc_cal) { in rk817_bat_calib_cap()
321 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3, in rk817_bat_calib_cap()
325 charger->res_div); in rk817_bat_calib_cap()
331 charger->fcc_mah = charger->fcc_mah - (charge_now / 1000); in rk817_bat_calib_cap()
333 dev_dbg(charger->dev, in rk817_bat_calib_cap()
335 charger->fcc_mah * 1000); in rk817_bat_calib_cap()
338 rk817_record_battery_nvram_values(charger); in rk817_bat_calib_cap()
343 static void rk817_read_props(struct rk817_charger *charger) in rk817_read_props() argument
354 regmap_read(charger->rk808->regmap, RK817_GAS_GAUGE_ADC_CONFIG1, &reg); in rk817_read_props()
356 rk817_bat_calib_cur(charger); in rk817_read_props()
357 rk817_bat_calib_vol(charger); in rk817_read_props()
358 regmap_write_bits(charger->rk808->regmap, in rk817_read_props()
365 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3, in rk817_read_props()
368 charger->charge_now_uah = ADC_TO_CHARGE_UAH(tmp, charger->res_div); in rk817_read_props()
369 if (charger->charge_now_uah < 0) in rk817_read_props()
370 charger->charge_now_uah = 0; in rk817_read_props()
371 if (charger->charge_now_uah > charger->fcc_mah * 1000) in rk817_read_props()
372 charger->charge_now_uah = charger->fcc_mah * 1000; in rk817_read_props()
375 charger->soc = charger->charge_now_uah * 100 / charger->fcc_mah; in rk817_read_props()
378 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_BAT_VOL_H, in rk817_read_props()
381 charger->volt_avg_uv = (charger->voltage_k * tmp) + 1000 * in rk817_read_props()
382 charger->voltage_b; in rk817_read_props()
388 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_BAT_CUR_H, in rk817_read_props()
391 charger->cur_avg_ua = ADC_TO_CURRENT(tmp, charger->res_div); in rk817_read_props()
398 regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_OUT, &reg); in rk817_read_props()
399 charger->max_chg_cur_ua = in rk817_read_props()
406 regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_OUT, &reg); in rk817_read_props()
407 charger->max_chg_volt_uv = ((((reg & RK817_CHRG_VOL_SEL) >> 4) * in rk817_read_props()
411 regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_STS, &reg); in rk817_read_props()
412 charger->battery_present = (reg & RK817_BAT_EXS); in rk817_read_props()
415 regmap_read(charger->rk808->regmap, RK817_PMIC_CHRG_STS, &reg); in rk817_read_props()
416 charger->charge_status = (reg >> 4) & 0x07; in rk817_read_props()
419 * Get charger input voltage. Note that on my example hardware (an in rk817_read_props()
430 regmap_bulk_read(charger->rk808->regmap, RK817_GAS_GAUGE_USB_VOL_H, in rk817_read_props()
434 tmp = ((charger->voltage_k * reg / 1000 + charger->voltage_b) * in rk817_read_props()
436 charger->charger_input_volt_avg_uv = tmp * 1000; in rk817_read_props()
438 charger->charger_input_volt_avg_uv = 0; in rk817_read_props()
442 rk817_bat_calib_cap(charger); in rk817_read_props()
449 struct rk817_charger *charger = power_supply_get_drvdata(ps); in rk817_bat_get_prop() local
453 val->intval = charger->battery_present; in rk817_bat_get_prop()
456 if (charger->cur_avg_ua < 0) { in rk817_bat_get_prop()
457 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in rk817_bat_get_prop()
460 switch (charger->charge_status) { in rk817_bat_get_prop()
462 val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; in rk817_bat_get_prop()
466 * observed it but assume it's a pre-charge for a dead in rk817_bat_get_prop()
472 val->intval = POWER_SUPPLY_STATUS_CHARGING; in rk817_bat_get_prop()
475 val->intval = POWER_SUPPLY_STATUS_FULL; in rk817_bat_get_prop()
478 val->intval = POWER_SUPPLY_STATUS_UNKNOWN; in rk817_bat_get_prop()
479 return -EINVAL; in rk817_bat_get_prop()
484 switch (charger->charge_status) { in rk817_bat_get_prop()
487 val->intval = POWER_SUPPLY_CHARGE_TYPE_NONE; in rk817_bat_get_prop()
490 val->intval = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; in rk817_bat_get_prop()
494 val->intval = POWER_SUPPLY_CHARGE_TYPE_STANDARD; in rk817_bat_get_prop()
497 val->intval = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; in rk817_bat_get_prop()
502 val->intval = charger->fcc_mah * 1000; in rk817_bat_get_prop()
505 val->intval = charger->bat_charge_full_design_uah; in rk817_bat_get_prop()
508 val->intval = 0; in rk817_bat_get_prop()
511 val->intval = charger->charge_now_uah; in rk817_bat_get_prop()
514 val->intval = charger->bat_voltage_min_design_uv; in rk817_bat_get_prop()
518 val->intval = (charger->soc + 500) / 1000; in rk817_bat_get_prop()
519 if (val->intval > 100) in rk817_bat_get_prop()
520 val->intval = 100; in rk817_bat_get_prop()
521 if (val->intval < 0) in rk817_bat_get_prop()
522 val->intval = 0; in rk817_bat_get_prop()
525 val->intval = charger->volt_avg_uv; in rk817_bat_get_prop()
528 val->intval = charger->cur_avg_ua; in rk817_bat_get_prop()
531 val->intval = charger->max_chg_cur_ua; in rk817_bat_get_prop()
534 val->intval = charger->max_chg_volt_uv; in rk817_bat_get_prop()
537 val->intval = charger->bat_voltage_max_design_uv; in rk817_bat_get_prop()
540 return -EINVAL; in rk817_bat_get_prop()
549 struct rk817_charger *charger = power_supply_get_drvdata(ps); in rk817_chg_get_prop() local
553 val->intval = charger->plugged_in; in rk817_chg_get_prop()
557 val->intval = 5500000; in rk817_chg_get_prop()
561 val->intval = 3800000; in rk817_chg_get_prop()
564 val->intval = charger->charger_input_volt_avg_uv; in rk817_chg_get_prop()
572 val->intval = POWER_SUPPLY_USB_TYPE_DCP; in rk817_chg_get_prop()
575 return -EINVAL; in rk817_chg_get_prop()
583 struct rk817_charger *charger; in rk817_plug_in_isr() local
585 charger = (struct rk817_charger *)cg; in rk817_plug_in_isr()
586 charger->plugged_in = 1; in rk817_plug_in_isr()
587 power_supply_changed(charger->chg_ps); in rk817_plug_in_isr()
588 power_supply_changed(charger->bat_ps); in rk817_plug_in_isr()
590 charger->soc_cal = 0; in rk817_plug_in_isr()
592 rk817_read_props(charger); in rk817_plug_in_isr()
594 dev_dbg(charger->dev, "Power Cord Inserted\n"); in rk817_plug_in_isr()
601 struct rk817_charger *charger; in rk817_plug_out_isr() local
604 charger = (struct rk817_charger *)cg; in rk817_plug_out_isr()
605 rk808 = charger->rk808; in rk817_plug_out_isr()
606 charger->plugged_in = 0; in rk817_plug_out_isr()
607 power_supply_changed(charger->bat_ps); in rk817_plug_out_isr()
608 power_supply_changed(charger->chg_ps); in rk817_plug_out_isr()
616 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, in rk817_plug_out_isr()
618 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_VLIM_EN, in rk817_plug_out_isr()
625 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, in rk817_plug_out_isr()
627 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_ILIM_EN, in rk817_plug_out_isr()
630 rk817_read_props(charger); in rk817_plug_out_isr()
632 dev_dbg(charger->dev, "Power Cord Removed\n"); in rk817_plug_out_isr()
668 .name = "rk817-battery",
676 .name = "rk817-charger",
685 static int rk817_read_battery_nvram_values(struct rk817_charger *charger) in rk817_read_battery_nvram_values() argument
691 ret = regmap_bulk_read(charger->rk808->regmap, in rk817_read_battery_nvram_values()
695 charger->fcc_mah = get_unaligned_le24(bulk_reg); in rk817_read_battery_nvram_values()
703 if ((charger->fcc_mah < 500) || in rk817_read_battery_nvram_values()
704 ((charger->fcc_mah * 1000) > charger->bat_charge_full_design_uah)) { in rk817_read_battery_nvram_values()
705 dev_info(charger->dev, in rk817_read_battery_nvram_values()
707 charger->bat_charge_full_design_uah); in rk817_read_battery_nvram_values()
708 charger->fcc_mah = charger->bat_charge_full_design_uah / 1000; in rk817_read_battery_nvram_values()
717 ret = regmap_bulk_read(charger->rk808->regmap, in rk817_read_battery_nvram_values()
721 charger->soc = get_unaligned_le24(bulk_reg); in rk817_read_battery_nvram_values()
722 if (charger->soc > 10000) in rk817_read_battery_nvram_values()
723 charger->soc = 10000; in rk817_read_battery_nvram_values()
729 rk817_read_or_set_full_charge_on_boot(struct rk817_charger *charger, in rk817_read_or_set_full_charge_on_boot() argument
732 struct rk808 *rk808 = charger->rk808; in rk817_read_or_set_full_charge_on_boot()
742 ret = regmap_read(rk808->regmap, RK817_GAS_GAUGE_GG_STS, &reg); in rk817_read_or_set_full_charge_on_boot()
752 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_PWRON_VOL_H, in rk817_read_or_set_full_charge_on_boot()
755 boot_voltage = (charger->voltage_k * tmp) + in rk817_read_or_set_full_charge_on_boot()
756 1000 * charger->voltage_b; in rk817_read_or_set_full_charge_on_boot()
762 charger->soc = power_supply_batinfo_ocv2cap(bat_info, in rk817_read_or_set_full_charge_on_boot()
765 if (charger->soc < 0) in rk817_read_or_set_full_charge_on_boot()
766 charger->soc = 0; in rk817_read_or_set_full_charge_on_boot()
769 charger->fcc_mah = charger->bat_charge_full_design_uah / 1000; in rk817_read_or_set_full_charge_on_boot()
772 * though datasheet claims it's a read-only value. in rk817_read_or_set_full_charge_on_boot()
774 regmap_write_bits(rk808->regmap, RK817_GAS_GAUGE_GG_STS, in rk817_read_or_set_full_charge_on_boot()
777 ret = rk817_record_battery_nvram_values(charger); in rk817_read_or_set_full_charge_on_boot()
781 ret = rk817_read_battery_nvram_values(charger); in rk817_read_or_set_full_charge_on_boot()
785 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3, in rk817_read_or_set_full_charge_on_boot()
791 charger->res_div) / 1000; in rk817_read_or_set_full_charge_on_boot()
794 * minutes as it tends to drift downward. If so, re-init soc in rk817_read_or_set_full_charge_on_boot()
803 regmap_read(rk808->regmap, RK817_GAS_GAUGE_OFF_CNT, &off_time); in rk817_read_or_set_full_charge_on_boot()
805 regmap_bulk_read(rk808->regmap, in rk817_read_or_set_full_charge_on_boot()
809 boot_voltage = (charger->voltage_k * tmp) + in rk817_read_or_set_full_charge_on_boot()
810 1000 * charger->voltage_b; in rk817_read_or_set_full_charge_on_boot()
811 charger->soc = in rk817_read_or_set_full_charge_on_boot()
816 charger->soc = (boot_charge_mah * 1000 * 100 / in rk817_read_or_set_full_charge_on_boot()
817 charger->fcc_mah); in rk817_read_or_set_full_charge_on_boot()
821 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_PWRON_VOL_H, in rk817_read_or_set_full_charge_on_boot()
824 boot_voltage = (charger->voltage_k * tmp) + 1000 * charger->voltage_b; in rk817_read_or_set_full_charge_on_boot()
825 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_Q_PRES_H3, in rk817_read_or_set_full_charge_on_boot()
830 boot_charge_mah = ADC_TO_CHARGE_UAH(tmp, charger->res_div) / 1000; in rk817_read_or_set_full_charge_on_boot()
831 regmap_bulk_read(rk808->regmap, RK817_GAS_GAUGE_OCV_VOL_H, in rk817_read_or_set_full_charge_on_boot()
834 boot_voltage = (charger->voltage_k * tmp) + 1000 * charger->voltage_b; in rk817_read_or_set_full_charge_on_boot()
840 boot_charge_mah = charger->soc * charger->fcc_mah / 100 / 1000; in rk817_read_or_set_full_charge_on_boot()
841 if (boot_charge_mah > charger->fcc_mah) in rk817_read_or_set_full_charge_on_boot()
842 boot_charge_mah = charger->fcc_mah; in rk817_read_or_set_full_charge_on_boot()
843 tmp = CHARGE_TO_ADC(boot_charge_mah, charger->res_div); in rk817_read_or_set_full_charge_on_boot()
845 ret = regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_Q_INIT_H3, in rk817_read_or_set_full_charge_on_boot()
851 tmp = CHARGE_TO_ADC((charger->bat_charge_full_design_uah / 1000), in rk817_read_or_set_full_charge_on_boot()
852 charger->res_div); in rk817_read_or_set_full_charge_on_boot()
854 ret = regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_Q_MAX_H3, in rk817_read_or_set_full_charge_on_boot()
862 static int rk817_battery_init(struct rk817_charger *charger, in rk817_battery_init() argument
865 struct rk808 *rk808 = charger->rk808; in rk817_battery_init()
872 regmap_read(rk808->regmap, RK817_SYS_STS, &tmp); in rk817_battery_init()
873 charger->plugged_in = (tmp & RK817_PLUG_IN_STS); in rk817_battery_init()
880 regmap_write(rk808->regmap, RK817_GAS_GAUGE_ADC_CONFIG0, 0xfc); in rk817_battery_init()
887 regmap_write(rk808->regmap, RK817_GAS_GAUGE_GG_CON, 0x04); in rk817_battery_init()
890 rk817_bat_calib_vol(charger); in rk817_battery_init()
893 tmp = CURRENT_TO_ADC(charger->sleep_enter_current_ua, in rk817_battery_init()
894 charger->res_div); in rk817_battery_init()
896 regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_RELAX_THRE_H, in rk817_battery_init()
900 tmp = CURRENT_TO_ADC(charger->sleep_filter_current_ua, in rk817_battery_init()
901 charger->res_div); in rk817_battery_init()
903 regmap_bulk_write(rk808->regmap, RK817_GAS_GAUGE_SLEEP_CON_SAMP_CUR_H, in rk817_battery_init()
907 regmap_write_bits(rk808->regmap, RK817_GAS_GAUGE_GG_STS, in rk817_battery_init()
914 regmap_write(rk808->regmap, RK817_GAS_GAUGE_OCV_THRE_VOL, 0xff); in rk817_battery_init()
921 max_chg_vol_mv = bat_info->constant_charge_voltage_max_uv / 1000; in rk817_battery_init()
922 max_chg_cur_ma = bat_info->constant_charge_current_max_ua / 1000; in rk817_battery_init()
925 return dev_err_probe(charger->dev, -EINVAL, in rk817_battery_init()
926 "invalid max charger voltage, value %u unsupported\n", in rk817_battery_init()
930 dev_info(charger->dev, in rk817_battery_init()
936 return dev_err_probe(charger->dev, -EINVAL, in rk817_battery_init()
937 "invalid max charger current, value %u unsupported\n", in rk817_battery_init()
941 dev_info(charger->dev, in rk817_battery_init()
950 max_chg_vol_reg = (max_chg_vol_mv - 4100) / 50; in rk817_battery_init()
955 return dev_err_probe(charger->dev, -EINVAL, in rk817_battery_init()
956 "invalid max charger voltage, value %u unsupported\n", in rk817_battery_init()
960 return dev_err_probe(charger->dev, -EINVAL, in rk817_battery_init()
961 "invalid max charger current, value %u unsupported\n", in rk817_battery_init()
969 ret = regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_OUT, in rk817_battery_init()
972 dev_emerg(charger->dev, in rk817_battery_init()
973 "Danger, unable to set max charger voltage: %u\n", in rk817_battery_init()
977 ret = regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_OUT, in rk817_battery_init()
980 dev_emerg(charger->dev, in rk817_battery_init()
981 "Danger, unable to set max charger current: %u\n", in rk817_battery_init()
986 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_TERM, in rk817_battery_init()
993 chg_term_ma = bat_info->charge_term_current_ua / 1000; in rk817_battery_init()
995 dev_warn(charger->dev, in rk817_battery_init()
1005 chg_term_i_reg = (chg_term_ma - 100) / 100; in rk817_battery_init()
1006 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_TERM, in rk817_battery_init()
1009 ret = rk817_read_or_set_full_charge_on_boot(charger, bat_info); in rk817_battery_init()
1017 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, in rk817_battery_init()
1019 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_VLIM_EN, in rk817_battery_init()
1026 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, in rk817_battery_init()
1028 regmap_write_bits(rk808->regmap, RK817_PMIC_CHRG_IN, RK817_USB_ILIM_EN, in rk817_battery_init()
1036 struct rk817_charger *charger; in rk817_charging_monitor() local
1038 charger = container_of(work, struct rk817_charger, work.work); in rk817_charging_monitor()
1040 rk817_read_props(charger); in rk817_charging_monitor()
1043 queue_delayed_work(system_wq, &charger->work, msecs_to_jiffies(8000)); in rk817_charging_monitor()
1048 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); in rk817_charger_probe()
1049 struct rk817_charger *charger; in rk817_charger_probe() local
1052 struct device *dev = &pdev->dev; in rk817_charger_probe()
1058 node = of_get_child_by_name(dev->parent->of_node, "charger"); in rk817_charger_probe()
1060 return -ENODEV; in rk817_charger_probe()
1062 charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL); in rk817_charger_probe()
1063 if (!charger) in rk817_charger_probe()
1064 return -ENOMEM; in rk817_charger_probe()
1066 charger->rk808 = rk808; in rk817_charger_probe()
1068 charger->dev = &pdev->dev; in rk817_charger_probe()
1069 platform_set_drvdata(pdev, charger); in rk817_charger_probe()
1071 rk817_bat_calib_vol(charger); in rk817_charger_probe()
1073 pscfg.drv_data = charger; in rk817_charger_probe()
1077 * Get sample resistor value. Note only values of 10000 or 20000 in rk817_charger_probe()
1079 * Odroid Go Advance) shows a 10 milliohm resistor for reference. in rk817_charger_probe()
1081 ret = of_property_read_u32(node, "rockchip,resistor-sense-micro-ohms", in rk817_charger_probe()
1085 "Error reading sample resistor value\n"); in rk817_charger_probe()
1091 charger->res_div = (of_value == 20000) ? 2 : 1; in rk817_charger_probe()
1098 "rockchip,sleep-enter-current-microamp", in rk817_charger_probe()
1104 charger->sleep_enter_current_ua = of_value; in rk817_charger_probe()
1108 "rockchip,sleep-filter-current-microamp", in rk817_charger_probe()
1115 charger->sleep_filter_current_ua = of_value; in rk817_charger_probe()
1117 charger->bat_ps = devm_power_supply_register(&pdev->dev, in rk817_charger_probe()
1119 if (IS_ERR(charger->bat_ps)) in rk817_charger_probe()
1120 return dev_err_probe(dev, -EINVAL, in rk817_charger_probe()
1123 charger->chg_ps = devm_power_supply_register(&pdev->dev, in rk817_charger_probe()
1125 if (IS_ERR(charger->chg_ps)) in rk817_charger_probe()
1126 return dev_err_probe(dev, -EINVAL, in rk817_charger_probe()
1127 "Charger failed to probe\n"); in rk817_charger_probe()
1129 ret = power_supply_get_battery_info(charger->bat_ps, in rk817_charger_probe()
1136 if ((bat_info->charge_full_design_uah <= 0) || in rk817_charger_probe()
1137 (bat_info->voltage_min_design_uv <= 0) || in rk817_charger_probe()
1138 (bat_info->voltage_max_design_uv <= 0) || in rk817_charger_probe()
1139 (bat_info->constant_charge_voltage_max_uv <= 0) || in rk817_charger_probe()
1140 (bat_info->constant_charge_current_max_ua <= 0) || in rk817_charger_probe()
1141 (bat_info->charge_term_current_ua <= 0)) { in rk817_charger_probe()
1142 return dev_err_probe(dev, -EINVAL, in rk817_charger_probe()
1146 charger->bat_charge_full_design_uah = bat_info->charge_full_design_uah; in rk817_charger_probe()
1147 charger->bat_voltage_min_design_uv = bat_info->voltage_min_design_uv; in rk817_charger_probe()
1148 charger->bat_voltage_max_design_uv = bat_info->voltage_max_design_uv; in rk817_charger_probe()
1154 ret = rk817_battery_init(charger, bat_info); in rk817_charger_probe()
1158 power_supply_put_battery_info(charger->bat_ps, bat_info); in rk817_charger_probe()
1168 ret = devm_request_threaded_irq(charger->dev, plugin_irq, NULL, in rk817_charger_probe()
1171 "rk817_plug_in", charger); in rk817_charger_probe()
1173 return dev_err_probe(&pdev->dev, ret, in rk817_charger_probe()
1177 ret = devm_request_threaded_irq(charger->dev, plugout_irq, NULL, in rk817_charger_probe()
1180 "rk817_plug_out", charger); in rk817_charger_probe()
1182 return dev_err_probe(&pdev->dev, ret, in rk817_charger_probe()
1186 ret = devm_delayed_work_autocancel(&pdev->dev, &charger->work, in rk817_charger_probe()
1192 mod_delayed_work(system_wq, &charger->work, 0); in rk817_charger_probe()
1201 .name = "rk817-charger",