summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/pcmmio.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2013-12-09 15:31:18 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-12-17 10:02:14 -0800
commitc5b970aeb9c19208abeabcb675194d5d6e9cfe68 (patch)
tree3f5ebd61dc61ce9a7716e197fccecfd4e33c43d0 /drivers/staging/comedi/drivers/pcmmio.c
parent2eb6b51822ab1c3b7e8b62564ba86fed6c629297 (diff)
staging: comedi: pcmmio: tidy up pcmmio_start_intr()
Refactor the function to remove some indent levels. Use pcmmio_dio_write() to write the polarity and enable paged registers instead of using the for () loop to write each register in the pages. The for () loop actually has a bug. It switches the page to the 'enab' registers for the first port then switches to the 'pol' registers for all remaining writes. It also was not using the pagelock spinlock to protect the writes to the page registers. Using the pcmmio_dio_write() helper ensures that the writes to the paged registers complete correctly. 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>
Diffstat (limited to 'drivers/staging/comedi/drivers/pcmmio.c')
-rw-r--r--drivers/staging/comedi/drivers/pcmmio.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/drivers/staging/comedi/drivers/pcmmio.c b/drivers/staging/comedi/drivers/pcmmio.c
index f61f9ced5d8f..ed91b027dacb 100644
--- a/drivers/staging/comedi/drivers/pcmmio.c
+++ b/drivers/staging/comedi/drivers/pcmmio.c
@@ -329,11 +329,6 @@ static int pcmmio_dio_insn_config(struct comedi_device *dev,
return insn->n;
}
-static void switch_page(struct comedi_device *dev, int page)
-{
- outb(PCMMIO_PAGE(page), dev->iobase + PCMMIO_PAGE_LOCK_REG);
-}
-
static void pcmmio_reset(struct comedi_device *dev)
{
/* Clear all the DIO port bits */
@@ -440,46 +435,38 @@ static int pcmmio_start_intr(struct comedi_device *dev,
struct comedi_subdevice *s)
{
struct pcmmio_private *devpriv = dev->private;
+ struct comedi_cmd *cmd = &s->async->cmd;
+ unsigned int bits = 0;
+ unsigned int pol_bits = 0;
+ int i;
if (!devpriv->continuous && devpriv->stop_count == 0) {
/* An empty acquisition! */
s->async->events |= COMEDI_CB_EOA;
devpriv->active = 0;
return 1;
- } else {
- unsigned bits = 0, pol_bits = 0, n;
- int nports, firstport, port;
- struct comedi_cmd *cmd = &s->async->cmd;
-
- devpriv->enabled_mask = 0;
- devpriv->active = 1;
- nports = 24 / CHANS_PER_PORT;
- firstport = 0 / CHANS_PER_PORT;
- if (cmd->chanlist) {
- for (n = 0; n < cmd->chanlist_len; n++) {
- bits |= (1U << CR_CHAN(cmd->chanlist[n]));
- pol_bits |= (CR_AREF(cmd->chanlist[n])
- || CR_RANGE(cmd->
- chanlist[n]) ? 1U : 0U)
- << CR_CHAN(cmd->chanlist[n]);
- }
- }
- bits &= ((0x1 << 24) - 1) << 0;
- devpriv->enabled_mask = bits;
-
- switch_page(dev, PCMMIO_PAGE_ENAB);
- for (port = firstport; port < firstport + nports; ++port) {
- unsigned enab, pol;
-
- enab = bits >> (0 + (port - firstport) * 8) & 0xff;
- pol = pol_bits >> (0 + (port - firstport) * 8) & 0xff;
+ }
- /* set enab intrs for this subdev.. */
- outb(enab, dev->iobase + PCMMIO_PAGE_REG(port));
- switch_page(dev, PCMMIO_PAGE_POL);
- outb(pol, dev->iobase + PCMMIO_PAGE_REG(port));
+ devpriv->enabled_mask = 0;
+ devpriv->active = 1;
+ if (cmd->chanlist) {
+ for (i = 0; i < cmd->chanlist_len; i++) {
+ unsigned int chanspec = cmd->chanlist[i];
+ unsigned int chan = CR_CHAN(chanspec);
+ unsigned int range = CR_RANGE(chanspec);
+ unsigned int aref = CR_AREF(chanspec);
+
+ bits |= (1 << chan);
+ pol_bits |= (((aref || range) ? 1 : 0) << chan);
}
}
+ bits &= ((1 << s->n_chan) - 1);
+ devpriv->enabled_mask = bits;
+
+ /* set polarity and enable interrupts */
+ pcmmio_dio_write(dev, pol_bits, PCMMIO_PAGE_POL, 0);
+ pcmmio_dio_write(dev, bits, PCMMIO_PAGE_ENAB, 0);
+
return 0;
}