drivers/platform/chrome/cros_ec_lightbar.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_lightbar.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_lightbar.c- Extension
.c- Size
- 16574 bytes
- Lines
- 707
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/ctype.hlinux/delay.hlinux/device.hlinux/fs.hlinux/kobject.hlinux/kstrtox.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/sched.hlinux/types.hlinux/uaccess.hlinux/slab.h
Detected Declarations
function interval_msec_showfunction interval_msec_storefunction lb_throttlefunction get_lightbar_versionfunction version_showfunction num_segments_showfunction brightness_storefunction whitespacefunction sequence_showfunction lb_send_empty_cmdfunction lb_manual_suspend_ctrlfunction sequence_storefunction program_storefunction userspace_control_showfunction userspace_control_storefunction cros_ec_lightbar_probefunction cros_ec_lightbar_removefunction cros_ec_lightbar_resumefunction cros_ec_lightbar_suspend
Annotated Snippet
if (schedule_timeout(delay) > 0) {
/* interrupted - just abort */
ret = -EINTR;
goto out;
}
now = jiffies;
}
last_access = now;
out:
mutex_unlock(&lb_mutex);
return ret;
}
static struct cros_ec_command *alloc_lightbar_cmd_msg(struct cros_ec_dev *ec)
{
int len = max(ec->ec_dev->max_response, ec->ec_dev->max_request);
struct cros_ec_command *msg;
msg = kmalloc(sizeof(*msg) + len, GFP_KERNEL);
if (!msg)
return NULL;
msg->version = 0;
msg->command = EC_CMD_LIGHTBAR_CMD + ec->cmd_offset;
/*
* Default sizes for regular commands.
* Can be set smaller to optimize transfer,
* larger when sending large light sequences.
*/
msg->outsize = sizeof(struct ec_params_lightbar);
msg->insize = sizeof(struct ec_response_lightbar);
return msg;
}
static int get_lightbar_version(struct cros_ec_dev *ec,
uint32_t *ver_ptr, uint32_t *flg_ptr)
{
struct ec_params_lightbar *param;
struct ec_response_lightbar *resp;
struct cros_ec_command *msg;
int ret;
msg = alloc_lightbar_cmd_msg(ec);
if (!msg)
return 0;
param = (struct ec_params_lightbar *)msg->data;
param->cmd = LIGHTBAR_CMD_VERSION;
msg->outsize = sizeof(param->cmd);
msg->insize = sizeof(resp->version);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0 && ret != -EINVAL) {
ret = 0;
goto exit;
}
switch (msg->result) {
case EC_RES_INVALID_PARAM:
/* Pixel had no version command. */
if (ver_ptr)
*ver_ptr = 0;
if (flg_ptr)
*flg_ptr = 0;
ret = 1;
goto exit;
case EC_RES_SUCCESS:
resp = (struct ec_response_lightbar *)msg->data;
/* Future devices w/lightbars should implement this command */
if (ver_ptr)
*ver_ptr = resp->version.num;
if (flg_ptr)
*flg_ptr = resp->version.flags;
ret = 1;
goto exit;
}
/* Anything else (ie, EC_RES_INVALID_COMMAND) - no lightbar */
ret = 0;
exit:
kfree(msg);
return ret;
}
static ssize_t version_show(struct device *dev,
struct device_attribute *attr, char *buf)
Annotation
- Immediate include surface: `linux/ctype.h`, `linux/delay.h`, `linux/device.h`, `linux/fs.h`, `linux/kobject.h`, `linux/kstrtox.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `function interval_msec_show`, `function interval_msec_store`, `function lb_throttle`, `function get_lightbar_version`, `function version_show`, `function num_segments_show`, `function brightness_store`, `function whitespace`, `function sequence_show`, `function lb_send_empty_cmd`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.