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.

Dependency Surface

Detected Declarations

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

Implementation Notes