Commit 818f569f authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi_pci: pass comedi_device to comedi_pci_enable()

Make comedi_pci_enable() use the same parameter type as
comedi_pci_disable(). This also allows comedi_pci_enable
to automatically determine the resource name passed to
pci_request_regions().

Make sure the errno value returned is passed on instead of
assuming an errno. Also, remove any kernel noise that is
generated when the call fails.

The National Instruments drivers that use the mite module
currently enable the PCI device in the mite module. For
those drivers move the call to comedi_pci_enable into the
driver.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7f072f54
......@@ -36,18 +36,23 @@ EXPORT_SYMBOL_GPL(comedi_to_pci_dev);
/**
* comedi_pci_enable() - Enable the PCI device and request the regions.
* @pcidev: pci_dev struct
* @res_name: name for the requested reqource
* @dev: comedi_device struct
*/
int comedi_pci_enable(struct pci_dev *pcidev, const char *res_name)
int comedi_pci_enable(struct comedi_device *dev)
{
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
int rc;
if (!pcidev)
return -ENODEV;
rc = pci_enable_device(pcidev);
if (rc < 0)
return rc;
rc = pci_request_regions(pcidev, res_name);
rc = pci_request_regions(pcidev, dev->board_name
? dev->board_name
: dev->driver->driver_name);
if (rc < 0)
pci_disable_device(pcidev);
......
......@@ -384,7 +384,7 @@ struct pci_driver;
struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
int comedi_pci_enable(struct pci_dev *, const char *);
int comedi_pci_enable(struct comedi_device *);
void comedi_pci_disable(struct comedi_device *);
int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *,
......@@ -421,7 +421,7 @@ static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
return NULL;
}
static inline int comedi_pci_enable(struct pci_dev *dev, const char *name)
static inline int comedi_pci_enable(struct comedi_device *dev)
{
return -ENOSYS;
}
......
......@@ -204,7 +204,7 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
iobase = pci_resource_start(pcidev, board->dio_badr);
......
......@@ -101,7 +101,7 @@ static int addi_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -303,7 +303,7 @@ static int apci1032_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -148,7 +148,7 @@ static int apci1516_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -142,7 +142,7 @@ static int apci16xx_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -42,7 +42,7 @@ static int apci1710_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -289,7 +289,7 @@ static int apci2032_auto_attach(struct comedi_device *dev,
dev->board_name = dev->driver->driver_name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 1);
......
......@@ -90,7 +90,7 @@ static int apci2200_auto_attach(struct comedi_device *dev,
dev->board_name = dev->driver->driver_name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -70,7 +70,7 @@ static int apci3120_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
pci_set_master(pcidev);
......
......@@ -346,7 +346,7 @@ static int apci3501_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -181,7 +181,7 @@ static int pci6208_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 2);
......
......@@ -164,7 +164,7 @@ static int adl_pci7x3x_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 2);
......
......@@ -80,7 +80,7 @@ static int adl_pci8164_auto_attach(struct comedi_device *dev,
dev->board_name = dev->driver->driver_name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 2);
......
......@@ -872,7 +872,7 @@ static int pci9111_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = dev_private;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev_private->lcr_io_base = pci_resource_start(pcidev, 1);
......
......@@ -1970,12 +1970,9 @@ static int pci9118_common_attach(struct comedi_device *dev, int disable_irq,
u16 u16w;
dev->board_name = this_board->name;
ret = comedi_pci_enable(pcidev, dev->board_name);
if (ret) {
dev_err(dev->class_dev,
"cannot enable PCI device %s\n", pci_name(pcidev));
ret = comedi_pci_enable(dev);
if (ret)
return ret;
}
if (master)
pci_set_master(pcidev);
......
......@@ -1248,7 +1248,7 @@ static int pci1710_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 2);
......
......@@ -249,7 +249,7 @@ static int pci1723_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 2);
......
......@@ -360,7 +360,7 @@ static int adv_pci1724_auto_attach(struct comedi_device *dev,
dev->board_name = dev->driver->driver_name;
retval = comedi_pci_enable(pcidev, dev->board_name);
retval = comedi_pci_enable(dev);
if (retval)
return retval;
......
......@@ -1104,7 +1104,7 @@ static int pci_dio_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, this_board->main_pci_region);
......
......@@ -1950,12 +1950,11 @@ static int dio200_auto_attach(struct comedi_device *dev,
return -EINVAL;
}
thisboard = comedi_board(dev);
ret = comedi_pci_enable(pci_dev, DIO200_DRIVER_NAME);
if (ret < 0) {
dev_err(dev->class_dev,
"error! cannot enable PCI device and request regions!\n");
ret = comedi_pci_enable(dev);
if (ret)
return ret;
}
bar = thisboard->mainbar;
base = pci_resource_start(pci_dev, bar);
len = pci_resource_len(pci_dev, bar);
......
......@@ -470,12 +470,10 @@ static int pc236_pci_common_attach(struct comedi_device *dev,
comedi_set_hw_dev(dev, &pci_dev->dev);
ret = comedi_pci_enable(pci_dev, PC236_DRIVER_NAME);
if (ret < 0) {
dev_err(dev->class_dev,
"error! cannot enable PCI device and request regions!\n");
ret = comedi_pci_enable(dev);
if (ret)
return ret;
}
devpriv->lcr_iobase = pci_resource_start(pci_dev, 1);
iobase = pci_resource_start(pci_dev, 2);
return pc236_common_attach(dev, iobase, pci_dev->irq, IRQF_SHARED);
......
......@@ -249,13 +249,11 @@ static int pc263_pci_common_attach(struct comedi_device *dev,
comedi_set_hw_dev(dev, &pci_dev->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");
ret = comedi_pci_enable(dev);
if (ret)
return ret;
}
iobase = pci_resource_start(pci_dev, 2);
return pc263_common_attach(dev, iobase);
}
......
......@@ -1280,13 +1280,10 @@ static int pci224_attach_common(struct comedi_device *dev,
comedi_set_hw_dev(dev, &pci_dev->dev);
ret = comedi_pci_enable(pci_dev, DRIVER_NAME);
if (ret < 0) {
dev_err(dev->class_dev,
"error! cannot enable PCI device and request regions!\n"
);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
}
spin_lock_init(&devpriv->ao_spinlock);
devpriv->iobase1 = pci_resource_start(pci_dev, 2);
......
......@@ -2645,12 +2645,11 @@ static int pci230_attach_common(struct comedi_device *dev,
comedi_set_hw_dev(dev, &pci_dev->dev);
dev->board_name = thisboard->name;
/* Enable PCI device and reserve I/O spaces. */
if (comedi_pci_enable(pci_dev, "amplc_pci230") < 0) {
dev_err(dev->class_dev,
"failed to enable PCI device and request regions\n");
return -EIO;
}
rc = comedi_pci_enable(dev);
if (rc)
return rc;
/* Read base addresses of the PCI230's two I/O regions from PCI
* configuration register. */
iobase1 = pci_resource_start(pci_dev, 2);
......
......@@ -1455,7 +1455,7 @@ static int cb_pcidas_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
......
......@@ -4059,11 +4059,9 @@ static int auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
if (comedi_pci_enable(pcidev, dev->driver->driver_name)) {
dev_warn(dev->class_dev,
"failed to enable PCI device and request regions\n");
return -EIO;
}
retval = comedi_pci_enable(dev);
if (retval)
return retval;
pci_set_master(pcidev);
/* Initialize dev->board_name */
......
......@@ -357,7 +357,7 @@ static int cb_pcidda_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 3);
......
......@@ -222,7 +222,7 @@ static int cb_pcimdas_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
......@@ -168,7 +168,7 @@ static int cb_pcimdda_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 3);
......
......@@ -79,7 +79,7 @@ static int contec_auto_attach(struct comedi_device *dev,
dev->board_name = dev->driver->driver_name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 0);
......
......@@ -709,8 +709,8 @@ static int daqboard2000_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
result = comedi_pci_enable(pcidev, dev->driver->driver_name);
if (result < 0)
result = comedi_pci_enable(dev);
if (result)
return result;
dev->iobase = 1; /* the "detach" needs this */
......
......@@ -71,7 +71,7 @@ static int das08_pci_auto_attach(struct comedi_device *dev,
/* The das08 driver needs the board_ptr */
dev->board_ptr = &das08_pci_boards[0];
ret = comedi_pci_enable(pdev, dev->driver->driver_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pdev, 2);
......
......@@ -735,7 +735,7 @@ static int dt3000_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret < 0)
return ret;
dev->iobase = 1; /* the "detach" needs this */
......
......@@ -194,7 +194,7 @@ static int dyna_pci10xx_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 2);
......
......@@ -499,11 +499,9 @@ static int hpdi_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
if (comedi_pci_enable(pcidev, dev->board_name)) {
dev_warn(dev->class_dev,
"failed enable PCI device and request regions\n");
return -EIO;
}
retval = comedi_pci_enable(dev);
if (retval)
return retval;
dev->iobase = 1; /* the "detach" needs this */
pci_set_master(pcidev);
......
......@@ -510,7 +510,7 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
iobase = pci_resource_start(pcidev, 2);
......
......@@ -702,11 +702,11 @@ static int jr3_pci_auto_attach(struct comedi_device *dev,
}
dev->board_name = "jr3_pci";
result = comedi_pci_enable(pcidev, "jr3_pci");
if (result < 0)
result = comedi_pci_enable(dev);
if (result)
return result;
dev->iobase = 1; /* the "detach" needs this */
devpriv->iobase = ioremap(pci_resource_start(pcidev, 0),
offsetof(struct jr3_t,
channel[devpriv->n_channels]));
......
......@@ -98,7 +98,7 @@ static int cnt_auto_attach(struct comedi_device *dev,
dev->board_name = dev->driver->driver_name;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = pci_resource_start(pcidev, 0);
......
......@@ -1571,7 +1571,7 @@ static int me4000_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = info;
result = comedi_pci_enable(pcidev, dev->board_name);
result = comedi_pci_enable(dev);
if (result)
return result;
......
......@@ -511,7 +511,7 @@ static int me_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = dev_private;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1; /* detach needs this */
......
......@@ -109,11 +109,6 @@ int mite_setup2(struct mite_struct *mite, unsigned use_iodwbsr_1)
u32 csigr_bits;
unsigned unknown_dma_burst_bits;
if (comedi_pci_enable(mite->pcidev, "mite")) {
dev_err(&mite->pcidev->dev,
"error enabling mite and requesting io regions\n");
return -EIO;
}
pci_set_master(mite->pcidev);
addr = pci_resource_start(mite->pcidev, 0);
......
......@@ -336,6 +336,11 @@ static int ni6527_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
......@@ -350,7 +355,6 @@ static int ni6527_auto_attach(struct comedi_device *dev,
dev_err(dev->class_dev, "error setting up mite\n");
return ret;
}
dev->iobase = 1;
dev_info(dev->class_dev, "board: %s, ID=0x%02x\n", dev->board_name,
readb(devpriv->mite->daq_io_addr + ID_Register));
......
......@@ -600,6 +600,11 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
......@@ -614,7 +619,6 @@ static int ni_65xx_auto_attach(struct comedi_device *dev,
dev_warn(dev->class_dev, "error setting up mite\n");
return ret;
}
dev->iobase = 1;
dev->irq = mite_irq(devpriv->mite);
dev_info(dev->class_dev, "board: %s, ID=0x%02x", dev->board_name,
......
......@@ -1174,6 +1174,11 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
ret = ni_660x_allocate_private(dev);
if (ret < 0)
return ret;
......@@ -1188,7 +1193,6 @@ static int ni_660x_auto_attach(struct comedi_device *dev,
dev_warn(dev->class_dev, "error setting up mite\n");
return ret;
}
dev->iobase = 1;
ret = ni_660x_alloc_mite_rings(dev);
if (ret < 0)
......
......@@ -208,6 +208,11 @@ static int ni_670x_auto_attach(struct comedi_device *dev,
dev->board_ptr = thisboard;
dev->board_name = thisboard->name;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
......@@ -222,7 +227,6 @@ static int ni_670x_auto_attach(struct comedi_device *dev,
dev_warn(dev->class_dev, "error setting up mite\n");
return ret;
}
dev->iobase = 1;
ret = comedi_alloc_subdevices(dev, 2);
if (ret)
......
......@@ -708,6 +708,11 @@ static int labpc_auto_attach(struct comedi_device *dev,
if (!IS_ENABLED(CONFIG_COMEDI_PCI_DRIVERS))
return -ENODEV;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
......@@ -722,7 +727,6 @@ static int labpc_auto_attach(struct comedi_device *dev,
ret = mite_setup(devpriv->mite);
if (ret < 0)
return ret;
dev->iobase = 1;
iobase = (unsigned long)devpriv->mite->daq_io_addr;
irq = mite_irq(devpriv->mite);
return labpc_common_attach(dev, iobase, irq, 0);
......
......@@ -1112,6 +1112,11 @@ static int nidio_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
devpriv = kzalloc(sizeof(*devpriv), GFP_KERNEL);
if (!devpriv)
return -ENOMEM;
......@@ -1128,7 +1133,6 @@ static int nidio_auto_attach(struct comedi_device *dev,
dev_warn(dev->class_dev, "error setting up mite\n");
return ret;
}
dev->iobase = 1;
devpriv->di_mite_ring = mite_alloc_ring(devpriv->mite);
if (devpriv->di_mite_ring == NULL)
......
......@@ -1488,6 +1488,11 @@ static int pcimio_auto_attach(struct comedi_device *dev,
dev->board_ptr = board;
dev->board_name = board->name;
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1;
ret = ni_alloc_private(dev);
if (ret)
return ret;
......@@ -1514,7 +1519,6 @@ static int pcimio_auto_attach(struct comedi_device *dev,
pr_warn("error setting up mite\n");
return ret;
}
dev->iobase = 1;
devpriv->ai_mite_ring = mite_alloc_ring(devpriv->mite);
if (devpriv->ai_mite_ring == NULL)
......
......@@ -1283,7 +1283,7 @@ static int rtd_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1; /* the "detach" needs this */
......
......@@ -2673,7 +2673,7 @@ static int s626_auto_attach(struct comedi_device *dev,
return -ENOMEM;
dev->private = devpriv;
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
dev->iobase = 1; /* detach needs this */
......
......@@ -567,7 +567,7 @@ static int skel_auto_attach(struct comedi_device *dev,
dev->private = devpriv;
/* Enable the PCI device. */
ret = comedi_pci_enable(pcidev, dev->board_name);
ret = comedi_pci_enable(dev);
if (ret)
return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment