Commit fc00fbc9 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d5aa6b7c
......@@ -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 <linux/module.h>
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment