Commit 4ba4a2d3 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: pcl818: clarify dma channel request in pcl818_attach()

All the board types that can do DMA can use DMA channels 3 or 1. Remove
the 'DMAbits', which is a mask of the valid channels, from the boardinfo
and replace it with a bit-field flag 'has_dma'.

Refactor pcl818_attach() to use the new flag and remove the need for the
goto.
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 ee34785c
......@@ -267,9 +267,9 @@ struct pcl818_board {
int n_dochan;
const struct comedi_lrange *ai_range_type;
unsigned int IRQbits;
unsigned int DMAbits;
int ai_maxdata;
int ao_maxdata;
unsigned int has_dma:1;
unsigned int has_fifo:1;
int is_818;
};
......@@ -286,9 +286,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_pcl818l_l_ai,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
.is_818 = 1,
}, {
.name = "pcl818h",
......@@ -301,9 +301,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_pcl818h_ai,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
.is_818 = 1,
}, {
.name = "pcl818hd",
......@@ -316,9 +316,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_pcl818h_ai,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
.has_fifo = 1,
.is_818 = 1,
}, {
......@@ -332,9 +332,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_pcl818hg_ai,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
.has_fifo = 1,
.is_818 = 1,
}, {
......@@ -348,9 +348,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_pcl818h_ai,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
.is_818 = 1,
}, {
.name = "pcl718",
......@@ -363,9 +363,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_unipolar5,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
}, {
.name = "pcm3718",
.n_ranges = 9,
......@@ -376,9 +376,9 @@ static const struct pcl818_board boardtypes[] = {
.n_dochan = 16,
.ai_range_type = &range_pcl818h_ai,
.IRQbits = 0x00fc,
.DMAbits = 0x0a,
.ai_maxdata = 0xfff,
.ao_maxdata = 0xfff,
.has_dma = 1,
.is_818 = 1,
},
};
......@@ -1315,7 +1315,6 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
const struct pcl818_board *board = comedi_board(dev);
struct pcl818_private *devpriv;
int ret;
int dma;
unsigned long pages;
struct comedi_subdevice *s;
......@@ -1347,24 +1346,18 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
devpriv->irq_blocked = 0; /* number of subdevice which use IRQ */
devpriv->ai_mode = 0; /* mode of irq */
/* grab our DMA */
dma = 0;
devpriv->dma = dma;
if (!dev->irq)
goto no_dma; /* if we haven't IRQ, we can't use DMA */
if (board->DMAbits != 0) { /* board support DMA */
dma = it->options[2];
if (dma < 1)
goto no_dma; /* DMA disabled */
if (((1 << dma) & board->DMAbits) == 0) {
/* we need an IRQ to do DMA on channel 3 or 1 */
if (dev->irq && board->has_dma &&
(it->options[2] == 3 || it->options[2] == 1)) {
ret = request_dma(it->options[2], dev->board_name);
if (ret) {
dev_err(dev->class_dev,
"DMA is out of allowed range, FAIL!\n");
return -EINVAL; /* Bad DMA */
"unable to request DMA channel %d\n",
it->options[2]);
return -EBUSY;
}
ret = request_dma(dma, dev->board_name);
if (ret)
return -EBUSY; /* DMA isn't free */
devpriv->dma = dma;
devpriv->dma = it->options[2];
pages = 2; /* we need 16KB */
devpriv->dmabuf[0] = __get_dma_pages(GFP_KERNEL, pages);
if (!devpriv->dmabuf[0])
......@@ -1381,8 +1374,6 @@ static int pcl818_attach(struct comedi_device *dev, struct comedi_devconfig *it)
devpriv->hwdmasize[1] = (1 << pages) * PAGE_SIZE;
}
no_dma:
ret = comedi_alloc_subdevices(dev, 4);
if (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