struct tegra_rtc_info { struct platform_device *pdev; struct rtc_device *rtc; void __iomem *base; /* NULL if not initialized */ struct clk *clk; int irq; /* alarm and periodic IRQ */
spinlock_t lock;
};
/* * RTC hardware is busy when it is updating its values over AHB once every * eight 32 kHz clocks (~250 us). Outside of these updates the CPU is free to * write. CPU is always free to read.
*/ staticinline u32 tegra_rtc_check_busy(struct tegra_rtc_info *info)
{ return readl(info->base + TEGRA_RTC_REG_BUSY) & 1;
}
/* * Wait for hardware to be ready for writing. This function tries to maximize * the amount of time before the next update. It does this by waiting for the * RTC to become busy with its periodic update, then returning once the RTC * first becomes not busy. * * This periodic update (where the seconds and milliseconds are copied to the * AHB side) occurs every eight 32 kHz clocks (~250 us). The behavior of this * function allows us to make some assumptions without introducing a race, * because 250 us is plenty of time to read/write a value.
*/ staticint tegra_rtc_wait_while_busy(struct device *dev)
{ struct tegra_rtc_info *info = dev_get_drvdata(dev); int retries = 500; /* ~490 us is the worst case, ~250 us is best */
/* * First wait for the RTC to become busy. This is when it posts its * updated seconds+msec registers to AHB side.
*/ while (tegra_rtc_check_busy(info)) { if (!retries--) goto retry_failed;
udelay(1);
}
/* now we have about 250 us to manipulate registers */ return 0;
/* * RTC hardware copies seconds to shadow seconds when a read of * milliseconds occurs. use a lock to keep other threads out.
*/
spin_lock_irqsave(&info->lock, flags);
/* read the original value, and OR in the flag */
status = readl(info->base + TEGRA_RTC_REG_INTR_MASK); if (enabled)
status |= TEGRA_RTC_INTR_MASK_SEC_ALARM0; /* set it */ else
status &= ~TEGRA_RTC_INTR_MASK_SEC_ALARM0; /* clear it */
if (alarm->enabled)
sec = rtc_tm_to_time64(&alarm->time); else
sec = 0;
tegra_rtc_wait_while_busy(dev);
writel(sec, info->base + TEGRA_RTC_REG_SECONDS_ALARM0);
dev_vdbg(dev, "alarm read back as %d\n",
readl(info->base + TEGRA_RTC_REG_SECONDS_ALARM0));
/* if successfully written and alarm is enabled ... */ if (sec) {
tegra_rtc_alarm_irq_enable(dev, 1);
dev_vdbg(dev, "alarm set as %u, %ptR\n", sec, &alarm->time);
} else { /* disable alarm if 0 or write error */
dev_vdbg(dev, "alarm disabled\n");
tegra_rtc_alarm_irq_enable(dev, 0);
}
status = readl(info->base + TEGRA_RTC_REG_INTR_STATUS); if (status) { /* clear the interrupt masks and status on any IRQ */
tegra_rtc_wait_while_busy(dev);
/* only use ALARM0 as a wake source */
writel(0xffffffff, info->base + TEGRA_RTC_REG_INTR_STATUS);
writel(TEGRA_RTC_INTR_STATUS_SEC_ALARM0,
info->base + TEGRA_RTC_REG_INTR_MASK);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.