drivers/rtc/rtc-rs5c372.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-rs5c372.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-rs5c372.c- Extension
.c- Size
- 23027 bytes
- Lines
- 931
- 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.
- 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/i2c.hlinux/rtc.hlinux/bcd.hlinux/slab.hlinux/module.hlinux/of.h
Detected Declarations
struct rs5c372enum rtc_typefunction rs5c_get_regsfunction rs5c_reg2hrfunction rs5c_hr2regfunction rs5c372_rtc_read_timefunction rs5c372_rtc_set_timefunction rs5c372_get_trimfunction rs5c_rtc_alarm_irq_enablefunction rs5c_read_alarmfunction rs5c_set_alarmfunction rs5c372_rtc_procfunction rs5c372_ioctlfunction rs5c372_read_offsetfunction rs5c372_set_offsetfunction rs5c372_sysfs_show_trimfunction rs5c372_sysfs_show_oscfunction rs5c_sysfs_registerfunction rs5c_sysfs_unregisterfunction rs5c_sysfs_registerfunction rs5c_sysfs_unregisterfunction rs5c_oscillator_setupfunction rs5c372_probefunction rs5c372_remove
Annotated Snippet
struct rs5c372 {
struct i2c_client *client;
struct rtc_device *rtc;
enum rtc_type type;
unsigned time24:1;
unsigned has_irq:1;
unsigned smbus:1;
char buf[17];
char *regs;
};
static int rs5c_get_regs(struct rs5c372 *rs5c)
{
struct i2c_client *client = rs5c->client;
struct i2c_msg msgs[] = {
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = sizeof(rs5c->buf),
.buf = rs5c->buf
},
};
/* This implements the third reading method from the datasheet, using
* an internal address that's reset after each transaction (by STOP)
* to 0x0f ... so we read extra registers, and skip the first one.
*
* The first method doesn't work with the iop3xx adapter driver, on at
* least 80219 chips; this works around that bug.
*
* The third method on the other hand doesn't work for the SMBus-only
* configurations, so we use the first method there, stripping off
* the extra register in the process.
*/
if (rs5c->smbus) {
int addr = RS5C_ADDR(RS5C372_REG_SECS);
int size = sizeof(rs5c->buf) - 1;
if (i2c_smbus_read_i2c_block_data(client, addr, size,
rs5c->buf + 1) != size) {
dev_warn(&client->dev, "can't read registers\n");
return -EIO;
}
} else {
if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
dev_warn(&client->dev, "can't read registers\n");
return -EIO;
}
}
dev_dbg(&client->dev,
"%3ph (%02x) %3ph (%02x), %3ph, %3ph; %02x %02x\n",
rs5c->regs + 0, rs5c->regs[3],
rs5c->regs + 4, rs5c->regs[7],
rs5c->regs + 8, rs5c->regs + 11,
rs5c->regs[14], rs5c->regs[15]);
return 0;
}
static unsigned rs5c_reg2hr(struct rs5c372 *rs5c, unsigned reg)
{
unsigned hour;
if (rs5c->time24)
return bcd2bin(reg & 0x3f);
hour = bcd2bin(reg & 0x1f);
if (hour == 12)
hour = 0;
if (reg & 0x20)
hour += 12;
return hour;
}
static unsigned rs5c_hr2reg(struct rs5c372 *rs5c, unsigned hour)
{
if (rs5c->time24)
return bin2bcd(hour);
if (hour > 12)
return 0x20 | bin2bcd(hour - 12);
if (hour == 12)
return 0x20 | bin2bcd(12);
if (hour == 0)
return bin2bcd(12);
return bin2bcd(hour);
}
static int rs5c372_rtc_read_time(struct device *dev, struct rtc_time *tm)
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/rtc.h`, `linux/bcd.h`, `linux/slab.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct rs5c372`, `enum rtc_type`, `function rs5c_get_regs`, `function rs5c_reg2hr`, `function rs5c_hr2reg`, `function rs5c372_rtc_read_time`, `function rs5c372_rtc_set_time`, `function rs5c372_get_trim`, `function rs5c_rtc_alarm_irq_enable`, `function rs5c_read_alarm`.
- 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.
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.