一、系统级看门狗定时器硬件设备简介(Xilinx ZYNQ7010)
这里讲解Xilinx ZYNQ7010此芯片的SWDT系统级看门狗定时器,它内部有一个24位计数器(其超时范围为32760 到 68719476736 个时钟周期),不仅可以使用CPU内部时钟,也可以使用外部设备或者PL输出的时钟,当看门狗计时器溢出超时时,可输出系统中断信号(PS)、系统复位(PS、PL、MIO)。
这些是系统级看门狗使用到相关的寄存器,具体可参考ug585-Zynq-7000-TRM.pdf文件
二、系统级看门狗驱动分析
在zynq-7000.dtsi文件中找到系统级看门狗设备树节点对应得到compatible属性为"cdns,wdt-r1p2",找到对应的驱动文件为/drivers/watchdog/cadence_wdt.c文件。
1、确认驱动加载模型
static const struct of_device_id cdns_wdt_of_match[] = {
{ .compatible = "cdns,wdt-r1p2", },
{ /* end of table */ }
};
MODULE_DEVICE_TABLE(of, cdns_wdt_of_match);
/* Driver Structure */
static struct platform_driver cdns_wdt_driver = {
.probe = cdns_wdt_probe,
.remove = cdns_wdt_remove,
.shutdown = cdns_wdt_shutdown,[]
.driver = {
.name = "cdns-wdt",
.of_match_table = cdns_wdt_of_match,
.pm = &cdns_wdt_pm_ops,
},
};
module_platform_driver(cdns_wdt_driver);
由此可知使用platform虚拟总线驱动模型。
2、分析probe函数
static int cdns_wdt_probe(struct platform_device *pdev)
{
struct resource *res;
int ret, irq;
unsigned long clock_f;
struct cdns_wdt *wdt;
struct watchdog_device *cdns_wdt_device;
wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
if (!wdt)
return -ENOMEM;
cdns_wdt_device = &wdt->cdns_wdt_device;
cdns_wdt_device->info = &cdns_wdt_info;
cdns_wdt_device->ops = &cd