drivers/power/supply/rx51_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/rx51_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/rx51_battery.c- Extension
.c- Size
- 6719 bytes
- Lines
- 249
- Domain
- Driver Families
- Bucket
- drivers/power
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/param.hlinux/platform_device.hlinux/power_supply.hlinux/slab.hlinux/iio/consumer.hlinux/of.h
Detected Declarations
struct rx51_device_infofunction rx51_battery_read_adcfunction rx51_battery_read_voltagefunction rx51_battery_read_temperaturefunction rx51_battery_read_capacityfunction rx51_battery_get_propertyfunction rx51_battery_probe
Annotated Snippet
struct rx51_device_info {
struct device *dev;
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct iio_channel *channel_temp;
struct iio_channel *channel_bsi;
struct iio_channel *channel_vbat;
};
/*
* Read ADCIN channel value, code copied from maemo kernel
*/
static int rx51_battery_read_adc(struct iio_channel *channel)
{
int val, err;
err = iio_read_channel_average_raw(channel, &val);
if (err < 0)
return err;
return val;
}
/*
* 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)
{
int voltage = rx51_battery_read_adc(di->channel_vbat);
if (voltage < 0) {
dev_err(di->dev, "Could not read ADC: %d\n", voltage);
return voltage;
}
return 1000 * (10000 * voltage / 1705);
}
/*
* 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[] = {
255, 201, 159, 138, 124, 114, 106, 99, 94, 89, 85, 82, 78, 75,
73, 70, 68, 66, 64, 62, 61, 59, 57, 56, 55
};
/*
* 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 53
static u16 rx51_temp_table2[] = {
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39,
40, 41, 43, 44, 46, 48, 49, 51, 53, 55, 57, 59, 61, 64,
66, 69, 71, 74, 77, 80, 83, 86, 90, 94, 97, 101, 106, 110,
115, 119, 125, 130, 136, 141, 148, 154, 161, 168, 176, 184, 202, 211,
221, 231, 242, 254, 266, 279, 293, 308, 323, 340, 357, 375, 395, 415,
437, 460, 485, 511, 539, 568, 600, 633, 669, 706, 747, 790, 836, 885,
937, 993, 1024
};
/*
* 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)
{
int min = 0;
int max = ARRAY_SIZE(rx51_temp_table2) - 1;
int raw = rx51_battery_read_adc(di->channel_temp);
if (raw < 0)
dev_err(di->dev, "Could not read ADC: %d\n", raw);
/* Zero and negative values are undefined */
if (raw <= 0)
return INT_MAX;
Annotation
- Immediate include surface: `linux/module.h`, `linux/param.h`, `linux/platform_device.h`, `linux/power_supply.h`, `linux/slab.h`, `linux/iio/consumer.h`, `linux/of.h`.
- Detected declarations: `struct rx51_device_info`, `function rx51_battery_read_adc`, `function rx51_battery_read_voltage`, `function rx51_battery_read_temperature`, `function rx51_battery_read_capacity`, `function rx51_battery_get_property`, `function rx51_battery_probe`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.