Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 317146
b: refs/heads/master
c: d8967b6
h: refs/heads/master
v: v3
  • Loading branch information
Ian Abbott authored and Greg Kroah-Hartman committed Jun 5, 2012
1 parent 0b2a84e commit 50410a4
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 47 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 04d66968b34e3e22a524064df387c9fe906c6efa
refs/heads/master: d8967b6ed676c697da3c05ab917a8eaae7a14f81
141 changes: 95 additions & 46 deletions trunk/drivers/staging/comedi/drivers/amplc_pc263.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ struct pc263_private {
struct pci_dev *pci_dev;
};

/*
* This function looks for a board matching the supplied PCI device.
*/
static const struct pc263_board *pc263_find_pci_board(struct pci_dev *pci_dev)
{
unsigned int i;

for (i = 0; i < ARRAY_SIZE(pc263_boards); i++)
if (pc263_boards[i].bustype == pci_bustype &&
pci_dev->device == pc263_boards[i].devid)
return &pc263_boards[i];
return NULL;
}


/*
* This function looks for a PCI device matching the requested board name,
* bus and slot.
Expand All @@ -124,21 +139,13 @@ pc263_find_pci(struct comedi_device *dev, int bus, int slot)
continue;
}
if (thisboard->model == anypci_model) {
/* Match any supported model. */
int i;

for (i = 0; i < ARRAY_SIZE(pc263_boards); i++) {
if (pc263_boards[i].bustype != pci_bustype)
continue;
if (pci_dev->device == pc263_boards[i].devid) {
/* Change board_ptr to matched board. */
dev->board_ptr = &pc263_boards[i];
thisboard = comedi_board(dev);
break;
}
}
if (i == ARRAY_SIZE(pc263_boards))
/* Wildcard board matches any supported PCI board. */
const struct pc263_board *foundboard;
foundboard = pc263_find_pci_board(pci_dev);
if (foundboard == NULL)
continue;
/* Replace wildcard board_ptr. */
dev->board_ptr = thisboard = foundboard;
} else {
/* Match specific model name. */
if (pci_dev->device != thisboard->devid)
Expand Down Expand Up @@ -211,6 +218,54 @@ static void pc263_report_attach(struct comedi_device *dev)
dev_info(dev->class_dev, "%s %sattached\n", dev->board_name, tmpbuf);
}

static int pc263_common_attach(struct comedi_device *dev, unsigned long iobase)
{
const struct pc263_board *thisboard = comedi_board(dev);
struct comedi_subdevice *s;
int ret;

dev->board_name = thisboard->name;
dev->iobase = iobase;

ret = alloc_subdevices(dev, 1);
if (ret < 0) {
dev_err(dev->class_dev, "error! out of memory!\n");
return ret;
}

s = dev->subdevices + 0;
/* digital output subdevice */
s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 16;
s->maxdata = 1;
s->range_table = &range_digital;
s->insn_bits = pc263_do_insn_bits;
/* read initial relay state */
s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);

pc263_report_attach(dev);
return 1;
}

static int pc263_pci_common_attach(struct comedi_device *dev,
struct pci_dev *pci_dev)
{
struct pc263_private *devpriv = dev->private;
unsigned long iobase;
int ret;

devpriv->pci_dev = pci_dev;
ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME);
if (ret < 0) {
dev_err(dev->class_dev,
"error! cannot enable PCI device and request regions!\n");
return ret;
}
iobase = pci_resource_start(pci_dev, 2);
return pc263_common_attach(dev, iobase);
}

/*
* Attach is called by the Comedi core to configure the driver
* for a particular board. If you specified a board_name array
Expand All @@ -220,73 +275,66 @@ static void pc263_report_attach(struct comedi_device *dev)
static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
const struct pc263_board *thisboard = comedi_board(dev);
struct comedi_subdevice *s;
unsigned long iobase = 0;
int ret;

dev_info(dev->class_dev, PC263_DRIVER_NAME ": attach\n");

/* Process options and reserve resources according to bus type. */
if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_ISA) &&
thisboard->bustype == isa_bustype) {
iobase = it->options[0];
unsigned long iobase = it->options[0];
ret = pc263_request_region(dev, iobase, PC263_IO_SIZE);
if (ret < 0)
return ret;
return pc263_common_attach(dev, iobase);
} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) &&
thisboard->bustype == pci_bustype) {
struct pc263_private *devpriv;
struct pci_dev *pci_dev = NULL;
struct pci_dev *pci_dev;
int bus, slot;

ret = alloc_private(dev, sizeof(struct pc263_private));
if (ret < 0) {
dev_err(dev->class_dev, "error! out of memory!\n");
return ret;
}
devpriv = dev->private;
bus = it->options[0];
slot = it->options[1];
pci_dev = pc263_find_pci(dev, bus, slot);
if (pci_dev == NULL)
return -EIO;
thisboard = comedi_board(dev); /* replaced wildcard board */
devpriv->pci_dev = pci_dev;
ret = comedi_pci_enable(pci_dev, PC263_DRIVER_NAME);
if (ret < 0) {
dev_err(dev->class_dev,
"error! cannot enable PCI device and request regions!\n");
return ret;
}
iobase = pci_resource_start(pci_dev, 2);
return pc263_pci_common_attach(dev, pci_dev);
} else {
dev_err(dev->class_dev, PC263_DRIVER_NAME
": BUG! cannot determine board type!\n");
return -EINVAL;
}
}
/*
* The attach_pci hook (if non-NULL) is called at PCI probe time in preference
* to the "manual" attach hook. dev->board_ptr is NULL on entry. There should
* be a board entry matching the supplied PCI device.
*/
static int __devinit pc263_attach_pci(struct comedi_device *dev,
struct pci_dev *pci_dev)
{
int ret;

dev->board_name = thisboard->name;
dev->iobase = iobase;
if (!IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI))
return -EINVAL;

ret = alloc_subdevices(dev, 1);
dev_info(dev->class_dev, PC263_DRIVER_NAME ": attach pci %s\n",
pci_name(pci_dev));
ret = alloc_private(dev, sizeof(struct pc263_private));
if (ret < 0) {
dev_err(dev->class_dev, "error! out of memory!\n");
return ret;
}

s = dev->subdevices + 0;
/* digital output subdevice */
s->type = COMEDI_SUBD_DO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 16;
s->maxdata = 1;
s->range_table = &range_digital;
s->insn_bits = pc263_do_insn_bits;
/* read initial relay state */
s->state = inb(dev->iobase) | (inb(dev->iobase + 1) << 8);

pc263_report_attach(dev);
return 1;
dev->board_ptr = pc263_find_pci_board(pci_dev);
if (dev->board_ptr == NULL) {
dev_err(dev->class_dev, "BUG! cannot determine board type!\n");
return -EINVAL;
}
return pc263_pci_common_attach(dev, pci_dev);
}

static void pc263_detach(struct comedi_device *dev)
Expand Down Expand Up @@ -314,6 +362,7 @@ static struct comedi_driver amplc_pc263_driver = {
.driver_name = PC263_DRIVER_NAME,
.module = THIS_MODULE,
.attach = pc263_attach,
.attach_pci = pc263_attach_pci,
.detach = pc263_detach,
.board_name = &pc263_boards[0].name,
.offset = sizeof(struct pc263_board),
Expand Down

0 comments on commit 50410a4

Please sign in to comment.