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

staging: comedi: das1800: tidy up das1800_init_dma()

Refactor this function so that a for loop can be used to request and
set up the two DMA descriptors.
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 fd8aab1a
...@@ -1228,15 +1228,24 @@ static int das1800_do_wbits(struct comedi_device *dev, ...@@ -1228,15 +1228,24 @@ static int das1800_do_wbits(struct comedi_device *dev,
return insn->n; return insn->n;
} }
static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0, static int das1800_init_dma(struct comedi_device *dev,
unsigned int dma1) struct comedi_devconfig *it)
{ {
struct das1800_private *devpriv = dev->private; struct das1800_private *devpriv = dev->private;
struct das1800_dma_desc *dma; struct das1800_dma_desc *dma;
unsigned int *dma_chan;
unsigned long flags; unsigned long flags;
int i;
/*
* it->options[2] is DMA channel 0
* it->options[3] is DMA channel 1
*
* Encode the DMA channels into 2 digit hexadecimal for switch.
*/
dma_chan = &it->options[2];
/* encode dma0 and dma1 into 2 digit hexadecimal for switch */ switch ((dma_chan[0] & 0x7) | (dma_chan[1] << 4)) {
switch ((dma0 & 0x7) | (dma1 << 4)) {
case 0x5: /* dma0 == 5 */ case 0x5: /* dma0 == 5 */
devpriv->dma_bits |= DMA_CH5; devpriv->dma_bits |= DMA_CH5;
break; break;
...@@ -1265,33 +1274,24 @@ static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0, ...@@ -1265,33 +1274,24 @@ static int das1800_init_dma(struct comedi_device *dev, unsigned int dma0,
return -EINVAL; return -EINVAL;
} }
dma = &devpriv->dma_desc[0]; for (i = 0; i < 2; i++) {
if (request_dma(dma0, dev->driver->driver_name)) { dma = &devpriv->dma_desc[i];
dev_err(dev->class_dev,
"failed to allocate dma channel %i\n", dma0);
return -EINVAL;
}
dma->chan = dma0;
dma->virt_addr = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA);
if (!dma->virt_addr)
return -ENOMEM;
flags = claim_dma_lock();
disable_dma(dma->chan);
set_dma_mode(dma->chan, DMA_MODE_READ);
release_dma_lock(flags);
if (dma1) { if (dma_chan[i] == 0)
dma = &devpriv->dma_desc[1]; break;
if (request_dma(dma1, dev->driver->driver_name)) {
if (request_dma(dma_chan[i], dev->board_name)) {
dev_err(dev->class_dev, dev_err(dev->class_dev,
"failed to allocate dma channel %i\n", "failed to allocate dma channel %i\n",
dma1); dma_chan[i]);
return -EINVAL; return -EINVAL;
} }
dma->chan = dma1; dma->chan = dma_chan[i];
dma->virt_addr = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA); dma->virt_addr = kmalloc(DMA_BUF_SIZE, GFP_KERNEL | GFP_DMA);
if (!dma->virt_addr) if (!dma->virt_addr)
return -ENOMEM; return -ENOMEM;
flags = claim_dma_lock(); flags = claim_dma_lock();
disable_dma(dma->chan); disable_dma(dma->chan);
set_dma_mode(dma->chan, DMA_MODE_READ); set_dma_mode(dma->chan, DMA_MODE_READ);
...@@ -1366,8 +1366,6 @@ static int das1800_attach(struct comedi_device *dev, ...@@ -1366,8 +1366,6 @@ static int das1800_attach(struct comedi_device *dev,
struct das1800_private *devpriv; struct das1800_private *devpriv;
struct comedi_subdevice *s; struct comedi_subdevice *s;
unsigned int irq = it->options[1]; unsigned int irq = it->options[1];
unsigned int dma0 = it->options[2];
unsigned int dma1 = it->options[3];
int board; int board;
int ret; int ret;
...@@ -1430,8 +1428,8 @@ static int das1800_attach(struct comedi_device *dev, ...@@ -1430,8 +1428,8 @@ static int das1800_attach(struct comedi_device *dev,
} }
/* an irq and one dma channel is required to use dma */ /* an irq and one dma channel is required to use dma */
if (dev->irq & dma0) { if (dev->irq & it->options[2]) {
ret = das1800_init_dma(dev, dma0, dma1); ret = das1800_init_dma(dev, it);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
......
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