drivers/power/supply/sbs-battery.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/sbs-battery.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/sbs-battery.c- Extension
.c- Size
- 33489 bytes
- Lines
- 1296
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bits.hlinux/delay.hlinux/devm-helpers.hlinux/err.hlinux/gpio/consumer.hlinux/i2c.hlinux/init.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/property.hlinux/of.hlinux/power/sbs-battery.hlinux/power_supply.hlinux/slab.hlinux/stat.hlinux/string_choices.h
Detected Declarations
struct sbs_infoenum sbs_capacity_modefunction sbs_invalidate_cached_propsfunction sbs_disable_charger_broadcastsfunction sbs_update_presencefunction sbs_read_word_datafunction sbs_read_string_data_fallbackfunction sbs_read_string_datafunction sbs_write_word_datafunction sbs_status_correctfunction sbs_bat_needs_calibrationfunction sbs_get_ti_battery_presence_and_healthfunction sbs_get_battery_presence_and_healthfunction sbs_get_battery_propertyfunction sbs_get_property_indexfunction sbs_unit_adjustmentfunction sbs_set_capacity_modefunction sbs_get_battery_capacityfunction sbs_get_battery_serial_numberfunction sbs_get_chemistryfunction sbs_get_battery_manufacture_datefunction sbs_get_propertyfunction sbs_supply_changedfunction sbs_irqfunction sbs_alertfunction sbs_external_power_changedfunction sbs_delayed_workfunction sbs_probefunction sbs_suspend
Annotated Snippet
struct sbs_info {
struct i2c_client *client;
struct power_supply *power_supply;
bool is_present;
struct gpio_desc *gpio_detect;
bool charger_broadcasts;
int last_state;
int poll_time;
u32 i2c_retry_count;
u32 poll_retry_count;
struct delayed_work work;
struct mutex mode_lock;
u32 flags;
int technology;
char strings[NR_STRING_BUFFERS][I2C_SMBUS_BLOCK_MAX + 1];
};
static char *sbs_get_string_buf(struct sbs_info *chip,
enum power_supply_property psp)
{
int i = 0;
for (i = 0; i < NR_STRING_BUFFERS; i++)
if (string_properties[i] == psp)
return chip->strings[i];
return ERR_PTR(-EINVAL);
}
static void sbs_invalidate_cached_props(struct sbs_info *chip)
{
int i = 0;
chip->technology = -1;
for (i = 0; i < NR_STRING_BUFFERS; i++)
chip->strings[i][0] = 0;
}
static bool force_load;
static int sbs_read_word_data(struct i2c_client *client, u8 address);
static int sbs_write_word_data(struct i2c_client *client, u8 address, u16 value);
static void sbs_disable_charger_broadcasts(struct sbs_info *chip)
{
int val = sbs_read_word_data(chip->client, BATTERY_MODE_OFFSET);
if (val < 0)
goto exit;
val |= BATTERY_MODE_CHARGER_MASK;
val = sbs_write_word_data(chip->client, BATTERY_MODE_OFFSET, val);
exit:
if (val < 0)
dev_err(&chip->client->dev,
"Failed to disable charger broadcasting: %d\n", val);
else
dev_dbg(&chip->client->dev, "%s\n", __func__);
}
static int sbs_update_presence(struct sbs_info *chip, bool is_present)
{
struct i2c_client *client = chip->client;
int retries = chip->i2c_retry_count;
s32 ret = 0;
u8 version;
if (chip->is_present == is_present)
return 0;
if (!is_present) {
chip->is_present = false;
/* Disable PEC when no device is present */
client->flags &= ~I2C_CLIENT_PEC;
sbs_invalidate_cached_props(chip);
return 0;
}
/* Check if device supports packet error checking and use it */
while (retries > 0) {
ret = i2c_smbus_read_word_data(client, REG_ADDR_SPEC_INFO);
if (ret >= 0)
break;
/*
* Some batteries trigger the detection pin before the
* I2C bus is properly connected. This works around the
* issue.
Annotation
- Immediate include surface: `linux/bits.h`, `linux/delay.h`, `linux/devm-helpers.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/init.h`, `linux/interrupt.h`.
- Detected declarations: `struct sbs_info`, `enum sbs_capacity_mode`, `function sbs_invalidate_cached_props`, `function sbs_disable_charger_broadcasts`, `function sbs_update_presence`, `function sbs_read_word_data`, `function sbs_read_string_data_fallback`, `function sbs_read_string_data`, `function sbs_write_word_data`, `function sbs_status_correct`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.