blob: 68b75e8feec0d7ba2ae6cb25dbfbf426218a7297 [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
Ian Abbott08f6b952015-01-27 17:49:02 +000021#include "comedi_usb.h"
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070022
23/**
24 * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
25 * @dev: comedi_device struct
26 */
27struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
28{
29 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
30}
31EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
32
33/**
H Hartley Sweeten61dd1492013-05-20 14:20:02 -070034 * comedi_to_usb_dev() - comedi_device pointer to usb_device pointer.
35 * @dev: comedi_device struct
36 */
37struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
38{
39 struct usb_interface *intf = comedi_to_usb_interface(dev);
40
41 return intf ? interface_to_usbdev(intf) : NULL;
42}
43EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
44
45/**
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070046 * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
47 * @intf: usb_interface struct
48 * @driver: comedi_driver struct
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -070049 * @context: driver specific data, passed to comedi_auto_config()
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070050 *
51 * Typically called from the usb_driver (*probe) function.
52 */
53int comedi_usb_auto_config(struct usb_interface *intf,
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -070054 struct comedi_driver *driver,
55 unsigned long context)
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070056{
H Hartley Sweeten55ab4f62013-02-05 17:23:40 -070057 return comedi_auto_config(&intf->dev, driver, context);
H Hartley Sweetenabac8b52013-01-30 15:21:49 -070058}
59EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
60
61/**
62 * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
63 * @intf: usb_interface struct
64 *
65 * Typically called from the usb_driver (*disconnect) function.
66 */
67void comedi_usb_auto_unconfig(struct usb_interface *intf)
68{
69 comedi_auto_unconfig(&intf->dev);
70}
71EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
72
73/**
74 * comedi_usb_driver_register() - Register a comedi USB driver.
75 * @comedi_driver: comedi_driver struct
76 * @usb_driver: usb_driver struct
77 *
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.
81 */
82int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
83 struct usb_driver *usb_driver)
84{
85 int ret;
86
87 ret = comedi_driver_register(comedi_driver);
88 if (ret < 0)
89 return ret;
90
91 ret = usb_register(usb_driver);
92 if (ret < 0) {
93 comedi_driver_unregister(comedi_driver);
94 return ret;
95 }
96
97 return 0;
98}
99EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
100
101/**
102 * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
103 * @comedi_driver: comedi_driver struct
104 * @usb_driver: usb_driver struct
105 *
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.
109 */
110void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
111 struct usb_driver *usb_driver)
112{
113 usb_deregister(usb_driver);
114 comedi_driver_unregister(comedi_driver);
115}
116EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
Ian Abbottba9ac252014-10-31 17:47:38 +0000117
118static int __init comedi_usb_init(void)
119{
120 return 0;
121}
122module_init(comedi_usb_init);
123
124static void __exit comedi_usb_exit(void)
125{
126}
127module_exit(comedi_usb_exit);
128
129MODULE_AUTHOR("http://www.comedi.org");
130MODULE_DESCRIPTION("Comedi USB interface module");
131MODULE_LICENSE("GPL");