staging: comedi: ni_mio_common: simplify ni_m_series_set_pfi_routing()
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 1 May 2015 21:58:30 +0000 (14:58 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 9 May 2015 17:05:03 +0000 (19:05 +0200)
This function is overly complex due to the M_Offset_PFI_Output_Select()
helper using a 1 based index for the registers and the private data using
a 0 based index for the cached values.

Modify the M_Offset_PFI_Output_Select() helper to use a 0 based index and
remove the sanity check which can never happen. The 'n' value passed is
calculated from the subdevice channel which will always be in range.

Tidy up the function by using a local variable to mask/set the pfi output
select bits.

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 4aa45e0836049084add2d2e1a662c262b156bee6..c1b1d7c95982f967da7cfe631eccc3e0fefe0e79 100644 (file)
@@ -4391,19 +4391,17 @@ static int ni_m_series_set_pfi_routing(struct comedi_device *dev,
                                       unsigned chan, unsigned source)
 {
        struct ni_private *devpriv = dev->private;
-       unsigned pfi_reg_index;
-       unsigned array_offset;
+       unsigned index = chan / 3;
+       unsigned short val = devpriv->pfi_output_select_reg[index];
 
        if ((source & 0x1f) != source)
                return -EINVAL;
-       pfi_reg_index = 1 + chan / 3;
-       array_offset = pfi_reg_index - 1;
-       devpriv->pfi_output_select_reg[array_offset] &=
-           ~MSeries_PFI_Output_Select_Mask(chan);
-       devpriv->pfi_output_select_reg[array_offset] |=
-           MSeries_PFI_Output_Select_Bits(chan, source);
-       ni_writew(dev, devpriv->pfi_output_select_reg[array_offset],
-                 M_Offset_PFI_Output_Select(pfi_reg_index));
+
+       val &= ~MSeries_PFI_Output_Select_Mask(chan);
+       val |= MSeries_PFI_Output_Select_Bits(chan, source);
+       ni_writew(dev, val, M_Offset_PFI_Output_Select(index));
+       devpriv->pfi_output_select_reg[index] = val;
+
        return 2;
 }
 
@@ -5409,7 +5407,7 @@ static int ni_E_init(struct comedi_device *dev,
                ni_writew(dev, s->state, M_Offset_PFI_DO);
                for (i = 0; i < NUM_PFI_OUTPUT_SELECT_REGS; ++i) {
                        ni_writew(dev, devpriv->pfi_output_select_reg[i],
-                                 M_Offset_PFI_Output_Select(i + 1));
+                                 M_Offset_PFI_Output_Select(i));
                }
        } else {
                s->n_chan       = 10;
index 69e710f19363a19e232b14425d1fe3ad419bf8c1..e9cabbde0ca1f8d511d86c3c323c2d612964eddc 100644 (file)
@@ -1021,12 +1021,7 @@ static inline int M_Offset_AO_Reference_Attenuation(int channel)
 
 static inline unsigned M_Offset_PFI_Output_Select(unsigned n)
 {
-       if (n < 1 || n > NUM_PFI_OUTPUT_SELECT_REGS) {
-               pr_err("%s: invalid pfi output select register=%i\n",
-                      __func__, n);
-               return M_Offset_PFI_Output_Select_1;
-       }
-       return M_Offset_PFI_Output_Select_1 + (n - 1) * 2;
+       return M_Offset_PFI_Output_Select_1 + (n * 2);
 }
 
 enum MSeries_AI_Config_FIFO_Data_Bits {
This page took 0.028624 seconds and 5 git commands to generate.