drivers/rtc/rtc-rv8803.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-rv8803.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-rv8803.c- Extension
.c- Size
- 18508 bytes
- Lines
- 773
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bitops.hlinux/bitfield.hlinux/log2.hlinux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/module.hlinux/of.hlinux/rtc.hlinux/pm_wakeirq.h
Detected Declarations
struct rv8803_dataenum rv8803_typefunction rv8803_read_regfunction rv8803_read_regsfunction rv8803_write_regfunction rv8803_write_regsfunction rv8803_regs_initfunction rv8803_regs_resetfunction rv8803_handle_irqfunction rv8803_get_timefunction rv8803_set_timefunction rv8803_get_alarmfunction rv8803_set_alarmfunction rv8803_alarm_irq_enablefunction rv8803_ioctlfunction rv8803_nvram_writefunction rv8803_nvram_readfunction rx8900_trickle_charger_initfunction rv8803_regs_configurefunction rv8803_resumefunction rv8803_suspendfunction rv8803_probe
Annotated Snippet
struct rv8803_data {
struct i2c_client *client;
struct rtc_device *rtc;
struct mutex flags_lock;
u8 ctrl;
u8 backup;
u8 alarm_invalid:1;
enum rv8803_type type;
};
static int rv8803_read_reg(const struct i2c_client *client, u8 reg)
{
int try = RV8803_I2C_TRY_COUNT;
s32 ret;
/*
* There is a 61µs window during which the RTC does not acknowledge I2C
* transfers. In that case, ensure that there are multiple attempts.
*/
do
ret = i2c_smbus_read_byte_data(client, reg);
while ((ret == -ENXIO || ret == -EIO) && --try);
if (ret < 0)
dev_err(&client->dev, "Unable to read register 0x%02x\n", reg);
return ret;
}
static int rv8803_read_regs(const struct i2c_client *client,
u8 reg, u8 count, u8 *values)
{
int try = RV8803_I2C_TRY_COUNT;
s32 ret;
do
ret = i2c_smbus_read_i2c_block_data(client, reg, count, values);
while ((ret == -ENXIO || ret == -EIO) && --try);
if (ret != count) {
dev_err(&client->dev,
"Unable to read registers 0x%02x..0x%02x\n",
reg, reg + count - 1);
return ret < 0 ? ret : -EIO;
}
return 0;
}
static int rv8803_write_reg(const struct i2c_client *client, u8 reg, u8 value)
{
int try = RV8803_I2C_TRY_COUNT;
s32 ret;
do
ret = i2c_smbus_write_byte_data(client, reg, value);
while ((ret == -ENXIO || ret == -EIO) && --try);
if (ret)
dev_err(&client->dev, "Unable to write register 0x%02x\n", reg);
return ret;
}
static int rv8803_write_regs(const struct i2c_client *client,
u8 reg, u8 count, const u8 *values)
{
int try = RV8803_I2C_TRY_COUNT;
s32 ret;
do
ret = i2c_smbus_write_i2c_block_data(client, reg, count,
values);
while ((ret == -ENXIO || ret == -EIO) && --try);
if (ret)
dev_err(&client->dev,
"Unable to write registers 0x%02x..0x%02x\n",
reg, reg + count - 1);
return ret;
}
static int rv8803_regs_init(struct rv8803_data *rv8803)
{
int ret;
ret = rv8803_write_reg(rv8803->client, RV8803_OSC_OFFSET, 0x00);
if (ret)
return ret;
ret = rv8803_write_reg(rv8803->client, RV8803_CTRL,
FIELD_PREP(RX8803_CTRL_CSEL, 1)); /* 2s */
if (ret)
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/bitops.h`, `linux/bitfield.h`, `linux/log2.h`, `linux/i2c.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct rv8803_data`, `enum rv8803_type`, `function rv8803_read_reg`, `function rv8803_read_regs`, `function rv8803_write_reg`, `function rv8803_write_regs`, `function rv8803_regs_init`, `function rv8803_regs_reset`, `function rv8803_handle_irq`, `function rv8803_get_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.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- 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.