drivers/rtc/rtc-abx80x.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-abx80x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-abx80x.c- Extension
.c- Size
- 24701 bytes
- Lines
- 1010
- 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/bcd.hlinux/bitfield.hlinux/i2c.hlinux/kstrtox.hlinux/module.hlinux/of.hlinux/rtc.hlinux/watchdog.h
Detected Declarations
struct abx80x_capstruct abx80x_privenum abx80x_chipfunction abx80x_write_config_keyfunction abx80x_is_rc_modefunction abx80x_enable_trickle_chargerfunction abx80x_rtc_read_timefunction abx80x_rtc_set_timefunction abx80x_handle_irqfunction abx80x_read_alarmfunction abx80x_set_alarmfunction abx80x_rtc_set_autocalibrationfunction abx80x_rtc_get_autocalibrationfunction autocalibration_storefunction autocalibration_showfunction oscillator_storefunction oscillator_showfunction abx80x_alarm_irq_enablefunction abx80x_ioctlfunction abx80x_dt_trickle_cfgfunction timeout_bitsfunction __abx80x_wdog_set_timeoutfunction abx80x_wdog_set_timeoutfunction abx80x_wdog_pingfunction abx80x_wdog_startfunction abx80x_wdog_stopfunction abx80x_setup_watchdogfunction abx80x_setup_watchdogfunction abx80x_nvmem_xferfunction abx80x_nvmem_readfunction abx80x_nvmem_writefunction abx80x_setup_nvmemfunction abx80x_probe
Annotated Snippet
struct abx80x_cap {
u16 pn;
bool has_tc;
bool has_wdog;
};
static struct abx80x_cap abx80x_caps[] = {
[AB0801] = {.pn = 0x0801},
[AB0803] = {.pn = 0x0803},
[AB0804] = {.pn = 0x0804, .has_tc = true, .has_wdog = true},
[AB0805] = {.pn = 0x0805, .has_tc = true, .has_wdog = true},
[AB1801] = {.pn = 0x1801},
[AB1803] = {.pn = 0x1803},
[AB1804] = {.pn = 0x1804, .has_tc = true, .has_wdog = true},
[AB1805] = {.pn = 0x1805, .has_tc = true, .has_wdog = true},
[RV1805] = {.pn = 0x1805, .has_tc = true, .has_wdog = true},
[ABX80X] = {.pn = 0}
};
struct abx80x_priv {
struct rtc_device *rtc;
struct i2c_client *client;
struct watchdog_device wdog;
};
static int abx80x_write_config_key(struct i2c_client *client, u8 key)
{
if (i2c_smbus_write_byte_data(client, ABX8XX_REG_CFG_KEY, key) < 0) {
dev_err(&client->dev, "Unable to write configuration key\n");
return -EIO;
}
return 0;
}
static int abx80x_is_rc_mode(struct i2c_client *client)
{
int flags = 0;
flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSS);
if (flags < 0) {
dev_err(&client->dev,
"Failed to read autocalibration attribute\n");
return flags;
}
return (flags & ABX8XX_OSS_OMODE) ? 1 : 0;
}
static int abx80x_enable_trickle_charger(struct i2c_client *client,
u8 trickle_cfg)
{
int err;
/*
* Write the configuration key register to enable access to the Trickle
* register
*/
if (abx80x_write_config_key(client, ABX8XX_CFG_KEY_MISC) < 0)
return -EIO;
err = i2c_smbus_write_byte_data(client, ABX8XX_REG_TRICKLE,
ABX8XX_TRICKLE_CHARGE_ENABLE |
trickle_cfg);
if (err < 0) {
dev_err(&client->dev, "Unable to write trickle register\n");
return -EIO;
}
return 0;
}
static int abx80x_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct i2c_client *client = to_i2c_client(dev);
unsigned char buf[8];
int err, flags, rc_mode = 0;
/* Read the Oscillator Failure only in XT mode */
rc_mode = abx80x_is_rc_mode(client);
if (rc_mode < 0)
return rc_mode;
if (!rc_mode) {
flags = i2c_smbus_read_byte_data(client, ABX8XX_REG_OSS);
if (flags < 0)
return flags;
if (flags & ABX8XX_OSS_OF) {
dev_err(dev, "Oscillator failure, data is invalid.\n");
Annotation
- Immediate include surface: `linux/bcd.h`, `linux/bitfield.h`, `linux/i2c.h`, `linux/kstrtox.h`, `linux/module.h`, `linux/of.h`, `linux/rtc.h`, `linux/watchdog.h`.
- Detected declarations: `struct abx80x_cap`, `struct abx80x_priv`, `enum abx80x_chip`, `function abx80x_write_config_key`, `function abx80x_is_rc_mode`, `function abx80x_enable_trickle_charger`, `function abx80x_rtc_read_time`, `function abx80x_rtc_set_time`, `function abx80x_handle_irq`, `function abx80x_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.
- 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.