Lines Matching +full:battery +full:- +full:temperature
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
62 * Table1 (temperature for first 25 RAW values)
73 * Table2 (lowest RAW value for temperature)
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()
110 /* First check for temperature in first direct table */ 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()
196 di = devm_kzalloc(&pdev->dev, sizeof(*di), GFP_KERNEL); in rx51_battery_probe()
198 return -ENOMEM; in rx51_battery_probe()
200 di->dev = &pdev->dev; in rx51_battery_probe()
201 di->bat_desc.name = "rx51-battery"; in rx51_battery_probe()
202 di->bat_desc.type = POWER_SUPPLY_TYPE_BATTERY; in rx51_battery_probe()
203 di->bat_desc.properties = rx51_battery_props; in rx51_battery_probe()
204 di->bat_desc.num_properties = ARRAY_SIZE(rx51_battery_props); in rx51_battery_probe()
205 di->bat_desc.get_property = rx51_battery_get_property; in rx51_battery_probe()
209 di->channel_temp = devm_iio_channel_get(di->dev, "temp"); in rx51_battery_probe()
210 if (IS_ERR(di->channel_temp)) in rx51_battery_probe()
211 return PTR_ERR(di->channel_temp); in rx51_battery_probe()
213 di->channel_bsi = devm_iio_channel_get(di->dev, "bsi"); in rx51_battery_probe()
214 if (IS_ERR(di->channel_bsi)) in rx51_battery_probe()
215 return PTR_ERR(di->channel_bsi); in rx51_battery_probe()
217 di->channel_vbat = devm_iio_channel_get(di->dev, "vbat"); in rx51_battery_probe()
218 if (IS_ERR(di->channel_vbat)) in rx51_battery_probe()
219 return PTR_ERR(di->channel_vbat); in rx51_battery_probe()
221 di->bat = devm_power_supply_register(di->dev, &di->bat_desc, &psy_cfg); in rx51_battery_probe()
222 if (IS_ERR(di->bat)) in rx51_battery_probe()
223 return PTR_ERR(di->bat); in rx51_battery_probe()
230 {.compatible = "nokia,n900-battery", },
239 .name = "rx51-battery",
245 MODULE_ALIAS("platform:rx51-battery");
247 MODULE_DESCRIPTION("Nokia RX-51 battery driver");