2 * Copyright (C) 2007 Meilhaus Electronic GmbH (support@meilhaus.de)
4 * Source File : medevice.h
5 * Author : GG (Guenter Gebhardt) <support@meilhaus.de>
11 #ifndef KBUILD_MODNAME
12 # define KBUILD_MODNAME KBUILD_STR(memain)
15 #include <linux/pci.h>
16 //#include <linux/usb.h>
18 #include <linux/spinlock.h>
27 * @brief Defines a pointer type to a PCI constructor function.
29 typedef struct me_device
*(*me_pci_constructor_t
) (struct pci_dev
*);
32 * @brief Defines a pointer type to a ME-4000 PCI constructor function.
35 typedef struct me_device
*(*me_bosch_constructor_t
) (struct pci_dev
*,
40 * @brief Defines a pointer type to a USB constructor function.
42 //typedef struct me_device *(*me_usb_constructor_t)(struct usb_interface *);
45 * @brief Defines a pointer type to the dummy constructor function.
47 typedef struct me_device
*(*me_dummy_constructor_t
) (unsigned short vendor_id
,
48 unsigned short device_id
,
49 unsigned int serial_no
,
52 int dev_no
, int func_no
);
54 //extern me_usb_constructor_t mephisto_s1_constructor __attribute__ ((weak));
57 * @brief Holds the PCI device information.
59 typedef struct me_pci_info
{
60 struct pci_dev
*pci_device
; /**< Kernel PCI device structure. */
61 uint32_t reg_bases
[6]; /**< The base adresses of the PCI bars. */
62 uint32_t reg_sizes
[6]; /**< The sizes of the PCI bars. */
64 uint32_t pci_bus_no
; /**< PCI bus number. */
65 uint32_t pci_dev_no
; /**< PCI device number. */
66 uint32_t pci_func_no
; /**< PCI function number. */
68 uint16_t vendor_id
; /**< Meilhaus PCI vendor id. */
69 uint16_t device_id
; /**< Meilhaus device id. */
70 uint8_t hw_revision
; /**< Hardware revision of the device. */
71 uint32_t serial_no
; /**< Serial number of the device. */
75 * @brief Holds the USB device information.
77 //typedef struct me_usb_info {
81 * @brief The Meilhaus device base class structure.
83 typedef struct me_device
{
85 struct list_head list
; /**< Enables the device to be added to a dynamic list. */
86 // int magic; /**< The magic number of the structure. */
88 int bus_type
; /**< The descriminator for the union. */
90 me_pci_info_t pci
; /**< PCI specific device information. */
91 // me_usb_info_t usb; /**< USB specific device information. */
92 } info
; /**< Holds the device information. */
94 int irq
; /**< The irq assigned to this device. */
96 me_dlock_t dlock
; /**< The device locking structure. */
97 me_slist_t slist
; /**< The container holding all subdevices belonging to this device. */
99 char *device_name
; /**< The name of the Meilhaus device. */
100 char *device_description
; /**< The description of the Meilhaus device. */
101 char *driver_name
; /**< The name of the device driver module supporting the device family. */
104 int (*me_device_io_irq_start
) (struct me_device
* device
,
109 int irq_edge
, int irq_arg
, int flags
);
111 int (*me_device_io_irq_wait
) (struct me_device
* device
,
116 int *value
, int time_out
, int flags
);
118 int (*me_device_io_irq_stop
) (struct me_device
* device
,
120 int subdevice
, int channel
, int flags
);
122 int (*me_device_io_reset_device
) (struct me_device
* device
,
123 struct file
* filep
, int flags
);
125 int (*me_device_io_reset_subdevice
) (struct me_device
* device
,
127 int subdevice
, int flags
);
129 int (*me_device_io_single_config
) (struct me_device
* device
,
137 int trig_edge
, int flags
);
139 int (*me_device_io_single_read
) (struct me_device
* device
,
143 int *value
, int time_out
, int flags
);
145 int (*me_device_io_single_write
) (struct me_device
* device
,
149 int value
, int time_out
, int flags
);
151 int (*me_device_io_stream_config
) (struct me_device
* device
,
154 meIOStreamConfig_t
* config_list
,
156 meIOStreamTrigger_t
* trigger
,
157 int fifo_irq_threshold
, int flags
);
159 int (*me_device_io_stream_new_values
) (struct me_device
* device
,
163 int *count
, int flags
);
165 int (*me_device_io_stream_read
) (struct me_device
* device
,
169 int *values
, int *count
, int flags
);
171 int (*me_device_io_stream_start
) (struct me_device
* device
,
175 int time_out
, int flags
);
177 int (*me_device_io_stream_status
) (struct me_device
* device
,
181 int *status
, int *count
, int flags
);
183 int (*me_device_io_stream_stop
) (struct me_device
* device
,
186 int stop_mode
, int flags
);
188 int (*me_device_io_stream_write
) (struct me_device
* device
,
192 int *values
, int *count
, int flags
);
194 int (*me_device_lock_device
) (struct me_device
* device
,
195 struct file
* filep
, int lock
, int flags
);
197 int (*me_device_lock_subdevice
) (struct me_device
* device
,
199 int subdevice
, int lock
, int flags
);
201 int (*me_device_query_description_device
) (struct me_device
* device
,
204 int (*me_device_query_info_device
) (struct me_device
* device
,
211 int *func_no
, int *plugged
);
213 int (*me_device_query_name_device
) (struct me_device
* device
,
216 int (*me_device_query_name_device_driver
) (struct me_device
* device
,
219 int (*me_device_query_number_subdevices
) (struct me_device
* device
,
222 int (*me_device_query_number_channels
) (struct me_device
* device
,
223 int subdevice
, int *number
);
225 int (*me_device_query_number_ranges
) (struct me_device
* device
,
227 int unit
, int *count
);
229 int (*me_device_query_range_by_min_max
) (struct me_device
* device
,
234 int *maxdata
, int *range
);
236 int (*me_device_query_range_info
) (struct me_device
* device
,
240 int *min
, int *max
, int *maxdata
);
242 int (*me_device_query_subdevice_by_type
) (struct me_device
* device
,
245 int subtype
, int *subdevice
);
247 int (*me_device_query_subdevice_type
) (struct me_device
* device
,
249 int *type
, int *subtype
);
251 int (*me_device_query_subdevice_caps
) (struct me_device
* device
,
252 int subdevice
, int *caps
);
254 int (*me_device_query_subdevice_caps_args
) (struct me_device
* device
,
257 int *args
, int count
);
259 int (*me_device_query_timer
) (struct me_device
* device
,
263 uint64_t * min_ticks
,
264 uint64_t * max_ticks
);
266 int (*me_device_query_version_device_driver
) (struct me_device
* device
,
269 int (*me_device_config_load
) (struct me_device
* device
,
271 me_cfg_device_entry_t
* config
);
273 void (*me_device_destructor
) (struct me_device
* device
);
277 * @brief Initializes a PCI device base class structure.
279 * @param pci_device The PCI device context as handed over by kernel.
281 * @return 0 on success.
283 int me_device_pci_init(me_device_t
* me_device
, struct pci_dev
*pci_device
);
286 * @brief Initializes a USB device base class structure.
288 * @param usb_interface The USB device interface as handed over by kernel.
290 * @return 0 on success.
292 //int me_device_usb_init(me_device_t *me_device, struct usb_interface *interface);
295 * @brief Deinitializes a device base class structure and frees any previously
296 * requested resources related with this structure. It also frees any subdevice
297 * instance hold by the subdevice list.
299 * @param me_device The device class to deinitialize.
301 void me_device_deinit(me_device_t
* me_device
);