drivers/power/supply/wilco-charger.c
Source file repositories/reference/linux-study-clean/drivers/power/supply/wilco-charger.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/power/supply/wilco-charger.c- Extension
.c- Size
- 5376 bytes
- Lines
- 193
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/platform_device.hlinux/platform_data/wilco-ec.hlinux/power_supply.h
Detected Declarations
enum charge_modefunction psp_val_to_charge_modefunction charge_mode_to_psp_valfunction wilco_charge_get_propertyfunction wilco_charge_set_propertyfunction wilco_charge_property_is_writeablefunction wilco_charge_probe
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Charging control driver for the Wilco EC
*
* Copyright 2019 Google LLC
*
* See Documentation/ABI/testing/sysfs-class-power and
* Documentation/ABI/testing/sysfs-class-power-wilco for userspace interface
* and other info.
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/platform_data/wilco-ec.h>
#include <linux/power_supply.h>
#define DRV_NAME "wilco-charger"
/* Property IDs and related EC constants */
#define PID_CHARGE_MODE 0x0710
#define PID_CHARGE_LOWER_LIMIT 0x0711
#define PID_CHARGE_UPPER_LIMIT 0x0712
enum charge_mode {
CHARGE_MODE_STD = 1, /* Used for Standard */
CHARGE_MODE_EXP = 2, /* Express Charge, used for Fast */
CHARGE_MODE_AC = 3, /* Mostly AC use, used for Trickle */
CHARGE_MODE_AUTO = 4, /* Used for Adaptive */
CHARGE_MODE_CUSTOM = 5, /* Used for Custom */
CHARGE_MODE_LONGLIFE = 6, /* Used for Long Life */
};
#define CHARGE_LOWER_LIMIT_MIN 50
#define CHARGE_LOWER_LIMIT_MAX 95
#define CHARGE_UPPER_LIMIT_MIN 55
#define CHARGE_UPPER_LIMIT_MAX 100
/* Convert from POWER_SUPPLY_PROP_CHARGE_TYPE value to the EC's charge mode */
static int psp_val_to_charge_mode(int psp_val)
{
switch (psp_val) {
case POWER_SUPPLY_CHARGE_TYPE_TRICKLE:
return CHARGE_MODE_AC;
case POWER_SUPPLY_CHARGE_TYPE_FAST:
return CHARGE_MODE_EXP;
case POWER_SUPPLY_CHARGE_TYPE_STANDARD:
return CHARGE_MODE_STD;
case POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE:
return CHARGE_MODE_AUTO;
case POWER_SUPPLY_CHARGE_TYPE_CUSTOM:
return CHARGE_MODE_CUSTOM;
case POWER_SUPPLY_CHARGE_TYPE_LONGLIFE:
return CHARGE_MODE_LONGLIFE;
default:
return -EINVAL;
}
}
/* Convert from EC's charge mode to POWER_SUPPLY_PROP_CHARGE_TYPE value */
static int charge_mode_to_psp_val(enum charge_mode mode)
{
switch (mode) {
case CHARGE_MODE_AC:
return POWER_SUPPLY_CHARGE_TYPE_TRICKLE;
case CHARGE_MODE_EXP:
return POWER_SUPPLY_CHARGE_TYPE_FAST;
case CHARGE_MODE_STD:
return POWER_SUPPLY_CHARGE_TYPE_STANDARD;
case CHARGE_MODE_AUTO:
return POWER_SUPPLY_CHARGE_TYPE_ADAPTIVE;
case CHARGE_MODE_CUSTOM:
return POWER_SUPPLY_CHARGE_TYPE_CUSTOM;
case CHARGE_MODE_LONGLIFE:
return POWER_SUPPLY_CHARGE_TYPE_LONGLIFE;
default:
return -EINVAL;
}
}
static enum power_supply_property wilco_charge_props[] = {
POWER_SUPPLY_PROP_CHARGE_TYPE,
POWER_SUPPLY_PROP_CHARGE_CONTROL_START_THRESHOLD,
POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD,
};
static int wilco_charge_get_property(struct power_supply *psy,
enum power_supply_property psp,
union power_supply_propval *val)
{
struct wilco_ec_device *ec = power_supply_get_drvdata(psy);
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/platform_data/wilco-ec.h`, `linux/power_supply.h`.
- Detected declarations: `enum charge_mode`, `function psp_val_to_charge_mode`, `function charge_mode_to_psp_val`, `function wilco_charge_get_property`, `function wilco_charge_set_property`, `function wilco_charge_property_is_writeable`, `function wilco_charge_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.