drivers/rtc/rtc-s35390a.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-s35390a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-s35390a.c- Extension
.c- Size
- 13705 bytes
- Lines
- 542
- 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/module.hlinux/rtc.hlinux/i2c.hlinux/bitrev.hlinux/bcd.hlinux/slab.hlinux/delay.h
Detected Declarations
struct s35390afunction s35390a_set_regfunction s35390a_get_regfunction s35390a_initfunction s35390a_read_statusfunction s35390a_disable_test_modefunction s35390a_hr2regfunction s35390a_reg2hrfunction s35390a_rtc_set_timefunction s35390a_rtc_read_timefunction s35390a_rtc_set_alarmfunction s35390a_rtc_read_alarmfunction s35390a_rtc_ioctlfunction s35390a_nvmem_readfunction s35390a_nvmem_writefunction s35390a_probe
Annotated Snippet
struct s35390a {
struct i2c_client *client[8];
int twentyfourhour;
};
static int s35390a_set_reg(struct s35390a *s35390a, int reg, u8 *buf, int len)
{
struct i2c_client *client = s35390a->client[reg];
struct i2c_msg msg[] = {
{
.addr = client->addr,
.len = len,
.buf = buf
},
};
if ((i2c_transfer(client->adapter, msg, 1)) != 1)
return -EIO;
return 0;
}
static int s35390a_get_reg(struct s35390a *s35390a, int reg, u8 *buf, int len)
{
struct i2c_client *client = s35390a->client[reg];
struct i2c_msg msg[] = {
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = len,
.buf = buf
},
};
if ((i2c_transfer(client->adapter, msg, 1)) != 1)
return -EIO;
return 0;
}
static int s35390a_init(struct s35390a *s35390a)
{
u8 buf;
int ret;
unsigned initcount = 0;
/*
* At least one of POC and BLD are set, so reinitialise chip. Keeping
* this information in the hardware to know later that the time isn't
* valid is unfortunately not possible because POC and BLD are cleared
* on read. So the reset is best done now.
*
* The 24H bit is kept over reset, so set it already here.
*/
initialize:
buf = S35390A_FLAG_RESET | S35390A_FLAG_24H;
ret = s35390a_set_reg(s35390a, S35390A_CMD_STATUS1, &buf, 1);
if (ret < 0)
return ret;
ret = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, &buf, 1);
if (ret < 0)
return ret;
if (buf & (S35390A_FLAG_POC | S35390A_FLAG_BLD)) {
/* Try up to five times to reset the chip */
if (initcount < 5) {
++initcount;
goto initialize;
} else
return -EIO;
}
return 1;
}
/*
* Returns <0 on error, 0 if rtc is setup fine and 1 if the chip was reset.
* To keep the information if an irq is pending, pass the value read from
* STATUS1 to the caller.
*/
static int s35390a_read_status(struct s35390a *s35390a, char *status1)
{
int ret;
ret = s35390a_get_reg(s35390a, S35390A_CMD_STATUS1, status1, 1);
if (ret < 0)
return ret;
Annotation
- Immediate include surface: `linux/module.h`, `linux/rtc.h`, `linux/i2c.h`, `linux/bitrev.h`, `linux/bcd.h`, `linux/slab.h`, `linux/delay.h`.
- Detected declarations: `struct s35390a`, `function s35390a_set_reg`, `function s35390a_get_reg`, `function s35390a_init`, `function s35390a_read_status`, `function s35390a_disable_test_mode`, `function s35390a_hr2reg`, `function s35390a_reg2hr`, `function s35390a_rtc_set_time`, `function s35390a_rtc_read_time`.
- 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.