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