diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index bb9acc969ae4..e0aa246d9948 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1175,11 +1175,7 @@ menuconfig COMEDI_USB_DRIVERS bool "Comedi USB drivers" depends on USB ---help--- - Enable comedi USB drivers to be built - - Note that the answer to this question won't directly affect the - kernel: saying N will just cause the configurator to skip all - the questions about USB comedi drivers. + Enable support for comedi USB drivers. if COMEDI_USB_DRIVERS diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index 51816c3fc268..872a87b9642e 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,9 +1,10 @@ -comedi-y := comedi_fops.o range.o drivers.o \ - comedi_buf.o -comedi-$(CONFIG_PROC_FS) += proc.o -comedi-$(CONFIG_COMPAT) += comedi_compat32.o +comedi-y := comedi_fops.o range.o drivers.o \ + comedi_buf.o +comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o +comedi-$(CONFIG_PROC_FS) += proc.o +comedi-$(CONFIG_COMPAT) += comedi_compat32.o -obj-$(CONFIG_COMEDI) += comedi.o +obj-$(CONFIG_COMEDI) += comedi.o -obj-$(CONFIG_COMEDI) += kcomedilib/ -obj-$(CONFIG_COMEDI) += drivers/ +obj-$(CONFIG_COMEDI) += kcomedilib/ +obj-$(CONFIG_COMEDI) += drivers/ diff --git a/drivers/staging/comedi/comedi_usb.c b/drivers/staging/comedi/comedi_usb.c new file mode 100644 index 000000000000..cd6abba8a2a8 --- /dev/null +++ b/drivers/staging/comedi/comedi_usb.c @@ -0,0 +1,106 @@ +/* + * comedi_usb.c + * Comedi USB driver specific functions. + * + * COMEDI - Linux Control and Measurement Device Interface + * Copyright (C) 1997-2000 David A. Schleef + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#include "comedidev.h" + +/** + * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer. + * @dev: comedi_device struct + */ +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); + +/** + * comedi_usb_auto_config() - Configure/probe a comedi USB driver. + * @intf: usb_interface struct + * @driver: comedi_driver struct + * + * Typically called from the usb_driver (*probe) function. + */ +int comedi_usb_auto_config(struct usb_interface *intf, + struct comedi_driver *driver) +{ + return comedi_auto_config(&intf->dev, driver, 0); +} +EXPORT_SYMBOL_GPL(comedi_usb_auto_config); + +/** + * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver. + * @intf: usb_interface struct + * + * Typically called from the usb_driver (*disconnect) function. + */ +void comedi_usb_auto_unconfig(struct usb_interface *intf) +{ + comedi_auto_unconfig(&intf->dev); +} +EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig); + +/** + * comedi_usb_driver_register() - Register a comedi USB driver. + * @comedi_driver: comedi_driver struct + * @usb_driver: usb_driver struct + * + * This function is used for the module_init() of comedi USB drivers. + * Do not call it directly, use the module_comedi_usb_driver() helper + * macro instead. + */ +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); + +/** + * comedi_usb_driver_unregister() - Unregister a comedi USB driver. + * @comedi_driver: comedi_driver struct + * @usb_driver: usb_driver struct + * + * This function is used for the module_exit() of comedi USB drivers. + * Do not call it directly, use the module_comedi_usb_driver() helper + * macro instead. + */ +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); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 503dd8c4b302..4fe29d5458d4 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -41,7 +41,6 @@ #include #include #include -#include #include "comedi.h" @@ -337,25 +336,6 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *, module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) -struct usb_driver; - -int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); -void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); - -/** - * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver - * @__comedi_driver: comedi_driver struct - * @__usb_driver: usb_driver struct - * - * Helper macro for comedi USB drivers which do not do anything special - * in module init/exit. This eliminates a lot of boilerplate. Each - * module may only use this macro once, and calling it replaces - * module_init() and module_exit() - */ -#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \ - module_driver(__comedi_driver, comedi_usb_driver_register, \ - comedi_usb_driver_unregister, &(__usb_driver)) - void init_polling(void); void cleanup_polling(void); void start_polling(struct comedi_device *); @@ -449,12 +429,6 @@ static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL; } -static inline struct usb_interface * -comedi_to_usb_interface(struct comedi_device *dev) -{ - return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL; -} - unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); @@ -485,15 +459,35 @@ static inline int comedi_pci_auto_config(struct pci_dev *pcidev, void comedi_pci_auto_unconfig(struct pci_dev *pcidev); -static inline int comedi_usb_auto_config(struct usb_interface *intf, - struct comedi_driver *driver) -{ - return comedi_auto_config(&intf->dev, driver, 0); -} +#ifdef CONFIG_COMEDI_USB_DRIVERS -static inline void comedi_usb_auto_unconfig(struct usb_interface *intf) -{ - comedi_auto_unconfig(&intf->dev); -} +/* comedi_usb.c - comedi USB driver specific functions */ + +struct usb_driver; +struct usb_interface; + +struct usb_interface *comedi_to_usb_interface(struct comedi_device *); + +int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *); +void comedi_usb_auto_unconfig(struct usb_interface *); + +int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *); +void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *); + +/** + * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver + * @__comedi_driver: comedi_driver struct + * @__usb_driver: usb_driver struct + * + * Helper macro for comedi USB drivers which do not do anything special + * in module init/exit. This eliminates a lot of boilerplate. Each + * module may only use this macro once, and calling it replaces + * module_init() and module_exit() + */ +#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \ + module_driver(__comedi_driver, comedi_usb_driver_register, \ + comedi_usb_driver_unregister, &(__usb_driver)) + +#endif /* CONFIG_COMEDI_USB_DRIVERS */ #endif /* _COMEDIDEV_H */ diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 87eeee58bda7..86fcd3698216 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -593,34 +592,3 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); #endif - -#if IS_ENABLED(CONFIG_USB) - -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); - -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); - -#endif diff --git a/drivers/staging/comedi/drivers/addi_apci_1032.c b/drivers/staging/comedi/drivers/addi_apci_1032.c index d2abfc2a7be5..d6c7ba6cd622 100644 --- a/drivers/staging/comedi/drivers/addi_apci_1032.c +++ b/drivers/staging/comedi/drivers/addi_apci_1032.c @@ -29,6 +29,8 @@ * source code. */ +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_2032.c b/drivers/staging/comedi/drivers/addi_apci_2032.c index 5ad9db9b84b2..15b080e737cf 100644 --- a/drivers/staging/comedi/drivers/addi_apci_2032.c +++ b/drivers/staging/comedi/drivers/addi_apci_2032.c @@ -29,6 +29,8 @@ * this source code. */ +#include + #include "../comedidev.h" #include "addi_watchdog.h" #include "comedi_fc.h" diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index 8920b96ab212..55127319bdff 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -29,6 +29,9 @@ * this source code. */ +#include +#include + #include "../comedidev.h" #include "comedi_fc.h" #include "amcc_s5933.h"