// SPDX-License-Identifier: GPL-2.0-or-later /* * Nokia RX-51 battery driver * * Copyright (C) 2012 Pali Rohár <[email protected]> */ #include <linux/module.h> #include <linux/param.h> #include <linux/platform_device.h> #include <linux/power_supply.h> #include <linux/slab.h> #include <linux/iio/consumer.h> #include <linux/of.h> struct rx51_device_info { … }; /* * Read ADCIN channel value, code copied from maemo kernel */ static int rx51_battery_read_adc(struct iio_channel *channel) { … } /* * Read ADCIN channel 12 (voltage) and convert RAW value to micro voltage * This conversion formula was extracted from maemo program bsi-read */ static int rx51_battery_read_voltage(struct rx51_device_info *di) { … } /* * Temperature look-up tables * TEMP = (1/(t1 + 1/298) - 273.15) * Where t1 = (1/B) * ln((RAW_ADC_U * 2.5)/(R * I * 255)) * Formula is based on experimental data, RX-51 CAL data, maemo program bme * and formula from da9052 driver with values R = 100, B = 3380, I = 0.00671 */ /* * Table1 (temperature for first 25 RAW values) * Usage: TEMP = rx51_temp_table1[RAW] * RAW is between 1 and 24 * TEMP is between 201 C and 55 C */ static u8 rx51_temp_table1[] = …; /* * Table2 (lowest RAW value for temperature) * Usage: RAW = rx51_temp_table2[TEMP-rx51_temp_table2_first] * TEMP is between 53 C and -32 C * RAW is between 25 and 993 */ #define rx51_temp_table2_first … static u16 rx51_temp_table2[] = …; /* * Read ADCIN channel 0 (battery temp) and convert value to tenths of Celsius * Use Temperature look-up tables for conversation */ static int rx51_battery_read_temperature(struct rx51_device_info *di) { … } /* * Read ADCIN channel 4 (BSI) and convert RAW value to micro Ah * This conversion formula was extracted from maemo program bsi-read */ static int rx51_battery_read_capacity(struct rx51_device_info *di) { … } /* * Return power_supply property */ static int rx51_battery_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { … } static enum power_supply_property rx51_battery_props[] = …; static int rx51_battery_probe(struct platform_device *pdev) { … } #ifdef CONFIG_OF static const struct of_device_id n900_battery_of_match[] = …; MODULE_DEVICE_TABLE(of, n900_battery_of_match); #endif static struct platform_driver rx51_battery_driver = …; module_platform_driver(…) …; MODULE_ALIAS(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;