drivers/pwm/pwm-cros-ec.c
Source file repositories/reference/linux-study-clean/drivers/pwm/pwm-cros-ec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pwm/pwm-cros-ec.c- Extension
.c- Size
- 7182 bytes
- Lines
- 287
- Domain
- Driver Families
- Bucket
- drivers/pwm
- 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/of.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/pwm.hlinux/slab.hdt-bindings/mfd/cros_ec.h
Detected Declarations
struct cros_ec_pwm_devicefunction cros_ec_dt_type_to_pwm_typefunction cros_ec_pwm_set_dutyfunction cros_ec_pwm_get_dutyfunction cros_ec_pwm_applyfunction cros_ec_pwm_get_statefunction cros_ec_num_pwmsfunction cros_ec_pwm_probe
Annotated Snippet
struct cros_ec_pwm_device {
struct cros_ec_device *ec;
bool use_pwm_type;
};
static inline struct cros_ec_pwm_device *pwm_to_cros_ec_pwm(struct pwm_chip *chip)
{
return pwmchip_get_drvdata(chip);
}
static int cros_ec_dt_type_to_pwm_type(u8 dt_index, u8 *pwm_type)
{
switch (dt_index) {
case CROS_EC_PWM_DT_KB_LIGHT:
*pwm_type = EC_PWM_TYPE_KB_LIGHT;
return 0;
case CROS_EC_PWM_DT_DISPLAY_LIGHT:
*pwm_type = EC_PWM_TYPE_DISPLAY_LIGHT;
return 0;
default:
return -EINVAL;
}
}
static int cros_ec_pwm_set_duty(struct cros_ec_pwm_device *ec_pwm, u8 index,
u16 duty)
{
struct cros_ec_device *ec = ec_pwm->ec;
TRAILING_OVERLAP(struct cros_ec_command, msg, data,
struct ec_params_pwm_set_duty params;
) __packed buf;
struct ec_params_pwm_set_duty *params = &buf.params;
struct cros_ec_command *msg = &buf.msg;
int ret;
memset(&buf, 0, sizeof(buf));
msg->version = 0;
msg->command = EC_CMD_PWM_SET_DUTY;
msg->insize = 0;
msg->outsize = sizeof(*params);
params->duty = duty;
if (ec_pwm->use_pwm_type) {
ret = cros_ec_dt_type_to_pwm_type(index, ¶ms->pwm_type);
if (ret) {
dev_err(ec->dev, "Invalid PWM type index: %d\n", index);
return ret;
}
params->index = 0;
} else {
params->pwm_type = EC_PWM_TYPE_GENERIC;
params->index = index;
}
return cros_ec_cmd_xfer_status(ec, msg);
}
static int cros_ec_pwm_get_duty(struct cros_ec_device *ec, bool use_pwm_type, u8 index)
{
TRAILING_OVERLAP(struct cros_ec_command, msg, data,
union {
struct ec_params_pwm_get_duty params;
struct ec_response_pwm_get_duty resp;
};
) __packed buf;
struct ec_params_pwm_get_duty *params = &buf.params;
struct ec_response_pwm_get_duty *resp = &buf.resp;
struct cros_ec_command *msg = &buf.msg;
int ret;
memset(&buf, 0, sizeof(buf));
msg->version = 0;
msg->command = EC_CMD_PWM_GET_DUTY;
msg->insize = sizeof(*resp);
msg->outsize = sizeof(*params);
if (use_pwm_type) {
ret = cros_ec_dt_type_to_pwm_type(index, ¶ms->pwm_type);
if (ret) {
dev_err(ec->dev, "Invalid PWM type index: %d\n", index);
return ret;
}
params->index = 0;
} else {
params->pwm_type = EC_PWM_TYPE_GENERIC;
params->index = index;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/of.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/platform_device.h`, `linux/pwm.h`, `linux/slab.h`, `dt-bindings/mfd/cros_ec.h`.
- Detected declarations: `struct cros_ec_pwm_device`, `function cros_ec_dt_type_to_pwm_type`, `function cros_ec_pwm_set_duty`, `function cros_ec_pwm_get_duty`, `function cros_ec_pwm_apply`, `function cros_ec_pwm_get_state`, `function cros_ec_num_pwms`, `function cros_ec_pwm_probe`.
- Atlas domain: Driver Families / drivers/pwm.
- 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.