From e0852f6ac1949f2d2612861ab608a5b1c614150c Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Fri, 1 May 2015 14:58:30 -0700 Subject: [PATCH] staging: comedi: ni_mio_common: simplify ni_m_series_set_pfi_routing() 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../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 4aa45e083604..c1b1d7c95982 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 69e710f19363..e9cabbde0ca1 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.34.1