drivers/power/supply/cros_charge-control.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/cros_charge-control.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/cros_charge-control.c- Extension
.c- Size
- 9708 bytes
- Lines
- 338
- 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
acpi/battery.hlinux/container_of.hlinux/dmi.hlinux/lockdep.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/types.h
Detected Declarations
struct cros_chctl_privfunction cros_chctl_send_charge_control_cmdfunction cros_chctl_configure_ecfunction cros_chctl_psy_ext_get_propfunction cros_chctl_psy_ext_set_thresholdfunction cros_chctl_psy_ext_set_propfunction cros_chctl_psy_prop_is_writeablefunction cros_chctl_add_batteryfunction cros_chctl_remove_batteryfunction cros_chctl_fwk_charge_control_versionsfunction cros_chctl_probe
Annotated Snippet
struct cros_chctl_priv {
struct device *dev;
struct cros_ec_device *cros_ec;
struct acpi_battery_hook battery_hook;
struct power_supply *hooked_battery;
u8 cmd_version;
const struct power_supply_ext *psy_ext;
struct mutex lock; /* protects fields below and cros_ec */
enum power_supply_charge_behaviour current_behaviour;
u8 current_start_threshold, current_end_threshold;
};
static int cros_chctl_send_charge_control_cmd(struct cros_ec_device *cros_ec,
u8 cmd_version, struct ec_params_charge_control *req)
{
int ret;
static const u8 outsizes[] = {
[1] = offsetof(struct ec_params_charge_control, cmd),
[2] = sizeof(struct ec_params_charge_control),
[3] = sizeof(struct ec_params_charge_control),
};
ret = cros_ec_cmd(cros_ec, cmd_version, EC_CMD_CHARGE_CONTROL, req,
outsizes[cmd_version], NULL, 0);
if (ret < 0)
return ret;
return 0;
}
static int cros_chctl_configure_ec(struct cros_chctl_priv *priv)
{
struct ec_params_charge_control req = {};
lockdep_assert_held(&priv->lock);
req.cmd = EC_CHARGE_CONTROL_CMD_SET;
switch (priv->current_behaviour) {
case POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO:
req.mode = CHARGE_CONTROL_NORMAL;
break;
case POWER_SUPPLY_CHARGE_BEHAVIOUR_INHIBIT_CHARGE:
req.mode = CHARGE_CONTROL_IDLE;
break;
case POWER_SUPPLY_CHARGE_BEHAVIOUR_FORCE_DISCHARGE:
req.mode = CHARGE_CONTROL_DISCHARGE;
break;
default:
return -EINVAL;
}
if (priv->current_behaviour == POWER_SUPPLY_CHARGE_BEHAVIOUR_AUTO &&
!(priv->current_start_threshold == 0 && priv->current_end_threshold == 100)) {
req.sustain_soc.lower = priv->current_start_threshold;
req.sustain_soc.upper = priv->current_end_threshold;
} else {
/* Disable charging limits */
req.sustain_soc.lower = -1;
req.sustain_soc.upper = -1;
}
return cros_chctl_send_charge_control_cmd(priv->cros_ec, priv->cmd_version, &req);
}
static int cros_chctl_psy_ext_get_prop(struct power_supply *psy,
const struct power_supply_ext *ext,
void *data,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct cros_chctl_priv *priv = data;
switch (psp) {
case POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD:
val->intval = priv->current_start_threshold;
return 0;
case POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD:
val->intval = priv->current_end_threshold;
return 0;
case POWER_SUPPLY_PROP_CHARGE_BEHAVIOUR:
val->intval = priv->current_behaviour;
return 0;
default:
return -EINVAL;
}
}
Annotation
- Immediate include surface: `acpi/battery.h`, `linux/container_of.h`, `linux/dmi.h`, `linux/lockdep.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/platform_data/cros_ec_commands.h`.
- Detected declarations: `struct cros_chctl_priv`, `function cros_chctl_send_charge_control_cmd`, `function cros_chctl_configure_ec`, `function cros_chctl_psy_ext_get_prop`, `function cros_chctl_psy_ext_set_threshold`, `function cros_chctl_psy_ext_set_prop`, `function cros_chctl_psy_prop_is_writeable`, `function cros_chctl_add_battery`, `function cros_chctl_remove_battery`, `function cros_chctl_fwk_charge_control_versions`.
- 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.