staging: comedi: conditionally build in USB driver support
[firefly-linux-kernel-4.4.55.git] / drivers / staging / comedi / comedi_usb.c
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.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #include <linux/usb.h>
24
25 #include "comedidev.h"
26
27 /**
28  * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
29  * @dev: comedi_device struct
30  */
31 struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
32 {
33         return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
34 }
35 EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
36
37 /**
38  * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
39  * @intf: usb_interface struct
40  * @driver: comedi_driver struct
41  *
42  * Typically called from the usb_driver (*probe) function.
43  */
44 int comedi_usb_auto_config(struct usb_interface *intf,
45                            struct comedi_driver *driver)
46 {
47         return comedi_auto_config(&intf->dev, driver, 0);
48 }
49 EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
50
51 /**
52  * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
53  * @intf: usb_interface struct
54  *
55  * Typically called from the usb_driver (*disconnect) function.
56  */
57 void comedi_usb_auto_unconfig(struct usb_interface *intf)
58 {
59         comedi_auto_unconfig(&intf->dev);
60 }
61 EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
62
63 /**
64  * comedi_usb_driver_register() - Register a comedi USB driver.
65  * @comedi_driver: comedi_driver struct
66  * @usb_driver: usb_driver struct
67  *
68  * This function is used for the module_init() of comedi USB drivers.
69  * Do not call it directly, use the module_comedi_usb_driver() helper
70  * macro instead.
71  */
72 int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
73                                struct usb_driver *usb_driver)
74 {
75         int ret;
76
77         ret = comedi_driver_register(comedi_driver);
78         if (ret < 0)
79                 return ret;
80
81         ret = usb_register(usb_driver);
82         if (ret < 0) {
83                 comedi_driver_unregister(comedi_driver);
84                 return ret;
85         }
86
87         return 0;
88 }
89 EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
90
91 /**
92  * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
93  * @comedi_driver: comedi_driver struct
94  * @usb_driver: usb_driver struct
95  *
96  * This function is used for the module_exit() of comedi USB drivers.
97  * Do not call it directly, use the module_comedi_usb_driver() helper
98  * macro instead.
99  */
100 void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
101                                   struct usb_driver *usb_driver)
102 {
103         usb_deregister(usb_driver);
104         comedi_driver_unregister(comedi_driver);
105 }
106 EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);