]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
staging: comedi: das08: use comedi_subdevice 'readback'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Mon, 25 Aug 2014 23:04:37 +0000 (16:04 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Aug 2014 20:22:33 +0000 (13:22 -0700)
Use the new comedi_subdevice 'readback' member and the core provided
(*insn_read) for the readback of the analog output subdevice channels.

The das08_ao_initialize() function is only called when the subdevice
is first setup during the attach. It is used to initialize the channels
to a known state. Absorb that function to simplify the code a bit.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/das08.c
drivers/staging/comedi/drivers/das08.h

index 9a5a06b79a615f93ad5daa57156139ed380e91fe..f761a5aae75e94a3759f5486478d21e7ade125b1 100644 (file)
@@ -338,7 +338,6 @@ static void das08_ao_set_data(struct comedi_device *dev,
                              unsigned int chan, unsigned int data)
 {
        const struct das08_board_struct *thisboard = comedi_board(dev);
-       struct das08_private_struct *devpriv = dev->private;
        unsigned char lsb;
        unsigned char msb;
 
@@ -355,18 +354,6 @@ static void das08_ao_set_data(struct comedi_device *dev,
                /* load DACs */
                inb(dev->iobase + DAS08AO_AO_UPDATE);
        }
-       devpriv->ao_readback[chan] = data;
-}
-
-static void das08_ao_initialize(struct comedi_device *dev,
-                               struct comedi_subdevice *s)
-{
-       int n;
-       unsigned int data;
-
-       data = s->maxdata / 2;  /* should be about 0 volts */
-       for (n = 0; n < s->n_chan; n++)
-               das08_ao_set_data(dev, n, data);
 }
 
 static int das08_ao_insn_write(struct comedi_device *dev,
@@ -375,30 +362,18 @@ static int das08_ao_insn_write(struct comedi_device *dev,
                               unsigned int *data)
 {
        unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val = s->readback[chan];
        int i;
 
-       for (i = 0; i < insn->n; i++)
-               das08_ao_set_data(dev, chan, data[i]);
+       for (i = 0; i < insn->n; i++) {
+               val = data[i];
+               das08_ao_set_data(dev, chan, val);
+       }
+       s->readback[chan] = val;
 
        return insn->n;
 }
 
-static int das08_ao_rinsn(struct comedi_device *dev,
-                         struct comedi_subdevice *s,
-                         struct comedi_insn *insn, unsigned int *data)
-{
-       struct das08_private_struct *devpriv = dev->private;
-       unsigned int n;
-       unsigned int chan;
-
-       chan = CR_CHAN(insn->chanspec);
-
-       for (n = 0; n < insn->n; n++)
-               data[n] = devpriv->ao_readback[chan];
-
-       return n;
-}
-
 static void i8254_initialize(struct comedi_device *dev)
 {
        const struct das08_board_struct *thisboard = comedi_board(dev);
@@ -461,6 +436,7 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
        struct das08_private_struct *devpriv = dev->private;
        struct comedi_subdevice *s;
        int ret;
+       int i;
 
        dev->iobase = iobase;
 
@@ -498,8 +474,17 @@ int das08_common_attach(struct comedi_device *dev, unsigned long iobase)
                s->maxdata = (1 << thisboard->ao_nbits) - 1;
                s->range_table = &range_bipolar5;
                s->insn_write = das08_ao_insn_write;
-               s->insn_read = das08_ao_rinsn;
-               das08_ao_initialize(dev, s);
+               s->insn_read = comedi_readback_insn_read;
+
+               ret = comedi_alloc_subdev_readback(s);
+               if (ret)
+                       return ret;
+
+               /* intialize all channels to 0V */
+               for (i = 0; i < s->n_chan; i++) {
+                       s->readback[i] = s->maxdata / 2;
+                       das08_ao_set_data(dev, i, s->readback[i]);
+               }
        } else {
                s->type = COMEDI_SUBD_UNUSED;
        }
index 18cc170facd066eefd12464ad2ec496d882fdcf2..f86167da589514cd3bb4530d472afd89928e383c 100644 (file)
@@ -44,7 +44,6 @@ struct das08_private_struct {
                                         *  without separate do register
                                         */
        const unsigned int *pg_gainlist;
-       unsigned int ao_readback[2];    /* assume 2 AO channels */
 };
 
 int das08_common_attach(struct comedi_device *dev, unsigned long iobase);