staging: comedi: ni_mio_common: tidy up AO trigger selection
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Thu, 14 Apr 2016 16:58:00 +0000 (09:58 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Apr 2016 05:17:28 +0000 (22:17 -0700)
The AO subdevice (*cancel), ni_ao_reset(), always sets the private
data 'ao_trigger_select' to 0. So when a command is started the
'trigsel' value in ni_ao_cmd_set_trigger() will always start as 0.
Remove the unnecessary member from the private data.

The (*do_cmdtest) validates that the cmd->start_src will only be
TRIG_INT or TRIG_EXT. Refactor ni_ao_cmd_set_trigger() and remove
the BUG() which can never occur.

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/ni_mio_common.c
drivers/staging/comedi/drivers/ni_stc.h

index 8c2c4f697587f6d0762f7ee40a77b5db99a34f46..c89bd1fbffeeaf76cc42c395a4501d8e4f4e88cb 100644 (file)
@@ -2967,6 +2967,7 @@ static void ni_ao_cmd_set_trigger(struct comedi_device *dev,
                                  const struct comedi_cmd *cmd)
 {
        struct ni_private *devpriv = dev->private;
+       unsigned int trigsel;
 
        ni_stc_writew(dev, NISTC_RESET_AO_CFG_START, NISTC_RESET_REG);
 
@@ -2980,39 +2981,20 @@ static void ni_ao_cmd_set_trigger(struct comedi_device *dev,
        }
        ni_stc_writew(dev, devpriv->ao_mode1, NISTC_AO_MODE1_REG);
 
-       {
-               unsigned int trigsel = devpriv->ao_trigger_select;
-
-               switch (cmd->start_src) {
-               case TRIG_INT:
-               case TRIG_NOW:
-                       trigsel &= ~(NISTC_AO_TRIG_START1_POLARITY |
-                                    NISTC_AO_TRIG_START1_SEL_MASK);
-                       trigsel |= NISTC_AO_TRIG_START1_EDGE |
-                                  NISTC_AO_TRIG_START1_SYNC;
-                       break;
-               case TRIG_EXT:
-                       trigsel = NISTC_AO_TRIG_START1_SEL(
-                                       CR_CHAN(cmd->start_arg) + 1);
-                       if (cmd->start_arg & CR_INVERT)
-                               /*
-                                * 0=active high, 1=active low.
-                                * see daq-stc 3-24 (p186)
-                                */
-                               trigsel |= NISTC_AO_TRIG_START1_POLARITY;
-                       if (cmd->start_arg & CR_EDGE)
-                               /* 0=edge detection disabled, 1=enabled */
-                               trigsel |= NISTC_AO_TRIG_START1_EDGE;
-                       break;
-               default:
-                       BUG();
-                       break;
-               }
-
-               devpriv->ao_trigger_select = trigsel;
-               ni_stc_writew(dev, devpriv->ao_trigger_select,
-                             NISTC_AO_TRIG_SEL_REG);
+       if (cmd->start_src == TRIG_INT) {
+               trigsel = NISTC_AO_TRIG_START1_EDGE |
+                         NISTC_AO_TRIG_START1_SYNC;
+       } else { /* TRIG_EXT */
+               trigsel = NISTC_AO_TRIG_START1_SEL(CR_CHAN(cmd->start_arg) + 1);
+               /* 0=active high, 1=active low. see daq-stc 3-24 (p186) */
+               if (cmd->start_arg & CR_INVERT)
+                       trigsel |= NISTC_AO_TRIG_START1_POLARITY;
+               /* 0=edge detection disabled, 1=enabled */
+               if (cmd->start_arg & CR_EDGE)
+                       trigsel |= NISTC_AO_TRIG_START1_EDGE;
        }
+       ni_stc_writew(dev, trigsel, NISTC_AO_TRIG_SEL_REG);
+
        /* AO_Delayed_START1 = 0, we do not support delayed start...yet */
 
        /* sync */
@@ -3443,7 +3425,6 @@ static int ni_ao_reset(struct comedi_device *dev, struct comedi_subdevice *s)
                devpriv->ao_mode3 = NISTC_AO_MODE3_LAST_GATE_DISABLE;
        else
                devpriv->ao_mode3 = 0;
-       devpriv->ao_trigger_select = 0;
 
        ni_stc_writew(dev, 0, NISTC_AO_PERSONAL_REG);
        ni_stc_writew(dev, 0, NISTC_AO_CMD1_REG);
index 896bc02354755f2fdd9661ebde2d62e2c7c25f4e..334a2e12fe841033bee2117f81c88fbe18eb7121 100644 (file)
@@ -1001,7 +1001,6 @@ struct ni_private {
        unsigned short ao_mode3;
        unsigned short ao_cmd1;
        unsigned short ao_cmd2;
-       unsigned short ao_trigger_select;
 
        struct ni_gpct_device *counter_dev;
        unsigned short an_trig_etc_reg;
This page took 0.033366 seconds and 5 git commands to generate.