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 19#include <linux/usb.h> 20 21#include "comedidev.h" 22 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/** 34 * 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/** 46 * comedi_usb_auto_config() - Configure/probe a comedi USB driver. 47 * @intf: usb_interface struct 48 * @driver: comedi_driver struct 49 * @context: driver specific data, passed to comedi_auto_config() 50 * 51 * Typically called from the usb_driver (*probe) function. 52 */ 53int comedi_usb_auto_config(struct usb_interface *intf, 54 struct comedi_driver *driver, 55 unsigned long context) 56{ 57 return comedi_auto_config(&intf->dev, driver, context); 58} 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); 117