drivers/rtc/rtc-ntxec.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-ntxec.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-ntxec.c- Extension
.c- Size
- 4001 bytes
- Lines
- 146
- 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/mfd/ntxec.hlinux/module.hlinux/platform_device.hlinux/regmap.hlinux/rtc.hlinux/types.h
Detected Declarations
struct ntxec_rtcfunction ntxec_read_timefunction ntxec_set_timefunction ntxec_rtc_probe
Annotated Snippet
struct ntxec_rtc {
struct device *dev;
struct ntxec *ec;
};
#define NTXEC_REG_WRITE_YEAR 0x10
#define NTXEC_REG_WRITE_MONTH 0x11
#define NTXEC_REG_WRITE_DAY 0x12
#define NTXEC_REG_WRITE_HOUR 0x13
#define NTXEC_REG_WRITE_MINUTE 0x14
#define NTXEC_REG_WRITE_SECOND 0x15
#define NTXEC_REG_READ_YEAR_MONTH 0x20
#define NTXEC_REG_READ_MDAY_HOUR 0x21
#define NTXEC_REG_READ_MINUTE_SECOND 0x23
static int ntxec_read_time(struct device *dev, struct rtc_time *tm)
{
struct ntxec_rtc *rtc = dev_get_drvdata(dev);
unsigned int value;
int res;
retry:
res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_MINUTE_SECOND, &value);
if (res < 0)
return res;
tm->tm_min = value >> 8;
tm->tm_sec = value & 0xff;
res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_MDAY_HOUR, &value);
if (res < 0)
return res;
tm->tm_mday = value >> 8;
tm->tm_hour = value & 0xff;
res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_YEAR_MONTH, &value);
if (res < 0)
return res;
tm->tm_year = (value >> 8) + 100;
tm->tm_mon = (value & 0xff) - 1;
/*
* Read the minutes/seconds field again. If it changed since the first
* read, we can't assume that the values read so far are consistent,
* and should start from the beginning.
*/
res = regmap_read(rtc->ec->regmap, NTXEC_REG_READ_MINUTE_SECOND, &value);
if (res < 0)
return res;
if (tm->tm_min != value >> 8 || tm->tm_sec != (value & 0xff))
goto retry;
return 0;
}
static int ntxec_set_time(struct device *dev, struct rtc_time *tm)
{
struct ntxec_rtc *rtc = dev_get_drvdata(dev);
/*
* To avoid time overflows while we're writing the full date/time,
* set the seconds field to zero before doing anything else. For the
* next 59 seconds (plus however long it takes until the RTC's next
* update of the second field), the seconds field will not overflow
* into the other fields.
*/
struct reg_sequence regs[] = {
{ NTXEC_REG_WRITE_SECOND, ntxec_reg8(0) },
{ NTXEC_REG_WRITE_YEAR, ntxec_reg8(tm->tm_year - 100) },
{ NTXEC_REG_WRITE_MONTH, ntxec_reg8(tm->tm_mon + 1) },
{ NTXEC_REG_WRITE_DAY, ntxec_reg8(tm->tm_mday) },
{ NTXEC_REG_WRITE_HOUR, ntxec_reg8(tm->tm_hour) },
{ NTXEC_REG_WRITE_MINUTE, ntxec_reg8(tm->tm_min) },
{ NTXEC_REG_WRITE_SECOND, ntxec_reg8(tm->tm_sec) },
};
return regmap_multi_reg_write(rtc->ec->regmap, regs, ARRAY_SIZE(regs));
}
static const struct rtc_class_ops ntxec_rtc_ops = {
.read_time = ntxec_read_time,
.set_time = ntxec_set_time,
};
static int ntxec_rtc_probe(struct platform_device *pdev)
{
Annotation
- Immediate include surface: `linux/mfd/ntxec.h`, `linux/module.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/rtc.h`, `linux/types.h`.
- Detected declarations: `struct ntxec_rtc`, `function ntxec_read_time`, `function ntxec_set_time`, `function ntxec_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.