Commit 158b6497 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: addi_apci_1516: fix i_APCI1516_ConfigWatchdog()

This function is used by the watchdog subdevice to enable/disable and
set the timeout for the watchdog. Rename the CamelCase function to
apci1516_wdog_insn_config.

Currently this function does not follow the comed API. Recode it so
it works like the core expects. data[0] is the configuration id code
(INSN_CONFIG_*) for the configuration instruction. Two instructions
are supported:

INSN_CONFIG_ARM: enables the watchdog and sets the timeout value
INSN_CONFIG_DISARM: disables the watchdog
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 9151b01f
...@@ -49,8 +49,7 @@ ...@@ -49,8 +49,7 @@
* PCI bar 2 I/O Register map * PCI bar 2 I/O Register map
*/ */
#define APCI1516_WDOG_REG 0x00 #define APCI1516_WDOG_REG 0x00
#define APCI1516_WDOG_RELOAD_LSB_REG 0x04 #define APCI1516_WDOG_RELOAD_REG 0x04
#define APCI1516_WDOG_RELOAD_MSB_REG 0x06
#define APCI1516_WDOG_CTRL_REG 0x0c #define APCI1516_WDOG_CTRL_REG 0x0c
#define APCI1516_WDOG_CTRL_ENABLE (1 << 0) #define APCI1516_WDOG_CTRL_ENABLE (1 << 0)
#define APCI1516_WDOG_CTRL_SOFT_TRIG (1 << 9) #define APCI1516_WDOG_CTRL_SOFT_TRIG (1 << 9)
...@@ -85,6 +84,7 @@ static const struct apci1516_boardinfo apci1516_boardtypes[] = { ...@@ -85,6 +84,7 @@ static const struct apci1516_boardinfo apci1516_boardtypes[] = {
struct apci1516_private { struct apci1516_private {
unsigned long wdog_iobase; unsigned long wdog_iobase;
unsigned int ctrl;
}; };
static int apci1516_di_insn_bits(struct comedi_device *dev, static int apci1516_di_insn_bits(struct comedi_device *dev,
...@@ -118,27 +118,42 @@ static int apci1516_do_insn_bits(struct comedi_device *dev, ...@@ -118,27 +118,42 @@ static int apci1516_do_insn_bits(struct comedi_device *dev,
return insn->n; return insn->n;
} }
static int i_APCI1516_ConfigWatchdog(struct comedi_device *dev, /*
* The watchdog subdevice is configured with two INSN_CONFIG instructions:
*
* Enable the watchdog and set the reload timeout:
* data[0] = INSN_CONFIG_ARM
* data[1] = timeout reload value
*
* Disable the watchdog:
* data[0] = INSN_CONFIG_DISARM
*/
static int apci1516_wdog_insn_config(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
{ {
struct apci1516_private *devpriv = dev->private; struct apci1516_private *devpriv = dev->private;
unsigned int reload;
if (data[0] == 0) { switch (data[0]) {
/* Disable the watchdog */ case INSN_CONFIG_ARM:
outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG); devpriv->ctrl = APCI1516_WDOG_CTRL_ENABLE;
/* Loading the Reload value */ reload = data[1] & s->maxdata;
outw(data[1], devpriv->wdog_iobase + outw(reload, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG);
APCI1516_WDOG_RELOAD_LSB_REG);
data[1] = data[1] >> 16; /* Time base is 20ms, let the user know the timeout */
outw(data[1], devpriv->wdog_iobase + dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
APCI1516_WDOG_RELOAD_MSB_REG); 20 * reload + 20);
} /* if(data[0]==0) */ break;
else { case INSN_CONFIG_DISARM:
printk("\nThe input parameters are wrong\n"); devpriv->ctrl = 0;
break;
default:
return -EINVAL; return -EINVAL;
} /* elseif(data[0]==0) */ }
outw(devpriv->ctrl, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG);
return insn->n; return insn->n;
} }
...@@ -193,8 +208,7 @@ static int apci1516_reset(struct comedi_device *dev) ...@@ -193,8 +208,7 @@ static int apci1516_reset(struct comedi_device *dev)
outw(0x0, dev->iobase + APCI1516_DO_REG); outw(0x0, dev->iobase + APCI1516_DO_REG);
outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG); outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG);
outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_LSB_REG); outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG);
outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_MSB_REG);
return 0; return 0;
} }
...@@ -275,11 +289,10 @@ static int __devinit apci1516_auto_attach(struct comedi_device *dev, ...@@ -275,11 +289,10 @@ static int __devinit apci1516_auto_attach(struct comedi_device *dev,
s->type = COMEDI_SUBD_TIMER; s->type = COMEDI_SUBD_TIMER;
s->subdev_flags = SDF_WRITEABLE; s->subdev_flags = SDF_WRITEABLE;
s->n_chan = 1; s->n_chan = 1;
s->maxdata = 0; s->maxdata = 0xff;
s->range_table = &range_digital;
s->insn_write = i_APCI1516_StartStopWriteWatchdog; s->insn_write = i_APCI1516_StartStopWriteWatchdog;
s->insn_read = apci1516_wdog_insn_read; s->insn_read = apci1516_wdog_insn_read;
s->insn_config = i_APCI1516_ConfigWatchdog; s->insn_config = apci1516_wdog_insn_config;
} else { } else {
s->type = COMEDI_SUBD_UNUSED; s->type = COMEDI_SUBD_UNUSED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment