drivers/rtc/rtc-bq32k.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-bq32k.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-bq32k.c- Extension
.c- Size
- 7885 bytes
- Lines
- 333
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/i2c.hlinux/rtc.hlinux/init.hlinux/kstrtox.hlinux/errno.hlinux/bcd.h
Detected Declarations
struct bq32k_regsfunction bq32k_readfunction bq32k_writefunction bq32k_rtc_read_timefunction bq32k_rtc_set_timefunction trickle_charger_of_initfunction bq32k_sysfs_show_tricklecharge_bypassfunction bq32k_sysfs_store_tricklecharge_bypassfunction bq32k_sysfs_registerfunction bq32k_sysfs_unregisterfunction bq32k_probefunction bq32k_remove
Annotated Snippet
struct bq32k_regs {
uint8_t seconds;
uint8_t minutes;
uint8_t cent_hours;
uint8_t day;
uint8_t date;
uint8_t month;
uint8_t years;
};
static struct i2c_driver bq32k_driver;
static int bq32k_read(struct device *dev, void *data, uint8_t off, uint8_t len)
{
struct i2c_client *client = to_i2c_client(dev);
struct i2c_msg msgs[] = {
{
.addr = client->addr,
.flags = 0,
.len = 1,
.buf = &off,
}, {
.addr = client->addr,
.flags = I2C_M_RD,
.len = len,
.buf = data,
}
};
if (i2c_transfer(client->adapter, msgs, 2) == 2)
return 0;
return -EIO;
}
static int bq32k_write(struct device *dev, void *data, uint8_t off, uint8_t len)
{
struct i2c_client *client = to_i2c_client(dev);
uint8_t buffer[MAX_LEN + 1];
buffer[0] = off;
memcpy(&buffer[1], data, len);
if (i2c_master_send(client, buffer, len + 1) == len + 1)
return 0;
return -EIO;
}
static int bq32k_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct bq32k_regs regs;
int error;
error = bq32k_read(dev, ®s, 0, sizeof(regs));
if (error)
return error;
/*
* In case of oscillator failure, the register contents should be
* considered invalid. The flag is cleared the next time the RTC is set.
*/
if (regs.minutes & BQ32K_OF)
return -EINVAL;
tm->tm_sec = bcd2bin(regs.seconds & BQ32K_SECONDS_MASK);
tm->tm_min = bcd2bin(regs.minutes & BQ32K_MINUTES_MASK);
tm->tm_hour = bcd2bin(regs.cent_hours & BQ32K_HOURS_MASK);
tm->tm_mday = bcd2bin(regs.date);
tm->tm_wday = bcd2bin(regs.day) - 1;
tm->tm_mon = bcd2bin(regs.month) - 1;
tm->tm_year = bcd2bin(regs.years) +
((regs.cent_hours & BQ32K_CENT) ? 100 : 0);
return 0;
}
static int bq32k_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct bq32k_regs regs;
regs.seconds = bin2bcd(tm->tm_sec);
regs.minutes = bin2bcd(tm->tm_min);
regs.cent_hours = bin2bcd(tm->tm_hour) | BQ32K_CENT_EN;
regs.day = bin2bcd(tm->tm_wday + 1);
regs.date = bin2bcd(tm->tm_mday);
regs.month = bin2bcd(tm->tm_mon + 1);
if (tm->tm_year >= 100) {
regs.cent_hours |= BQ32K_CENT;
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/rtc.h`, `linux/init.h`, `linux/kstrtox.h`, `linux/errno.h`, `linux/bcd.h`.
- Detected declarations: `struct bq32k_regs`, `function bq32k_read`, `function bq32k_write`, `function bq32k_rtc_read_time`, `function bq32k_rtc_set_time`, `function trickle_charger_of_init`, `function bq32k_sysfs_show_tricklecharge_bypass`, `function bq32k_sysfs_store_tricklecharge_bypass`, `function bq32k_sysfs_register`, `function bq32k_sysfs_unregister`.
- 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.