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

staging: comedi: dt282x: convert 'adbits' boardinfo to 'ai_maxdata'

This member of the boardinfo is the number of bits in the analog input data.
Convert this member into the subdevice 'maxdata', (1 << board->adbits) - 1,
to avoid needing to do the calculation.

Use the subdevice 'maxdata' in the driver instead of using the boardinfo and
use the comedi_offset_munge() helper to convert the two's complement data to
the offset binary form that the comedi core expects.
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 f11c4b6c
...@@ -207,7 +207,7 @@ static const struct comedi_lrange range_dt282x_ai_hi_unipolar = { ...@@ -207,7 +207,7 @@ static const struct comedi_lrange range_dt282x_ai_hi_unipolar = {
struct dt282x_board { struct dt282x_board {
const char *name; const char *name;
int adbits; unsigned int ai_maxdata;
int adchan_se; int adchan_se;
int adchan_di; int adchan_di;
int ai_speed; int ai_speed;
...@@ -219,7 +219,7 @@ struct dt282x_board { ...@@ -219,7 +219,7 @@ struct dt282x_board {
static const struct dt282x_board boardtypes[] = { static const struct dt282x_board boardtypes[] = {
{ {
.name = "dt2821", .name = "dt2821",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 20000, .ai_speed = 20000,
...@@ -227,7 +227,7 @@ static const struct dt282x_board boardtypes[] = { ...@@ -227,7 +227,7 @@ static const struct dt282x_board boardtypes[] = {
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt2821-f", .name = "dt2821-f",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 6500, .ai_speed = 6500,
...@@ -235,7 +235,7 @@ static const struct dt282x_board boardtypes[] = { ...@@ -235,7 +235,7 @@ static const struct dt282x_board boardtypes[] = {
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt2821-g", .name = "dt2821-g",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 4000, .ai_speed = 4000,
...@@ -243,27 +243,27 @@ static const struct dt282x_board boardtypes[] = { ...@@ -243,27 +243,27 @@ static const struct dt282x_board boardtypes[] = {
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt2823", .name = "dt2823",
.adbits = 16, .ai_maxdata = 0xffff,
.adchan_di = 4, .adchan_di = 4,
.ai_speed = 10000, .ai_speed = 10000,
.dachan = 2, .dachan = 2,
.dabits = 16, .dabits = 16,
}, { }, {
.name = "dt2824-pgh", .name = "dt2824-pgh",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 20000, .ai_speed = 20000,
}, { }, {
.name = "dt2824-pgl", .name = "dt2824-pgl",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 20000, .ai_speed = 20000,
.ispgl = 1, .ispgl = 1,
}, { }, {
.name = "dt2825", .name = "dt2825",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 20000, .ai_speed = 20000,
...@@ -272,28 +272,28 @@ static const struct dt282x_board boardtypes[] = { ...@@ -272,28 +272,28 @@ static const struct dt282x_board boardtypes[] = {
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt2827", .name = "dt2827",
.adbits = 16, .ai_maxdata = 0xffff,
.adchan_di = 4, .adchan_di = 4,
.ai_speed = 10000, .ai_speed = 10000,
.dachan = 2, .dachan = 2,
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt2828", .name = "dt2828",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 4, .adchan_se = 4,
.ai_speed = 10000, .ai_speed = 10000,
.dachan = 2, .dachan = 2,
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt2829", .name = "dt2829",
.adbits = 16, .ai_maxdata = 0xffff,
.adchan_se = 8, .adchan_se = 8,
.ai_speed = 33250, .ai_speed = 33250,
.dachan = 2, .dachan = 2,
.dabits = 16, .dabits = 16,
}, { }, {
.name = "dt21-ez", .name = "dt21-ez",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 10000, .ai_speed = 10000,
...@@ -301,19 +301,19 @@ static const struct dt282x_board boardtypes[] = { ...@@ -301,19 +301,19 @@ static const struct dt282x_board boardtypes[] = {
.dabits = 12, .dabits = 12,
}, { }, {
.name = "dt23-ez", .name = "dt23-ez",
.adbits = 16, .ai_maxdata = 0xffff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 10000, .ai_speed = 10000,
}, { }, {
.name = "dt24-ez", .name = "dt24-ez",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 10000, .ai_speed = 10000,
}, { }, {
.name = "dt24-ez-pgl", .name = "dt24-ez-pgl",
.adbits = 12, .ai_maxdata = 0x0fff,
.adchan_se = 16, .adchan_se = 16,
.adchan_di = 8, .adchan_di = 8,
.ai_speed = 10000, .ai_speed = 10000,
...@@ -449,26 +449,26 @@ static int dt282x_ns_to_timer(int *nanosec, int round_mode) ...@@ -449,26 +449,26 @@ static int dt282x_ns_to_timer(int *nanosec, int round_mode)
return (15 << 8) | (255 - divider); return (15 << 8) | (255 - divider);
} }
static void dt282x_munge(struct comedi_device *dev, unsigned short *buf, static void dt282x_munge(struct comedi_device *dev,
struct comedi_subdevice *s,
unsigned short *buf,
unsigned int nbytes) unsigned int nbytes)
{ {
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private; struct dt282x_private *devpriv = dev->private;
unsigned int i; unsigned int val;
unsigned short mask = (1 << board->adbits) - 1; int i;
unsigned short sign = 1 << (board->adbits - 1);
int n;
if (devpriv->ad_2scomp)
sign = 1 << (board->adbits - 1);
else
sign = 0;
if (nbytes % 2) if (nbytes % 2)
comedi_error(dev, "bug! odd number of bytes from dma xfer"); comedi_error(dev, "bug! odd number of bytes from dma xfer");
n = nbytes / 2;
for (i = 0; i < n; i++) for (i = 0; i < nbytes / 2; i++) {
buf[i] = (buf[i] & mask) ^ sign; val = buf[i];
val &= s->maxdata;
if (devpriv->ad_2scomp)
val = comedi_offset_munge(s, val);
buf[i] = val;
}
} }
static void dt282x_ao_dma_interrupt(struct comedi_device *dev) static void dt282x_ao_dma_interrupt(struct comedi_device *dev)
...@@ -527,7 +527,7 @@ static void dt282x_ai_dma_interrupt(struct comedi_device *dev) ...@@ -527,7 +527,7 @@ static void dt282x_ai_dma_interrupt(struct comedi_device *dev)
devpriv->current_dma_index = 1 - i; devpriv->current_dma_index = 1 - i;
dt282x_munge(dev, ptr, size); dt282x_munge(dev, s, ptr, size);
ret = cfc_write_array_to_buffer(s, ptr, size); ret = cfc_write_array_to_buffer(s, ptr, size);
if (ret != size) { if (ret != size) {
s->async->events |= COMEDI_CB_OVERFLOW; s->async->events |= COMEDI_CB_OVERFLOW;
...@@ -597,10 +597,10 @@ static irqreturn_t dt282x_interrupt(int irq, void *d) ...@@ -597,10 +597,10 @@ static irqreturn_t dt282x_interrupt(int irq, void *d)
unsigned short data; unsigned short data;
data = inw(dev->iobase + DT2821_ADDAT); data = inw(dev->iobase + DT2821_ADDAT);
data &= (1 << board->adbits) - 1; data &= s->maxdata;
if (devpriv->ad_2scomp) if (devpriv->ad_2scomp)
data ^= 1 << (board->adbits - 1); data = comedi_offset_munge(s, data);
ret = comedi_buf_put(s, data); ret = comedi_buf_put(s, data);
if (ret == 0) if (ret == 0)
...@@ -671,10 +671,11 @@ static int dt282x_ai_timeout(struct comedi_device *dev, ...@@ -671,10 +671,11 @@ static int dt282x_ai_timeout(struct comedi_device *dev,
*/ */
static int dt282x_ai_insn_read(struct comedi_device *dev, static int dt282x_ai_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn,
unsigned int *data)
{ {
const struct dt282x_board *board = comedi_board(dev);
struct dt282x_private *devpriv = dev->private; struct dt282x_private *devpriv = dev->private;
unsigned int val;
int ret; int ret;
int i; int i;
...@@ -698,11 +699,12 @@ static int dt282x_ai_insn_read(struct comedi_device *dev, ...@@ -698,11 +699,12 @@ static int dt282x_ai_insn_read(struct comedi_device *dev,
if (ret) if (ret)
return ret; return ret;
data[i] = val = inw(dev->iobase + DT2821_ADDAT);
inw(dev->iobase + val &= s->maxdata;
DT2821_ADDAT) & ((1 << board->adbits) - 1);
if (devpriv->ad_2scomp) if (devpriv->ad_2scomp)
data[i] ^= (1 << (board->adbits - 1)); val = comedi_offset_munge(s, val);
data[i] = val;
} }
return i; return i;
...@@ -1260,7 +1262,7 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -1260,7 +1262,7 @@ static int dt282x_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->n_chan = s->n_chan =
(it->options[opt_diff]) ? board->adchan_di : board->adchan_se; (it->options[opt_diff]) ? board->adchan_di : board->adchan_se;
s->insn_read = dt282x_ai_insn_read; s->insn_read = dt282x_ai_insn_read;
s->maxdata = (1 << board->adbits) - 1; s->maxdata = board->ai_maxdata;
s->range_table = s->range_table =
opt_ai_range_lkup(board->ispgl, it->options[opt_ai_range]); opt_ai_range_lkup(board->ispgl, it->options[opt_ai_range]);
devpriv->ad_2scomp = it->options[opt_ai_twos]; devpriv->ad_2scomp = it->options[opt_ai_twos];
......
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