drivers/rtc/rtc-moxart.c
Source file repositories/reference/linux-study-clean/drivers/rtc/rtc-moxart.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/rtc/rtc-moxart.c- Extension
.c- Size
- 8329 bytes
- Lines
- 309
- 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/err.hlinux/init.hlinux/kernel.hlinux/delay.hlinux/rtc.hlinux/platform_device.hlinux/module.hlinux/mod_devicetable.hlinux/gpio/consumer.h
Detected Declarations
struct moxart_rtcfunction moxart_rtc_write_bytefunction moxart_rtc_read_bytefunction moxart_rtc_read_registerfunction moxart_rtc_write_registerfunction moxart_rtc_set_timefunction moxart_rtc_read_timefunction moxart_rtc_probe
Annotated Snippet
struct moxart_rtc {
struct rtc_device *rtc;
spinlock_t rtc_lock;
struct gpio_desc *gpio_data;
struct gpio_desc *gpio_sclk;
struct gpio_desc *gpio_reset;
};
static int day_of_year[12] = { 0, 31, 59, 90, 120, 151, 181,
212, 243, 273, 304, 334 };
static void moxart_rtc_write_byte(struct device *dev, u8 data)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
int i;
for (i = 0; i < 8; i++, data >>= 1) {
gpiod_set_value(moxart_rtc->gpio_sclk, 0);
gpiod_set_value(moxart_rtc->gpio_data, ((data & 1) == 1));
udelay(GPIO_RTC_DELAY_TIME);
gpiod_set_value(moxart_rtc->gpio_sclk, 1);
udelay(GPIO_RTC_DELAY_TIME);
}
}
static u8 moxart_rtc_read_byte(struct device *dev)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
int i;
u8 data = 0;
for (i = 0; i < 8; i++) {
gpiod_set_value(moxart_rtc->gpio_sclk, 0);
udelay(GPIO_RTC_DELAY_TIME);
gpiod_set_value(moxart_rtc->gpio_sclk, 1);
udelay(GPIO_RTC_DELAY_TIME);
if (gpiod_get_value(moxart_rtc->gpio_data))
data |= (1 << i);
udelay(GPIO_RTC_DELAY_TIME);
}
return data;
}
static u8 moxart_rtc_read_register(struct device *dev, u8 cmd)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
u8 data;
unsigned long flags;
local_irq_save(flags);
gpiod_direction_output(moxart_rtc->gpio_data, 0);
gpiod_set_value(moxart_rtc->gpio_reset, 1);
udelay(GPIO_RTC_DELAY_TIME);
moxart_rtc_write_byte(dev, cmd);
gpiod_direction_input(moxart_rtc->gpio_data);
udelay(GPIO_RTC_DELAY_TIME);
data = moxart_rtc_read_byte(dev);
gpiod_set_value(moxart_rtc->gpio_sclk, 0);
gpiod_set_value(moxart_rtc->gpio_reset, 0);
udelay(GPIO_RTC_DELAY_TIME);
local_irq_restore(flags);
return data;
}
static void moxart_rtc_write_register(struct device *dev, u8 cmd, u8 data)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
unsigned long flags;
local_irq_save(flags);
gpiod_direction_output(moxart_rtc->gpio_data, 0);
gpiod_set_value(moxart_rtc->gpio_reset, 1);
udelay(GPIO_RTC_DELAY_TIME);
moxart_rtc_write_byte(dev, cmd);
moxart_rtc_write_byte(dev, data);
gpiod_set_value(moxart_rtc->gpio_sclk, 0);
gpiod_set_value(moxart_rtc->gpio_reset, 0);
udelay(GPIO_RTC_DELAY_TIME);
local_irq_restore(flags);
}
static int moxart_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
struct moxart_rtc *moxart_rtc = dev_get_drvdata(dev);
Annotation
- Immediate include surface: `linux/err.h`, `linux/init.h`, `linux/kernel.h`, `linux/delay.h`, `linux/rtc.h`, `linux/platform_device.h`, `linux/module.h`, `linux/mod_devicetable.h`.
- Detected declarations: `struct moxart_rtc`, `function moxart_rtc_write_byte`, `function moxart_rtc_read_byte`, `function moxart_rtc_read_register`, `function moxart_rtc_write_register`, `function moxart_rtc_set_time`, `function moxart_rtc_read_time`, `function moxart_rtc_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.