drivers/rtc/rtc-cros-ec.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-cros-ec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-cros-ec.c- Extension
.c- Size
- 10700 bytes
- Lines
- 411
- Domain
- Driver Families
- Bucket
- drivers/rtc
- 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/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_device.hlinux/rtc.hlinux/slab.h
Detected Declarations
struct cros_ec_rtcfunction cros_ec_rtc_getfunction cros_ec_rtc_setfunction cros_ec_rtc_read_timefunction cros_ec_rtc_set_timefunction cros_ec_rtc_read_alarmfunction cros_ec_rtc_set_alarmfunction cros_ec_rtc_alarm_irq_enablefunction cros_ec_rtc_eventfunction cros_ec_rtc_suspendfunction cros_ec_rtc_resumefunction cros_ec_rtc_probefunction cros_ec_rtc_remove
Annotated Snippet
struct cros_ec_rtc {
struct cros_ec_device *cros_ec;
struct rtc_device *rtc;
struct notifier_block notifier;
u32 saved_alarm;
};
static int cros_ec_rtc_get(struct cros_ec_device *cros_ec, u32 command,
u32 *response)
{
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
sizeof(struct ec_response_rtc));
int ret;
msg->command = command;
msg->insize = sizeof(struct ec_response_rtc);
ret = cros_ec_cmd_xfer_status(cros_ec, msg);
if (ret < 0)
return ret;
*response = ((struct ec_response_rtc *)msg->data)->time;
return 0;
}
static int cros_ec_rtc_set(struct cros_ec_device *cros_ec, u32 command,
u32 param)
{
DEFINE_RAW_FLEX(struct cros_ec_command, msg, data,
sizeof(struct ec_response_rtc));
int ret;
msg->command = command;
msg->outsize = sizeof(struct ec_response_rtc);
((struct ec_response_rtc *)msg->data)->time = param;
ret = cros_ec_cmd_xfer_status(cros_ec, msg);
if (ret < 0)
return ret;
return 0;
}
/* Read the current time from the EC. */
static int cros_ec_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
int ret;
u32 time;
ret = cros_ec_rtc_get(cros_ec, EC_CMD_RTC_GET_VALUE, &time);
if (ret) {
dev_err(dev, "error getting time: %d\n", ret);
return ret;
}
rtc_time64_to_tm(time, tm);
return 0;
}
/* Set the current EC time. */
static int cros_ec_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
int ret;
time64_t time = rtc_tm_to_time64(tm);
ret = cros_ec_rtc_set(cros_ec, EC_CMD_RTC_SET_VALUE, (u32)time);
if (ret < 0) {
dev_err(dev, "error setting time: %d\n", ret);
return ret;
}
return 0;
}
/* Read alarm time from RTC. */
static int cros_ec_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct cros_ec_rtc *cros_ec_rtc = dev_get_drvdata(dev);
struct cros_ec_device *cros_ec = cros_ec_rtc->cros_ec;
int ret;
u32 current_time, alarm_offset;
/*
* The EC host command for getting the alarm is relative (i.e. 5
* seconds from now) whereas rtc_wkalrm is absolute. Get the current
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/slab.h`.
- Detected declarations: `struct cros_ec_rtc`, `function cros_ec_rtc_get`, `function cros_ec_rtc_set`, `function cros_ec_rtc_read_time`, `function cros_ec_rtc_set_time`, `function cros_ec_rtc_read_alarm`, `function cros_ec_rtc_set_alarm`, `function cros_ec_rtc_alarm_irq_enable`, `function cros_ec_rtc_event`, `function cros_ec_rtc_suspend`.
- Atlas domain: Driver Families / drivers/rtc.
- 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.