Lines Matching +full:adc +full:- +full:battery
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Nokia RX-51 battery driver
39 * This conversion formula was extracted from maemo program bsi-read
43 int voltage = rx51_battery_read_adc(di->channel_vbat); in rx51_battery_read_voltage()
46 dev_err(di->dev, "Could not read ADC: %d\n", voltage); in rx51_battery_read_voltage()
54 * Temperature look-up tables
55 * TEMP = (1/(t1 + 1/298) - 273.15)
57 * Formula is based on experimental data, RX-51 CAL data, maemo program bme
74 * Usage: RAW = rx51_temp_table2[TEMP-rx51_temp_table2_first]
75 * TEMP is between 53 C and -32 C
90 * Read ADCIN channel 0 (battery temp) and convert value to tenths of Celsius
91 * Use Temperature look-up tables for conversation
96 int max = ARRAY_SIZE(rx51_temp_table2) - 1; in rx51_battery_read_temperature()
97 int raw = rx51_battery_read_adc(di->channel_temp); in rx51_battery_read_temperature()
100 dev_err(di->dev, "Could not read ADC: %d\n", raw); in rx51_battery_read_temperature()
106 /* ADC channels are 10 bit, higher value are undefined */ in rx51_battery_read_temperature()
115 while (max - min > 1) { in rx51_battery_read_temperature()
125 return (rx51_temp_table2_first - min) * 10; in rx51_battery_read_temperature()
130 * This conversion formula was extracted from maemo program bsi-read
134 int capacity = rx51_battery_read_adc(di->channel_bsi); in rx51_battery_read_capacity()
137 dev_err(di->dev, "Could not read ADC: %d\n", capacity); in rx51_battery_read_capacity()
141 return 1280 * (1200 * capacity)/(1024 - capacity); in rx51_battery_read_capacity()
155 val->intval = POWER_SUPPLY_TECHNOLOGY_LION; in rx51_battery_get_property()
158 val->intval = 4200000; in rx51_battery_get_property()
161 val->intval = rx51_battery_read_voltage(di) ? 1 : 0; in rx51_battery_get_property()
164 val->intval = rx51_battery_read_voltage(di); in rx51_battery_get_property()
167 val->intval = rx51_battery_read_temperature(di); in rx51_battery_get_property()
170 val->intval = rx51_battery_read_capacity(di); in rx51_battery_get_property()
173 return -EINVAL; in rx51_battery_get_property()
176 if (val->intval == INT_MAX || val->intval == INT_MIN) in rx51_battery_get_property()
177 return -EINVAL; in rx51_battery_get_property()
197 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); in rx51_battery_probe()
199 return -ENOMEM; in rx51_battery_probe()
203 di->dev = &pdev->dev; in rx51_battery_probe()
204 di->bat_desc.name = "rx51-battery"; in rx51_battery_probe()
205 di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY; in rx51_battery_probe()
206 di->bat_desc.properties = rx51_battery_props; in rx51_battery_probe()
207 di->bat_desc.num_properties = ARRAY_SIZE(rx51_battery_props); in rx51_battery_probe()
208 di->bat_desc.get_property = rx51_battery_get_property; in rx51_battery_probe()
212 di->channel_temp = iio_channel_get(di->dev, "temp"); in rx51_battery_probe()
213 if (IS_ERR(di->channel_temp)) { in rx51_battery_probe()
214 ret = PTR_ERR(di->channel_temp); in rx51_battery_probe()
218 di->channel_bsi = iio_channel_get(di->dev, "bsi"); in rx51_battery_probe()
219 if (IS_ERR(di->channel_bsi)) { in rx51_battery_probe()
220 ret = PTR_ERR(di->channel_bsi); in rx51_battery_probe()
224 di->channel_vbat = iio_channel_get(di->dev, "vbat"); in rx51_battery_probe()
225 if (IS_ERR(di->channel_vbat)) { in rx51_battery_probe()
226 ret = PTR_ERR(di->channel_vbat); in rx51_battery_probe()
230 di->bat = power_supply_register(di->dev, &di->bat_desc, &psy_cfg); in rx51_battery_probe()
231 if (IS_ERR(di->bat)) { in rx51_battery_probe()
232 ret = PTR_ERR(di->bat); in rx51_battery_probe()
239 iio_channel_release(di->channel_vbat); in rx51_battery_probe()
241 iio_channel_release(di->channel_bsi); in rx51_battery_probe()
243 iio_channel_release(di->channel_temp); in rx51_battery_probe()
253 power_supply_unregister(di->bat); in rx51_battery_remove()
255 iio_channel_release(di->channel_vbat); in rx51_battery_remove()
256 iio_channel_release(di->channel_bsi); in rx51_battery_remove()
257 iio_channel_release(di->channel_temp); in rx51_battery_remove()
264 {.compatible = "nokia,n900-battery", },
274 .name = "rx51-battery",
280 MODULE_ALIAS("platform:rx51-battery");
282 MODULE_DESCRIPTION("Nokia RX-51 battery driver");