358
359 static const struct of_device_id omap_wdt_of_match[] = {
360 { .compatible = "ti,omap3-wdt", },
361 {},
362 };
363 MODULE_DEVICE_TABLE(of, omap_wdt_of_match);
364
365 static struct platform_driver omap_wdt_driver = {
366 .probe = omap_wdt_probe,
367 .remove = omap_wdt_remove,
368 .shutdown = omap_wdt_shutdown,
369 .suspend = omap_wdt_suspend,
370 .resume = omap_wdt_resume,
371 .driver = {
372 .name = "omap_wdt",
373 .of_match_table = omap_wdt_of_match,
374 },
375 };
376
377 module_platform_driver(omap_wdt_driver);
378
wdt@44e35000 {
compatible = "ti,omap3-wdt";
ti,hwmods = "wd_timer2";
reg = <0x44e35000 0x1000>;
interrupts = <0x5b>;
};
运行probe
230 static int omap_wdt_probe(struct platform_device *pdev)
231 {
232 struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
233 struct resource *res;
234 struct omap_wdt_dev *wdev;
235 int ret;
236
237 wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL);
238 if (!wdev)
239 return -ENOMEM;
240
241 wdev->omap_wdt_users = false;
242 wdev->dev = &pdev->dev;
243 wdev->wdt_trgr_pattern = 0x1234;
244 mutex_init(&wdev->lock);
245
246 /* reserve static register mappings */
247 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
248 wdev->base = devm_ioremap_resource(&pdev->dev, res);
249 if (IS_ERR(wdev->base))
250 return PTR_ERR(wdev->base);
251
252 wdev->wdog.info = &omap_wdt_info;
253 wdev->wdog.ops = &omap_wdt_ops;
254 wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
255 wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
256 wdev->wdog.parent = &pdev->dev;
257
258 if (watchdog_init_timeout(&wdev->wdog, timer_margin, &pdev->dev) < 0)
259 wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
260
261 watchdog_set_nowayout(&wdev->wdog, nowayout);
262
263 platform_set_drvdata(pdev, wdev);
264
265 pm_runtime_enable(wdev->dev);
266 pm_runtime_get_sync(wdev->dev);
267
268 if (pdata && pdata->read_reset_sources) {
269 u32 rs = pdata->read_reset_sources();
270 if (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT))
271 wdev->wdog.bootstatus = WDIOF_CARDRESET;
272 }
273
274 if (!early_enable)
275 omap_wdt_disable(wdev);
276
277 ret = watchdog_register_device(&wdev->wdog);
278 if (ret) {
279 pm_runtime_disable(wdev->dev);
280 return ret;
281 }
282
283 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
284 readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
285 wdev->wdog.timeout);
286
287 if (early_enable)
288 omap_wdt_start(&wdev->wdog);
289
290 pm_runtime_put(wdev->dev);
291
292 return 0;
293 }
294
237行:分配内存
247行:获取资源res->start = 0x44e35000;
252 行 wdev->wdog.info = &omap_wdt_info;
253 行 wdev->wdog.ops = &omap_wdt_ops;
254 行 wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
255 行 wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
258行:watchdog_init_timeout
98 /**
99 * watchdog_init_timeout() - initialize the timeout field
100 * @timeout_parm: timeout module parameter
101 * @dev: Device that stores the timeout-sec property
102 *
103 * Initialize the timeout field of the watchdog_device struct with either the
104 * timeout module parameter (if it is valid value) or the timeout-sec property
105 * (only if it is a valid value and the timeout_parm is out of bounds).
106 * If none of them are valid then we keep the old value (which should normally
107 * be the default timeout value).
108 *
109 * A zero is returned on success and -EINVAL for failure.
110 */
111 int watchdog_init_timeout(struct watchdog_device *wdd,
112 unsigned int timeout_parm, struct device *dev)
113 {
114 unsigned int t = 0;
115 int ret = 0;
116
117 watchdog_check_min_max_timeout(wdd);
118
119 /* try to get the timeout module parameter first */
120 if (!watchdog_timeout_invalid(wdd, timeout_parm) && timeout_parm) {
121 wdd->timeout = timeout_parm;
122 return ret;
123 }
124 if (timeout_parm)
125 ret = -EINVAL;
126
127 /* try to get the timeout_sec property */
128 if (dev == NULL || dev->of_node == NULL)
129 return ret;
130 of_property_read_u32(dev->of_node, "timeout-sec", &t);
131 if (!watchdog_timeout_invalid(wdd, t) && t)
132 wdd->timeout = t;
133 else
134 ret = -EINVAL;
135
136 return ret;
137 }
138 EXPORT_SYMBOL_GPL(watchdog_init_timeout);
139
初始化watchdog:返回ret = -EINVAL;
所以 wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
274行:关闭看门狗
103 static void omap_wdt_disable(struct omap_wdt_dev *wdev)
104 {
105 void __iomem *base = wdev->base;
106
107 /* sequence required to disable watchdog */
108 writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
109 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
110 cpu_relax();
111
112 writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
113 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
114 cpu_relax();
115 }
277行:注册看门狗:生成节点/dev/watchdog
接下来的操作就是按照芯片手册设置看门狗;