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

staging: comedi: adl_pci9118: tidy up check_channel_list()

Rename this function to give it namespace associated with the driver.

Currently this function is called by both the AI (*do_cmdtest) and the (*do_cmd)
functions. It really only needs to be called by the (*do_cmdtest) to validate
that the chanlist meets the requirements of the hardware. It's only called by
the (*do_cmd) to verify that the scan length is not to large after adding the
extra samples needed to satisfy the DMA.

Move the extra scan length check into the (*do_cmd) function and remove the
unnecessary parameters 'frontadd' and 'backadd'.

Tidy up the reset of the function.
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 7c999314
...@@ -169,11 +169,6 @@ static const struct comedi_lrange pci9118hg_ai_range = { ...@@ -169,11 +169,6 @@ static const struct comedi_lrange pci9118hg_ai_range = {
} }
}; };
#define PCI9118_BIPOLAR_RANGES 4 /*
* used for test on mixture
* of BIP/UNI ranges
*/
enum pci9118_boardid { enum pci9118_boardid {
BOARD_PCI9118DG, BOARD_PCI9118DG,
BOARD_PCI9118HG, BOARD_PCI9118HG,
...@@ -296,46 +291,44 @@ static void pci9118_ai_reset_fifo(struct comedi_device *dev) ...@@ -296,46 +291,44 @@ static void pci9118_ai_reset_fifo(struct comedi_device *dev)
outl(0, dev->iobase + PCI9118_FIFO_RESET_REG); outl(0, dev->iobase + PCI9118_FIFO_RESET_REG);
} }
static int check_channel_list(struct comedi_device *dev, static int pci9118_ai_check_chanlist(struct comedi_device *dev,
struct comedi_subdevice *s, int n_chan, struct comedi_subdevice *s,
unsigned int *chanlist, int frontadd, int backadd) struct comedi_cmd *cmd)
{ {
struct pci9118_private *devpriv = dev->private; struct pci9118_private *devpriv = dev->private;
unsigned int i, differencial = 0, bipolar = 0; unsigned int range0 = CR_RANGE(cmd->chanlist[0]);
unsigned int aref0 = CR_AREF(cmd->chanlist[0]);
int i;
if ((frontadd + n_chan + backadd) > s->len_chanlist) { /* single channel scans are always ok */
dev_err(dev->class_dev, if (cmd->chanlist_len == 1)
"range/channel list is too long for actual configuration!\n");
return 0; return 0;
}
if (CR_AREF(chanlist[0]) == AREF_DIFF) for (i = 1; i < cmd->chanlist_len; i++) {
differencial = 1; /* all input must be diff */ unsigned int chan = CR_CHAN(cmd->chanlist[i]);
if (CR_RANGE(chanlist[0]) < PCI9118_BIPOLAR_RANGES) unsigned int range = CR_RANGE(cmd->chanlist[i]);
bipolar = 1; /* all input must be bipolar */ unsigned int aref = CR_AREF(cmd->chanlist[i]);
if (n_chan > 1)
for (i = 1; i < n_chan; i++) { /* check S.E/diff */ if (aref != aref0) {
if ((CR_AREF(chanlist[i]) == AREF_DIFF) != dev_err(dev->class_dev,
(differencial)) { "Differential and single ended inputs can't be mixed!\n");
dev_err(dev->class_dev, return -EINVAL;
"Differential and single ended inputs can't be mixed!\n"); }
return 0; if (comedi_range_is_bipolar(s, range) !=
} comedi_range_is_bipolar(s, range0)) {
if ((CR_RANGE(chanlist[i]) < PCI9118_BIPOLAR_RANGES) != dev_err(dev->class_dev,
(bipolar)) { "Bipolar and unipolar ranges can't be mixed!\n");
dev_err(dev->class_dev, return -EINVAL;
"Bipolar and unipolar ranges can't be mixed!\n"); }
return 0; if (!devpriv->usemux && aref == AREF_DIFF &&
} (chan >= (s->n_chan / 2))) {
if (!devpriv->usemux && differencial && dev_err(dev->class_dev,
(CR_CHAN(chanlist[i]) >= (s->n_chan / 2))) { "AREF_DIFF is only available for the first 8 channels!\n");
dev_err(dev->class_dev, return -EINVAL;
"AREF_DIFF is only available for the first 8 channels!\n");
return 0;
}
} }
}
return 1; return 0;
} }
static void pci9118_set_chanlist(struct comedi_device *dev, static void pci9118_set_chanlist(struct comedi_device *dev,
...@@ -940,6 +933,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -940,6 +933,7 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
struct comedi_8254 *pacer = dev->pacer; struct comedi_8254 *pacer = dev->pacer;
struct comedi_cmd *cmd = &s->async->cmd; struct comedi_cmd *cmd = &s->async->cmd;
unsigned int addchans = 0; unsigned int addchans = 0;
unsigned int scanlen;
devpriv->ai12_startstop = 0; devpriv->ai12_startstop = 0;
devpriv->ai_flags = cmd->flags; devpriv->ai_flags = cmd->flags;
...@@ -1025,19 +1019,20 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -1025,19 +1019,20 @@ static int pci9118_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
} }
} }
/* well, we now know what must be all added */ /* well, we now know what must be all added */
devpriv->ai_n_realscanlen = /* scanlen = devpriv->ai_add_front + cmd->chanlist_len +
* what we must take from card in real devpriv->ai_add_back;
* to have cmd->scan_end_arg on output? /*
*/ * what we must take from card in real to have cmd->scan_end_arg
(devpriv->ai_add_front + cmd->chanlist_len + * on output?
devpriv->ai_add_back) * (cmd->scan_end_arg / */
cmd->chanlist_len); devpriv->ai_n_realscanlen = scanlen *
(cmd->scan_end_arg / cmd->chanlist_len);
/* check and setup channel list */
if (!check_channel_list(dev, s, cmd->chanlist_len, if (scanlen > s->len_chanlist) {
cmd->chanlist, devpriv->ai_add_front, dev_err(dev->class_dev,
devpriv->ai_add_back)) "range/channel list is too long for actual configuration!\n");
return -EINVAL; return -EINVAL;
}
/* /*
* Configure analog input and load the chanlist. * Configure analog input and load the chanlist.
...@@ -1307,10 +1302,13 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev, ...@@ -1307,10 +1302,13 @@ static int pci9118_ai_cmdtest(struct comedi_device *dev,
if (err) if (err)
return 4; return 4;
/* Step 5: check channel list if it exists */
if (cmd->chanlist) if (cmd->chanlist)
if (!check_channel_list(dev, s, cmd->chanlist_len, err |= pci9118_ai_check_chanlist(dev, s, cmd);
cmd->chanlist, 0, 0))
return 5; /* incorrect channels list */ if (err)
return 5;
return 0; return 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