]> git.openfabrics.org - ~shefty/rdma-dev.git/commitdiff
staging: comedi: addi_apci_3200: use the pci id_table 'driver_data'
authorH Hartley Sweeten <hsweeten@visionengravers.com>
Tue, 5 Mar 2013 17:24:43 +0000 (10:24 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 Mar 2013 17:05:23 +0000 (10:05 -0700)
Create an enum to the boardinfo and pass that enum in the pci_driver
id_table as the driver_data.

Change the macro used to fill in the device table from PCI_DEVICE()
to PCI_VDEVICE(). This allows passing the enum as the next field.

Set the dev->board_ptr before calling addi_auto_attach(). This
removes the need for the common code to search for the boardinfo.

Since the search is not done we can remove the unnecessary board
information from the comedi_driver.

For aesthetic reasons, move the pci device table near the pci_driver.

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>
drivers/staging/comedi/drivers/addi_apci_3200.c

index a28bcbdffe079f967140a888d67b08266e7b47b0..e23831bcec4db4a62a3a28a785e1f5a7e8143b28 100644 (file)
@@ -22,8 +22,13 @@ static void fpu_end(void)
 #include "addi-data/hwdrv_apci3200.c"
 #include "addi-data/addi_common.c"
 
+enum apci3200_boardid {
+       BOARD_APCI3200,
+       BOARD_APCI3300,
+};
+
 static const struct addi_board apci3200_boardtypes[] = {
-       {
+       [BOARD_APCI3200] = {
                .pc_DriverName          = "apci3200",
                .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
                .i_DeviceId             = 0x3000,
@@ -53,7 +58,8 @@ static const struct addi_board apci3200_boardtypes[] = {
                .ai_cancel              = i_APCI3200_StopCyclicAcquisition,
                .di_bits                = apci3200_di_insn_bits,
                .do_bits                = apci3200_do_insn_bits,
-       }, {
+       },
+       [BOARD_APCI3300] = {
                .pc_DriverName          = "apci3300",
                .i_VendorId             = PCI_VENDOR_ID_ADDIDATA,
                .i_DeviceId             = 0x3007,
@@ -85,21 +91,25 @@ static const struct addi_board apci3200_boardtypes[] = {
        },
 };
 
-static DEFINE_PCI_DEVICE_TABLE(apci3200_pci_table) = {
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3000) },
-       { PCI_DEVICE(PCI_VENDOR_ID_ADDIDATA, 0x3007) },
-       { 0 }
-};
-MODULE_DEVICE_TABLE(pci, apci3200_pci_table);
+static int apci3200_auto_attach(struct comedi_device *dev,
+                               unsigned long context)
+{
+       const struct addi_board *board = NULL;
+
+       if (context < ARRAY_SIZE(apci3200_boardtypes))
+               board = &apci3200_boardtypes[context];
+       if (!board)
+               return -ENODEV;
+       dev->board_ptr = board;
+
+       return addi_auto_attach(dev, context);
+}
 
 static struct comedi_driver apci3200_driver = {
        .driver_name    = "addi_apci_3200",
        .module         = THIS_MODULE,
-       .auto_attach    = addi_auto_attach,
+       .auto_attach    = apci3200_auto_attach,
        .detach         = i_ADDI_Detach,
-       .num_names      = ARRAY_SIZE(apci3200_boardtypes),
-       .board_name     = &apci3200_boardtypes[0].pc_DriverName,
-       .offset         = sizeof(struct addi_board),
 };
 
 static int apci3200_pci_probe(struct pci_dev *dev,
@@ -108,6 +118,13 @@ static int apci3200_pci_probe(struct pci_dev *dev,
        return comedi_pci_auto_config(dev, &apci3200_driver, id->driver_data);
 }
 
+static DEFINE_PCI_DEVICE_TABLE(apci3200_pci_table) = {
+       { PCI_VDEVICE(ADDIDATA, 0x3000), BOARD_APCI3200 },
+       { PCI_VDEVICE(ADDIDATA, 0x3007), BOARD_APCI3300 },
+       { 0 }
+};
+MODULE_DEVICE_TABLE(pci, apci3200_pci_table);
+
 static struct pci_driver apci3200_pci_driver = {
        .name           = "addi_apci_3200",
        .id_table       = apci3200_pci_table,