aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2013-01-30 17:21:49 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-31 04:35:48 -0500
commitabac8b54a353b9a1ac7d09ff790812655f618896 (patch)
tree987dc914a3b1a8aadb7559db0101ebf3a9a79e63
parentae5943de8c8c4438cbac5cda599ff0b88c224468 (diff)
staging: comedi: conditionally build in USB driver support
Separate the comedi_usb_* functions out of drivers.c into a new source file, comedi_usb.c. This allows conditionally building support for comedi USB drivers into the comedi core without the need for the #if'defery. Fix the Kconfig and Makefile appropriately. For aesthetic reasons, add some whitespace to the Makefile to keep everything lined up. Group all the comedi_usb_* prototypes into one place in comedidev.h. Protect these prototypes with an #ifdef so that building a comedi usb driver without USB support will cause a build error. This will normally not happen as long as the comedi USB driver is placed in the proper group in the Kconfig. Remove the #include<linux/usb.h> from comedidev.h and drivers.c. This include is only needed by the comedi USB driver support code and the USB drivers. The include should occur in those files. Removing the include of usb.h exposed a couple drivers that need <linux/interrupt.h> and <linux/sched.h>. Add the missing includes. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/comedi/Kconfig6
-rw-r--r--drivers/staging/comedi/Makefile15
-rw-r--r--drivers/staging/comedi/comedi_usb.c106
-rw-r--r--drivers/staging/comedi/comedidev.h64
-rw-r--r--drivers/staging/comedi/drivers.c32
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_1032.c2
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_2032.c2
-rw-r--r--drivers/staging/comedi/drivers/addi_apci_3501.c3
8 files changed, 151 insertions, 79 deletions
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
1175 bool "Comedi USB drivers" 1175 bool "Comedi USB drivers"
1176 depends on USB 1176 depends on USB
1177 ---help--- 1177 ---help---
1178 Enable comedi USB drivers to be built 1178 Enable support for comedi USB drivers.
1179
1180 Note that the answer to this question won't directly affect the
1181 kernel: saying N will just cause the configurator to skip all
1182 the questions about USB comedi drivers.
1183 1179
1184if COMEDI_USB_DRIVERS 1180if COMEDI_USB_DRIVERS
1185 1181
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 @@
1comedi-y := comedi_fops.o range.o drivers.o \ 1comedi-y := comedi_fops.o range.o drivers.o \
2 comedi_buf.o 2 comedi_buf.o
3comedi-$(CONFIG_PROC_FS) += proc.o 3comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o
4comedi-$(CONFIG_COMPAT) += comedi_compat32.o 4comedi-$(CONFIG_PROC_FS) += proc.o
5comedi-$(CONFIG_COMPAT) += comedi_compat32.o
5 6
6obj-$(CONFIG_COMEDI) += comedi.o 7obj-$(CONFIG_COMEDI) += comedi.o
7 8
8obj-$(CONFIG_COMEDI) += kcomedilib/ 9obj-$(CONFIG_COMEDI) += kcomedilib/
9obj-$(CONFIG_COMEDI) += drivers/ 10obj-$(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 @@
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 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/usb.h>
24
25#include "comedidev.h"
26
27/**
28 * comedi_to_usb_interface() - comedi_device pointer to usb_interface pointer.
29 * @dev: comedi_device struct
30 */
31struct usb_interface *comedi_to_usb_interface(struct comedi_device *dev)
32{
33 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
34}
35EXPORT_SYMBOL_GPL(comedi_to_usb_interface);
36
37/**
38 * comedi_usb_auto_config() - Configure/probe a comedi USB driver.
39 * @intf: usb_interface struct
40 * @driver: comedi_driver struct
41 *
42 * Typically called from the usb_driver (*probe) function.
43 */
44int comedi_usb_auto_config(struct usb_interface *intf,
45 struct comedi_driver *driver)
46{
47 return comedi_auto_config(&intf->dev, driver, 0);
48}
49EXPORT_SYMBOL_GPL(comedi_usb_auto_config);
50
51/**
52 * comedi_pci_auto_unconfig() - Unconfigure/disconnect a comedi USB driver.
53 * @intf: usb_interface struct
54 *
55 * Typically called from the usb_driver (*disconnect) function.
56 */
57void comedi_usb_auto_unconfig(struct usb_interface *intf)
58{
59 comedi_auto_unconfig(&intf->dev);
60}
61EXPORT_SYMBOL_GPL(comedi_usb_auto_unconfig);
62
63/**
64 * comedi_usb_driver_register() - Register a comedi USB driver.
65 * @comedi_driver: comedi_driver struct
66 * @usb_driver: usb_driver struct
67 *
68 * This function is used for the module_init() of comedi USB drivers.
69 * Do not call it directly, use the module_comedi_usb_driver() helper
70 * macro instead.
71 */
72int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
73 struct usb_driver *usb_driver)
74{
75 int ret;
76
77 ret = comedi_driver_register(comedi_driver);
78 if (ret < 0)
79 return ret;
80
81 ret = usb_register(usb_driver);
82 if (ret < 0) {
83 comedi_driver_unregister(comedi_driver);
84 return ret;
85 }
86
87 return 0;
88}
89EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
90
91/**
92 * comedi_usb_driver_unregister() - Unregister a comedi USB driver.
93 * @comedi_driver: comedi_driver struct
94 * @usb_driver: usb_driver struct
95 *
96 * This function is used for the module_exit() of comedi USB drivers.
97 * Do not call it directly, use the module_comedi_usb_driver() helper
98 * macro instead.
99 */
100void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
101 struct usb_driver *usb_driver)
102{
103 usb_deregister(usb_driver);
104 comedi_driver_unregister(comedi_driver);
105}
106EXPORT_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 @@
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/timer.h> 42#include <linux/timer.h>
43#include <linux/pci.h> 43#include <linux/pci.h>
44#include <linux/usb.h>
45 44
46#include "comedi.h" 45#include "comedi.h"
47 46
@@ -337,25 +336,6 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *,
337 module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ 336 module_driver(__comedi_driver, comedi_pcmcia_driver_register, \
338 comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) 337 comedi_pcmcia_driver_unregister, &(__pcmcia_driver))
339 338
340struct usb_driver;
341
342int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
343void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
344
345/**
346 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
347 * @__comedi_driver: comedi_driver struct
348 * @__usb_driver: usb_driver struct
349 *
350 * Helper macro for comedi USB drivers which do not do anything special
351 * in module init/exit. This eliminates a lot of boilerplate. Each
352 * module may only use this macro once, and calling it replaces
353 * module_init() and module_exit()
354 */
355#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \
356 module_driver(__comedi_driver, comedi_usb_driver_register, \
357 comedi_usb_driver_unregister, &(__usb_driver))
358
359void init_polling(void); 339void init_polling(void);
360void cleanup_polling(void); 340void cleanup_polling(void);
361void start_polling(struct comedi_device *); 341void start_polling(struct comedi_device *);
@@ -449,12 +429,6 @@ static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
449 return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL; 429 return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
450} 430}
451 431
452static inline struct usb_interface *
453comedi_to_usb_interface(struct comedi_device *dev)
454{
455 return dev->hw_dev ? to_usb_interface(dev->hw_dev) : NULL;
456}
457
458unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int); 432unsigned int comedi_buf_write_alloc(struct comedi_async *, unsigned int);
459unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int); 433unsigned int comedi_buf_write_free(struct comedi_async *, unsigned int);
460 434
@@ -485,15 +459,35 @@ static inline int comedi_pci_auto_config(struct pci_dev *pcidev,
485 459
486void comedi_pci_auto_unconfig(struct pci_dev *pcidev); 460void comedi_pci_auto_unconfig(struct pci_dev *pcidev);
487 461
488static inline int comedi_usb_auto_config(struct usb_interface *intf, 462#ifdef CONFIG_COMEDI_USB_DRIVERS
489 struct comedi_driver *driver)
490{
491 return comedi_auto_config(&intf->dev, driver, 0);
492}
493 463
494static inline void comedi_usb_auto_unconfig(struct usb_interface *intf) 464/* comedi_usb.c - comedi USB driver specific functions */
495{ 465
496 comedi_auto_unconfig(&intf->dev); 466struct usb_driver;
497} 467struct usb_interface;
468
469struct usb_interface *comedi_to_usb_interface(struct comedi_device *);
470
471int comedi_usb_auto_config(struct usb_interface *, struct comedi_driver *);
472void comedi_usb_auto_unconfig(struct usb_interface *);
473
474int comedi_usb_driver_register(struct comedi_driver *, struct usb_driver *);
475void comedi_usb_driver_unregister(struct comedi_driver *, struct usb_driver *);
476
477/**
478 * module_comedi_usb_driver() - Helper macro for registering a comedi USB driver
479 * @__comedi_driver: comedi_driver struct
480 * @__usb_driver: usb_driver struct
481 *
482 * Helper macro for comedi USB drivers which do not do anything special
483 * in module init/exit. This eliminates a lot of boilerplate. Each
484 * module may only use this macro once, and calling it replaces
485 * module_init() and module_exit()
486 */
487#define module_comedi_usb_driver(__comedi_driver, __usb_driver) \
488 module_driver(__comedi_driver, comedi_usb_driver_register, \
489 comedi_usb_driver_unregister, &(__usb_driver))
490
491#endif /* CONFIG_COMEDI_USB_DRIVERS */
498 492
499#endif /* _COMEDIDEV_H */ 493#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 @@
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <pcmcia/cistpl.h> 27#include <pcmcia/cistpl.h>
28#include <pcmcia/ds.h> 28#include <pcmcia/ds.h>
29#include <linux/usb.h>
30#include <linux/errno.h> 29#include <linux/errno.h>
31#include <linux/kconfig.h> 30#include <linux/kconfig.h>
32#include <linux/kernel.h> 31#include <linux/kernel.h>
@@ -593,34 +592,3 @@ void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver,
593EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); 592EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister);
594 593
595#endif 594#endif
596
597#if IS_ENABLED(CONFIG_USB)
598
599int comedi_usb_driver_register(struct comedi_driver *comedi_driver,
600 struct usb_driver *usb_driver)
601{
602 int ret;
603
604 ret = comedi_driver_register(comedi_driver);
605 if (ret < 0)
606 return ret;
607
608 ret = usb_register(usb_driver);
609 if (ret < 0) {
610 comedi_driver_unregister(comedi_driver);
611 return ret;
612 }
613
614 return 0;
615}
616EXPORT_SYMBOL_GPL(comedi_usb_driver_register);
617
618void comedi_usb_driver_unregister(struct comedi_driver *comedi_driver,
619 struct usb_driver *usb_driver)
620{
621 usb_deregister(usb_driver);
622 comedi_driver_unregister(comedi_driver);
623}
624EXPORT_SYMBOL_GPL(comedi_usb_driver_unregister);
625
626#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 @@
29 * source code. 29 * source code.
30 */ 30 */
31 31
32#include <linux/interrupt.h>
33
32#include "../comedidev.h" 34#include "../comedidev.h"
33#include "comedi_fc.h" 35#include "comedi_fc.h"
34#include "amcc_s5933.h" 36#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 @@
29 * this source code. 29 * this source code.
30 */ 30 */
31 31
32#include <linux/interrupt.h>
33
32#include "../comedidev.h" 34#include "../comedidev.h"
33#include "addi_watchdog.h" 35#include "addi_watchdog.h"
34#include "comedi_fc.h" 36#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 @@
29 * this source code. 29 * this source code.
30 */ 30 */
31 31
32#include <linux/interrupt.h>
33#include <linux/sched.h>
34
32#include "../comedidev.h" 35#include "../comedidev.h"
33#include "comedi_fc.h" 36#include "comedi_fc.h"
34#include "amcc_s5933.h" 37#include "amcc_s5933.h"