Skip to content

Commit 7fd2dae

Browse files
bigguinessgregkh
authored andcommitted
staging: comedi: adv_pci1710: introduce pci171x_ai_read_sample()
Introduce a helper function to read an analog input sample, check for channel dropout, and mask the sample to the maxdata of the subdevice. 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>
1 parent a65e141 commit 7fd2dae

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

drivers/staging/comedi/drivers/adv_pci1710.c

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -276,31 +276,6 @@ struct pci1710_private {
276276
* internal state */
277277
};
278278

279-
static int pci171x_ai_dropout(struct comedi_device *dev,
280-
struct comedi_subdevice *s,
281-
unsigned int chan,
282-
unsigned int val)
283-
{
284-
const struct boardtype *board = dev->board_ptr;
285-
struct pci1710_private *devpriv = dev->private;
286-
287-
if (!board->is_pci1713) {
288-
/*
289-
* The upper 4 bits of the 16-bit sample are the channel number
290-
* that the sample was acquired from. Verify that this channel
291-
* number matches the expected channel number.
292-
*/
293-
val >>= 12;
294-
if (val != devpriv->act_chanlist[chan]) {
295-
dev_err(dev->class_dev,
296-
"A/D data droput: received from channel %d, expected %d\n",
297-
val, devpriv->act_chanlist[chan]);
298-
return -ENODATA;
299-
}
300-
}
301-
return 0;
302-
}
303-
304279
static int pci171x_ai_check_chanlist(struct comedi_device *dev,
305280
struct comedi_subdevice *s,
306281
struct comedi_cmd *cmd)
@@ -416,6 +391,35 @@ static int pci171x_ai_eoc(struct comedi_device *dev,
416391
return -EBUSY;
417392
}
418393

394+
static int pci171x_ai_read_sample(struct comedi_device *dev,
395+
struct comedi_subdevice *s,
396+
unsigned int cur_chan,
397+
unsigned int *val)
398+
{
399+
const struct boardtype *board = dev->board_ptr;
400+
struct pci1710_private *devpriv = dev->private;
401+
unsigned int sample;
402+
unsigned int chan;
403+
404+
sample = inw(dev->iobase + PCI171x_AD_DATA);
405+
if (!board->is_pci1713) {
406+
/*
407+
* The upper 4 bits of the 16-bit sample are the channel number
408+
* that the sample was acquired from. Verify that this channel
409+
* number matches the expected channel number.
410+
*/
411+
chan = sample >> 12;
412+
if (chan != devpriv->act_chanlist[cur_chan]) {
413+
dev_err(dev->class_dev,
414+
"A/D data droput: received from channel %d, expected %d\n",
415+
chan, devpriv->act_chanlist[cur_chan]);
416+
return -ENODATA;
417+
}
418+
}
419+
*val = sample & s->maxdata;
420+
return 0;
421+
}
422+
419423
static int pci171x_ai_insn_read(struct comedi_device *dev,
420424
struct comedi_subdevice *s,
421425
struct comedi_insn *insn,
@@ -443,12 +447,11 @@ static int pci171x_ai_insn_read(struct comedi_device *dev,
443447
if (ret)
444448
break;
445449

446-
val = inw(dev->iobase + PCI171x_AD_DATA);
447-
ret = pci171x_ai_dropout(dev, s, chan, val);
450+
ret = pci171x_ai_read_sample(dev, s, chan, &val);
448451
if (ret)
449452
break;
450453

451-
data[i] = val & s->maxdata;
454+
data[i] = val;
452455
}
453456

454457
outb(0, dev->iobase + PCI171x_CLRFIFO);
@@ -677,14 +680,12 @@ static void pci1710_handle_every_sample(struct comedi_device *dev,
677680
outb(0, dev->iobase + PCI171x_CLRINT); /* clear our INT request */
678681

679682
for (; !(inw(dev->iobase + PCI171x_STATUS) & Status_FE);) {
680-
val = inw(dev->iobase + PCI171x_AD_DATA);
681-
ret = pci171x_ai_dropout(dev, s, s->async->cur_chan, val);
683+
ret = pci171x_ai_read_sample(dev, s, s->async->cur_chan, &val);
682684
if (ret) {
683685
s->async->events |= COMEDI_CB_ERROR;
684686
break;
685687
}
686688

687-
val &= s->maxdata;
688689
comedi_buf_write_samples(s, &val, 1);
689690

690691
if (cmd->stop_src == TRIG_COUNT &&
@@ -707,15 +708,12 @@ static int move_block_from_fifo(struct comedi_device *dev,
707708
int i;
708709

709710
for (i = 0; i < n; i++) {
710-
val = inw(dev->iobase + PCI171x_AD_DATA);
711-
712-
ret = pci171x_ai_dropout(dev, s, s->async->cur_chan, val);
711+
ret = pci171x_ai_read_sample(dev, s, s->async->cur_chan, &val);
713712
if (ret) {
714713
s->async->events |= COMEDI_CB_ERROR;
715714
return ret;
716715
}
717716

718-
val &= s->maxdata;
719717
comedi_buf_write_samples(s, &val, 1);
720718
}
721719
return 0;

0 commit comments

Comments
 (0)