drivers/rtc/rtc-amlogic-a4.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-amlogic-a4.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-amlogic-a4.c- Extension
.c- Size
- 11662 bytes
- Lines
- 444
- 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/bitfield.hlinux/clk.hlinux/clk-provider.hlinux/delay.hlinux/module.hlinux/platform_device.hlinux/regmap.hlinux/rtc.hlinux/time64.h
Detected Declarations
struct aml_rtc_configstruct aml_rtc_datafunction gray_to_binaryfunction binary_to_grayfunction aml_rtc_read_timefunction aml_rtc_set_timefunction aml_rtc_set_alarmfunction aml_rtc_read_alarmfunction aml_rtc_read_offsetfunction aml_rtc_set_offsetfunction aml_rtc_alarm_enablefunction aml_rtc_handlerfunction aml_rtc_initfunction aml_rtc_probefunction aml_rtc_suspendfunction aml_rtc_resume
Annotated Snippet
struct aml_rtc_config {
bool gray_stored;
};
struct aml_rtc_data {
struct regmap *map;
struct rtc_device *rtc_dev;
int irq;
struct clk *rtc_clk;
struct clk *sys_clk;
int rtc_enabled;
const struct aml_rtc_config *config;
};
static inline u32 gray_to_binary(u32 gray)
{
u32 bcd = gray;
int size = sizeof(bcd) * 8;
int i;
for (i = 0; (1 << i) < size; i++)
bcd ^= bcd >> (1 << i);
return bcd;
}
static inline u32 binary_to_gray(u32 bcd)
{
return bcd ^ (bcd >> 1);
}
static int aml_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
struct aml_rtc_data *rtc = dev_get_drvdata(dev);
u32 time_sec;
/* if RTC disabled, read time failed */
if (!rtc->rtc_enabled)
return -EINVAL;
regmap_read(rtc->map, RTC_REAL_TIME, &time_sec);
if (rtc->config->gray_stored)
time_sec = gray_to_binary(time_sec);
rtc_time64_to_tm(time_sec, tm);
dev_dbg(dev, "%s: read time = %us\n", __func__, time_sec);
return 0;
}
static int aml_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct aml_rtc_data *rtc = dev_get_drvdata(dev);
u32 time_sec;
/* if RTC disabled, first enable it */
if (!rtc->rtc_enabled) {
regmap_write_bits(rtc->map, RTC_CTRL, RTC_ENABLE, RTC_ENABLE);
usleep_range(100, 200);
rtc->rtc_enabled = regmap_test_bits(rtc->map, RTC_CTRL, RTC_ENABLE);
if (!rtc->rtc_enabled)
return -EINVAL;
}
time_sec = rtc_tm_to_time64(tm);
if (rtc->config->gray_stored)
time_sec = binary_to_gray(time_sec);
regmap_write(rtc->map, RTC_COUNTER_REG, time_sec);
dev_dbg(dev, "%s: set time = %us\n", __func__, time_sec);
return 0;
}
static int aml_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
{
struct aml_rtc_data *rtc = dev_get_drvdata(dev);
time64_t alarm_sec;
/* if RTC disabled, set alarm failed */
if (!rtc->rtc_enabled)
return -EINVAL;
regmap_update_bits(rtc->map, RTC_CTRL,
RTC_ALRM0_EN, RTC_ALRM0_EN);
regmap_update_bits(rtc->map, RTC_INT_MASK,
RTC_ALRM0_IRQ_MSK, 0);
alarm_sec = rtc_tm_to_time64(&alarm->time);
if (rtc->config->gray_stored)
alarm_sec = binary_to_gray(alarm_sec);
regmap_write(rtc->map, RTC_ALARM0_REG, alarm_sec);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/clk-provider.h`, `linux/delay.h`, `linux/module.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/rtc.h`.
- Detected declarations: `struct aml_rtc_config`, `struct aml_rtc_data`, `function gray_to_binary`, `function binary_to_gray`, `function aml_rtc_read_time`, `function aml_rtc_set_time`, `function aml_rtc_set_alarm`, `function aml_rtc_read_alarm`, `function aml_rtc_read_offset`, `function aml_rtc_set_offset`.
- 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.