]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - drivers/staging/comedi/comedidev.h
staging: comedi: conditionally build in PCI driver support
[mirror_ubuntu-hirsute-kernel.git] / drivers / staging / comedi / comedidev.h
index 692e1e615d443d1fa334f78f07873d118da032e7..666caded363bc983a50908225a04df95f5faa984 100644 (file)
@@ -40,8 +40,6 @@
 #include <linux/uaccess.h>
 #include <linux/io.h>
 #include <linux/timer.h>
-#include <linux/pci.h>
-#include <linux/usb.h>
 
 #include "comedi.h"
 
        COMEDI_MINORVERSION, COMEDI_MICROVERSION)
 #define COMEDI_RELEASE VERSION
 
-/*
- * PCI Vendor IDs not in <linux/pci_ids.h>
- */
-#define PCI_VENDOR_ID_KOLTER           0x1001
-#define PCI_VENDOR_ID_ICP              0x104c
-#define PCI_VENDOR_ID_AMCC             0x10e8
-#define PCI_VENDOR_ID_DT               0x1116
-#define PCI_VENDOR_ID_IOTECH           0x1616
-#define PCI_VENDOR_ID_CONTEC           0x1221
-#define PCI_VENDOR_ID_CB               0x1307  /* Measurement Computing */
-#define PCI_VENDOR_ID_ADVANTECH                0x13fe
-#define PCI_VENDOR_ID_MEILHAUS         0x1402
-#define PCI_VENDOR_ID_RTD              0x1435
-#define PCI_VENDOR_ID_ADLINK           0x144a
-#define PCI_VENDOR_ID_AMPLICON         0x14dc
-
 #define COMEDI_NUM_MINORS 0x100
 #define COMEDI_NUM_BOARD_MINORS 0x30
 #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS
 
 struct comedi_subdevice {
        struct comedi_device *device;
+       int index;
        int type;
        int n_chan;
        int subdev_flags;
@@ -250,13 +233,6 @@ static inline const void *comedi_board(const struct comedi_device *dev)
        return dev->board_ptr;
 }
 
-struct comedi_device_file_info {
-       struct comedi_device *device;
-       struct comedi_subdevice *read_subdevice;
-       struct comedi_subdevice *write_subdevice;
-       struct device *hardware_device;
-};
-
 #ifdef CONFIG_COMEDI_DEBUG
 extern int comedi_debug;
 #else
@@ -280,27 +256,7 @@ enum comedi_minor_bits {
 static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4;
 static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1;
 
-struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor);
-
-static inline struct comedi_subdevice *comedi_get_read_subdevice(
-       const struct comedi_device_file_info *info)
-{
-       if (info->read_subdevice)
-               return info->read_subdevice;
-       if (info->device == NULL)
-               return NULL;
-       return info->device->read_subdev;
-}
-
-static inline struct comedi_subdevice *comedi_get_write_subdevice(
-       const struct comedi_device_file_info *info)
-{
-       if (info->write_subdevice)
-               return info->write_subdevice;
-       if (info->device == NULL)
-               return NULL;
-       return info->device->write_subdev;
-}
+struct comedi_device *comedi_dev_from_minor(unsigned minor);
 
 int comedi_alloc_subdevices(struct comedi_device *, int);
 
@@ -322,44 +278,26 @@ int comedi_driver_unregister(struct comedi_driver *);
        module_driver(__comedi_driver, comedi_driver_register, \
                        comedi_driver_unregister)
 
-int comedi_pci_enable(struct pci_dev *, const char *);
-void comedi_pci_disable(struct pci_dev *);
+struct pcmcia_driver;
 
-int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
-void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_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_pci_driver() - Helper macro for registering a comedi PCI driver
+ * module_comedi_pcmcia_driver() - Helper macro for registering a comedi PCMCIA driver
  * @__comedi_driver: comedi_driver struct
- * @__pci_driver: pci_driver struct
+ * @__pcmcia_driver: pcmcia_driver struct
  *
- * Helper macro for comedi PCI drivers which do not do anything special
+ * 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_pci_driver(__comedi_driver, __pci_driver) \
-       module_driver(__comedi_driver, comedi_pci_driver_register, \
-                       comedi_pci_driver_unregister, &(__pci_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))
+#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);
@@ -389,10 +327,11 @@ enum subdevice_runflags {
        SRF_RUNNING = 0x08000000
 };
 
+bool comedi_is_subdevice_running(struct comedi_subdevice *s);
+
 int comedi_check_chanlist(struct comedi_subdevice *s,
                          int n,
                          unsigned int *chanlist);
-unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s);
 
 /* range stuff */
 
@@ -433,83 +372,35 @@ static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd)
                return sizeof(short);
 }
 
-/* must be used in attach to set dev->hw_dev if you wish to dma directly
-into comedi's buffer */
+/*
+ * Must set dev->hw_dev if you wish to dma directly into comedi's buffer.
+ * Also useful for retrieving a previously configured hardware device of
+ * known bus type.  Set automatically for auto-configured devices.
+ * Automatically set to NULL when detaching hardware device.
+ */
 static inline void comedi_set_hw_dev(struct comedi_device *dev,
                                     struct device *hw_dev)
 {
-       if (dev->hw_dev == hw_dev)
-               return;
-       if (dev->hw_dev)
-               put_device(dev->hw_dev);
-       dev->hw_dev = hw_dev;
-       if (dev->hw_dev) {
-               dev->hw_dev = get_device(dev->hw_dev);
-               BUG_ON(dev->hw_dev == NULL);
-       }
-}
+       struct device *old_hw_dev = dev->hw_dev;
 
-static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
-{
-       return dev->hw_dev ? to_pci_dev(dev->hw_dev) : NULL;
+       dev->hw_dev = get_device(hw_dev);
+       put_device(old_hw_dev);
 }
 
-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);
+
+unsigned int comedi_buf_read_n_available(struct comedi_async *);
+unsigned int comedi_buf_read_alloc(struct comedi_async *, unsigned int);
+unsigned int comedi_buf_read_free(struct comedi_async *, unsigned int);
+
+int comedi_buf_put(struct comedi_async *, short);
+int comedi_buf_get(struct comedi_async *, short *);
 
-int comedi_buf_put(struct comedi_async *async, short x);
-int comedi_buf_get(struct comedi_async *async, short *x);
-
-unsigned int comedi_buf_write_n_available(struct comedi_async *async);
-unsigned int comedi_buf_write_alloc(struct comedi_async *async,
-                                   unsigned int nbytes);
-unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async,
-                                          unsigned int nbytes);
-unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes);
-unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes);
-unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes);
-unsigned int comedi_buf_read_n_available(struct comedi_async *async);
 void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset,
                          const void *source, unsigned int num_bytes);
 void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset,
                            void *destination, unsigned int num_bytes);
-static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async)
-{
-       return async->buf_write_alloc_count - async->buf_write_count;
-}
-
-static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async)
-{
-       return async->buf_read_alloc_count - async->buf_read_count;
-}
-
-static inline void *comedi_aux_data(int options[], int n)
-{
-       unsigned long address;
-       unsigned long addressLow;
-       int bit_shift;
-       if (sizeof(int) >= sizeof(void *))
-               address = options[COMEDI_DEVCONF_AUX_DATA_LO];
-       else {
-               address = options[COMEDI_DEVCONF_AUX_DATA_HI];
-               bit_shift = sizeof(int) * 8;
-               address <<= bit_shift;
-               addressLow = options[COMEDI_DEVCONF_AUX_DATA_LO];
-               addressLow &= (1UL << bit_shift) - 1;
-               address |= addressLow;
-       }
-       if (n >= 1)
-               address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH];
-       if (n >= 2)
-               address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH];
-       if (n >= 3)
-               address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH];
-       BUG_ON(n > 3);
-       return (void *)address;
-}
 
 int comedi_alloc_subdevice_minor(struct comedi_device *dev,
                                 struct comedi_subdevice *s);
@@ -518,26 +409,107 @@ int comedi_auto_config(struct device *hardware_device,
                       struct comedi_driver *driver, unsigned long context);
 void comedi_auto_unconfig(struct device *hardware_device);
 
-static inline int comedi_pci_auto_config(struct pci_dev *pcidev,
-                                        struct comedi_driver *driver)
-{
-       return comedi_auto_config(&pcidev->dev, driver, 0);
-}
+#ifdef CONFIG_COMEDI_PCI_DRIVERS
+
+/* comedi_pci.c - comedi PCI driver specific functions */
+
+/*
+ * PCI Vendor IDs not in <linux/pci_ids.h>
+ */
+#define PCI_VENDOR_ID_KOLTER           0x1001
+#define PCI_VENDOR_ID_ICP              0x104c
+#define PCI_VENDOR_ID_AMCC             0x10e8
+#define PCI_VENDOR_ID_DT               0x1116
+#define PCI_VENDOR_ID_IOTECH           0x1616
+#define PCI_VENDOR_ID_CONTEC           0x1221
+#define PCI_VENDOR_ID_CB               0x1307  /* Measurement Computing */
+#define PCI_VENDOR_ID_ADVANTECH                0x13fe
+#define PCI_VENDOR_ID_MEILHAUS         0x1402
+#define PCI_VENDOR_ID_RTD              0x1435
+#define PCI_VENDOR_ID_ADLINK           0x144a
+#define PCI_VENDOR_ID_AMPLICON         0x14dc
+
+struct pci_dev;
+struct pci_driver;
+
+struct pci_dev *comedi_to_pci_dev(struct comedi_device *);
+
+int comedi_pci_enable(struct pci_dev *, const char *);
+void comedi_pci_disable(struct pci_dev *);
+
+int comedi_pci_auto_config(struct pci_dev *, struct comedi_driver *);
+void comedi_pci_auto_unconfig(struct pci_dev *);
+
+int comedi_pci_driver_register(struct comedi_driver *, struct pci_driver *);
+void comedi_pci_driver_unregister(struct comedi_driver *, struct pci_driver *);
+
+/**
+ * module_comedi_pci_driver() - Helper macro for registering a comedi PCI driver
+ * @__comedi_driver: comedi_driver struct
+ * @__pci_driver: pci_driver struct
+ *
+ * Helper macro for comedi PCI 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_pci_driver(__comedi_driver, __pci_driver) \
+       module_driver(__comedi_driver, comedi_pci_driver_register, \
+                       comedi_pci_driver_unregister, &(__pci_driver))
+
+#else
+
+/*
+ * Some of the comedi mixed ISA/PCI drivers call the PCI specific
+ * functions. Provide some dummy functions if CONFIG_COMEDI_PCI_DRIVERS
+ * is not enabled.
+ */
 
-static inline void comedi_pci_auto_unconfig(struct pci_dev *pcidev)
+static inline struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev)
 {
-       comedi_auto_unconfig(&pcidev->dev);
+       return NULL;
 }
 
-static inline int comedi_usb_auto_config(struct usb_interface *intf,
-                                        struct comedi_driver *driver)
+static inline int comedi_pci_enable(struct pci_dev *dev, const char *name)
 {
-       return comedi_auto_config(&intf->dev, driver, 0);
+       return -ENOSYS;
 }
 
-static inline void comedi_usb_auto_unconfig(struct usb_interface *intf)
+static inline void comedi_pci_disable(struct pci_dev *dev)
 {
-       comedi_auto_unconfig(&intf->dev);
 }
 
+#endif /* CONFIG_COMEDI_PCI_DRIVERS */
+
+#ifdef CONFIG_COMEDI_USB_DRIVERS
+
+/* 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 */