1 // SPDX-License-Identifier: GPL-2.0+
3 * COMEDI driver for the watchdog subdevice found on some addi-data boards
4 * Copyright (c) 2013 H Hartley Sweeten <hsweeten@visionengravers.com>
6 * Based on implementations in various addi-data COMEDI drivers.
8 * COMEDI - Linux Control and Measurement Device Interface
9 * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
12 #include <linux/module.h>
13 #include "../comedidev.h"
15 #include "addi_watchdog.h"
17 struct addi_watchdog_private {
19 unsigned int wdog_ctrl;
23 * The watchdog subdevice is configured with two INSN_CONFIG instructions:
25 * Enable the watchdog and set the reload timeout:
26 * data[0] = INSN_CONFIG_ARM
27 * data[1] = timeout reload value
29 * Disable the watchdog:
30 * data[0] = INSN_CONFIG_DISARM
32 static int addi_watchdog_insn_config(struct comedi_device *dev,
33 struct comedi_subdevice *s,
34 struct comedi_insn *insn,
37 struct addi_watchdog_private *spriv = s->private;
42 spriv->wdog_ctrl = ADDI_TCW_CTRL_ENA;
43 reload = data[1] & s->maxdata;
44 outl(reload, spriv->iobase + ADDI_TCW_RELOAD_REG);
46 /* Time base is 20ms, let the user know the timeout */
47 dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
50 case INSN_CONFIG_DISARM:
57 outl(spriv->wdog_ctrl, spriv->iobase + ADDI_TCW_CTRL_REG);
62 static int addi_watchdog_insn_read(struct comedi_device *dev,
63 struct comedi_subdevice *s,
64 struct comedi_insn *insn,
67 struct addi_watchdog_private *spriv = s->private;
70 for (i = 0; i < insn->n; i++)
71 data[i] = inl(spriv->iobase + ADDI_TCW_STATUS_REG);
76 static int addi_watchdog_insn_write(struct comedi_device *dev,
77 struct comedi_subdevice *s,
78 struct comedi_insn *insn,
81 struct addi_watchdog_private *spriv = s->private;
84 if (spriv->wdog_ctrl == 0) {
85 dev_warn(dev->class_dev, "watchdog is disabled\n");
89 /* "ping" the watchdog */
90 for (i = 0; i < insn->n; i++) {
91 outl(spriv->wdog_ctrl | ADDI_TCW_CTRL_TRIG,
92 spriv->iobase + ADDI_TCW_CTRL_REG);
98 void addi_watchdog_reset(unsigned long iobase)
100 outl(0x0, iobase + ADDI_TCW_CTRL_REG);
101 outl(0x0, iobase + ADDI_TCW_RELOAD_REG);
103 EXPORT_SYMBOL_GPL(addi_watchdog_reset);
105 int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase)
107 struct addi_watchdog_private *spriv;
109 spriv = comedi_alloc_spriv(s, sizeof(*spriv));
113 spriv->iobase = iobase;
115 s->type = COMEDI_SUBD_TIMER;
116 s->subdev_flags = SDF_WRITABLE;
119 s->insn_config = addi_watchdog_insn_config;
120 s->insn_read = addi_watchdog_insn_read;
121 s->insn_write = addi_watchdog_insn_write;
125 EXPORT_SYMBOL_GPL(addi_watchdog_init);
127 static int __init addi_watchdog_module_init(void)
131 module_init(addi_watchdog_module_init);
133 static void __exit addi_watchdog_module_exit(void)
136 module_exit(addi_watchdog_module_exit);
138 MODULE_DESCRIPTION("ADDI-DATA Watchdog subdevice");
139 MODULE_AUTHOR("H Hartley Sweeten <hsweeten@visionengravers.com>");
140 MODULE_LICENSE("GPL");