drivers/regulator/cros-ec-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/cros-ec-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/cros-ec-regulator.c- Extension
.c- Size
- 6044 bytes
- Lines
- 229
- Domain
- Driver Families
- Bucket
- drivers/regulator
- 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/of.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/regulator/driver.hlinux/regulator/machine.hlinux/regulator/of_regulator.hlinux/slab.h
Detected Declarations
struct cros_ec_regulator_datafunction cros_ec_regulator_enablefunction cros_ec_regulator_disablefunction cros_ec_regulator_is_enabledfunction cros_ec_regulator_list_voltagefunction cros_ec_regulator_get_voltagefunction cros_ec_regulator_set_voltagefunction cros_ec_regulator_init_infofunction cros_ec_regulator_probe
Annotated Snippet
struct cros_ec_regulator_data {
struct regulator_desc desc;
struct regulator_dev *dev;
struct cros_ec_device *ec_dev;
u32 index;
u16 *voltages_mV;
u16 num_voltages;
};
static int cros_ec_regulator_enable(struct regulator_dev *dev)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
struct ec_params_regulator_enable cmd = {
.index = data->index,
.enable = 1,
};
return cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_ENABLE, &cmd,
sizeof(cmd), NULL, 0);
}
static int cros_ec_regulator_disable(struct regulator_dev *dev)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
struct ec_params_regulator_enable cmd = {
.index = data->index,
.enable = 0,
};
return cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_ENABLE, &cmd,
sizeof(cmd), NULL, 0);
}
static int cros_ec_regulator_is_enabled(struct regulator_dev *dev)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
struct ec_params_regulator_is_enabled cmd = {
.index = data->index,
};
struct ec_response_regulator_is_enabled resp;
int ret;
ret = cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_IS_ENABLED, &cmd,
sizeof(cmd), &resp, sizeof(resp));
if (ret < 0)
return ret;
return resp.enabled;
}
static int cros_ec_regulator_list_voltage(struct regulator_dev *dev,
unsigned int selector)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
if (selector >= data->num_voltages)
return -EINVAL;
return data->voltages_mV[selector] * 1000;
}
static int cros_ec_regulator_get_voltage(struct regulator_dev *dev)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
struct ec_params_regulator_get_voltage cmd = {
.index = data->index,
};
struct ec_response_regulator_get_voltage resp;
int ret;
ret = cros_ec_cmd(data->ec_dev, 0, EC_CMD_REGULATOR_GET_VOLTAGE, &cmd,
sizeof(cmd), &resp, sizeof(resp));
if (ret < 0)
return ret;
return resp.voltage_mv * 1000;
}
static int cros_ec_regulator_set_voltage(struct regulator_dev *dev, int min_uV,
int max_uV, unsigned int *selector)
{
struct cros_ec_regulator_data *data = rdev_get_drvdata(dev);
int min_mV = DIV_ROUND_UP(min_uV, 1000);
int max_mV = max_uV / 1000;
struct ec_params_regulator_set_voltage cmd = {
.index = data->index,
.min_mv = min_mV,
.max_mv = max_mV,
};
Annotation
- Immediate include surface: `linux/module.h`, `linux/of.h`, `linux/platform_data/cros_ec_proto.h`, `linux/platform_device.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`, `linux/regulator/of_regulator.h`, `linux/slab.h`.
- Detected declarations: `struct cros_ec_regulator_data`, `function cros_ec_regulator_enable`, `function cros_ec_regulator_disable`, `function cros_ec_regulator_is_enabled`, `function cros_ec_regulator_list_voltage`, `function cros_ec_regulator_get_voltage`, `function cros_ec_regulator_set_voltage`, `function cros_ec_regulator_init_info`, `function cros_ec_regulator_probe`.
- Atlas domain: Driver Families / drivers/regulator.
- 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.