Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Watchdog driver for Technologic Systems TS-72xx based SBCs
0003  * (TS-7200, TS-7250 and TS-7260). These boards have external
0004  * glue logic CPLD chip, which includes programmable watchdog
0005  * timer.
0006  *
0007  * Copyright (c) 2009 Mika Westerberg <mika.westerberg@iki.fi>
0008  *
0009  * This driver is based on ep93xx_wdt and wm831x_wdt drivers.
0010  *
0011  * This file is licensed under the terms of the GNU General Public
0012  * License version 2. This program is licensed "as is" without any
0013  * warranty of any kind, whether express or implied.
0014  */
0015 
0016 #include <linux/platform_device.h>
0017 #include <linux/module.h>
0018 #include <linux/watchdog.h>
0019 #include <linux/io.h>
0020 
0021 #define TS72XX_WDT_DEFAULT_TIMEOUT  30
0022 
0023 static int timeout;
0024 module_param(timeout, int, 0);
0025 MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds.");
0026 
0027 static bool nowayout = WATCHDOG_NOWAYOUT;
0028 module_param(nowayout, bool, 0);
0029 MODULE_PARM_DESC(nowayout, "Disable watchdog shutdown on close");
0030 
0031 /* priv->control_reg */
0032 #define TS72XX_WDT_CTRL_DISABLE     0x00
0033 #define TS72XX_WDT_CTRL_250MS       0x01
0034 #define TS72XX_WDT_CTRL_500MS       0x02
0035 #define TS72XX_WDT_CTRL_1SEC        0x03
0036 #define TS72XX_WDT_CTRL_RESERVED    0x04
0037 #define TS72XX_WDT_CTRL_2SEC        0x05
0038 #define TS72XX_WDT_CTRL_4SEC        0x06
0039 #define TS72XX_WDT_CTRL_8SEC        0x07
0040 
0041 /* priv->feed_reg */
0042 #define TS72XX_WDT_FEED_VAL     0x05
0043 
0044 struct ts72xx_wdt_priv {
0045     void __iomem    *control_reg;
0046     void __iomem    *feed_reg;
0047     struct watchdog_device wdd;
0048     unsigned char regval;
0049 };
0050 
0051 static int ts72xx_wdt_start(struct watchdog_device *wdd)
0052 {
0053     struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
0054 
0055     writeb(TS72XX_WDT_FEED_VAL, priv->feed_reg);
0056     writeb(priv->regval, priv->control_reg);
0057 
0058     return 0;
0059 }
0060 
0061 static int ts72xx_wdt_stop(struct watchdog_device *wdd)
0062 {
0063     struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
0064 
0065     writeb(TS72XX_WDT_FEED_VAL, priv->feed_reg);
0066     writeb(TS72XX_WDT_CTRL_DISABLE, priv->control_reg);
0067 
0068     return 0;
0069 }
0070 
0071 static int ts72xx_wdt_ping(struct watchdog_device *wdd)
0072 {
0073     struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
0074 
0075     writeb(TS72XX_WDT_FEED_VAL, priv->feed_reg);
0076 
0077     return 0;
0078 }
0079 
0080 static int ts72xx_wdt_settimeout(struct watchdog_device *wdd, unsigned int to)
0081 {
0082     struct ts72xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
0083 
0084     if (to == 1) {
0085         priv->regval = TS72XX_WDT_CTRL_1SEC;
0086     } else if (to == 2) {
0087         priv->regval = TS72XX_WDT_CTRL_2SEC;
0088     } else if (to <= 4) {
0089         priv->regval = TS72XX_WDT_CTRL_4SEC;
0090         to = 4;
0091     } else {
0092         priv->regval = TS72XX_WDT_CTRL_8SEC;
0093         if (to <= 8)
0094             to = 8;
0095     }
0096 
0097     wdd->timeout = to;
0098 
0099     if (watchdog_active(wdd)) {
0100         ts72xx_wdt_stop(wdd);
0101         ts72xx_wdt_start(wdd);
0102     }
0103 
0104     return 0;
0105 }
0106 
0107 static const struct watchdog_info ts72xx_wdt_ident = {
0108     .options        = WDIOF_KEEPALIVEPING |
0109                   WDIOF_SETTIMEOUT |
0110                   WDIOF_MAGICCLOSE,
0111     .firmware_version   = 1,
0112     .identity       = "TS-72XX WDT",
0113 };
0114 
0115 static const struct watchdog_ops ts72xx_wdt_ops = {
0116     .owner      = THIS_MODULE,
0117     .start      = ts72xx_wdt_start,
0118     .stop       = ts72xx_wdt_stop,
0119     .ping       = ts72xx_wdt_ping,
0120     .set_timeout    = ts72xx_wdt_settimeout,
0121 };
0122 
0123 static int ts72xx_wdt_probe(struct platform_device *pdev)
0124 {
0125     struct device *dev = &pdev->dev;
0126     struct ts72xx_wdt_priv *priv;
0127     struct watchdog_device *wdd;
0128     int ret;
0129 
0130     priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0131     if (!priv)
0132         return -ENOMEM;
0133 
0134     priv->control_reg = devm_platform_ioremap_resource(pdev, 0);
0135     if (IS_ERR(priv->control_reg))
0136         return PTR_ERR(priv->control_reg);
0137 
0138     priv->feed_reg = devm_platform_ioremap_resource(pdev, 1);
0139     if (IS_ERR(priv->feed_reg))
0140         return PTR_ERR(priv->feed_reg);
0141 
0142     wdd = &priv->wdd;
0143     wdd->info = &ts72xx_wdt_ident;
0144     wdd->ops = &ts72xx_wdt_ops;
0145     wdd->min_timeout = 1;
0146     wdd->max_hw_heartbeat_ms = 8000;
0147     wdd->parent = dev;
0148 
0149     watchdog_set_nowayout(wdd, nowayout);
0150 
0151     wdd->timeout = TS72XX_WDT_DEFAULT_TIMEOUT;
0152     watchdog_init_timeout(wdd, timeout, dev);
0153 
0154     watchdog_set_drvdata(wdd, priv);
0155 
0156     ret = devm_watchdog_register_device(dev, wdd);
0157     if (ret)
0158         return ret;
0159 
0160     dev_info(dev, "TS-72xx Watchdog driver\n");
0161 
0162     return 0;
0163 }
0164 
0165 static struct platform_driver ts72xx_wdt_driver = {
0166     .probe      = ts72xx_wdt_probe,
0167     .driver     = {
0168         .name   = "ts72xx-wdt",
0169     },
0170 };
0171 
0172 module_platform_driver(ts72xx_wdt_driver);
0173 
0174 MODULE_AUTHOR("Mika Westerberg <mika.westerberg@iki.fi>");
0175 MODULE_DESCRIPTION("TS-72xx SBC Watchdog");
0176 MODULE_LICENSE("GPL");
0177 MODULE_ALIAS("platform:ts72xx-wdt");