drivers/power/supply/max1721x_battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/max1721x_battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/max1721x_battery.c- Extension
.c- Size
- 13069 bytes
- Lines
- 449
- 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/slab.hlinux/w1.hlinux/regmap.hlinux/power_supply.h
Detected Declarations
struct max17211_device_infofunction max172xx_time_to_psfunction max172xx_percent_to_psfunction max172xx_voltage_to_psfunction max172xx_capacity_to_psfunction max172xx_temperature_to_psfunction max172xx_current_to_voltagefunction to_device_infofunction max1721x_battery_get_propertyfunction get_stringfunction get_sn_stringfunction devm_w1_max1721x_add_device
Annotated Snippet
struct max17211_device_info {
char name[PSY_MAX_NAME_LEN];
struct power_supply *bat;
struct power_supply_desc bat_desc;
struct device *w1_dev;
struct regmap *regmap;
/* battery design format */
unsigned int rsense; /* in tenths uOhm */
char DeviceName[2 * MAX1721X_REG_DEV_NUMB + 1];
char ManufacturerName[2 * MAX1721X_REG_MFG_NUMB + 1];
char SerialNumber[13]; /* see get_sn_str() later for comment */
};
/* Convert regs value to power_supply units */
static inline int max172xx_time_to_ps(unsigned int reg)
{
return reg * 5625 / 1000; /* in sec. */
}
static inline int max172xx_percent_to_ps(unsigned int reg)
{
return reg / 256; /* in percent from 0 to 100 */
}
static inline int max172xx_voltage_to_ps(unsigned int reg)
{
return reg * 1250; /* in uV */
}
static inline int max172xx_capacity_to_ps(unsigned int reg)
{
return reg * 500; /* in uAh */
}
/*
* Current and temperature is signed values, so unsigned regs
* value must be converted to signed type
*/
static inline int max172xx_temperature_to_ps(unsigned int reg)
{
int val = (int16_t)(reg);
return val * 10 / 256; /* in tenths of deg. C */
}
/*
* Calculating current registers resolution:
*
* RSense stored in 10^-5 Ohm, so measurement voltage must be
* in 10^-11 Volts for get current in uA.
* 16 bit current reg fullscale +/-51.2mV is 102400 uV.
* So: 102400 / 65535 * 10^5 = 156252
*/
static inline int max172xx_current_to_voltage(unsigned int reg)
{
int val = (int16_t)(reg);
return val * 156252;
}
static inline struct max17211_device_info *
to_device_info(struct power_supply *psy)
{
return power_supply_get_drvdata(psy);
}
static int max1721x_battery_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct max17211_device_info *info = to_device_info(psy);
unsigned int reg = 0;
int ret = 0;
switch (psp) {
case POWER_SUPPLY_PROP_PRESENT:
/*
* POWER_SUPPLY_PROP_PRESENT will always readable via
* sysfs interface. Value return 0 if battery not
* present or unaccessible via W1.
*/
val->intval =
regmap_read(info->regmap, MAX172XX_REG_STATUS,
®) ? 0 : !(reg & MAX172XX_BAT_PRESENT);
break;
case POWER_SUPPLY_PROP_CAPACITY:
ret = regmap_read(info->regmap, MAX172XX_REG_REPSOC, ®);
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/w1.h`, `linux/regmap.h`, `linux/power_supply.h`.
- Detected declarations: `struct max17211_device_info`, `function max172xx_time_to_ps`, `function max172xx_percent_to_ps`, `function max172xx_voltage_to_ps`, `function max172xx_capacity_to_ps`, `function max172xx_temperature_to_ps`, `function max172xx_current_to_voltage`, `function to_device_info`, `function max1721x_battery_get_property`, `function get_string`.
- 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.