blob: 0b862a64c0493987bce20cf4d168d95aa6b46141 [file] [log] [blame]
H Hartley Sweetenabac8b52013-01-30 15:21:49 -07001/*
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.
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070017 */
18
Ian Abbottba9ac252014-10-31 17:47:38 +000019#include <linux/module.h>
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070020#include <linux/usb.h>
21
22#include "comedidev.h"
23
24/**
25 * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
26 * @dev: comedi_device struct
27 */
28struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
29{
30 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
31}
32EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
33
34/**
H Hartley Sweeten61dd1492013-05-20 14:20:02 -070035 * comedi_to_usb_dev() - comedi_device pointer to usb_device pointer.
36 * @dev: comedi_device struct
37 */
38struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
39{
40 struct usb_interface *intf = comedi_to_usb_interface(dev);
41
42 return intf ? interface_to_usbdev(intf) : NULL;
43}
44EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
45
46/**
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070047 * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
48 * @intf: usb_interface struct
49 * @driver: comedi_driver struct
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -070050 * @context: driver specific data, passed to comedi_auto_config()
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070051 *
52 * Typically called from the usb_driver (*probe) function.
53 */
54int comedi_usb_auto_config(struct usb_interface *intf,
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -070055 struct comedi_driver *driver,
56 unsigned long context)
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070057{
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -070058 return comedi_auto_config(&intf->dev, driver, context);
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070059}
60EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
61
62/**
63 * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
64 * @intf: usb_interface struct
65 *
66 * Typically called from the usb_driver (*disconnect) function.
67 */
68void comedi_usb_auto_unconfig(struct usb_interface *intf)
69{
70 comedi_auto_unconfig(&intf->dev);
71}
72EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
73
74/**
75 * comedi_usb_driver_register() - Register a comedi USB driver.
76 * @comedi_driver: comedi_driver struct
77 * @usb_driver: usb_driver struct
78 *
79 * This function is used for the module_init() of comedi USB drivers.
80 * Do not call it directly, use the module_comedi_usb_driver() helper
81 * macro instead.
82 */
83int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
84 struct usb_driver *usb_driver)
85{
86 int ret;
87
88 ret = comedi_driver_register(comedi_driver);
89 if (ret < 0)
90 return ret;
91
92 ret = usb_register(usb_driver);
93 if (ret < 0) {
94 comedi_driver_unregister(comedi_driver);
95 return ret;
96 }
97
98 return 0;
99}
100EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
101
102/**
103 * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
104 * @comedi_driver: comedi_driver struct
105 * @usb_driver: usb_driver struct
106 *
107 * This function is used for the module_exit() of comedi USB drivers.
108 * Do not call it directly, use the module_comedi_usb_driver() helper
109 * macro instead.
110 */
111void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
112 struct usb_driver *usb_driver)
113{
114 usb_deregister(usb_driver);
115 comedi_driver_unregister(comedi_driver);
116}
117EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
Ian Abbottba9ac252014-10-31 17:47:38 +0000118
119static int __init comedi_usb_init(void)
120{
121 return 0;
122}
123module_init(comedi_usb_init);
124
125static void __exit comedi_usb_exit(void)
126{
127}
128module_exit(comedi_usb_exit);
129
130MODULE_AUTHOR("http://www.comedi.org");
131MODULE_DESCRIPTION("Comedi USB interface module");
132MODULE_LICENSE("GPL");