#if IS_ENABLED(CONFIG_STMP3XXX_RTC_WATCHDOG) /** * stmp3xxx_wdt_set_timeout - configure the watchdog inside the STMP3xxx RTC * @dev: the parent device of the watchdog (= the RTC) * @timeout: the desired value for the timeout register of the watchdog. * 0 disables the watchdog * * The watchdog needs one register and two bits which are in the RTC domain. * To handle the resource conflict, the RTC driver will create another * platform_device for the watchdog driver as a child of the RTC device. * The watchdog driver is passed the below accessor function via platform_data * to configure the watchdog. Locking is not needed because accessing SET/CLR * registers is atomic.
*/
if (wdt_pdev) {
wdt_pdev->dev.parent = &rtc_pdev->dev;
wdt_pdev->dev.platform_data = &wdt_pdata;
rc = platform_device_add(wdt_pdev); if (rc)
platform_device_put(wdt_pdev);
}
if (rc)
dev_err(&rtc_pdev->dev, "failed to register stmp3xxx_rtc_wdt\n");
} #else staticvoid stmp3xxx_wdt_register(struct platform_device *rtc_pdev)
{
} #endif/* CONFIG_STMP3XXX_RTC_WATCHDOG */
staticint stmp3xxx_wait_time(struct stmp3xxx_rtc_data *rtc_data)
{ int timeout = 5000; /* 3ms according to i.MX28 Ref Manual */ /* * The i.MX28 Applications Processor Reference Manual, Rev. 1, 2010 * states: * | The order in which registers are updated is * | Persistent 0, 1, 2, 3, 4, 5, Alarm, Seconds. * | (This list is in bitfield order, from LSB to MSB, as they would * | appear in the STALE_REGS and NEW_REGS bitfields of the HW_RTC_STAT * | register. For example, the Seconds register corresponds to * | STALE_REGS or NEW_REGS containing 0x80.)
*/ do { if (!(readl(rtc_data->io + STMP3XXX_RTC_STAT) &
(0x80 << STMP3XXX_RTC_STAT_STALE_SHIFT))) return 0;
udelay(1);
} while (--timeout > 0); return (readl(rtc_data->io + STMP3XXX_RTC_STAT) &
(0x80 << STMP3XXX_RTC_STAT_STALE_SHIFT)) ? -ETIME : 0;
}
/* Time read/write */ staticint stmp3xxx_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
{ int ret; struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
ret = stmp3xxx_wait_time(rtc_data); if (ret) return ret;
rtc_stat = readl(rtc_data->io + STMP3XXX_RTC_STAT); if (!(rtc_stat & STMP3XXX_RTC_STAT_RTC_PRESENT)) {
dev_err(&pdev->dev, "no device onboard\n"); return -ENODEV;
}
platform_set_drvdata(pdev, rtc_data);
/* * Resetting the rtc stops the watchdog timer that is potentially * running. So (assuming it is running on purpose) don't reset if the * watchdog is enabled.
*/ if (readl(rtc_data->io + STMP3XXX_RTC_CTRL) &
STMP3XXX_RTC_CTRL_WATCHDOGEN) {
dev_info(&pdev->dev, "Watchdog is running, skip resetting rtc\n");
} else {
err = stmp_reset_block(rtc_data->io); if (err) {
dev_err(&pdev->dev, "stmp_reset_block failed: %d\n",
err); return err;
}
}
/* * Obviously the rtc needs a clock input to be able to run. * This clock can be provided by an external 32k crystal. If that one is * missing XTAL must not be disabled in suspend which consumes a * lot of power. Normally the presence and exact frequency (supported * are 32000 Hz and 32768 Hz) is detectable from fuses, but as reality * proves these fuses are not blown correctly on all machines, so the * frequency can be overridden in the device tree.
*/ if (rtc_stat & STMP3XXX_RTC_STAT_XTAL32000_PRESENT)
crystalfreq = 32000; elseif (rtc_stat & STMP3XXX_RTC_STAT_XTAL32768_PRESENT)
crystalfreq = 32768;
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.