Clarify the timer operations by using the helper functions in 8253.h.

For aesthetics, factor the "ai start conversion" code out of daq700_ai_rinsn().

Signed-off-by: H Hartley Sweeten <hswee...@visionengravers.com>
Cc: Ian Abbott <abbo...@mev.co.uk>
Cc: Greg Kroah-Hartman <gr...@linuxfoundation.org>
---
 drivers/staging/comedi/drivers/ni_daq_700.c | 35 ++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_daq_700.c 
b/drivers/staging/comedi/drivers/ni_daq_700.c
index 4d5cb5a..16b52b6 100644
--- a/drivers/staging/comedi/drivers/ni_daq_700.c
+++ b/drivers/staging/comedi/drivers/ni_daq_700.c
@@ -51,11 +51,18 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 
-#include "../comedidev.h"
-
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 
+#include "../comedidev.h"
+
+#include "8253.h"
+
+/*
+ * Regsiter I/O map
+ */
+#define DAQ700_TIMER_BASE              0x08
+
 /* daqcard700 registers */
 #define DIO_W          0x04    /* WO 8bit */
 #define DIO_R          0x05    /* RO 8bit */
@@ -66,10 +73,6 @@
 #define STA_R2         0x01    /* RO 8bit */
 #define ADFIFO_R       0x02    /* RO 16bit */
 #define ADCLEAR_R      0x01    /* WO 8bit */
-#define CDA_R0         0x08    /* RW 8bit */
-#define CDA_R1         0x09    /* RW 8bit */
-#define CDA_R2         0x0A    /* RW 8bit */
-#define CMO_R          0x0B    /* RO 8bit */
 #define TIC_R          0x06    /* WO 8bit */
 /* daqcard700 modes */
 #define CMD_R3_DIFF     0x04    /* diff mode */
@@ -122,6 +125,18 @@ static int daq700_dio_insn_config(struct comedi_device 
*dev,
        return insn->n;
 }
 
+static void daq700_ai_start_conv(struct comedi_device *dev)
+{
+       /*
+        * Manually trigger an A/D conversion with a low-to-high
+        * transition of OUT0.
+        */
+       i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
+                      0, I8254_MODE0 | I8254_BINARY);  /* OUT0 low */
+       i8254_set_mode(dev->iobase + DAQ700_TIMER_BASE, 0,
+                      0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
+}
+
 static int daq700_ai_eoc(struct comedi_device *dev,
                         struct comedi_subdevice *s,
                         struct comedi_insn *insn,
@@ -168,10 +183,7 @@ static int daq700_ai_rinsn(struct comedi_device *dev,
 
        /* convert n samples */
        for (n = 0; n < insn->n; n++) {
-               /* trigger conversion with out0 L to H */
-               outb(0x30, dev->iobase + CMO_R); /* mode 0 out0 L, from H */
-               /* mode 1 out0 H, L to H, start conversion */
-               outb(0x32, dev->iobase + CMO_R);
+               daq700_ai_start_conv(dev);
 
                /* wait for conversion to end */
                ret = comedi_timeout(dev, s, insn, daq700_ai_eoc, 0);
@@ -208,7 +220,8 @@ static void daq700_ai_config(struct comedi_device *dev,
        outb(0x80, iobase + CMD_R1);    /* disable scanning, ADC to chan 0 */
        outb(0x00, iobase + CMD_R2);    /* clear all bits */
        outb(0x00, iobase + CMD_R3);    /* set +-10 range */
-       outb(0x32, iobase + CMO_R);     /* config counter mode1, out0 to H */
+       i8254_set_mode(iobase + DAQ700_TIMER_BASE, 0,
+                      0, I8254_MODE1 | I8254_BINARY);  /* OUT0 high */
        outb(0x00, iobase + TIC_R);     /* clear counter interrupt */
        outb(0x00, iobase + ADCLEAR_R); /* clear the ADC FIFO */
        inw(iobase + ADFIFO_R);         /* read 16bit junk from FIFO to clear */
-- 
1.9.3

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

Reply via email to