staging: comedi: rtd520: sample types are unsigned

Sample values in comedi are generally represented as unsigned values.
Use unsigned types for sample value manipulations in the "rtd520" driver
for consistency.

Also replace the hand-coded munging of 2's complement sample values with
calls to `comedi_offset_munge()` and AND with `s->maxdata` to strip off
any extra sign bits.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Ian Abbott 2013-10-16 14:40:35 +01:00 committed by Greg Kroah-Hartman
parent 8bab0d680e
commit 055a1e2c56
1 changed files with 13 additions and 18 deletions

View File

@ -602,7 +602,7 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
/* convert n samples */ /* convert n samples */
for (n = 0; n < insn->n; n++) { for (n = 0; n < insn->n; n++) {
s16 d; unsigned short d;
/* trigger conversion */ /* trigger conversion */
writew(0, devpriv->las0 + LAS0_ADC); writew(0, devpriv->las0 + LAS0_ADC);
@ -621,9 +621,8 @@ static int rtd_ai_rinsn(struct comedi_device *dev,
d = d >> 3; /* low 3 bits are marker lines */ d = d >> 3; /* low 3 bits are marker lines */
if (CHAN_ARRAY_TEST(devpriv->chan_is_bipolar, 0)) if (CHAN_ARRAY_TEST(devpriv->chan_is_bipolar, 0))
/* convert to comedi unsigned data */ /* convert to comedi unsigned data */
data[n] = d + 2048; d = comedi_offset_munge(s, d);
else data[n] = d & s->maxdata;
data[n] = d;
} }
/* return the number of samples read/written */ /* return the number of samples read/written */
@ -643,8 +642,7 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
int ii; int ii;
for (ii = 0; ii < count; ii++) { for (ii = 0; ii < count; ii++) {
short sample; unsigned short d;
s16 d;
if (0 == devpriv->ai_count) { /* done */ if (0 == devpriv->ai_count) { /* done */
d = readw(devpriv->las1 + LAS1_ADC_FIFO); d = readw(devpriv->las1 + LAS1_ADC_FIFO);
@ -654,13 +652,12 @@ static int ai_read_n(struct comedi_device *dev, struct comedi_subdevice *s,
d = readw(devpriv->las1 + LAS1_ADC_FIFO); d = readw(devpriv->las1 + LAS1_ADC_FIFO);
d = d >> 3; /* low 3 bits are marker lines */ d = d >> 3; /* low 3 bits are marker lines */
if (CHAN_ARRAY_TEST(devpriv->chan_is_bipolar, if (CHAN_ARRAY_TEST(devpriv->chan_is_bipolar,
s->async->cur_chan)) { s->async->cur_chan))
/* convert to comedi unsigned data */ /* convert to comedi unsigned data */
sample = d + 2048; d = comedi_offset_munge(s, d);
} else d &= s->maxdata;
sample = d;
if (!comedi_buf_put(s->async, sample)) if (!comedi_buf_put(s->async, d))
return -1; return -1;
if (devpriv->ai_count > 0) /* < 0, means read forever */ if (devpriv->ai_count > 0) /* < 0, means read forever */
@ -677,8 +674,7 @@ static int ai_read_dregs(struct comedi_device *dev, struct comedi_subdevice *s)
struct rtd_private *devpriv = dev->private; struct rtd_private *devpriv = dev->private;
while (readl(devpriv->las0 + LAS0_ADC) & FS_ADC_NOT_EMPTY) { while (readl(devpriv->las0 + LAS0_ADC) & FS_ADC_NOT_EMPTY) {
short sample; unsigned short d = readw(devpriv->las1 + LAS1_ADC_FIFO);
s16 d = readw(devpriv->las1 + LAS1_ADC_FIFO);
if (0 == devpriv->ai_count) { /* done */ if (0 == devpriv->ai_count) { /* done */
continue; /* read rest */ continue; /* read rest */
@ -686,13 +682,12 @@ static int ai_read_dregs(struct comedi_device *dev, struct comedi_subdevice *s)
d = d >> 3; /* low 3 bits are marker lines */ d = d >> 3; /* low 3 bits are marker lines */
if (CHAN_ARRAY_TEST(devpriv->chan_is_bipolar, if (CHAN_ARRAY_TEST(devpriv->chan_is_bipolar,
s->async->cur_chan)) { s->async->cur_chan))
/* convert to comedi unsigned data */ /* convert to comedi unsigned data */
sample = d + 2048; d = comedi_offset_munge(s, d);
} else d &= s->maxdata;
sample = d;
if (!comedi_buf_put(s->async, sample)) if (!comedi_buf_put(s->async, d))
return -1; return -1;
if (devpriv->ai_count > 0) /* < 0, means read forever */ if (devpriv->ai_count > 0) /* < 0, means read forever */