drivers/rtc/rtc-nct6694.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-nct6694.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-nct6694.c- Extension
.c- Size
- 7807 bytes
- Lines
- 298
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bcd.hlinux/irqdomain.hlinux/kernel.hlinux/mfd/nct6694.hlinux/module.hlinux/platform_device.hlinux/rtc.hlinux/slab.h
Detected Declarations
struct nct6694_rtc_datafunction nct6694_rtc_read_timefunction nct6694_rtc_set_timefunction nct6694_rtc_read_alarmfunction nct6694_rtc_set_alarmfunction nct6694_rtc_alarm_irq_enablefunction nct6694_irqfunction nct6694_irq_dispose_mappingfunction nct6694_rtc_probe
Annotated Snippet
struct nct6694_rtc_data {
struct nct6694 *nct6694;
struct rtc_device *rtc;
union nct6694_rtc_msg *msg;
int irq;
};
static int nct6694_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct nct6694_rtc_data *data = dev_get_drvdata(dev);
struct nct6694_rtc_time *time = &data->msg->time;
static const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_RTC_MOD,
.cmd = NCT6694_RTC_TIME,
.sel = NCT6694_RTC_TIME_SEL,
.len = cpu_to_le16(sizeof(*time))
};
int ret;
ret = nct6694_read_msg(data->nct6694, &cmd_hd, time);
if (ret)
return ret;
tm->tm_sec = bcd2bin(time->sec); /* tm_sec expect 0 ~ 59 */
tm->tm_min = bcd2bin(time->min); /* tm_min expect 0 ~ 59 */
tm->tm_hour = bcd2bin(time->hour); /* tm_hour expect 0 ~ 23 */
tm->tm_wday = bcd2bin(time->week) - 1; /* tm_wday expect 0 ~ 6 */
tm->tm_mday = bcd2bin(time->day); /* tm_mday expect 1 ~ 31 */
tm->tm_mon = bcd2bin(time->month) - 1; /* tm_month expect 0 ~ 11 */
tm->tm_year = bcd2bin(time->year) + 100; /* tm_year expect since 1900 */
return ret;
}
static int nct6694_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct nct6694_rtc_data *data = dev_get_drvdata(dev);
struct nct6694_rtc_time *time = &data->msg->time;
static const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_RTC_MOD,
.cmd = NCT6694_RTC_TIME,
.sel = NCT6694_RTC_TIME_SEL,
.len = cpu_to_le16(sizeof(*time))
};
time->sec = bin2bcd(tm->tm_sec);
time->min = bin2bcd(tm->tm_min);
time->hour = bin2bcd(tm->tm_hour);
time->week = bin2bcd(tm->tm_wday + 1);
time->day = bin2bcd(tm->tm_mday);
time->month = bin2bcd(tm->tm_mon + 1);
time->year = bin2bcd(tm->tm_year - 100);
return nct6694_write_msg(data->nct6694, &cmd_hd, time);
}
static int nct6694_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct nct6694_rtc_data *data = dev_get_drvdata(dev);
struct nct6694_rtc_alarm *alarm = &data->msg->alarm;
static const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_RTC_MOD,
.cmd = NCT6694_RTC_ALARM,
.sel = NCT6694_RTC_ALARM_SEL,
.len = cpu_to_le16(sizeof(*alarm))
};
int ret;
ret = nct6694_read_msg(data->nct6694, &cmd_hd, alarm);
if (ret)
return ret;
alrm->time.tm_sec = bcd2bin(alarm->sec);
alrm->time.tm_min = bcd2bin(alarm->min);
alrm->time.tm_hour = bcd2bin(alarm->hour);
alrm->enabled = alarm->alarm_en;
alrm->pending = alarm->alarm_pend;
return ret;
}
static int nct6694_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{
struct nct6694_rtc_data *data = dev_get_drvdata(dev);
struct nct6694_rtc_alarm *alarm = &data->msg->alarm;
static const struct nct6694_cmd_header cmd_hd = {
.mod = NCT6694_RTC_MOD,
.cmd = NCT6694_RTC_ALARM,
.sel = NCT6694_RTC_ALARM_SEL,
.len = cpu_to_le16(sizeof(*alarm))
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/irqdomain.h`, `linux/kernel.h`, `linux/mfd/nct6694.h`, `linux/module.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/slab.h`.
- Detected declarations: `struct nct6694_rtc_data`, `function nct6694_rtc_read_time`, `function nct6694_rtc_set_time`, `function nct6694_rtc_read_alarm`, `function nct6694_rtc_set_alarm`, `function nct6694_rtc_alarm_irq_enable`, `function nct6694_irq`, `function nct6694_irq_dispose_mapping`, `function nct6694_rtc_probe`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.