diff options
Diffstat (limited to 'drivers/staging/comedi/comedidev.h')
-rw-r--r-- | drivers/staging/comedi/comedidev.h | 356 |
1 files changed, 172 insertions, 184 deletions
diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index cb67a5cb9c82..f3a990b45df5 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -40,7 +40,6 @@ #include <linux/uaccess.h> #include <linux/io.h> #include <linux/timer.h> -#include <linux/pci.h> #include "comedi.h" @@ -54,16 +53,13 @@ COMEDI_MINORVERSION, COMEDI_MICROVERSION) #define COMEDI_RELEASE VERSION -#define PCI_VENDOR_ID_ADLINK 0x144a -#define PCI_VENDOR_ID_ICP 0x104c -#define PCI_VENDOR_ID_CONTEC 0x1221 - #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; @@ -181,8 +177,6 @@ struct comedi_async { unsigned int x); }; -struct usb_interface; - struct comedi_driver { struct comedi_driver *next; @@ -190,8 +184,7 @@ struct comedi_driver { struct module *module; int (*attach) (struct comedi_device *, struct comedi_devconfig *); void (*detach) (struct comedi_device *); - int (*attach_pci) (struct comedi_device *, struct pci_dev *); - int (*attach_usb) (struct comedi_device *, struct usb_interface *); + int (*auto_attach) (struct comedi_device *, unsigned long); /* number of elements in board_name and board_id arrays */ unsigned int num_names; @@ -235,18 +228,11 @@ struct comedi_device { void (*close) (struct comedi_device *dev); }; -static inline const void *comedi_board(struct comedi_device *dev) +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 @@ -270,105 +256,13 @@ 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; -} - -int comedi_alloc_subdevices(struct comedi_device *, int); - -void comedi_device_detach(struct comedi_device *dev); -int comedi_device_attach(struct comedi_device *dev, - struct comedi_devconfig *it); -int comedi_driver_register(struct comedi_driver *); -int comedi_driver_unregister(struct comedi_driver *); - -/** - * module_comedi_driver() - Helper macro for registering a comedi driver - * @__comedi_driver: comedi_driver struct - * - * Helper macro for comedi 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_driver(__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 *); - -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)) - -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)) +struct comedi_device *comedi_dev_from_minor(unsigned minor); void init_polling(void); void cleanup_polling(void); void start_polling(struct comedi_device *); void stop_polling(struct comedi_device *); -#ifdef CONFIG_PROC_FS -void comedi_proc_init(void); -void comedi_proc_cleanup(void); -#else -static inline void comedi_proc_init(void) -{ -} - -static inline void comedi_proc_cleanup(void) -{ -} -#endif - /* subdevice runflags */ enum subdevice_runflags { SRF_USER = 0x00000001, @@ -379,10 +273,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 */ @@ -415,14 +310,6 @@ struct comedi_lrange { /* some silly little inline functions */ -static inline int alloc_private(struct comedi_device *dev, int size) -{ - dev->private = kzalloc(size, GFP_KERNEL); - if (!dev->private) - return -ENOMEM; - return 0; -} - static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) { if (subd->subdev_flags & SDF_LSAMPL) @@ -431,85 +318,186 @@ 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 */ -static inline void comedi_set_hw_dev(struct comedi_device *dev, - struct device *hw_dev) -{ - 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); - } -} +/* + * 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. + */ +int comedi_set_hw_dev(struct comedi_device *dev, struct device *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; -} +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) + +/* drivers.c - general comedi driver functions */ + +int comedi_alloc_subdevices(struct comedi_device *, int); + +int comedi_auto_config(struct device *, struct comedi_driver *, + unsigned long context); +void comedi_auto_unconfig(struct device *); + +int comedi_driver_register(struct comedi_driver *); +int comedi_driver_unregister(struct comedi_driver *); + +/** + * module_comedi_driver() - Helper macro for registering a comedi driver + * @__comedi_driver: comedi_driver struct + * + * Helper macro for comedi 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_driver(__comedi_driver) \ + module_driver(__comedi_driver, comedi_driver_register, \ + comedi_driver_unregister) + +#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_RTD 0x1435 + +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 struct pci_dev *comedi_to_pci_dev(struct comedi_device *dev) { - return async->buf_write_alloc_count - async->buf_write_count; + return NULL; } -static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) +static inline int comedi_pci_enable(struct pci_dev *dev, const char *name) { - return async->buf_read_alloc_count - async->buf_read_count; + return -ENOSYS; } -static inline void *comedi_aux_data(int options[], int n) +static inline void comedi_pci_disable(struct pci_dev *dev) { - 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); -void comedi_free_subdevice_minor(struct comedi_subdevice *s); -int comedi_pci_auto_config(struct pci_dev *pcidev, - struct comedi_driver *driver); -void comedi_pci_auto_unconfig(struct pci_dev *pcidev); -int comedi_usb_auto_config(struct usb_interface *intf, - struct comedi_driver *driver); -void comedi_usb_auto_unconfig(struct usb_interface *intf); +#endif /* CONFIG_COMEDI_PCI_DRIVERS */ + +#ifdef CONFIG_COMEDI_PCMCIA_DRIVERS + +/* comedi_pcmcia.c - comedi PCMCIA driver specific functions */ + +struct pcmcia_driver; +struct pcmcia_device; + +struct pcmcia_device *comedi_to_pcmcia_dev(struct comedi_device *); + +int comedi_pcmcia_enable(struct comedi_device *, + int (*conf_check)(struct pcmcia_device *, void *)); +void comedi_pcmcia_disable(struct comedi_device *); + +int comedi_pcmcia_auto_config(struct pcmcia_device *, struct comedi_driver *); +void comedi_pcmcia_auto_unconfig(struct pcmcia_device *); + +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 */ + +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 *, + unsigned long context); +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 */ |