drivers/rtc/rtc-pcf8583.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-pcf8583.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-pcf8583.c- Extension
.c- Size
- 6566 bytes
- Lines
- 318
- 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/module.hlinux/i2c.hlinux/slab.hlinux/rtc.hlinux/init.hlinux/err.hlinux/errno.hlinux/bcd.h
Detected Declarations
struct rtc_memstruct pcf8583function pcf8583_get_datetimefunction pcf8583_set_datetimefunction pcf8583_get_ctrlfunction pcf8583_set_ctrlfunction pcf8583_read_memfunction pcf8583_write_memfunction pcf8583_rtc_read_timefunction pcf8583_rtc_set_timefunction pcf8583_probe
Annotated Snippet
struct rtc_mem {
unsigned int loc;
unsigned int nr;
unsigned char *data;
};
struct pcf8583 {
struct rtc_device *rtc;
unsigned char ctrl;
};
#define CTRL_STOP 0x80
#define CTRL_HOLD 0x40
#define CTRL_32KHZ 0x00
#define CTRL_MASK 0x08
#define CTRL_ALARMEN 0x04
#define CTRL_ALARM 0x02
#define CTRL_TIMER 0x01
static struct i2c_driver pcf8583_driver;
#define get_ctrl(x) ((struct pcf8583 *)i2c_get_clientdata(x))->ctrl
#define set_ctrl(x, v) get_ctrl(x) = v
#define CMOS_YEAR (64 + 128)
#define CMOS_CHECKSUM (63)
static int pcf8583_get_datetime(struct i2c_client *client, struct rtc_time *dt)
{
unsigned char buf[8], addr[1] = { 1 };
struct i2c_msg msgs[2] = {
{
.addr = client->addr,
.flags = 0,
.len = 1,
.buf = addr,
}, {
.addr = client->addr,
.flags = I2C_M_RD,
.len = 6,
.buf = buf,
}
};
int ret;
memset(buf, 0, sizeof(buf));
ret = i2c_transfer(client->adapter, msgs, 2);
if (ret == 2) {
dt->tm_year = buf[4] >> 6;
dt->tm_wday = buf[5] >> 5;
buf[4] &= 0x3f;
buf[5] &= 0x1f;
dt->tm_sec = bcd2bin(buf[1]);
dt->tm_min = bcd2bin(buf[2]);
dt->tm_hour = bcd2bin(buf[3]);
dt->tm_mday = bcd2bin(buf[4]);
dt->tm_mon = bcd2bin(buf[5]) - 1;
}
return ret == 2 ? 0 : -EIO;
}
static int pcf8583_set_datetime(struct i2c_client *client, struct rtc_time *dt, int datetoo)
{
unsigned char buf[8];
int ret, len = 6;
buf[0] = 0;
buf[1] = get_ctrl(client) | 0x80;
buf[2] = 0;
buf[3] = bin2bcd(dt->tm_sec);
buf[4] = bin2bcd(dt->tm_min);
buf[5] = bin2bcd(dt->tm_hour);
if (datetoo) {
len = 8;
buf[6] = bin2bcd(dt->tm_mday) | (dt->tm_year << 6);
buf[7] = bin2bcd(dt->tm_mon + 1) | (dt->tm_wday << 5);
}
ret = i2c_master_send(client, (char *)buf, len);
if (ret != len)
return -EIO;
buf[1] = get_ctrl(client);
ret = i2c_master_send(client, (char *)buf, 2);
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/slab.h`, `linux/rtc.h`, `linux/init.h`, `linux/err.h`, `linux/errno.h`, `linux/bcd.h`.
- Detected declarations: `struct rtc_mem`, `struct pcf8583`, `function pcf8583_get_datetime`, `function pcf8583_set_datetime`, `function pcf8583_get_ctrl`, `function pcf8583_set_ctrl`, `function pcf8583_read_mem`, `function pcf8583_write_mem`, `function pcf8583_rtc_read_time`, `function pcf8583_rtc_set_time`.
- 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.