diff options
author | H Hartley Sweeten <hartleys@visionengravers.com> | 2012-09-24 16:23:57 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-09-26 12:37:31 -0400 |
commit | b7047895b9c9deee0b0f4cb2a0a788c189f985f2 (patch) | |
tree | e991436490d67ef9a376893909eedea6177f56bd /drivers | |
parent | 97d87e00e3d6bdc8f3de606dd7cc5aa149709435 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/comedi/drivers/s626.c | 57 |
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) | |||
2437 | } | 2437 | } |
2438 | } | 2438 | } |
2439 | 2439 | ||
2440 | static int s626_allocate_dma_buffers(struct comedi_device *dev) | ||
2441 | { | ||
2442 | struct pci_dev *pcidev = comedi_to_pci_dev(dev); | ||
2443 | void *addr; | ||
2444 | dma_addr_t appdma; | ||
2445 | |||
2446 | devpriv->allocatedBuf = 0; | ||
2447 | |||
2448 | addr = pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma); | ||
2449 | if (!addr) | ||
2450 | return -ENOMEM; | ||
2451 | devpriv->ANABuf.LogicalBase = addr; | ||
2452 | devpriv->ANABuf.PhysicalBase = appdma; | ||
2453 | |||
2454 | devpriv->allocatedBuf++; | ||
2455 | |||
2456 | addr = pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma); | ||
2457 | if (!addr) | ||
2458 | return -ENOMEM; | ||
2459 | devpriv->RPSBuf.LogicalBase = addr; | ||
2460 | devpriv->RPSBuf.PhysicalBase = appdma; | ||
2461 | |||
2462 | devpriv->allocatedBuf++; | ||
2463 | |||
2464 | return 0; | ||
2465 | } | ||
2466 | |||
2440 | static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev) | 2467 | static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev) |
2441 | { | 2468 | { |
2442 | /* uint8_t PollList; */ | 2469 | /* uint8_t PollList; */ |
@@ -2446,7 +2473,6 @@ static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev) | |||
2446 | /* unsigned int data[16]; */ | 2473 | /* unsigned int data[16]; */ |
2447 | int i; | 2474 | int i; |
2448 | int ret; | 2475 | int ret; |
2449 | dma_addr_t appdma; | ||
2450 | struct comedi_subdevice *s; | 2476 | struct comedi_subdevice *s; |
2451 | 2477 | ||
2452 | comedi_set_hw_dev(dev, &pcidev->dev); | 2478 | comedi_set_hw_dev(dev, &pcidev->dev); |
@@ -2473,32 +2499,9 @@ static int s626_attach_pci(struct comedi_device *dev, struct pci_dev *pcidev) | |||
2473 | 2499 | ||
2474 | /* DMA FIXME DMA// */ | 2500 | /* DMA FIXME DMA// */ |
2475 | 2501 | ||
2476 | /* adc buffer allocation */ | 2502 | ret = s626_allocate_dma_buffers(dev); |
2477 | devpriv->allocatedBuf = 0; | 2503 | if (ret) |
2478 | 2504 | return ret; | |
2479 | devpriv->ANABuf.LogicalBase = | ||
2480 | pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma); | ||
2481 | |||
2482 | if (devpriv->ANABuf.LogicalBase == NULL) { | ||
2483 | printk(KERN_ERR "s626_attach: DMA Memory mapping error\n"); | ||
2484 | return -ENOMEM; | ||
2485 | } | ||
2486 | |||
2487 | devpriv->ANABuf.PhysicalBase = appdma; | ||
2488 | |||
2489 | devpriv->allocatedBuf++; | ||
2490 | |||
2491 | devpriv->RPSBuf.LogicalBase = | ||
2492 | pci_alloc_consistent(pcidev, DMABUF_SIZE, &appdma); | ||
2493 | |||
2494 | if (devpriv->RPSBuf.LogicalBase == NULL) { | ||
2495 | printk(KERN_ERR "s626_attach: DMA Memory mapping error\n"); | ||
2496 | return -ENOMEM; | ||
2497 | } | ||
2498 | |||
2499 | devpriv->RPSBuf.PhysicalBase = appdma; | ||
2500 | |||
2501 | devpriv->allocatedBuf++; | ||
2502 | 2505 | ||
2503 | ret = comedi_alloc_subdevices(dev, 6); | 2506 | ret = comedi_alloc_subdevices(dev, 6); |
2504 | if (ret) | 2507 | if (ret) |