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

staging: comedi: refactor dt282x driver to remove forward declarations

Move the struct comedi_driver and variables to the end of the
source. This is more typical of how other drivers are written and
removes the need for the forward declarations.

Convert the driver to use the module_comedi_driver() macro which
makes the code smaller and a bit simpler.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Mori Hess <fmhess@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 15362c5e
...@@ -221,135 +221,6 @@ struct dt282x_board { ...@@ -221,135 +221,6 @@ struct dt282x_board {
int dabits; int dabits;
}; };
static const struct dt282x_board boardtypes[] = {
{.name = "dt2821",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
},
{.name = "dt2821-f",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 6500,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
},
{.name = "dt2821-g",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 4000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
},
{.name = "dt2823",
.adbits = 16,
.adchan_se = 0,
.adchan_di = 4,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 16,
},
{.name = "dt2824-pgh",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
},
{.name = "dt2824-pgl",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 1,
.dachan = 0,
.dabits = 0,
},
{.name = "dt2825",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 1,
.dachan = 2,
.dabits = 12,
},
{.name = "dt2827",
.adbits = 16,
.adchan_se = 0,
.adchan_di = 4,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
},
{.name = "dt2828",
.adbits = 12,
.adchan_se = 4,
.adchan_di = 0,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
},
{.name = "dt2829",
.adbits = 16,
.adchan_se = 8,
.adchan_di = 0,
.ai_speed = 33250,
.ispgl = 0,
.dachan = 2,
.dabits = 16,
},
{.name = "dt21-ez",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
},
{.name = "dt23-ez",
.adbits = 16,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
},
{.name = "dt24-ez",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
},
{.name = "dt24-ez-pgl",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 1,
.dachan = 0,
.dabits = 0,
},
};
#define this_board ((const struct dt282x_board *)dev->board_ptr) #define this_board ((const struct dt282x_board *)dev->board_ptr)
struct dt282x_private { struct dt282x_private {
...@@ -410,33 +281,6 @@ struct dt282x_private { ...@@ -410,33 +281,6 @@ struct dt282x_private {
b \ b \
} while (0) } while (0)
static int dt282x_attach(struct comedi_device *dev,
struct comedi_devconfig *it);
static int dt282x_detach(struct comedi_device *dev);
static struct comedi_driver driver_dt282x = {
.driver_name = "dt282x",
.module = THIS_MODULE,
.attach = dt282x_attach,
.detach = dt282x_detach,
.board_name = &boardtypes[0].name,
.num_names = ARRAY_SIZE(boardtypes),
.offset = sizeof(struct dt282x_board),
};
static int __init driver_dt282x_init_module(void)
{
return comedi_driver_register(&driver_dt282x);
}
static void __exit driver_dt282x_cleanup_module(void)
{
comedi_driver_unregister(&driver_dt282x);
}
module_init(driver_dt282x_init_module);
module_exit(driver_dt282x_cleanup_module);
static void free_resources(struct comedi_device *dev);
static int prep_ai_dma(struct comedi_device *dev, int chan, int size); static int prep_ai_dma(struct comedi_device *dev, int chan, int size);
static int prep_ao_dma(struct comedi_device *dev, int chan, int size); static int prep_ao_dma(struct comedi_device *dev, int chan, int size);
static int dt282x_ai_cancel(struct comedi_device *dev, static int dt282x_ai_cancel(struct comedi_device *dev,
...@@ -1270,6 +1114,52 @@ enum { /* i/o base, irq, dma channels */ ...@@ -1270,6 +1114,52 @@ enum { /* i/o base, irq, dma channels */
opt_ai_range, opt_ao0_range, opt_ao1_range, /* range */ opt_ai_range, opt_ao0_range, opt_ao1_range, /* range */
}; };
static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2)
{
int ret;
devpriv->usedma = 0;
if (!dma1 && !dma2) {
printk(KERN_ERR " (no dma)");
return 0;
}
if (dma1 == dma2 || dma1 < 5 || dma2 < 5 || dma1 > 7 || dma2 > 7)
return -EINVAL;
if (dma2 < dma1) {
int i;
i = dma1;
dma1 = dma2;
dma2 = i;
}
ret = request_dma(dma1, "dt282x A");
if (ret)
return -EBUSY;
devpriv->dma[0].chan = dma1;
ret = request_dma(dma2, "dt282x B");
if (ret)
return -EBUSY;
devpriv->dma[1].chan = dma2;
devpriv->dma_maxsize = PAGE_SIZE;
devpriv->dma[0].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
devpriv->dma[1].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA);
if (!devpriv->dma[0].buf || !devpriv->dma[1].buf) {
printk(KERN_ERR " can't get DMA memory");
return -ENOMEM;
}
printk(KERN_INFO " (dma=%d,%d)", dma1, dma2);
devpriv->usedma = 1;
return 0;
}
/* /*
options: options:
0 i/o base 0 i/o base
...@@ -1468,51 +1358,146 @@ static int dt282x_detach(struct comedi_device *dev) ...@@ -1468,51 +1358,146 @@ static int dt282x_detach(struct comedi_device *dev)
return 0; return 0;
} }
static int dt282x_grab_dma(struct comedi_device *dev, int dma1, int dma2) static const struct dt282x_board boardtypes[] = {
{ {
int ret; .name = "dt2821",
.adbits = 12,
devpriv->usedma = 0; .adchan_se = 16,
.adchan_di = 8,
if (!dma1 && !dma2) { .ai_speed = 20000,
printk(KERN_ERR " (no dma)"); .ispgl = 0,
return 0; .dachan = 2,
} .dabits = 12,
}, {
if (dma1 == dma2 || dma1 < 5 || dma2 < 5 || dma1 > 7 || dma2 > 7) .name = "dt2821-f",
return -EINVAL; .adbits = 12,
.adchan_se = 16,
if (dma2 < dma1) { .adchan_di = 8,
int i; .ai_speed = 6500,
i = dma1; .ispgl = 0,
dma1 = dma2; .dachan = 2,
dma2 = i; .dabits = 12,
} }, {
.name = "dt2821-g",
ret = request_dma(dma1, "dt282x A"); .adbits = 12,
if (ret) .adchan_se = 16,
return -EBUSY; .adchan_di = 8,
devpriv->dma[0].chan = dma1; .ai_speed = 4000,
.ispgl = 0,
ret = request_dma(dma2, "dt282x B"); .dachan = 2,
if (ret) .dabits = 12,
return -EBUSY; }, {
devpriv->dma[1].chan = dma2; .name = "dt2823",
.adbits = 16,
devpriv->dma_maxsize = PAGE_SIZE; .adchan_se = 0,
devpriv->dma[0].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); .adchan_di = 4,
devpriv->dma[1].buf = (void *)__get_free_page(GFP_KERNEL | GFP_DMA); .ai_speed = 10000,
if (!devpriv->dma[0].buf || !devpriv->dma[1].buf) { .ispgl = 0,
printk(KERN_ERR " can't get DMA memory"); .dachan = 2,
return -ENOMEM; .dabits = 16,
} }, {
.name = "dt2824-pgh",
printk(KERN_INFO " (dma=%d,%d)", dma1, dma2); .adbits = 12,
.adchan_se = 16,
devpriv->usedma = 1; .adchan_di = 8,
.ai_speed = 20000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt2824-pgl",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 1,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt2825",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 20000,
.ispgl = 1,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2827",
.adbits = 16,
.adchan_se = 0,
.adchan_di = 4,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2828",
.adbits = 12,
.adchan_se = 4,
.adchan_di = 0,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt2829",
.adbits = 16,
.adchan_se = 8,
.adchan_di = 0,
.ai_speed = 33250,
.ispgl = 0,
.dachan = 2,
.dabits = 16,
}, {
.name = "dt21-ez",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 2,
.dabits = 12,
}, {
.name = "dt23-ez",
.adbits = 16,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt24-ez",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 0,
.dachan = 0,
.dabits = 0,
}, {
.name = "dt24-ez-pgl",
.adbits = 12,
.adchan_se = 16,
.adchan_di = 8,
.ai_speed = 10000,
.ispgl = 1,
.dachan = 0,
.dabits = 0,
},
};
return 0; static struct comedi_driver dt282x_driver = {
} .driver_name = "dt282x",
.module = THIS_MODULE,
.attach = dt282x_attach,
.detach = dt282x_detach,
.board_name = &boardtypes[0].name,
.num_names = ARRAY_SIZE(boardtypes),
.offset = sizeof(struct dt282x_board),
};
module_comedi_driver(dt282x_driver);
MODULE_AUTHOR("Comedi http://www.comedi.org"); MODULE_AUTHOR("Comedi http://www.comedi.org");
MODULE_DESCRIPTION("Comedi low-level driver"); MODULE_DESCRIPTION("Comedi low-level driver");
......
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