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

staging: comedi: ni_at_2150: tidy up irq/dma request

This driver needs both an irq and dma in order to support async
commands. If the irq and dma are not available the driver will
still function for single analog input reads.

Tidy up the code that does the irq and dma requests so that the
driver will still attach if they are not avaliable. The attach
will still fail, with -ENOMEM, if the dma buffer cannot be allocated.

Remove the noise about the irq and dma during the attach.

Only hook up the async commands support if the irq and dma are
available. Remove the then unnecessary sanity check in a2150_ai_cmd().
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 a1caff6d
...@@ -395,11 +395,6 @@ static int a2150_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -395,11 +395,6 @@ static int a2150_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
unsigned int old_config_bits = devpriv->config_bits; unsigned int old_config_bits = devpriv->config_bits;
unsigned int trigger_bits; unsigned int trigger_bits;
if (!dev->irq || !devpriv->dma) {
comedi_error(dev,
" irq and dma required, cannot do hardware conversions");
return -1;
}
if (cmd->flags & TRIG_RT) { if (cmd->flags & TRIG_RT) {
comedi_error(dev, comedi_error(dev,
" dma incompatible with hard real-time interrupt (TRIG_RT), aborting"); " dma incompatible with hard real-time interrupt (TRIG_RT), aborting");
...@@ -703,35 +698,27 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -703,35 +698,27 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
if (ret) if (ret)
return ret; return ret;
/* grab our IRQ */ dev->board_ptr = a2150_boards + a2150_probe(dev);
if (irq) { thisboard = comedi_board(dev);
/* check that irq is supported */ dev->board_name = thisboard->name;
if (irq < 3 || irq == 8 || irq == 13 || irq > 15) {
printk(" invalid irq line %u\n", irq); if ((irq >= 3 && irq <= 7) || (irq >= 9 && irq <= 12) ||
return -EINVAL; irq == 14 || irq == 15) {
} ret = request_irq(irq, a2150_interrupt, 0,
if (request_irq(irq, a2150_interrupt, 0, dev->board_name, dev);
dev->driver->driver_name, dev)) { if (ret == 0) {
printk("unable to allocate irq %u\n", irq);
return -EINVAL;
}
devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq); devpriv->irq_dma_bits |= IRQ_LVL_BITS(irq);
dev->irq = irq; dev->irq = irq;
} }
/* initialize dma */
if (dma) {
if (dma == 4 || dma > 7) {
printk(" invalid dma channel %u\n", dma);
return -EINVAL;
}
if (request_dma(dma, dev->driver->driver_name)) {
printk(" failed to allocate dma channel %u\n", dma);
return -EINVAL;
} }
if (dev->irq && ((dma >= 0 && dma <= 4) || (dma >= 5 && dma <= 7))) {
ret = request_dma(dma, dev->board_name);
if (ret == 0) {
devpriv->dma = dma; devpriv->dma = dma;
devpriv->dma_buffer = devpriv->dma_buffer = kmalloc(A2150_DMA_BUFFER_SIZE,
kmalloc(A2150_DMA_BUFFER_SIZE, GFP_KERNEL | GFP_DMA); GFP_KERNEL | GFP_DMA);
if (devpriv->dma_buffer == NULL) if (!devpriv->dma_buffer)
return -ENOMEM; return -ENOMEM;
disable_dma(dma); disable_dma(dma);
...@@ -739,10 +726,7 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -739,10 +726,7 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma); devpriv->irq_dma_bits |= DMA_CHAN_BITS(dma);
} }
}
dev->board_ptr = a2150_boards + a2150_probe(dev);
thisboard = comedi_board(dev);
dev->board_name = thisboard->name;
ret = comedi_alloc_subdevices(dev, 1); ret = comedi_alloc_subdevices(dev, 1);
if (ret) if (ret)
...@@ -750,17 +734,20 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -750,17 +734,20 @@ static int a2150_attach(struct comedi_device *dev, struct comedi_devconfig *it)
/* analog input subdevice */ /* analog input subdevice */
s = &dev->subdevices[0]; s = &dev->subdevices[0];
dev->read_subdev = s;
s->type = COMEDI_SUBD_AI; s->type = COMEDI_SUBD_AI;
s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER | SDF_CMD_READ; s->subdev_flags = SDF_READABLE | SDF_GROUND | SDF_OTHER;
s->n_chan = 4; s->n_chan = 4;
s->len_chanlist = 4;
s->maxdata = 0xffff; s->maxdata = 0xffff;
s->range_table = &range_a2150; s->range_table = &range_a2150;
s->insn_read = a2150_ai_rinsn;
if (dev->irq && devpriv->dma) {
dev->read_subdev = s;
s->subdev_flags |= SDF_CMD_READ;
s->len_chanlist = s->n_chan;
s->do_cmd = a2150_ai_cmd; s->do_cmd = a2150_ai_cmd;
s->do_cmdtest = a2150_ai_cmdtest; s->do_cmdtest = a2150_ai_cmdtest;
s->insn_read = a2150_ai_rinsn;
s->cancel = a2150_cancel; s->cancel = a2150_cancel;
}
/* need to do this for software counting of completed conversions, to /* need to do this for software counting of completed conversions, to
* prevent hardware count from stopping acquisition */ * prevent hardware count from stopping acquisition */
......
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