Staging: comedi: add comedi_usb_auto_[un]config functions

This will be used by the usbdux and usbduxfast drivers.

From: Bernd Porr <BerndPorr@f2s.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Frank Mori Hess <fmhess@users.sourceforge.net>
Cc: David Schleef <ds@schleef.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
Bernd Porr 2008-12-08 23:30:13 +00:00 committed by Greg Kroah-Hartman
parent 1dd33ab8a9
commit c28264dac4
3 changed files with 37 additions and 4 deletions

View file

@ -60,6 +60,8 @@ EXPORT_SYMBOL_GPL(comedi_alloc_board_minor);
EXPORT_SYMBOL_GPL(comedi_free_board_minor);
EXPORT_SYMBOL_GPL(comedi_pci_auto_config);
EXPORT_SYMBOL_GPL(comedi_pci_auto_unconfig);
EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
/* for kcomedilib */
EXPORT_SYMBOL(check_chanlist);

View file

@ -530,6 +530,9 @@ int comedi_alloc_subdevice_minor(comedi_device *dev, comedi_subdevice *s);
void comedi_free_subdevice_minor(comedi_subdevice *s);
int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name);
void comedi_pci_auto_unconfig(struct pci_dev *pcidev);
struct usb_device; /* forward declaration */
int comedi_usb_auto_config(struct usb_device *usbdev, const char *board_name);
void comedi_usb_auto_unconfig(struct usb_device *usbdev);
#include "comedi_rt.h"

View file

@ -28,6 +28,7 @@
#include <linux/device.h>
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/usb.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/sched.h>
@ -796,13 +797,21 @@ int comedi_auto_config(struct device *hardware_device, const char *board_name, c
int minor;
struct comedi_device_file_info *dev_file_info;
int retval;
unsigned *private_data = NULL;
if (!comedi_autoconfig)
return -ENODEV;
minor = comedi_alloc_board_minor(hardware_device);
if(minor < 0) return minor;
dev_set_drvdata(hardware_device, (void*)(unsigned long)minor);
private_data = kmalloc(sizeof(unsigned), GFP_KERNEL);
if (private_data == NULL) {
retval = -ENOMEM;
goto cleanup;
}
*private_data = minor;
dev_set_drvdata(hardware_device, private_data);
dev_file_info = comedi_get_device_file_info(minor);
@ -815,8 +824,11 @@ int comedi_auto_config(struct device *hardware_device, const char *board_name, c
mutex_lock(&dev_file_info->device->mutex);
retval = comedi_device_attach(dev_file_info->device, &it);
mutex_unlock(&dev_file_info->device->mutex);
cleanup:
if(retval < 0)
{
kfree(private_data);
comedi_free_board_minor(minor);
}
return retval;
@ -824,11 +836,14 @@ int comedi_auto_config(struct device *hardware_device, const char *board_name, c
void comedi_auto_unconfig(struct device *hardware_device)
{
unsigned long minor = (unsigned long)dev_get_drvdata(hardware_device);
unsigned *minor = (unsigned *)dev_get_drvdata(hardware_device);
if(minor == NULL) return;
BUG_ON(minor >= COMEDI_NUM_BOARD_MINORS);
BUG_ON(*minor >= COMEDI_NUM_BOARD_MINORS);
comedi_free_board_minor(minor);
comedi_free_board_minor(*minor);
dev_set_drvdata(hardware_device, NULL);
kfree(minor);
}
int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name)
@ -847,3 +862,16 @@ void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
{
comedi_auto_unconfig(&pcidev->dev);
}
int comedi_usb_auto_config(struct usb_device *usbdev,
const char *board_name)
{
BUG_ON(usbdev == NULL);
return comedi_auto_config(&usbdev->dev, board_name, NULL, 0);
}
void comedi_usb_auto_unconfig(struct usb_device *usbdev)
{
BUG_ON(usbdev == NULL);
comedi_auto_unconfig(&usbdev->dev);
}