[PATCH 005/107] staging: comedi: ni_mio_common: simplify ni_m_series_set_pfi_routing()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman >gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/ni_mio_common.c | 20 +++++++++-----------
 drivers/staging/comedi/drivers/ni_stc.h        |  7 +------
 2 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/comedi/drivers/ni_mio_common.c b/drivers/staging/comedi/drivers/ni_mio_common.c
index 4aa45e0..c1b1d7c 100644
--- a/drivers/staging/comedi/drivers/ni_mio_common.c
+++ b/drivers/staging/comedi/drivers/ni_mio_common.c
@@ -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;
diff --git a/drivers/staging/comedi/drivers/ni_stc.h b/drivers/staging/comedi/drivers/ni_stc.h
index 69e710f..e9cabbd 100644
--- a/drivers/staging/comedi/drivers/ni_stc.h
+++ b/drivers/staging/comedi/drivers/ni_stc.h
@@ -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 {
-- 
2.3.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux