From: H Hartley Sweeten Date: Fri, 20 Jun 2014 20:12:56 +0000 (-0700) Subject: staging: comedi: dt282x: cleanup analog output range table X-Git-Tag: firefly_0821_release~176^2~3491^2~1529 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fc00fbc990871a17e0e0f31acc0876f83165cf53;p=firefly-linux-kernel-4.4.55.git staging: comedi: dt282x: cleanup analog output range table The DT2821 series boards do not have programmable analog output ranges. The range is set, per-channel, with jumpers on the board. Currently the user has to pass some configuration options when attaching to the driver in order to set the range for each channel. If they do not pass the range options they will default to 0. If they pass an invalid range option they will also default to 0. The 0 range option is bipolar 10V. If the user passes a range option that does not match the hardware setting it doesn't cause any problems in the driver it just causes the user space comedilib library to incorrectly convert the hardware values to physical values. Make the attach a bit simpler by deprecating these options and providing a range table with all the valid ranges for the analog outputs. The user can then select the correct range when they use the comedilib functions. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/staging/comedi/drivers/dt282x.c b/drivers/staging/comedi/drivers/dt282x.c index 66f15aa55b7e..6c799f0a5ffc 100644 --- a/drivers/staging/comedi/drivers/dt282x.c +++ b/drivers/staging/comedi/drivers/dt282x.c @@ -39,16 +39,18 @@ Configuration options: [6] - AO 0 jumpered for 0=straight binary, 1=2's complement [7] - AO 1 jumpered for 0=straight binary, 1=2's complement [8] - AI jumpered for 0=[-10,10]V, 1=[0,10], 2=[-5,5], 3=[0,5] - [9] - AO 0 jumpered for 0=[-10,10]V, 1=[0,10], 2=[-5,5], 3=[0,5], - 4=[-2.5,2.5] - [10]- A0 1 jumpered for 0=[-10,10]V, 1=[0,10], 2=[-5,5], 3=[0,5], - 4=[-2.5,2.5] + [9] - AO channel 0 range (deprecated, see below) + [10]- AO channel 1 range (deprecated, see below) Notes: - AO commands might be broken. - If you try to run a command on both the AI and AO subdevices simultaneously, bad things will happen. The driver needs to be fixed to check for this situation and return an error. + - AO range is not programmable. The AO subdevice has a range_table + containing all the possible analog output ranges. Use the range + that matches your board configuration to convert between data + values and physical units. */ #include @@ -183,6 +185,21 @@ static const struct comedi_lrange range_dt282x_ai_hi_unipolar = { } }; +/* + * The Analog Output range is set per-channel using jumpers on the board. + * All of these ranges may not be available on some DT2821 series boards. + * The default jumper setting has both channels set for +/-10V output. + */ +static const struct comedi_lrange dt282x_ao_range = { + 5, { + BIP_RANGE(10), + BIP_RANGE(5), + BIP_RANGE(2.5), + UNI_RANGE(10), + UNI_RANGE(5), + } +}; + struct dt282x_board { const char *name; unsigned int ai_maxdata; @@ -304,8 +321,6 @@ struct dt282x_private { unsigned int da0_2scomp:1; unsigned int da1_2scomp:1; - const struct comedi_lrange *darangelist[2]; - unsigned short ao_readback[2]; int dacsr; /* software copies of registers */ @@ -1064,21 +1079,6 @@ static const struct comedi_lrange *opt_ai_range_lkup(int ispgl, int x) } } -static const struct comedi_lrange *const ao_range_table[] = { - &range_bipolar10, - &range_unipolar10, - &range_bipolar5, - &range_unipolar5, - &range_bipolar2_5 -}; - -static const struct comedi_lrange *opt_ao_range_lkup(int x) -{ - if (x < 0 || x >= 5) - x = 0; - return ao_range_table[x]; -} - static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2) { struct dt282x_private *devpriv = dev->private; @@ -1246,9 +1246,7 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it) s->maxdata = board->ao_maxdata; /* ranges are per-channel, set by jumpers on the board */ - s->range_table_list = devpriv->darangelist; - devpriv->darangelist[0] = opt_ao_range_lkup(it->options[9]); - devpriv->darangelist[1] = opt_ao_range_lkup(it->options[10]); + s->range_table = &dt282x_ao_range; devpriv->da0_2scomp = it->options[6] ? 1 : 0; devpriv->da1_2scomp = it->options[7] ? 1 : 0;