summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-09-24 13:23:57 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-09-26 09:37:31 -0700
commitb7047895b9c9deee0b0f4cb2a0a788c189f985f2 (patch)
treee991436490d67ef9a376893909eedea6177f56bd
parent97d87e00e3d6bdc8f3de606dd7cc5aa149709435 (diff)
downloadblackbird-op-linux-b7047895b9c9deee0b0f4cb2a0a788c189f985f2.tar.gz
blackbird-op-linux-b7047895b9c9deee0b0f4cb2a0a788c189f985f2.zip
staging: comedi: s626: factor out the dma buffer allocation
To make the attach a bit cleaner, factor the dma buffer allocation out of attach_pci() into a new function. 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>
-rw-r--r--drivers/staging/comedi/drivers/s626.c57
1 files changed, 30 insertions, 27 deletions
diff --git a/drivers/staging/comedi/drivers/s626.c b/drivers/staging/comedi/drivers/s626.c
index a9d78c721403..61bb8ab05786 100644
--- a/drivers/staging/comedi/drivers/s626.c
+++ b/drivers/staging/comedi/drivers/s626.c
@@ -2437,6 +2437,33 @@ static void CountersInit(struct comedi_device *dev)
}
}
+static int s626_allocate_dma_buffers(struct comedi_device *dev)
+{
+ struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+ void *addr;
+ dma_addr_t appdma;
+
+ devpriv->allocatedBuf = 0;
+
+ addr = pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma);
+ if (!addr)
+ return -ENOMEM;
+ devpriv->ANABuf.LogicalBase = addr;
+ devpriv->ANABuf.PhysicalBase = appdma;
+
+ devpriv->allocatedBuf++;
+
+ addr = pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma);
+ if (!addr)
+ return -ENOMEM;
+ devpriv->RPSBuf.LogicalBase = addr;
+ devpriv->RPSBuf.PhysicalBase = appdma;
+
+ devpriv->allocatedBuf++;
+
+ return 0;
+}
+
static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev)
{
/* uint8_t PollList; */
@@ -2446,7 +2473,6 @@ static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev)
/* unsigned int data[16]; */
int i;
int ret;
- dma_addr_t appdma;
struct comedi_subdevice *s;
comedi_set_hw_dev(dev, &pcidev->dev);
@@ -2473,32 +2499,9 @@ static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev)
/* DMA FIXME DMA// */
- /* adc buffer allocation */
- devpriv->allocatedBuf = 0;
-
- devpriv->ANABuf.LogicalBase =
- pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma);
-
- if (devpriv->ANABuf.LogicalBase == NULL) {
- printk(KERN_ERR "s626_attach: DMA Memory mapping error\n");
- return -ENOMEM;
- }
-
- devpriv->ANABuf.PhysicalBase = appdma;
-
- devpriv->allocatedBuf++;
-
- devpriv->RPSBuf.LogicalBase =
- pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma);
-
- if (devpriv->RPSBuf.LogicalBase == NULL) {
- printk(KERN_ERR "s626_attach: DMA Memory mapping error\n");
- return -ENOMEM;
- }
-
- devpriv->RPSBuf.PhysicalBase = appdma;
-
- devpriv->allocatedBuf++;
+ ret = s626_allocate_dma_buffers(dev);
+ if (ret)
+ return ret;
ret = comedi_alloc_subdevices(dev, 6);
if (ret)
OpenPOWER on IntegriCloud