drivers/rtc/rtc-sd2405al.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-sd2405al.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-sd2405al.c- Extension
.c- Size
- 5922 bytes
- Lines
- 230
- 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/bcd.hlinux/i2c.hlinux/regmap.hlinux/rtc.h
Detected Declarations
struct sd2405alfunction sd2405al_enable_reg_writefunction sd2405al_disable_reg_writefunction sd2405al_read_timefunction sd2405al_set_timefunction sd2405al_probe
Annotated Snippet
struct sd2405al {
struct device *dev;
struct regmap *regmap;
};
static int sd2405al_enable_reg_write(struct sd2405al *sd2405al)
{
int ret;
/* order of writes is important */
ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR2,
SD2405AL_BIT_WRTC1, SD2405AL_BIT_WRTC1);
if (ret < 0)
return ret;
ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR1,
SD2405AL_BIT_WRTC2 | SD2405AL_BIT_WRTC3,
SD2405AL_BIT_WRTC2 | SD2405AL_BIT_WRTC3);
if (ret < 0)
return ret;
return 0;
}
static int sd2405al_disable_reg_write(struct sd2405al *sd2405al)
{
int ret;
/* order of writes is important */
ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR1,
SD2405AL_BIT_WRTC2 | SD2405AL_BIT_WRTC3, 0x00);
if (ret < 0)
return ret;
ret = regmap_update_bits(sd2405al->regmap, SD2405AL_REG_CTR2,
SD2405AL_BIT_WRTC1, 0x00);
if (ret < 0)
return ret;
return 0;
}
static int sd2405al_read_time(struct device *dev, struct rtc_time *time)
{
u8 data[SD2405AL_NUM_T_REGS] = { 0 };
struct sd2405al *sd2405al = dev_get_drvdata(dev);
int ret;
ret = regmap_bulk_read(sd2405al->regmap, SD2405AL_REG_T_SEC, data,
SD2405AL_NUM_T_REGS);
if (ret < 0)
return ret;
time->tm_sec = bcd2bin(data[SD2405AL_REG_T_SEC] & 0x7F);
time->tm_min = bcd2bin(data[SD2405AL_REG_T_MIN] & 0x7F);
if (data[SD2405AL_REG_T_HOUR] & SD2405AL_BIT_24H)
time->tm_hour = bcd2bin(data[SD2405AL_REG_T_HOUR] & 0x3F);
else
if (data[SD2405AL_REG_T_HOUR] & SD2405AL_BIT_12H_PM)
time->tm_hour = bcd2bin(data[SD2405AL_REG_T_HOUR]
& 0x1F) + 12;
else /* 12 hour mode, AM */
time->tm_hour = bcd2bin(data[SD2405AL_REG_T_HOUR]
& 0x1F);
time->tm_wday = bcd2bin(data[SD2405AL_REG_T_WEEK] & 0x07);
time->tm_mday = bcd2bin(data[SD2405AL_REG_T_DAY] & 0x3F);
time->tm_mon = bcd2bin(data[SD2405AL_REG_T_MON] & 0x1F) - 1;
time->tm_year = bcd2bin(data[SD2405AL_REG_T_YEAR]) + 100;
dev_dbg(sd2405al->dev, "read time: %ptR (%d)\n", time, time->tm_wday);
return 0;
}
static int sd2405al_set_time(struct device *dev, struct rtc_time *time)
{
u8 data[SD2405AL_NUM_T_REGS];
struct sd2405al *sd2405al = dev_get_drvdata(dev);
int ret;
data[SD2405AL_REG_T_SEC] = bin2bcd(time->tm_sec);
data[SD2405AL_REG_T_MIN] = bin2bcd(time->tm_min);
data[SD2405AL_REG_T_HOUR] = bin2bcd(time->tm_hour) | SD2405AL_BIT_24H;
data[SD2405AL_REG_T_DAY] = bin2bcd(time->tm_mday);
data[SD2405AL_REG_T_WEEK] = bin2bcd(time->tm_wday);
data[SD2405AL_REG_T_MON] = bin2bcd(time->tm_mon) + 1;
data[SD2405AL_REG_T_YEAR] = bin2bcd(time->tm_year - 100);
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/i2c.h`, `linux/regmap.h`, `linux/rtc.h`.
- Detected declarations: `struct sd2405al`, `function sd2405al_enable_reg_write`, `function sd2405al_disable_reg_write`, `function sd2405al_read_time`, `function sd2405al_set_time`, `function sd2405al_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.