drivers/power/supply/ucs1002_power.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/ucs1002_power.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/ucs1002_power.c- Extension
.c- Size
- 17988 bytes
- Lines
- 689
- 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.
- 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/freezer.hlinux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/kthread.hlinux/device.hlinux/module.hlinux/of.hlinux/of_irq.hlinux/power_supply.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
struct ucs1002_infofunction ucs1002_get_onlinefunction ucs1002_get_chargefunction ucs1002_get_currentfunction ucs1002_get_max_currentfunction ucs1002_set_max_currentfunction ucs1002_set_usb_typefunction ucs1002_get_usb_typefunction ucs1002_get_propertyfunction ucs1002_set_propertyfunction ucs1002_property_is_writeablefunction ucs1002_health_pollfunction ucs1002_charger_irqfunction ucs1002_alert_irqfunction ucs1002_regulator_enablefunction ucs1002_probe
Annotated Snippet
struct ucs1002_info {
struct power_supply *charger;
struct i2c_client *client;
struct regmap *regmap;
struct regulator_desc *regulator_descriptor;
struct regulator_dev *rdev;
bool present;
bool output_disable;
struct delayed_work health_poll;
int health;
};
static enum power_supply_property ucs1002_props[] = {
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_CHARGE_NOW,
POWER_SUPPLY_PROP_CURRENT_NOW,
POWER_SUPPLY_PROP_CURRENT_MAX,
POWER_SUPPLY_PROP_PRESENT, /* the presence of PED */
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_USB_TYPE,
POWER_SUPPLY_PROP_HEALTH,
};
static int ucs1002_get_online(struct ucs1002_info *info,
union power_supply_propval *val)
{
unsigned int reg;
int ret;
ret = regmap_read(info->regmap, UCS1002_REG_OTHER_STATUS, ®);
if (ret)
return ret;
val->intval = !!(reg & F_CHG_ACT);
return 0;
}
static int ucs1002_get_charge(struct ucs1002_info *info,
union power_supply_propval *val)
{
/*
* To fit within 32 bits some values are rounded (uA/h)
*
* For Total Accumulated Charge Middle Low Byte register, addr
* 03h, byte 2
*
* B0: 0.01084 mA/h rounded to 11 uA/h
* B1: 0.02169 mA/h rounded to 22 uA/h
* B2: 0.04340 mA/h rounded to 43 uA/h
* B3: 0.08676 mA/h rounded to 87 uA/h
* B4: 0.17350 mA/h rounded to 173 uÁ/h
*
* For Total Accumulated Charge Low Byte register, addr 04h,
* byte 3
*
* B6: 0.00271 mA/h rounded to 3 uA/h
* B7: 0.005422 mA/h rounded to 5 uA/h
*/
static const int bit_weights_uAh[BITS_PER_TYPE(u32)] = {
/*
* Bit corresponding to low byte (offset 0x04)
* B0 B1 B2 B3 B4 B5 B6 B7
*/
0, 0, 0, 0, 0, 0, 3, 5,
/*
* Bit corresponding to middle low byte (offset 0x03)
* B0 B1 B2 B3 B4 B5 B6 B7
*/
11, 22, 43, 87, 173, 347, 694, 1388,
/*
* Bit corresponding to middle high byte (offset 0x02)
* B0 B1 B2 B3 B4 B5 B6 B7
*/
2776, 5552, 11105, 22210, 44420, 88840, 177700, 355400,
/*
* Bit corresponding to high byte (offset 0x01)
* B0 B1 B2 B3 B4 B5 B6 B7
*/
710700, 1421000, 2843000, 5685000, 11371000, 22742000,
45484000, 90968000,
};
unsigned long total_acc_charger;
unsigned int reg;
int i, ret;
ret = regmap_bulk_read(info->regmap, UCS1002_REG_TOTAL_ACC_CHARGE,
®, sizeof(u32));
if (ret)
Annotation
- Immediate include surface: `linux/bits.h`, `linux/freezer.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/kthread.h`, `linux/device.h`, `linux/module.h`.
- Detected declarations: `struct ucs1002_info`, `function ucs1002_get_online`, `function ucs1002_get_charge`, `function ucs1002_get_current`, `function ucs1002_get_max_current`, `function ucs1002_set_max_current`, `function ucs1002_set_usb_type`, `function ucs1002_get_usb_type`, `function ucs1002_get_property`, `function ucs1002_set_property`.
- Atlas domain: Driver Families / drivers/power.
- Implementation status: source implementation candidate.
- 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.