Move some functions and data around to avoid the need for forward
declarations.

Signed-off-by: Ian Abbott <[email protected]>
Cc: Frank Mori Hess <[email protected]>
---
v2: Fix missing `if (ret)` after call to `comedi_alloc_subdevices()`.
---
 drivers/staging/comedi/drivers/adv_pci1724.c | 264 ++++++++++++---------------
 1 file changed, 121 insertions(+), 143 deletions(-)

diff --git a/drivers/staging/comedi/drivers/adv_pci1724.c 
b/drivers/staging/comedi/drivers/adv_pci1724.c
index b2004d2..1e9ecda 100644
--- a/drivers/staging/comedi/drivers/adv_pci1724.c
+++ b/drivers/staging/comedi/drivers/adv_pci1724.c
@@ -132,14 +132,6 @@ static const struct comedi_lrange *const 
ao_range_list_1724[NUM_AO_CHANNELS] = {
        [0 ... NUM_AO_CHANNELS - 1] = &ao_ranges_1724,
 };
 
-
-static DEFINE_PCI_DEVICE_TABLE(adv_pci1724_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1724) },
-       { 0 }
-};
-
-MODULE_DEVICE_TABLE(pci, adv_pci1724_pci_table);
-
 /* this structure is for data unique to this hardware driver. */
 struct adv_pci1724_private {
        int ao_value[NUM_AO_CHANNELS];
@@ -147,141 +139,6 @@ struct adv_pci1724_private {
        int gain_value[NUM_AO_CHANNELS];
 };
 
-static int adv_pci1724_auto_attach(struct comedi_device *dev,
-                                  unsigned long context_unused);
-static void adv_pci1724_detach(struct comedi_device *dev);
-static struct comedi_driver adv_pci1724_driver = {
-       .driver_name = "adv_pci1724",
-       .module = THIS_MODULE,
-       .auto_attach = adv_pci1724_auto_attach,
-       .detach = adv_pci1724_detach,
-};
-
-static int ao_winsn(struct comedi_device *dev, struct comedi_subdevice *s,
-                   struct comedi_insn *insn, unsigned int *data);
-static int ao_readback_insn(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn, unsigned int *data);
-static int gain_read_insn(struct comedi_device *dev,
-                          struct comedi_subdevice *s, struct comedi_insn *insn,
-                          unsigned int *data);
-static int gain_write_insn(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn, unsigned int *data);
-static int offset_read_insn(struct comedi_device *dev,
-                          struct comedi_subdevice *s, struct comedi_insn *insn,
-                          unsigned int *data);
-static int offset_write_insn(struct comedi_device *dev,
-                           struct comedi_subdevice *s,
-                           struct comedi_insn *insn, unsigned int *data);
-
-static int adv_pci1724_pci_probe(struct pci_dev *dev,
-                                const struct pci_device_id *ent)
-{
-       return comedi_pci_auto_config(dev, &adv_pci1724_driver);
-}
-
-static struct pci_driver adv_pci1724_pci_driver = {
-       .name = "adv_pci1724",
-       .id_table = adv_pci1724_pci_table,
-       .probe = adv_pci1724_pci_probe,
-       .remove = comedi_pci_auto_unconfig,
-};
-
-module_comedi_pci_driver(adv_pci1724_driver, adv_pci1724_pci_driver);
-
-/* Allocate and initialize the subdevice structures.
- */
-static int setup_subdevices(struct comedi_device *dev)
-{
-       struct comedi_subdevice *s;
-       int ret;
-
-       ret = comedi_alloc_subdevices(dev, 3);
-       if (ret)
-               return ret;
-
-       /* analog output subdevice */
-       s = &dev->subdevices[0];
-       s->type = COMEDI_SUBD_AO;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
-       s->n_chan = NUM_AO_CHANNELS;
-       s->maxdata = 0x3fff;
-       s->range_table_list = ao_range_list_1724;
-       s->insn_read = ao_readback_insn;
-       s->insn_write = ao_winsn;
-
-       /* offset calibration */
-       s = &dev->subdevices[1];
-       s->type = COMEDI_SUBD_CALIB;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-       s->n_chan = NUM_AO_CHANNELS;
-       s->insn_read = offset_read_insn;
-       s->insn_write = offset_write_insn;
-       s->maxdata = 0x3fff;
-
-       /* gain calibration */
-       s = &dev->subdevices[2];
-       s->type = COMEDI_SUBD_CALIB;
-       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
-       s->n_chan = NUM_AO_CHANNELS;
-       s->insn_read = gain_read_insn;
-       s->insn_write = gain_write_insn;
-       s->maxdata = 0x3fff;
-
-       return 0;
-}
-
-static int adv_pci1724_auto_attach(struct comedi_device *dev,
-                                  unsigned long context_unused)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-       struct adv_pci1724_private *devpriv;
-       int i;
-       int retval;
-       unsigned int board_id;
-
-       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
-       if (!devpriv)
-               return -ENOMEM;
-       dev->private = devpriv;
-
-       /* init software copies of output values to indicate we don't know
-        * what the output value is since it has never been written. */
-       for (i = 0; i < NUM_AO_CHANNELS; ++i) {
-               devpriv->ao_value[i] = -1;
-               devpriv->offset_value[i] = -1;
-               devpriv->gain_value[i] = -1;
-       }
-
-       dev->board_name = dev->driver->driver_name;
-
-       retval = comedi_pci_enable(pcidev, dev->board_name);
-       if (retval)
-               return retval;
-
-       dev->iobase = pci_resource_start(pcidev, 2);
-       board_id = inl(dev->iobase + BOARD_ID_REG) & BOARD_ID_MASK;
-
-       retval = setup_subdevices(dev);
-       if (retval < 0)
-               return retval;
-
-       dev_info(dev->class_dev, "%s (pci %s) attached, board id: %u\n",
-                dev->board_name, pci_name(pcidev), board_id);
-       return 0;
-}
-
-static void adv_pci1724_detach(struct comedi_device *dev)
-{
-       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
-
-       if (pcidev && dev->iobase) {
-               comedi_pci_disable(pcidev);
-               dev_info(dev->class_dev, "detached\n");
-       }
-}
-
 static int wait_for_dac_idle(struct comedi_device *dev)
 {
        static const int timeout = 10000;
@@ -437,6 +294,127 @@ static int gain_read_insn(struct comedi_device *dev,
        return insn->n;
 }
 
+/* Allocate and initialize the subdevice structures.
+ */
+static int setup_subdevices(struct comedi_device *dev)
+{
+       struct comedi_subdevice *s;
+       int ret;
+
+       ret = comedi_alloc_subdevices(dev, 3);
+       if (ret)
+               return ret;
+
+       /* analog output subdevice */
+       s = &dev->subdevices[0];
+       s->type = COMEDI_SUBD_AO;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_GROUND;
+       s->n_chan = NUM_AO_CHANNELS;
+       s->maxdata = 0x3fff;
+       s->range_table_list = &ao_range_list_1724;
+       s->insn_read = ao_readback_insn;
+       s->insn_write = ao_winsn;
+
+       /* offset calibration */
+       s = &dev->subdevices[1];
+       s->type = COMEDI_SUBD_CALIB;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+       s->n_chan = NUM_AO_CHANNELS;
+       s->insn_read = offset_read_insn;
+       s->insn_write = offset_write_insn;
+       s->maxdata = 0x3fff;
+
+       /* gain calibration */
+       s = &dev->subdevices[2];
+       s->type = COMEDI_SUBD_CALIB;
+       s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
+       s->n_chan = NUM_AO_CHANNELS;
+       s->insn_read = gain_read_insn;
+       s->insn_write = gain_write_insn;
+       s->maxdata = 0x3fff;
+
+       return 0;
+}
+
+static int adv_pci1724_auto_attach(struct comedi_device *dev,
+                                  unsigned long context_unused)
+{
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+       struct adv_pci1724_private *devpriv;
+       int i;
+       int retval;
+       unsigned int board_id;
+
+       devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
+       if (!devpriv)
+               return -ENOMEM;
+       dev->private = devpriv;
+
+       /* init software copies of output values to indicate we don't know
+        * what the output value is since it has never been written. */
+       for (i = 0; i < NUM_AO_CHANNELS; ++i) {
+               devpriv->ao_value[i] = -1;
+               devpriv->offset_value[i] = -1;
+               devpriv->gain_value[i] = -1;
+       }
+
+       dev->board_name = dev->driver->driver_name;
+
+       retval = comedi_pci_enable(pcidev, dev->board_name);
+       if (retval)
+               return retval;
+
+       dev->iobase = pci_resource_start(pcidev, 2);
+       board_id = inl(dev->iobase + BOARD_ID_REG) & BOARD_ID_MASK;
+       dev_info(dev->class_dev, "board id: %d\n", board_id);
+
+       retval = setup_subdevices(dev);
+       if (retval < 0)
+               return retval;
+
+       dev_info(dev->class_dev, "%s (pci %s) attached, board id: %u\n",
+                dev->board_name, pci_name(pcidev), board_id);
+       return 0;
+}
+
+static void adv_pci1724_detach(struct comedi_device *dev)
+{
+       struct pci_dev *pcidev = comedi_to_pci_dev(dev);
+
+       if (pcidev && dev->iobase) {
+               comedi_pci_disable(pcidev);
+               dev_info(dev->class_dev, "detached\n");
+       }
+}
+
+static struct comedi_driver adv_pci1724_driver = {
+       .driver_name = "adv_pci1724",
+       .module = THIS_MODULE,
+       .auto_attach = adv_pci1724_auto_attach,
+       .detach = adv_pci1724_detach,
+};
+
+static int adv_pci1724_pci_probe(struct pci_dev *dev,
+                                const struct pci_device_id *ent)
+{
+       return comedi_pci_auto_config(dev, &adv_pci1724_driver);
+}
+
+static DEFINE_PCI_DEVICE_TABLE(adv_pci1724_pci_table) = {
+       { PCI_DEVICE(PCI_VENDOR_ID_ADVANTECH, 0x1724) },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, adv_pci1724_pci_table);
+
+static struct pci_driver adv_pci1724_pci_driver = {
+       .name = "adv_pci1724",
+       .id_table = adv_pci1724_pci_table,
+       .probe = adv_pci1724_pci_probe,
+       .remove = comedi_pci_auto_unconfig,
+};
+
+module_comedi_pci_driver(adv_pci1724_driver, adv_pci1724_pci_driver);
+
 MODULE_AUTHOR("Comedi http://www.comedi.org";);
 MODULE_DESCRIPTION("Comedi low-level driver");
 MODULE_LICENSE("GPL");
-- 
1.8.1.2

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

Reply via email to