drivers/rtc/rtc-rv3032.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-rv3032.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-rv3032.c- Extension
.c- Size
- 24032 bytes
- Lines
- 1005
- 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.
- 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/clk.hlinux/clk-provider.hlinux/bcd.hlinux/bitfield.hlinux/bitops.hlinux/hwmon.hlinux/i2c.hlinux/interrupt.hlinux/kernel.hlinux/log2.hlinux/module.hlinux/of.hlinux/regmap.hlinux/rtc.h
Detected Declarations
struct rv3032_datafunction rv3032_exit_eerdfunction rv3032_enter_eerdfunction rv3032_update_cfgfunction rv3032_handle_irqfunction rv3032_get_timefunction rv3032_set_timefunction rv3032_get_alarmfunction rv3032_set_alarmfunction rv3032_alarm_irq_enablefunction rv3032_read_offsetfunction rv3032_set_offsetfunction rv3032_param_getfunction rv3032_param_setfunction rv3032_ioctlfunction rv3032_nvram_writefunction rv3032_nvram_readfunction rv3032_eeprom_writefunction rv3032_eeprom_readfunction rv3032_trickle_charger_setupfunction rv3032_clkout_recalc_ratefunction rv3032_clkout_determine_ratefunction rv3032_clkout_set_ratefunction rv3032_clkout_preparefunction rv3032_clkout_unpreparefunction rv3032_clkout_is_preparedfunction rv3032_clkout_register_clkfunction rv3032_hwmon_read_tempfunction rv3032_hwmon_is_visiblefunction rv3032_hwmon_readfunction rv3032_hwmon_registerfunction rv3032_probe
Annotated Snippet
struct rv3032_data {
struct regmap *regmap;
struct rtc_device *rtc;
bool trickle_charger_set;
#ifdef CONFIG_COMMON_CLK
struct clk_hw clkout_hw;
#endif
};
static u16 rv3032_trickle_resistors[] = {1000, 2000, 7000, 11000};
static u16 rv3032_trickle_voltages[] = {0, 1750, 3000, 4400};
static int rv3032_exit_eerd(struct rv3032_data *rv3032, u32 eerd)
{
if (eerd)
return 0;
return regmap_update_bits(rv3032->regmap, RV3032_CTRL1, RV3032_CTRL1_EERD, 0);
}
static int rv3032_enter_eerd(struct rv3032_data *rv3032, u32 *eerd)
{
u32 ctrl1, status;
int ret;
ret = regmap_read(rv3032->regmap, RV3032_CTRL1, &ctrl1);
if (ret)
return ret;
*eerd = ctrl1 & RV3032_CTRL1_EERD;
if (*eerd)
return 0;
ret = regmap_update_bits(rv3032->regmap, RV3032_CTRL1,
RV3032_CTRL1_EERD, RV3032_CTRL1_EERD);
if (ret)
return ret;
ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status,
!(status & RV3032_TLSB_EEBUSY),
RV3032_EEBUSY_POLL, RV3032_EEBUSY_TIMEOUT);
if (ret) {
rv3032_exit_eerd(rv3032, *eerd);
return ret;
}
return 0;
}
static int rv3032_update_cfg(struct rv3032_data *rv3032, unsigned int reg,
unsigned int mask, unsigned int val)
{
u32 status, eerd;
int ret;
ret = rv3032_enter_eerd(rv3032, &eerd);
if (ret)
return ret;
ret = regmap_update_bits(rv3032->regmap, reg, mask, val);
if (ret)
goto exit_eerd;
ret = regmap_write(rv3032->regmap, RV3032_EEPROM_CMD, RV3032_EEPROM_CMD_UPDATE);
if (ret)
goto exit_eerd;
usleep_range(46000, RV3032_EEBUSY_TIMEOUT);
ret = regmap_read_poll_timeout(rv3032->regmap, RV3032_TLSB, status,
!(status & RV3032_TLSB_EEBUSY),
RV3032_EEBUSY_POLL, RV3032_EEBUSY_TIMEOUT);
exit_eerd:
rv3032_exit_eerd(rv3032, eerd);
return ret;
}
static irqreturn_t rv3032_handle_irq(int irq, void *dev_id)
{
struct rv3032_data *rv3032 = dev_id;
unsigned long events = 0;
u32 status = 0, ctrl = 0;
if (regmap_read(rv3032->regmap, RV3032_STATUS, &status) < 0 ||
status == 0) {
return IRQ_NONE;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/bcd.h`, `linux/bitfield.h`, `linux/bitops.h`, `linux/hwmon.h`, `linux/i2c.h`, `linux/interrupt.h`.
- Detected declarations: `struct rv3032_data`, `function rv3032_exit_eerd`, `function rv3032_enter_eerd`, `function rv3032_update_cfg`, `function rv3032_handle_irq`, `function rv3032_get_time`, `function rv3032_set_time`, `function rv3032_get_alarm`, `function rv3032_set_alarm`, `function rv3032_alarm_irq_enable`.
- 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.
- 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.