Lines Matching +full:twl4030 +full:- +full:madc
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Dumb driver for LiIon batteries using TWL4030 madc.
57 return (madc_read(bt->channel_ichg) > 0) ? 1 : 0; in twl4030_madc_bat_get_charging_status()
62 return madc_read(bt->channel_vbat); in twl4030_madc_bat_get_voltage()
67 return madc_read(bt->channel_ichg) * 1000; in twl4030_madc_bat_get_current()
72 return madc_read(bt->channel_temp) * 10; in twl4030_madc_bat_get_temp()
83 calibration = bat->pdata->charging; in twl4030_madc_bat_voltscale()
85 calibration = bat->pdata->discharging; in twl4030_madc_bat_voltscale()
93 /* interval found - interpolate within range */ in twl4030_madc_bat_voltscale()
94 res = calibration[i].level - in twl4030_madc_bat_voltscale()
95 ((calibration[i].voltage - volt) * in twl4030_madc_bat_voltscale()
96 (calibration[i].level - in twl4030_madc_bat_voltscale()
98 (calibration[i].voltage - in twl4030_madc_bat_voltscale()
117 val->intval = POWER_SUPPLY_STATUS_FULL; in twl4030_madc_bat_get_property()
120 val->intval = POWER_SUPPLY_STATUS_CHARGING; in twl4030_madc_bat_get_property()
122 val->intval = POWER_SUPPLY_STATUS_DISCHARGING; in twl4030_madc_bat_get_property()
126 val->intval = twl4030_madc_bat_get_voltage(bat) * 1000; in twl4030_madc_bat_get_property()
129 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in twl4030_madc_bat_get_property()
132 val->intval = twl4030_madc_bat_get_current(bat); in twl4030_madc_bat_get_property()
136 val->intval = 1; in twl4030_madc_bat_get_property()
141 val->intval = (percent * bat->pdata->capacity) / 100; in twl4030_madc_bat_get_property()
145 val->intval = twl4030_madc_bat_voltscale(bat, in twl4030_madc_bat_get_property()
149 val->intval = bat->pdata->capacity; in twl4030_madc_bat_get_property()
152 val->intval = twl4030_madc_bat_get_temp(bat); in twl4030_madc_bat_get_property()
158 int chg = (percent * (bat->pdata->capacity/1000))/100; in twl4030_madc_bat_get_property()
161 val->intval = (3600l * chg) / 400; in twl4030_madc_bat_get_property()
165 return -EINVAL; in twl4030_madc_bat_get_property()
182 return ((struct twl4030_madc_bat_calibration *)b)->voltage - in twl4030_cmp()
183 ((struct twl4030_madc_bat_calibration *)a)->voltage; in twl4030_cmp()
189 struct twl4030_madc_bat_platform_data *pdata = pdev->dev.platform_data; in twl4030_madc_battery_probe()
192 twl4030_madc_bat = devm_kzalloc(&pdev->dev, sizeof(*twl4030_madc_bat), in twl4030_madc_battery_probe()
195 return -ENOMEM; in twl4030_madc_battery_probe()
197 twl4030_madc_bat->channel_temp = devm_iio_channel_get(&pdev->dev, "temp"); in twl4030_madc_battery_probe()
198 if (IS_ERR(twl4030_madc_bat->channel_temp)) in twl4030_madc_battery_probe()
199 return PTR_ERR(twl4030_madc_bat->channel_temp); in twl4030_madc_battery_probe()
201 twl4030_madc_bat->channel_ichg = devm_iio_channel_get(&pdev->dev, "ichg"); in twl4030_madc_battery_probe()
202 if (IS_ERR(twl4030_madc_bat->channel_ichg)) in twl4030_madc_battery_probe()
203 return PTR_ERR(twl4030_madc_bat->channel_ichg); in twl4030_madc_battery_probe()
205 twl4030_madc_bat->channel_vbat = devm_iio_channel_get(&pdev->dev, "vbat"); in twl4030_madc_battery_probe()
206 if (IS_ERR(twl4030_madc_bat->channel_vbat)) in twl4030_madc_battery_probe()
207 return PTR_ERR(twl4030_madc_bat->channel_vbat); in twl4030_madc_battery_probe()
210 sort(pdata->charging, pdata->charging_size, in twl4030_madc_battery_probe()
213 sort(pdata->discharging, pdata->discharging_size, in twl4030_madc_battery_probe()
217 twl4030_madc_bat->pdata = pdata; in twl4030_madc_battery_probe()
219 twl4030_madc_bat->psy = devm_power_supply_register(&pdev->dev, in twl4030_madc_battery_probe()
222 if (IS_ERR(twl4030_madc_bat->psy)) in twl4030_madc_battery_probe()
223 return PTR_ERR(twl4030_madc_bat->psy); in twl4030_madc_battery_probe()