Commit | Line | Data |
---|---|---|
abac8b54 HS |
1 | /* |
2 | * comedi_usb.c | |
3 | * Comedi USB driver specific functions. | |
4 | * | |
5 | * COMEDI - Linux Control and Measurement Device Interface | |
6 | * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> | |
7 | * | |
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. | |
12 | * | |
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. | |
abac8b54 HS |
17 | */ |
18 | ||
ba9ac25e | 19 | #include <linux/module.h> |
abac8b54 | 20 | |
08f6b95b | 21 | #include "comedi_usb.h" |
abac8b54 HS |
22 | |
23 | /** | |
ddf837ea IA |
24 | * comedi_to_usb_interface() - Return USB interface attached to COMEDI device |
25 | * @dev: COMEDI device. | |
26 | * | |
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. | |
29 | * | |
30 | * Return: Attached USB interface if @dev->hw_dev is non-%NULL. | |
31 | * Return %NULL if @dev->hw_dev is %NULL. | |
abac8b54 HS |
32 | */ |
33 | struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev) | |
34 | { | |
35 | return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; | |
36 | } | |
37 | EXPORT_SYMBOL_GPL(comedi_to_usb_interface); | |
38 | ||
61dd149b | 39 | /** |
ddf837ea IA |
40 | * comedi_to_usb_dev() - Return USB device attached to COMEDI device |
41 | * @dev: COMEDI device. | |
42 | * | |
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. | |
45 | * | |
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. | |
61dd149b HS |
48 | */ |
49 | struct usb_device *comedi_to_usb_dev(struct comedi_device *dev) | |
50 | { | |
51 | struct usb_interface *intf = comedi_to_usb_interface(dev); | |
52 | ||
53 | return intf ? interface_to_usbdev(intf) : NULL; | |
54 | } | |
55 | EXPORT_SYMBOL_GPL(comedi_to_usb_dev); | |
56 | ||
abac8b54 | 57 | /** |
ddf837ea IA |
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(). | |
abac8b54 | 62 | * |
ddf837ea IA |
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. | |
68 | * | |
69 | * Return: The result of calling comedi_auto_config() (%0 on success, or | |
70 | * a negative error number on failure). | |
abac8b54 HS |
71 | */ |
72 | int comedi_usb_auto_config(struct usb_interface *intf, | |
55ab4f64 HS |
73 | struct comedi_driver *driver, |
74 | unsigned long context) | |
abac8b54 | 75 | { |
55ab4f64 | 76 | return comedi_auto_config(&intf->dev, driver, context); |
abac8b54 HS |
77 | } |
78 | EXPORT_SYMBOL_GPL(comedi_usb_auto_config); | |
79 | ||
80 | /** | |
ddf837ea IA |
81 | * comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device |
82 | * @intf: USB interface. | |
abac8b54 HS |
83 | * |
84 | * Typically called from the usb_driver (*disconnect) function. | |
ddf837ea IA |
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. | |
89 | * | |
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. | |
abac8b54 HS |
93 | */ |
94 | void comedi_usb_auto_unconfig(struct usb_interface *intf) | |
95 | { | |
96 | comedi_auto_unconfig(&intf->dev); | |
97 | } | |
98 | EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig); | |
99 | ||
100 | /** | |
ddf837ea IA |
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. | |
104 | * | |
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. | |
abac8b54 | 108 | * |
ddf837ea | 109 | * Return: %0 on success, or a negative error number on failure. |
abac8b54 HS |
110 | */ |
111 | int comedi_usb_driver_register(struct comedi_driver *comedi_driver, | |
112 | struct usb_driver *usb_driver) | |
113 | { | |
114 | int ret; | |
115 | ||
116 | ret = comedi_driver_register(comedi_driver); | |
117 | if (ret < 0) | |
118 | return ret; | |
119 | ||
120 | ret = usb_register(usb_driver); | |
121 | if (ret < 0) { | |
122 | comedi_driver_unregister(comedi_driver); | |
123 | return ret; | |
124 | } | |
125 | ||
126 | return 0; | |
127 | } | |
128 | EXPORT_SYMBOL_GPL(comedi_usb_driver_register); | |
129 | ||
130 | /** | |
ddf837ea IA |
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. | |
abac8b54 | 134 | * |
ddf837ea IA |
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. | |
abac8b54 HS |
138 | */ |
139 | void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver, | |
140 | struct usb_driver *usb_driver) | |
141 | { | |
142 | usb_deregister(usb_driver); | |
143 | comedi_driver_unregister(comedi_driver); | |
144 | } | |
145 | EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister); | |
ba9ac25e IA |
146 | |
147 | static int __init comedi_usb_init(void) | |
148 | { | |
149 | return 0; | |
150 | } | |
151 | module_init(comedi_usb_init); | |
152 | ||
153 | static void __exit comedi_usb_exit(void) | |
154 | { | |
155 | } | |
156 | module_exit(comedi_usb_exit); | |
157 | ||
158 | MODULE_AUTHOR("http://www.comedi.org"); | |
159 | MODULE_DESCRIPTION("Comedi USB interface module"); | |
160 | MODULE_LICENSE("GPL"); |