From 9b315bcb6f1d45938658dec82ee356546745b217 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 5 Mar 2013 10:00:15 -0700 Subject: [PATCH] staging: comedi: cb_pcidas: use the pci id_table 'driver_data' 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 'device_id' data from the boardinfo as well the search function that was used to locate the boardinfo for the PCI device. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/cb_pcidas.c | 80 ++++++++++------------ 1 file changed, 38 insertions(+), 42 deletions(-) diff --git a/drivers/staging/comedi/drivers/cb_pcidas.c b/drivers/staging/comedi/drivers/cb_pcidas.c index 425a5a18a787..1f9316996951 100644 --- a/drivers/staging/comedi/drivers/cb_pcidas.c +++ b/drivers/staging/comedi/drivers/cb_pcidas.c @@ -231,9 +231,19 @@ enum trimpot_model { AD8402, }; +enum cb_pcidas_boardid { + BOARD_PCIDAS1602_16, + BOARD_PCIDAS1200, + BOARD_PCIDAS1602_12, + BOARD_PCIDAS1200_JR, + BOARD_PCIDAS1602_16_JR, + BOARD_PCIDAS1000, + BOARD_PCIDAS1001, + BOARD_PCIDAS1002, +}; + struct cb_pcidas_board { const char *name; - unsigned short device_id; int ai_nchan; /* Inputs in single-ended mode */ int ai_bits; /* analog input resolution */ int ai_speed; /* fastest conversion period in ns */ @@ -248,9 +258,8 @@ struct cb_pcidas_board { }; static const struct cb_pcidas_board cb_pcidas_boards[] = { - { + [BOARD_PCIDAS1602_16] = { .name = "pci-das1602/16", - .device_id = 0x1, .ai_nchan = 16, .ai_bits = 16, .ai_speed = 5000, @@ -262,9 +271,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = { .trimpot = AD8402, .has_dac08 = 1, .is_1602 = 1, - }, { + }, + [BOARD_PCIDAS1200] = { .name = "pci-das1200", - .device_id = 0xF, .ai_nchan = 16, .ai_bits = 12, .ai_speed = 3200, @@ -272,9 +281,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = { .fifo_size = 1024, .ranges = &cb_pcidas_ranges, .trimpot = AD7376, - }, { + }, + [BOARD_PCIDAS1602_12] = { .name = "pci-das1602/12", - .device_id = 0x10, .ai_nchan = 16, .ai_bits = 12, .ai_speed = 3200, @@ -285,18 +294,18 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = { .ranges = &cb_pcidas_ranges, .trimpot = AD7376, .is_1602 = 1, - }, { + }, + [BOARD_PCIDAS1200_JR] = { .name = "pci-das1200/jr", - .device_id = 0x19, .ai_nchan = 16, .ai_bits = 12, .ai_speed = 3200, .fifo_size = 1024, .ranges = &cb_pcidas_ranges, .trimpot = AD7376, - }, { + }, + [BOARD_PCIDAS1602_16_JR] = { .name = "pci-das1602/16/jr", - .device_id = 0x1C, .ai_nchan = 16, .ai_bits = 16, .ai_speed = 5000, @@ -305,18 +314,18 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = { .trimpot = AD8402, .has_dac08 = 1, .is_1602 = 1, - }, { + }, + [BOARD_PCIDAS1000] = { .name = "pci-das1000", - .device_id = 0x4C, .ai_nchan = 16, .ai_bits = 12, .ai_speed = 4000, .fifo_size = 1024, .ranges = &cb_pcidas_ranges, .trimpot = AD7376, - }, { + }, + [BOARD_PCIDAS1001] = { .name = "pci-das1001", - .device_id = 0x1a, .ai_nchan = 16, .ai_bits = 12, .ai_speed = 6800, @@ -324,9 +333,9 @@ static const struct cb_pcidas_board cb_pcidas_boards[] = { .fifo_size = 1024, .ranges = &cb_pcidas_alt_ranges, .trimpot = AD7376, - }, { + }, + [BOARD_PCIDAS1002] = { .name = "pci-das1002", - .device_id = 0x1b, .ai_nchan = 16, .ai_bits = 12, .ai_speed = 6800, @@ -1424,31 +1433,18 @@ static irqreturn_t cb_pcidas_interrupt(int irq, void *d) return IRQ_HANDLED; } -static const void *cb_pcidas_find_boardinfo(struct comedi_device *dev, - struct pci_dev *pcidev) -{ - const struct cb_pcidas_board *thisboard; - int i; - - for (i = 0; i < ARRAY_SIZE(cb_pcidas_boards); i++) { - thisboard = &cb_pcidas_boards[i]; - if (thisboard->device_id == pcidev->device) - return thisboard; - } - return NULL; -} - static int cb_pcidas_auto_attach(struct comedi_device *dev, - unsigned long context_unused) + unsigned long context) { struct pci_dev *pcidev = comedi_to_pci_dev(dev); - const struct cb_pcidas_board *thisboard; + const struct cb_pcidas_board *thisboard = NULL; struct cb_pcidas_private *devpriv; struct comedi_subdevice *s; int i; int ret; - thisboard = cb_pcidas_find_boardinfo(dev, pcidev); + if (context < ARRAY_SIZE(cb_pcidas_boards)) + thisboard = &cb_pcidas_boards[context]; if (!thisboard) return -ENODEV; dev->board_ptr = thisboard; @@ -1636,14 +1632,14 @@ static int cb_pcidas_pci_probe(struct pci_dev *dev, } static DEFINE_PCI_DEVICE_TABLE(cb_pcidas_pci_table) = { - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0001) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x000f) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0010) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x0019) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001c) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x004c) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001a) }, - { PCI_DEVICE(PCI_VENDOR_ID_CB, 0x001b) }, + { PCI_VDEVICE(CB, 0x0001), BOARD_PCIDAS1602_16 }, + { PCI_VDEVICE(CB, 0x000f), BOARD_PCIDAS1200 }, + { PCI_VDEVICE(CB, 0x0010), BOARD_PCIDAS1602_12 }, + { PCI_VDEVICE(CB, 0x0019), BOARD_PCIDAS1200_JR }, + { PCI_VDEVICE(CB, 0x001c), BOARD_PCIDAS1602_16_JR }, + { PCI_VDEVICE(CB, 0x004c), BOARD_PCIDAS1000 }, + { PCI_VDEVICE(CB, 0x001a), BOARD_PCIDAS1001 }, + { PCI_VDEVICE(CB, 0x001b), BOARD_PCIDAS1002 }, { 0 } }; MODULE_DEVICE_TABLE(pci, cb_pcidas_pci_table); -- 2.39.5