Skip to content

Commit

Permalink
staging: comedi: ni_6527: use the pci id_table 'driver_data'
Browse files Browse the repository at this point in the history
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@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
H Hartley Sweeten authored and Greg Kroah-Hartman committed Mar 11, 2013
1 parent dcf9cfd commit 1787b7c
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions drivers/staging/comedi/drivers/ni_6527.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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));

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1787b7c

Please sign in to comment.