Blame view

drivers/watchdog/ep93xx_wdt.c 3.61 KB
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
1
2
3
4
5
6
7
8
9
10
  /*
   * Watchdog driver for Cirrus Logic EP93xx family of devices.
   *
   * Copyright (c) 2004 Ray Lehtiniemi
   * Copyright (c) 2006 Tower Technologies
   * Based on ep93xx driver, bits from alim7101_wdt.c
   *
   * Authors: Ray Lehtiniemi <rayl@mail.com>,
   *	Alessandro Zummo <a.zummo@towertech.it>
   *
e12a679dd   H Hartley Sweeten   watchdog: Convert...
11
12
13
   * Copyright (c) 2012 H Hartley Sweeten <hsweeten@visionengravers.com>
   *	Convert to a platform device and use the watchdog framework API
   *
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
14
15
16
17
18
19
20
21
   * This file is licensed under the terms of the GNU General Public
   * License version 2. This program is licensed "as is" without any
   * warranty of any kind, whether express or implied.
   *
   * This watchdog fires after 250msec, which is a too short interval
   * for us to rely on the user space daemon alone. So we ping the
   * wdt each ~200msec and eventually stop doing it if the user space
   * daemon dies.
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
22
   */
3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
23
  #include <linux/platform_device.h>
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
24
  #include <linux/module.h>
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
25
  #include <linux/watchdog.h>
2653d1d7f   Ryan Mallon   [ARM] 5606/1: Fix...
26
  #include <linux/io.h>
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
27

f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
28
29
  /* default timeout (secs) */
  #define WDT_TIMEOUT 30
86a1e1896   Wim Van Sebroeck   watchdog: nowayou...
30
  static bool nowayout = WATCHDOG_NOWAYOUT;
e12a679dd   H Hartley Sweeten   watchdog: Convert...
31
32
  module_param(nowayout, bool, 0);
  MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started");
917003610   H Hartley Sweeten   watchdog: ep93xx_...
33
  static unsigned int timeout;
2ca160635   Wim Van Sebroeck   watchdog: ep93xx_...
34
  module_param(timeout, uint, 0);
917003610   H Hartley Sweeten   watchdog: ep93xx_...
35
  MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds.");
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
36

3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
37
38
  #define EP93XX_WATCHDOG		0x00
  #define EP93XX_WDSTATUS		0x04
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
39

917003610   H Hartley Sweeten   watchdog: ep93xx_...
40
41
42
43
  struct ep93xx_wdt_priv {
  	void __iomem *mmio;
  	struct watchdog_device wdd;
  };
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
44

e12a679dd   H Hartley Sweeten   watchdog: Convert...
45
  static int ep93xx_wdt_start(struct watchdog_device *wdd)
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
46
  {
917003610   H Hartley Sweeten   watchdog: ep93xx_...
47
  	struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
48

917003610   H Hartley Sweeten   watchdog: ep93xx_...
49
  	writel(0xaaaa, priv->mmio + EP93XX_WATCHDOG);
e12a679dd   H Hartley Sweeten   watchdog: Convert...
50
51
  
  	return 0;
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
52
  }
e12a679dd   H Hartley Sweeten   watchdog: Convert...
53
  static int ep93xx_wdt_stop(struct watchdog_device *wdd)
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
54
  {
917003610   H Hartley Sweeten   watchdog: ep93xx_...
55
56
57
  	struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
  
  	writel(0xaa55, priv->mmio + EP93XX_WATCHDOG);
e12a679dd   H Hartley Sweeten   watchdog: Convert...
58
59
  
  	return 0;
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
60
  }
917003610   H Hartley Sweeten   watchdog: ep93xx_...
61
  static int ep93xx_wdt_ping(struct watchdog_device *wdd)
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
62
  {
917003610   H Hartley Sweeten   watchdog: ep93xx_...
63
64
65
  	struct ep93xx_wdt_priv *priv = watchdog_get_drvdata(wdd);
  
  	writel(0x5555, priv->mmio + EP93XX_WATCHDOG);
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
66

e12a679dd   H Hartley Sweeten   watchdog: Convert...
67
  	return 0;
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
68
  }
e12a679dd   H Hartley Sweeten   watchdog: Convert...
69
70
  static const struct watchdog_info ep93xx_wdt_ident = {
  	.options	= WDIOF_CARDRESET |
917003610   H Hartley Sweeten   watchdog: ep93xx_...
71
  			  WDIOF_SETTIMEOUT |
e12a679dd   H Hartley Sweeten   watchdog: Convert...
72
73
74
  			  WDIOF_MAGICCLOSE |
  			  WDIOF_KEEPALIVEPING,
  	.identity	= "EP93xx Watchdog",
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
75
  };
b893e344b   Bhumika Goyal   watchdog: constif...
76
  static const struct watchdog_ops ep93xx_wdt_ops = {
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
77
  	.owner		= THIS_MODULE,
e12a679dd   H Hartley Sweeten   watchdog: Convert...
78
79
  	.start		= ep93xx_wdt_start,
  	.stop		= ep93xx_wdt_stop,
917003610   H Hartley Sweeten   watchdog: ep93xx_...
80
  	.ping		= ep93xx_wdt_ping,
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
81
  };
2d991a164   Bill Pemberton   watchdog: remove ...
82
  static int ep93xx_wdt_probe(struct platform_device *pdev)
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
83
  {
d6ab05106   Guenter Roeck   watchdog: ep93xx_...
84
  	struct device *dev = &pdev->dev;
917003610   H Hartley Sweeten   watchdog: ep93xx_...
85
86
  	struct ep93xx_wdt_priv *priv;
  	struct watchdog_device *wdd;
3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
87
  	unsigned long val;
917003610   H Hartley Sweeten   watchdog: ep93xx_...
88
  	int ret;
d6ab05106   Guenter Roeck   watchdog: ep93xx_...
89
  	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
917003610   H Hartley Sweeten   watchdog: ep93xx_...
90
91
  	if (!priv)
  		return -ENOMEM;
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
92

0f0a6a285   Guenter Roeck   watchdog: Convert...
93
  	priv->mmio = devm_platform_ioremap_resource(pdev, 0);
917003610   H Hartley Sweeten   watchdog: ep93xx_...
94
95
  	if (IS_ERR(priv->mmio))
  		return PTR_ERR(priv->mmio);
3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
96

917003610   H Hartley Sweeten   watchdog: ep93xx_...
97
  	val = readl(priv->mmio + EP93XX_WATCHDOG);
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
98

917003610   H Hartley Sweeten   watchdog: ep93xx_...
99
100
101
102
103
104
  	wdd = &priv->wdd;
  	wdd->bootstatus = (val & 0x01) ? WDIOF_CARDRESET : 0;
  	wdd->info = &ep93xx_wdt_ident;
  	wdd->ops = &ep93xx_wdt_ops;
  	wdd->min_timeout = 1;
  	wdd->max_hw_heartbeat_ms = 200;
d6ab05106   Guenter Roeck   watchdog: ep93xx_...
105
  	wdd->parent = dev;
e12a679dd   H Hartley Sweeten   watchdog: Convert...
106

917003610   H Hartley Sweeten   watchdog: ep93xx_...
107
  	watchdog_set_nowayout(wdd, nowayout);
697b41e4d   Wim Van Sebroeck   watchdog: ep93xx_...
108

917003610   H Hartley Sweeten   watchdog: ep93xx_...
109
  	wdd->timeout = WDT_TIMEOUT;
d6ab05106   Guenter Roeck   watchdog: ep93xx_...
110
  	watchdog_init_timeout(wdd, timeout, dev);
697b41e4d   Wim Van Sebroeck   watchdog: ep93xx_...
111

917003610   H Hartley Sweeten   watchdog: ep93xx_...
112
  	watchdog_set_drvdata(wdd, priv);
697b41e4d   Wim Van Sebroeck   watchdog: ep93xx_...
113

d6ab05106   Guenter Roeck   watchdog: ep93xx_...
114
  	ret = devm_watchdog_register_device(dev, wdd);
917003610   H Hartley Sweeten   watchdog: ep93xx_...
115
116
  	if (ret)
  		return ret;
e12a679dd   H Hartley Sweeten   watchdog: Convert...
117

d6ab05106   Guenter Roeck   watchdog: ep93xx_...
118
119
120
  	dev_info(dev, "EP93XX watchdog driver %s
  ",
  		 (val & 0x08) ? " (nCS1 disable detected)" : "");
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
121

3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
122
  	return 0;
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
123
  }
3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
124
125
  static struct platform_driver ep93xx_wdt_driver = {
  	.driver		= {
3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
126
127
128
  		.name	= "ep93xx-wdt",
  	},
  	.probe		= ep93xx_wdt_probe,
3e0113a89   H Hartley Sweeten   watchdog: ep93xx:...
129
130
131
  };
  
  module_platform_driver(ep93xx_wdt_driver);
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
132

5f5e19093   Jingoo Han   watchdog: fix che...
133
134
135
  MODULE_AUTHOR("Ray Lehtiniemi <rayl@mail.com>");
  MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
  MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
f52ac8fec   Alessandro Zummo   [PATCH] cirrus ep...
136
137
  MODULE_DESCRIPTION("EP93xx Watchdog");
  MODULE_LICENSE("GPL");