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 <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
0a9752d81a
commit
e0852f6ac1
2 changed files with 10 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue