Lines Matching refs:data

124 static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity);
125 static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data,
127 static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap);
128 static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp);
137 static int sc27xx_fgu_adc_to_current(struct sc27xx_fgu_data *data, s64 adc) in sc27xx_fgu_adc_to_current() argument
139 return DIV_S64_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc); in sc27xx_fgu_adc_to_current()
142 static int sc27xx_fgu_adc_to_voltage(struct sc27xx_fgu_data *data, s64 adc) in sc27xx_fgu_adc_to_voltage() argument
144 return DIV_S64_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc); in sc27xx_fgu_adc_to_voltage()
147 static int sc27xx_fgu_voltage_to_adc(struct sc27xx_fgu_data *data, int vol) in sc27xx_fgu_voltage_to_adc() argument
149 return DIV_ROUND_CLOSEST(vol * data->vol_1000mv_adc, 1000); in sc27xx_fgu_voltage_to_adc()
152 static bool sc27xx_fgu_is_first_poweron(struct sc27xx_fgu_data *data) in sc27xx_fgu_is_first_poweron() argument
156 ret = regmap_read(data->regmap, in sc27xx_fgu_is_first_poweron()
157 data->base + SC27XX_FGU_USER_AREA_STATUS, &status); in sc27xx_fgu_is_first_poweron()
179 static int sc27xx_fgu_save_boot_mode(struct sc27xx_fgu_data *data, in sc27xx_fgu_save_boot_mode() argument
184 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_save_boot_mode()
185 data->base + SC27XX_FGU_USER_AREA_CLEAR, in sc27xx_fgu_save_boot_mode()
199 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_save_boot_mode()
200 data->base + SC27XX_FGU_USER_AREA_SET, in sc27xx_fgu_save_boot_mode()
219 return regmap_update_bits(data->regmap, in sc27xx_fgu_save_boot_mode()
220 data->base + SC27XX_FGU_USER_AREA_CLEAR, in sc27xx_fgu_save_boot_mode()
224 static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap) in sc27xx_fgu_save_last_cap() argument
228 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_save_last_cap()
229 data->base + SC27XX_FGU_USER_AREA_CLEAR, in sc27xx_fgu_save_last_cap()
243 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_save_last_cap()
244 data->base + SC27XX_FGU_USER_AREA_SET, in sc27xx_fgu_save_last_cap()
262 return regmap_update_bits(data->regmap, in sc27xx_fgu_save_last_cap()
263 data->base + SC27XX_FGU_USER_AREA_CLEAR, in sc27xx_fgu_save_last_cap()
267 static int sc27xx_fgu_read_last_cap(struct sc27xx_fgu_data *data, int *cap) in sc27xx_fgu_read_last_cap() argument
271 ret = regmap_read(data->regmap, in sc27xx_fgu_read_last_cap()
272 data->base + SC27XX_FGU_USER_AREA_STATUS, &value); in sc27xx_fgu_read_last_cap()
286 static int sc27xx_fgu_get_boot_capacity(struct sc27xx_fgu_data *data, int *cap) in sc27xx_fgu_get_boot_capacity() argument
289 bool is_first_poweron = sc27xx_fgu_is_first_poweron(data); in sc27xx_fgu_get_boot_capacity()
297 ret = sc27xx_fgu_read_last_cap(data, cap); in sc27xx_fgu_get_boot_capacity()
301 return sc27xx_fgu_save_boot_mode(data, SC27XX_FGU_NORMAIL_POWERTON); in sc27xx_fgu_get_boot_capacity()
308 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_CLBCNT_QMAXL, in sc27xx_fgu_get_boot_capacity()
314 oci = sc27xx_fgu_adc_to_current(data, cur - SC27XX_FGU_CUR_BASIC_ADC); in sc27xx_fgu_get_boot_capacity()
321 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_POCV, &volt); in sc27xx_fgu_get_boot_capacity()
325 volt = sc27xx_fgu_adc_to_voltage(data, volt); in sc27xx_fgu_get_boot_capacity()
326 ocv = volt * 1000 - oci * data->internal_resist; in sc27xx_fgu_get_boot_capacity()
327 data->boot_volt = ocv; in sc27xx_fgu_get_boot_capacity()
333 *cap = power_supply_ocv2cap_simple(data->cap_table, data->table_len, in sc27xx_fgu_get_boot_capacity()
336 ret = sc27xx_fgu_save_last_cap(data, *cap); in sc27xx_fgu_get_boot_capacity()
340 return sc27xx_fgu_save_boot_mode(data, SC27XX_FGU_NORMAIL_POWERTON); in sc27xx_fgu_get_boot_capacity()
343 static int sc27xx_fgu_set_clbcnt(struct sc27xx_fgu_data *data, int clbcnt) in sc27xx_fgu_set_clbcnt() argument
347 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_set_clbcnt()
348 data->base + SC27XX_FGU_CLBCNT_SETL, in sc27xx_fgu_set_clbcnt()
353 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_set_clbcnt()
354 data->base + SC27XX_FGU_CLBCNT_SETH, in sc27xx_fgu_set_clbcnt()
360 return regmap_update_bits(data->regmap, data->base + SC27XX_FGU_START, in sc27xx_fgu_set_clbcnt()
365 static int sc27xx_fgu_get_clbcnt(struct sc27xx_fgu_data *data, int *clb_cnt) in sc27xx_fgu_get_clbcnt() argument
369 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_CLBCNT_VALL, in sc27xx_fgu_get_clbcnt()
374 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_CLBCNT_VALH, in sc27xx_fgu_get_clbcnt()
385 static int sc27xx_fgu_get_vol_now(struct sc27xx_fgu_data *data, int *val) in sc27xx_fgu_get_vol_now() argument
390 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_VOLTAGE_BUF, in sc27xx_fgu_get_vol_now()
399 *val = sc27xx_fgu_adc_to_voltage(data, vol); in sc27xx_fgu_get_vol_now()
404 static int sc27xx_fgu_get_cur_now(struct sc27xx_fgu_data *data, int *val) in sc27xx_fgu_get_cur_now() argument
409 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_CURRENT_BUF, in sc27xx_fgu_get_cur_now()
418 *val = sc27xx_fgu_adc_to_current(data, cur - SC27XX_FGU_CUR_BASIC_ADC); in sc27xx_fgu_get_cur_now()
423 static int sc27xx_fgu_get_capacity(struct sc27xx_fgu_data *data, int *cap) in sc27xx_fgu_get_capacity() argument
428 ret = sc27xx_fgu_get_clbcnt(data, &cur_clbcnt); in sc27xx_fgu_get_capacity()
432 delta_clbcnt = cur_clbcnt - data->init_clbcnt; in sc27xx_fgu_get_capacity()
439 temp = sc27xx_fgu_adc_to_current(data, temp / 1000); in sc27xx_fgu_get_capacity()
445 delta_cap = DIV_ROUND_CLOSEST(temp * 100, data->total_cap); in sc27xx_fgu_get_capacity()
446 *cap = delta_cap + data->init_cap; in sc27xx_fgu_get_capacity()
449 sc27xx_fgu_capacity_calibration(data, *cap, false); in sc27xx_fgu_get_capacity()
454 static int sc27xx_fgu_get_vbat_vol(struct sc27xx_fgu_data *data, int *val) in sc27xx_fgu_get_vbat_vol() argument
458 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_VOLTAGE, &vol); in sc27xx_fgu_get_vbat_vol()
466 *val = sc27xx_fgu_adc_to_voltage(data, vol); in sc27xx_fgu_get_vbat_vol()
471 static int sc27xx_fgu_get_current(struct sc27xx_fgu_data *data, int *val) in sc27xx_fgu_get_current() argument
475 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_CURRENT, &cur); in sc27xx_fgu_get_current()
483 *val = sc27xx_fgu_adc_to_current(data, cur - SC27XX_FGU_CUR_BASIC_ADC); in sc27xx_fgu_get_current()
488 static int sc27xx_fgu_get_vbat_ocv(struct sc27xx_fgu_data *data, int *val) in sc27xx_fgu_get_vbat_ocv() argument
492 ret = sc27xx_fgu_get_vbat_vol(data, &vol); in sc27xx_fgu_get_vbat_ocv()
496 ret = sc27xx_fgu_get_current(data, &cur); in sc27xx_fgu_get_vbat_ocv()
500 resistance = data->internal_resist; in sc27xx_fgu_get_vbat_ocv()
501 if (data->resist_table_len > 0) { in sc27xx_fgu_get_vbat_ocv()
502 ret = sc27xx_fgu_get_temp(data, &temp); in sc27xx_fgu_get_vbat_ocv()
506 resistance = power_supply_temp2resist_simple(data->resist_table, in sc27xx_fgu_get_vbat_ocv()
507 data->resist_table_len, temp); in sc27xx_fgu_get_vbat_ocv()
508 resistance = data->internal_resist * resistance / 100; in sc27xx_fgu_get_vbat_ocv()
517 static int sc27xx_fgu_get_charge_vol(struct sc27xx_fgu_data *data, int *val) in sc27xx_fgu_get_charge_vol() argument
521 ret = iio_read_channel_processed(data->charge_chan, &vol); in sc27xx_fgu_get_charge_vol()
529 static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp) in sc27xx_fgu_get_temp() argument
531 return iio_read_channel_processed(data->channel, temp); in sc27xx_fgu_get_temp()
534 static int sc27xx_fgu_get_health(struct sc27xx_fgu_data *data, int *health) in sc27xx_fgu_get_health() argument
538 ret = sc27xx_fgu_get_vbat_vol(data, &vol); in sc27xx_fgu_get_health()
542 if (vol > data->max_volt) in sc27xx_fgu_get_health()
550 static int sc27xx_fgu_get_status(struct sc27xx_fgu_data *data, int *status) in sc27xx_fgu_get_status() argument
577 struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy); in sc27xx_fgu_get_property() local
581 mutex_lock(&data->lock); in sc27xx_fgu_get_property()
585 ret = sc27xx_fgu_get_status(data, &value); in sc27xx_fgu_get_property()
593 ret = sc27xx_fgu_get_health(data, &value); in sc27xx_fgu_get_property()
601 val->intval = data->bat_present; in sc27xx_fgu_get_property()
605 ret = sc27xx_fgu_get_temp(data, &value); in sc27xx_fgu_get_property()
617 ret = sc27xx_fgu_get_capacity(data, &value); in sc27xx_fgu_get_property()
625 ret = sc27xx_fgu_get_vbat_vol(data, &value); in sc27xx_fgu_get_property()
633 ret = sc27xx_fgu_get_vbat_ocv(data, &value); in sc27xx_fgu_get_property()
641 ret = sc27xx_fgu_get_charge_vol(data, &value); in sc27xx_fgu_get_property()
649 ret = sc27xx_fgu_get_current(data, &value); in sc27xx_fgu_get_property()
657 val->intval = data->total_cap * 1000; in sc27xx_fgu_get_property()
661 ret = sc27xx_fgu_get_clbcnt(data, &value); in sc27xx_fgu_get_property()
667 val->intval = sc27xx_fgu_adc_to_current(data, value); in sc27xx_fgu_get_property()
672 ret = sc27xx_fgu_get_vol_now(data, &value); in sc27xx_fgu_get_property()
680 ret = sc27xx_fgu_get_cur_now(data, &value); in sc27xx_fgu_get_property()
688 val->intval = data->boot_volt; in sc27xx_fgu_get_property()
697 mutex_unlock(&data->lock); in sc27xx_fgu_get_property()
705 struct sc27xx_fgu_data *data = power_supply_get_drvdata(psy); in sc27xx_fgu_set_property() local
708 mutex_lock(&data->lock); in sc27xx_fgu_set_property()
712 ret = sc27xx_fgu_save_last_cap(data, val->intval); in sc27xx_fgu_set_property()
714 dev_err(data->dev, "failed to save battery capacity\n"); in sc27xx_fgu_set_property()
718 sc27xx_fgu_adjust_cap(data, val->intval); in sc27xx_fgu_set_property()
723 data->total_cap = val->intval / 1000; in sc27xx_fgu_set_property()
731 mutex_unlock(&data->lock); in sc27xx_fgu_set_property()
775 static void sc27xx_fgu_adjust_cap(struct sc27xx_fgu_data *data, int cap) in sc27xx_fgu_adjust_cap() argument
779 data->init_cap = cap; in sc27xx_fgu_adjust_cap()
780 ret = sc27xx_fgu_get_clbcnt(data, &data->init_clbcnt); in sc27xx_fgu_adjust_cap()
782 dev_err(data->dev, "failed to get init coulomb counter\n"); in sc27xx_fgu_adjust_cap()
785 static void sc27xx_fgu_capacity_calibration(struct sc27xx_fgu_data *data, in sc27xx_fgu_capacity_calibration() argument
790 ret = sc27xx_fgu_get_vbat_ocv(data, &ocv); in sc27xx_fgu_capacity_calibration()
792 dev_err(data->dev, "get battery ocv error.\n"); in sc27xx_fgu_capacity_calibration()
796 ret = sc27xx_fgu_get_status(data, &chg_sts); in sc27xx_fgu_capacity_calibration()
798 dev_err(data->dev, "get charger status error.\n"); in sc27xx_fgu_capacity_calibration()
809 if ((ocv > data->cap_table[0].ocv && cap < 100) || cap > 100) { in sc27xx_fgu_capacity_calibration()
815 sc27xx_fgu_adjust_cap(data, 100); in sc27xx_fgu_capacity_calibration()
816 } else if (ocv <= data->cap_table[data->table_len - 1].ocv) { in sc27xx_fgu_capacity_calibration()
821 sc27xx_fgu_adjust_cap(data, 0); in sc27xx_fgu_capacity_calibration()
822 } else if ((ocv > data->cap_table[data->table_len - 1].ocv && cap <= 0) || in sc27xx_fgu_capacity_calibration()
823 (ocv > data->min_volt && cap <= data->alarm_cap)) { in sc27xx_fgu_capacity_calibration()
829 int cur_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_capacity_calibration()
830 data->table_len, ocv); in sc27xx_fgu_capacity_calibration()
832 sc27xx_fgu_adjust_cap(data, cur_cap); in sc27xx_fgu_capacity_calibration()
833 } else if (ocv <= data->min_volt) { in sc27xx_fgu_capacity_calibration()
839 if (cap > data->alarm_cap) { in sc27xx_fgu_capacity_calibration()
840 sc27xx_fgu_adjust_cap(data, data->alarm_cap); in sc27xx_fgu_capacity_calibration()
850 cur_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_capacity_calibration()
851 data->table_len, in sc27xx_fgu_capacity_calibration()
853 sc27xx_fgu_adjust_cap(data, cur_cap); in sc27xx_fgu_capacity_calibration()
863 data->min_volt = data->cap_table[data->table_len - 1].ocv; in sc27xx_fgu_capacity_calibration()
864 data->alarm_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_capacity_calibration()
865 data->table_len, in sc27xx_fgu_capacity_calibration()
866 data->min_volt); in sc27xx_fgu_capacity_calibration()
868 adc = sc27xx_fgu_voltage_to_adc(data, data->min_volt / 1000); in sc27xx_fgu_capacity_calibration()
869 regmap_update_bits(data->regmap, in sc27xx_fgu_capacity_calibration()
870 data->base + SC27XX_FGU_LOW_OVERLOAD, in sc27xx_fgu_capacity_calibration()
877 struct sc27xx_fgu_data *data = dev_id; in sc27xx_fgu_interrupt() local
881 mutex_lock(&data->lock); in sc27xx_fgu_interrupt()
883 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_INT_STS, in sc27xx_fgu_interrupt()
888 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_CLR, in sc27xx_fgu_interrupt()
900 ret = sc27xx_fgu_get_capacity(data, &cap); in sc27xx_fgu_interrupt()
904 sc27xx_fgu_capacity_calibration(data, cap, true); in sc27xx_fgu_interrupt()
907 mutex_unlock(&data->lock); in sc27xx_fgu_interrupt()
909 power_supply_changed(data->battery); in sc27xx_fgu_interrupt()
915 struct sc27xx_fgu_data *data = dev_id; in sc27xx_fgu_bat_detection() local
918 mutex_lock(&data->lock); in sc27xx_fgu_bat_detection()
920 state = gpiod_get_value_cansleep(data->gpiod); in sc27xx_fgu_bat_detection()
922 dev_err(data->dev, "failed to get gpio state\n"); in sc27xx_fgu_bat_detection()
923 mutex_unlock(&data->lock); in sc27xx_fgu_bat_detection()
927 data->bat_present = !!state; in sc27xx_fgu_bat_detection()
929 mutex_unlock(&data->lock); in sc27xx_fgu_bat_detection()
931 power_supply_changed(data->battery); in sc27xx_fgu_bat_detection()
937 struct sc27xx_fgu_data *data = _data; in sc27xx_fgu_disable() local
939 regmap_update_bits(data->regmap, SC27XX_CLK_EN0, SC27XX_FGU_RTC_EN, 0); in sc27xx_fgu_disable()
940 regmap_update_bits(data->regmap, SC27XX_MODULE_EN0, SC27XX_FGU_EN, 0); in sc27xx_fgu_disable()
943 static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity) in sc27xx_fgu_cap_to_clbcnt() argument
949 int cur_cap = DIV_ROUND_CLOSEST(data->total_cap * capacity, 100); in sc27xx_fgu_cap_to_clbcnt()
955 return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc * SC27XX_FGU_SAMPLE_HZ, 10); in sc27xx_fgu_cap_to_clbcnt()
958 static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data) in sc27xx_fgu_calibration() argument
965 cell = nvmem_cell_get(data->dev, "fgu_calib"); in sc27xx_fgu_calibration()
983 data->vol_1000mv_adc = DIV_ROUND_CLOSEST(cal_4200mv * 10, 42); in sc27xx_fgu_calibration()
984 data->cur_1000ma_adc = in sc27xx_fgu_calibration()
985 DIV_ROUND_CLOSEST(data->vol_1000mv_adc * 4 * data->calib_resist, in sc27xx_fgu_calibration()
992 static int sc27xx_fgu_hw_init(struct sc27xx_fgu_data *data) in sc27xx_fgu_hw_init() argument
998 ret = power_supply_get_battery_info(data->battery, &info); in sc27xx_fgu_hw_init()
1000 dev_err(data->dev, "failed to get battery information\n"); in sc27xx_fgu_hw_init()
1004 data->total_cap = info->charge_full_design_uah / 1000; in sc27xx_fgu_hw_init()
1005 data->max_volt = info->constant_charge_voltage_max_uv / 1000; in sc27xx_fgu_hw_init()
1006 data->internal_resist = info->factory_internal_resistance_uohm / 1000; in sc27xx_fgu_hw_init()
1007 data->min_volt = info->voltage_min_design_uv; in sc27xx_fgu_hw_init()
1013 table = power_supply_find_ocv2cap_table(info, 20, &data->table_len); in sc27xx_fgu_hw_init()
1017 data->cap_table = devm_kmemdup(data->dev, table, in sc27xx_fgu_hw_init()
1018 data->table_len * sizeof(*table), in sc27xx_fgu_hw_init()
1020 if (!data->cap_table) { in sc27xx_fgu_hw_init()
1021 power_supply_put_battery_info(data->battery, info); in sc27xx_fgu_hw_init()
1025 data->alarm_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_hw_init()
1026 data->table_len, in sc27xx_fgu_hw_init()
1027 data->min_volt); in sc27xx_fgu_hw_init()
1028 if (!data->alarm_cap) in sc27xx_fgu_hw_init()
1029 data->alarm_cap += 1; in sc27xx_fgu_hw_init()
1031 data->resist_table_len = info->resist_table_size; in sc27xx_fgu_hw_init()
1032 if (data->resist_table_len > 0) { in sc27xx_fgu_hw_init()
1033 data->resist_table = devm_kmemdup(data->dev, info->resist_table, in sc27xx_fgu_hw_init()
1034 data->resist_table_len * in sc27xx_fgu_hw_init()
1037 if (!data->resist_table) { in sc27xx_fgu_hw_init()
1038 power_supply_put_battery_info(data->battery, info); in sc27xx_fgu_hw_init()
1043 power_supply_put_battery_info(data->battery, info); in sc27xx_fgu_hw_init()
1045 ret = sc27xx_fgu_calibration(data); in sc27xx_fgu_hw_init()
1050 ret = regmap_update_bits(data->regmap, SC27XX_MODULE_EN0, in sc27xx_fgu_hw_init()
1053 dev_err(data->dev, "failed to enable fgu\n"); in sc27xx_fgu_hw_init()
1058 ret = regmap_update_bits(data->regmap, SC27XX_CLK_EN0, in sc27xx_fgu_hw_init()
1061 dev_err(data->dev, "failed to enable fgu RTC clock\n"); in sc27xx_fgu_hw_init()
1065 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_CLR, in sc27xx_fgu_hw_init()
1068 dev_err(data->dev, "failed to clear interrupt status\n"); in sc27xx_fgu_hw_init()
1077 alarm_adc = sc27xx_fgu_voltage_to_adc(data, data->min_volt / 1000); in sc27xx_fgu_hw_init()
1078 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_LOW_OVERLOAD, in sc27xx_fgu_hw_init()
1081 dev_err(data->dev, "failed to set fgu low overload\n"); in sc27xx_fgu_hw_init()
1092 delta_clbcnt = sc27xx_fgu_cap_to_clbcnt(data, 1); in sc27xx_fgu_hw_init()
1094 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_CLBCNT_DELTL, in sc27xx_fgu_hw_init()
1097 dev_err(data->dev, "failed to set low delta coulomb counter\n"); in sc27xx_fgu_hw_init()
1101 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_CLBCNT_DELTH, in sc27xx_fgu_hw_init()
1105 dev_err(data->dev, "failed to set high delta coulomb counter\n"); in sc27xx_fgu_hw_init()
1114 ret = sc27xx_fgu_get_boot_capacity(data, &data->init_cap); in sc27xx_fgu_hw_init()
1116 dev_err(data->dev, "failed to get boot capacity\n"); in sc27xx_fgu_hw_init()
1124 data->init_clbcnt = sc27xx_fgu_cap_to_clbcnt(data, data->init_cap); in sc27xx_fgu_hw_init()
1125 ret = sc27xx_fgu_set_clbcnt(data, data->init_clbcnt); in sc27xx_fgu_hw_init()
1127 dev_err(data->dev, "failed to initialize coulomb counter\n"); in sc27xx_fgu_hw_init()
1134 regmap_update_bits(data->regmap, SC27XX_CLK_EN0, SC27XX_FGU_RTC_EN, 0); in sc27xx_fgu_hw_init()
1136 regmap_update_bits(data->regmap, SC27XX_MODULE_EN0, SC27XX_FGU_EN, 0); in sc27xx_fgu_hw_init()
1146 struct sc27xx_fgu_data *data; in sc27xx_fgu_probe() local
1149 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); in sc27xx_fgu_probe()
1150 if (!data) in sc27xx_fgu_probe()
1153 data->regmap = dev_get_regmap(dev->parent, NULL); in sc27xx_fgu_probe()
1154 if (!data->regmap) { in sc27xx_fgu_probe()
1159 ret = device_property_read_u32(dev, "reg", &data->base); in sc27xx_fgu_probe()
1167 &data->calib_resist); in sc27xx_fgu_probe()
1174 data->channel = devm_iio_channel_get(dev, "bat-temp"); in sc27xx_fgu_probe()
1175 if (IS_ERR(data->channel)) { in sc27xx_fgu_probe()
1177 return PTR_ERR(data->channel); in sc27xx_fgu_probe()
1180 data->charge_chan = devm_iio_channel_get(dev, "charge-vol"); in sc27xx_fgu_probe()
1181 if (IS_ERR(data->charge_chan)) { in sc27xx_fgu_probe()
1183 return PTR_ERR(data->charge_chan); in sc27xx_fgu_probe()
1186 data->gpiod = devm_gpiod_get(dev, "bat-detect", GPIOD_IN); in sc27xx_fgu_probe()
1187 if (IS_ERR(data->gpiod)) { in sc27xx_fgu_probe()
1189 return PTR_ERR(data->gpiod); in sc27xx_fgu_probe()
1192 ret = gpiod_get_value_cansleep(data->gpiod); in sc27xx_fgu_probe()
1198 data->bat_present = !!ret; in sc27xx_fgu_probe()
1199 mutex_init(&data->lock); in sc27xx_fgu_probe()
1200 data->dev = dev; in sc27xx_fgu_probe()
1201 platform_set_drvdata(pdev, data); in sc27xx_fgu_probe()
1203 fgu_cfg.drv_data = data; in sc27xx_fgu_probe()
1205 data->battery = devm_power_supply_register(dev, &sc27xx_fgu_desc, in sc27xx_fgu_probe()
1207 if (IS_ERR(data->battery)) { in sc27xx_fgu_probe()
1209 return PTR_ERR(data->battery); in sc27xx_fgu_probe()
1212 ret = sc27xx_fgu_hw_init(data); in sc27xx_fgu_probe()
1218 ret = devm_add_action_or_reset(dev, sc27xx_fgu_disable, data); in sc27xx_fgu_probe()
1228 ret = devm_request_threaded_irq(data->dev, irq, NULL, in sc27xx_fgu_probe()
1231 pdev->name, data); in sc27xx_fgu_probe()
1233 dev_err(data->dev, "failed to request fgu IRQ\n"); in sc27xx_fgu_probe()
1237 irq = gpiod_to_irq(data->gpiod); in sc27xx_fgu_probe()
1247 pdev->name, data); in sc27xx_fgu_probe()
1259 struct sc27xx_fgu_data *data = dev_get_drvdata(dev); in sc27xx_fgu_resume() local
1262 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_resume()
1266 dev_err(data->dev, "failed to disable fgu interrupts\n"); in sc27xx_fgu_resume()
1275 struct sc27xx_fgu_data *data = dev_get_drvdata(dev); in sc27xx_fgu_suspend() local
1278 ret = sc27xx_fgu_get_status(data, &status); in sc27xx_fgu_suspend()
1290 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1294 dev_err(data->dev, "failed to enable low voltage interrupt\n"); in sc27xx_fgu_suspend()
1298 ret = sc27xx_fgu_get_vbat_ocv(data, &ocv); in sc27xx_fgu_suspend()
1307 if (ocv < data->min_volt) { in sc27xx_fgu_suspend()
1308 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_suspend()
1309 data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1313 dev_err(data->dev, in sc27xx_fgu_suspend()
1322 regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()