drivers/rtc/rtc-imx-sc.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-imx-sc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-imx-sc.c- Extension
.c- Size
- 4354 bytes
- Lines
- 185
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
dt-bindings/firmware/imx/rsrc.hlinux/arm-smccc.hlinux/firmware/imx/sci.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/rtc.h
Detected Declarations
struct imx_sc_msg_timer_get_rtc_timestruct imx_sc_msg_timer_rtc_set_alarmfunction imx_sc_rtc_read_timefunction imx_sc_rtc_set_timefunction imx_sc_rtc_alarm_irq_enablefunction imx_sc_rtc_set_alarmfunction imx_sc_rtc_alarm_notifyfunction imx_sc_rtc_probe
Annotated Snippet
struct imx_sc_msg_timer_get_rtc_time {
struct imx_sc_rpc_msg hdr;
u32 time;
} __packed;
struct imx_sc_msg_timer_rtc_set_alarm {
struct imx_sc_rpc_msg hdr;
u16 year;
u8 mon;
u8 day;
u8 hour;
u8 min;
u8 sec;
} __packed __aligned(4);
static int imx_sc_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct imx_sc_msg_timer_get_rtc_time msg;
struct imx_sc_rpc_msg *hdr = &msg.hdr;
int ret;
hdr->ver = IMX_SC_RPC_VERSION;
hdr->svc = IMX_SC_RPC_SVC_TIMER;
hdr->func = IMX_SC_TIMER_FUNC_GET_RTC_SEC1970;
hdr->size = 1;
ret = imx_scu_call_rpc(rtc_ipc_handle, &msg, true);
if (ret) {
dev_err(dev, "read rtc time failed, ret %d\n", ret);
return ret;
}
rtc_time64_to_tm(msg.time, tm);
return 0;
}
static int imx_sc_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct arm_smccc_res res;
/* pack 2 time parameters into 1 register, 16 bits for each */
arm_smccc_smc(IMX_SIP_SRTC, IMX_SIP_SRTC_SET_TIME,
((tm->tm_year + 1900) << 16) | (tm->tm_mon + 1),
(tm->tm_mday << 16) | tm->tm_hour,
(tm->tm_min << 16) | tm->tm_sec,
0, 0, 0, &res);
return res.a0;
}
static int imx_sc_rtc_alarm_irq_enable(struct device *dev, unsigned int enable)
{
return imx_scu_irq_group_enable(SC_IRQ_GROUP_RTC, SC_IRQ_RTC, enable);
}
static int imx_sc_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct imx_sc_msg_timer_rtc_set_alarm msg;
struct imx_sc_rpc_msg *hdr = &msg.hdr;
int ret;
struct rtc_time *alrm_tm = &alrm->time;
hdr->ver = IMX_SC_RPC_VERSION;
hdr->svc = IMX_SC_RPC_SVC_TIMER;
hdr->func = IMX_SC_TIMER_FUNC_SET_RTC_ALARM;
hdr->size = 3;
msg.year = alrm_tm->tm_year + 1900;
msg.mon = alrm_tm->tm_mon + 1;
msg.day = alrm_tm->tm_mday;
msg.hour = alrm_tm->tm_hour;
msg.min = alrm_tm->tm_min;
msg.sec = alrm_tm->tm_sec;
ret = imx_scu_call_rpc(rtc_ipc_handle, &msg, true);
if (ret) {
dev_err(dev, "set rtc alarm failed, ret %d\n", ret);
return ret;
}
ret = imx_sc_rtc_alarm_irq_enable(dev, alrm->enabled);
if (ret) {
dev_err(dev, "enable rtc alarm failed, ret %d\n", ret);
return ret;
}
return 0;
}
Annotation
- Immediate include surface: `dt-bindings/firmware/imx/rsrc.h`, `linux/arm-smccc.h`, `linux/firmware/imx/sci.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/rtc.h`.
- Detected declarations: `struct imx_sc_msg_timer_get_rtc_time`, `struct imx_sc_msg_timer_rtc_set_alarm`, `function imx_sc_rtc_read_time`, `function imx_sc_rtc_set_time`, `function imx_sc_rtc_alarm_irq_enable`, `function imx_sc_rtc_set_alarm`, `function imx_sc_rtc_alarm_notify`, `function imx_sc_rtc_probe`.
- 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.