]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - drivers/staging/comedi/drivers/skel.c
staging: comedi: comedi_pci: introduce comedi_pci_detach()
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / comedi / drivers / skel.c
index 3bfa221faf4d450e6544b1468eebf9885f5d81c8..869652b36b31cdade490d2edb960a145513ae2a4 100644 (file)
@@ -75,9 +75,6 @@ Configuration Options:
 #include "comedi_fc.h"
 
 /* Imaginary registers for the imaginary board */
-
-#define SKEL_SIZE 0
-
 #define SKEL_START_AI_CONV     0
 #define SKEL_AI_READ           0
 
@@ -117,11 +114,7 @@ static const struct skel_board skel_boards[] = {
    feel free to suggest moving the variable to the struct comedi_device struct.
  */
 struct skel_private {
-
        int data;
-
-       /* Used for AO readback */
-       unsigned int ao_readback[2];
 };
 
 /* This function doesn't require a particular form, this is just
@@ -129,7 +122,7 @@ struct skel_private {
  * convert ns nanoseconds to a counter value suitable for programming
  * the device.  Also, it should adjust ns so that it cooresponds to
  * the actual time that the device will use. */
-static int skel_ns_to_timer(unsigned int *ns, int round)
+static int skel_ns_to_timer(unsigned int *ns, unsigned int flags)
 {
        /* trivial timer */
        /* if your timing is done through two cascaded timers, the
@@ -287,12 +280,12 @@ static int skel_ai_cmdtest(struct comedi_device *dev,
 
        if (cmd->scan_begin_src == TRIG_TIMER) {
                arg = cmd->scan_begin_arg;
-               skel_ns_to_timer(&arg, cmd->flags & TRIG_ROUND_MASK);
+               skel_ns_to_timer(&arg, cmd->flags);
                err |= cfc_check_trigger_arg_is(&cmd->scan_begin_arg, arg);
        }
        if (cmd->convert_src == TRIG_TIMER) {
                arg = cmd->convert_arg;
-               skel_ns_to_timer(&arg, cmd->flags & TRIG_ROUND_MASK);
+               skel_ns_to_timer(&arg, cmd->flags);
                err |= cfc_check_trigger_arg_is(&cmd->convert_arg, arg);
 
                if (cmd->scan_begin_src == TRIG_TIMER) {
@@ -308,38 +301,29 @@ static int skel_ai_cmdtest(struct comedi_device *dev,
        return 0;
 }
 
-static int skel_ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                        struct comedi_insn *insn, unsigned int *data)
+static int skel_ao_insn_write(struct comedi_device *dev,
+                             struct comedi_subdevice *s,
+                             struct comedi_insn *insn,
+                             unsigned int *data)
 {
-       struct skel_private *devpriv = dev->private;
+       unsigned int chan = CR_CHAN(insn->chanspec);
+       unsigned int val = s->readback[chan];
        int i;
-       int chan = CR_CHAN(insn->chanspec);
 
-       /* Writing a list of values to an AO channel is probably not
-        * very useful, but that's how the interface is defined. */
+       /*
+        * Writing a list of values to an AO channel is probably not
+        * very useful, but that's how the interface is defined.
+        */
        for (i = 0; i < insn->n; i++) {
+               val = data[i];
+
                /* a typical programming sequence */
-               /* outw(data[i],dev->iobase + SKEL_DA0 + chan); */
-               devpriv->ao_readback[chan] = data[i];
+               /* outw(data[i], dev->iobase + SKEL_DA0 + chan); */
        }
+       /* save the last value for readback */
+       s->readback[chan] = val;
 
-       /* return the number of samples read/written */
-       return i;
-}
-
-/* AO subdevices should have a read insn as well as a write insn.
- * Usually this means copying a value stored in devpriv. */
-static int skel_ao_rinsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                        struct comedi_insn *insn, unsigned int *data)
-{
-       struct skel_private *devpriv = dev->private;
-       int i;
-       int chan = CR_CHAN(insn->chanspec);
-
-       for (i = 0; i < insn->n; i++)
-               data[i] = devpriv->ao_readback[chan];
-
-       return i;
+       return insn->n;
 }
 
 /*
@@ -449,8 +433,25 @@ static int skel_common_attach(struct comedi_device *dev)
        s->n_chan = 1;
        s->maxdata = 0xffff;
        s->range_table = &range_bipolar5;
-       s->insn_write = skel_ao_winsn;
-       s->insn_read = skel_ao_rinsn;
+       s->insn_write = skel_ao_insn_write;
+       /*
+        * AO subdevices should have a (*insn_read) as well. Usually the
+        * hardware is not readable so the channel values need to be stored
+        * somewhere for readback. The comedi_subdevice has a 'readback'
+        * member to handle this.
+        *
+        * The comedi_readback_insn_read() function provides the (*insn_read)
+        * to return the 'readback' values.
+        *
+        * The comedi_alloc_subdev_readback() function will allocate memory
+        * for s->n_chan 'readback' values. The core will kfree the memory
+        * when the driver is detached.
+        */
+       s->insn_read = comedi_readback_insn_read;
+
+       ret = comedi_alloc_subdev_readback(s);
+       if (ret)
+               return ret;
 
        s = &dev->subdevices[2];
        /* digital i/o subdevice */
@@ -639,7 +640,7 @@ static void skel_detach(struct comedi_device *dev)
                 * If PCI device enabled by _auto_attach() (or _attach()),
                 * disable it here.
                 */
-               comedi_pci_disable(dev);
+               comedi_pci_detach(dev);
        } else {
                /*
                 * ISA board