2 * COMEDI driver for the watchdog subdevice found on some addi-data boards
3 * Copyright (c) 2013 H Hartley Sweeten <hsweeten@visionengravers.com>
5 * Based on implementations in various addi-data COMEDI drivers.
7 * COMEDI - Linux Control and Measurement Device Interface
8 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include <linux/module.h>
22 #include "../comedidev.h"
24 #include "addi_watchdog.h"
26 struct addi_watchdog_private {
28 unsigned int wdog_ctrl;
32 * The watchdog subdevice is configured with two INSN_CONFIG instructions:
34 * Enable the watchdog and set the reload timeout:
35 * data[0] = INSN_CONFIG_ARM
36 * data[1] = timeout reload value
38 * Disable the watchdog:
39 * data[0] = INSN_CONFIG_DISARM
41 static int addi_watchdog_insn_config(struct comedi_device *dev,
42 struct comedi_subdevice *s,
43 struct comedi_insn *insn,
46 struct addi_watchdog_private *spriv = s->private;
51 spriv->wdog_ctrl = ADDI_TCW_CTRL_ENA;
52 reload = data[1] & s->maxdata;
53 outl(reload, spriv->iobase + ADDI_TCW_RELOAD_REG);
55 /* Time base is 20ms, let the user know the timeout */
56 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
59 case INSN_CONFIG_DISARM:
66 outl(spriv->wdog_ctrl, spriv->iobase + ADDI_TCW_CTRL_REG);
71 static int addi_watchdog_insn_read(struct comedi_device *dev,
72 struct comedi_subdevice *s,
73 struct comedi_insn *insn,
76 struct addi_watchdog_private *spriv = s->private;
79 for (i = 0; i < insn->n; i++)
80 data[i] = inl(spriv->iobase + ADDI_TCW_STATUS_REG);
85 static int addi_watchdog_insn_write(struct comedi_device *dev,
86 struct comedi_subdevice *s,
87 struct comedi_insn *insn,
90 struct addi_watchdog_private *spriv = s->private;
93 if (spriv->wdog_ctrl == 0) {
94 dev_warn(dev->class_dev, "watchdog is disabled\n");
98 /* "ping" the watchdog */
99 for (i = 0; i < insn->n; i++) {
100 outl(spriv->wdog_ctrl | ADDI_TCW_CTRL_TRIG,
101 spriv->iobase + ADDI_TCW_CTRL_REG);
107 void addi_watchdog_reset(unsigned long iobase)
109 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
110 outl(0x0, iobase + ADDI_TCW_RELOAD_REG);
112 EXPORT_SYMBOL_GPL(addi_watchdog_reset);
114 int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
116 struct addi_watchdog_private *spriv;
118 spriv = comedi_alloc_spriv(s, sizeof(*spriv));
122 spriv->iobase = iobase;
124 s->type = COMEDI_SUBD_TIMER;
125 s->subdev_flags = SDF_WRITABLE;
128 s->insn_config = addi_watchdog_insn_config;
129 s->insn_read = addi_watchdog_insn_read;
130 s->insn_write = addi_watchdog_insn_write;
134 EXPORT_SYMBOL_GPL(addi_watchdog_init);
136 static int __init addi_watchdog_module_init(void)
140 module_init(addi_watchdog_module_init);
142 static void __exit addi_watchdog_module_exit(void)
145 module_exit(addi_watchdog_module_exit);
147 MODULE_DESCRIPTION("ADDI-DATA Watchdog subdevice");
148 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
149 MODULE_LICENSE("GPL");