H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 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. |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Ian Abbott | ba9ac25 | 2014-10-31 17:47:38 +0000 | [diff] [blame] | 19 | #include <linux/module.h> |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 20 | |
Ian Abbott | 08f6b95 | 2015-01-27 17:49:02 +0000 | [diff] [blame^] | 21 | #include "comedi_usb.h" |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer. |
| 25 | * @dev: comedi_device struct |
| 26 | */ |
| 27 | struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev) |
| 28 | { |
| 29 | return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; |
| 30 | } |
| 31 | EXPORT_SYMBOL_GPL(comedi_to_usb_interface); |
| 32 | |
| 33 | /** |
H Hartley Sweeten | 61dd149 | 2013-05-20 14:20:02 -0700 | [diff] [blame] | 34 | * comedi_to_usb_dev() - comedi_device pointer to usb_device pointer. |
| 35 | * @dev: comedi_device struct |
| 36 | */ |
| 37 | struct 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 | } |
| 43 | EXPORT_SYMBOL_GPL(comedi_to_usb_dev); |
| 44 | |
| 45 | /** |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 46 | * comedi_usb_auto_config() - Configure/probe a comedi USB driver. |
| 47 | * @intf: usb_interface struct |
| 48 | * @driver: comedi_driver struct |
H Hartley Sweeten | 55ab4f6 | 2013-02-05 17:23:40 -0700 | [diff] [blame] | 49 | * @context: driver specific data, passed to comedi_auto_config() |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 50 | * |
| 51 | * Typically called from the usb_driver (*probe) function. |
| 52 | */ |
| 53 | int comedi_usb_auto_config(struct usb_interface *intf, |
H Hartley Sweeten | 55ab4f6 | 2013-02-05 17:23:40 -0700 | [diff] [blame] | 54 | struct comedi_driver *driver, |
| 55 | unsigned long context) |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 56 | { |
H Hartley Sweeten | 55ab4f6 | 2013-02-05 17:23:40 -0700 | [diff] [blame] | 57 | return comedi_auto_config(&intf->dev, driver, context); |
H Hartley Sweeten | abac8b5 | 2013-01-30 15:21:49 -0700 | [diff] [blame] | 58 | } |
| 59 | EXPORT_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 | */ |
| 67 | void comedi_usb_auto_unconfig(struct usb_interface *intf) |
| 68 | { |
| 69 | comedi_auto_unconfig(&intf->dev); |
| 70 | } |
| 71 | EXPORT_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 | */ |
| 82 | int 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 | } |
| 99 | EXPORT_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 | */ |
| 110 | void 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 | } |
| 116 | EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister); |
Ian Abbott | ba9ac25 | 2014-10-31 17:47:38 +0000 | [diff] [blame] | 117 | |
| 118 | static int __init comedi_usb_init(void) |
| 119 | { |
| 120 | return 0; |
| 121 | } |
| 122 | module_init(comedi_usb_init); |
| 123 | |
| 124 | static void __exit comedi_usb_exit(void) |
| 125 | { |
| 126 | } |
| 127 | module_exit(comedi_usb_exit); |
| 128 | |
| 129 | MODULE_AUTHOR("http://www.comedi.org"); |
| 130 | MODULE_DESCRIPTION("Comedi USB interface module"); |
| 131 | MODULE_LICENSE("GPL"); |