imx6 WatchDog驱动程序及测试例程

本文档详细介绍了IMX2系列处理器的WatchDog驱动程序,包括驱动结构、宏定义、函数实现以及如何设置超时时间和喂狗操作。此外,还提供了测试例程,展示了如何通过ioctl和write方法与驱动进行交互,保持看门狗的运行状态。
摘要由CSDN通过智能技术生成
/*
 * Watchdog driver for IMX2 and later processors
 *
 *  Copyright (C) 2010 Wolfram Sang, Pengutronix e.K. <w.sang@pengutronix.de>
 *
 * some parts adapted by similar drivers from Darius Augulis and Vladimir
 * Zapolskiy, additional improvements by Wim Van Sebroeck.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * NOTE: MX1 has a slightly different Watchdog than MX2 and later:
 *
 *            MX1:        MX2+:
 *            ----        -----
 * Registers:        32-bit        16-bit
 * Stopable timer:    Yes        No
 * Need to enable clk:    No        Yes
 * Halt on suspend:    Manual        Can be automatic
 */

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/platform_device.h>
#include <linux/watchdog.h>
#include <linux/clk.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/uaccess.h>
#include <linux/timer.h>
#include <linux/jiffies.h>
#include <linux/interrupt.h>
#include <mach/hardware.h>
#include <mach/irqs.h>

#define DRIVER_NAME "imx2-wdt"

//定义一些宏,方便使用。

#define IMX2_WDT_WCR        0x00        /* Control Register */
#define IMX2_WDT_WCR_WT        (0xFF << 8)    /* -> Watchdog Timeout Field */
#define IMX2_WDT_WCR_WRE    (1 << 3)    /* -> WDOG Reset Enable */
#define IMX2_WDT_WCR_WDE    (1 << 2)    /* -> Watchdog Enable */
#define IMX2_WDT_WCR_WDZST    (1 << 0)    /* -> Watchdog timer Suspend */


#define IMX2_WDT_WSR        0x02        /* Service Register */
#define IMX2_WDT_SEQ1        0x5555        /* -> service sequence 1 */
#define IMX2_WDT_SEQ2        0xAAAA        /* -> service sequence 2 */

#define IMX2_WDT_WICR        0x06        /*Interrupt Control Register*/
#define IMX2_WDT_WICR_WIE    (1 << 15)    /* -> Interrupt Enable */
#define IMX2_WDT_WICR_WTIS    (1 << 14)    /* -> Interrupt Status */
#define IMX2_WDT_WICR_WICT    (0xFF << 0)    /* -> Watchdog Interrupt Timeout Field */

#define IMX2_WDT_MAX_TIME    128
#define IMX2_WDT_DEFAULT_TIME    60        /* in seconds */

#define WDOG_SEC_TO_COUNT(s)    ((s * 2 - 1) << 8)
#define WDOG_SEC_TO_PRECOUNT(s)    (s * 2)        /* set WDOG pre timeout count*/

#define IMX2_WDT_STATUS_OPEN    0
#define IMX2_WDT_STATUS_STARTED    1
#define IMX2_WDT_EXPECT_CLOSE    2

static struct {
    struct clk *clk;
    void __iomem *base;
    unsigned timeout;
    unsigned pretimeout;
    unsigned long status;
    struct timer_list timer;    /* Pings the watchdog when closed */
} imx2_wdt;

static struct miscdevice imx2_wdt_miscdev;

static int nowayout = WATCHDOG_NOWAYOUT;
module_param(nowayout, int, 0);//内核参数
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
                __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");


static unsigned timeout = IMX2_WDT_DEFAULT_TIME;
module_param(timeout, uint, 0);//内核参数
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds (default="
                __MODULE_STRING(IMX2_WDT_DEFAULT_TIME) ")");

//这个结构体很重要,描述了驱动所支持的操作。
//应用程序使用ioctl GETSUPPORT调用来获取这个结构体
//然后在应用层使用位与检测每一位的功能。
static const struct watchdog_info imx2_wdt_info = {
    .identity = "imx2+ watchdog",
    .options = WDIOF_KEEPALIVEPING | WDIOF_S
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值