// SPDX-License-Identifier: GPL-2.0+1/*2* comedi_usb.c3* Comedi USB driver specific functions.4*5* COMEDI - Linux Control and Measurement Device Interface6* Copyright (C) 1997-2000 David A. Schleef <[email protected]>7*/89#include <linux/module.h>10#include <linux/comedi/comedi_usb.h>1112/**13* comedi_to_usb_interface() - Return USB interface attached to COMEDI device14* @dev: COMEDI device.15*16* Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a17* a &struct device embedded in a &struct usb_interface.18*19* Return: Attached USB interface if @dev->hw_dev is non-%NULL.20* Return %NULL if @dev->hw_dev is %NULL.21*/22struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)23{24return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;25}26EXPORT_SYMBOL_GPL(comedi_to_usb_interface);2728/**29* comedi_to_usb_dev() - Return USB device attached to COMEDI device30* @dev: COMEDI device.31*32* Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a33* a &struct device embedded in a &struct usb_interface.34*35* Return: USB device to which the USB interface belongs if @dev->hw_dev is36* non-%NULL. Return %NULL if @dev->hw_dev is %NULL.37*/38struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)39{40struct usb_interface *intf = comedi_to_usb_interface(dev);4142return intf ? interface_to_usbdev(intf) : NULL;43}44EXPORT_SYMBOL_GPL(comedi_to_usb_dev);4546/**47* comedi_usb_auto_config() - Configure/probe a USB COMEDI driver48* @intf: USB interface.49* @driver: Registered COMEDI driver.50* @context: Driver specific data, passed to comedi_auto_config().51*52* Typically called from the usb_driver (*probe) function. Auto-configure a53* COMEDI device, using a pointer to the &struct device embedded in *@intf as54* the hardware device. The @context value gets passed through to @driver's55* "auto_attach" handler. The "auto_attach" handler may call56* comedi_to_usb_interface() on the passed in COMEDI device to recover @intf.57*58* Return: The result of calling comedi_auto_config() (%0 on success, or59* a negative error number on failure).60*/61int comedi_usb_auto_config(struct usb_interface *intf,62struct comedi_driver *driver,63unsigned long context)64{65return comedi_auto_config(&intf->dev, driver, context);66}67EXPORT_SYMBOL_GPL(comedi_usb_auto_config);6869/**70* comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device71* @intf: USB interface.72*73* Typically called from the usb_driver (*disconnect) function.74* Auto-unconfigure a COMEDI device attached to this USB interface, using a75* pointer to the &struct device embedded in *@intf as the hardware device.76* The COMEDI driver's "detach" handler will be called during unconfiguration77* of the COMEDI device.78*79* Note that the COMEDI device may have already been unconfigured using the80* %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it81* again should be ignored.82*/83void comedi_usb_auto_unconfig(struct usb_interface *intf)84{85comedi_auto_unconfig(&intf->dev);86}87EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);8889/**90* comedi_usb_driver_register() - Register a USB COMEDI driver91* @comedi_driver: COMEDI driver to be registered.92* @usb_driver: USB driver to be registered.93*94* This function is called from the module_init() of USB COMEDI driver modules95* to register the COMEDI driver and the USB driver. Do not call it directly,96* use the module_comedi_usb_driver() helper macro instead.97*98* Return: %0 on success, or a negative error number on failure.99*/100int comedi_usb_driver_register(struct comedi_driver *comedi_driver,101struct usb_driver *usb_driver)102{103int ret;104105ret = comedi_driver_register(comedi_driver);106if (ret < 0)107return ret;108109ret = usb_register(usb_driver);110if (ret < 0) {111comedi_driver_unregister(comedi_driver);112return ret;113}114115return 0;116}117EXPORT_SYMBOL_GPL(comedi_usb_driver_register);118119/**120* comedi_usb_driver_unregister() - Unregister a USB COMEDI driver121* @comedi_driver: COMEDI driver to be registered.122* @usb_driver: USB driver to be registered.123*124* This function is called from the module_exit() of USB COMEDI driver modules125* to unregister the USB driver and the COMEDI driver. Do not call it126* directly, use the module_comedi_usb_driver() helper macro instead.127*/128void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,129struct usb_driver *usb_driver)130{131usb_deregister(usb_driver);132comedi_driver_unregister(comedi_driver);133}134EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);135136static int __init comedi_usb_init(void)137{138return 0;139}140module_init(comedi_usb_init);141142static void __exit comedi_usb_exit(void)143{144}145module_exit(comedi_usb_exit);146147MODULE_AUTHOR("https://www.comedi.org");148MODULE_DESCRIPTION("Comedi USB interface module");149MODULE_LICENSE("GPL");150151152