Merge tag 'gpio-for-v3.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw...
[linux-2.6.git] / drivers / staging / comedi / comedi_usb.c
blob13f18bef60916ab07c5145269373ecf550aacc89
1 /*
2 * comedi_usb.c
3 * Comedi USB driver specific functions.
5 * COMEDI - Linux Control and Measurement Device Interface
6 * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/usb.h>
21 #include "comedidev.h"
23 /**
24 * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
25 * @dev: comedi_device struct
27 struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
29 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
31 EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
33 /**
34 * comedi_to_usb_dev() - comedi_device pointer to usb_device pointer.
35 * @dev: comedi_device struct
37 struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
39 struct usb_interface *intf = comedi_to_usb_interface(dev);
41 return intf ? interface_to_usbdev(intf) : NULL;
43 EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
45 /**
46 * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
47 * @intf: usb_interface struct
48 * @driver: comedi_driver struct
49 * @context: driver specific data, passed to comedi_auto_config()
51 * Typically called from the usb_driver (*probe) function.
53 int comedi_usb_auto_config(struct usb_interface *intf,
54 struct comedi_driver *driver,
55 unsigned long context)
57 return comedi_auto_config(&intf->dev, driver, context);
59 EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
61 /**
62 * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
63 * @intf: usb_interface struct
65 * Typically called from the usb_driver (*disconnect) function.
67 void comedi_usb_auto_unconfig(struct usb_interface *intf)
69 comedi_auto_unconfig(&intf->dev);
71 EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
73 /**
74 * comedi_usb_driver_register() - Register a comedi USB driver.
75 * @comedi_driver: comedi_driver struct
76 * @usb_driver: usb_driver struct
78 * This function is used for the module_init() of comedi USB drivers.
79 * Do not call it directly, use the module_comedi_usb_driver() helper
80 * macro instead.
82 int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
83 struct usb_driver *usb_driver)
85 int ret;
87 ret = comedi_driver_register(comedi_driver);
88 if (ret < 0)
89 return ret;
91 ret = usb_register(usb_driver);
92 if (ret < 0) {
93 comedi_driver_unregister(comedi_driver);
94 return ret;
97 return 0;
99 EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
102 * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
103 * @comedi_driver: comedi_driver struct
104 * @usb_driver: usb_driver struct
106 * This function is used for the module_exit() of comedi USB drivers.
107 * Do not call it directly, use the module_comedi_usb_driver() helper
108 * macro instead.
110 void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
111 struct usb_driver *usb_driver)
113 usb_deregister(usb_driver);
114 comedi_driver_unregister(comedi_driver);
116 EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);