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. This allows removing the 'dev_id' data from the boardinfo as well the search function that was used to locate the boardinfo for the PCI device. For aesthetic reasons, add some whitespace to the boardinfo. Remove the now unnecessary 'this_board' macro. Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx> Cc: Ian Abbott <abbotti@xxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/staging/comedi/drivers/ni_6527.c | 56 +++++++++++++------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/drivers/staging/comedi/drivers/ni_6527.c b/drivers/staging/comedi/drivers/ni_6527.c index 41945df..514d5db 100644 --- a/drivers/staging/comedi/drivers/ni_6527.c +++ b/drivers/staging/comedi/drivers/ni_6527.c @@ -81,25 +81,24 @@ Updated: Sat, 25 Jan 2003 13:24:40 -0800 #define Rising_Edge_Detection_Enable(x) (0x018+(x)) #define Falling_Edge_Detection_Enable(x) (0x020+(x)) -struct ni6527_board { +enum ni6527_boardid { + BOARD_PCI6527, + BOARD_PXI6527, +}; - int dev_id; +struct ni6527_board { const char *name; }; static const struct ni6527_board ni6527_boards[] = { - { - .dev_id = 0x2b20, - .name = "pci-6527", - }, - { - .dev_id = 0x2b10, - .name = "pxi-6527", - }, + [BOARD_PCI6527] = { + .name = "pci-6527", + }, + [BOARD_PXI6527] = { + .name = "pxi-6527", + }, }; -#define this_board ((const struct ni6527_board *)dev->board_ptr) - struct ni6527_private { struct mite_struct *mite; unsigned int filter_interval; @@ -321,37 +320,27 @@ static int ni6527_intr_insn_config(struct comedi_device *dev, return 2; } -static const struct ni6527_board * -ni6527_find_boardinfo(struct pci_dev *pcidev) -{ - unsigned int dev_id = pcidev->device; - unsigned int n; - - for (n = 0; n < ARRAY_SIZE(ni6527_boards); n++) { - const struct ni6527_board *board = &ni6527_boards[n]; - if (board->dev_id == dev_id) - return board; - } - return NULL; -} - static int ni6527_auto_attach(struct comedi_device *dev, - unsigned long context_unused) + unsigned long context) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); + const struct ni6527_board *board = NULL; struct ni6527_private *devpriv; struct comedi_subdevice *s; int ret; + if (context < ARRAY_SIZE(ni6527_boards)) + board = &ni6527_boards[context]; + if (!board) + return -ENODEV; + dev->board_ptr = board; + dev->board_name = board->name; + devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL); if (!devpriv) return -ENOMEM; dev->private = devpriv; - dev->board_ptr = ni6527_find_boardinfo(pcidev); - if (!dev->board_ptr) - return -ENODEV; - devpriv->mite = mite_alloc(pcidev); if (!devpriv->mite) return -ENOMEM; @@ -362,7 +351,6 @@ static int ni6527_auto_attach(struct comedi_device *dev, return ret; } - dev->board_name = this_board->name; dev_info(dev->class_dev, "board: %s, ID=0x%02x\n", dev->board_name, readb(devpriv->mite->daq_io_addr + ID_Register)); @@ -447,8 +435,8 @@ static int ni6527_pci_probe(struct pci_dev *dev, } static DEFINE_PCI_DEVICE_TABLE(ni6527_pci_table) = { - { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b10) }, - { PCI_DEVICE(PCI_VENDOR_ID_NI, 0x2b20) }, + { PCI_VDEVICE(NI, 0x2b10), BOARD_PXI6527 }, + { PCI_VDEVICE(NI, 0x2b20), BOARD_PCI6527 }, { 0 } }; MODULE_DEVICE_TABLE(pci, ni6527_pci_table); -- 1.8.1.4 _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/devel