drivers/rtc/rtc-bq4802.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-bq4802.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-bq4802.c- Extension
.c- Size
- 4267 bytes
- Lines
- 203
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/kernel.hlinux/module.hlinux/init.hlinux/io.hlinux/platform_device.hlinux/rtc.hlinux/bcd.hlinux/slab.h
Detected Declarations
struct bq4802function bq4802_read_iofunction bq4802_write_iofunction bq4802_read_memfunction bq4802_write_memfunction bq4802_read_timefunction bq4802_set_timefunction bq4802_probe
Annotated Snippet
struct bq4802 {
void __iomem *regs;
unsigned long ioport;
struct rtc_device *rtc;
spinlock_t lock;
struct resource *r;
u8 (*read)(struct bq4802 *, int);
void (*write)(struct bq4802 *, int, u8);
};
static u8 bq4802_read_io(struct bq4802 *p, int off)
{
return inb(p->ioport + off);
}
static void bq4802_write_io(struct bq4802 *p, int off, u8 val)
{
outb(val, p->ioport + off);
}
static u8 bq4802_read_mem(struct bq4802 *p, int off)
{
return readb(p->regs + off);
}
static void bq4802_write_mem(struct bq4802 *p, int off, u8 val)
{
writeb(val, p->regs + off);
}
static int bq4802_read_time(struct device *dev, struct rtc_time *tm)
{
struct bq4802 *p = dev_get_drvdata(dev);
unsigned long flags;
unsigned int century;
u8 val;
spin_lock_irqsave(&p->lock, flags);
val = p->read(p, 0x0e);
p->write(p, 0xe, val | 0x08);
tm->tm_sec = p->read(p, 0x00);
tm->tm_min = p->read(p, 0x02);
tm->tm_hour = p->read(p, 0x04);
tm->tm_mday = p->read(p, 0x06);
tm->tm_mon = p->read(p, 0x09);
tm->tm_year = p->read(p, 0x0a);
tm->tm_wday = p->read(p, 0x08);
century = p->read(p, 0x0f);
p->write(p, 0x0e, val);
spin_unlock_irqrestore(&p->lock, flags);
tm->tm_sec = bcd2bin(tm->tm_sec);
tm->tm_min = bcd2bin(tm->tm_min);
tm->tm_hour = bcd2bin(tm->tm_hour);
tm->tm_mday = bcd2bin(tm->tm_mday);
tm->tm_mon = bcd2bin(tm->tm_mon);
tm->tm_year = bcd2bin(tm->tm_year);
tm->tm_wday = bcd2bin(tm->tm_wday);
century = bcd2bin(century);
tm->tm_year += (century * 100);
tm->tm_year -= 1900;
tm->tm_mon--;
return 0;
}
static int bq4802_set_time(struct device *dev, struct rtc_time *tm)
{
struct bq4802 *p = dev_get_drvdata(dev);
u8 sec, min, hrs, day, mon, yrs, century, val;
unsigned long flags;
unsigned int year;
year = tm->tm_year + 1900;
century = year / 100;
yrs = year % 100;
mon = tm->tm_mon + 1; /* tm_mon starts at zero */
day = tm->tm_mday;
hrs = tm->tm_hour;
min = tm->tm_min;
sec = tm->tm_sec;
sec = bin2bcd(sec);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/io.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/bcd.h`, `linux/slab.h`.
- Detected declarations: `struct bq4802`, `function bq4802_read_io`, `function bq4802_write_io`, `function bq4802_read_mem`, `function bq4802_write_mem`, `function bq4802_read_time`, `function bq4802_set_time`, `function bq4802_probe`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.