3 * Comedi USB driver specific functions.
5 * COMEDI - Linux Control and Measurement Device Interface
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/module.h>
21 #include "comedi_usb.h"
24 * comedi_to_usb_interface() - Return USB interface attached to COMEDI device
25 * @dev: COMEDI device.
27 * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
28 * a &struct device embedded in a &struct usb_interface.
30 * Return: Attached USB interface if @dev->hw_dev is non-%NULL.
31 * Return %NULL if @dev->hw_dev is %NULL.
33 struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
35 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
37 EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
40 * comedi_to_usb_dev() - Return USB device attached to COMEDI device
41 * @dev: COMEDI device.
43 * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
44 * a &struct device embedded in a &struct usb_interface.
46 * Return: USB device to which the USB interface belongs if @dev->hw_dev is
47 * non-%NULL. Return %NULL if @dev->hw_dev is %NULL.
49 struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
51 struct usb_interface *intf = comedi_to_usb_interface(dev);
53 return intf ? interface_to_usbdev(intf) : NULL;
55 EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
58 * comedi_usb_auto_config() - Configure/probe a USB COMEDI driver
59 * @intf: USB interface.
60 * @driver: Registered COMEDI driver.
61 * @context: Driver specific data, passed to comedi_auto_config().
63 * Typically called from the usb_driver (*probe) function. Auto-configure a
64 * COMEDI device, using a pointer to the &struct device embedded in *@intf as
65 * the hardware device. The @context value gets passed through to @driver's
66 * "auto_attach" handler. The "auto_attach" handler may call
67 * comedi_to_usb_interface() on the passed in COMEDI device to recover @intf.
69 * Return: The result of calling comedi_auto_config() (%0 on success, or
70 * a negative error number on failure).
72 int comedi_usb_auto_config(struct usb_interface *intf,
73 struct comedi_driver *driver,
74 unsigned long context)
76 return comedi_auto_config(&intf->dev, driver, context);
78 EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
81 * comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device
82 * @intf: USB interface.
84 * Typically called from the usb_driver (*disconnect) function.
85 * Auto-unconfigure a COMEDI device attached to this USB interface, using a
86 * pointer to the &struct device embedded in *@intf as the hardware device.
87 * The COMEDI driver's "detach" handler will be called during unconfiguration
88 * of the COMEDI device.
90 * Note that the COMEDI device may have already been unconfigured using the
91 * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
92 * again should be ignored.
94 void comedi_usb_auto_unconfig(struct usb_interface *intf)
96 comedi_auto_unconfig(&intf->dev);
98 EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
101 * comedi_usb_driver_register() - Register a USB COMEDI driver
102 * @comedi_driver: COMEDI driver to be registered.
103 * @usb_driver: USB driver to be registered.
105 * This function is called from the module_init() of USB COMEDI driver modules
106 * to register the COMEDI driver and the USB driver. Do not call it directly,
107 * use the module_comedi_usb_driver() helper macro instead.
109 * Return: %0 on success, or a negative error number on failure.
111 int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
112 struct usb_driver *usb_driver)
116 ret = comedi_driver_register(comedi_driver);
120 ret = usb_register(usb_driver);
122 comedi_driver_unregister(comedi_driver);
128 EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
131 * comedi_usb_driver_unregister() - Unregister a USB COMEDI driver
132 * @comedi_driver: COMEDI driver to be registered.
133 * @usb_driver: USB driver to be registered.
135 * This function is called from the module_exit() of USB COMEDI driver modules
136 * to unregister the USB driver and the COMEDI driver. Do not call it
137 * directly, use the module_comedi_usb_driver() helper macro instead.
139 void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
140 struct usb_driver *usb_driver)
142 usb_deregister(usb_driver);
143 comedi_driver_unregister(comedi_driver);
145 EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
147 static int __init comedi_usb_init(void)
151 module_init(comedi_usb_init);
153 static void __exit comedi_usb_exit(void)
156 module_exit(comedi_usb_exit);
158 MODULE_AUTHOR("http://www.comedi.org");
159 MODULE_DESCRIPTION("Comedi USB interface module");
160 MODULE_LICENSE("GPL");