drivers/rtc/rtc-lp8788.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-lp8788.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-lp8788.c- Extension
.c- Size
- 7753 bytes
- Lines
- 323
- 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 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/err.hlinux/irqdomain.hlinux/mfd/lp8788.hlinux/module.hlinux/platform_device.hlinux/rtc.hlinux/slab.h
Detected Declarations
struct lp8788_rtcenum lp8788_timefunction _to_tm_wdayfunction _to_lp8788_wdayfunction lp8788_rtc_unlockfunction lp8788_rtc_read_timefunction lp8788_rtc_set_timefunction lp8788_read_alarmfunction lp8788_set_alarmfunction lp8788_alarm_irq_enablefunction lp8788_alarm_irq_handlerfunction lp8788_alarm_irq_registerfunction lp8788_rtc_probe
Annotated Snippet
struct lp8788_rtc {
struct lp8788 *lp;
struct rtc_device *rdev;
enum lp8788_alarm_sel alarm;
int irq;
};
static const u8 addr_alarm_sec[LP8788_ALARM_MAX] = {
LP8788_ALM1_SEC,
LP8788_ALM2_SEC,
};
static const u8 addr_alarm_en[LP8788_ALARM_MAX] = {
LP8788_ALM1_EN,
LP8788_ALM2_EN,
};
static const u8 mask_alarm_en[LP8788_ALARM_MAX] = {
LP8788_INT_RTC_ALM1_M,
LP8788_INT_RTC_ALM2_M,
};
static const u8 shift_alarm_en[LP8788_ALARM_MAX] = {
LP8788_INT_RTC_ALM1_S,
LP8788_INT_RTC_ALM2_S,
};
static int _to_tm_wday(u8 lp8788_wday)
{
int i;
if (lp8788_wday == 0)
return 0;
/* lookup defined weekday from read register value */
for (i = 0; i < MAX_WDAY_BITS; i++) {
if ((lp8788_wday >> i) == LP8788_WDAY_SET)
break;
}
return i + 1;
}
static inline int _to_lp8788_wday(int tm_wday)
{
return LP8788_WDAY_SET << (tm_wday - 1);
}
static void lp8788_rtc_unlock(struct lp8788 *lp)
{
lp8788_write_byte(lp, LP8788_RTC_UNLOCK, RTC_UNLOCK);
lp8788_write_byte(lp, LP8788_RTC_UNLOCK, RTC_LATCH);
}
static int lp8788_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct lp8788_rtc *rtc = dev_get_drvdata(dev);
struct lp8788 *lp = rtc->lp;
u8 data[LPTIME_MAX];
int ret;
lp8788_rtc_unlock(lp);
ret = lp8788_read_multi_bytes(lp, LP8788_RTC_SEC, data, LPTIME_MAX);
if (ret)
return ret;
tm->tm_sec = data[LPTIME_SEC];
tm->tm_min = data[LPTIME_MIN];
tm->tm_hour = data[LPTIME_HOUR];
tm->tm_mday = data[LPTIME_MDAY];
tm->tm_mon = data[LPTIME_MON] - LP8788_MONTH_OFFSET;
tm->tm_year = data[LPTIME_YEAR] + LP8788_BASE_YEAR - 1900;
tm->tm_wday = _to_tm_wday(data[LPTIME_WDAY]);
return 0;
}
static int lp8788_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct lp8788_rtc *rtc = dev_get_drvdata(dev);
struct lp8788 *lp = rtc->lp;
u8 data[LPTIME_MAX - 1];
int ret, i, year;
year = tm->tm_year + 1900 - LP8788_BASE_YEAR;
if (year < 0) {
dev_err(lp->dev, "invalid year: %d\n", year);
return -EINVAL;
}
Annotation
- Immediate include surface: `linux/err.h`, `linux/irqdomain.h`, `linux/mfd/lp8788.h`, `linux/module.h`, `linux/platform_device.h`, `linux/rtc.h`, `linux/slab.h`.
- Detected declarations: `struct lp8788_rtc`, `enum lp8788_time`, `function _to_tm_wday`, `function _to_lp8788_wday`, `function lp8788_rtc_unlock`, `function lp8788_rtc_read_time`, `function lp8788_rtc_set_time`, `function lp8788_read_alarm`, `function lp8788_set_alarm`, `function lp8788_alarm_irq_enable`.
- Atlas domain: Driver Families / drivers/rtc.
- Implementation status: source implementation candidate.
- 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.