Lines Matching +full:ocv +full:- +full:capacity +full:- +full:celsius

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()
740 power_supply_changed(data->battery); in sc27xx_fgu_external_power_changed()
771 .name = "sc27xx-fgu",
786 data->init_cap = cap; in sc27xx_fgu_adjust_cap()
787 ret = sc27xx_fgu_get_clbcnt(data, &data->init_clbcnt); in sc27xx_fgu_adjust_cap()
789 dev_err(data->dev, "failed to get init coulomb counter\n"); in sc27xx_fgu_adjust_cap()
795 int ret, ocv, chg_sts, adc; in sc27xx_fgu_capacity_calibration() local
797 ret = sc27xx_fgu_get_vbat_ocv(data, &ocv); in sc27xx_fgu_capacity_calibration()
799 dev_err(data->dev, "get battery ocv error.\n"); in sc27xx_fgu_capacity_calibration()
805 dev_err(data->dev, "get charger status error.\n"); in sc27xx_fgu_capacity_calibration()
811 * lower capacity. in sc27xx_fgu_capacity_calibration()
816 if ((ocv > data->cap_table[0].ocv && cap < 100) || cap > 100) { in sc27xx_fgu_capacity_calibration()
818 * If current OCV value is larger than the max OCV value in in sc27xx_fgu_capacity_calibration()
819 * OCV table, or the current capacity is larger than 100, in sc27xx_fgu_capacity_calibration()
820 * we should force the inititial capacity to 100. in sc27xx_fgu_capacity_calibration()
823 } else if (ocv <= data->cap_table[data->table_len - 1].ocv) { in sc27xx_fgu_capacity_calibration()
825 * If current OCV value is leass than the minimum OCV value in in sc27xx_fgu_capacity_calibration()
826 * OCV table, we should force the inititial capacity to 0. in sc27xx_fgu_capacity_calibration()
829 } else if ((ocv > data->cap_table[data->table_len - 1].ocv && cap <= 0) || in sc27xx_fgu_capacity_calibration()
830 (ocv > data->min_volt && cap <= data->alarm_cap)) { in sc27xx_fgu_capacity_calibration()
832 * If current OCV value is not matchable with current capacity, in sc27xx_fgu_capacity_calibration()
833 * we should re-calculate current capacity by looking up the in sc27xx_fgu_capacity_calibration()
834 * OCV table. in sc27xx_fgu_capacity_calibration()
836 int cur_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_capacity_calibration()
837 data->table_len, ocv); in sc27xx_fgu_capacity_calibration()
840 } else if (ocv <= data->min_volt) { in sc27xx_fgu_capacity_calibration()
842 * If current OCV value is less than the low alarm voltage, but in sc27xx_fgu_capacity_calibration()
843 * current capacity is larger than the alarm capacity, we should in sc27xx_fgu_capacity_calibration()
844 * adjust the inititial capacity to alarm capacity. in sc27xx_fgu_capacity_calibration()
846 if (cap > data->alarm_cap) { in sc27xx_fgu_capacity_calibration()
847 sc27xx_fgu_adjust_cap(data, data->alarm_cap); in sc27xx_fgu_capacity_calibration()
852 * If current capacity is equal with 0 or less than 0 in sc27xx_fgu_capacity_calibration()
854 * capacity to the capacity corresponding to current OCV in sc27xx_fgu_capacity_calibration()
857 cur_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_capacity_calibration()
858 data->table_len, in sc27xx_fgu_capacity_calibration()
859 ocv); in sc27xx_fgu_capacity_calibration()
867 * After adjusting the battery capacity, we should set the in sc27xx_fgu_capacity_calibration()
870 data->min_volt = data->cap_table[data->table_len - 1].ocv; in sc27xx_fgu_capacity_calibration()
871 data->alarm_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_capacity_calibration()
872 data->table_len, in sc27xx_fgu_capacity_calibration()
873 data->min_volt); in sc27xx_fgu_capacity_calibration()
875 adc = sc27xx_fgu_voltage_to_adc(data, data->min_volt / 1000); in sc27xx_fgu_capacity_calibration()
876 regmap_update_bits(data->regmap, in sc27xx_fgu_capacity_calibration()
877 data->base + SC27XX_FGU_LOW_OVERLOAD, in sc27xx_fgu_capacity_calibration()
888 mutex_lock(&data->lock); in sc27xx_fgu_interrupt()
890 ret = regmap_read(data->regmap, data->base + SC27XX_FGU_INT_STS, in sc27xx_fgu_interrupt()
895 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_CLR, in sc27xx_fgu_interrupt()
902 * battery capacity in lower voltage stage. in sc27xx_fgu_interrupt()
914 mutex_unlock(&data->lock); in sc27xx_fgu_interrupt()
916 power_supply_changed(data->battery); in sc27xx_fgu_interrupt()
925 mutex_lock(&data->lock); in sc27xx_fgu_bat_detection()
927 state = gpiod_get_value_cansleep(data->gpiod); in sc27xx_fgu_bat_detection()
929 dev_err(data->dev, "failed to get gpio state\n"); in sc27xx_fgu_bat_detection()
930 mutex_unlock(&data->lock); in sc27xx_fgu_bat_detection()
934 data->bat_present = !!state; in sc27xx_fgu_bat_detection()
936 mutex_unlock(&data->lock); in sc27xx_fgu_bat_detection()
938 power_supply_changed(data->battery); in sc27xx_fgu_bat_detection()
946 regmap_update_bits(data->regmap, SC27XX_CLK_EN0, SC27XX_FGU_RTC_EN, 0); in sc27xx_fgu_disable()
947 regmap_update_bits(data->regmap, SC27XX_MODULE_EN0, SC27XX_FGU_EN, 0); in sc27xx_fgu_disable()
950 static int sc27xx_fgu_cap_to_clbcnt(struct sc27xx_fgu_data *data, int capacity) in sc27xx_fgu_cap_to_clbcnt() argument
953 * Get current capacity (mAh) = battery total capacity (mAh) * in sc27xx_fgu_cap_to_clbcnt()
954 * current capacity percent (capacity / 100). in sc27xx_fgu_cap_to_clbcnt()
956 int cur_cap = DIV_ROUND_CLOSEST(data->total_cap * capacity, 100); in sc27xx_fgu_cap_to_clbcnt()
959 * Convert current capacity (mAh) to coulomb counter according to the in sc27xx_fgu_cap_to_clbcnt()
962 return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc * SC27XX_FGU_SAMPLE_HZ, 10); in sc27xx_fgu_cap_to_clbcnt()
972 cell = nvmem_cell_get(data->dev, "fgu_calib"); in sc27xx_fgu_calibration()
989 cal_4200mv = (calib_data & 0x1ff) + 6963 - 4096 - 256; in sc27xx_fgu_calibration()
990 data->vol_1000mv_adc = DIV_ROUND_CLOSEST(cal_4200mv * 10, 42); in sc27xx_fgu_calibration()
991 data->cur_1000ma_adc = in sc27xx_fgu_calibration()
992 DIV_ROUND_CLOSEST(data->vol_1000mv_adc * 4 * data->calib_resist, in sc27xx_fgu_calibration()
1005 ret = power_supply_get_battery_info(data->battery, &info); in sc27xx_fgu_hw_init()
1007 dev_err(data->dev, "failed to get battery information\n"); in sc27xx_fgu_hw_init()
1011 data->total_cap = info.charge_full_design_uah / 1000; in sc27xx_fgu_hw_init()
1012 data->max_volt = info.constant_charge_voltage_max_uv / 1000; in sc27xx_fgu_hw_init()
1013 data->internal_resist = info.factory_internal_resistance_uohm / 1000; in sc27xx_fgu_hw_init()
1014 data->min_volt = info.voltage_min_design_uv; in sc27xx_fgu_hw_init()
1017 * For SC27XX fuel gauge device, we only use one ocv-capacity in sc27xx_fgu_hw_init()
1018 * table in normal temperature 20 Celsius. in sc27xx_fgu_hw_init()
1020 table = power_supply_find_ocv2cap_table(&info, 20, &data->table_len); in sc27xx_fgu_hw_init()
1022 return -EINVAL; in sc27xx_fgu_hw_init()
1024 data->cap_table = devm_kmemdup(data->dev, table, in sc27xx_fgu_hw_init()
1025 data->table_len * sizeof(*table), in sc27xx_fgu_hw_init()
1027 if (!data->cap_table) { in sc27xx_fgu_hw_init()
1028 power_supply_put_battery_info(data->battery, &info); in sc27xx_fgu_hw_init()
1029 return -ENOMEM; in sc27xx_fgu_hw_init()
1032 data->alarm_cap = power_supply_ocv2cap_simple(data->cap_table, in sc27xx_fgu_hw_init()
1033 data->table_len, in sc27xx_fgu_hw_init()
1034 data->min_volt); in sc27xx_fgu_hw_init()
1035 if (!data->alarm_cap) in sc27xx_fgu_hw_init()
1036 data->alarm_cap += 1; in sc27xx_fgu_hw_init()
1038 data->resist_table_len = info.resist_table_size; in sc27xx_fgu_hw_init()
1039 if (data->resist_table_len > 0) { in sc27xx_fgu_hw_init()
1040 data->resist_table = devm_kmemdup(data->dev, info.resist_table, in sc27xx_fgu_hw_init()
1041 data->resist_table_len * in sc27xx_fgu_hw_init()
1044 if (!data->resist_table) { in sc27xx_fgu_hw_init()
1045 power_supply_put_battery_info(data->battery, &info); in sc27xx_fgu_hw_init()
1046 return -ENOMEM; in sc27xx_fgu_hw_init()
1050 power_supply_put_battery_info(data->battery, &info); in sc27xx_fgu_hw_init()
1057 ret = regmap_update_bits(data->regmap, SC27XX_MODULE_EN0, in sc27xx_fgu_hw_init()
1060 dev_err(data->dev, "failed to enable fgu\n"); in sc27xx_fgu_hw_init()
1065 ret = regmap_update_bits(data->regmap, SC27XX_CLK_EN0, in sc27xx_fgu_hw_init()
1068 dev_err(data->dev, "failed to enable fgu RTC clock\n"); in sc27xx_fgu_hw_init()
1072 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_CLR, in sc27xx_fgu_hw_init()
1075 dev_err(data->dev, "failed to clear interrupt status\n"); in sc27xx_fgu_hw_init()
1084 alarm_adc = sc27xx_fgu_voltage_to_adc(data, data->min_volt / 1000); in sc27xx_fgu_hw_init()
1085 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_LOW_OVERLOAD, in sc27xx_fgu_hw_init()
1088 dev_err(data->dev, "failed to set fgu low overload\n"); in sc27xx_fgu_hw_init()
1096 * capacity. Now we set the delta threshold as a counter value of 1% in sc27xx_fgu_hw_init()
1097 * capacity. in sc27xx_fgu_hw_init()
1101 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_CLBCNT_DELTL, in sc27xx_fgu_hw_init()
1104 dev_err(data->dev, "failed to set low delta coulomb counter\n"); in sc27xx_fgu_hw_init()
1108 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_CLBCNT_DELTH, in sc27xx_fgu_hw_init()
1112 dev_err(data->dev, "failed to set high delta coulomb counter\n"); in sc27xx_fgu_hw_init()
1117 * Get the boot battery capacity when system powers on, which is used to in sc27xx_fgu_hw_init()
1119 * counter to measure the battery capacity. in sc27xx_fgu_hw_init()
1121 ret = sc27xx_fgu_get_boot_capacity(data, &data->init_cap); in sc27xx_fgu_hw_init()
1123 dev_err(data->dev, "failed to get boot capacity\n"); in sc27xx_fgu_hw_init()
1128 * Convert battery capacity to the corresponding initial coulomb counter in sc27xx_fgu_hw_init()
1131 data->init_clbcnt = sc27xx_fgu_cap_to_clbcnt(data, data->init_cap); in sc27xx_fgu_hw_init()
1132 ret = sc27xx_fgu_set_clbcnt(data, data->init_clbcnt); in sc27xx_fgu_hw_init()
1134 dev_err(data->dev, "failed to initialize coulomb counter\n"); in sc27xx_fgu_hw_init()
1141 regmap_update_bits(data->regmap, SC27XX_CLK_EN0, SC27XX_FGU_RTC_EN, 0); in sc27xx_fgu_hw_init()
1143 regmap_update_bits(data->regmap, SC27XX_MODULE_EN0, SC27XX_FGU_EN, 0); in sc27xx_fgu_hw_init()
1150 struct device *dev = &pdev->dev; in sc27xx_fgu_probe()
1151 struct device_node *np = dev->of_node; in sc27xx_fgu_probe()
1158 return -ENOMEM; in sc27xx_fgu_probe()
1160 data->regmap = dev_get_regmap(dev->parent, NULL); in sc27xx_fgu_probe()
1161 if (!data->regmap) { in sc27xx_fgu_probe()
1163 return -ENODEV; in sc27xx_fgu_probe()
1166 ret = device_property_read_u32(dev, "reg", &data->base); in sc27xx_fgu_probe()
1172 ret = device_property_read_u32(&pdev->dev, in sc27xx_fgu_probe()
1173 "sprd,calib-resistance-micro-ohms", in sc27xx_fgu_probe()
1174 &data->calib_resist); in sc27xx_fgu_probe()
1176 dev_err(&pdev->dev, in sc27xx_fgu_probe()
1181 data->channel = devm_iio_channel_get(dev, "bat-temp"); in sc27xx_fgu_probe()
1182 if (IS_ERR(data->channel)) { in sc27xx_fgu_probe()
1184 return PTR_ERR(data->channel); in sc27xx_fgu_probe()
1187 data->charge_chan = devm_iio_channel_get(dev, "charge-vol"); in sc27xx_fgu_probe()
1188 if (IS_ERR(data->charge_chan)) { in sc27xx_fgu_probe()
1190 return PTR_ERR(data->charge_chan); in sc27xx_fgu_probe()
1193 data->gpiod = devm_gpiod_get(dev, "bat-detect", GPIOD_IN); in sc27xx_fgu_probe()
1194 if (IS_ERR(data->gpiod)) { in sc27xx_fgu_probe()
1196 return PTR_ERR(data->gpiod); in sc27xx_fgu_probe()
1199 ret = gpiod_get_value_cansleep(data->gpiod); in sc27xx_fgu_probe()
1205 data->bat_present = !!ret; in sc27xx_fgu_probe()
1206 mutex_init(&data->lock); in sc27xx_fgu_probe()
1207 data->dev = dev; in sc27xx_fgu_probe()
1212 data->battery = devm_power_supply_register(dev, &sc27xx_fgu_desc, in sc27xx_fgu_probe()
1214 if (IS_ERR(data->battery)) { in sc27xx_fgu_probe()
1216 return PTR_ERR(data->battery); in sc27xx_fgu_probe()
1237 ret = devm_request_threaded_irq(data->dev, irq, NULL, in sc27xx_fgu_probe()
1240 pdev->name, data); in sc27xx_fgu_probe()
1242 dev_err(data->dev, "failed to request fgu IRQ\n"); in sc27xx_fgu_probe()
1246 irq = gpiod_to_irq(data->gpiod); in sc27xx_fgu_probe()
1256 pdev->name, data); in sc27xx_fgu_probe()
1271 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_resume()
1275 dev_err(data->dev, "failed to disable fgu interrupts\n"); in sc27xx_fgu_resume()
1285 int ret, status, ocv; in sc27xx_fgu_suspend() local
1293 * adjust the battery capacity. in sc27xx_fgu_suspend()
1299 ret = regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1303 dev_err(data->dev, "failed to enable low voltage interrupt\n"); in sc27xx_fgu_suspend()
1307 ret = sc27xx_fgu_get_vbat_ocv(data, &ocv); in sc27xx_fgu_suspend()
1312 * If current OCV is less than the minimum voltage, we should enable the in sc27xx_fgu_suspend()
1314 * battery capacity. in sc27xx_fgu_suspend()
1316 if (ocv < data->min_volt) { in sc27xx_fgu_suspend()
1317 ret = regmap_update_bits(data->regmap, in sc27xx_fgu_suspend()
1318 data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1322 dev_err(data->dev, in sc27xx_fgu_suspend()
1331 regmap_update_bits(data->regmap, data->base + SC27XX_FGU_INT_EN, in sc27xx_fgu_suspend()
1342 { .compatible = "sprd,sc2731-fgu", },
1349 .name = "sc27xx-fgu",