staging: comedi: drivers: use comedi_dio_insn_config() for complex cases
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / drivers / dt2801.c
index e0e7beab7274b255c79e079fa94a5e190b2a13f6..38918a1198aa83cfbcc717f69be05c074b9bd7aa 100644 (file)
@@ -551,32 +551,19 @@ static int dt2801_dio_insn_bits(struct comedi_device *dev,
 
 static int dt2801_dio_insn_config(struct comedi_device *dev,
                                  struct comedi_subdevice *s,
-                                 struct comedi_insn *insn, unsigned int *data)
+                                 struct comedi_insn *insn,
+                                 unsigned int *data)
 {
-       int which = 0;
+       int ret;
 
-       if (s == &dev->subdevices[3])
-               which = 1;
+       ret = comedi_dio_insn_config(dev, s, insn, data, 0xff);
+       if (ret)
+               return ret;
 
-       /* configure */
-       switch (data[0]) {
-       case INSN_CONFIG_DIO_OUTPUT:
-               s->io_bits = 0xff;
-               dt2801_writecmd(dev, DT_C_SET_DIGOUT);
-               break;
-       case INSN_CONFIG_DIO_INPUT:
-               s->io_bits = 0;
-               dt2801_writecmd(dev, DT_C_SET_DIGIN);
-               break;
-       case INSN_CONFIG_DIO_QUERY:
-               data[1] = s->io_bits ? COMEDI_OUTPUT : COMEDI_INPUT;
-               return insn->n;
-       default:
-               return -EINVAL;
-       }
-       dt2801_writedata(dev, which);
+       dt2801_writecmd(dev, s->io_bits ? DT_C_SET_DIGOUT : DT_C_SET_DIGIN);
+       dt2801_writedata(dev, (s == &dev->subdevices[3]) ? 1 : 0);
 
-       return 1;
+       return insn->n;
 }
 
 /*