2017-11-07 13:58:43 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-01-30 22:21:49 +00:00
|
|
|
/*
|
|
|
|
* comedi_usb.c
|
|
|
|
* Comedi USB driver specific functions.
|
|
|
|
*
|
|
|
|
* COMEDI - Linux Control and Measurement Device Interface
|
|
|
|
* Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
|
|
|
|
*/
|
|
|
|
|
2014-10-31 17:47:38 +00:00
|
|
|
#include <linux/module.h>
|
2021-11-17 12:05:59 +00:00
|
|
|
#include <linux/comedi/comedi_usb.h>
|
2013-01-30 22:21:49 +00:00
|
|
|
|
|
|
|
/**
|
2015-09-30 16:37:13 +00:00
|
|
|
* comedi_to_usb_interface() - Return USB interface attached to COMEDI device
|
|
|
|
* @dev: COMEDI device.
|
|
|
|
*
|
|
|
|
* Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
|
|
|
|
* a &struct device embedded in a &struct usb_interface.
|
|
|
|
*
|
|
|
|
* Return: Attached USB interface if @dev->hw_dev is non-%NULL.
|
|
|
|
* Return %NULL if @dev->hw_dev is %NULL.
|
2013-01-30 22:21:49 +00:00
|
|
|
*/
|
|
|
|
struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
|
|
|
|
{
|
|
|
|
return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
|
|
|
|
|
2013-05-20 21:20:02 +00:00
|
|
|
/**
|
2015-09-30 16:37:13 +00:00
|
|
|
* comedi_to_usb_dev() - Return USB device attached to COMEDI device
|
|
|
|
* @dev: COMEDI device.
|
|
|
|
*
|
|
|
|
* Assuming @dev->hw_dev is non-%NULL, it is assumed to be pointing to a
|
|
|
|
* a &struct device embedded in a &struct usb_interface.
|
|
|
|
*
|
|
|
|
* Return: USB device to which the USB interface belongs if @dev->hw_dev is
|
|
|
|
* non-%NULL. Return %NULL if @dev->hw_dev is %NULL.
|
2013-05-20 21:20:02 +00:00
|
|
|
*/
|
|
|
|
struct usb_device *comedi_to_usb_dev(struct comedi_device *dev)
|
|
|
|
{
|
|
|
|
struct usb_interface *intf = comedi_to_usb_interface(dev);
|
|
|
|
|
|
|
|
return intf ? interface_to_usbdev(intf) : NULL;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(comedi_to_usb_dev);
|
|
|
|
|
2013-01-30 22:21:49 +00:00
|
|
|
/**
|
2015-09-30 16:37:13 +00:00
|
|
|
* comedi_usb_auto_config() - Configure/probe a USB COMEDI driver
|
|
|
|
* @intf: USB interface.
|
|
|
|
* @driver: Registered COMEDI driver.
|
|
|
|
* @context: Driver specific data, passed to comedi_auto_config().
|
2013-01-30 22:21:49 +00:00
|
|
|
*
|
2015-09-30 16:37:13 +00:00
|
|
|
* Typically called from the usb_driver (*probe) function. Auto-configure a
|
|
|
|
* COMEDI device, using a pointer to the &struct device embedded in *@intf as
|
|
|
|
* the hardware device. The @context value gets passed through to @driver's
|
|
|
|
* "auto_attach" handler. The "auto_attach" handler may call
|
|
|
|
* comedi_to_usb_interface() on the passed in COMEDI device to recover @intf.
|
|
|
|
*
|
|
|
|
* Return: The result of calling comedi_auto_config() (%0 on success, or
|
|
|
|
* a negative error number on failure).
|
2013-01-30 22:21:49 +00:00
|
|
|
*/
|
|
|
|
int comedi_usb_auto_config(struct usb_interface *intf,
|
2013-02-06 00:23:40 +00:00
|
|
|
struct comedi_driver *driver,
|
|
|
|
unsigned long context)
|
2013-01-30 22:21:49 +00:00
|
|
|
{
|
2013-02-06 00:23:40 +00:00
|
|
|
return comedi_auto_config(&intf->dev, driver, context);
|
2013-01-30 22:21:49 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
|
|
|
|
|
|
|
|
/**
|
2015-09-30 16:37:13 +00:00
|
|
|
* comedi_usb_auto_unconfig() - Unconfigure/disconnect a USB COMEDI device
|
|
|
|
* @intf: USB interface.
|
2013-01-30 22:21:49 +00:00
|
|
|
*
|
|
|
|
* Typically called from the usb_driver (*disconnect) function.
|
2015-09-30 16:37:13 +00:00
|
|
|
* Auto-unconfigure a COMEDI device attached to this USB interface, using a
|
|
|
|
* pointer to the &struct device embedded in *@intf as the hardware device.
|
|
|
|
* The COMEDI driver's "detach" handler will be called during unconfiguration
|
|
|
|
* of the COMEDI device.
|
|
|
|
*
|
|
|
|
* Note that the COMEDI device may have already been unconfigured using the
|
|
|
|
* %COMEDI_DEVCONFIG ioctl, in which case this attempt to unconfigure it
|
|
|
|
* again should be ignored.
|
2013-01-30 22:21:49 +00:00
|
|
|
*/
|
|
|
|
void comedi_usb_auto_unconfig(struct usb_interface *intf)
|
|
|
|
{
|
|
|
|
comedi_auto_unconfig(&intf->dev);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
|
|
|
|
|
|
|
|
/**
|
2015-09-30 16:37:13 +00:00
|
|
|
* comedi_usb_driver_register() - Register a USB COMEDI driver
|
|
|
|
* @comedi_driver: COMEDI driver to be registered.
|
|
|
|
* @usb_driver: USB driver to be registered.
|
|
|
|
*
|
|
|
|
* This function is called from the module_init() of USB COMEDI driver modules
|
|
|
|
* to register the COMEDI driver and the USB driver. Do not call it directly,
|
|
|
|
* use the module_comedi_usb_driver() helper macro instead.
|
2013-01-30 22:21:49 +00:00
|
|
|
*
|
2015-09-30 16:37:13 +00:00
|
|
|
* Return: %0 on success, or a negative error number on failure.
|
2013-01-30 22:21:49 +00:00
|
|
|
*/
|
|
|
|
int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
|
|
|
|
struct usb_driver *usb_driver)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = comedi_driver_register(comedi_driver);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = usb_register(usb_driver);
|
|
|
|
if (ret < 0) {
|
|
|
|
comedi_driver_unregister(comedi_driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
|
|
|
|
|
|
|
|
/**
|
2015-09-30 16:37:13 +00:00
|
|
|
* comedi_usb_driver_unregister() - Unregister a USB COMEDI driver
|
|
|
|
* @comedi_driver: COMEDI driver to be registered.
|
|
|
|
* @usb_driver: USB driver to be registered.
|
2013-01-30 22:21:49 +00:00
|
|
|
*
|
2015-09-30 16:37:13 +00:00
|
|
|
* This function is called from the module_exit() of USB COMEDI driver modules
|
|
|
|
* to unregister the USB driver and the COMEDI driver. Do not call it
|
|
|
|
* directly, use the module_comedi_usb_driver() helper macro instead.
|
2013-01-30 22:21:49 +00:00
|
|
|
*/
|
|
|
|
void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
|
|
|
|
struct usb_driver *usb_driver)
|
|
|
|
{
|
|
|
|
usb_deregister(usb_driver);
|
|
|
|
comedi_driver_unregister(comedi_driver);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
|
2014-10-31 17:47:38 +00:00
|
|
|
|
|
|
|
static int __init comedi_usb_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
module_init(comedi_usb_init);
|
|
|
|
|
|
|
|
static void __exit comedi_usb_exit(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
module_exit(comedi_usb_exit);
|
|
|
|
|
2020-07-23 19:40:53 +00:00
|
|
|
MODULE_AUTHOR("https://www.comedi.org");
|
2014-10-31 17:47:38 +00:00
|
|
|
MODULE_DESCRIPTION("Comedi USB interface module");
|
|
|
|
MODULE_LICENSE("GPL");
|