Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * comedi_usb.c
0004  * Comedi USB driver specific functions.
0005  *
0006  * COMEDI - Linux Control and Measurement Device Interface
0007  * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
0008  */
0009 
0010 #include <linux/module.h>
0011 #include <linux/comedi/comedi_usb.h>
0012 
0013 /**
0014  * comedi_to_usb_interface() - Return USB interface attached to COMEDI device
0015  * @dev: COMEDI device.
0016  *
0017  * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
0018  * a &struct device embedded in a &struct usb_interface.
0019  *
0020  * Return: Attached USB interface if @dev->hw_dev is non-%NULL.
0021  * Return %NULL if @dev->hw_dev is %NULL.
0022  */
0023 struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
0024 {
0025     return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
0026 }
0027 EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
0028 
0029 /**
0030  * comedi_to_usb_dev() - Return USB device attached to COMEDI device
0031  * @dev: COMEDI device.
0032  *
0033  * Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
0034  * a &struct device embedded in a &struct usb_interface.
0035  *
0036  * Return: USB device to which the USB interface belongs if @dev->hw_dev is
0037  * non-%NULL.  Return %NULL if @dev->hw_dev is %NULL.
0038  */
0039 struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
0040 {
0041     struct usb_interface *intf = comedi_to_usb_interface(dev);
0042 
0043     return intf ? interface_to_usbdev(intf) : NULL;
0044 }
0045 EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
0046 
0047 /**
0048  * comedi_usb_auto_config() - Configure/probe a USB COMEDI driver
0049  * @intf: USB interface.
0050  * @driver: Registered COMEDI driver.
0051  * @context: Driver specific data, passed to comedi_auto_config().
0052  *
0053  * Typically called from the usb_driver (*probe) function.  Auto-configure a
0054  * COMEDI device, using a pointer to the &struct device embedded in *@intf as
0055  * the hardware device.  The @context value gets passed through to @driver's
0056  * "auto_attach" handler.  The "auto_attach" handler may call
0057  * comedi_to_usb_interface() on the passed in COMEDI device to recover @intf.
0058  *
0059  * Return: The result of calling comedi_auto_config() (%0 on success, or
0060  * a negative error number on failure).
0061  */
0062 int comedi_usb_auto_config(struct usb_interface *intf,
0063                struct comedi_driver *driver,
0064                unsigned long context)
0065 {
0066     return comedi_auto_config(&intf->dev, driver, context);
0067 }
0068 EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
0069 
0070 /**
0071  * comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device
0072  * @intf: USB interface.
0073  *
0074  * Typically called from the usb_driver (*disconnect) function.
0075  * Auto-unconfigure a COMEDI device attached to this USB interface, using a
0076  * pointer to the &struct device embedded in *@intf as the hardware device.
0077  * The COMEDI driver's "detach" handler will be called during unconfiguration
0078  * of the COMEDI device.
0079  *
0080  * Note that the COMEDI device may have already been unconfigured using the
0081  * %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
0082  * again should be ignored.
0083  */
0084 void comedi_usb_auto_unconfig(struct usb_interface *intf)
0085 {
0086     comedi_auto_unconfig(&intf->dev);
0087 }
0088 EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
0089 
0090 /**
0091  * comedi_usb_driver_register() - Register a USB COMEDI driver
0092  * @comedi_driver: COMEDI driver to be registered.
0093  * @usb_driver: USB driver to be registered.
0094  *
0095  * This function is called from the module_init() of USB COMEDI driver modules
0096  * to register the COMEDI driver and the USB driver.  Do not call it directly,
0097  * use the module_comedi_usb_driver() helper macro instead.
0098  *
0099  * Return: %0 on success, or a negative error number on failure.
0100  */
0101 int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
0102                    struct usb_driver *usb_driver)
0103 {
0104     int ret;
0105 
0106     ret = comedi_driver_register(comedi_driver);
0107     if (ret < 0)
0108         return ret;
0109 
0110     ret = usb_register(usb_driver);
0111     if (ret < 0) {
0112         comedi_driver_unregister(comedi_driver);
0113         return ret;
0114     }
0115 
0116     return 0;
0117 }
0118 EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
0119 
0120 /**
0121  * comedi_usb_driver_unregister() - Unregister a USB COMEDI driver
0122  * @comedi_driver: COMEDI driver to be registered.
0123  * @usb_driver: USB driver to be registered.
0124  *
0125  * This function is called from the module_exit() of USB COMEDI driver modules
0126  * to unregister the USB driver and the COMEDI driver.  Do not call it
0127  * directly, use the module_comedi_usb_driver() helper macro instead.
0128  */
0129 void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
0130                   struct usb_driver *usb_driver)
0131 {
0132     usb_deregister(usb_driver);
0133     comedi_driver_unregister(comedi_driver);
0134 }
0135 EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
0136 
0137 static int __init comedi_usb_init(void)
0138 {
0139     return 0;
0140 }
0141 module_init(comedi_usb_init);
0142 
0143 static void __exit comedi_usb_exit(void)
0144 {
0145 }
0146 module_exit(comedi_usb_exit);
0147 
0148 MODULE_AUTHOR("https://www.comedi.org");
0149 MODULE_DESCRIPTION("Comedi USB interface module");
0150 MODULE_LICENSE("GPL");