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.

Dependency Surface

Detected Declarations

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

Implementation Notes