module_param(wdt_timeout, int, 0644);
MODULE_PARM_DESC(wdt_timeout, "Watchdog time in seconds. (default="
__MODULE_STRING(CDNS_WDT_DEFAULT_TIMEOUT) ")");
module_param(nowayout, int, 0644);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
/** * struct cdns_wdt - Watchdog device structure * @regs: baseaddress of device * @rst: reset flag * @clk: struct clk * of a clock source * @prescaler: for saving prescaler value * @ctrl_clksel: counter clock prescaler selection * @io_lock: spinlock for IO register access * @cdns_wdt_device: watchdog device structure * * Structure containing parameters specific to cadence watchdog.
*/ struct cdns_wdt { void __iomem *regs; bool rst; struct clk *clk;
u32 prescaler;
u32 ctrl_clksel;
spinlock_t io_lock; struct watchdog_device cdns_wdt_device;
};
/* Register Offsets for the WDT */ #define CDNS_WDT_ZMR_OFFSET 0x0 /* Zero Mode Register */ #define CDNS_WDT_CCR_OFFSET 0x4 /* Counter Control Register */ #define CDNS_WDT_RESTART_OFFSET 0x8 /* Restart Register */ #define CDNS_WDT_SR_OFFSET 0xC /* Status Register */
/* * Zero Mode Register - This register controls how the time out is indicated * and also contains the access code to allow writes to the register (0xABC).
*/ #define CDNS_WDT_ZMR_WDEN_MASK 0x00000001 /* Enable the WDT */ #define CDNS_WDT_ZMR_RSTEN_MASK 0x00000002 /* Enable the reset output */ #define CDNS_WDT_ZMR_IRQEN_MASK 0x00000004 /* Enable IRQ output */ #define CDNS_WDT_ZMR_RSTLEN_16 0x00000030 /* Reset pulse of 16 pclk cycles */ #define CDNS_WDT_ZMR_ZKEY_VAL 0x00ABC000 /* Access key, 0xABC << 12 */ /* * Counter Control register - This register controls how fast the timer runs * and the reset value and also contains the access code to allow writes to * the register.
*/ #define CDNS_WDT_CCR_CRV_MASK 0x00003FFC /* Counter reset value */
/** * cdns_wdt_stop - Stop the watchdog. * * @wdd: watchdog device * * Read the contents of the ZMR register, clear the WDEN bit * in the register and set the access key for successful write. * * Return: always 0
*/ staticint cdns_wdt_stop(struct watchdog_device *wdd)
{ struct cdns_wdt *wdt = watchdog_get_drvdata(wdd);
/** * cdns_wdt_start - Enable and start the watchdog. * * @wdd: watchdog device * * The counter value is calculated according to the formula: * calculated count = (timeout * clock) / prescaler + 1. * The calculated count is divided by 0x1000 to obtain the field value * to write to counter control register. * Clears the contents of prescaler and counter reset value. Sets the * prescaler to 4096 and the calculated count and access key * to write to CCR Register. * Sets the WDT (WDEN bit) and either the Reset signal(RSTEN bit) * or Interrupt signal(IRQEN) with a specified cycles and the access * key to write to ZMR Register. * * Return: always 0
*/ staticint cdns_wdt_start(struct watchdog_device *wdd)
{ struct cdns_wdt *wdt = watchdog_get_drvdata(wdd); unsignedint data = 0; unsignedshort count; unsignedlong clock_f = clk_get_rate(wdt->clk);
/* * Counter value divisor to obtain the value of * counter reset to be written to control register.
*/
count = (wdd->timeout * (clock_f / wdt->prescaler)) /
CDNS_WDT_COUNTER_VALUE_DIVISOR + 1;
if (count > CDNS_WDT_COUNTER_MAX)
count = CDNS_WDT_COUNTER_MAX;
/* Write counter access key first to be able write to register */
data = count | CDNS_WDT_REGISTER_ACCESS_KEY | wdt->ctrl_clksel;
cdns_wdt_writereg(wdt, CDNS_WDT_CCR_OFFSET, data);
data = CDNS_WDT_ZMR_WDEN_MASK | CDNS_WDT_ZMR_RSTLEN_16 |
CDNS_WDT_ZMR_ZKEY_VAL;
/* Reset on timeout if specified in device tree. */ if (wdt->rst) {
data |= CDNS_WDT_ZMR_RSTEN_MASK;
data &= ~CDNS_WDT_ZMR_IRQEN_MASK;
} else {
data &= ~CDNS_WDT_ZMR_RSTEN_MASK;
data |= CDNS_WDT_ZMR_IRQEN_MASK;
}
cdns_wdt_writereg(wdt, CDNS_WDT_ZMR_OFFSET, data);
cdns_wdt_writereg(wdt, CDNS_WDT_RESTART_OFFSET,
CDNS_WDT_RESTART_KEY);
spin_unlock(&wdt->io_lock);
return 0;
}
/** * cdns_wdt_settimeout - Set a new timeout value for the watchdog device. * * @wdd: watchdog device * @new_time: new timeout value that needs to be set * Return: 0 on success * * Update the watchdog_device timeout with new value which is used when * cdns_wdt_start is called.
*/ staticint cdns_wdt_settimeout(struct watchdog_device *wdd, unsignedint new_time)
{
wdd->timeout = new_time;
return cdns_wdt_start(wdd);
}
/** * cdns_wdt_irq_handler - Notifies of watchdog timeout. * * @irq: interrupt number * @dev_id: pointer to a platform device structure * Return: IRQ_HANDLED * * The handler is invoked when the watchdog times out and a * reset on timeout has not been enabled.
*/ static irqreturn_t cdns_wdt_irq_handler(int irq, void *dev_id)
{ struct platform_device *pdev = dev_id;
dev_info(&pdev->dev, "Watchdog timed out. Internal reset not enabled\n");
return IRQ_HANDLED;
}
/* * Info structure used to indicate the features supported by the device * to the upper layers. This is defined in watchdog.h header file.
*/ staticconststruct watchdog_info cdns_wdt_info = {
.identity = "cdns_wdt watchdog",
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
WDIOF_MAGICCLOSE,
};
/************************Platform Operations*****************************/ /** * cdns_wdt_probe - Probe call for the device. * * @pdev: handle to the platform device structure. * Return: 0 on success, negative error otherwise. * * It does all the memory allocation and registration for the device.
*/ staticint cdns_wdt_probe(struct platform_device *pdev)
{ struct device *dev = &pdev->dev; int ret, irq; unsignedlong clock_f; struct cdns_wdt *wdt; struct watchdog_device *cdns_wdt_device;
wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL); if (!wdt) return -ENOMEM;
if (watchdog_active(&wdt->cdns_wdt_device)) {
cdns_wdt_stop(&wdt->cdns_wdt_device);
clk_disable_unprepare(wdt->clk);
}
return 0;
}
/** * cdns_wdt_resume - Resume the device. * * @dev: handle to the device structure. * Return: 0 on success, errno otherwise.
*/ staticint __maybe_unused cdns_wdt_resume(struct device *dev)
{ int ret; struct cdns_wdt *wdt = dev_get_drvdata(dev);
if (watchdog_active(&wdt->cdns_wdt_device)) {
ret = clk_prepare_enable(wdt->clk); if (ret) {
dev_err(dev, "unable to enable clock\n"); return ret;
}
cdns_wdt_start(&wdt->cdns_wdt_device);
}
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.