staging: comedi: ni_labpc: allow board to attach without dma
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Fri, 22 Mar 2013 16:55:30 +0000 (09:55 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Mar 2013 18:43:01 +0000 (11:43 -0700)
If the dma channel is not available this driver will still work
with interrupts for the analog input subdevice command support.

In addition, only dma channels 1 and 3 are valid for the ISA
devices.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/drivers/ni_labpc.c

index a52647a901f64ad1e45e09ca560db0f07684ddcb..744db1f5aa254afc564525d19841002cda4ab51f 100644 (file)
@@ -1673,30 +1673,23 @@ int labpc_common_attach(struct comedi_device *dev, unsigned long iobase,
        }
 
 #ifdef CONFIG_ISA_DMA_API
-       /* grab dma channel */
-       if (dma_chan > 3) {
-               dev_err(dev->class_dev, "invalid dma channel %u\n", dma_chan);
-               return -EINVAL;
-       } else if (dma_chan) {
-               unsigned long dma_flags;
-
-               /* allocate dma buffer */
+       if (dma_chan == 1 || dma_chan == 3) {
                devpriv->dma_buffer = kmalloc(dma_buffer_size,
                                              GFP_KERNEL | GFP_DMA);
-               if (devpriv->dma_buffer == NULL)
-                       return -ENOMEM;
-
-               if (request_dma(dma_chan, dev->board_name)) {
-                       dev_err(dev->class_dev,
-                               "failed to allocate dma channel %u\n",
-                               dma_chan);
-                       return -EINVAL;
+               if (devpriv->dma_buffer) {
+                       ret = request_dma(dma_chan, dev->board_name);
+                       if (ret == 0) {
+                               unsigned long dma_flags;
+
+                               devpriv->dma_chan = dma_chan;
+                               dma_flags = claim_dma_lock();
+                               disable_dma(devpriv->dma_chan);
+                               set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
+                               release_dma_lock(dma_flags);
+                       } else {
+                               kfree(devpriv->dma_buffer);
+                       }
                }
-               devpriv->dma_chan = dma_chan;
-               dma_flags = claim_dma_lock();
-               disable_dma(devpriv->dma_chan);
-               set_dma_mode(devpriv->dma_chan, DMA_MODE_READ);
-               release_dma_lock(dma_flags);
        }
 #endif