1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <linux/module.h>
22#include "../comedidev.h"
23#include "addi_tcw.h"
24#include "addi_watchdog.h"
25
26struct addi_watchdog_private {
27 unsigned long iobase;
28 unsigned int wdog_ctrl;
29};
30
31
32
33
34
35
36
37
38
39
40
41static int addi_watchdog_insn_config(struct comedi_device *dev,
42 struct comedi_subdevice *s,
43 struct comedi_insn *insn,
44 unsigned int *data)
45{
46 struct addi_watchdog_private *spriv = s->private;
47 unsigned int reload;
48
49 switch (data[0]) {
50 case INSN_CONFIG_ARM:
51 spriv->wdog_ctrl = ADDI_TCW_CTRL_ENA;
52 reload = data[1] & s->maxdata;
53 outl(reload, spriv->iobase + ADDI_TCW_RELOAD_REG);
54
55
56 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
57 20 * reload + 20);
58 break;
59 case INSN_CONFIG_DISARM:
60 spriv->wdog_ctrl = 0;
61 break;
62 default:
63 return -EINVAL;
64 }
65
66 outl(spriv->wdog_ctrl, spriv->iobase + ADDI_TCW_CTRL_REG);
67
68 return insn->n;
69}
70
71static int addi_watchdog_insn_read(struct comedi_device *dev,
72 struct comedi_subdevice *s,
73 struct comedi_insn *insn,
74 unsigned int *data)
75{
76 struct addi_watchdog_private *spriv = s->private;
77 int i;
78
79 for (i = 0; i < insn->n; i++)
80 data[i] = inl(spriv->iobase + ADDI_TCW_STATUS_REG);
81
82 return insn->n;
83}
84
85static int addi_watchdog_insn_write(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn,
88 unsigned int *data)
89{
90 struct addi_watchdog_private *spriv = s->private;
91 int i;
92
93 if (spriv->wdog_ctrl == 0) {
94 dev_warn(dev->class_dev, "watchdog is disabled\n");
95 return -EINVAL;
96 }
97
98
99 for (i = 0; i < insn->n; i++) {
100 outl(spriv->wdog_ctrl | ADDI_TCW_CTRL_TRIG,
101 spriv->iobase + ADDI_TCW_CTRL_REG);
102 }
103
104 return insn->n;
105}
106
107void addi_watchdog_reset(unsigned long iobase)
108{
109 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
110 outl(0x0, iobase + ADDI_TCW_RELOAD_REG);
111}
112EXPORT_SYMBOL_GPL(addi_watchdog_reset);
113
114int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
115{
116 struct addi_watchdog_private *spriv;
117
118 spriv = comedi_alloc_spriv(s, sizeof(*spriv));
119 if (!spriv)
120 return -ENOMEM;
121
122 spriv->iobase = iobase;
123
124 s->type = COMEDI_SUBD_TIMER;
125 s->subdev_flags = SDF_WRITABLE;
126 s->n_chan = 1;
127 s->maxdata = 0xff;
128 s->insn_config = addi_watchdog_insn_config;
129 s->insn_read = addi_watchdog_insn_read;
130 s->insn_write = addi_watchdog_insn_write;
131
132 return 0;
133}
134EXPORT_SYMBOL_GPL(addi_watchdog_init);
135
136static int __init addi_watchdog_module_init(void)
137{
138 return 0;
139}
140module_init(addi_watchdog_module_init);
141
142static void __exit addi_watchdog_module_exit(void)
143{
144}
145module_exit(addi_watchdog_module_exit);
146
147MODULE_DESCRIPTION("ADDI-DATA Watchdog subdevice");
148MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
149MODULE_LICENSE("GPL");
150