staging: comedi: comedi_test: use unsigned int for waveform timing
[linux-2.6-block.git] / drivers / staging / comedi / drivers / aio_aio12_8.c
index 2262da0d21b4b62aa97269c28d9c2784d079da56..43a0ce5721d3a3e6a8f7cf943848b567b46ed6e4 100644 (file)
@@ -20,7 +20,7 @@
  * Author: Pablo Mejia <pablo.mejia@cctechnol.com>
  * Devices: [Access I/O] PC-104 AIO12-8 (aio_aio12_8),
  *   [Access I/O] PC-104 AI12-8 (aio_ai12_8),
- *   [Access I/O] PC-104 AO12-8 (aio_ao12_8)
+ *   [Access I/O] PC-104 AO12-4 (aio_ao12_4)
  * Status: experimental
  *
  * Configuration Options:
@@ -87,21 +87,21 @@ static const struct comedi_lrange aio_aio12_8_range = {
 
 struct aio12_8_boardtype {
        const char *name;
-       int ai_nchan;
-       int ao_nchan;
+       unsigned int has_ai:1;
+       unsigned int has_ao:1;
 };
 
 static const struct aio12_8_boardtype board_types[] = {
        {
                .name           = "aio_aio12_8",
-               .ai_nchan       = 8,
-               .ao_nchan       = 4,
+               .has_ai         = 1,
+               .has_ao         = 1,
        }, {
                .name           = "aio_ai12_8",
-               .ai_nchan       = 8,
+               .has_ai         = 1,
        }, {
-               .name           = "aio_ao12_8",
-               .ao_nchan       = 4,
+               .name           = "aio_ao12_4",
+               .has_ao         = 1,
        },
 };
 
@@ -120,13 +120,15 @@ static int aio_aio12_8_ai_eoc(struct comedi_device *dev,
 
 static int aio_aio12_8_ai_read(struct comedi_device *dev,
                               struct comedi_subdevice *s,
-                              struct comedi_insn *insn, unsigned int *data)
+                              struct comedi_insn *insn,
+                              unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
        unsigned int range = CR_RANGE(insn->chanspec);
+       unsigned int val;
        unsigned char control;
        int ret;
-       int n;
+       int i;
 
        /*
         * Setup the control byte for internal 2MHz clock, 3uS conversion,
@@ -138,7 +140,7 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev,
        /* Read status to clear EOC latch */
        inb(dev->iobase + AIO12_8_STATUS_REG);
 
-       for (n = 0; n < insn->n; n++) {
+       for (i = 0; i < insn->n; i++) {
                /*  Setup and start conversion */
                outb(control, dev->iobase + AIO12_8_ADC_REG);
 
@@ -147,7 +149,13 @@ static int aio_aio12_8_ai_read(struct comedi_device *dev,
                if (ret)
                        return ret;
 
-               data[n] = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata;
+               val = inw(dev->iobase + AIO12_8_ADC_REG) & s->maxdata;
+
+               /* munge bipolar 2's complement data to offset binary */
+               if (comedi_range_is_bipolar(s, range))
+                       val = comedi_offset_munge(s, val);
+
+               data[i] = val;
        }
 
        return insn->n;
@@ -217,12 +225,12 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
        if (ret)
                return ret;
 
+       /* Analog Input subdevice */
        s = &dev->subdevices[0];
-       if (board->ai_nchan) {
-               /* Analog input subdevice */
+       if (board->has_ai) {
                s->type         = COMEDI_SUBD_AI;
                s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_DIFF;
-               s->n_chan       = board->ai_nchan;
+               s->n_chan       = 8;
                s->maxdata      = 0x0fff;
                s->range_table  = &aio_aio12_8_range;
                s->insn_read    = aio_aio12_8_ai_read;
@@ -230,9 +238,9 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
                s->type = COMEDI_SUBD_UNUSED;
        }
 
+       /* Analog Output subdevice */
        s = &dev->subdevices[1];
-       if (board->ao_nchan) {
-               /* Analog output subdevice */
+       if (board->has_ao) {
                s->type         = COMEDI_SUBD_AO;
                s->subdev_flags = SDF_WRITABLE | SDF_GROUND;
                s->n_chan       = 4;
@@ -247,8 +255,8 @@ static int aio_aio12_8_attach(struct comedi_device *dev,
                s->type = COMEDI_SUBD_UNUSED;
        }
 
+       /* Digital I/O subdevice (8255) */
        s = &dev->subdevices[2];
-       /* 8255 Digital i/o subdevice */
        ret = subdev_8255_init(dev, s, NULL, AIO12_8_8255_BASE_REG);
        if (ret)
                return ret;