From 309231d7a610554b02084ff7b465e43ef383a3bc Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 30 Jan 2013 15:22:44 -0700 Subject: [PATCH] staging: comedi: conditionally build in PCMCIA driver support Separate the comedi_pcmcia_* functions out of drivers.c into a new source file, comedi_pcmcia.c. This allows conditionally building support for comedi pcmcia drivers into the comedi core without the need for the #if'defery. Fix the Kconfig and Makefile appropriately. Group all the comedi_pcmcia_* prototypes into one place in comedidev.h. Protect these prototypes with an #ifdef so that building a comedi pcmcia driver without PCMCIA support will cause a build error. This will normally not happen as long as the comedi pcmcia driver is placed in the proper group in the Kconfig. Remove the #include from drivers.c. These includes are only needed by the comedi pcmcia driver support code and the pcmcia drivers. The include should occur in those files. Signed-off-by: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/Kconfig | 6 +-- drivers/staging/comedi/Makefile | 1 + drivers/staging/comedi/comedi_pcmcia.c | 73 ++++++++++++++++++++++++++ drivers/staging/comedi/comedidev.h | 48 +++++++++-------- drivers/staging/comedi/drivers.c | 32 ----------- 5 files changed, 102 insertions(+), 58 deletions(-) create mode 100644 drivers/staging/comedi/comedi_pcmcia.c diff --git a/drivers/staging/comedi/Kconfig b/drivers/staging/comedi/Kconfig index 9cc16b596e42..2da9290e3b7f 100644 --- a/drivers/staging/comedi/Kconfig +++ b/drivers/staging/comedi/Kconfig @@ -1090,11 +1090,7 @@ menuconfig COMEDI_PCMCIA_DRIVERS bool "Comedi PCMCIA drivers" depends on PCMCIA ---help--- - Enable comedi PCMCIA and PCCARD 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 PCMCIA comedi drivers. + Enable support for comedi PCMCIA drivers. if COMEDI_PCMCIA_DRIVERS diff --git a/drivers/staging/comedi/Makefile b/drivers/staging/comedi/Makefile index 5372cb1adb5c..e6dfc98f8c8e 100644 --- a/drivers/staging/comedi/Makefile +++ b/drivers/staging/comedi/Makefile @@ -1,6 +1,7 @@ comedi-y := comedi_fops.o range.o drivers.o \ comedi_buf.o comedi-$(CONFIG_COMEDI_PCI_DRIVERS) += comedi_pci.o +comedi-$(CONFIG_COMEDI_PCMCIA_DRIVERS) += comedi_pcmcia.o comedi-$(CONFIG_COMEDI_USB_DRIVERS) += comedi_usb.o comedi-$(CONFIG_PROC_FS) += proc.o comedi-$(CONFIG_COMPAT) += comedi_compat32.o diff --git a/drivers/staging/comedi/comedi_pcmcia.c b/drivers/staging/comedi/comedi_pcmcia.c new file mode 100644 index 000000000000..85229456bf28 --- /dev/null +++ b/drivers/staging/comedi/comedi_pcmcia.c @@ -0,0 +1,73 @@ +/* + * comedi_pcmcia.c + * Comedi PCMCIA 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 +#include + +#include "comedidev.h" + +/** + * comedi_pcmcia_driver_register() - Register a comedi PCMCIA driver. + * @comedi_driver: comedi_driver struct + * @pcmcia_driver: pcmcia_driver struct + * + * This function is used for the module_init() of comedi USB drivers. + * Do not call it directly, use the module_comedi_pcmcia_driver() helper + * macro instead. + */ +int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, + struct pcmcia_driver *pcmcia_driver) +{ + int ret; + + ret = comedi_driver_register(comedi_driver); + if (ret < 0) + return ret; + + ret = pcmcia_register_driver(pcmcia_driver); + if (ret < 0) { + comedi_driver_unregister(comedi_driver); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register); + +/** + * comedi_pcmcia_driver_unregister() - Unregister a comedi PCMCIA driver. + * @comedi_driver: comedi_driver struct + * @pcmcia_driver: pcmcia_driver struct + * + * This function is used for the module_exit() of comedi PCMCIA drivers. + * Do not call it directly, use the module_comedi_pcmcia_driver() helper + * macro instead. + */ +void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, + struct pcmcia_driver *pcmcia_driver) +{ + pcmcia_unregister_driver(pcmcia_driver); + comedi_driver_unregister(comedi_driver); +} +EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index 666caded363b..329b1d7bc45e 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -278,27 +278,6 @@ int comedi_driver_unregister(struct comedi_driver *); module_driver(__comedi_driver, comedi_driver_register, \ comedi_driver_unregister) -struct pcmcia_driver; - -int comedi_pcmcia_driver_register(struct comedi_driver *, - struct pcmcia_driver *); -void comedi_pcmcia_driver_unregister(struct comedi_driver *, - struct pcmcia_driver *); - -/** - * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver - * @__comedi_driver: comedi_driver struct - * @__pcmcia_driver: pcmcia_driver struct - * - * Helper macro for comedi PCMCIA 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_pcmcia_driver(__comedi_driver, __pcmcia_driver) \ - module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ - comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) - void init_polling(void); void cleanup_polling(void); void start_polling(struct comedi_device *); @@ -481,6 +460,33 @@ static inline void comedi_pci_disable(struct pci_dev *dev) #endif /* CONFIG_COMEDI_PCI_DRIVERS */ +#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS + +/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */ + +struct pcmcia_driver; + +int comedi_pcmcia_driver_register(struct comedi_driver *, + struct pcmcia_driver *); +void comedi_pcmcia_driver_unregister(struct comedi_driver *, + struct pcmcia_driver *); + +/** + * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver + * @__comedi_driver: comedi_driver struct + * @__pcmcia_driver: pcmcia_driver struct + * + * Helper macro for comedi PCMCIA 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_pcmcia_driver(__comedi_driver, __pcmcia_driver) \ + module_driver(__comedi_driver, comedi_pcmcia_driver_register, \ + comedi_pcmcia_driver_unregister, &(__pcmcia_driver)) + +#endif /* CONFIG_COMEDI_PCMCIA_DRIVERS */ + #ifdef CONFIG_COMEDI_USB_DRIVERS /* comedi_usb.c - comedi USB driver specific functions */ diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c index 4e6e8a1700f5..151e0845569e 100644 --- a/drivers/staging/comedi/drivers.c +++ b/drivers/staging/comedi/drivers.c @@ -23,8 +23,6 @@ #include #include -#include -#include #include #include #include @@ -494,33 +492,3 @@ void comedi_auto_unconfig(struct device *hardware_device) comedi_free_board_minor(minor); } EXPORT_SYMBOL_GPL(comedi_auto_unconfig); - -#if IS_ENABLED(CONFIG_PCMCIA) -int comedi_pcmcia_driver_register(struct comedi_driver *comedi_driver, - struct pcmcia_driver *pcmcia_driver) -{ - int ret; - - ret = comedi_driver_register(comedi_driver); - if (ret < 0) - return ret; - - ret = pcmcia_register_driver(pcmcia_driver); - if (ret < 0) { - comedi_driver_unregister(comedi_driver); - return ret; - } - - return 0; -} -EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_register); - -void comedi_pcmcia_driver_unregister(struct comedi_driver *comedi_driver, - struct pcmcia_driver *pcmcia_driver) -{ - pcmcia_unregister_driver(pcmcia_driver); - comedi_driver_unregister(comedi_driver); -} -EXPORT_SYMBOL_GPL(comedi_pcmcia_driver_unregister); - -#endif -- 2.39.5