drivers/rtc/rtc-nct3018y.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-nct3018y.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-nct3018y.c- Extension
.c- Size
- 15795 bytes
- Lines
- 601
- 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 user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/clk-provider.hlinux/err.hlinux/i2c.hlinux/module.hlinux/of.hlinux/rtc.hlinux/slab.h
Detected Declarations
struct nct3018yfunction nct3018y_set_alarm_modefunction nct3018y_get_alarm_modefunction nct3018y_irqfunction nct3018y_rtc_read_timefunction nct3018y_rtc_set_timefunction nct3018y_rtc_read_alarmfunction nct3018y_rtc_set_alarmfunction nct3018y_irq_enablefunction nct3018y_ioctlfunction nct3018y_clkout_recalc_ratefunction nct3018y_clkout_determine_ratefunction nct3018y_clkout_set_ratefunction nct3018y_clkout_controlfunction nct3018y_clkout_preparefunction nct3018y_clkout_unpreparefunction nct3018y_clkout_is_preparedfunction nct3018y_probe
Annotated Snippet
struct nct3018y {
struct rtc_device *rtc;
struct i2c_client *client;
int part_num;
#ifdef CONFIG_COMMON_CLK
struct clk_hw clkout_hw;
#endif
};
static int nct3018y_set_alarm_mode(struct i2c_client *client, bool on)
{
int err, flags;
dev_dbg(&client->dev, "%s:on:%d\n", __func__, on);
flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
if (flags < 0) {
dev_dbg(&client->dev,
"Failed to read NCT3018Y_REG_CTRL\n");
return flags;
}
if (on)
flags |= NCT3018Y_BIT_AIE;
else
flags &= ~NCT3018Y_BIT_AIE;
flags |= NCT3018Y_BIT_CIE;
err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_CTRL, flags);
if (err < 0) {
dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_CTRL\n");
return err;
}
flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST);
if (flags < 0) {
dev_dbg(&client->dev,
"Failed to read NCT3018Y_REG_ST\n");
return flags;
}
flags &= ~(NCT3018Y_BIT_AF);
err = i2c_smbus_write_byte_data(client, NCT3018Y_REG_ST, flags);
if (err < 0) {
dev_dbg(&client->dev, "Unable to write NCT3018Y_REG_ST\n");
return err;
}
return 0;
}
static int nct3018y_get_alarm_mode(struct i2c_client *client, unsigned char *alarm_enable,
unsigned char *alarm_flag)
{
int flags;
if (alarm_enable) {
dev_dbg(&client->dev, "%s:NCT3018Y_REG_CTRL\n", __func__);
flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_CTRL);
if (flags < 0)
return flags;
*alarm_enable = flags & NCT3018Y_BIT_AIE;
dev_dbg(&client->dev, "%s:alarm_enable:%x\n", __func__, *alarm_enable);
}
if (alarm_flag) {
dev_dbg(&client->dev, "%s:NCT3018Y_REG_ST\n", __func__);
flags = i2c_smbus_read_byte_data(client, NCT3018Y_REG_ST);
if (flags < 0)
return flags;
*alarm_flag = flags & NCT3018Y_BIT_AF;
dev_dbg(&client->dev, "%s:alarm_flag:%x\n", __func__, *alarm_flag);
}
return 0;
}
static irqreturn_t nct3018y_irq(int irq, void *dev_id)
{
struct nct3018y *nct3018y = i2c_get_clientdata(dev_id);
struct i2c_client *client = nct3018y->client;
int err;
unsigned char alarm_flag;
unsigned char alarm_enable;
dev_dbg(&client->dev, "%s:irq:%d\n", __func__, irq);
err = nct3018y_get_alarm_mode(nct3018y->client, &alarm_enable, &alarm_flag);
if (err)
return IRQ_NONE;
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/clk-provider.h`, `linux/err.h`, `linux/i2c.h`, `linux/module.h`, `linux/of.h`, `linux/rtc.h`, `linux/slab.h`.
- Detected declarations: `struct nct3018y`, `function nct3018y_set_alarm_mode`, `function nct3018y_get_alarm_mode`, `function nct3018y_irq`, `function nct3018y_rtc_read_time`, `function nct3018y_rtc_set_time`, `function nct3018y_rtc_read_alarm`, `function nct3018y_rtc_set_alarm`, `function nct3018y_irq_enable`, `function nct3018y_ioctl`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.