Commit 8ed705af authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: add generic auto-config functions

Add (and export) generic auto-config function `comedi_auto_config()` to
allow hardware devices on arbitrary bus types (e.g. platform devices,
spi devices, etc.) to be auto-configured as comedi devices.  This uses a
new `auto_attach()` hook in the `struct comedi_driver`.  This new hook
will eventually replace the bus-specific `attach_pci()` and
`attach_usb()` hooks in the low-level comedi drivers.

When the `auto_attach()` hook is called in the low-level driver, the
`hw_dev` member of the `struct comedi_device` will have already been set
to the hardware device passed to `comedi_auto_config()`.  The low-level
driver can convert this to some bus-device wrapper structure pointer,
possibly with the help of the `context` parameter that is passed
unchanged from the `comedi_auto_config()` call.

Also export the existing `comedi_auto_unconfig()` function as the
matching call to `comedi_auto_config()`.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 156096a0
...@@ -204,6 +204,7 @@ struct comedi_driver { ...@@ -204,6 +204,7 @@ struct comedi_driver {
void (*detach) (struct comedi_device *); void (*detach) (struct comedi_device *);
int (*attach_pci) (struct comedi_device *, struct pci_dev *); int (*attach_pci) (struct comedi_device *, struct pci_dev *);
int (*attach_usb) (struct comedi_device *, struct usb_interface *); int (*attach_usb) (struct comedi_device *, struct usb_interface *);
int (*auto_attach) (struct comedi_device *, unsigned long);
/* number of elements in board_name and board_id arrays */ /* number of elements in board_name and board_id arrays */
unsigned int num_names; unsigned int num_names;
...@@ -510,6 +511,9 @@ static inline void *comedi_aux_data(int options[], int n) ...@@ -510,6 +511,9 @@ static inline void *comedi_aux_data(int options[], int n)
int comedi_alloc_subdevice_minor(struct comedi_device *dev, int comedi_alloc_subdevice_minor(struct comedi_device *dev,
struct comedi_subdevice *s); struct comedi_subdevice *s);
void comedi_free_subdevice_minor(struct comedi_subdevice *s); void comedi_free_subdevice_minor(struct comedi_subdevice *s);
int comedi_auto_config(struct device *hardware_device,
struct comedi_driver *driver, unsigned long context);
void comedi_auto_unconfig(struct device *hardware_device);
int comedi_pci_auto_config(struct pci_dev *pcidev, int comedi_pci_auto_config(struct pci_dev *pcidev,
struct comedi_driver *driver); struct comedi_driver *driver);
void comedi_pci_auto_unconfig(struct pci_dev *pcidev); void comedi_pci_auto_unconfig(struct pci_dev *pcidev);
......
...@@ -922,7 +922,27 @@ static int comedi_old_auto_config(struct device *hardware_device, ...@@ -922,7 +922,27 @@ static int comedi_old_auto_config(struct device *hardware_device,
(unsigned long)&it); (unsigned long)&it);
} }
static void comedi_auto_unconfig(struct device *hardware_device) static int comedi_auto_config_wrapper(struct comedi_device *dev,
unsigned long context)
{
if (!dev->driver->auto_attach) {
dev_warn(dev->class_dev,
"BUG! driver '%s' has no auto_attach handler\n",
dev->driver->driver_name);
return -EINVAL;
}
return dev->driver->auto_attach(dev, context);
}
int comedi_auto_config(struct device *hardware_device,
struct comedi_driver *driver, unsigned long context)
{
return comedi_auto_config_helper(hardware_device, driver,
comedi_auto_config_wrapper, context);
}
EXPORT_SYMBOL_GPL(comedi_auto_config);
void comedi_auto_unconfig(struct device *hardware_device)
{ {
int minor; int minor;
...@@ -934,6 +954,7 @@ static void comedi_auto_unconfig(struct device *hardware_device) ...@@ -934,6 +954,7 @@ static void comedi_auto_unconfig(struct device *hardware_device)
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS); BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
comedi_free_board_minor(minor); comedi_free_board_minor(minor);
} }
EXPORT_SYMBOL_GPL(comedi_auto_unconfig);
/** /**
* comedi_pci_enable() - Enable the PCI device and request the regions. * comedi_pci_enable() - Enable the PCI device and request the regions.
......
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