Lines Matching +full:chg +full:- +full:int
1 // SPDX-License-Identifier: GPL-2.0-only
45 static int madc_read(struct iio_channel *channel) in madc_read()
47 int val, err; in madc_read()
55 static int twl4030_madc_bat_get_charging_status(struct twl4030_madc_battery *bt) in twl4030_madc_bat_get_charging_status()
57 return (madc_read(bt->channel_ichg) > 0) ? 1 : 0; in twl4030_madc_bat_get_charging_status()
60 static int twl4030_madc_bat_get_voltage(struct twl4030_madc_battery *bt) in twl4030_madc_bat_get_voltage()
62 return madc_read(bt->channel_vbat); in twl4030_madc_bat_get_voltage()
65 static int twl4030_madc_bat_get_current(struct twl4030_madc_battery *bt) in twl4030_madc_bat_get_current()
67 return madc_read(bt->channel_ichg) * 1000; in twl4030_madc_bat_get_current()
70 static int twl4030_madc_bat_get_temp(struct twl4030_madc_battery *bt) in twl4030_madc_bat_get_temp()
72 return madc_read(bt->channel_temp) * 10; in twl4030_madc_bat_get_temp()
75 static int twl4030_madc_bat_voltscale(struct twl4030_madc_battery *bat, in twl4030_madc_bat_voltscale()
76 int volt) in twl4030_madc_bat_voltscale()
79 int i, res = 0; in twl4030_madc_bat_voltscale()
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()
107 static int twl4030_madc_bat_get_property(struct power_supply *psy, in twl4030_madc_bat_get_property()
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()
139 int percent = twl4030_madc_bat_voltscale(bat, 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()
155 int percent = twl4030_madc_bat_voltscale(bat, in twl4030_madc_bat_get_property()
158 int chg = (percent * (bat->pdata->capacity/1000))/100; in twl4030_madc_bat_get_property() local
161 val->intval = (3600l * chg) / 400; in twl4030_madc_bat_get_property()
165 return -EINVAL; in twl4030_madc_bat_get_property()
180 static int twl4030_cmp(const void *a, const void *b) in twl4030_cmp()
182 return ((struct twl4030_madc_bat_calibration *)b)->voltage - in twl4030_cmp()
183 ((struct twl4030_madc_bat_calibration *)a)->voltage; in twl4030_cmp()
186 static int twl4030_madc_battery_probe(struct platform_device *pdev) in twl4030_madc_battery_probe()
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()