[PATCH 35/41] staging: comedi: addi_apci_1516: fix i_APCI1516_ConfigWatchdog()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/addi_apci_1516.c | 55 +++++++++++++++----------
 1 file changed, 34 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/comedi/drivers/addi_apci_1516.c b/drivers/staging/comedi/drivers/addi_apci_1516.c
index 49b2f5c..856bb19 100644
--- a/drivers/staging/comedi/drivers/addi_apci_1516.c
+++ b/drivers/staging/comedi/drivers/addi_apci_1516.c
@@ -49,8 +49,7 @@
  * PCI bar 2 I/O Register map
  */
 #define APCI1516_WDOG_REG			0x00
-#define APCI1516_WDOG_RELOAD_LSB_REG		0x04
-#define APCI1516_WDOG_RELOAD_MSB_REG		0x06
+#define APCI1516_WDOG_RELOAD_REG		0x04
 #define APCI1516_WDOG_CTRL_REG			0x0c
 #define APCI1516_WDOG_CTRL_ENABLE		(1 << 0)
 #define APCI1516_WDOG_CTRL_SOFT_TRIG		(1 << 9)
@@ -85,6 +84,7 @@ static const struct apci1516_boardinfo apci1516_boardtypes[] = {
 
 struct apci1516_private {
 	unsigned long wdog_iobase;
+	unsigned int ctrl;
 };
 
 static int apci1516_di_insn_bits(struct comedi_device *dev,
@@ -118,27 +118,42 @@ static int apci1516_do_insn_bits(struct comedi_device *dev,
 	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_insn *insn,
 				     unsigned int *data)
 {
 	struct apci1516_private *devpriv = dev->private;
+	unsigned int reload;
 
-	if (data[0] == 0) {
-		/* Disable the watchdog */
-		outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG);
-		/* Loading the Reload value */
-		outw(data[1], devpriv->wdog_iobase +
-				APCI1516_WDOG_RELOAD_LSB_REG);
-		data[1] = data[1] >> 16;
-		outw(data[1], devpriv->wdog_iobase +
-				APCI1516_WDOG_RELOAD_MSB_REG);
-	}			/* if(data[0]==0) */
-	else {
-		printk("\nThe input parameters are wrong\n");
+	switch (data[0]) {
+	case INSN_CONFIG_ARM:
+		devpriv->ctrl = APCI1516_WDOG_CTRL_ENABLE;
+		reload = data[1] & s->maxdata;
+		outw(reload, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG);
+
+		/* Time base is 20ms, let the user know the timeout */
+		dev_info(dev->class_dev, "watchdog enabled, timeout:%dms\n",
+			20 * reload + 20);
+		break;
+	case INSN_CONFIG_DISARM:
+		devpriv->ctrl = 0;
+		break;
+	default:
 		return -EINVAL;
-	}			/* elseif(data[0]==0) */
+	}
+
+	outw(devpriv->ctrl, devpriv->wdog_iobase + APCI1516_WDOG_CTRL_REG);
 
 	return insn->n;
 }
@@ -193,8 +208,7 @@ static int apci1516_reset(struct comedi_device *dev)
 
 	outw(0x0, dev->iobase + APCI1516_DO_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_MSB_REG);
+	outw(0x0, devpriv->wdog_iobase + APCI1516_WDOG_RELOAD_REG);
 
 	return 0;
 }
@@ -275,11 +289,10 @@ static int __devinit apci1516_auto_attach(struct comedi_device *dev,
 		s->type		= COMEDI_SUBD_TIMER;
 		s->subdev_flags	= SDF_WRITEABLE;
 		s->n_chan	= 1;
-		s->maxdata	= 0;
-		s->range_table	= &range_digital;
+		s->maxdata	= 0xff;
 		s->insn_write	= i_APCI1516_StartStopWriteWatchdog;
 		s->insn_read	= apci1516_wdog_insn_read;
-		s->insn_config	= i_APCI1516_ConfigWatchdog;
+		s->insn_config	= apci1516_wdog_insn_config;
 	} else {
 		s->type		= COMEDI_SUBD_UNUSED;
 	}
-- 
1.7.11

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel


[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux