Lines Matching +full:ocv +full:- +full:capacity
1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/nvmem-consumer.h>
82 * @total_cap: the total capacity of the battery in mAh
83 * @init_cap: the initial capacity of the battery in mAh
84 * @alarm_cap: the alarm capacity
89 * @table_len: the capacity table length
94 * @cap_table: capacity table with corresponding ocv
124 static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity);
139 return DIV_S64_ROUND_CLOSEST(adc * 1000, data->cur_1000ma_adc); in sc27xx_fgu_adc_to_current()
144 return DIV_S64_ROUND_CLOSEST(adc * 1000, data->vol_1000mv_adc); in sc27xx_fgu_adc_to_voltage()
149 return DIV_ROUND_CLOSEST(vol * data->vol_1000mv_adc, 1000); in sc27xx_fgu_voltage_to_adc()
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()
162 * We use low 4 bits to save the last battery capacity and high 12 bits in sc27xx_fgu_is_first_poweron()
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()
192 * Since the user area registers are put on power always-on region, 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()
207 * Since the user area registers are put on power always-on region, 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()
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()
236 * Since the user area registers are put on power always-on region, 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()
250 * Since the user area registers are put on power always-on region, 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()
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()
281 * When system boots on, we can not read battery capacity from coulomb
284 * capacity according to the capacity table.
288 int volt, cur, oci, ocv, ret; in sc27xx_fgu_get_boot_capacity() local
293 * battery capacity as the initial battery capacity. Otherwise we should in sc27xx_fgu_get_boot_capacity()
294 * re-calculate the initial battery capacity. 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()
317 * Should get the OCV from SC27XX_FGU_POCV register at the system in sc27xx_fgu_get_boot_capacity()
321 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_POCV, &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()
330 * Parse the capacity table to look up the correct capacity percent in sc27xx_fgu_get_boot_capacity()
331 * according to current battery's corresponding OCV values. in sc27xx_fgu_get_boot_capacity()
333 *cap = power_supply_ocv2cap_simple(data->cap_table, data->table_len, in sc27xx_fgu_get_boot_capacity()
334 ocv); in sc27xx_fgu_get_boot_capacity()
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()
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()
390 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_VOLTAGE_BUF, in sc27xx_fgu_get_vol_now()
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()
432 delta_clbcnt = cur_clbcnt - data->init_clbcnt; in sc27xx_fgu_get_capacity()
435 * Convert coulomb counter to delta capacity (mAh), and set multiplier in sc27xx_fgu_get_capacity()
442 * Convert to capacity percent of the battery total capacity, 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()
448 /* Calibrate the battery capacity in a normal range. */ in sc27xx_fgu_get_capacity()
458 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_VOLTAGE, &vol); in sc27xx_fgu_get_vbat_vol()
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()
500 resistance = data->internal_resist; in sc27xx_fgu_get_vbat_ocv()
501 if (data->resist_table_len > 0) { 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()
511 /* Return the battery OCV in micro volts. */ in sc27xx_fgu_get_vbat_ocv()
512 *val = vol * 1000 - cur * resistance; in sc27xx_fgu_get_vbat_ocv()
521 ret = iio_read_channel_processed(data->charge_chan, &vol); in sc27xx_fgu_get_charge_vol()
531 return iio_read_channel_processed(data->channel, temp); in sc27xx_fgu_get_temp()
542 if (vol > data->max_volt) in sc27xx_fgu_get_health()
554 int i, ret = -EINVAL; in sc27xx_fgu_get_status()
581 mutex_lock(&data->lock); in sc27xx_fgu_get_property()
589 val->intval = value; in sc27xx_fgu_get_property()
597 val->intval = value; in sc27xx_fgu_get_property()
601 val->intval = data->bat_present; in sc27xx_fgu_get_property()
609 val->intval = value; in sc27xx_fgu_get_property()
613 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in sc27xx_fgu_get_property()
621 val->intval = value; in sc27xx_fgu_get_property()
629 val->intval = value * 1000; in sc27xx_fgu_get_property()
637 val->intval = value; in sc27xx_fgu_get_property()
645 val->intval = value; in sc27xx_fgu_get_property()
653 val->intval = value * 1000; in sc27xx_fgu_get_property()
657 val->intval = data->total_cap * 1000; in sc27xx_fgu_get_property()
667 val->intval = sc27xx_fgu_adc_to_current(data, value); in sc27xx_fgu_get_property()
676 val->intval = value * 1000; in sc27xx_fgu_get_property()
684 val->intval = value * 1000; in sc27xx_fgu_get_property()
688 val->intval = data->boot_volt; in sc27xx_fgu_get_property()
692 ret = -EINVAL; in sc27xx_fgu_get_property()
697 mutex_unlock(&data->lock); in sc27xx_fgu_get_property()
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()
728 ret = -EINVAL; in sc27xx_fgu_set_property()
731 mutex_unlock(&data->lock); in sc27xx_fgu_set_property()
764 .name = "sc27xx-fgu",
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()
788 int ret, ocv, chg_sts, adc; in sc27xx_fgu_capacity_calibration() local
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()
798 dev_err(data->dev, "get charger status error.\n"); in sc27xx_fgu_capacity_calibration()
804 * lower capacity. in sc27xx_fgu_capacity_calibration()
809 if ((ocv > data->cap_table[0].ocv && cap < 100) || cap > 100) { in sc27xx_fgu_capacity_calibration()
811 * If current OCV value is larger than the max OCV value in in sc27xx_fgu_capacity_calibration()
812 * OCV table, or the current capacity is larger than 100, in sc27xx_fgu_capacity_calibration()
813 * we should force the inititial capacity to 100. in sc27xx_fgu_capacity_calibration()
816 } else if (ocv <= data->cap_table[data->table_len - 1].ocv) { in sc27xx_fgu_capacity_calibration()
818 * If current OCV value is leass than the minimum OCV value in in sc27xx_fgu_capacity_calibration()
819 * OCV table, we should force the inititial capacity to 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()
825 * If current OCV value is not matchable with current capacity, in sc27xx_fgu_capacity_calibration()
826 * we should re-calculate current capacity by looking up the in sc27xx_fgu_capacity_calibration()
827 * OCV table. 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()
833 } else if (ocv <= data->min_volt) { in sc27xx_fgu_capacity_calibration()
835 * If current OCV value is less than the low alarm voltage, but in sc27xx_fgu_capacity_calibration()
836 * current capacity is larger than the alarm capacity, we should in sc27xx_fgu_capacity_calibration()
837 * adjust the inititial capacity to alarm capacity. 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()
845 * If current capacity is equal with 0 or less than 0 in sc27xx_fgu_capacity_calibration()
847 * capacity to the capacity corresponding to current OCV 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()
852 ocv); in sc27xx_fgu_capacity_calibration()
860 * After adjusting the battery capacity, we should set the 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()
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()
895 * battery capacity in lower voltage stage. in sc27xx_fgu_interrupt()
907 mutex_unlock(&data->lock); in sc27xx_fgu_interrupt()
909 power_supply_changed(data->battery); in sc27xx_fgu_interrupt()
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()
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
946 * Get current capacity (mAh) = battery total capacity (mAh) * in sc27xx_fgu_cap_to_clbcnt()
947 * current capacity percent (capacity / 100). in sc27xx_fgu_cap_to_clbcnt()
949 int cur_cap = DIV_ROUND_CLOSEST(data->total_cap * capacity, 100); in sc27xx_fgu_cap_to_clbcnt()
952 * Convert current capacity (mAh) to coulomb counter according to the 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()
965 cell = nvmem_cell_get(data->dev, "fgu_calib"); in sc27xx_fgu_calibration()
982 cal_4200mv = (calib_data & 0x1ff) + 6963 - 4096 - 256; 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()
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()
1010 * For SC27XX fuel gauge device, we only use one ocv-capacity in sc27xx_fgu_hw_init()
1013 table = power_supply_find_ocv2cap_table(info, 20, &data->table_len); in sc27xx_fgu_hw_init()
1015 return -EINVAL; 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()
1022 return -ENOMEM; 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()
1039 return -ENOMEM; in sc27xx_fgu_hw_init()
1043 power_supply_put_battery_info(data->battery, info); 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()
1089 * capacity. Now we set the delta threshold as a counter value of 1% in sc27xx_fgu_hw_init()
1090 * capacity. 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()
1110 * Get the boot battery capacity when system powers on, which is used to in sc27xx_fgu_hw_init()
1112 * counter to measure the battery capacity. 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()
1121 * Convert battery capacity to the corresponding initial coulomb counter 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()
1143 struct device *dev = &pdev->dev; in sc27xx_fgu_probe()
1144 struct device_node *np = dev->of_node; in sc27xx_fgu_probe()
1151 return -ENOMEM; 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()
1156 return -ENODEV; in sc27xx_fgu_probe()
1159 ret = device_property_read_u32(dev, "reg", &data->base); in sc27xx_fgu_probe()
1165 ret = device_property_read_u32(&pdev->dev, in sc27xx_fgu_probe()
1166 "sprd,calib-resistance-micro-ohms", in sc27xx_fgu_probe()
1167 &data->calib_resist); in sc27xx_fgu_probe()
1169 dev_err(&pdev->dev, 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, "battery-detect", GPIOD_IN); in sc27xx_fgu_probe()
1187 if (IS_ERR(data->gpiod)) { in sc27xx_fgu_probe()
1188 data->gpiod = devm_gpiod_get(dev, "bat-detect", GPIOD_IN); in sc27xx_fgu_probe()
1189 if (IS_ERR(data->gpiod)) { in sc27xx_fgu_probe()
1191 return PTR_ERR(data->gpiod); in sc27xx_fgu_probe()
1193 dev_warn(dev, "bat-detect is deprecated, please use battery-detect\n"); in sc27xx_fgu_probe()
1196 ret = gpiod_get_value_cansleep(data->gpiod); in sc27xx_fgu_probe()
1202 data->bat_present = !!ret; in sc27xx_fgu_probe()
1203 mutex_init(&data->lock); in sc27xx_fgu_probe()
1204 data->dev = dev; in sc27xx_fgu_probe()
1209 data->battery = devm_power_supply_register(dev, &sc27xx_fgu_desc, in sc27xx_fgu_probe()
1211 if (IS_ERR(data->battery)) { in sc27xx_fgu_probe()
1213 return PTR_ERR(data->battery); in sc27xx_fgu_probe()
1232 ret = devm_request_threaded_irq(data->dev, irq, NULL, in sc27xx_fgu_probe()
1235 pdev->name, data); in sc27xx_fgu_probe()
1237 dev_err(data->dev, "failed to request fgu IRQ\n"); in sc27xx_fgu_probe()
1241 irq = gpiod_to_irq(data->gpiod); in sc27xx_fgu_probe()
1251 pdev->name, data); in sc27xx_fgu_probe()
1266 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_resume()
1270 dev_err(data->dev, "failed to disable fgu interrupts\n"); in sc27xx_fgu_resume()
1280 int ret, status, ocv; in sc27xx_fgu_suspend() local
1288 * adjust the battery capacity. in sc27xx_fgu_suspend()
1294 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1298 dev_err(data->dev, "failed to enable low voltage interrupt\n"); in sc27xx_fgu_suspend()
1302 ret = sc27xx_fgu_get_vbat_ocv(data, &ocv); in sc27xx_fgu_suspend()
1307 * If current OCV is less than the minimum voltage, we should enable the in sc27xx_fgu_suspend()
1309 * battery capacity. in sc27xx_fgu_suspend()
1311 if (ocv < data->min_volt) { in sc27xx_fgu_suspend()
1312 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_suspend()
1313 data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1317 dev_err(data->dev, in sc27xx_fgu_suspend()
1326 regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1337 { .compatible = "sprd,sc2731-fgu", },
1345 .name = "sc27xx-fgu",