1 From c0f005888c6663898a040cd922947dd8caa55160 Mon Sep 17 00:00:00 2001
2 From: Greg Kroah-Hartman <gregkh@suse.de>
3 Date: Fri, 21 Mar 2008 14:12:51 -0700
4 Subject: [PATCH 09/23] Staging: add me4000 pci data collection driver
7 Originally written by Guenter Gebhardt <g.gebhardt@meilhaus.de>
10 - checkpatch.pl cleanups
12 - possible /proc interaction cleanups
13 - more info needed for Kconfig entry
15 - module parameter cleanup
17 Cc: Wolfgang Beiter <w.beiter@aon.at>
18 Cc: Guenter Gebhardt <g.gebhardt@meilhaus.de>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
21 drivers/staging/Kconfig | 2 +
22 drivers/staging/Makefile | 1 +
23 drivers/staging/me4000/Kconfig | 10 +
24 drivers/staging/me4000/Makefile | 1 +
25 drivers/staging/me4000/README | 13 +
26 drivers/staging/me4000/me4000.c | 6133 +++++++++++++++++++++++++++++++++++++++
27 drivers/staging/me4000/me4000.h | 954 ++++++
28 7 files changed, 7114 insertions(+), 0 deletions(-)
29 create mode 100644 drivers/staging/me4000/Kconfig
30 create mode 100644 drivers/staging/me4000/Makefile
31 create mode 100644 drivers/staging/me4000/README
32 create mode 100644 drivers/staging/me4000/me4000.c
33 create mode 100644 drivers/staging/me4000/me4000.h
35 diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
36 index 6da7662..56c73bc 100644
37 --- a/drivers/staging/Kconfig
38 +++ b/drivers/staging/Kconfig
39 @@ -29,4 +29,6 @@ source "drivers/staging/slicoss/Kconfig"
41 source "drivers/staging/sxg/Kconfig"
43 +source "drivers/staging/me4000/Kconfig"
46 diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
47 index cd6d6a5..97df19b 100644
48 --- a/drivers/staging/Makefile
49 +++ b/drivers/staging/Makefile
51 obj-$(CONFIG_ET131X) += et131x/
52 obj-$(CONFIG_SLICOSS) += slicoss/
53 obj-$(CONFIG_SXG) += sxg/
54 +obj-$(CONFIG_ME4000) += me4000/
55 diff --git a/drivers/staging/me4000/Kconfig b/drivers/staging/me4000/Kconfig
57 index 0000000..5e6c9de
59 +++ b/drivers/staging/me4000/Kconfig
62 + tristate "Meilhaus ME-4000 support"
66 + This driver supports the Meilhaus ME-4000 family of boards
67 + that do data collection and multipurpose I/O.
69 + To compile this driver as a module, choose M here: the module
70 + will be called me4000.
71 diff --git a/drivers/staging/me4000/Makefile b/drivers/staging/me4000/Makefile
73 index 0000000..74487cd
75 +++ b/drivers/staging/me4000/Makefile
77 +obj-$(CONFIG_ME4000) += me4000.o
78 diff --git a/drivers/staging/me4000/README b/drivers/staging/me4000/README
80 index 0000000..bbb8386
82 +++ b/drivers/staging/me4000/README
86 + - checkpatch.pl cleanups
88 + - possible /proc interaction cleanups
89 + - more info needed for Kconfig entry
91 + - module parameter cleanup
93 +Please send patches to Greg Kroah-Hartman <gregkh@suse.de>
94 +and Cc: Wolfgang Beiter <w.beiter@aon.at> and
95 +Guenter Gebhardt <g.gebhardt@meilhaus.de>
97 diff --git a/drivers/staging/me4000/me4000.c b/drivers/staging/me4000/me4000.c
99 index 0000000..862dd7f
101 +++ b/drivers/staging/me4000/me4000.c
103 +/* Device driver for Meilhaus ME-4000 board family.
104 + * ================================================
106 + * Copyright (C) 2003 Meilhaus Electronic GmbH (support@meilhaus.de)
108 + * This file is free software; you can redistribute it and/or modify
109 + * it under the terms of the GNU General Public License as published by
110 + * the Free Software Foundation; either version 2 of the License, or
111 + * (at your option) any later version.
113 + * This program is distributed in the hope that it will be useful,
114 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
115 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
116 + * GNU General Public License for more details.
118 + * You should have received a copy of the GNU General Public License
119 + * along with this program; if not, write to the Free Software
120 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
122 + * Author: Guenter Gebhardt <g.gebhardt@meilhaus.de>
125 +#include <linux/module.h>
126 +#include <linux/fs.h>
127 +#include <linux/sched.h>
128 +#include <linux/interrupt.h>
129 +#include <linux/pci.h>
131 +#include <asm/system.h>
132 +#include <asm/uaccess.h>
133 +#include <linux/errno.h>
134 +#include <linux/delay.h>
135 +#include <linux/fs.h>
136 +#include <linux/mm.h>
137 +#include <linux/unistd.h>
138 +#include <linux/list.h>
139 +#include <linux/proc_fs.h>
141 +#include <linux/poll.h>
142 +#include <linux/vmalloc.h>
143 +#include <asm/pgtable.h>
144 +#include <asm/uaccess.h>
145 +#include <linux/types.h>
147 +#include <linux/slab.h>
149 +/* Include-File for the Meilhaus ME-4000 I/O board */
151 +#include "me4000_firmware.h"
152 +#include "me4610_firmware.h"
154 +/* Administrative stuff for modinfo */
155 +MODULE_AUTHOR("Guenter Gebhardt <g.gebhardt@meilhaus.de>");
157 + ("Device Driver Module for Meilhaus ME-4000 boards version 1.0.5");
158 +MODULE_SUPPORTED_DEVICE("Meilhaus ME-4000 Multi I/O boards");
159 +MODULE_LICENSE("GPL");
161 +/* Board specific data are kept in a global list */
162 +LIST_HEAD(me4000_board_info_list);
164 +/* Major Device Numbers. 0 means to get it automatically from the System */
165 +static int me4000_ao_major_driver_no = 0;
166 +static int me4000_ai_major_driver_no = 0;
167 +static int me4000_dio_major_driver_no = 0;
168 +static int me4000_cnt_major_driver_no = 0;
169 +static int me4000_ext_int_major_driver_no = 0;
171 +/* Let the user specify a custom major driver number */
172 +module_param(me4000_ao_major_driver_no, int, 0);
173 +MODULE_PARM_DESC(me4000_ao_major_driver_no,
174 + "Major driver number for analog output (default 0)");
176 +module_param(me4000_ai_major_driver_no, int, 0);
177 +MODULE_PARM_DESC(me4000_ai_major_driver_no,
178 + "Major driver number for analog input (default 0)");
180 +module_param(me4000_dio_major_driver_no, int, 0);
181 +MODULE_PARM_DESC(me4000_dio_major_driver_no,
182 + "Major driver number digital I/O (default 0)");
184 +module_param(me4000_cnt_major_driver_no, int, 0);
185 +MODULE_PARM_DESC(me4000_cnt_major_driver_no,
186 + "Major driver number for counter (default 0)");
188 +module_param(me4000_ext_int_major_driver_no, int, 0);
189 +MODULE_PARM_DESC(me4000_ext_int_major_driver_no,
190 + "Major driver number for external interrupt (default 0)");
192 +/*-----------------------------------------------------------------------------
194 + ---------------------------------------------------------------------------*/
195 +int init_module(void);
196 +void cleanup_module(void);
198 +/*-----------------------------------------------------------------------------
199 + Board detection and initialization
200 + ---------------------------------------------------------------------------*/
201 +static int me4000_probe(struct pci_dev *dev, const struct pci_device_id *id);
202 +static int me4000_xilinx_download(me4000_info_t *);
203 +static int me4000_reset_board(me4000_info_t *);
205 +static void clear_board_info_list(void);
206 +static int get_registers(struct pci_dev *dev, me4000_info_t * info);
207 +static int init_board_info(struct pci_dev *dev, me4000_info_t * board_info);
208 +static int alloc_ao_contexts(me4000_info_t * info);
209 +static void release_ao_contexts(me4000_info_t * board_info);
210 +static int alloc_ai_context(me4000_info_t * info);
211 +static int alloc_dio_context(me4000_info_t * info);
212 +static int alloc_cnt_context(me4000_info_t * info);
213 +static int alloc_ext_int_context(me4000_info_t * info);
215 +/*-----------------------------------------------------------------------------
216 + Stuff used by all device parts
217 + ---------------------------------------------------------------------------*/
218 +static int me4000_open(struct inode *, struct file *);
219 +static int me4000_release(struct inode *, struct file *);
221 +static int me4000_get_user_info(me4000_user_info_t *,
222 + me4000_info_t * board_info);
223 +static int me4000_read_procmem(char *, char **, off_t, int, int *, void *);
225 +/*-----------------------------------------------------------------------------
226 + Analog output stuff
227 + ---------------------------------------------------------------------------*/
228 +static ssize_t me4000_ao_write_sing(struct file *, const char *, size_t,
230 +static ssize_t me4000_ao_write_wrap(struct file *, const char *, size_t,
232 +static ssize_t me4000_ao_write_cont(struct file *, const char *, size_t,
235 +static int me4000_ao_ioctl_sing(struct inode *, struct file *, unsigned int,
237 +static int me4000_ao_ioctl_wrap(struct inode *, struct file *, unsigned int,
239 +static int me4000_ao_ioctl_cont(struct inode *, struct file *, unsigned int,
242 +static unsigned int me4000_ao_poll_cont(struct file *, poll_table *);
243 +static int me4000_ao_fsync_cont(struct file *, struct dentry *, int);
245 +static int me4000_ao_start(unsigned long *, me4000_ao_context_t *);
246 +static int me4000_ao_stop(me4000_ao_context_t *);
247 +static int me4000_ao_immediate_stop(me4000_ao_context_t *);
248 +static int me4000_ao_timer_set_divisor(u32 *, me4000_ao_context_t *);
249 +static int me4000_ao_preload(me4000_ao_context_t *);
250 +static int me4000_ao_preload_update(me4000_ao_context_t *);
251 +static int me4000_ao_ex_trig_set_edge(int *, me4000_ao_context_t *);
252 +static int me4000_ao_ex_trig_enable(me4000_ao_context_t *);
253 +static int me4000_ao_ex_trig_disable(me4000_ao_context_t *);
254 +static int me4000_ao_prepare(me4000_ao_context_t * ao_info);
255 +static int me4000_ao_reset(me4000_ao_context_t * ao_info);
256 +static int me4000_ao_enable_do(me4000_ao_context_t *);
257 +static int me4000_ao_disable_do(me4000_ao_context_t *);
258 +static int me4000_ao_fsm_state(int *, me4000_ao_context_t *);
260 +static int me4000_ao_simultaneous_ex_trig(me4000_ao_context_t * ao_context);
261 +static int me4000_ao_simultaneous_sw(me4000_ao_context_t * ao_context);
262 +static int me4000_ao_simultaneous_disable(me4000_ao_context_t * ao_context);
263 +static int me4000_ao_simultaneous_update(me4000_ao_channel_list_t * channels,
264 + me4000_ao_context_t * ao_context);
266 +static int me4000_ao_synchronous_ex_trig(me4000_ao_context_t * ao_context);
267 +static int me4000_ao_synchronous_sw(me4000_ao_context_t * ao_context);
268 +static int me4000_ao_synchronous_disable(me4000_ao_context_t * ao_context);
270 +static int me4000_ao_ex_trig_timeout(unsigned long *arg,
271 + me4000_ao_context_t * ao_context);
272 +static int me4000_ao_get_free_buffer(unsigned long *arg,
273 + me4000_ao_context_t * ao_context);
275 +/*-----------------------------------------------------------------------------
277 + ---------------------------------------------------------------------------*/
278 +static int me4000_ai_single(me4000_ai_single_t *, me4000_ai_context_t *);
279 +static int me4000_ai_ioctl_sing(struct inode *, struct file *, unsigned int,
282 +static ssize_t me4000_ai_read(struct file *, char *, size_t, loff_t *);
283 +static int me4000_ai_ioctl_sw(struct inode *, struct file *, unsigned int,
285 +static unsigned int me4000_ai_poll(struct file *, poll_table *);
286 +static int me4000_ai_fasync(int fd, struct file *file_p, int mode);
288 +static int me4000_ai_ioctl_ext(struct inode *, struct file *, unsigned int,
291 +static int me4000_ai_prepare(me4000_ai_context_t * ai_context);
292 +static int me4000_ai_reset(me4000_ai_context_t * ai_context);
293 +static int me4000_ai_config(me4000_ai_config_t *, me4000_ai_context_t *);
294 +static int me4000_ai_start(me4000_ai_context_t *);
295 +static int me4000_ai_start_ex(unsigned long *, me4000_ai_context_t *);
296 +static int me4000_ai_stop(me4000_ai_context_t *);
297 +static int me4000_ai_immediate_stop(me4000_ai_context_t *);
298 +static int me4000_ai_ex_trig_enable(me4000_ai_context_t *);
299 +static int me4000_ai_ex_trig_disable(me4000_ai_context_t *);
300 +static int me4000_ai_ex_trig_setup(me4000_ai_trigger_t *,
301 + me4000_ai_context_t *);
302 +static int me4000_ai_sc_setup(me4000_ai_sc_t * arg,
303 + me4000_ai_context_t * ai_context);
304 +static int me4000_ai_offset_enable(me4000_ai_context_t * ai_context);
305 +static int me4000_ai_offset_disable(me4000_ai_context_t * ai_context);
306 +static int me4000_ai_fullscale_enable(me4000_ai_context_t * ai_context);
307 +static int me4000_ai_fullscale_disable(me4000_ai_context_t * ai_context);
308 +static int me4000_ai_fsm_state(int *arg, me4000_ai_context_t * ai_context);
309 +static int me4000_ai_get_count_buffer(unsigned long *arg,
310 + me4000_ai_context_t * ai_context);
312 +/*-----------------------------------------------------------------------------
314 + ---------------------------------------------------------------------------*/
315 +static int me4000_eeprom_read(me4000_eeprom_t * arg,
316 + me4000_ai_context_t * ai_context);
317 +static int me4000_eeprom_write(me4000_eeprom_t * arg,
318 + me4000_ai_context_t * ai_context);
319 +static unsigned short eeprom_read_cmd(me4000_ai_context_t * ai_context,
320 + unsigned long cmd, int length);
321 +static int eeprom_write_cmd(me4000_ai_context_t * ai_context, unsigned long cmd,
324 +/*-----------------------------------------------------------------------------
326 + ---------------------------------------------------------------------------*/
327 +static int me4000_dio_ioctl(struct inode *, struct file *, unsigned int,
329 +static int me4000_dio_config(me4000_dio_config_t *, me4000_dio_context_t *);
330 +static int me4000_dio_get_byte(me4000_dio_byte_t *, me4000_dio_context_t *);
331 +static int me4000_dio_set_byte(me4000_dio_byte_t *, me4000_dio_context_t *);
332 +static int me4000_dio_reset(me4000_dio_context_t *);
334 +/*-----------------------------------------------------------------------------
336 + ---------------------------------------------------------------------------*/
337 +static int me4000_cnt_ioctl(struct inode *, struct file *, unsigned int,
339 +static int me4000_cnt_config(me4000_cnt_config_t *, me4000_cnt_context_t *);
340 +static int me4000_cnt_read(me4000_cnt_t *, me4000_cnt_context_t *);
341 +static int me4000_cnt_write(me4000_cnt_t *, me4000_cnt_context_t *);
342 +static int me4000_cnt_reset(me4000_cnt_context_t *);
344 +/*-----------------------------------------------------------------------------
345 + External interrupt routines
346 + ---------------------------------------------------------------------------*/
347 +static int me4000_ext_int_ioctl(struct inode *, struct file *, unsigned int,
349 +static int me4000_ext_int_enable(me4000_ext_int_context_t *);
350 +static int me4000_ext_int_disable(me4000_ext_int_context_t *);
351 +static int me4000_ext_int_count(unsigned long *arg,
352 + me4000_ext_int_context_t * ext_int_context);
353 +static int me4000_ext_int_fasync(int fd, struct file *file_ptr, int mode);
355 +/*-----------------------------------------------------------------------------
356 + The interrupt service routines
357 + ---------------------------------------------------------------------------*/
358 +static irqreturn_t me4000_ao_isr(int, void *);
359 +static irqreturn_t me4000_ai_isr(int, void *);
360 +static irqreturn_t me4000_ext_int_isr(int, void *);
362 +/*-----------------------------------------------------------------------------
364 + ---------------------------------------------------------------------------*/
365 +static int inline me4000_buf_count(me4000_circ_buf_t, int);
366 +static int inline me4000_buf_space(me4000_circ_buf_t, int);
367 +static int inline me4000_space_to_end(me4000_circ_buf_t, int);
368 +static int inline me4000_values_to_end(me4000_circ_buf_t, int);
370 +static void inline me4000_outb(unsigned char value, unsigned long port);
371 +static void inline me4000_outl(unsigned long value, unsigned long port);
372 +static unsigned long inline me4000_inl(unsigned long port);
373 +static unsigned char inline me4000_inb(unsigned long port);
375 +static int me4000_buf_count(me4000_circ_buf_t buf, int size)
377 + return ((buf.head - buf.tail) & (size - 1));
380 +static int me4000_buf_space(me4000_circ_buf_t buf, int size)
382 + return ((buf.tail - (buf.head + 1)) & (size - 1));
385 +static int me4000_values_to_end(me4000_circ_buf_t buf, int size)
389 + end = size - buf.tail;
390 + n = (buf.head + end) & (size - 1);
391 + return (n < end) ? n : end;
394 +static int me4000_space_to_end(me4000_circ_buf_t buf, int size)
399 + end = size - 1 - buf.head;
400 + n = (end + buf.tail) & (size - 1);
401 + return (n <= end) ? n : (end + 1);
404 +static void me4000_outb(unsigned char value, unsigned long port)
406 + PORT_PDEBUG("--> 0x%02X port 0x%04lX\n", value, port);
410 +static void me4000_outl(unsigned long value, unsigned long port)
412 + PORT_PDEBUG("--> 0x%08lX port 0x%04lX\n", value, port);
416 +static unsigned long me4000_inl(unsigned long port)
418 + unsigned long value;
420 + PORT_PDEBUG("<-- 0x%08lX port 0x%04lX\n", value, port);
424 +static unsigned char me4000_inb(unsigned long port)
426 + unsigned char value;
428 + PORT_PDEBUG("<-- 0x%08X port 0x%04lX\n", value, port);
432 +struct pci_driver me4000_driver = {
433 + .name = ME4000_NAME,
434 + .id_table = me4000_pci_table,
435 + .probe = me4000_probe
438 +static struct file_operations me4000_ao_fops_sing = {
440 + write:me4000_ao_write_sing,
441 + ioctl:me4000_ao_ioctl_sing,
443 + release:me4000_release,
446 +static struct file_operations me4000_ao_fops_wrap = {
448 + write:me4000_ao_write_wrap,
449 + ioctl:me4000_ao_ioctl_wrap,
451 + release:me4000_release,
454 +static struct file_operations me4000_ao_fops_cont = {
456 + write:me4000_ao_write_cont,
457 + poll:me4000_ao_poll_cont,
458 + ioctl:me4000_ao_ioctl_cont,
460 + release:me4000_release,
461 + fsync:me4000_ao_fsync_cont,
464 +static struct file_operations me4000_ai_fops_sing = {
466 + ioctl:me4000_ai_ioctl_sing,
468 + release:me4000_release,
471 +static struct file_operations me4000_ai_fops_cont_sw = {
473 + read:me4000_ai_read,
474 + poll:me4000_ai_poll,
475 + ioctl:me4000_ai_ioctl_sw,
477 + release:me4000_release,
478 + fasync:me4000_ai_fasync,
481 +static struct file_operations me4000_ai_fops_cont_et = {
483 + read:me4000_ai_read,
484 + poll:me4000_ai_poll,
485 + ioctl:me4000_ai_ioctl_ext,
487 + release:me4000_release,
490 +static struct file_operations me4000_ai_fops_cont_et_value = {
492 + read:me4000_ai_read,
493 + poll:me4000_ai_poll,
494 + ioctl:me4000_ai_ioctl_ext,
496 + release:me4000_release,
499 +static struct file_operations me4000_ai_fops_cont_et_chanlist = {
501 + read:me4000_ai_read,
502 + poll:me4000_ai_poll,
503 + ioctl:me4000_ai_ioctl_ext,
505 + release:me4000_release,
508 +static struct file_operations me4000_dio_fops = {
510 + ioctl:me4000_dio_ioctl,
512 + release:me4000_release,
515 +static struct file_operations me4000_cnt_fops = {
517 + ioctl:me4000_cnt_ioctl,
519 + release:me4000_release,
522 +static struct file_operations me4000_ext_int_fops = {
524 + ioctl:me4000_ext_int_ioctl,
526 + release:me4000_release,
527 + fasync:me4000_ext_int_fasync,
530 +static struct file_operations *me4000_ao_fops_array[] = {
531 + &me4000_ao_fops_sing, // single operations
532 + &me4000_ao_fops_wrap, // wraparound operations
533 + &me4000_ao_fops_cont, // continous operations
536 +static struct file_operations *me4000_ai_fops_array[] = {
537 + &me4000_ai_fops_sing, // single operations
538 + &me4000_ai_fops_cont_sw, // continuous operations with software start
539 + &me4000_ai_fops_cont_et, // continous operations with external trigger
540 + &me4000_ai_fops_cont_et_value, // sample values by external trigger
541 + &me4000_ai_fops_cont_et_chanlist, // work through one channel list by external trigger
544 +int __init me4000_init_module(void)
548 + CALL_PDEBUG("init_module() is executed\n");
550 + /* Register driver capabilities */
551 + result = pci_register_driver(&me4000_driver);
552 + PDEBUG("init_module():%d devices detected\n", result);
554 + printk(KERN_ERR "ME4000:init_module():Can't register driver\n");
558 + /* Allocate major number for analog output */
560 + register_chrdev(me4000_ao_major_driver_no, ME4000_AO_NAME,
561 + &me4000_ao_fops_sing);
563 + printk(KERN_ERR "ME4000:init_module():Can't get AO major no\n");
566 + me4000_ao_major_driver_no = result;
568 + PDEBUG("init_module():Major driver number for AO = %ld\n",
569 + me4000_ao_major_driver_no);
571 + /* Allocate major number for analog input */
573 + register_chrdev(me4000_ai_major_driver_no, ME4000_AI_NAME,
574 + &me4000_ai_fops_sing);
576 + printk(KERN_ERR "ME4000:init_module():Can't get AI major no\n");
579 + me4000_ai_major_driver_no = result;
581 + PDEBUG("init_module():Major driver number for AI = %ld\n",
582 + me4000_ai_major_driver_no);
584 + /* Allocate major number for digital I/O */
586 + register_chrdev(me4000_dio_major_driver_no, ME4000_DIO_NAME,
590 + "ME4000:init_module():Can't get DIO major no\n");
593 + me4000_dio_major_driver_no = result;
595 + PDEBUG("init_module():Major driver number for DIO = %ld\n",
596 + me4000_dio_major_driver_no);
598 + /* Allocate major number for counter */
600 + register_chrdev(me4000_cnt_major_driver_no, ME4000_CNT_NAME,
604 + "ME4000:init_module():Can't get CNT major no\n");
607 + me4000_cnt_major_driver_no = result;
609 + PDEBUG("init_module():Major driver number for CNT = %ld\n",
610 + me4000_cnt_major_driver_no);
612 + /* Allocate major number for external interrupt */
614 + register_chrdev(me4000_ext_int_major_driver_no, ME4000_EXT_INT_NAME,
615 + &me4000_ext_int_fops);
618 + "ME4000:init_module():Can't get major no for external interrupt\n");
621 + me4000_ext_int_major_driver_no = result;
624 + ("init_module():Major driver number for external interrupt = %ld\n",
625 + me4000_ext_int_major_driver_no);
627 + /* Create the /proc/me4000 entry */
628 + if (!create_proc_read_entry
629 + ("me4000", 0, NULL, me4000_read_procmem, NULL)) {
632 + "ME4000:init_module():Can't create proc entry\n");
639 + unregister_chrdev(me4000_ext_int_major_driver_no, ME4000_EXT_INT_NAME);
642 + unregister_chrdev(me4000_cnt_major_driver_no, ME4000_CNT_NAME);
645 + unregister_chrdev(me4000_dio_major_driver_no, ME4000_DIO_NAME);
648 + unregister_chrdev(me4000_ai_major_driver_no, ME4000_AI_NAME);
651 + unregister_chrdev(me4000_ao_major_driver_no, ME4000_AO_NAME);
654 + pci_unregister_driver(&me4000_driver);
655 + clear_board_info_list();
661 +module_init(me4000_init_module);
663 +static void clear_board_info_list(void)
665 + struct list_head *board_p;
666 + struct list_head *dac_p;
667 + me4000_info_t *board_info;
668 + me4000_ao_context_t *ao_context;
670 + /* Clear context lists */
671 + for (board_p = me4000_board_info_list.next;
672 + board_p != &me4000_board_info_list; board_p = board_p->next) {
673 + board_info = list_entry(board_p, me4000_info_t, list);
674 + /* Clear analog output context list */
675 + while (!list_empty(&board_info->ao_context_list)) {
676 + dac_p = board_info->ao_context_list.next;
678 + list_entry(dac_p, me4000_ao_context_t, list);
679 + me4000_ao_reset(ao_context);
680 + free_irq(ao_context->irq, ao_context);
681 + if (ao_context->circ_buf.buf)
682 + kfree(ao_context->circ_buf.buf);
687 + /* Clear analog input context */
688 + if (board_info->ai_context->circ_buf.buf)
689 + kfree(board_info->ai_context->circ_buf.buf);
690 + kfree(board_info->ai_context);
692 + /* Clear digital I/O context */
693 + kfree(board_info->dio_context);
695 + /* Clear counter context */
696 + kfree(board_info->cnt_context);
698 + /* Clear external interrupt context */
699 + kfree(board_info->ext_int_context);
702 + /* Clear the board info list */
703 + while (!list_empty(&me4000_board_info_list)) {
704 + board_p = me4000_board_info_list.next;
705 + board_info = list_entry(board_p, me4000_info_t, list);
706 + pci_release_regions(board_info->pci_dev_p);
712 +static int get_registers(struct pci_dev *dev, me4000_info_t * board_info)
715 + /*--------------------------- plx regbase ---------------------------------*/
717 + board_info->plx_regbase = pci_resource_start(dev, 1);
718 + if (board_info->plx_regbase == 0) {
720 + "ME4000:get_registers():PCI base address 1 is not available\n");
723 + board_info->plx_regbase_size = pci_resource_len(dev, 1);
726 + ("get_registers():PLX configuration registers at address 0x%4lX [0x%4lX]\n",
727 + board_info->plx_regbase, board_info->plx_regbase_size);
729 + /*--------------------------- me4000 regbase ------------------------------*/
731 + board_info->me4000_regbase = pci_resource_start(dev, 2);
732 + if (board_info->me4000_regbase == 0) {
734 + "ME4000:get_registers():PCI base address 2 is not available\n");
737 + board_info->me4000_regbase_size = pci_resource_len(dev, 2);
739 + PDEBUG("get_registers():ME4000 registers at address 0x%4lX [0x%4lX]\n",
740 + board_info->me4000_regbase, board_info->me4000_regbase_size);
742 + /*--------------------------- timer regbase ------------------------------*/
744 + board_info->timer_regbase = pci_resource_start(dev, 3);
745 + if (board_info->timer_regbase == 0) {
747 + "ME4000:get_registers():PCI base address 3 is not available\n");
750 + board_info->timer_regbase_size = pci_resource_len(dev, 3);
752 + PDEBUG("get_registers():Timer registers at address 0x%4lX [0x%4lX]\n",
753 + board_info->timer_regbase, board_info->timer_regbase_size);
755 + /*--------------------------- program regbase ------------------------------*/
757 + board_info->program_regbase = pci_resource_start(dev, 5);
758 + if (board_info->program_regbase == 0) {
760 + "get_registers():ME4000:PCI base address 5 is not available\n");
763 + board_info->program_regbase_size = pci_resource_len(dev, 5);
765 + PDEBUG("get_registers():Program registers at address 0x%4lX [0x%4lX]\n",
766 + board_info->program_regbase, board_info->program_regbase_size);
771 +static int init_board_info(struct pci_dev *pci_dev_p,
772 + me4000_info_t * board_info)
776 + struct list_head *board_p;
777 + board_info->pci_dev_p = pci_dev_p;
779 + for (i = 0; i < ME4000_BOARD_VERSIONS; i++) {
780 + if (me4000_boards[i].device_id == pci_dev_p->device) {
781 + board_info->board_p = &me4000_boards[i];
785 + if (i == ME4000_BOARD_VERSIONS) {
787 + "ME4000:init_board_info():Device ID not valid\n");
791 + /* Get the index of the board in the global list */
792 + for (board_p = me4000_board_info_list.next, i = 0;
793 + board_p != &me4000_board_info_list; board_p = board_p->next, i++) {
794 + if (board_p == &board_info->list) {
795 + board_info->board_count = i;
799 + if (board_p == &me4000_board_info_list) {
801 + "ME4000:init_board_info():Cannot get index of baord\n");
805 + /* Init list head for analog output contexts */
806 + INIT_LIST_HEAD(&board_info->ao_context_list);
808 + /* Init spin locks */
809 + spin_lock_init(&board_info->preload_lock);
810 + spin_lock_init(&board_info->ai_ctrl_lock);
812 + /* Get the serial number */
813 + result = pci_read_config_dword(pci_dev_p, 0x2C, &board_info->serial_no);
814 + if (result != PCIBIOS_SUCCESSFUL) {
815 + printk(KERN_WARNING
816 + "ME4000:init_board_info: Can't get serial_no\n");
819 + PDEBUG("init_board_info():serial_no = 0x%x\n", board_info->serial_no);
821 + /* Get the hardware revision */
823 + pci_read_config_byte(pci_dev_p, 0x08, &board_info->hw_revision);
824 + if (result != PCIBIOS_SUCCESSFUL) {
825 + printk(KERN_WARNING
826 + "ME4000:init_board_info():Can't get hw_revision\n");
829 + PDEBUG("init_board_info():hw_revision = 0x%x\n",
830 + board_info->hw_revision);
832 + /* Get the vendor id */
833 + board_info->vendor_id = pci_dev_p->vendor;
834 + PDEBUG("init_board_info():vendor_id = 0x%x\n", board_info->vendor_id);
836 + /* Get the device id */
837 + board_info->device_id = pci_dev_p->device;
838 + PDEBUG("init_board_info():device_id = 0x%x\n", board_info->device_id);
840 + /* Get the pci device number */
841 + board_info->pci_dev_no = PCI_FUNC(pci_dev_p->devfn);
842 + PDEBUG("init_board_info():pci_func_no = 0x%x\n",
843 + board_info->pci_func_no);
845 + /* Get the pci slot number */
846 + board_info->pci_dev_no = PCI_SLOT(pci_dev_p->devfn);
847 + PDEBUG("init_board_info():pci_dev_no = 0x%x\n", board_info->pci_dev_no);
849 + /* Get the pci bus number */
850 + board_info->pci_bus_no = pci_dev_p->bus->number;
851 + PDEBUG("init_board_info():pci_bus_no = 0x%x\n", board_info->pci_bus_no);
853 + /* Get the irq assigned to the board */
854 + board_info->irq = pci_dev_p->irq;
855 + PDEBUG("init_board_info():irq = %d\n", board_info->irq);
860 +static int alloc_ao_contexts(me4000_info_t * info)
864 + me4000_ao_context_t *ao_context;
866 + for (i = 0; i < info->board_p->ao.count; i++) {
867 + ao_context = kmalloc(sizeof(me4000_ao_context_t), GFP_KERNEL);
870 + "alloc_ao_contexts():Can't get memory for ao context\n");
871 + release_ao_contexts(info);
874 + memset(ao_context, 0, sizeof(me4000_ao_context_t));
876 + spin_lock_init(&ao_context->use_lock);
877 + spin_lock_init(&ao_context->int_lock);
878 + ao_context->irq = info->irq;
879 + init_waitqueue_head(&ao_context->wait_queue);
880 + ao_context->board_info = info;
882 + if (info->board_p->ao.fifo_count) {
883 + /* Allocate circular buffer */
884 + ao_context->circ_buf.buf =
885 + kmalloc(ME4000_AO_BUFFER_SIZE, GFP_KERNEL);
886 + if (!ao_context->circ_buf.buf) {
888 + "alloc_ao_contexts():Can't get circular buffer\n");
889 + release_ao_contexts(info);
892 + memset(ao_context->circ_buf.buf, 0,
893 + ME4000_AO_BUFFER_SIZE);
895 + /* Clear the circular buffer */
896 + ao_context->circ_buf.head = 0;
897 + ao_context->circ_buf.tail = 0;
902 + ao_context->ctrl_reg =
903 + info->me4000_regbase + ME4000_AO_00_CTRL_REG;
904 + ao_context->status_reg =
905 + info->me4000_regbase + ME4000_AO_00_STATUS_REG;
906 + ao_context->fifo_reg =
907 + info->me4000_regbase + ME4000_AO_00_FIFO_REG;
908 + ao_context->single_reg =
909 + info->me4000_regbase + ME4000_AO_00_SINGLE_REG;
910 + ao_context->timer_reg =
911 + info->me4000_regbase + ME4000_AO_00_TIMER_REG;
912 + ao_context->irq_status_reg =
913 + info->me4000_regbase + ME4000_IRQ_STATUS_REG;
914 + ao_context->preload_reg =
915 + info->me4000_regbase + ME4000_AO_LOADSETREG_XX;
918 + ao_context->ctrl_reg =
919 + info->me4000_regbase + ME4000_AO_01_CTRL_REG;
920 + ao_context->status_reg =
921 + info->me4000_regbase + ME4000_AO_01_STATUS_REG;
922 + ao_context->fifo_reg =
923 + info->me4000_regbase + ME4000_AO_01_FIFO_REG;
924 + ao_context->single_reg =
925 + info->me4000_regbase + ME4000_AO_01_SINGLE_REG;
926 + ao_context->timer_reg =
927 + info->me4000_regbase + ME4000_AO_01_TIMER_REG;
928 + ao_context->irq_status_reg =
929 + info->me4000_regbase + ME4000_IRQ_STATUS_REG;
930 + ao_context->preload_reg =
931 + info->me4000_regbase + ME4000_AO_LOADSETREG_XX;
934 + ao_context->ctrl_reg =
935 + info->me4000_regbase + ME4000_AO_02_CTRL_REG;
936 + ao_context->status_reg =
937 + info->me4000_regbase + ME4000_AO_02_STATUS_REG;
938 + ao_context->fifo_reg =
939 + info->me4000_regbase + ME4000_AO_02_FIFO_REG;
940 + ao_context->single_reg =
941 + info->me4000_regbase + ME4000_AO_02_SINGLE_REG;
942 + ao_context->timer_reg =
943 + info->me4000_regbase + ME4000_AO_02_TIMER_REG;
944 + ao_context->irq_status_reg =
945 + info->me4000_regbase + ME4000_IRQ_STATUS_REG;
946 + ao_context->preload_reg =
947 + info->me4000_regbase + ME4000_AO_LOADSETREG_XX;
950 + ao_context->ctrl_reg =
951 + info->me4000_regbase + ME4000_AO_03_CTRL_REG;
952 + ao_context->status_reg =
953 + info->me4000_regbase + ME4000_AO_03_STATUS_REG;
954 + ao_context->fifo_reg =
955 + info->me4000_regbase + ME4000_AO_03_FIFO_REG;
956 + ao_context->single_reg =
957 + info->me4000_regbase + ME4000_AO_03_SINGLE_REG;
958 + ao_context->timer_reg =
959 + info->me4000_regbase + ME4000_AO_03_TIMER_REG;
960 + ao_context->irq_status_reg =
961 + info->me4000_regbase + ME4000_IRQ_STATUS_REG;
962 + ao_context->preload_reg =
963 + info->me4000_regbase + ME4000_AO_LOADSETREG_XX;
969 + if (info->board_p->ao.fifo_count) {
970 + /* Request the interrupt line */
972 + request_irq(ao_context->irq, me4000_ao_isr,
973 + IRQF_DISABLED | IRQF_SHARED,
974 + ME4000_NAME, ao_context);
977 + "alloc_ao_contexts():Can't get interrupt line");
978 + if (ao_context->circ_buf.buf)
979 + kfree(ao_context->circ_buf.buf);
981 + release_ao_contexts(info);
986 + list_add_tail(&ao_context->list, &info->ao_context_list);
987 + ao_context->index = i;
993 +static void release_ao_contexts(me4000_info_t * board_info)
995 + struct list_head *dac_p;
996 + me4000_ao_context_t *ao_context;
998 + /* Clear analog output context list */
999 + while (!list_empty(&board_info->ao_context_list)) {
1000 + dac_p = board_info->ao_context_list.next;
1001 + ao_context = list_entry(dac_p, me4000_ao_context_t, list);
1002 + free_irq(ao_context->irq, ao_context);
1003 + if (ao_context->circ_buf.buf)
1004 + kfree(ao_context->circ_buf.buf);
1006 + kfree(ao_context);
1010 +static int alloc_ai_context(me4000_info_t * info)
1012 + me4000_ai_context_t *ai_context;
1014 + if (info->board_p->ai.count) {
1015 + ai_context = kmalloc(sizeof(me4000_ai_context_t), GFP_KERNEL);
1016 + if (!ai_context) {
1018 + "ME4000:alloc_ai_context():Can't get memory for ai context\n");
1021 + memset(ai_context, 0, sizeof(me4000_ai_context_t));
1023 + info->ai_context = ai_context;
1025 + spin_lock_init(&ai_context->use_lock);
1026 + spin_lock_init(&ai_context->int_lock);
1027 + ai_context->number = 0;
1028 + ai_context->irq = info->irq;
1029 + init_waitqueue_head(&ai_context->wait_queue);
1030 + ai_context->board_info = info;
1032 + ai_context->ctrl_reg =
1033 + info->me4000_regbase + ME4000_AI_CTRL_REG;
1034 + ai_context->status_reg =
1035 + info->me4000_regbase + ME4000_AI_STATUS_REG;
1036 + ai_context->channel_list_reg =
1037 + info->me4000_regbase + ME4000_AI_CHANNEL_LIST_REG;
1038 + ai_context->data_reg =
1039 + info->me4000_regbase + ME4000_AI_DATA_REG;
1040 + ai_context->chan_timer_reg =
1041 + info->me4000_regbase + ME4000_AI_CHAN_TIMER_REG;
1042 + ai_context->chan_pre_timer_reg =
1043 + info->me4000_regbase + ME4000_AI_CHAN_PRE_TIMER_REG;
1044 + ai_context->scan_timer_low_reg =
1045 + info->me4000_regbase + ME4000_AI_SCAN_TIMER_LOW_REG;
1046 + ai_context->scan_timer_high_reg =
1047 + info->me4000_regbase + ME4000_AI_SCAN_TIMER_HIGH_REG;
1048 + ai_context->scan_pre_timer_low_reg =
1049 + info->me4000_regbase + ME4000_AI_SCAN_PRE_TIMER_LOW_REG;
1050 + ai_context->scan_pre_timer_high_reg =
1051 + info->me4000_regbase + ME4000_AI_SCAN_PRE_TIMER_HIGH_REG;
1052 + ai_context->start_reg =
1053 + info->me4000_regbase + ME4000_AI_START_REG;
1054 + ai_context->irq_status_reg =
1055 + info->me4000_regbase + ME4000_IRQ_STATUS_REG;
1056 + ai_context->sample_counter_reg =
1057 + info->me4000_regbase + ME4000_AI_SAMPLE_COUNTER_REG;
1063 +static int alloc_dio_context(me4000_info_t * info)
1065 + me4000_dio_context_t *dio_context;
1067 + if (info->board_p->dio.count) {
1068 + dio_context = kmalloc(sizeof(me4000_dio_context_t), GFP_KERNEL);
1069 + if (!dio_context) {
1071 + "ME4000:alloc_dio_context():Can't get memory for dio context\n");
1074 + memset(dio_context, 0, sizeof(me4000_dio_context_t));
1076 + info->dio_context = dio_context;
1078 + spin_lock_init(&dio_context->use_lock);
1079 + dio_context->board_info = info;
1081 + dio_context->dio_count = info->board_p->dio.count;
1083 + dio_context->dir_reg =
1084 + info->me4000_regbase + ME4000_DIO_DIR_REG;
1085 + dio_context->ctrl_reg =
1086 + info->me4000_regbase + ME4000_DIO_CTRL_REG;
1087 + dio_context->port_0_reg =
1088 + info->me4000_regbase + ME4000_DIO_PORT_0_REG;
1089 + dio_context->port_1_reg =
1090 + info->me4000_regbase + ME4000_DIO_PORT_1_REG;
1091 + dio_context->port_2_reg =
1092 + info->me4000_regbase + ME4000_DIO_PORT_2_REG;
1093 + dio_context->port_3_reg =
1094 + info->me4000_regbase + ME4000_DIO_PORT_3_REG;
1100 +static int alloc_cnt_context(me4000_info_t * info)
1102 + me4000_cnt_context_t *cnt_context;
1104 + if (info->board_p->cnt.count) {
1105 + cnt_context = kmalloc(sizeof(me4000_cnt_context_t), GFP_KERNEL);
1106 + if (!cnt_context) {
1108 + "ME4000:alloc_cnt_context():Can't get memory for cnt context\n");
1111 + memset(cnt_context, 0, sizeof(me4000_cnt_context_t));
1113 + info->cnt_context = cnt_context;
1115 + spin_lock_init(&cnt_context->use_lock);
1116 + cnt_context->board_info = info;
1118 + cnt_context->ctrl_reg =
1119 + info->timer_regbase + ME4000_CNT_CTRL_REG;
1120 + cnt_context->counter_0_reg =
1121 + info->timer_regbase + ME4000_CNT_COUNTER_0_REG;
1122 + cnt_context->counter_1_reg =
1123 + info->timer_regbase + ME4000_CNT_COUNTER_1_REG;
1124 + cnt_context->counter_2_reg =
1125 + info->timer_regbase + ME4000_CNT_COUNTER_2_REG;
1131 +static int alloc_ext_int_context(me4000_info_t * info)
1133 + me4000_ext_int_context_t *ext_int_context;
1135 + if (info->board_p->cnt.count) {
1137 + kmalloc(sizeof(me4000_ext_int_context_t), GFP_KERNEL);
1138 + if (!ext_int_context) {
1140 + "ME4000:alloc_ext_int_context():Can't get memory for cnt context\n");
1143 + memset(ext_int_context, 0, sizeof(me4000_ext_int_context_t));
1145 + info->ext_int_context = ext_int_context;
1147 + spin_lock_init(&ext_int_context->use_lock);
1148 + ext_int_context->board_info = info;
1150 + ext_int_context->fasync_ptr = NULL;
1151 + ext_int_context->irq = info->irq;
1153 + ext_int_context->ctrl_reg =
1154 + info->me4000_regbase + ME4000_AI_CTRL_REG;
1155 + ext_int_context->irq_status_reg =
1156 + info->me4000_regbase + ME4000_IRQ_STATUS_REG;
1162 +static int me4000_probe(struct pci_dev *dev, const struct pci_device_id *id)
1165 + me4000_info_t *board_info;
1167 + CALL_PDEBUG("me4000_probe() is executed\n");
1169 + /* Allocate structure for board context */
1170 + board_info = kmalloc(sizeof(me4000_info_t), GFP_KERNEL);
1171 + if (!board_info) {
1173 + "ME4000:Can't get memory for board info structure\n");
1175 + goto PROBE_ERROR_1;
1177 + memset(board_info, 0, sizeof(me4000_info_t));
1179 + /* Add to global linked list */
1180 + list_add_tail(&board_info->list, &me4000_board_info_list);
1182 + /* Get the PCI base registers */
1183 + result = get_registers(dev, board_info);
1185 + printk(KERN_ERR "me4000_probe():Cannot get registers\n");
1186 + goto PROBE_ERROR_2;
1189 + /* Enable the device */
1190 + result = pci_enable_device(dev);
1192 + printk(KERN_ERR "me4000_probe():Cannot enable PCI device\n");
1193 + goto PROBE_ERROR_2;
1196 + /* Request the PCI register regions */
1197 + result = pci_request_regions(dev, ME4000_NAME);
1199 + printk(KERN_ERR "me4000_probe():Cannot request I/O regions\n");
1200 + goto PROBE_ERROR_2;
1203 + /* Initialize board info */
1204 + result = init_board_info(dev, board_info);
1206 + printk(KERN_ERR "me4000_probe():Cannot init baord info\n");
1207 + goto PROBE_ERROR_3;
1210 + /* Download the xilinx firmware */
1211 + result = me4000_xilinx_download(board_info);
1213 + printk(KERN_ERR "me4000_probe:Can't download firmware\n");
1214 + goto PROBE_ERROR_3;
1217 + /* Make a hardware reset */
1218 + result = me4000_reset_board(board_info);
1220 + printk(KERN_ERR "me4000_probe:Can't reset board\n");
1221 + goto PROBE_ERROR_3;
1224 + /* Allocate analog output context structures */
1225 + result = alloc_ao_contexts(board_info);
1227 + printk(KERN_ERR "me4000_probe():Cannot allocate ao contexts\n");
1228 + goto PROBE_ERROR_3;
1231 + /* Allocate analog input context */
1232 + result = alloc_ai_context(board_info);
1234 + printk(KERN_ERR "me4000_probe():Cannot allocate ai context\n");
1235 + goto PROBE_ERROR_4;
1238 + /* Allocate digital I/O context */
1239 + result = alloc_dio_context(board_info);
1241 + printk(KERN_ERR "me4000_probe():Cannot allocate dio context\n");
1242 + goto PROBE_ERROR_5;
1245 + /* Allocate counter context */
1246 + result = alloc_cnt_context(board_info);
1248 + printk(KERN_ERR "me4000_probe():Cannot allocate cnt context\n");
1249 + goto PROBE_ERROR_6;
1252 + /* Allocate external interrupt context */
1253 + result = alloc_ext_int_context(board_info);
1256 + "me4000_probe():Cannot allocate ext_int context\n");
1257 + goto PROBE_ERROR_7;
1263 + kfree(board_info->cnt_context);
1266 + kfree(board_info->dio_context);
1269 + kfree(board_info->ai_context);
1272 + release_ao_contexts(board_info);
1275 + pci_release_regions(dev);
1278 + list_del(&board_info->list);
1279 + kfree(board_info);
1285 +static int me4000_xilinx_download(me4000_info_t * info)
1290 + unsigned char *firm;
1291 + wait_queue_head_t queue;
1293 + CALL_PDEBUG("me4000_xilinx_download() is executed\n");
1295 + init_waitqueue_head(&queue);
1297 + firm = (info->device_id == 0x4610) ? xilinx_firm_4610 : xilinx_firm;
1300 + * Set PLX local interrupt 2 polarity to high.
1301 + * Interrupt is thrown by init pin of xilinx.
1303 + outl(0x10, info->plx_regbase + PLX_INTCSR);
1305 + /* Set /CS and /WRITE of the Xilinx */
1306 + value = inl(info->plx_regbase + PLX_ICR);
1308 + outl(value, info->plx_regbase + PLX_ICR);
1310 + /* Init Xilinx with CS1 */
1311 + inb(info->program_regbase + 0xC8);
1313 + /* Wait until /INIT pin is set */
1315 + if (!inl(info->plx_regbase + PLX_INTCSR) & 0x20) {
1316 + printk(KERN_ERR "me4000_xilinx_download():Can't init Xilinx\n");
1320 + /* Reset /CS and /WRITE of the Xilinx */
1321 + value = inl(info->plx_regbase + PLX_ICR);
1323 + outl(value, info->plx_regbase + PLX_ICR);
1325 + /* Download Xilinx firmware */
1326 + size = (firm[0] << 24) + (firm[1] << 16) + (firm[2] << 8) + firm[3];
1329 + for (idx = 0; idx < size; idx++) {
1330 + outb(firm[16 + idx], info->program_regbase);
1334 + /* Check if BUSY flag is low */
1335 + if (inl(info->plx_regbase + PLX_ICR) & 0x20) {
1337 + "me4000_xilinx_download():Xilinx is still busy (idx = %d)\n",
1343 + PDEBUG("me4000_xilinx_download():%d bytes written\n", idx);
1345 + /* If done flag is high download was successful */
1346 + if (inl(info->plx_regbase + PLX_ICR) & 0x4) {
1347 + PDEBUG("me4000_xilinx_download():Done flag is set\n");
1348 + PDEBUG("me4000_xilinx_download():Download was successful\n");
1351 + "ME4000:me4000_xilinx_download():DONE flag is not set\n");
1353 + "ME4000:me4000_xilinx_download():Download not succesful\n");
1357 + /* Set /CS and /WRITE */
1358 + value = inl(info->plx_regbase + PLX_ICR);
1360 + outl(value, info->plx_regbase + PLX_ICR);
1365 +static int me4000_reset_board(me4000_info_t * info)
1367 + unsigned long icr;
1369 + CALL_PDEBUG("me4000_reset_board() is executed\n");
1371 + /* Make a hardware reset */
1372 + icr = me4000_inl(info->plx_regbase + PLX_ICR);
1373 + icr |= 0x40000000;
1374 + me4000_outl(icr, info->plx_regbase + PLX_ICR);
1375 + icr &= ~0x40000000;
1376 + me4000_outl(icr, info->plx_regbase + PLX_ICR);
1378 + /* Set both stop bits in the analog input control register */
1379 + me4000_outl(ME4000_AI_CTRL_BIT_IMMEDIATE_STOP | ME4000_AI_CTRL_BIT_STOP,
1380 + info->me4000_regbase + ME4000_AI_CTRL_REG);
1382 + /* Set both stop bits in the analog output control register */
1383 + me4000_outl(ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP,
1384 + info->me4000_regbase + ME4000_AO_00_CTRL_REG);
1385 + me4000_outl(ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP,
1386 + info->me4000_regbase + ME4000_AO_01_CTRL_REG);
1387 + me4000_outl(ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP,
1388 + info->me4000_regbase + ME4000_AO_02_CTRL_REG);
1389 + me4000_outl(ME4000_AO_CTRL_BIT_IMMEDIATE_STOP | ME4000_AO_CTRL_BIT_STOP,
1390 + info->me4000_regbase + ME4000_AO_03_CTRL_REG);
1392 + /* 0x8000 to the DACs means an output voltage of 0V */
1393 + me4000_outl(0x8000, info->me4000_regbase + ME4000_AO_00_SINGLE_REG);
1394 + me4000_outl(0x8000, info->me4000_regbase + ME4000_AO_01_SINGLE_REG);
1395 + me4000_outl(0x8000, info->me4000_regbase + ME4000_AO_02_SINGLE_REG);
1396 + me4000_outl(0x8000, info->me4000_regbase + ME4000_AO_03_SINGLE_REG);
1398 + /* Enable interrupts on the PLX */
1399 + me4000_outl(0x43, info->plx_regbase + PLX_INTCSR);
1401 + /* Set the adustment register for AO demux */
1402 + me4000_outl(ME4000_AO_DEMUX_ADJUST_VALUE,
1403 + info->me4000_regbase + ME4000_AO_DEMUX_ADJUST_REG);
1405 + /* Set digital I/O direction for port 0 to output on isolated versions */
1406 + if (!(me4000_inl(info->me4000_regbase + ME4000_DIO_DIR_REG) & 0x1)) {
1407 + me4000_outl(0x1, info->me4000_regbase + ME4000_DIO_CTRL_REG);
1413 +static int me4000_open(struct inode *inode_p, struct file *file_p)
1415 + int board, dev, mode;
1418 + struct list_head *ptr;
1419 + me4000_info_t *board_info = NULL;
1420 + me4000_ao_context_t *ao_context = NULL;
1421 + me4000_ai_context_t *ai_context = NULL;
1422 + me4000_dio_context_t *dio_context = NULL;
1423 + me4000_cnt_context_t *cnt_context = NULL;
1424 + me4000_ext_int_context_t *ext_int_context = NULL;
1426 + CALL_PDEBUG("me4000_open() is executed\n");
1428 + /* Analog output */
1429 + if (MAJOR(inode_p->i_rdev) == me4000_ao_major_driver_no) {
1430 + board = AO_BOARD(inode_p->i_rdev);
1431 + dev = AO_PORT(inode_p->i_rdev);
1432 + mode = AO_MODE(inode_p->i_rdev);
1434 + PDEBUG("me4000_open():board = %d ao = %d mode = %d\n", board,
1437 + /* Search for the board context */
1438 + for (ptr = me4000_board_info_list.next, i = 0;
1439 + ptr != &me4000_board_info_list; ptr = ptr->next, i++) {
1440 + board_info = list_entry(ptr, me4000_info_t, list);
1445 + if (ptr == &me4000_board_info_list) {
1447 + "ME4000:me4000_open():Board %d not in device list\n",
1452 + /* Search for the dac context */
1453 + for (ptr = board_info->ao_context_list.next, i = 0;
1454 + ptr != &board_info->ao_context_list;
1455 + ptr = ptr->next, i++) {
1456 + ao_context = list_entry(ptr, me4000_ao_context_t, list);
1461 + if (ptr == &board_info->ao_context_list) {
1463 + "ME4000:me4000_open():Device %d not in device list\n",
1468 + /* Check if mode is valid */
1471 + "ME4000:me4000_open():Mode is not valid\n");
1475 + /* Check if mode is valid for this AO */
1476 + if ((mode != ME4000_AO_CONV_MODE_SINGLE)
1477 + && (dev >= board_info->board_p->ao.fifo_count)) {
1479 + "ME4000:me4000_open():AO %d only in single mode available\n",
1484 + /* Check if already opened */
1485 + spin_lock(&ao_context->use_lock);
1486 + if (ao_context->dac_in_use) {
1488 + "ME4000:me4000_open():AO %d already in use\n",
1490 + spin_unlock(&ao_context->use_lock);
1493 + ao_context->dac_in_use = 1;
1494 + spin_unlock(&ao_context->use_lock);
1496 + ao_context->mode = mode;
1498 + /* Hold the context in private data */
1499 + file_p->private_data = ao_context;
1501 + /* Set file operations pointer */
1502 + file_p->f_op = me4000_ao_fops_array[mode];
1504 + err = me4000_ao_prepare(ao_context);
1506 + ao_context->dac_in_use = 0;
1510 + /* Analog input */
1511 + else if (MAJOR(inode_p->i_rdev) == me4000_ai_major_driver_no) {
1512 + board = AI_BOARD(inode_p->i_rdev);
1513 + mode = AI_MODE(inode_p->i_rdev);
1515 + PDEBUG("me4000_open():ai board = %d mode = %d\n", board, mode);
1517 + /* Search for the board context */
1518 + for (ptr = me4000_board_info_list.next, i = 0;
1519 + ptr != &me4000_board_info_list; ptr = ptr->next, i++) {
1520 + board_info = list_entry(ptr, me4000_info_t, list);
1525 + if (ptr == &me4000_board_info_list) {
1527 + "ME4000:me4000_open():Board %d not in device list\n",
1532 + ai_context = board_info->ai_context;
1534 + /* Check if mode is valid */
1537 + "ME4000:me4000_open():Mode is not valid\n");
1541 + /* Check if already opened */
1542 + spin_lock(&ai_context->use_lock);
1543 + if (ai_context->in_use) {
1545 + "ME4000:me4000_open():AI already in use\n");
1546 + spin_unlock(&ai_context->use_lock);
1549 + ai_context->in_use = 1;
1550 + spin_unlock(&ai_context->use_lock);
1552 + ai_context->mode = mode;
1554 + /* Hold the context in private data */
1555 + file_p->private_data = ai_context;
1557 + /* Set file operations pointer */
1558 + file_p->f_op = me4000_ai_fops_array[mode];
1560 + /* Prepare analog input */
1561 + me4000_ai_prepare(ai_context);
1564 + else if (MAJOR(inode_p->i_rdev) == me4000_dio_major_driver_no) {
1565 + board = DIO_BOARD(inode_p->i_rdev);
1569 + PDEBUG("me4000_open():board = %d\n", board);
1571 + /* Search for the board context */
1572 + for (ptr = me4000_board_info_list.next;
1573 + ptr != &me4000_board_info_list; ptr = ptr->next) {
1574 + board_info = list_entry(ptr, me4000_info_t, list);
1575 + if (board_info->board_count == board)
1579 + if (ptr == &me4000_board_info_list) {
1581 + "ME4000:me4000_open():Board %d not in device list\n",
1586 + /* Search for the dio context */
1587 + dio_context = board_info->dio_context;
1589 + /* Check if already opened */
1590 + spin_lock(&dio_context->use_lock);
1591 + if (dio_context->in_use) {
1593 + "ME4000:me4000_open():DIO already in use\n");
1594 + spin_unlock(&dio_context->use_lock);
1597 + dio_context->in_use = 1;
1598 + spin_unlock(&dio_context->use_lock);
1600 + /* Hold the context in private data */
1601 + file_p->private_data = dio_context;
1603 + /* Set file operations pointer to single functions */
1604 + file_p->f_op = &me4000_dio_fops;
1606 + //me4000_dio_reset(dio_context);
1609 + else if (MAJOR(inode_p->i_rdev) == me4000_cnt_major_driver_no) {
1610 + board = CNT_BOARD(inode_p->i_rdev);
1614 + PDEBUG("me4000_open():board = %d\n", board);
1616 + /* Search for the board context */
1617 + for (ptr = me4000_board_info_list.next;
1618 + ptr != &me4000_board_info_list; ptr = ptr->next) {
1619 + board_info = list_entry(ptr, me4000_info_t, list);
1620 + if (board_info->board_count == board)
1624 + if (ptr == &me4000_board_info_list) {
1626 + "ME4000:me4000_open():Board %d not in device list\n",
1631 + /* Get the cnt context */
1632 + cnt_context = board_info->cnt_context;
1634 + /* Check if already opened */
1635 + spin_lock(&cnt_context->use_lock);
1636 + if (cnt_context->in_use) {
1638 + "ME4000:me4000_open():CNT already in use\n");
1639 + spin_unlock(&cnt_context->use_lock);
1642 + cnt_context->in_use = 1;
1643 + spin_unlock(&cnt_context->use_lock);
1645 + /* Hold the context in private data */
1646 + file_p->private_data = cnt_context;
1648 + /* Set file operations pointer to single functions */
1649 + file_p->f_op = &me4000_cnt_fops;
1651 + /* External Interrupt */
1652 + else if (MAJOR(inode_p->i_rdev) == me4000_ext_int_major_driver_no) {
1653 + board = EXT_INT_BOARD(inode_p->i_rdev);
1657 + PDEBUG("me4000_open():board = %d\n", board);
1659 + /* Search for the board context */
1660 + for (ptr = me4000_board_info_list.next;
1661 + ptr != &me4000_board_info_list; ptr = ptr->next) {
1662 + board_info = list_entry(ptr, me4000_info_t, list);
1663 + if (board_info->board_count == board)
1667 + if (ptr == &me4000_board_info_list) {
1669 + "ME4000:me4000_open():Board %d not in device list\n",
1674 + /* Get the external interrupt context */
1675 + ext_int_context = board_info->ext_int_context;
1677 + /* Check if already opened */
1678 + spin_lock(&cnt_context->use_lock);
1679 + if (ext_int_context->in_use) {
1681 + "ME4000:me4000_open():External interrupt already in use\n");
1682 + spin_unlock(&ext_int_context->use_lock);
1685 + ext_int_context->in_use = 1;
1686 + spin_unlock(&ext_int_context->use_lock);
1688 + /* Hold the context in private data */
1689 + file_p->private_data = ext_int_context;
1691 + /* Set file operations pointer to single functions */
1692 + file_p->f_op = &me4000_ext_int_fops;
1694 + /* Request the interrupt line */
1696 + request_irq(ext_int_context->irq, me4000_ext_int_isr,
1697 + IRQF_DISABLED | IRQF_SHARED, ME4000_NAME,
1701 + "ME4000:me4000_open():Can't get interrupt line");
1702 + ext_int_context->in_use = 0;
1706 + /* Reset the counter */
1707 + me4000_ext_int_disable(ext_int_context);
1709 + printk(KERN_ERR "ME4000:me4000_open():Major number unknown\n");
1716 +static int me4000_release(struct inode *inode_p, struct file *file_p)
1718 + me4000_ao_context_t *ao_context;
1719 + me4000_ai_context_t *ai_context;
1720 + me4000_dio_context_t *dio_context;
1721 + me4000_cnt_context_t *cnt_context;
1722 + me4000_ext_int_context_t *ext_int_context;
1724 + CALL_PDEBUG("me4000_release() is executed\n");
1726 + if (MAJOR(inode_p->i_rdev) == me4000_ao_major_driver_no) {
1727 + ao_context = file_p->private_data;
1729 + /* Mark DAC as unused */
1730 + ao_context->dac_in_use = 0;
1731 + } else if (MAJOR(inode_p->i_rdev) == me4000_ai_major_driver_no) {
1732 + ai_context = file_p->private_data;
1734 + /* Reset the analog input */
1735 + me4000_ai_reset(ai_context);
1737 + /* Free the interrupt and the circular buffer */
1738 + if (ai_context->mode) {
1739 + free_irq(ai_context->irq, ai_context);
1740 + kfree(ai_context->circ_buf.buf);
1741 + ai_context->circ_buf.buf = NULL;
1742 + ai_context->circ_buf.head = 0;
1743 + ai_context->circ_buf.tail = 0;
1746 + /* Mark AI as unused */
1747 + ai_context->in_use = 0;
1748 + } else if (MAJOR(inode_p->i_rdev) == me4000_dio_major_driver_no) {
1749 + dio_context = file_p->private_data;
1751 + /* Mark digital I/O as unused */
1752 + dio_context->in_use = 0;
1753 + } else if (MAJOR(inode_p->i_rdev) == me4000_cnt_major_driver_no) {
1754 + cnt_context = file_p->private_data;
1756 + /* Mark counters as unused */
1757 + cnt_context->in_use = 0;
1758 + } else if (MAJOR(inode_p->i_rdev) == me4000_ext_int_major_driver_no) {
1759 + ext_int_context = file_p->private_data;
1761 + /* Disable the externel interrupt */
1762 + me4000_ext_int_disable(ext_int_context);
1764 + free_irq(ext_int_context->irq, ext_int_context);
1766 + /* Delete the fasync structure and free memory */
1767 + me4000_ext_int_fasync(0, file_p, 0);
1769 + /* Mark as unused */
1770 + ext_int_context->in_use = 0;
1773 + "ME4000:me4000_release():Major number unknown\n");
1780 +/*------------------------------- Analog output stuff --------------------------------------*/
1782 +static int me4000_ao_prepare(me4000_ao_context_t * ao_context)
1784 + unsigned long flags;
1786 + CALL_PDEBUG("me4000_ao_prepare() is executed\n");
1788 + if (ao_context->mode == ME4000_AO_CONV_MODE_CONTINUOUS) {
1789 + /* Only do anything if not already in the correct mode */
1790 + unsigned long mode = me4000_inl(ao_context->ctrl_reg);
1791 + if ((mode & ME4000_AO_CONV_MODE_CONTINUOUS)
1792 + && (mode & ME4000_AO_CTRL_BIT_ENABLE_FIFO)) {
1796 + /* Stop any conversion */
1797 + me4000_ao_immediate_stop(ao_context);
1799 + /* Set the control register to default state */
1800 + spin_lock_irqsave(&ao_context->int_lock, flags);
1801 + me4000_outl(ME4000_AO_CONV_MODE_CONTINUOUS |
1802 + ME4000_AO_CTRL_BIT_ENABLE_FIFO |
1803 + ME4000_AO_CTRL_BIT_STOP |
1804 + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP,
1805 + ao_context->ctrl_reg);
1806 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
1808 + /* Set to fastest sample rate */
1809 + me4000_outl(65, ao_context->timer_reg);
1810 + } else if (ao_context->mode == ME4000_AO_CONV_MODE_WRAPAROUND) {
1811 + /* Only do anything if not already in the correct mode */
1812 + unsigned long mode = me4000_inl(ao_context->ctrl_reg);
1813 + if ((mode & ME4000_AO_CONV_MODE_WRAPAROUND)
1814 + && (mode & ME4000_AO_CTRL_BIT_ENABLE_FIFO)) {
1818 + /* Stop any conversion */
1819 + me4000_ao_immediate_stop(ao_context);
1821 + /* Set the control register to default state */
1822 + spin_lock_irqsave(&ao_context->int_lock, flags);
1823 + me4000_outl(ME4000_AO_CONV_MODE_WRAPAROUND |
1824 + ME4000_AO_CTRL_BIT_ENABLE_FIFO |
1825 + ME4000_AO_CTRL_BIT_STOP |
1826 + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP,
1827 + ao_context->ctrl_reg);
1828 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
1830 + /* Set to fastest sample rate */
1831 + me4000_outl(65, ao_context->timer_reg);
1832 + } else if (ao_context->mode == ME4000_AO_CONV_MODE_SINGLE) {
1833 + /* Only do anything if not already in the correct mode */
1834 + unsigned long mode = me4000_inl(ao_context->ctrl_reg);
1837 + (ME4000_AO_CONV_MODE_WRAPAROUND |
1838 + ME4000_AO_CONV_MODE_CONTINUOUS))) {
1842 + /* Stop any conversion */
1843 + me4000_ao_immediate_stop(ao_context);
1845 + /* Clear the control register */
1846 + spin_lock_irqsave(&ao_context->int_lock, flags);
1847 + me4000_outl(0x0, ao_context->ctrl_reg);
1848 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
1850 + /* Set voltage to 0V */
1851 + me4000_outl(0x8000, ao_context->single_reg);
1854 + "ME4000:me4000_ao_prepare():Invalid mode specified\n");
1861 +static int me4000_ao_reset(me4000_ao_context_t * ao_context)
1864 + wait_queue_head_t queue;
1865 + unsigned long flags;
1867 + CALL_PDEBUG("me4000_ao_reset() is executed\n");
1869 + init_waitqueue_head(&queue);
1871 + if (ao_context->mode == ME4000_AO_CONV_MODE_WRAPAROUND) {
1873 + * First stop conversion of the DAC before reconfigure.
1874 + * This is essantial, cause of the state machine.
1875 + * If not stopped before configuring mode, it could
1876 + * walk in a undefined state.
1878 + tmp = me4000_inl(ao_context->ctrl_reg);
1879 + tmp |= ME4000_AO_CTRL_BIT_IMMEDIATE_STOP;
1880 + me4000_outl(tmp, ao_context->ctrl_reg);
1882 + while (inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) {
1883 + sleep_on_timeout(&queue, 1);
1886 + /* Set to transparent mode */
1887 + me4000_ao_simultaneous_disable(ao_context);
1889 + /* Set to single mode in order to set default voltage */
1890 + me4000_outl(0x0, ao_context->ctrl_reg);
1892 + /* Set voltage to 0V */
1893 + me4000_outl(0x8000, ao_context->single_reg);
1895 + /* Set to fastest sample rate */
1896 + me4000_outl(65, ao_context->timer_reg);
1898 + /* Set the original mode and enable FIFO */
1899 + me4000_outl(ME4000_AO_CONV_MODE_WRAPAROUND |
1900 + ME4000_AO_CTRL_BIT_ENABLE_FIFO |
1901 + ME4000_AO_CTRL_BIT_STOP |
1902 + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP,
1903 + ao_context->ctrl_reg);
1904 + } else if (ao_context->mode == ME4000_AO_CONV_MODE_CONTINUOUS) {
1906 + * First stop conversion of the DAC before reconfigure.
1907 + * This is essantial, cause of the state machine.
1908 + * If not stopped before configuring mode, it could
1909 + * walk in a undefined state.
1911 + spin_lock_irqsave(&ao_context->int_lock, flags);
1912 + tmp = me4000_inl(ao_context->ctrl_reg);
1913 + tmp |= ME4000_AO_CTRL_BIT_STOP;
1914 + me4000_outl(tmp, ao_context->ctrl_reg);
1915 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
1917 + while (inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) {
1918 + sleep_on_timeout(&queue, 1);
1921 + /* Clear the circular buffer */
1922 + ao_context->circ_buf.head = 0;
1923 + ao_context->circ_buf.tail = 0;
1925 + /* Set to transparent mode */
1926 + me4000_ao_simultaneous_disable(ao_context);
1928 + /* Set to single mode in order to set default voltage */
1929 + spin_lock_irqsave(&ao_context->int_lock, flags);
1930 + tmp = me4000_inl(ao_context->ctrl_reg);
1931 + me4000_outl(0x0, ao_context->ctrl_reg);
1933 + /* Set voltage to 0V */
1934 + me4000_outl(0x8000, ao_context->single_reg);
1936 + /* Set to fastest sample rate */
1937 + me4000_outl(65, ao_context->timer_reg);
1939 + /* Set the original mode and enable FIFO */
1940 + me4000_outl(ME4000_AO_CONV_MODE_CONTINUOUS |
1941 + ME4000_AO_CTRL_BIT_ENABLE_FIFO |
1942 + ME4000_AO_CTRL_BIT_STOP |
1943 + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP,
1944 + ao_context->ctrl_reg);
1945 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
1947 + /* Set to transparent mode */
1948 + me4000_ao_simultaneous_disable(ao_context);
1950 + /* Set voltage to 0V */
1951 + me4000_outl(0x8000, ao_context->single_reg);
1957 +static ssize_t me4000_ao_write_sing(struct file *filep, const char *buff,
1958 + size_t cnt, loff_t * offp)
1960 + me4000_ao_context_t *ao_context = filep->private_data;
1962 + const u16 *buffer = (const u16 *)buff;
1964 + CALL_PDEBUG("me4000_ao_write_sing() is executed\n");
1968 + "me4000_ao_write_sing():Write count is not 2\n");
1972 + if (get_user(value, buffer)) {
1974 + "me4000_ao_write_sing():Cannot copy data from user\n");
1978 + me4000_outl(value, ao_context->single_reg);
1983 +static ssize_t me4000_ao_write_wrap(struct file *filep, const char *buff,
1984 + size_t cnt, loff_t * offp)
1986 + me4000_ao_context_t *ao_context = filep->private_data;
1990 + const u16 *buffer = (const u16 *)buff;
1991 + size_t count = cnt / 2;
1993 + CALL_PDEBUG("me4000_ao_write_wrap() is executed\n");
1995 + /* Check if a conversion is already running */
1996 + if (inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) {
1998 + "ME4000:me4000_ao_write_wrap():There is already a conversion running\n");
2002 + if (count > ME4000_AO_FIFO_COUNT) {
2004 + "me4000_ao_write_wrap():Can't load more than %d values\n",
2005 + ME4000_AO_FIFO_COUNT);
2009 + /* Reset the FIFO */
2010 + tmp = inl(ao_context->ctrl_reg);
2011 + tmp &= ~ME4000_AO_CTRL_BIT_ENABLE_FIFO;
2012 + outl(tmp, ao_context->ctrl_reg);
2013 + tmp |= ME4000_AO_CTRL_BIT_ENABLE_FIFO;
2014 + outl(tmp, ao_context->ctrl_reg);
2016 + for (i = 0; i < count; i++) {
2017 + if (get_user(value, buffer + i)) {
2019 + "me4000_ao_write_single():Cannot copy data from user\n");
2022 + if (((ao_context->fifo_reg & 0xFF) == ME4000_AO_01_FIFO_REG)
2023 + || ((ao_context->fifo_reg & 0xFF) == ME4000_AO_03_FIFO_REG))
2024 + value = value << 16;
2025 + outl(value, ao_context->fifo_reg);
2027 + CALL_PDEBUG("me4000_ao_write_wrap() is leaved with %d\n", i * 2);
2032 +static ssize_t me4000_ao_write_cont(struct file *filep, const char *buff,
2033 + size_t cnt, loff_t * offp)
2035 + me4000_ao_context_t *ao_context = filep->private_data;
2036 + const u16 *buffer = (const u16 *)buff;
2037 + size_t count = cnt / 2;
2038 + unsigned long flags;
2046 + wait_queue_head_t queue;
2048 + CALL_PDEBUG("me4000_ao_write_cont() is executed\n");
2050 + init_waitqueue_head(&queue);
2054 + PDEBUG("me4000_ao_write_cont():Count is 0\n");
2058 + if (filep->f_flags & O_APPEND) {
2059 + PDEBUG("me4000_ao_write_cont():Append data to data stream\n");
2060 + while (count > 0) {
2061 + if (filep->f_flags & O_NONBLOCK) {
2062 + if (ao_context->pipe_flag) {
2064 + "ME4000:me4000_ao_write_cont():Broken pipe in nonblocking write\n");
2067 + c = me4000_space_to_end(ao_context->circ_buf,
2068 + ME4000_AO_BUFFER_COUNT);
2071 + ("me4000_ao_write_cont():Returning from nonblocking write\n");
2075 + wait_event_interruptible(ao_context->wait_queue,
2077 + me4000_space_to_end
2078 + (ao_context->circ_buf,
2079 + ME4000_AO_BUFFER_COUNT)));
2080 + if (ao_context->pipe_flag) {
2082 + "me4000_ao_write_cont():Broken pipe in blocking write\n");
2085 + if (signal_pending(current)) {
2087 + "me4000_ao_write_cont():Wait for free buffer interrupted from signal\n");
2092 + PDEBUG("me4000_ao_write_cont():Space to end = %d\n", c);
2094 + /* Only able to write size of free buffer or size of count */
2099 + k -= copy_from_user(ao_context->circ_buf.buf +
2100 + ao_context->circ_buf.head, buffer,
2104 + ("me4000_ao_write_cont():Copy %d values from user space\n",
2110 + ao_context->circ_buf.head =
2111 + (ao_context->circ_buf.head +
2112 + c) & (ME4000_AO_BUFFER_COUNT - 1);
2117 + /* Values are now available so enable interrupts */
2118 + spin_lock_irqsave(&ao_context->int_lock, flags);
2119 + if (me4000_buf_count
2120 + (ao_context->circ_buf, ME4000_AO_BUFFER_COUNT)) {
2121 + tmp = me4000_inl(ao_context->ctrl_reg);
2122 + tmp |= ME4000_AO_CTRL_BIT_ENABLE_IRQ;
2123 + me4000_outl(tmp, ao_context->ctrl_reg);
2125 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2128 + /* Wait until the state machine is stopped if O_SYNC is set */
2129 + if (filep->f_flags & O_SYNC) {
2130 + while (inl(ao_context->status_reg) &
2131 + ME4000_AO_STATUS_BIT_FSM) {
2132 + interruptible_sleep_on_timeout(&queue, 1);
2133 + if (ao_context->pipe_flag) {
2135 + ("me4000_ao_write_cont():Broken pipe detected after sync\n");
2138 + if (signal_pending(current)) {
2140 + "me4000_ao_write_cont():Wait on state machine after sync interrupted\n");
2146 + PDEBUG("me4000_ao_write_cont():Preload DAC FIFO\n");
2147 + if ((me4000_inl(ao_context->status_reg) &
2148 + ME4000_AO_STATUS_BIT_FSM)) {
2150 + "me4000_ao_write_cont():Can't Preload DAC FIFO while conversion is running\n");
2154 + /* Clear the FIFO */
2155 + spin_lock_irqsave(&ao_context->int_lock, flags);
2156 + tmp = me4000_inl(ao_context->ctrl_reg);
2158 + ~(ME4000_AO_CTRL_BIT_ENABLE_FIFO |
2159 + ME4000_AO_CTRL_BIT_ENABLE_IRQ);
2160 + me4000_outl(tmp, ao_context->ctrl_reg);
2161 + tmp |= ME4000_AO_CTRL_BIT_ENABLE_FIFO;
2162 + me4000_outl(tmp, ao_context->ctrl_reg);
2163 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2165 + /* Clear the circular buffer */
2166 + ao_context->circ_buf.head = 0;
2167 + ao_context->circ_buf.tail = 0;
2169 + /* Reset the broken pipe flag */
2170 + ao_context->pipe_flag = 0;
2172 + /* Only able to write size of fifo or count */
2173 + c = ME4000_AO_FIFO_COUNT;
2178 + ("me4000_ao_write_cont():Write %d values to DAC on 0x%lX\n",
2179 + c, ao_context->fifo_reg);
2181 + /* Write values to the fifo */
2182 + for (i = 0; i < c; i++) {
2183 + if (get_user(svalue, buffer))
2186 + if (((ao_context->fifo_reg & 0xFF) ==
2187 + ME4000_AO_01_FIFO_REG)
2188 + || ((ao_context->fifo_reg & 0xFF) ==
2189 + ME4000_AO_03_FIFO_REG)) {
2190 + lvalue = ((u32) svalue) << 16;
2192 + lvalue = (u32) svalue;
2194 + outl(lvalue, ao_context->fifo_reg);
2201 + /* Get free buffer */
2202 + c = me4000_space_to_end(ao_context->circ_buf,
2203 + ME4000_AO_BUFFER_COUNT);
2208 + /* Only able to write size of free buffer or size of count */
2212 + /* If count = 0 return to user */
2215 + ("me4000_ao_write_cont():Count reached 0\n");
2220 + k -= copy_from_user(ao_context->circ_buf.buf +
2221 + ao_context->circ_buf.head, buffer,
2225 + ("me4000_ao_write_cont():Wrote %d values to buffer\n",
2231 + ao_context->circ_buf.head =
2232 + (ao_context->circ_buf.head +
2233 + c) & (ME4000_AO_BUFFER_COUNT - 1);
2238 + /* If values in the buffer are available so enable interrupts */
2239 + spin_lock_irqsave(&ao_context->int_lock, flags);
2240 + if (me4000_buf_count
2241 + (ao_context->circ_buf, ME4000_AO_BUFFER_COUNT)) {
2243 + ("me4000_ao_write_cont():Enable Interrupts\n");
2244 + tmp = me4000_inl(ao_context->ctrl_reg);
2245 + tmp |= ME4000_AO_CTRL_BIT_ENABLE_IRQ;
2246 + me4000_outl(tmp, ao_context->ctrl_reg);
2248 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2252 + if (filep->f_flags & O_NONBLOCK) {
2253 + return (ret == 0) ? -EAGAIN : 2 * ret;
2259 +static unsigned int me4000_ao_poll_cont(struct file *file_p, poll_table * wait)
2261 + me4000_ao_context_t *ao_context;
2262 + unsigned long mask = 0;
2264 + CALL_PDEBUG("me4000_ao_poll_cont() is executed\n");
2266 + ao_context = file_p->private_data;
2268 + poll_wait(file_p, &ao_context->wait_queue, wait);
2270 + /* Get free buffer */
2271 + if (me4000_space_to_end(ao_context->circ_buf, ME4000_AO_BUFFER_COUNT))
2272 + mask |= POLLOUT | POLLWRNORM;
2274 + CALL_PDEBUG("me4000_ao_poll_cont():Return mask %lX\n", mask);
2279 +static int me4000_ao_fsync_cont(struct file *file_p, struct dentry *dentry_p,
2282 + me4000_ao_context_t *ao_context;
2283 + wait_queue_head_t queue;
2285 + CALL_PDEBUG("me4000_ao_fsync_cont() is executed\n");
2287 + ao_context = file_p->private_data;
2288 + init_waitqueue_head(&queue);
2290 + while (inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) {
2291 + interruptible_sleep_on_timeout(&queue, 1);
2292 + if (ao_context->pipe_flag) {
2294 + "me4000_ao_fsync_cont():Broken pipe detected\n");
2298 + if (signal_pending(current)) {
2300 + "me4000_ao_fsync_cont():Wait on state machine interrupted\n");
2308 +static int me4000_ao_ioctl_sing(struct inode *inode_p, struct file *file_p,
2309 + unsigned int service, unsigned long arg)
2311 + me4000_ao_context_t *ao_context;
2313 + CALL_PDEBUG("me4000_ao_ioctl_sing() is executed\n");
2315 + ao_context = file_p->private_data;
2317 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
2319 + PDEBUG("me4000_ao_ioctl_sing():Wrong magic number\n");
2322 + switch (service) {
2323 + case ME4000_AO_EX_TRIG_SETUP:
2324 + return me4000_ao_ex_trig_set_edge((int *)arg, ao_context);
2325 + case ME4000_AO_EX_TRIG_ENABLE:
2326 + return me4000_ao_ex_trig_enable(ao_context);
2327 + case ME4000_AO_EX_TRIG_DISABLE:
2328 + return me4000_ao_ex_trig_disable(ao_context);
2329 + case ME4000_AO_PRELOAD:
2330 + return me4000_ao_preload(ao_context);
2331 + case ME4000_AO_PRELOAD_UPDATE:
2332 + return me4000_ao_preload_update(ao_context);
2333 + case ME4000_GET_USER_INFO:
2334 + return me4000_get_user_info((me4000_user_info_t *) arg,
2335 + ao_context->board_info);
2336 + case ME4000_AO_SIMULTANEOUS_EX_TRIG:
2337 + return me4000_ao_simultaneous_ex_trig(ao_context);
2338 + case ME4000_AO_SIMULTANEOUS_SW:
2339 + return me4000_ao_simultaneous_sw(ao_context);
2340 + case ME4000_AO_SIMULTANEOUS_DISABLE:
2341 + return me4000_ao_simultaneous_disable(ao_context);
2342 + case ME4000_AO_SIMULTANEOUS_UPDATE:
2344 + me4000_ao_simultaneous_update((me4000_ao_channel_list_t *)
2346 + case ME4000_AO_EX_TRIG_TIMEOUT:
2347 + return me4000_ao_ex_trig_timeout((unsigned long *)arg,
2349 + case ME4000_AO_DISABLE_DO:
2350 + return me4000_ao_disable_do(ao_context);
2353 + "me4000_ao_ioctl_sing():Service number invalid\n");
2360 +static int me4000_ao_ioctl_wrap(struct inode *inode_p, struct file *file_p,
2361 + unsigned int service, unsigned long arg)
2363 + me4000_ao_context_t *ao_context;
2365 + CALL_PDEBUG("me4000_ao_ioctl_wrap() is executed\n");
2367 + ao_context = file_p->private_data;
2369 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
2371 + PDEBUG("me4000_ao_ioctl_wrap():Wrong magic number\n");
2374 + switch (service) {
2375 + case ME4000_AO_START:
2376 + return me4000_ao_start((unsigned long *)arg, ao_context);
2377 + case ME4000_AO_STOP:
2378 + return me4000_ao_stop(ao_context);
2379 + case ME4000_AO_IMMEDIATE_STOP:
2380 + return me4000_ao_immediate_stop(ao_context);
2381 + case ME4000_AO_RESET:
2382 + return me4000_ao_reset(ao_context);
2383 + case ME4000_AO_TIMER_SET_DIVISOR:
2384 + return me4000_ao_timer_set_divisor((u32 *) arg, ao_context);
2385 + case ME4000_AO_EX_TRIG_SETUP:
2386 + return me4000_ao_ex_trig_set_edge((int *)arg, ao_context);
2387 + case ME4000_AO_EX_TRIG_ENABLE:
2388 + return me4000_ao_ex_trig_enable(ao_context);
2389 + case ME4000_AO_EX_TRIG_DISABLE:
2390 + return me4000_ao_ex_trig_disable(ao_context);
2391 + case ME4000_GET_USER_INFO:
2392 + return me4000_get_user_info((me4000_user_info_t *) arg,
2393 + ao_context->board_info);
2394 + case ME4000_AO_FSM_STATE:
2395 + return me4000_ao_fsm_state((int *)arg, ao_context);
2396 + case ME4000_AO_ENABLE_DO:
2397 + return me4000_ao_enable_do(ao_context);
2398 + case ME4000_AO_DISABLE_DO:
2399 + return me4000_ao_disable_do(ao_context);
2400 + case ME4000_AO_SYNCHRONOUS_EX_TRIG:
2401 + return me4000_ao_synchronous_ex_trig(ao_context);
2402 + case ME4000_AO_SYNCHRONOUS_SW:
2403 + return me4000_ao_synchronous_sw(ao_context);
2404 + case ME4000_AO_SYNCHRONOUS_DISABLE:
2405 + return me4000_ao_synchronous_disable(ao_context);
2412 +static int me4000_ao_ioctl_cont(struct inode *inode_p, struct file *file_p,
2413 + unsigned int service, unsigned long arg)
2415 + me4000_ao_context_t *ao_context;
2417 + CALL_PDEBUG("me4000_ao_ioctl_cont() is executed\n");
2419 + ao_context = file_p->private_data;
2421 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
2423 + PDEBUG("me4000_ao_ioctl_cont():Wrong magic number\n");
2426 + switch (service) {
2427 + case ME4000_AO_START:
2428 + return me4000_ao_start((unsigned long *)arg, ao_context);
2429 + case ME4000_AO_STOP:
2430 + return me4000_ao_stop(ao_context);
2431 + case ME4000_AO_IMMEDIATE_STOP:
2432 + return me4000_ao_immediate_stop(ao_context);
2433 + case ME4000_AO_RESET:
2434 + return me4000_ao_reset(ao_context);
2435 + case ME4000_AO_TIMER_SET_DIVISOR:
2436 + return me4000_ao_timer_set_divisor((u32 *) arg, ao_context);
2437 + case ME4000_AO_EX_TRIG_SETUP:
2438 + return me4000_ao_ex_trig_set_edge((int *)arg, ao_context);
2439 + case ME4000_AO_EX_TRIG_ENABLE:
2440 + return me4000_ao_ex_trig_enable(ao_context);
2441 + case ME4000_AO_EX_TRIG_DISABLE:
2442 + return me4000_ao_ex_trig_disable(ao_context);
2443 + case ME4000_AO_ENABLE_DO:
2444 + return me4000_ao_enable_do(ao_context);
2445 + case ME4000_AO_DISABLE_DO:
2446 + return me4000_ao_disable_do(ao_context);
2447 + case ME4000_AO_FSM_STATE:
2448 + return me4000_ao_fsm_state((int *)arg, ao_context);
2449 + case ME4000_GET_USER_INFO:
2450 + return me4000_get_user_info((me4000_user_info_t *) arg,
2451 + ao_context->board_info);
2452 + case ME4000_AO_SYNCHRONOUS_EX_TRIG:
2453 + return me4000_ao_synchronous_ex_trig(ao_context);
2454 + case ME4000_AO_SYNCHRONOUS_SW:
2455 + return me4000_ao_synchronous_sw(ao_context);
2456 + case ME4000_AO_SYNCHRONOUS_DISABLE:
2457 + return me4000_ao_synchronous_disable(ao_context);
2458 + case ME4000_AO_GET_FREE_BUFFER:
2459 + return me4000_ao_get_free_buffer((unsigned long *)arg,
2467 +static int me4000_ao_start(unsigned long *arg, me4000_ao_context_t * ao_context)
2470 + wait_queue_head_t queue;
2471 + unsigned long ref;
2472 + unsigned long timeout;
2473 + unsigned long flags;
2475 + CALL_PDEBUG("me4000_ao_start() is executed\n");
2477 + if (get_user(timeout, arg)) {
2479 + "me4000_ao_start():Cannot copy data from user\n");
2483 + init_waitqueue_head(&queue);
2485 + spin_lock_irqsave(&ao_context->int_lock, flags);
2486 + tmp = inl(ao_context->ctrl_reg);
2487 + tmp &= ~(ME4000_AO_CTRL_BIT_STOP | ME4000_AO_CTRL_BIT_IMMEDIATE_STOP);
2488 + me4000_outl(tmp, ao_context->ctrl_reg);
2489 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2491 + if ((tmp & ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG)) {
2495 + (inl(ao_context->status_reg) &
2496 + ME4000_AO_STATUS_BIT_FSM)) {
2497 + interruptible_sleep_on_timeout(&queue, 1);
2498 + if (signal_pending(current)) {
2500 + "ME4000:me4000_ao_start():Wait on start of state machine interrupted\n");
2503 + if (((jiffies - ref) > (timeout * HZ / USER_HZ))) { // 2.6 has diffrent definitions for HZ in user and kernel space
2505 + "ME4000:me4000_ao_start():Timeout reached\n");
2511 + me4000_outl(0x8000, ao_context->single_reg);
2517 +static int me4000_ao_stop(me4000_ao_context_t * ao_context)
2520 + wait_queue_head_t queue;
2521 + unsigned long flags;
2523 + init_waitqueue_head(&queue);
2525 + CALL_PDEBUG("me4000_ao_stop() is executed\n");
2527 + /* Set the stop bit */
2528 + spin_lock_irqsave(&ao_context->int_lock, flags);
2529 + tmp = inl(ao_context->ctrl_reg);
2530 + tmp |= ME4000_AO_CTRL_BIT_STOP;
2531 + me4000_outl(tmp, ao_context->ctrl_reg);
2532 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2534 + while (inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) {
2535 + interruptible_sleep_on_timeout(&queue, 1);
2536 + if (signal_pending(current)) {
2538 + "me4000_ao_stop():Wait on state machine after stop interrupted\n");
2543 + /* Clear the stop bit */
2544 + //tmp &= ~ME4000_AO_CTRL_BIT_STOP;
2545 + //me4000_outl(tmp, ao_context->ctrl_reg);
2550 +static int me4000_ao_immediate_stop(me4000_ao_context_t * ao_context)
2553 + wait_queue_head_t queue;
2554 + unsigned long flags;
2556 + init_waitqueue_head(&queue);
2558 + CALL_PDEBUG("me4000_ao_immediate_stop() is executed\n");
2560 + spin_lock_irqsave(&ao_context->int_lock, flags);
2561 + tmp = inl(ao_context->ctrl_reg);
2562 + tmp |= ME4000_AO_CTRL_BIT_STOP | ME4000_AO_CTRL_BIT_IMMEDIATE_STOP;
2563 + me4000_outl(tmp, ao_context->ctrl_reg);
2564 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2566 + while (inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) {
2567 + interruptible_sleep_on_timeout(&queue, 1);
2568 + if (signal_pending(current)) {
2570 + "me4000_ao_immediate_stop():Wait on state machine after stop interrupted\n");
2575 + /* Clear the stop bits */
2576 + //tmp &= ~(ME4000_AO_CTRL_BIT_STOP | ME4000_AO_CTRL_BIT_IMMEDIATE_STOP);
2577 + //me4000_outl(tmp, ao_context->ctrl_reg);
2582 +static int me4000_ao_timer_set_divisor(u32 * arg,
2583 + me4000_ao_context_t * ao_context)
2588 + CALL_PDEBUG("me4000_ao_timer set_divisor() is executed\n");
2590 + if (get_user(divisor, arg))
2593 + /* Check if the state machine is stopped */
2594 + tmp = me4000_inl(ao_context->status_reg);
2595 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2597 + "me4000_ao_timer_set_divisor():Can't set timer while DAC is running\n");
2601 + PDEBUG("me4000_ao_timer set_divisor():Divisor from user = %d\n",
2604 + /* Check if the divisor is right. ME4000_AO_MIN_TICKS is the lowest */
2605 + if (divisor < ME4000_AO_MIN_TICKS) {
2607 + "ME4000:me4000_ao_timer set_divisor():Divisor to low\n");
2611 + /* Fix bug in Firmware */
2614 + PDEBUG("me4000_ao_timer set_divisor():Divisor to HW = %d\n", divisor);
2616 + /* Write the divisor */
2617 + me4000_outl(divisor, ao_context->timer_reg);
2622 +static int me4000_ao_ex_trig_set_edge(int *arg,
2623 + me4000_ao_context_t * ao_context)
2627 + unsigned long flags;
2629 + CALL_PDEBUG("me4000_ao_ex_trig_set_edge() is executed\n");
2631 + if (get_user(mode, arg))
2634 + /* Check if the state machine is stopped */
2635 + tmp = me4000_inl(ao_context->status_reg);
2636 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2638 + "me4000_ao_ex_trig_set_edge():Can't set trigger while DAC is running\n");
2642 + if (mode == ME4000_AO_TRIGGER_EXT_EDGE_RISING) {
2643 + spin_lock_irqsave(&ao_context->int_lock, flags);
2644 + tmp = me4000_inl(ao_context->ctrl_reg);
2646 + ~(ME4000_AO_CTRL_BIT_EX_TRIG_EDGE |
2647 + ME4000_AO_CTRL_BIT_EX_TRIG_BOTH);
2648 + me4000_outl(tmp, ao_context->ctrl_reg);
2649 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2650 + } else if (mode == ME4000_AO_TRIGGER_EXT_EDGE_FALLING) {
2651 + spin_lock_irqsave(&ao_context->int_lock, flags);
2652 + tmp = me4000_inl(ao_context->ctrl_reg);
2653 + tmp &= ~ME4000_AO_CTRL_BIT_EX_TRIG_BOTH;
2654 + tmp |= ME4000_AO_CTRL_BIT_EX_TRIG_EDGE;
2655 + me4000_outl(tmp, ao_context->ctrl_reg);
2656 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2657 + } else if (mode == ME4000_AO_TRIGGER_EXT_EDGE_BOTH) {
2658 + spin_lock_irqsave(&ao_context->int_lock, flags);
2659 + tmp = me4000_inl(ao_context->ctrl_reg);
2661 + ME4000_AO_CTRL_BIT_EX_TRIG_EDGE |
2662 + ME4000_AO_CTRL_BIT_EX_TRIG_BOTH;
2663 + me4000_outl(tmp, ao_context->ctrl_reg);
2664 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2667 + "me4000_ao_ex_trig_set_edge():Invalid trigger mode\n");
2674 +static int me4000_ao_ex_trig_enable(me4000_ao_context_t * ao_context)
2677 + unsigned long flags;
2679 + CALL_PDEBUG("me4000_ao_ex_trig_enable() is executed\n");
2681 + /* Check if the state machine is stopped */
2682 + tmp = me4000_inl(ao_context->status_reg);
2683 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2685 + "me4000_ao_ex_trig_enable():Can't enable trigger while DAC is running\n");
2689 + spin_lock_irqsave(&ao_context->int_lock, flags);
2690 + tmp = me4000_inl(ao_context->ctrl_reg);
2691 + tmp |= ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG;
2692 + me4000_outl(tmp, ao_context->ctrl_reg);
2693 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2698 +static int me4000_ao_ex_trig_disable(me4000_ao_context_t * ao_context)
2701 + unsigned long flags;
2703 + CALL_PDEBUG("me4000_ao_ex_trig_disable() is executed\n");
2705 + /* Check if the state machine is stopped */
2706 + tmp = me4000_inl(ao_context->status_reg);
2707 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2709 + "me4000_ao_ex_trig_disable():Can't disable trigger while DAC is running\n");
2713 + spin_lock_irqsave(&ao_context->int_lock, flags);
2714 + tmp = me4000_inl(ao_context->ctrl_reg);
2715 + tmp &= ~ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG;
2716 + me4000_outl(tmp, ao_context->ctrl_reg);
2717 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2722 +static int me4000_ao_simultaneous_disable(me4000_ao_context_t * ao_context)
2726 + CALL_PDEBUG("me4000_ao_simultaneous_disable() is executed\n");
2728 + /* Check if the state machine is stopped */
2729 + /* Be careful here because this function is called from
2730 + me4000_ao_synchronous disable */
2731 + tmp = me4000_inl(ao_context->status_reg);
2732 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2734 + "me4000_ao_simultaneous_disable():Can't disable while DAC is running\n");
2738 + spin_lock(&ao_context->board_info->preload_lock);
2739 + tmp = me4000_inl(ao_context->preload_reg);
2740 + tmp &= ~(0x1 << ao_context->index); // Disable preload bit
2741 + tmp &= ~(0x1 << (ao_context->index + 16)); // Disable hw simultaneous bit
2742 + me4000_outl(tmp, ao_context->preload_reg);
2743 + spin_unlock(&ao_context->board_info->preload_lock);
2748 +static int me4000_ao_simultaneous_ex_trig(me4000_ao_context_t * ao_context)
2752 + CALL_PDEBUG("me4000_ao_simultaneous_ex_trig() is executed\n");
2754 + spin_lock(&ao_context->board_info->preload_lock);
2755 + tmp = me4000_inl(ao_context->preload_reg);
2756 + tmp |= (0x1 << ao_context->index); // Enable preload bit
2757 + tmp |= (0x1 << (ao_context->index + 16)); // Enable hw simultaneous bit
2758 + me4000_outl(tmp, ao_context->preload_reg);
2759 + spin_unlock(&ao_context->board_info->preload_lock);
2764 +static int me4000_ao_simultaneous_sw(me4000_ao_context_t * ao_context)
2768 + CALL_PDEBUG("me4000_ao_simultaneous_sw() is executed\n");
2770 + spin_lock(&ao_context->board_info->preload_lock);
2771 + tmp = me4000_inl(ao_context->preload_reg);
2772 + tmp |= (0x1 << ao_context->index); // Enable preload bit
2773 + tmp &= ~(0x1 << (ao_context->index + 16)); // Disable hw simultaneous bit
2774 + me4000_outl(tmp, ao_context->preload_reg);
2775 + spin_unlock(&ao_context->board_info->preload_lock);
2780 +static int me4000_ao_preload(me4000_ao_context_t * ao_context)
2782 + CALL_PDEBUG("me4000_ao_preload() is executed\n");
2783 + return me4000_ao_simultaneous_sw(ao_context);
2786 +static int me4000_ao_preload_update(me4000_ao_context_t * ao_context)
2790 + struct list_head *entry;
2792 + CALL_PDEBUG("me4000_ao_preload_update() is executed\n");
2794 + spin_lock(&ao_context->board_info->preload_lock);
2795 + tmp = me4000_inl(ao_context->preload_reg);
2796 + list_for_each(entry, &ao_context->board_info->ao_context_list) {
2797 + /* The channels we update must be in the following state :
2799 + - Hardware trigger is disabled
2800 + - Corresponding simultaneous bit is reset
2802 + ctrl = me4000_inl(ao_context->ctrl_reg);
2805 + (ME4000_AO_CTRL_BIT_MODE_0 | ME4000_AO_CTRL_BIT_MODE_1 |
2806 + ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG))) {
2810 + (((me4000_ao_context_t *) entry)->index + 16)))) {
2813 + (((me4000_ao_context_t *) entry)->index));
2817 + me4000_outl(tmp, ao_context->preload_reg);
2818 + spin_unlock(&ao_context->board_info->preload_lock);
2823 +static int me4000_ao_simultaneous_update(me4000_ao_channel_list_t * arg,
2824 + me4000_ao_context_t * ao_context)
2829 + me4000_ao_channel_list_t channels;
2831 + CALL_PDEBUG("me4000_ao_simultaneous_update() is executed\n");
2833 + /* Copy data from user */
2834 + err = copy_from_user(&channels, arg, sizeof(me4000_ao_channel_list_t));
2837 + "ME4000:me4000_ao_simultaneous_update():Can't copy command\n");
2842 + kmalloc(sizeof(unsigned long) * channels.count, GFP_KERNEL);
2843 + if (!channels.list) {
2845 + "ME4000:me4000_ao_simultaneous_update():Can't get buffer\n");
2848 + memset(channels.list, 0, sizeof(unsigned long) * channels.count);
2850 + /* Copy channel list from user */
2852 + copy_from_user(channels.list, arg->list,
2853 + sizeof(unsigned long) * channels.count);
2856 + "ME4000:me4000_ao_simultaneous_update():Can't copy list\n");
2857 + kfree(channels.list);
2861 + spin_lock(&ao_context->board_info->preload_lock);
2862 + tmp = me4000_inl(ao_context->preload_reg);
2863 + for (i = 0; i < channels.count; i++) {
2864 + if (channels.list[i] >
2865 + ao_context->board_info->board_p->ao.count) {
2866 + spin_unlock(&ao_context->board_info->preload_lock);
2867 + kfree(channels.list);
2869 + "ME4000:me4000_ao_simultaneous_update():Invalid board number specified\n");
2872 + tmp &= ~(0x1 << channels.list[i]); // Clear the preload bit
2873 + tmp &= ~(0x1 << (channels.list[i] + 16)); // Clear the hw simultaneous bit
2875 + me4000_outl(tmp, ao_context->preload_reg);
2876 + spin_unlock(&ao_context->board_info->preload_lock);
2877 + kfree(channels.list);
2882 +static int me4000_ao_synchronous_ex_trig(me4000_ao_context_t * ao_context)
2885 + unsigned long flags;
2887 + CALL_PDEBUG("me4000_ao_synchronous_ex_trig() is executed\n");
2889 + /* Check if the state machine is stopped */
2890 + tmp = me4000_inl(ao_context->status_reg);
2891 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2893 + "me4000_ao_synchronous_ex_trig(): DAC is running\n");
2897 + spin_lock(&ao_context->board_info->preload_lock);
2898 + tmp = me4000_inl(ao_context->preload_reg);
2899 + tmp &= ~(0x1 << ao_context->index); // Disable synchronous sw bit
2900 + tmp |= 0x1 << (ao_context->index + 16); // Enable synchronous hw bit
2901 + me4000_outl(tmp, ao_context->preload_reg);
2902 + spin_unlock(&ao_context->board_info->preload_lock);
2904 + /* Make runnable */
2905 + spin_lock_irqsave(&ao_context->int_lock, flags);
2906 + tmp = me4000_inl(ao_context->ctrl_reg);
2907 + if (tmp & (ME4000_AO_CTRL_BIT_MODE_0 | ME4000_AO_CTRL_BIT_MODE_1)) {
2909 + ~(ME4000_AO_CTRL_BIT_STOP |
2910 + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP);
2911 + me4000_outl(tmp, ao_context->ctrl_reg);
2913 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2918 +static int me4000_ao_synchronous_sw(me4000_ao_context_t * ao_context)
2921 + unsigned long flags;
2923 + CALL_PDEBUG("me4000_ao_synchronous_sw() is executed\n");
2925 + /* Check if the state machine is stopped */
2926 + tmp = me4000_inl(ao_context->status_reg);
2927 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
2928 + printk(KERN_ERR "me4000_ao_synchronous_sw(): DAC is running\n");
2932 + spin_lock(&ao_context->board_info->preload_lock);
2933 + tmp = me4000_inl(ao_context->preload_reg);
2934 + tmp |= 0x1 << ao_context->index; // Enable synchronous sw bit
2935 + tmp &= ~(0x1 << (ao_context->index + 16)); // Disable synchronous hw bit
2936 + me4000_outl(tmp, ao_context->preload_reg);
2937 + spin_unlock(&ao_context->board_info->preload_lock);
2939 + /* Make runnable */
2940 + spin_lock_irqsave(&ao_context->int_lock, flags);
2941 + tmp = me4000_inl(ao_context->ctrl_reg);
2942 + if (tmp & (ME4000_AO_CTRL_BIT_MODE_0 | ME4000_AO_CTRL_BIT_MODE_1)) {
2944 + ~(ME4000_AO_CTRL_BIT_STOP |
2945 + ME4000_AO_CTRL_BIT_IMMEDIATE_STOP);
2946 + me4000_outl(tmp, ao_context->ctrl_reg);
2948 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
2953 +static int me4000_ao_synchronous_disable(me4000_ao_context_t * ao_context)
2955 + return me4000_ao_simultaneous_disable(ao_context);
2958 +static int me4000_ao_get_free_buffer(unsigned long *arg,
2959 + me4000_ao_context_t * ao_context)
2964 + c = me4000_buf_space(ao_context->circ_buf, ME4000_AO_BUFFER_COUNT);
2966 + err = copy_to_user(arg, &c, sizeof(unsigned long));
2969 + "ME4000:me4000_ao_get_free_buffer():Can't copy to user space\n");
2976 +static int me4000_ao_ex_trig_timeout(unsigned long *arg,
2977 + me4000_ao_context_t * ao_context)
2980 + wait_queue_head_t queue;
2981 + unsigned long ref;
2982 + unsigned long timeout;
2984 + CALL_PDEBUG("me4000_ao_ex_trig_timeout() is executed\n");
2986 + if (get_user(timeout, arg)) {
2988 + "me4000_ao_ex_trig_timeout():Cannot copy data from user\n");
2992 + init_waitqueue_head(&queue);
2994 + tmp = inl(ao_context->ctrl_reg);
2996 + if ((tmp & ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG)) {
2999 + while ((inl(ao_context->status_reg) &
3000 + ME4000_AO_STATUS_BIT_FSM)) {
3001 + interruptible_sleep_on_timeout(&queue, 1);
3002 + if (signal_pending(current)) {
3004 + "ME4000:me4000_ao_ex_trig_timeout():Wait on start of state machine interrupted\n");
3007 + if (((jiffies - ref) > (timeout * HZ / USER_HZ))) { // 2.6 has diffrent definitions for HZ in user and kernel space
3009 + "ME4000:me4000_ao_ex_trig_timeout():Timeout reached\n");
3014 + while ((inl(ao_context->status_reg) &
3015 + ME4000_AO_STATUS_BIT_FSM)) {
3016 + interruptible_sleep_on_timeout(&queue, 1);
3017 + if (signal_pending(current)) {
3019 + "ME4000:me4000_ao_ex_trig_timeout():Wait on start of state machine interrupted\n");
3026 + "ME4000:me4000_ao_ex_trig_timeout():External Trigger is not enabled\n");
3033 +static int me4000_ao_enable_do(me4000_ao_context_t * ao_context)
3036 + unsigned long flags;
3038 + CALL_PDEBUG("me4000_ao_enable_do() is executed\n");
3040 + /* Only available for analog output 3 */
3041 + if (ao_context->index != 3) {
3043 + "me4000_ao_enable_do():Only available for analog output 3\n");
3047 + /* Check if the state machine is stopped */
3048 + tmp = me4000_inl(ao_context->status_reg);
3049 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
3050 + printk(KERN_ERR "me4000_ao_enable_do(): DAC is running\n");
3054 + /* Set the stop bit */
3055 + spin_lock_irqsave(&ao_context->int_lock, flags);
3056 + tmp = inl(ao_context->ctrl_reg);
3057 + tmp |= ME4000_AO_CTRL_BIT_ENABLE_DO;
3058 + me4000_outl(tmp, ao_context->ctrl_reg);
3059 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
3064 +static int me4000_ao_disable_do(me4000_ao_context_t * ao_context)
3067 + unsigned long flags;
3069 + CALL_PDEBUG("me4000_ao_disable_do() is executed\n");
3071 + /* Only available for analog output 3 */
3072 + if (ao_context->index != 3) {
3074 + "me4000_ao_disable():Only available for analog output 3\n");
3078 + /* Check if the state machine is stopped */
3079 + tmp = me4000_inl(ao_context->status_reg);
3080 + if (tmp & ME4000_AO_STATUS_BIT_FSM) {
3081 + printk(KERN_ERR "me4000_ao_disable_do(): DAC is running\n");
3085 + spin_lock_irqsave(&ao_context->int_lock, flags);
3086 + tmp = inl(ao_context->ctrl_reg);
3087 + tmp &= ~(ME4000_AO_CTRL_BIT_ENABLE_DO);
3088 + me4000_outl(tmp, ao_context->ctrl_reg);
3089 + spin_unlock_irqrestore(&ao_context->int_lock, flags);
3094 +static int me4000_ao_fsm_state(int *arg, me4000_ao_context_t * ao_context)
3096 + unsigned long tmp;
3098 + CALL_PDEBUG("me4000_ao_fsm_state() is executed\n");
3101 + (me4000_inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM) ? 1
3104 + if (ao_context->pipe_flag) {
3105 + printk(KERN_ERR "me4000_ao_fsm_state():Broken pipe detected\n");
3109 + if (put_user(tmp, arg)) {
3110 + printk(KERN_ERR "me4000_ao_fsm_state():Cannot copy to user\n");
3117 +/*------------------------------- Analog input stuff --------------------------------------*/
3119 +static int me4000_ai_prepare(me4000_ai_context_t * ai_context)
3121 + wait_queue_head_t queue;
3124 + CALL_PDEBUG("me4000_ai_prepare() is executed\n");
3126 + init_waitqueue_head(&queue);
3128 + /* Set the new mode and stop bits */
3129 + me4000_outl(ai_context->
3130 + mode | ME4000_AI_CTRL_BIT_STOP |
3131 + ME4000_AI_CTRL_BIT_IMMEDIATE_STOP, ai_context->ctrl_reg);
3133 + /* Set the timer registers */
3134 + ai_context->chan_timer = 66;
3135 + ai_context->chan_pre_timer = 66;
3136 + ai_context->scan_timer_low = 0;
3137 + ai_context->scan_timer_high = 0;
3139 + me4000_outl(65, ai_context->chan_timer_reg);
3140 + me4000_outl(65, ai_context->chan_pre_timer_reg);
3141 + me4000_outl(0, ai_context->scan_timer_low_reg);
3142 + me4000_outl(0, ai_context->scan_timer_high_reg);
3143 + me4000_outl(0, ai_context->scan_pre_timer_low_reg);
3144 + me4000_outl(0, ai_context->scan_pre_timer_high_reg);
3146 + ai_context->channel_list_count = 0;
3148 + if (ai_context->mode) {
3149 + /* Request the interrupt line */
3151 + request_irq(ai_context->irq, me4000_ai_isr,
3152 + IRQF_DISABLED | IRQF_SHARED, ME4000_NAME,
3156 + "ME4000:me4000_ai_prepare():Can't get interrupt line");
3160 + /* Allocate circular buffer */
3161 + ai_context->circ_buf.buf =
3162 + kmalloc(ME4000_AI_BUFFER_SIZE, GFP_KERNEL);
3163 + if (!ai_context->circ_buf.buf) {
3165 + "ME4000:me4000_ai_prepare():Can't get circular buffer\n");
3166 + free_irq(ai_context->irq, ai_context);
3169 + memset(ai_context->circ_buf.buf, 0, ME4000_AI_BUFFER_SIZE);
3171 + /* Clear the circular buffer */
3172 + ai_context->circ_buf.head = 0;
3173 + ai_context->circ_buf.tail = 0;
3179 +static int me4000_ai_reset(me4000_ai_context_t * ai_context)
3181 + wait_queue_head_t queue;
3183 + unsigned long flags;
3185 + CALL_PDEBUG("me4000_ai_reset() is executed\n");
3187 + init_waitqueue_head(&queue);
3190 + * First stop conversion of the state machine before reconfigure.
3191 + * If not stopped before configuring mode, it could
3192 + * walk in a undefined state.
3194 + spin_lock_irqsave(&ai_context->int_lock, flags);
3195 + tmp = me4000_inl(ai_context->ctrl_reg);
3196 + tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
3197 + me4000_outl(tmp, ai_context->ctrl_reg);
3198 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
3200 + while (inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM) {
3201 + interruptible_sleep_on_timeout(&queue, 1);
3202 + if (signal_pending(current)) {
3204 + "me4000_ai_reset():Wait on state machine after stop interrupted\n");
3209 + /* Clear the control register and set the stop bits */
3210 + spin_lock_irqsave(&ai_context->int_lock, flags);
3211 + tmp = me4000_inl(ai_context->ctrl_reg);
3212 + me4000_outl(ME4000_AI_CTRL_BIT_IMMEDIATE_STOP | ME4000_AI_CTRL_BIT_STOP,
3213 + ai_context->ctrl_reg);
3214 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
3216 + /* Reset timer registers */
3217 + ai_context->chan_timer = 66;
3218 + ai_context->chan_pre_timer = 66;
3219 + ai_context->scan_timer_low = 0;
3220 + ai_context->scan_timer_high = 0;
3221 + ai_context->sample_counter = 0;
3222 + ai_context->sample_counter_reload = 0;
3224 + me4000_outl(65, ai_context->chan_timer_reg);
3225 + me4000_outl(65, ai_context->chan_pre_timer_reg);
3226 + me4000_outl(0, ai_context->scan_timer_low_reg);
3227 + me4000_outl(0, ai_context->scan_timer_high_reg);
3228 + me4000_outl(0, ai_context->scan_pre_timer_low_reg);
3229 + me4000_outl(0, ai_context->scan_pre_timer_high_reg);
3230 + me4000_outl(0, ai_context->sample_counter_reg);
3232 + ai_context->channel_list_count = 0;
3234 + /* Clear the circular buffer */
3235 + ai_context->circ_buf.head = 0;
3236 + ai_context->circ_buf.tail = 0;
3241 +static int me4000_ai_ioctl_sing(struct inode *inode_p, struct file *file_p,
3242 + unsigned int service, unsigned long arg)
3244 + me4000_ai_context_t *ai_context;
3246 + CALL_PDEBUG("me4000_ai_ioctl_sing() is executed\n");
3248 + ai_context = file_p->private_data;
3250 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
3251 + printk(KERN_ERR "me4000_ai_ioctl_sing():Wrong magic number\n");
3254 + if (_IOC_NR(service) > ME4000_IOCTL_MAXNR) {
3256 + "me4000_ai_ioctl_sing():Service number to high\n");
3260 + switch (service) {
3261 + case ME4000_AI_SINGLE:
3262 + return me4000_ai_single((me4000_ai_single_t *) arg, ai_context);
3263 + case ME4000_AI_EX_TRIG_ENABLE:
3264 + return me4000_ai_ex_trig_enable(ai_context);
3265 + case ME4000_AI_EX_TRIG_DISABLE:
3266 + return me4000_ai_ex_trig_disable(ai_context);
3267 + case ME4000_AI_EX_TRIG_SETUP:
3268 + return me4000_ai_ex_trig_setup((me4000_ai_trigger_t *) arg,
3270 + case ME4000_GET_USER_INFO:
3271 + return me4000_get_user_info((me4000_user_info_t *) arg,
3272 + ai_context->board_info);
3273 + case ME4000_AI_OFFSET_ENABLE:
3274 + return me4000_ai_offset_enable(ai_context);
3275 + case ME4000_AI_OFFSET_DISABLE:
3276 + return me4000_ai_offset_disable(ai_context);
3277 + case ME4000_AI_FULLSCALE_ENABLE:
3278 + return me4000_ai_fullscale_enable(ai_context);
3279 + case ME4000_AI_FULLSCALE_DISABLE:
3280 + return me4000_ai_fullscale_disable(ai_context);
3281 + case ME4000_AI_EEPROM_READ:
3282 + return me4000_eeprom_read((me4000_eeprom_t *) arg, ai_context);
3283 + case ME4000_AI_EEPROM_WRITE:
3284 + return me4000_eeprom_write((me4000_eeprom_t *) arg, ai_context);
3287 + "me4000_ai_ioctl_sing():Invalid service number\n");
3293 +static int me4000_ai_single(me4000_ai_single_t * arg,
3294 + me4000_ai_context_t * ai_context)
3296 + me4000_ai_single_t cmd;
3299 + wait_queue_head_t queue;
3300 + unsigned long jiffy;
3302 + CALL_PDEBUG("me4000_ai_single() is executed\n");
3304 + init_waitqueue_head(&queue);
3306 + /* Copy data from user */
3307 + err = copy_from_user(&cmd, arg, sizeof(me4000_ai_single_t));
3310 + "ME4000:me4000_ai_single():Can't copy from user space\n");
3314 + /* Check range parameter */
3315 + switch (cmd.range) {
3316 + case ME4000_AI_LIST_RANGE_BIPOLAR_10:
3317 + case ME4000_AI_LIST_RANGE_BIPOLAR_2_5:
3318 + case ME4000_AI_LIST_RANGE_UNIPOLAR_10:
3319 + case ME4000_AI_LIST_RANGE_UNIPOLAR_2_5:
3323 + "ME4000:me4000_ai_single():Invalid range specified\n");
3327 + /* Check mode and channel number */
3328 + switch (cmd.mode) {
3329 + case ME4000_AI_LIST_INPUT_SINGLE_ENDED:
3330 + if (cmd.channel >= ai_context->board_info->board_p->ai.count) {
3332 + "ME4000:me4000_ai_single():Analog input is not available\n");
3336 + case ME4000_AI_LIST_INPUT_DIFFERENTIAL:
3337 + if (cmd.channel >=
3338 + ai_context->board_info->board_p->ai.diff_count) {
3340 + "ME4000:me4000_ai_single():Analog input is not available in differential mode\n");
3346 + "ME4000:me4000_ai_single():Invalid mode specified\n");
3350 + /* Clear channel list, data fifo and both stop bits */
3351 + tmp = me4000_inl(ai_context->ctrl_reg);
3353 + ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO | ME4000_AI_CTRL_BIT_DATA_FIFO |
3354 + ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP);
3355 + me4000_outl(tmp, ai_context->ctrl_reg);
3357 + /* Enable channel list and data fifo */
3358 + tmp |= ME4000_AI_CTRL_BIT_CHANNEL_FIFO | ME4000_AI_CTRL_BIT_DATA_FIFO;
3359 + me4000_outl(tmp, ai_context->ctrl_reg);
3361 + /* Generate channel list entry */
3362 + me4000_outl(cmd.channel | cmd.range | cmd.
3363 + mode | ME4000_AI_LIST_LAST_ENTRY,
3364 + ai_context->channel_list_reg);
3366 + /* Set the timer to maximum */
3367 + me4000_outl(66, ai_context->chan_timer_reg);
3368 + me4000_outl(66, ai_context->chan_pre_timer_reg);
3370 + if (tmp & ME4000_AI_CTRL_BIT_EX_TRIG) {
3373 + (me4000_inl(ai_context->status_reg) &
3374 + ME4000_AI_STATUS_BIT_EF_DATA)) {
3375 + interruptible_sleep_on_timeout(&queue, 1);
3376 + if (signal_pending(current)) {
3378 + "ME4000:me4000_ai_single():Wait on start of state machine interrupted\n");
3381 + if (((jiffies - jiffy) > (cmd.timeout * HZ / USER_HZ)) && cmd.timeout) { // 2.6 has diffrent definitions for HZ in user and kernel space
3383 + "ME4000:me4000_ai_single():Timeout reached\n");
3388 + /* Start conversion */
3389 + me4000_inl(ai_context->start_reg);
3391 + /* Wait until ready */
3394 + (me4000_inl(ai_context->status_reg) &
3395 + ME4000_AI_STATUS_BIT_EF_DATA)) {
3397 + "ME4000:me4000_ai_single():Value not available after wait\n");
3402 + /* Read value from data fifo */
3403 + cmd.value = me4000_inl(ai_context->data_reg) & 0xFFFF;
3405 + /* Copy result back to user */
3406 + err = copy_to_user(arg, &cmd, sizeof(me4000_ai_single_t));
3409 + "ME4000:me4000_ai_single():Can't copy to user space\n");
3416 +static int me4000_ai_ioctl_sw(struct inode *inode_p, struct file *file_p,
3417 + unsigned int service, unsigned long arg)
3419 + me4000_ai_context_t *ai_context;
3421 + CALL_PDEBUG("me4000_ai_ioctl_sw() is executed\n");
3423 + ai_context = file_p->private_data;
3425 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
3426 + printk(KERN_ERR "me4000_ai_ioctl_sw():Wrong magic number\n");
3429 + if (_IOC_NR(service) > ME4000_IOCTL_MAXNR) {
3431 + "me4000_ai_ioctl_sw():Service number to high\n");
3435 + switch (service) {
3436 + case ME4000_AI_SC_SETUP:
3437 + return me4000_ai_sc_setup((me4000_ai_sc_t *) arg, ai_context);
3438 + case ME4000_AI_CONFIG:
3439 + return me4000_ai_config((me4000_ai_config_t *) arg, ai_context);
3440 + case ME4000_AI_START:
3441 + return me4000_ai_start(ai_context);
3442 + case ME4000_AI_STOP:
3443 + return me4000_ai_stop(ai_context);
3444 + case ME4000_AI_IMMEDIATE_STOP:
3445 + return me4000_ai_immediate_stop(ai_context);
3446 + case ME4000_AI_FSM_STATE:
3447 + return me4000_ai_fsm_state((int *)arg, ai_context);
3448 + case ME4000_GET_USER_INFO:
3449 + return me4000_get_user_info((me4000_user_info_t *) arg,
3450 + ai_context->board_info);
3451 + case ME4000_AI_EEPROM_READ:
3452 + return me4000_eeprom_read((me4000_eeprom_t *) arg, ai_context);
3453 + case ME4000_AI_EEPROM_WRITE:
3454 + return me4000_eeprom_write((me4000_eeprom_t *) arg, ai_context);
3455 + case ME4000_AI_GET_COUNT_BUFFER:
3456 + return me4000_ai_get_count_buffer((unsigned long *)arg,
3460 + "ME4000:me4000_ai_ioctl_sw():Invalid service number %d\n",
3467 +static int me4000_ai_ioctl_ext(struct inode *inode_p, struct file *file_p,
3468 + unsigned int service, unsigned long arg)
3470 + me4000_ai_context_t *ai_context;
3472 + CALL_PDEBUG("me4000_ai_ioctl_ext() is executed\n");
3474 + ai_context = file_p->private_data;
3476 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
3477 + printk(KERN_ERR "me4000_ai_ioctl_ext():Wrong magic number\n");
3480 + if (_IOC_NR(service) > ME4000_IOCTL_MAXNR) {
3482 + "me4000_ai_ioctl_ext():Service number to high\n");
3486 + switch (service) {
3487 + case ME4000_AI_SC_SETUP:
3488 + return me4000_ai_sc_setup((me4000_ai_sc_t *) arg, ai_context);
3489 + case ME4000_AI_CONFIG:
3490 + return me4000_ai_config((me4000_ai_config_t *) arg, ai_context);
3491 + case ME4000_AI_START:
3492 + return me4000_ai_start_ex((unsigned long *)arg, ai_context);
3493 + case ME4000_AI_STOP:
3494 + return me4000_ai_stop(ai_context);
3495 + case ME4000_AI_IMMEDIATE_STOP:
3496 + return me4000_ai_immediate_stop(ai_context);
3497 + case ME4000_AI_EX_TRIG_ENABLE:
3498 + return me4000_ai_ex_trig_enable(ai_context);
3499 + case ME4000_AI_EX_TRIG_DISABLE:
3500 + return me4000_ai_ex_trig_disable(ai_context);
3501 + case ME4000_AI_EX_TRIG_SETUP:
3502 + return me4000_ai_ex_trig_setup((me4000_ai_trigger_t *) arg,
3504 + case ME4000_AI_FSM_STATE:
3505 + return me4000_ai_fsm_state((int *)arg, ai_context);
3506 + case ME4000_GET_USER_INFO:
3507 + return me4000_get_user_info((me4000_user_info_t *) arg,
3508 + ai_context->board_info);
3509 + case ME4000_AI_GET_COUNT_BUFFER:
3510 + return me4000_ai_get_count_buffer((unsigned long *)arg,
3514 + "ME4000:me4000_ai_ioctl_ext():Invalid service number %d\n",
3521 +static int me4000_ai_fasync(int fd, struct file *file_p, int mode)
3523 + me4000_ai_context_t *ai_context;
3525 + CALL_PDEBUG("me4000_ao_fasync_cont() is executed\n");
3527 + ai_context = file_p->private_data;
3528 + return fasync_helper(fd, file_p, mode, &ai_context->fasync_p);
3531 +static int me4000_ai_config(me4000_ai_config_t * arg,
3532 + me4000_ai_context_t * ai_context)
3534 + me4000_ai_config_t cmd;
3539 + wait_queue_head_t queue;
3543 + CALL_PDEBUG("me4000_ai_config() is executed\n");
3545 + init_waitqueue_head(&queue);
3547 + /* Check if conversion is stopped */
3548 + if (inl(ai_context->ctrl_reg) & ME4000_AI_STATUS_BIT_FSM) {
3550 + "ME4000:me4000_ai_config():Conversion is not stopped\n");
3552 + goto AI_CONFIG_ERR;
3555 + /* Copy data from user */
3556 + err = copy_from_user(&cmd, arg, sizeof(me4000_ai_config_t));
3559 + "ME4000:me4000_ai_config():Can't copy from user space\n");
3561 + goto AI_CONFIG_ERR;
3565 + ("me4000_ai_config():chan = %ld, pre_chan = %ld, scan_low = %ld, scan_high = %ld, count = %ld\n",
3566 + cmd.timer.chan, cmd.timer.pre_chan, cmd.timer.scan_low,
3567 + cmd.timer.scan_high, cmd.channel_list.count);
3569 + /* Check whether sample and hold is available for this board */
3571 + if (!ai_context->board_info->board_p->ai.sh_count) {
3573 + "ME4000:me4000_ai_config():Sample and Hold is not available for this board\n");
3575 + goto AI_CONFIG_ERR;
3579 + /* Check the channel list size */
3580 + if (cmd.channel_list.count > ME4000_AI_CHANNEL_LIST_COUNT) {
3582 + "me4000_ai_config():Channel list is to large\n");
3584 + goto AI_CONFIG_ERR;
3587 + /* Copy channel list from user */
3588 + list = kmalloc(sizeof(u32) * cmd.channel_list.count, GFP_KERNEL);
3591 + "ME4000:me4000_ai_config():Can't get memory for channel list\n");
3593 + goto AI_CONFIG_ERR;
3596 + copy_from_user(list, cmd.channel_list.list,
3597 + sizeof(u32) * cmd.channel_list.count);
3600 + "ME4000:me4000_ai_config():Can't copy from user space\n");
3602 + goto AI_CONFIG_ERR;
3605 + /* Check if last entry bit is set */
3606 + if (!(list[cmd.channel_list.count - 1] & ME4000_AI_LIST_LAST_ENTRY)) {
3607 + printk(KERN_WARNING
3608 + "me4000_ai_config():Last entry bit is not set\n");
3609 + list[cmd.channel_list.count - 1] |= ME4000_AI_LIST_LAST_ENTRY;
3612 + /* Check whether mode is equal for all entries */
3613 + mode = list[0] & 0x20;
3614 + for (i = 0; i < cmd.channel_list.count; i++) {
3615 + if ((list[i] & 0x20) != mode) {
3617 + "ME4000:me4000_ai_config():Mode is not equal for all entries\n");
3619 + goto AI_CONFIG_ERR;
3623 + /* Check whether channels are available for this mode */
3624 + if (mode == ME4000_AI_LIST_INPUT_SINGLE_ENDED) {
3625 + for (i = 0; i < cmd.channel_list.count; i++) {
3626 + if ((list[i] & 0x1F) >=
3627 + ai_context->board_info->board_p->ai.count) {
3629 + "ME4000:me4000_ai_config():Channel is not available for single ended\n");
3631 + goto AI_CONFIG_ERR;
3634 + } else if (mode == ME4000_AI_LIST_INPUT_DIFFERENTIAL) {
3635 + for (i = 0; i < cmd.channel_list.count; i++) {
3636 + if ((list[i] & 0x1F) >=
3637 + ai_context->board_info->board_p->ai.diff_count) {
3639 + "ME4000:me4000_ai_config():Channel is not available for differential\n");
3641 + goto AI_CONFIG_ERR;
3646 + /* Check if bipolar is set for all entries when in differential mode */
3647 + if (mode == ME4000_AI_LIST_INPUT_DIFFERENTIAL) {
3648 + for (i = 0; i < cmd.channel_list.count; i++) {
3649 + if ((list[i] & 0xC0) != ME4000_AI_LIST_RANGE_BIPOLAR_10
3650 + && (list[i] & 0xC0) !=
3651 + ME4000_AI_LIST_RANGE_BIPOLAR_2_5) {
3653 + "ME4000:me4000_ai_config():Bipolar is not selected in differential mode\n");
3655 + goto AI_CONFIG_ERR;
3660 + if (ai_context->mode != ME4000_AI_ACQ_MODE_EXT_SINGLE_VALUE) {
3661 + /* Check for minimum channel divisor */
3662 + if (cmd.timer.chan < ME4000_AI_MIN_TICKS) {
3664 + "ME4000:me4000_ai_config():Channel timer divisor is to low\n");
3666 + goto AI_CONFIG_ERR;
3669 + /* Check if minimum channel divisor is adjusted when sample and hold is activated */
3670 + if ((cmd.sh) && (cmd.timer.chan != ME4000_AI_MIN_TICKS)) {
3672 + "ME4000:me4000_ai_config():Channel timer divisor must be at minimum when sample and hold is activated\n");
3674 + goto AI_CONFIG_ERR;
3677 + /* Check for minimum channel pre divisor */
3678 + if (cmd.timer.pre_chan < ME4000_AI_MIN_TICKS) {
3680 + "ME4000:me4000_ai_config():Channel pre timer divisor is to low\n");
3682 + goto AI_CONFIG_ERR;
3685 + /* Write the channel timers */
3686 + me4000_outl(cmd.timer.chan - 1, ai_context->chan_timer_reg);
3687 + me4000_outl(cmd.timer.pre_chan - 1,
3688 + ai_context->chan_pre_timer_reg);
3690 + /* Save the timer values in the board context */
3691 + ai_context->chan_timer = cmd.timer.chan;
3692 + ai_context->chan_pre_timer = cmd.timer.pre_chan;
3694 + if (ai_context->mode != ME4000_AI_ACQ_MODE_EXT_SINGLE_CHANLIST) {
3695 + /* Check for scan timer divisor */
3697 + (u64) cmd.timer.scan_low | ((u64) cmd.timer.
3701 + cmd.channel_list.count * cmd.timer.chan +
3704 + "ME4000:me4000_ai_config():Scan timer divisor is to low\n");
3706 + goto AI_CONFIG_ERR;
3710 + /* Write the scan timers */
3713 + tmp = (u32) (scan & 0xFFFFFFFF);
3715 + ai_context->scan_timer_low_reg);
3716 + tmp = (u32) ((scan >> 32) & 0xFFFFFFFF);
3718 + ai_context->scan_timer_high_reg);
3721 + scan - (cmd.timer.chan - 1) +
3722 + (cmd.timer.pre_chan - 1);
3723 + tmp = (u32) (scan & 0xFFFFFFFF);
3725 + ai_context->scan_pre_timer_low_reg);
3726 + tmp = (u32) ((scan >> 32) & 0xFFFFFFFF);
3729 + scan_pre_timer_high_reg);
3732 + ai_context->scan_timer_low_reg);
3734 + ai_context->scan_timer_high_reg);
3737 + ai_context->scan_pre_timer_low_reg);
3740 + scan_pre_timer_high_reg);
3743 + ai_context->scan_timer_low = cmd.timer.scan_low;
3744 + ai_context->scan_timer_high = cmd.timer.scan_high;
3748 + /* Clear the channel list */
3749 + tmp = me4000_inl(ai_context->ctrl_reg);
3750 + tmp &= ~ME4000_AI_CTRL_BIT_CHANNEL_FIFO;
3751 + me4000_outl(tmp, ai_context->ctrl_reg);
3752 + tmp |= ME4000_AI_CTRL_BIT_CHANNEL_FIFO;
3753 + me4000_outl(tmp, ai_context->ctrl_reg);
3755 + /* Write the channel list */
3756 + for (i = 0; i < cmd.channel_list.count; i++) {
3757 + me4000_outl(list[i], ai_context->channel_list_reg);
3760 + /* Setup sample and hold */
3762 + tmp |= ME4000_AI_CTRL_BIT_SAMPLE_HOLD;
3763 + me4000_outl(tmp, ai_context->ctrl_reg);
3765 + tmp &= ~ME4000_AI_CTRL_BIT_SAMPLE_HOLD;
3766 + me4000_outl(tmp, ai_context->ctrl_reg);
3769 + /* Save the channel list size in the board context */
3770 + ai_context->channel_list_count = cmd.channel_list.count;
3778 + /* Reset the timers */
3779 + ai_context->chan_timer = 66;
3780 + ai_context->chan_pre_timer = 66;
3781 + ai_context->scan_timer_low = 0;
3782 + ai_context->scan_timer_high = 0;
3784 + me4000_outl(65, ai_context->chan_timer_reg);
3785 + me4000_outl(65, ai_context->chan_pre_timer_reg);
3786 + me4000_outl(0, ai_context->scan_timer_high_reg);
3787 + me4000_outl(0, ai_context->scan_timer_low_reg);
3788 + me4000_outl(0, ai_context->scan_pre_timer_high_reg);
3789 + me4000_outl(0, ai_context->scan_pre_timer_low_reg);
3791 + ai_context->channel_list_count = 0;
3793 + tmp = me4000_inl(ai_context->ctrl_reg);
3795 + ~(ME4000_AI_CTRL_BIT_CHANNEL_FIFO | ME4000_AI_CTRL_BIT_SAMPLE_HOLD);
3804 +static int ai_common_start(me4000_ai_context_t * ai_context)
3807 + CALL_PDEBUG("ai_common_start() is executed\n");
3809 + tmp = me4000_inl(ai_context->ctrl_reg);
3811 + /* Check if conversion is stopped */
3812 + if (tmp & ME4000_AI_STATUS_BIT_FSM) {
3814 + "ME4000:ai_common_start():Conversion is not stopped\n");
3818 + /* Clear data fifo, disable all interrupts, clear sample counter reload */
3819 + tmp &= ~(ME4000_AI_CTRL_BIT_DATA_FIFO | ME4000_AI_CTRL_BIT_LE_IRQ |
3820 + ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ |
3821 + ME4000_AI_CTRL_BIT_SC_RELOAD);
3823 + me4000_outl(tmp, ai_context->ctrl_reg);
3825 + /* Clear circular buffer */
3826 + ai_context->circ_buf.head = 0;
3827 + ai_context->circ_buf.tail = 0;
3829 + /* Enable data fifo */
3830 + tmp |= ME4000_AI_CTRL_BIT_DATA_FIFO;
3832 + /* Determine interrupt setup */
3833 + if (ai_context->sample_counter && !ai_context->sample_counter_reload) {
3834 + /* Enable Half Full Interrupt and Sample Counter Interrupt */
3835 + tmp |= ME4000_AI_CTRL_BIT_SC_IRQ | ME4000_AI_CTRL_BIT_HF_IRQ;
3836 + } else if (ai_context->sample_counter
3837 + && ai_context->sample_counter_reload) {
3838 + if (ai_context->sample_counter <= ME4000_AI_FIFO_COUNT / 2) {
3839 + /* Enable only Sample Counter Interrupt */
3841 + ME4000_AI_CTRL_BIT_SC_IRQ |
3842 + ME4000_AI_CTRL_BIT_SC_RELOAD;
3844 + /* Enable Half Full Interrupt and Sample Counter Interrupt */
3846 + ME4000_AI_CTRL_BIT_SC_IRQ |
3847 + ME4000_AI_CTRL_BIT_HF_IRQ |
3848 + ME4000_AI_CTRL_BIT_SC_RELOAD;
3851 + /* Enable only Half Full Interrupt */
3852 + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ;
3855 + /* Clear the stop bits */
3856 + tmp &= ~(ME4000_AI_CTRL_BIT_STOP | ME4000_AI_CTRL_BIT_IMMEDIATE_STOP);
3858 + /* Write setup to hardware */
3859 + me4000_outl(tmp, ai_context->ctrl_reg);
3861 + /* Write sample counter */
3862 + me4000_outl(ai_context->sample_counter, ai_context->sample_counter_reg);
3867 +static int me4000_ai_start(me4000_ai_context_t * ai_context)
3870 + CALL_PDEBUG("me4000_ai_start() is executed\n");
3872 + /* Prepare Hardware */
3873 + err = ai_common_start(ai_context);
3877 + /* Start conversion by dummy read */
3878 + me4000_inl(ai_context->start_reg);
3883 +static int me4000_ai_start_ex(unsigned long *arg,
3884 + me4000_ai_context_t * ai_context)
3887 + wait_queue_head_t queue;
3888 + unsigned long ref;
3889 + unsigned long timeout;
3891 + CALL_PDEBUG("me4000_ai_start_ex() is executed\n");
3893 + if (get_user(timeout, arg)) {
3895 + "me4000_ai_start_ex():Cannot copy data from user\n");
3899 + init_waitqueue_head(&queue);
3901 + /* Prepare Hardware */
3902 + err = ai_common_start(ai_context);
3909 + (inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM))
3911 + interruptible_sleep_on_timeout(&queue, 1);
3912 + if (signal_pending(current)) {
3914 + "ME4000:me4000_ai_start_ex():Wait on start of state machine interrupted\n");
3917 + if (((jiffies - ref) > (timeout * HZ / USER_HZ))) { // 2.6 has diffrent definitions for HZ in user and kernel space
3919 + "ME4000:me4000_ai_start_ex():Timeout reached\n");
3925 + (inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM))
3927 + interruptible_sleep_on_timeout(&queue, 1);
3928 + if (signal_pending(current)) {
3930 + "ME4000:me4000_ai_start_ex():Wait on start of state machine interrupted\n");
3939 +static int me4000_ai_stop(me4000_ai_context_t * ai_context)
3941 + wait_queue_head_t queue;
3943 + unsigned long flags;
3945 + CALL_PDEBUG("me4000_ai_stop() is executed\n");
3947 + init_waitqueue_head(&queue);
3949 + /* Disable irqs and clear data fifo */
3950 + spin_lock_irqsave(&ai_context->int_lock, flags);
3951 + tmp = me4000_inl(ai_context->ctrl_reg);
3953 + ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ |
3954 + ME4000_AI_CTRL_BIT_DATA_FIFO);
3955 + /* Stop conversion of the state machine */
3956 + tmp |= ME4000_AI_CTRL_BIT_STOP;
3957 + me4000_outl(tmp, ai_context->ctrl_reg);
3958 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
3960 + /* Clear circular buffer */
3961 + ai_context->circ_buf.head = 0;
3962 + ai_context->circ_buf.tail = 0;
3964 + while (inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM) {
3965 + interruptible_sleep_on_timeout(&queue, 1);
3966 + if (signal_pending(current)) {
3968 + "ME4000:me4000_ai_stop():Wait on state machine after stop interrupted\n");
3976 +static int me4000_ai_immediate_stop(me4000_ai_context_t * ai_context)
3978 + wait_queue_head_t queue;
3980 + unsigned long flags;
3982 + CALL_PDEBUG("me4000_ai_stop() is executed\n");
3984 + init_waitqueue_head(&queue);
3986 + /* Disable irqs and clear data fifo */
3987 + spin_lock_irqsave(&ai_context->int_lock, flags);
3988 + tmp = me4000_inl(ai_context->ctrl_reg);
3990 + ~(ME4000_AI_CTRL_BIT_HF_IRQ | ME4000_AI_CTRL_BIT_SC_IRQ |
3991 + ME4000_AI_CTRL_BIT_DATA_FIFO);
3992 + /* Stop conversion of the state machine */
3993 + tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
3994 + me4000_outl(tmp, ai_context->ctrl_reg);
3995 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
3997 + /* Clear circular buffer */
3998 + ai_context->circ_buf.head = 0;
3999 + ai_context->circ_buf.tail = 0;
4001 + while (inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM) {
4002 + interruptible_sleep_on_timeout(&queue, 1);
4003 + if (signal_pending(current)) {
4005 + "ME4000:me4000_ai_stop():Wait on state machine after stop interrupted\n");
4013 +static int me4000_ai_ex_trig_enable(me4000_ai_context_t * ai_context)
4016 + unsigned long flags;
4018 + CALL_PDEBUG("me4000_ai_ex_trig_enable() is executed\n");
4020 + spin_lock_irqsave(&ai_context->int_lock, flags);
4021 + tmp = me4000_inl(ai_context->ctrl_reg);
4022 + tmp |= ME4000_AI_CTRL_BIT_EX_TRIG;
4023 + me4000_outl(tmp, ai_context->ctrl_reg);
4024 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
4029 +static int me4000_ai_ex_trig_disable(me4000_ai_context_t * ai_context)
4032 + unsigned long flags;
4034 + CALL_PDEBUG("me4000_ai_ex_trig_disable() is executed\n");
4036 + spin_lock_irqsave(&ai_context->int_lock, flags);
4037 + tmp = me4000_inl(ai_context->ctrl_reg);
4038 + tmp &= ~ME4000_AI_CTRL_BIT_EX_TRIG;
4039 + me4000_outl(tmp, ai_context->ctrl_reg);
4040 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
4045 +static int me4000_ai_ex_trig_setup(me4000_ai_trigger_t * arg,
4046 + me4000_ai_context_t * ai_context)
4048 + me4000_ai_trigger_t cmd;
4051 + unsigned long flags;
4053 + CALL_PDEBUG("me4000_ai_ex_trig_setup() is executed\n");
4055 + /* Copy data from user */
4056 + err = copy_from_user(&cmd, arg, sizeof(me4000_ai_trigger_t));
4059 + "ME4000:me4000_ai_ex_trig_setup():Can't copy from user space\n");
4063 + spin_lock_irqsave(&ai_context->int_lock, flags);
4064 + tmp = me4000_inl(ai_context->ctrl_reg);
4066 + if (cmd.mode == ME4000_AI_TRIGGER_EXT_DIGITAL) {
4067 + tmp &= ~ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG;
4068 + } else if (cmd.mode == ME4000_AI_TRIGGER_EXT_ANALOG) {
4069 + if (!ai_context->board_info->board_p->ai.ex_trig_analog) {
4071 + "ME4000:me4000_ai_ex_trig_setup():No analog trigger available\n");
4074 + tmp |= ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG;
4076 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
4078 + "ME4000:me4000_ai_ex_trig_setup():Invalid trigger mode specified\n");
4082 + if (cmd.edge == ME4000_AI_TRIGGER_EXT_EDGE_RISING) {
4084 + ~(ME4000_AI_CTRL_BIT_EX_TRIG_BOTH |
4085 + ME4000_AI_CTRL_BIT_EX_TRIG_FALLING);
4086 + } else if (cmd.edge == ME4000_AI_TRIGGER_EXT_EDGE_FALLING) {
4087 + tmp |= ME4000_AI_CTRL_BIT_EX_TRIG_FALLING;
4088 + tmp &= ~ME4000_AI_CTRL_BIT_EX_TRIG_BOTH;
4089 + } else if (cmd.edge == ME4000_AI_TRIGGER_EXT_EDGE_BOTH) {
4091 + ME4000_AI_CTRL_BIT_EX_TRIG_BOTH |
4092 + ME4000_AI_CTRL_BIT_EX_TRIG_FALLING;
4094 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
4096 + "ME4000:me4000_ai_ex_trig_setup():Invalid trigger edge specified\n");
4100 + me4000_outl(tmp, ai_context->ctrl_reg);
4101 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
4105 +static int me4000_ai_sc_setup(me4000_ai_sc_t * arg,
4106 + me4000_ai_context_t * ai_context)
4108 + me4000_ai_sc_t cmd;
4111 + CALL_PDEBUG("me4000_ai_sc_setup() is executed\n");
4113 + /* Copy data from user */
4114 + err = copy_from_user(&cmd, arg, sizeof(me4000_ai_sc_t));
4117 + "ME4000:me4000_ai_sc_setup():Can't copy from user space\n");
4121 + ai_context->sample_counter = cmd.value;
4122 + ai_context->sample_counter_reload = cmd.reload;
4127 +static ssize_t me4000_ai_read(struct file *filep, char *buff, size_t cnt,
4130 + me4000_ai_context_t *ai_context = filep->private_data;
4131 + s16 *buffer = (s16 *) buff;
4132 + size_t count = cnt / 2;
4133 + unsigned long flags;
4138 + wait_queue_t wait;
4140 + CALL_PDEBUG("me4000_ai_read() is executed\n");
4142 + init_waitqueue_entry(&wait, current);
4146 + PDEBUG("me4000_ai_read():Count is 0\n");
4150 + while (count > 0) {
4151 + if (filep->f_flags & O_NONBLOCK) {
4152 + c = me4000_values_to_end(ai_context->circ_buf,
4153 + ME4000_AI_BUFFER_COUNT);
4156 + ("me4000_ai_read():Returning from nonblocking read\n");
4160 + /* Check if conversion is still running */
4162 + (me4000_inl(ai_context->status_reg) &
4163 + ME4000_AI_STATUS_BIT_FSM)) {
4165 + "ME4000:me4000_ai_read():Conversion interrupted\n");
4169 + wait_event_interruptible(ai_context->wait_queue,
4170 + (me4000_values_to_end
4171 + (ai_context->circ_buf,
4172 + ME4000_AI_BUFFER_COUNT)));
4173 + if (signal_pending(current)) {
4175 + "ME4000:me4000_ai_read():Wait on values interrupted from signal\n");
4180 + /* Only read count values or as much as available */
4181 + c = me4000_values_to_end(ai_context->circ_buf,
4182 + ME4000_AI_BUFFER_COUNT);
4183 + PDEBUG("me4000_ai_read():%d values to end\n", c);
4187 + PDEBUG("me4000_ai_read():Copy %d values to user space\n", c);
4189 + k -= copy_to_user(buffer,
4190 + ai_context->circ_buf.buf +
4191 + ai_context->circ_buf.tail, k);
4195 + "ME4000:me4000_ai_read():Cannot copy new values to user\n");
4199 + ai_context->circ_buf.tail =
4200 + (ai_context->circ_buf.tail + c) & (ME4000_AI_BUFFER_COUNT -
4206 + spin_lock_irqsave(&ai_context->int_lock, flags);
4207 + if (me4000_buf_space
4208 + (ai_context->circ_buf, ME4000_AI_BUFFER_COUNT)) {
4209 + tmp = me4000_inl(ai_context->ctrl_reg);
4211 + /* Determine interrupt setup */
4212 + if (ai_context->sample_counter
4213 + && !ai_context->sample_counter_reload) {
4214 + /* Enable Half Full Interrupt and Sample Counter Interrupt */
4216 + ME4000_AI_CTRL_BIT_SC_IRQ |
4217 + ME4000_AI_CTRL_BIT_HF_IRQ;
4218 + } else if (ai_context->sample_counter
4219 + && ai_context->sample_counter_reload) {
4220 + if (ai_context->sample_counter <
4221 + ME4000_AI_FIFO_COUNT / 2) {
4222 + /* Enable only Sample Counter Interrupt */
4223 + tmp |= ME4000_AI_CTRL_BIT_SC_IRQ;
4225 + /* Enable Half Full Interrupt and Sample Counter Interrupt */
4227 + ME4000_AI_CTRL_BIT_SC_IRQ |
4228 + ME4000_AI_CTRL_BIT_HF_IRQ;
4231 + /* Enable only Half Full Interrupt */
4232 + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ;
4235 + me4000_outl(tmp, ai_context->ctrl_reg);
4237 + spin_unlock_irqrestore(&ai_context->int_lock, flags);
4240 + /* Check if conversion is still running */
4241 + if (!(me4000_inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM)) {
4243 + "ME4000:me4000_ai_read():Conversion not running after complete read\n");
4247 + if (filep->f_flags & O_NONBLOCK) {
4248 + return (k == 0) ? -EAGAIN : 2 * ret;
4251 + CALL_PDEBUG("me4000_ai_read() is leaved\n");
4255 +static unsigned int me4000_ai_poll(struct file *file_p, poll_table * wait)
4257 + me4000_ai_context_t *ai_context;
4258 + unsigned long mask = 0;
4260 + CALL_PDEBUG("me4000_ai_poll() is executed\n");
4262 + ai_context = file_p->private_data;
4264 + /* Register wait queue */
4265 + poll_wait(file_p, &ai_context->wait_queue, wait);
4267 + /* Get available values */
4268 + if (me4000_values_to_end(ai_context->circ_buf, ME4000_AI_BUFFER_COUNT))
4269 + mask |= POLLIN | POLLRDNORM;
4271 + PDEBUG("me4000_ai_poll():Return mask %lX\n", mask);
4276 +static int me4000_ai_offset_enable(me4000_ai_context_t * ai_context)
4278 + unsigned long tmp;
4280 + CALL_PDEBUG("me4000_ai_offset_enable() is executed\n");
4282 + tmp = me4000_inl(ai_context->ctrl_reg);
4283 + tmp |= ME4000_AI_CTRL_BIT_OFFSET;
4284 + me4000_outl(tmp, ai_context->ctrl_reg);
4289 +static int me4000_ai_offset_disable(me4000_ai_context_t * ai_context)
4291 + unsigned long tmp;
4293 + CALL_PDEBUG("me4000_ai_offset_disable() is executed\n");
4295 + tmp = me4000_inl(ai_context->ctrl_reg);
4296 + tmp &= ~ME4000_AI_CTRL_BIT_OFFSET;
4297 + me4000_outl(tmp, ai_context->ctrl_reg);
4302 +static int me4000_ai_fullscale_enable(me4000_ai_context_t * ai_context)
4304 + unsigned long tmp;
4306 + CALL_PDEBUG("me4000_ai_fullscale_enable() is executed\n");
4308 + tmp = me4000_inl(ai_context->ctrl_reg);
4309 + tmp |= ME4000_AI_CTRL_BIT_FULLSCALE;
4310 + me4000_outl(tmp, ai_context->ctrl_reg);
4315 +static int me4000_ai_fullscale_disable(me4000_ai_context_t * ai_context)
4317 + unsigned long tmp;
4319 + CALL_PDEBUG("me4000_ai_fullscale_disable() is executed\n");
4321 + tmp = me4000_inl(ai_context->ctrl_reg);
4322 + tmp &= ~ME4000_AI_CTRL_BIT_FULLSCALE;
4323 + me4000_outl(tmp, ai_context->ctrl_reg);
4328 +static int me4000_ai_fsm_state(int *arg, me4000_ai_context_t * ai_context)
4330 + unsigned long tmp;
4332 + CALL_PDEBUG("me4000_ai_fsm_state() is executed\n");
4335 + (me4000_inl(ai_context->status_reg) & ME4000_AI_STATUS_BIT_FSM) ? 1
4338 + if (put_user(tmp, arg)) {
4339 + printk(KERN_ERR "me4000_ai_fsm_state():Cannot copy to user\n");
4346 +static int me4000_ai_get_count_buffer(unsigned long *arg,
4347 + me4000_ai_context_t * ai_context)
4352 + c = me4000_buf_count(ai_context->circ_buf, ME4000_AI_BUFFER_COUNT);
4354 + err = copy_to_user(arg, &c, sizeof(unsigned long));
4357 + "ME4000:me4000_ai_get_count_buffer():Can't copy to user space\n");
4364 +/*---------------------------------- EEPROM stuff ---------------------------*/
4366 +static int eeprom_write_cmd(me4000_ai_context_t * ai_context, unsigned long cmd,
4370 + unsigned long value;
4372 + CALL_PDEBUG("eeprom_write_cmd() is executed\n");
4374 + PDEBUG("eeprom_write_cmd():Write command 0x%08lX with length = %d\n",
4377 + /* Get the ICR register and clear the related bits */
4378 + value = me4000_inl(ai_context->board_info->plx_regbase + PLX_ICR);
4379 + value &= ~(PLX_ICR_MASK_EEPROM);
4380 + me4000_outl(value, ai_context->board_info->plx_regbase + PLX_ICR);
4382 + /* Raise the chip select */
4383 + value |= PLX_ICR_BIT_EEPROM_CHIP_SELECT;
4384 + me4000_outl(value, ai_context->board_info->plx_regbase + PLX_ICR);
4385 + udelay(EEPROM_DELAY);
4387 + for (i = 0; i < length; i++) {
4388 + if (cmd & ((0x1 << (length - 1)) >> i)) {
4389 + value |= PLX_ICR_BIT_EEPROM_WRITE;
4391 + value &= ~PLX_ICR_BIT_EEPROM_WRITE;
4394 + /* Write to EEPROM */
4395 + me4000_outl(value,
4396 + ai_context->board_info->plx_regbase + PLX_ICR);
4397 + udelay(EEPROM_DELAY);
4399 + /* Raising edge of the clock */
4400 + value |= PLX_ICR_BIT_EEPROM_CLOCK_SET;
4401 + me4000_outl(value,
4402 + ai_context->board_info->plx_regbase + PLX_ICR);
4403 + udelay(EEPROM_DELAY);
4405 + /* Falling edge of the clock */
4406 + value &= ~PLX_ICR_BIT_EEPROM_CLOCK_SET;
4407 + me4000_outl(value,
4408 + ai_context->board_info->plx_regbase + PLX_ICR);
4409 + udelay(EEPROM_DELAY);
4412 + /* Clear the chip select */
4413 + value &= ~PLX_ICR_BIT_EEPROM_CHIP_SELECT;
4414 + me4000_outl(value, ai_context->board_info->plx_regbase + PLX_ICR);
4415 + udelay(EEPROM_DELAY);
4417 + /* Wait until hardware is ready for sure */
4423 +static unsigned short eeprom_read_cmd(me4000_ai_context_t * ai_context,
4424 + unsigned long cmd, int length)
4427 + unsigned long value;
4428 + unsigned short id = 0;
4430 + CALL_PDEBUG("eeprom_read_cmd() is executed\n");
4432 + PDEBUG("eeprom_read_cmd():Read command 0x%08lX with length = %d\n", cmd,
4435 + /* Get the ICR register and clear the related bits */
4436 + value = me4000_inl(ai_context->board_info->plx_regbase + PLX_ICR);
4437 + value &= ~(PLX_ICR_MASK_EEPROM);
4439 + me4000_outl(value, ai_context->board_info->plx_regbase + PLX_ICR);
4441 + /* Raise the chip select */
4442 + value |= PLX_ICR_BIT_EEPROM_CHIP_SELECT;
4443 + me4000_outl(value, ai_context->board_info->plx_regbase + PLX_ICR);
4444 + udelay(EEPROM_DELAY);
4446 + /* Write the read command to the eeprom */
4447 + for (i = 0; i < length; i++) {
4448 + if (cmd & ((0x1 << (length - 1)) >> i)) {
4449 + value |= PLX_ICR_BIT_EEPROM_WRITE;
4451 + value &= ~PLX_ICR_BIT_EEPROM_WRITE;
4453 + me4000_outl(value,
4454 + ai_context->board_info->plx_regbase + PLX_ICR);
4455 + udelay(EEPROM_DELAY);
4457 + /* Raising edge of the clock */
4458 + value |= PLX_ICR_BIT_EEPROM_CLOCK_SET;
4459 + me4000_outl(value,
4460 + ai_context->board_info->plx_regbase + PLX_ICR);
4461 + udelay(EEPROM_DELAY);
4463 + /* Falling edge of the clock */
4464 + value &= ~PLX_ICR_BIT_EEPROM_CLOCK_SET;
4465 + me4000_outl(value,
4466 + ai_context->board_info->plx_regbase + PLX_ICR);
4467 + udelay(EEPROM_DELAY);
4470 + /* Read the value from the eeprom */
4471 + for (i = 0; i < 16; i++) {
4472 + /* Raising edge of the clock */
4473 + value |= PLX_ICR_BIT_EEPROM_CLOCK_SET;
4474 + me4000_outl(value,
4475 + ai_context->board_info->plx_regbase + PLX_ICR);
4476 + udelay(EEPROM_DELAY);
4478 + if (me4000_inl(ai_context->board_info->plx_regbase + PLX_ICR) &
4479 + PLX_ICR_BIT_EEPROM_READ) {
4480 + id |= (0x8000 >> i);
4481 + PDEBUG("eeprom_read_cmd():OR with 0x%04X\n",
4484 + PDEBUG("eeprom_read_cmd():Dont't OR\n");
4487 + /* Falling edge of the clock */
4488 + value &= ~PLX_ICR_BIT_EEPROM_CLOCK_SET;
4489 + me4000_outl(value,
4490 + ai_context->board_info->plx_regbase + PLX_ICR);
4491 + udelay(EEPROM_DELAY);
4494 + /* Clear the chip select */
4495 + value &= ~PLX_ICR_BIT_EEPROM_CHIP_SELECT;
4496 + me4000_outl(value, ai_context->board_info->plx_regbase + PLX_ICR);
4497 + udelay(EEPROM_DELAY);
4502 +static int me4000_eeprom_write(me4000_eeprom_t * arg,
4503 + me4000_ai_context_t * ai_context)
4506 + me4000_eeprom_t setup;
4507 + unsigned long cmd;
4508 + unsigned long date_high;
4509 + unsigned long date_low;
4511 + CALL_PDEBUG("me4000_eeprom_write() is executed\n");
4513 + err = copy_from_user(&setup, arg, sizeof(setup));
4516 + "ME4000:me4000_eeprom_write():Cannot copy from user\n");
4520 + /* Enable writing */
4521 + eeprom_write_cmd(ai_context, ME4000_EEPROM_CMD_WRITE_ENABLE,
4522 + ME4000_EEPROM_CMD_LENGTH_WRITE_ENABLE);
4524 + /* Command for date */
4525 + date_high = (setup.date & 0xFFFF0000) >> 16;
4526 + date_low = (setup.date & 0x0000FFFF);
4529 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_DATE_HIGH <<
4530 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4534 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4539 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_DATE_LOW <<
4540 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4544 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4548 + /* Command for unipolar 10V offset */
4550 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_1_UNI_OFFSET <<
4551 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4556 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4560 + /* Command for unipolar 10V fullscale */
4562 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_1_UNI_FULLSCALE <<
4563 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4567 + uni_10_fullscale);
4568 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4572 + /* Command for unipolar 2,5V offset */
4574 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_4_UNI_OFFSET <<
4575 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4580 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4584 + /* Command for unipolar 2,5V fullscale */
4586 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_4_UNI_FULLSCALE <<
4587 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4591 + uni_2_5_fullscale);
4592 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4596 + /* Command for bipolar 10V offset */
4598 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_1_BI_OFFSET <<
4599 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4604 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4608 + /* Command for bipolar 10V fullscale */
4610 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_1_BI_FULLSCALE <<
4611 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4616 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4620 + /* Command for bipolar 2,5V offset */
4622 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_4_BI_OFFSET <<
4623 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4628 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4632 + /* Command for bipolar 2,5V fullscale */
4634 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_4_BI_FULLSCALE <<
4635 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4639 + bi_2_5_fullscale);
4640 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4644 + /* Command for differential 10V offset */
4646 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_1_DIFF_OFFSET <<
4647 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4652 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4656 + /* Command for differential 10V fullscale */
4658 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_1_DIFF_FULLSCALE
4659 + << ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4663 + diff_10_fullscale);
4664 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4668 + /* Command for differential 2,5V offset */
4670 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_4_DIFF_OFFSET <<
4671 + ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4676 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4680 + /* Command for differential 2,5V fullscale */
4682 + ME4000_EEPROM_CMD_WRITE | (ME4000_EEPROM_ADR_GAIN_4_DIFF_FULLSCALE
4683 + << ME4000_EEPROM_DATA_LENGTH) | (0xFFFF &
4687 + diff_2_5_fullscale);
4688 + err = eeprom_write_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_WRITE);
4692 + /* Disable writing */
4693 + eeprom_write_cmd(ai_context, ME4000_EEPROM_CMD_WRITE_DISABLE,
4694 + ME4000_EEPROM_CMD_LENGTH_WRITE_DISABLE);
4699 +static int me4000_eeprom_read(me4000_eeprom_t * arg,
4700 + me4000_ai_context_t * ai_context)
4703 + unsigned long cmd;
4704 + me4000_eeprom_t setup;
4706 + CALL_PDEBUG("me4000_eeprom_read() is executed\n");
4708 + /* Command for date */
4709 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_DATE_HIGH;
4711 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4712 + setup.date <<= 16;
4713 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_DATE_LOW;
4715 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4717 + /* Command for unipolar 10V offset */
4718 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_1_UNI_OFFSET;
4719 + setup.uni_10_offset =
4720 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4722 + /* Command for unipolar 10V fullscale */
4723 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_1_UNI_FULLSCALE;
4724 + setup.uni_10_fullscale =
4725 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4727 + /* Command for unipolar 2,5V offset */
4728 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_4_UNI_OFFSET;
4729 + setup.uni_2_5_offset =
4730 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4732 + /* Command for unipolar 2,5V fullscale */
4733 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_4_UNI_FULLSCALE;
4734 + setup.uni_2_5_fullscale =
4735 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4737 + /* Command for bipolar 10V offset */
4738 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_1_BI_OFFSET;
4739 + setup.bi_10_offset =
4740 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4742 + /* Command for bipolar 10V fullscale */
4743 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_1_BI_FULLSCALE;
4744 + setup.bi_10_fullscale =
4745 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4747 + /* Command for bipolar 2,5V offset */
4748 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_4_BI_OFFSET;
4749 + setup.bi_2_5_offset =
4750 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4752 + /* Command for bipolar 2,5V fullscale */
4753 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_4_BI_FULLSCALE;
4754 + setup.bi_2_5_fullscale =
4755 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4757 + /* Command for differntial 10V offset */
4758 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_1_DIFF_OFFSET;
4759 + setup.diff_10_offset =
4760 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4762 + /* Command for differential 10V fullscale */
4763 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_1_DIFF_FULLSCALE;
4764 + setup.diff_10_fullscale =
4765 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4767 + /* Command for differntial 2,5V offset */
4768 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_4_DIFF_OFFSET;
4769 + setup.diff_2_5_offset =
4770 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4772 + /* Command for differential 2,5V fullscale */
4773 + cmd = ME4000_EEPROM_CMD_READ | ME4000_EEPROM_ADR_GAIN_4_DIFF_FULLSCALE;
4774 + setup.diff_2_5_fullscale =
4775 + eeprom_read_cmd(ai_context, cmd, ME4000_EEPROM_CMD_LENGTH_READ);
4777 + err = copy_to_user(arg, &setup, sizeof(setup));
4780 + "ME4000:me4000_eeprom_read():Cannot copy to user\n");
4787 +/*------------------------------------ DIO stuff ----------------------------------------------*/
4789 +static int me4000_dio_ioctl(struct inode *inode_p, struct file *file_p,
4790 + unsigned int service, unsigned long arg)
4792 + me4000_dio_context_t *dio_context;
4794 + CALL_PDEBUG("me4000_dio_ioctl() is executed\n");
4796 + dio_context = file_p->private_data;
4798 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
4799 + printk(KERN_ERR "me4000_dio_ioctl():Wrong magic number\n");
4802 + if (_IOC_NR(service) > ME4000_IOCTL_MAXNR) {
4803 + printk(KERN_ERR "me4000_dio_ioctl():Service number to high\n");
4807 + switch (service) {
4808 + case ME4000_DIO_CONFIG:
4809 + return me4000_dio_config((me4000_dio_config_t *) arg,
4811 + case ME4000_DIO_SET_BYTE:
4812 + return me4000_dio_set_byte((me4000_dio_byte_t *) arg,
4814 + case ME4000_DIO_GET_BYTE:
4815 + return me4000_dio_get_byte((me4000_dio_byte_t *) arg,
4817 + case ME4000_DIO_RESET:
4818 + return me4000_dio_reset(dio_context);
4821 + "ME4000:me4000_dio_ioctl():Invalid service number %d\n",
4828 +static int me4000_dio_config(me4000_dio_config_t * arg,
4829 + me4000_dio_context_t * dio_context)
4831 + me4000_dio_config_t cmd;
4835 + CALL_PDEBUG("me4000_dio_config() is executed\n");
4837 + /* Copy data from user */
4838 + err = copy_from_user(&cmd, arg, sizeof(me4000_dio_config_t));
4841 + "ME4000:me4000_dio_config():Can't copy from user space\n");
4845 + /* Check port parameter */
4846 + if (cmd.port >= dio_context->dio_count) {
4848 + "ME4000:me4000_dio_config():Port %d is not available\n",
4853 + PDEBUG("me4000_dio_config(): port %d, mode %d, function %d\n", cmd.port,
4854 + cmd.mode, cmd.function);
4856 + if (cmd.port == ME4000_DIO_PORT_A) {
4857 + if (cmd.mode == ME4000_DIO_PORT_INPUT) {
4858 + /* Check if opto isolated version */
4859 + if (!(me4000_inl(dio_context->dir_reg) & 0x1)) {
4861 + "ME4000:me4000_dio_config():Cannot set to input on opto isolated versions\n");
4865 + tmp = me4000_inl(dio_context->ctrl_reg);
4867 + ~(ME4000_DIO_CTRL_BIT_MODE_0 |
4868 + ME4000_DIO_CTRL_BIT_MODE_1);
4869 + me4000_outl(tmp, dio_context->ctrl_reg);
4870 + } else if (cmd.mode == ME4000_DIO_PORT_OUTPUT) {
4871 + tmp = me4000_inl(dio_context->ctrl_reg);
4873 + ~(ME4000_DIO_CTRL_BIT_MODE_0 |
4874 + ME4000_DIO_CTRL_BIT_MODE_1);
4875 + tmp |= ME4000_DIO_CTRL_BIT_MODE_0;
4876 + me4000_outl(tmp, dio_context->ctrl_reg);
4877 + } else if (cmd.mode == ME4000_DIO_FIFO_LOW) {
4878 + tmp = me4000_inl(dio_context->ctrl_reg);
4880 + ~(ME4000_DIO_CTRL_BIT_MODE_0 |
4881 + ME4000_DIO_CTRL_BIT_MODE_1 |
4882 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_0);
4884 + ME4000_DIO_CTRL_BIT_MODE_0 |
4885 + ME4000_DIO_CTRL_BIT_MODE_1;
4886 + me4000_outl(tmp, dio_context->ctrl_reg);
4887 + } else if (cmd.mode == ME4000_DIO_FIFO_HIGH) {
4888 + tmp = me4000_inl(dio_context->ctrl_reg);
4890 + ME4000_DIO_CTRL_BIT_MODE_0 |
4891 + ME4000_DIO_CTRL_BIT_MODE_1 |
4892 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_0;
4893 + me4000_outl(tmp, dio_context->ctrl_reg);
4896 + "ME4000:me4000_dio_config():Mode %d is not available\n",
4900 + } else if (cmd.port == ME4000_DIO_PORT_B) {
4901 + if (cmd.mode == ME4000_DIO_PORT_INPUT) {
4902 + /* Only do anything when TTL version is installed */
4903 + if ((me4000_inl(dio_context->dir_reg) & 0x1)) {
4904 + tmp = me4000_inl(dio_context->ctrl_reg);
4906 + ~(ME4000_DIO_CTRL_BIT_MODE_2 |
4907 + ME4000_DIO_CTRL_BIT_MODE_3);
4908 + me4000_outl(tmp, dio_context->ctrl_reg);
4910 + } else if (cmd.mode == ME4000_DIO_PORT_OUTPUT) {
4911 + /* Check if opto isolated version */
4912 + if (!(me4000_inl(dio_context->dir_reg) & 0x1)) {
4914 + "ME4000:me4000_dio_config():Cannot set to output on opto isolated versions\n");
4918 + tmp = me4000_inl(dio_context->ctrl_reg);
4920 + ~(ME4000_DIO_CTRL_BIT_MODE_2 |
4921 + ME4000_DIO_CTRL_BIT_MODE_3);
4922 + tmp |= ME4000_DIO_CTRL_BIT_MODE_2;
4923 + me4000_outl(tmp, dio_context->ctrl_reg);
4924 + } else if (cmd.mode == ME4000_DIO_FIFO_LOW) {
4925 + /* Check if opto isolated version */
4926 + if (!(me4000_inl(dio_context->dir_reg) & 0x1)) {
4928 + "ME4000:me4000_dio_config():Cannot set to FIFO low output on opto isolated versions\n");
4932 + tmp = me4000_inl(dio_context->ctrl_reg);
4934 + ~(ME4000_DIO_CTRL_BIT_MODE_2 |
4935 + ME4000_DIO_CTRL_BIT_MODE_3 |
4936 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_1);
4938 + ME4000_DIO_CTRL_BIT_MODE_2 |
4939 + ME4000_DIO_CTRL_BIT_MODE_3;
4940 + me4000_outl(tmp, dio_context->ctrl_reg);
4941 + } else if (cmd.mode == ME4000_DIO_FIFO_HIGH) {
4942 + /* Check if opto isolated version */
4943 + if (!(me4000_inl(dio_context->dir_reg) & 0x1)) {
4945 + "ME4000:me4000_dio_config():Cannot set to FIFO high output on opto isolated versions\n");
4949 + tmp = me4000_inl(dio_context->ctrl_reg);
4951 + ME4000_DIO_CTRL_BIT_MODE_2 |
4952 + ME4000_DIO_CTRL_BIT_MODE_3 |
4953 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_1;
4954 + me4000_outl(tmp, dio_context->ctrl_reg);
4957 + "ME4000:me4000_dio_config():Mode %d is not available\n",
4961 + } else if (cmd.port == ME4000_DIO_PORT_C) {
4962 + if (cmd.mode == ME4000_DIO_PORT_INPUT) {
4963 + tmp = me4000_inl(dio_context->ctrl_reg);
4965 + ~(ME4000_DIO_CTRL_BIT_MODE_4 |
4966 + ME4000_DIO_CTRL_BIT_MODE_5);
4967 + me4000_outl(tmp, dio_context->ctrl_reg);
4968 + } else if (cmd.mode == ME4000_DIO_PORT_OUTPUT) {
4969 + tmp = me4000_inl(dio_context->ctrl_reg);
4971 + ~(ME4000_DIO_CTRL_BIT_MODE_4 |
4972 + ME4000_DIO_CTRL_BIT_MODE_5);
4973 + tmp |= ME4000_DIO_CTRL_BIT_MODE_4;
4974 + me4000_outl(tmp, dio_context->ctrl_reg);
4975 + } else if (cmd.mode == ME4000_DIO_FIFO_LOW) {
4976 + tmp = me4000_inl(dio_context->ctrl_reg);
4978 + ~(ME4000_DIO_CTRL_BIT_MODE_4 |
4979 + ME4000_DIO_CTRL_BIT_MODE_5 |
4980 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_2);
4982 + ME4000_DIO_CTRL_BIT_MODE_4 |
4983 + ME4000_DIO_CTRL_BIT_MODE_5;
4984 + me4000_outl(tmp, dio_context->ctrl_reg);
4985 + } else if (cmd.mode == ME4000_DIO_FIFO_HIGH) {
4986 + tmp = me4000_inl(dio_context->ctrl_reg);
4988 + ME4000_DIO_CTRL_BIT_MODE_4 |
4989 + ME4000_DIO_CTRL_BIT_MODE_5 |
4990 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_2;
4991 + me4000_outl(tmp, dio_context->ctrl_reg);
4994 + "ME4000:me4000_dio_config():Mode %d is not available\n",
4998 + } else if (cmd.port == ME4000_DIO_PORT_D) {
4999 + if (cmd.mode == ME4000_DIO_PORT_INPUT) {
5000 + tmp = me4000_inl(dio_context->ctrl_reg);
5002 + ~(ME4000_DIO_CTRL_BIT_MODE_6 |
5003 + ME4000_DIO_CTRL_BIT_MODE_7);
5004 + me4000_outl(tmp, dio_context->ctrl_reg);
5005 + } else if (cmd.mode == ME4000_DIO_PORT_OUTPUT) {
5006 + tmp = me4000_inl(dio_context->ctrl_reg);
5008 + ~(ME4000_DIO_CTRL_BIT_MODE_6 |
5009 + ME4000_DIO_CTRL_BIT_MODE_7);
5010 + tmp |= ME4000_DIO_CTRL_BIT_MODE_6;
5011 + me4000_outl(tmp, dio_context->ctrl_reg);
5012 + } else if (cmd.mode == ME4000_DIO_FIFO_LOW) {
5013 + tmp = me4000_inl(dio_context->ctrl_reg);
5015 + ~(ME4000_DIO_CTRL_BIT_MODE_6 |
5016 + ME4000_DIO_CTRL_BIT_MODE_7 |
5017 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_3);
5019 + ME4000_DIO_CTRL_BIT_MODE_6 |
5020 + ME4000_DIO_CTRL_BIT_MODE_7;
5021 + me4000_outl(tmp, dio_context->ctrl_reg);
5022 + } else if (cmd.mode == ME4000_DIO_FIFO_HIGH) {
5023 + tmp = me4000_inl(dio_context->ctrl_reg);
5025 + ME4000_DIO_CTRL_BIT_MODE_6 |
5026 + ME4000_DIO_CTRL_BIT_MODE_7 |
5027 + ME4000_DIO_CTRL_BIT_FIFO_HIGH_3;
5028 + me4000_outl(tmp, dio_context->ctrl_reg);
5031 + "ME4000:me4000_dio_config():Mode %d is not available\n",
5037 + "ME4000:me4000_dio_config():Port %d is not available\n",
5042 + PDEBUG("me4000_dio_config(): port %d, mode %d, function %d\n", cmd.port,
5043 + cmd.mode, cmd.function);
5045 + if ((cmd.mode == ME4000_DIO_FIFO_HIGH)
5046 + || (cmd.mode == ME4000_DIO_FIFO_LOW)) {
5047 + tmp = me4000_inl(dio_context->ctrl_reg);
5049 + ~(ME4000_DIO_CTRL_BIT_FUNCTION_0 |
5050 + ME4000_DIO_CTRL_BIT_FUNCTION_1);
5051 + if (cmd.function == ME4000_DIO_FUNCTION_PATTERN) {
5052 + me4000_outl(tmp, dio_context->ctrl_reg);
5053 + } else if (cmd.function == ME4000_DIO_FUNCTION_DEMUX) {
5054 + tmp |= ME4000_DIO_CTRL_BIT_FUNCTION_0;
5055 + me4000_outl(tmp, dio_context->ctrl_reg);
5056 + } else if (cmd.function == ME4000_DIO_FUNCTION_MUX) {
5057 + tmp |= ME4000_DIO_CTRL_BIT_FUNCTION_1;
5058 + me4000_outl(tmp, dio_context->ctrl_reg);
5061 + "ME4000:me4000_dio_config():Invalid port function specified\n");
5069 +static int me4000_dio_set_byte(me4000_dio_byte_t * arg,
5070 + me4000_dio_context_t * dio_context)
5072 + me4000_dio_byte_t cmd;
5075 + CALL_PDEBUG("me4000_dio_set_byte() is executed\n");
5077 + /* Copy data from user */
5078 + err = copy_from_user(&cmd, arg, sizeof(me4000_dio_byte_t));
5081 + "ME4000:me4000_dio_set_byte():Can't copy from user space\n");
5085 + /* Check port parameter */
5086 + if (cmd.port >= dio_context->dio_count) {
5088 + "ME4000:me4000_dio_set_byte():Port %d is not available\n",
5093 + if (cmd.port == ME4000_DIO_PORT_A) {
5094 + if ((me4000_inl(dio_context->ctrl_reg) & 0x3) != 0x1) {
5096 + "ME4000:me4000_dio_set_byte():Port %d is not in output mode\n",
5100 + me4000_outl(cmd.byte, dio_context->port_0_reg);
5101 + } else if (cmd.port == ME4000_DIO_PORT_B) {
5102 + if ((me4000_inl(dio_context->ctrl_reg) & 0xC) != 0x4) {
5104 + "ME4000:me4000_dio_set_byte():Port %d is not in output mode\n",
5108 + me4000_outl(cmd.byte, dio_context->port_1_reg);
5109 + } else if (cmd.port == ME4000_DIO_PORT_C) {
5110 + if ((me4000_inl(dio_context->ctrl_reg) & 0x30) != 0x10) {
5112 + "ME4000:me4000_dio_set_byte():Port %d is not in output mode\n",
5116 + me4000_outl(cmd.byte, dio_context->port_2_reg);
5117 + } else if (cmd.port == ME4000_DIO_PORT_D) {
5118 + if ((me4000_inl(dio_context->ctrl_reg) & 0xC0) != 0x40) {
5120 + "ME4000:me4000_dio_set_byte():Port %d is not in output mode\n",
5124 + me4000_outl(cmd.byte, dio_context->port_3_reg);
5127 + "ME4000:me4000_dio_set_byte():Port %d is not available\n",
5135 +static int me4000_dio_get_byte(me4000_dio_byte_t * arg,
5136 + me4000_dio_context_t * dio_context)
5138 + me4000_dio_byte_t cmd;
5141 + CALL_PDEBUG("me4000_dio_get_byte() is executed\n");
5143 + /* Copy data from user */
5144 + err = copy_from_user(&cmd, arg, sizeof(me4000_dio_byte_t));
5147 + "ME4000:me4000_dio_get_byte():Can't copy from user space\n");
5151 + /* Check port parameter */
5152 + if (cmd.port >= dio_context->dio_count) {
5154 + "ME4000:me4000_dio_get_byte():Port %d is not available\n",
5159 + if (cmd.port == ME4000_DIO_PORT_A) {
5160 + cmd.byte = me4000_inl(dio_context->port_0_reg) & 0xFF;
5161 + } else if (cmd.port == ME4000_DIO_PORT_B) {
5162 + cmd.byte = me4000_inl(dio_context->port_1_reg) & 0xFF;
5163 + } else if (cmd.port == ME4000_DIO_PORT_C) {
5164 + cmd.byte = me4000_inl(dio_context->port_2_reg) & 0xFF;
5165 + } else if (cmd.port == ME4000_DIO_PORT_D) {
5166 + cmd.byte = me4000_inl(dio_context->port_3_reg) & 0xFF;
5169 + "ME4000:me4000_dio_get_byte():Port %d is not available\n",
5174 + /* Copy result back to user */
5175 + err = copy_to_user(arg, &cmd, sizeof(me4000_dio_byte_t));
5178 + "ME4000:me4000_dio_get_byte():Can't copy to user space\n");
5185 +static int me4000_dio_reset(me4000_dio_context_t * dio_context)
5187 + CALL_PDEBUG("me4000_dio_reset() is executed\n");
5189 + /* Clear the control register */
5190 + me4000_outl(0, dio_context->ctrl_reg);
5192 + /* Check for opto isolated version */
5193 + if (!(me4000_inl(dio_context->dir_reg) & 0x1)) {
5194 + me4000_outl(0x1, dio_context->ctrl_reg);
5195 + me4000_outl(0x0, dio_context->port_0_reg);
5201 +/*------------------------------------ COUNTER STUFF ------------------------------------*/
5203 +static int me4000_cnt_ioctl(struct inode *inode_p, struct file *file_p,
5204 + unsigned int service, unsigned long arg)
5206 + me4000_cnt_context_t *cnt_context;
5208 + CALL_PDEBUG("me4000_cnt_ioctl() is executed\n");
5210 + cnt_context = file_p->private_data;
5212 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
5213 + printk(KERN_ERR "me4000_dio_ioctl():Wrong magic number\n");
5216 + if (_IOC_NR(service) > ME4000_IOCTL_MAXNR) {
5217 + printk(KERN_ERR "me4000_dio_ioctl():Service number to high\n");
5221 + switch (service) {
5222 + case ME4000_CNT_READ:
5223 + return me4000_cnt_read((me4000_cnt_t *) arg, cnt_context);
5224 + case ME4000_CNT_WRITE:
5225 + return me4000_cnt_write((me4000_cnt_t *) arg, cnt_context);
5226 + case ME4000_CNT_CONFIG:
5227 + return me4000_cnt_config((me4000_cnt_config_t *) arg,
5229 + case ME4000_CNT_RESET:
5230 + return me4000_cnt_reset(cnt_context);
5233 + "ME4000:me4000_dio_ioctl():Invalid service number %d\n",
5240 +static int me4000_cnt_config(me4000_cnt_config_t * arg,
5241 + me4000_cnt_context_t * cnt_context)
5243 + me4000_cnt_config_t cmd;
5248 + CALL_PDEBUG("me4000_cnt_config() is executed\n");
5250 + /* Copy data from user */
5251 + err = copy_from_user(&cmd, arg, sizeof(me4000_cnt_config_t));
5254 + "ME4000:me4000_cnt_config():Can't copy from user space\n");
5258 + /* Check counter parameter */
5259 + switch (cmd.counter) {
5260 + case ME4000_CNT_COUNTER_0:
5261 + counter = ME4000_CNT_CTRL_BIT_COUNTER_0;
5263 + case ME4000_CNT_COUNTER_1:
5264 + counter = ME4000_CNT_CTRL_BIT_COUNTER_1;
5266 + case ME4000_CNT_COUNTER_2:
5267 + counter = ME4000_CNT_CTRL_BIT_COUNTER_2;
5271 + "ME4000:me4000_cnt_config():Counter %d is not available\n",
5276 + /* Check mode parameter */
5277 + switch (cmd.mode) {
5278 + case ME4000_CNT_MODE_0:
5279 + mode = ME4000_CNT_CTRL_BIT_MODE_0;
5281 + case ME4000_CNT_MODE_1:
5282 + mode = ME4000_CNT_CTRL_BIT_MODE_1;
5284 + case ME4000_CNT_MODE_2:
5285 + mode = ME4000_CNT_CTRL_BIT_MODE_2;
5287 + case ME4000_CNT_MODE_3:
5288 + mode = ME4000_CNT_CTRL_BIT_MODE_3;
5290 + case ME4000_CNT_MODE_4:
5291 + mode = ME4000_CNT_CTRL_BIT_MODE_4;
5293 + case ME4000_CNT_MODE_5:
5294 + mode = ME4000_CNT_CTRL_BIT_MODE_5;
5298 + "ME4000:me4000_cnt_config():Mode %d is not available\n",
5303 + /* Write the control word */
5304 + me4000_outb((counter | mode | 0x30), cnt_context->ctrl_reg);
5309 +static int me4000_cnt_read(me4000_cnt_t * arg,
5310 + me4000_cnt_context_t * cnt_context)
5316 + CALL_PDEBUG("me4000_cnt_read() is executed\n");
5318 + /* Copy data from user */
5319 + err = copy_from_user(&cmd, arg, sizeof(me4000_cnt_t));
5322 + "ME4000:me4000_cnt_read():Can't copy from user space\n");
5326 + /* Read counter */
5327 + switch (cmd.counter) {
5328 + case ME4000_CNT_COUNTER_0:
5329 + tmp = me4000_inb(cnt_context->counter_0_reg);
5331 + tmp = me4000_inb(cnt_context->counter_0_reg);
5332 + cmd.value |= ((u16) tmp) << 8;
5334 + case ME4000_CNT_COUNTER_1:
5335 + tmp = me4000_inb(cnt_context->counter_1_reg);
5337 + tmp = me4000_inb(cnt_context->counter_1_reg);
5338 + cmd.value |= ((u16) tmp) << 8;
5340 + case ME4000_CNT_COUNTER_2:
5341 + tmp = me4000_inb(cnt_context->counter_2_reg);
5343 + tmp = me4000_inb(cnt_context->counter_2_reg);
5344 + cmd.value |= ((u16) tmp) << 8;
5348 + "ME4000:me4000_cnt_read():Counter %d is not available\n",
5353 + /* Copy result back to user */
5354 + err = copy_to_user(arg, &cmd, sizeof(me4000_cnt_t));
5357 + "ME4000:me4000_cnt_read():Can't copy to user space\n");
5364 +static int me4000_cnt_write(me4000_cnt_t * arg,
5365 + me4000_cnt_context_t * cnt_context)
5371 + CALL_PDEBUG("me4000_cnt_write() is executed\n");
5373 + /* Copy data from user */
5374 + err = copy_from_user(&cmd, arg, sizeof(me4000_cnt_t));
5377 + "ME4000:me4000_cnt_write():Can't copy from user space\n");
5381 + /* Write counter */
5382 + switch (cmd.counter) {
5383 + case ME4000_CNT_COUNTER_0:
5384 + tmp = cmd.value & 0xFF;
5385 + me4000_outb(tmp, cnt_context->counter_0_reg);
5386 + tmp = (cmd.value >> 8) & 0xFF;
5387 + me4000_outb(tmp, cnt_context->counter_0_reg);
5389 + case ME4000_CNT_COUNTER_1:
5390 + tmp = cmd.value & 0xFF;
5391 + me4000_outb(tmp, cnt_context->counter_1_reg);
5392 + tmp = (cmd.value >> 8) & 0xFF;
5393 + me4000_outb(tmp, cnt_context->counter_1_reg);
5395 + case ME4000_CNT_COUNTER_2:
5396 + tmp = cmd.value & 0xFF;
5397 + me4000_outb(tmp, cnt_context->counter_2_reg);
5398 + tmp = (cmd.value >> 8) & 0xFF;
5399 + me4000_outb(tmp, cnt_context->counter_2_reg);
5403 + "ME4000:me4000_cnt_write():Counter %d is not available\n",
5411 +static int me4000_cnt_reset(me4000_cnt_context_t * cnt_context)
5413 + CALL_PDEBUG("me4000_cnt_reset() is executed\n");
5415 + /* Set the mode and value for counter 0 */
5416 + me4000_outb(0x30, cnt_context->ctrl_reg);
5417 + me4000_outb(0x00, cnt_context->counter_0_reg);
5418 + me4000_outb(0x00, cnt_context->counter_0_reg);
5420 + /* Set the mode and value for counter 1 */
5421 + me4000_outb(0x70, cnt_context->ctrl_reg);
5422 + me4000_outb(0x00, cnt_context->counter_1_reg);
5423 + me4000_outb(0x00, cnt_context->counter_1_reg);
5425 + /* Set the mode and value for counter 2 */
5426 + me4000_outb(0xB0, cnt_context->ctrl_reg);
5427 + me4000_outb(0x00, cnt_context->counter_2_reg);
5428 + me4000_outb(0x00, cnt_context->counter_2_reg);
5433 +/*------------------------------------ External Interrupt stuff ------------------------------------*/
5435 +static int me4000_ext_int_ioctl(struct inode *inode_p, struct file *file_p,
5436 + unsigned int service, unsigned long arg)
5438 + me4000_ext_int_context_t *ext_int_context;
5440 + CALL_PDEBUG("me4000_ext_int_ioctl() is executed\n");
5442 + ext_int_context = file_p->private_data;
5444 + if (_IOC_TYPE(service) != ME4000_MAGIC) {
5445 + printk(KERN_ERR "me4000_ext_int_ioctl():Wrong magic number\n");
5448 + if (_IOC_NR(service) > ME4000_IOCTL_MAXNR) {
5450 + "me4000_ext_int_ioctl():Service number to high\n");
5454 + switch (service) {
5455 + case ME4000_EXT_INT_ENABLE:
5456 + return me4000_ext_int_enable(ext_int_context);
5457 + case ME4000_EXT_INT_DISABLE:
5458 + return me4000_ext_int_disable(ext_int_context);
5459 + case ME4000_EXT_INT_COUNT:
5460 + return me4000_ext_int_count((unsigned long *)arg,
5464 + "ME4000:me4000_ext_int_ioctl():Invalid service number %d\n",
5471 +static int me4000_ext_int_enable(me4000_ext_int_context_t * ext_int_context)
5473 + unsigned long tmp;
5475 + CALL_PDEBUG("me4000_ext_int_enable() is executed\n");
5477 + tmp = me4000_inl(ext_int_context->ctrl_reg);
5478 + tmp |= ME4000_AI_CTRL_BIT_EX_IRQ;
5479 + me4000_outl(tmp, ext_int_context->ctrl_reg);
5484 +static int me4000_ext_int_disable(me4000_ext_int_context_t * ext_int_context)
5486 + unsigned long tmp;
5488 + CALL_PDEBUG("me4000_ext_int_disable() is executed\n");
5490 + tmp = me4000_inl(ext_int_context->ctrl_reg);
5491 + tmp &= ~ME4000_AI_CTRL_BIT_EX_IRQ;
5492 + me4000_outl(tmp, ext_int_context->ctrl_reg);
5497 +static int me4000_ext_int_count(unsigned long *arg,
5498 + me4000_ext_int_context_t * ext_int_context)
5501 + CALL_PDEBUG("me4000_ext_int_count() is executed\n");
5503 + put_user(ext_int_context->int_count, arg);
5507 +/*------------------------------------ General stuff ------------------------------------*/
5509 +static int me4000_get_user_info(me4000_user_info_t * arg,
5510 + me4000_info_t * board_info)
5512 + me4000_user_info_t user_info;
5514 + CALL_PDEBUG("me4000_get_user_info() is executed\n");
5516 + user_info.board_count = board_info->board_count;
5517 + user_info.plx_regbase = board_info->plx_regbase;
5518 + user_info.plx_regbase_size = board_info->plx_regbase_size;
5519 + user_info.me4000_regbase = board_info->me4000_regbase;
5520 + user_info.me4000_regbase_size = board_info->me4000_regbase_size;
5521 + user_info.serial_no = board_info->serial_no;
5522 + user_info.hw_revision = board_info->hw_revision;
5523 + user_info.vendor_id = board_info->vendor_id;
5524 + user_info.device_id = board_info->device_id;
5525 + user_info.pci_bus_no = board_info->pci_bus_no;
5526 + user_info.pci_dev_no = board_info->pci_dev_no;
5527 + user_info.pci_func_no = board_info->pci_func_no;
5528 + user_info.irq = board_info->irq;
5529 + user_info.irq_count = board_info->irq_count;
5530 + user_info.driver_version = ME4000_DRIVER_VERSION;
5531 + user_info.ao_count = board_info->board_p->ao.count;
5532 + user_info.ao_fifo_count = board_info->board_p->ao.fifo_count;
5534 + user_info.ai_count = board_info->board_p->ai.count;
5535 + user_info.ai_sh_count = board_info->board_p->ai.sh_count;
5536 + user_info.ai_ex_trig_analog = board_info->board_p->ai.ex_trig_analog;
5538 + user_info.dio_count = board_info->board_p->dio.count;
5540 + user_info.cnt_count = board_info->board_p->cnt.count;
5542 + if (copy_to_user(arg, &user_info, sizeof(me4000_user_info_t)))
5548 +/*------------------------------------ ISR STUFF ------------------------------------*/
5550 +static int me4000_ext_int_fasync(int fd, struct file *file_ptr, int mode)
5553 + me4000_ext_int_context_t *ext_int_context;
5555 + CALL_PDEBUG("me4000_ext_int_fasync() is executed\n");
5557 + ext_int_context = file_ptr->private_data;
5560 + fasync_helper(fd, file_ptr, mode, &ext_int_context->fasync_ptr);
5562 + CALL_PDEBUG("me4000_ext_int_fasync() is leaved\n");
5566 +static irqreturn_t me4000_ao_isr(int irq, void *dev_id)
5570 + me4000_ao_context_t *ao_context;
5574 + //unsigned long before;
5575 + //unsigned long after;
5577 + ISR_PDEBUG("me4000_ao_isr() is executed\n");
5579 + ao_context = dev_id;
5581 + /* Check if irq number is right */
5582 + if (irq != ao_context->irq) {
5583 + ISR_PDEBUG("me4000_ao_isr():incorrect interrupt num: %d\n",
5588 + /* Check if this DAC rised an interrupt */
5590 + ((0x1 << (ao_context->index + 3)) &
5591 + me4000_inl(ao_context->irq_status_reg))) {
5592 + ISR_PDEBUG("me4000_ao_isr():Not this DAC\n");
5596 + /* Read status register to find out what happened */
5597 + tmp = me4000_inl(ao_context->status_reg);
5599 + if (!(tmp & ME4000_AO_STATUS_BIT_EF) && (tmp & ME4000_AO_STATUS_BIT_HF)
5600 + && (tmp & ME4000_AO_STATUS_BIT_HF)) {
5601 + c = ME4000_AO_FIFO_COUNT;
5602 + ISR_PDEBUG("me4000_ao_isr():Fifo empty\n");
5603 + } else if ((tmp & ME4000_AO_STATUS_BIT_EF)
5604 + && (tmp & ME4000_AO_STATUS_BIT_HF)
5605 + && (tmp & ME4000_AO_STATUS_BIT_HF)) {
5606 + c = ME4000_AO_FIFO_COUNT / 2;
5607 + ISR_PDEBUG("me4000_ao_isr():Fifo under half full\n");
5610 + ISR_PDEBUG("me4000_ao_isr():Fifo full\n");
5613 + ISR_PDEBUG("me4000_ao_isr():Try to write 0x%04X values\n", c);
5616 + c1 = me4000_values_to_end(ao_context->circ_buf,
5617 + ME4000_AO_BUFFER_COUNT);
5618 + ISR_PDEBUG("me4000_ao_isr():Values to end = %d\n", c1);
5624 + ("me4000_ao_isr():Work done or buffer empty\n");
5628 + if (((ao_context->fifo_reg & 0xFF) == ME4000_AO_01_FIFO_REG) ||
5629 + ((ao_context->fifo_reg & 0xFF) == ME4000_AO_03_FIFO_REG)) {
5630 + for (i = 0; i < c1; i++) {
5634 + (ao_context->circ_buf.buf +
5635 + ao_context->circ_buf.tail + i))) << 16;
5636 + outl(value, ao_context->fifo_reg);
5639 + outsw(ao_context->fifo_reg,
5640 + ao_context->circ_buf.buf +
5641 + ao_context->circ_buf.tail, c1);
5644 + //printk(KERN_ERR"ME4000:me4000_ao_isr():Time lapse = %lu\n", after - before);
5646 + ao_context->circ_buf.tail =
5647 + (ao_context->circ_buf.tail + c1) & (ME4000_AO_BUFFER_COUNT -
5649 + ISR_PDEBUG("me4000_ao_isr():%d values wrote to port 0x%04X\n",
5650 + c1, ao_context->fifo_reg);
5654 + /* If there are no values left in the buffer, disable interrupts */
5655 + spin_lock(&ao_context->int_lock);
5656 + if (!me4000_buf_count(ao_context->circ_buf, ME4000_AO_BUFFER_COUNT)) {
5658 + ("me4000_ao_isr():Disable Interrupt because no values left in buffer\n");
5659 + tmp = me4000_inl(ao_context->ctrl_reg);
5660 + tmp &= ~ME4000_AO_CTRL_BIT_ENABLE_IRQ;
5661 + me4000_outl(tmp, ao_context->ctrl_reg);
5663 + spin_unlock(&ao_context->int_lock);
5665 + /* Reset the interrupt */
5666 + spin_lock(&ao_context->int_lock);
5667 + tmp = me4000_inl(ao_context->ctrl_reg);
5668 + tmp |= ME4000_AO_CTRL_BIT_RESET_IRQ;
5669 + me4000_outl(tmp, ao_context->ctrl_reg);
5670 + tmp &= ~ME4000_AO_CTRL_BIT_RESET_IRQ;
5671 + me4000_outl(tmp, ao_context->ctrl_reg);
5673 + /* If state machine is stopped, flow was interrupted */
5674 + if (!(me4000_inl(ao_context->status_reg) & ME4000_AO_STATUS_BIT_FSM)) {
5675 + printk(KERN_ERR "ME4000:me4000_ao_isr():Broken pipe\n");
5676 + ao_context->pipe_flag = 1; // Set flag in order to inform write routine
5677 + tmp &= ~ME4000_AO_CTRL_BIT_ENABLE_IRQ; // Disable interrupt
5679 + me4000_outl(tmp, ao_context->ctrl_reg);
5680 + spin_unlock(&ao_context->int_lock);
5682 + /* Wake up waiting process */
5683 + wake_up_interruptible(&(ao_context->wait_queue));
5685 + /* Count the interrupt */
5686 + ao_context->board_info->irq_count++;
5688 + return IRQ_HANDLED;
5691 +static irqreturn_t me4000_ai_isr(int irq, void *dev_id)
5694 + me4000_ai_context_t *ai_context;
5698 +#ifdef ME4000_ISR_DEBUG
5699 + unsigned long before;
5700 + unsigned long after;
5703 + ISR_PDEBUG("me4000_ai_isr() is executed\n");
5705 +#ifdef ME4000_ISR_DEBUG
5709 + ai_context = dev_id;
5711 + /* Check if irq number is right */
5712 + if (irq != ai_context->irq) {
5713 + ISR_PDEBUG("me4000_ai_isr():incorrect interrupt num: %d\n",
5718 + if (me4000_inl(ai_context->irq_status_reg) &
5719 + ME4000_IRQ_STATUS_BIT_AI_HF) {
5721 + ("me4000_ai_isr():Fifo half full interrupt occured\n");
5723 + /* Read status register to find out what happened */
5724 + tmp = me4000_inl(ai_context->ctrl_reg);
5726 + if (!(tmp & ME4000_AI_STATUS_BIT_FF_DATA) &&
5727 + !(tmp & ME4000_AI_STATUS_BIT_HF_DATA)
5728 + && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
5729 + ISR_PDEBUG("me4000_ai_isr():Fifo full\n");
5730 + c = ME4000_AI_FIFO_COUNT;
5732 + /* FIFO overflow, so stop conversion and disable all interrupts */
5733 + spin_lock(&ai_context->int_lock);
5734 + tmp = me4000_inl(ai_context->ctrl_reg);
5735 + tmp |= ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
5737 + ~(ME4000_AI_CTRL_BIT_HF_IRQ |
5738 + ME4000_AI_CTRL_BIT_SC_IRQ);
5739 + outl(tmp, ai_context->ctrl_reg);
5740 + spin_unlock(&ai_context->int_lock);
5741 + } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA) &&
5742 + !(tmp & ME4000_AI_STATUS_BIT_HF_DATA)
5743 + && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
5744 + ISR_PDEBUG("me4000_ai_isr():Fifo half full\n");
5745 + c = ME4000_AI_FIFO_COUNT / 2;
5749 + ("me4000_ai_isr():Can't determine state of fifo\n");
5752 + ISR_PDEBUG("me4000_ai_isr():Try to read %d values\n", c);
5755 + c1 = me4000_space_to_end(ai_context->circ_buf,
5756 + ME4000_AI_BUFFER_COUNT);
5757 + ISR_PDEBUG("me4000_ai_isr():Space to end = %d\n", c1);
5763 + ("me4000_ai_isr():Work done or buffer full\n");
5767 + insw(ai_context->data_reg,
5768 + ai_context->circ_buf.buf +
5769 + ai_context->circ_buf.head, c1);
5770 + ai_context->circ_buf.head =
5771 + (ai_context->circ_buf.head +
5772 + c1) & (ME4000_AI_BUFFER_COUNT - 1);
5776 + /* Work is done, so reset the interrupt */
5778 + ("me4000_ai_isr():reset interrupt fifo half full interrupt\n");
5779 + spin_lock(&ai_context->int_lock);
5780 + tmp = me4000_inl(ai_context->ctrl_reg);
5781 + tmp |= ME4000_AI_CTRL_BIT_HF_IRQ_RESET;
5782 + me4000_outl(tmp, ai_context->ctrl_reg);
5783 + tmp &= ~ME4000_AI_CTRL_BIT_HF_IRQ_RESET;
5784 + me4000_outl(tmp, ai_context->ctrl_reg);
5785 + spin_unlock(&ai_context->int_lock);
5788 + if (me4000_inl(ai_context->irq_status_reg) & ME4000_IRQ_STATUS_BIT_SC) {
5790 + ("me4000_ai_isr():Sample counter interrupt occured\n");
5792 + if (!ai_context->sample_counter_reload) {
5794 + ("me4000_ai_isr():Single data block available\n");
5796 + /* Poll data until fifo empty */
5798 + (i < ME4000_AI_FIFO_COUNT / 2)
5799 + && (inl(ai_context->ctrl_reg) &
5800 + ME4000_AI_STATUS_BIT_EF_DATA); i++) {
5801 + if (me4000_space_to_end
5802 + (ai_context->circ_buf,
5803 + ME4000_AI_BUFFER_COUNT)) {
5804 + *(ai_context->circ_buf.buf +
5805 + ai_context->circ_buf.head) =
5806 + inw(ai_context->data_reg);
5807 + ai_context->circ_buf.head =
5808 + (ai_context->circ_buf.head +
5809 + 1) & (ME4000_AI_BUFFER_COUNT - 1);
5813 + ISR_PDEBUG("me4000_ai_isr():%d values read\n", i);
5815 + if (ai_context->sample_counter <=
5816 + ME4000_AI_FIFO_COUNT / 2) {
5818 + ("me4000_ai_isr():Interrupt from adjustable half full threshold\n");
5820 + /* Read status register to find out what happened */
5821 + tmp = me4000_inl(ai_context->ctrl_reg);
5823 + if (!(tmp & ME4000_AI_STATUS_BIT_FF_DATA) &&
5824 + !(tmp & ME4000_AI_STATUS_BIT_HF_DATA)
5825 + && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
5827 + ("me4000_ai_isr():Fifo full\n");
5828 + c = ME4000_AI_FIFO_COUNT;
5830 + /* FIFO overflow, so stop conversion */
5831 + spin_lock(&ai_context->int_lock);
5832 + tmp = me4000_inl(ai_context->ctrl_reg);
5834 + ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
5835 + outl(tmp, ai_context->ctrl_reg);
5836 + spin_unlock(&ai_context->int_lock);
5837 + } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA)
5839 + ME4000_AI_STATUS_BIT_HF_DATA)
5841 + ME4000_AI_STATUS_BIT_EF_DATA)) {
5843 + ("me4000_ai_isr():Fifo half full\n");
5844 + c = ME4000_AI_FIFO_COUNT / 2;
5846 + c = ai_context->sample_counter;
5848 + ("me4000_ai_isr():Sample count values\n");
5852 + ("me4000_ai_isr():Try to read %d values\n",
5856 + c1 = me4000_space_to_end(ai_context->
5858 + ME4000_AI_BUFFER_COUNT);
5860 + ("me4000_ai_isr():Space to end = %d\n",
5867 + ("me4000_ai_isr():Work done or buffer full\n");
5871 + insw(ai_context->data_reg,
5872 + ai_context->circ_buf.buf +
5873 + ai_context->circ_buf.head, c1);
5874 + ai_context->circ_buf.head =
5875 + (ai_context->circ_buf.head +
5876 + c1) & (ME4000_AI_BUFFER_COUNT - 1);
5881 + ("me4000_ai_isr():Multiple data block available\n");
5883 + /* Read status register to find out what happened */
5884 + tmp = me4000_inl(ai_context->ctrl_reg);
5886 + if (!(tmp & ME4000_AI_STATUS_BIT_FF_DATA) &&
5887 + !(tmp & ME4000_AI_STATUS_BIT_HF_DATA)
5888 + && (tmp & ME4000_AI_STATUS_BIT_EF_DATA)) {
5890 + ("me4000_ai_isr():Fifo full\n");
5891 + c = ME4000_AI_FIFO_COUNT;
5893 + /* FIFO overflow, so stop conversion */
5894 + spin_lock(&ai_context->int_lock);
5895 + tmp = me4000_inl(ai_context->ctrl_reg);
5897 + ME4000_AI_CTRL_BIT_IMMEDIATE_STOP;
5898 + outl(tmp, ai_context->ctrl_reg);
5899 + spin_unlock(&ai_context->int_lock);
5902 + c1 = me4000_space_to_end
5903 + (ai_context->circ_buf,
5904 + ME4000_AI_BUFFER_COUNT);
5906 + ("me4000_ai_isr():Space to end = %d\n",
5913 + ("me4000_ai_isr():Work done or buffer full\n");
5917 + insw(ai_context->data_reg,
5918 + ai_context->circ_buf.buf +
5919 + ai_context->circ_buf.head,
5921 + ai_context->circ_buf.head =
5922 + (ai_context->circ_buf.head +
5924 + (ME4000_AI_BUFFER_COUNT -
5928 + } else if ((tmp & ME4000_AI_STATUS_BIT_FF_DATA)
5930 + ME4000_AI_STATUS_BIT_HF_DATA)
5932 + ME4000_AI_STATUS_BIT_EF_DATA)) {
5934 + ("me4000_ai_isr():Fifo half full\n");
5935 + c = ME4000_AI_FIFO_COUNT / 2;
5938 + c1 = me4000_space_to_end
5939 + (ai_context->circ_buf,
5940 + ME4000_AI_BUFFER_COUNT);
5942 + ("me4000_ai_isr():Space to end = %d\n",
5949 + ("me4000_ai_isr():Work done or buffer full\n");
5953 + insw(ai_context->data_reg,
5954 + ai_context->circ_buf.buf +
5955 + ai_context->circ_buf.head,
5957 + ai_context->circ_buf.head =
5958 + (ai_context->circ_buf.head +
5960 + (ME4000_AI_BUFFER_COUNT -
5965 + /* Poll data until fifo empty */
5967 + (i < ME4000_AI_FIFO_COUNT / 2)
5968 + && (inl(ai_context->ctrl_reg) &
5969 + ME4000_AI_STATUS_BIT_EF_DATA);
5971 + if (me4000_space_to_end
5972 + (ai_context->circ_buf,
5973 + ME4000_AI_BUFFER_COUNT)) {
5974 + *(ai_context->circ_buf.
5976 + ai_context->circ_buf.
5978 + inw(ai_context->data_reg);
5979 + ai_context->circ_buf.
5984 + (ME4000_AI_BUFFER_COUNT
5990 + ("me4000_ai_isr():%d values read\n",
5996 + /* Work is done, so reset the interrupt */
5998 + ("me4000_ai_isr():reset interrupt from sample counter\n");
5999 + spin_lock(&ai_context->int_lock);
6000 + tmp = me4000_inl(ai_context->ctrl_reg);
6001 + tmp |= ME4000_AI_CTRL_BIT_SC_IRQ_RESET;
6002 + me4000_outl(tmp, ai_context->ctrl_reg);
6003 + tmp &= ~ME4000_AI_CTRL_BIT_SC_IRQ_RESET;
6004 + me4000_outl(tmp, ai_context->ctrl_reg);
6005 + spin_unlock(&ai_context->int_lock);
6008 + /* Values are now available, so wake up waiting process */
6009 + if (me4000_buf_count(ai_context->circ_buf, ME4000_AI_BUFFER_COUNT)) {
6010 + ISR_PDEBUG("me4000_ai_isr():Wake up waiting process\n");
6011 + wake_up_interruptible(&(ai_context->wait_queue));
6014 + /* If there is no space left in the buffer, disable interrupts */
6015 + spin_lock(&ai_context->int_lock);
6016 + if (!me4000_buf_space(ai_context->circ_buf, ME4000_AI_BUFFER_COUNT)) {
6018 + ("me4000_ai_isr():Disable Interrupt because no space left in buffer\n");
6019 + tmp = me4000_inl(ai_context->ctrl_reg);
6021 + ~(ME4000_AI_CTRL_BIT_SC_IRQ | ME4000_AI_CTRL_BIT_HF_IRQ |
6022 + ME4000_AI_CTRL_BIT_LE_IRQ);
6023 + me4000_outl(tmp, ai_context->ctrl_reg);
6025 + spin_unlock(&ai_context->int_lock);
6027 +#ifdef ME4000_ISR_DEBUG
6029 + printk(KERN_ERR "ME4000:me4000_ai_isr():Time lapse = %lu\n",
6033 + return IRQ_HANDLED;
6036 +static irqreturn_t me4000_ext_int_isr(int irq, void *dev_id)
6038 + me4000_ext_int_context_t *ext_int_context;
6039 + unsigned long tmp;
6041 + ISR_PDEBUG("me4000_ext_int_isr() is executed\n");
6043 + ext_int_context = dev_id;
6045 + /* Check if irq number is right */
6046 + if (irq != ext_int_context->irq) {
6047 + ISR_PDEBUG("me4000_ext_int_isr():incorrect interrupt num: %d\n",
6052 + if (me4000_inl(ext_int_context->irq_status_reg) &
6053 + ME4000_IRQ_STATUS_BIT_EX) {
6054 + ISR_PDEBUG("me4000_ext_int_isr():External interrupt occured\n");
6055 + tmp = me4000_inl(ext_int_context->ctrl_reg);
6056 + tmp |= ME4000_AI_CTRL_BIT_EX_IRQ_RESET;
6057 + me4000_outl(tmp, ext_int_context->ctrl_reg);
6058 + tmp &= ~ME4000_AI_CTRL_BIT_EX_IRQ_RESET;
6059 + me4000_outl(tmp, ext_int_context->ctrl_reg);
6061 + ext_int_context->int_count++;
6063 + if (ext_int_context->fasync_ptr) {
6065 + ("me2600_ext_int_isr():Send signal to process\n");
6066 + kill_fasync(&ext_int_context->fasync_ptr, SIGIO,
6071 + return IRQ_HANDLED;
6074 +void __exit me4000_module_exit(void)
6076 + struct list_head *board_p;
6077 + me4000_info_t *board_info;
6079 + CALL_PDEBUG("cleanup_module() is executed\n");
6081 + unregister_chrdev(me4000_ext_int_major_driver_no, ME4000_EXT_INT_NAME);
6083 + unregister_chrdev(me4000_cnt_major_driver_no, ME4000_CNT_NAME);
6085 + unregister_chrdev(me4000_dio_major_driver_no, ME4000_DIO_NAME);
6087 + unregister_chrdev(me4000_ai_major_driver_no, ME4000_AI_NAME);
6089 + unregister_chrdev(me4000_ao_major_driver_no, ME4000_AO_NAME);
6091 + remove_proc_entry("me4000", NULL);
6093 + pci_unregister_driver(&me4000_driver);
6095 + /* Reset the boards */
6096 + for (board_p = me4000_board_info_list.next;
6097 + board_p != &me4000_board_info_list; board_p = board_p->next) {
6098 + board_info = list_entry(board_p, me4000_info_t, list);
6099 + me4000_reset_board(board_info);
6102 + clear_board_info_list();
6105 +module_exit(me4000_module_exit);
6107 +static int me4000_read_procmem(char *buf, char **start, off_t offset, int count,
6108 + int *eof, void *data)
6111 + int limit = count - 1000;
6112 + me4000_info_t *board_info;
6113 + struct list_head *ptr;
6115 + len += sprintf(buf + len, "\nME4000 DRIVER VERSION %X.%X.%X\n\n",
6116 + (ME4000_DRIVER_VERSION & 0xFF0000) >> 16,
6117 + (ME4000_DRIVER_VERSION & 0xFF00) >> 8,
6118 + (ME4000_DRIVER_VERSION & 0xFF));
6120 + /* Search for the board context */
6121 + for (ptr = me4000_board_info_list.next;
6122 + (ptr != &me4000_board_info_list) && (len < limit);
6123 + ptr = ptr->next) {
6124 + board_info = list_entry(ptr, me4000_info_t, list);
6127 + sprintf(buf + len, "Board number %d:\n",
6128 + board_info->board_count);
6129 + len += sprintf(buf + len, "---------------\n");
6131 + sprintf(buf + len, "PLX base register = 0x%lX\n",
6132 + board_info->plx_regbase);
6134 + sprintf(buf + len, "PLX base register size = 0x%lX\n",
6135 + board_info->plx_regbase_size);
6137 + sprintf(buf + len, "ME4000 base register = 0x%lX\n",
6138 + board_info->me4000_regbase);
6140 + sprintf(buf + len, "ME4000 base register size = 0x%lX\n",
6141 + board_info->me4000_regbase_size);
6143 + sprintf(buf + len, "Serial number = 0x%X\n",
6144 + board_info->serial_no);
6146 + sprintf(buf + len, "Hardware revision = 0x%X\n",
6147 + board_info->hw_revision);
6149 + sprintf(buf + len, "Vendor id = 0x%X\n",
6150 + board_info->vendor_id);
6152 + sprintf(buf + len, "Device id = 0x%X\n",
6153 + board_info->device_id);
6155 + sprintf(buf + len, "PCI bus number = %d\n",
6156 + board_info->pci_bus_no);
6158 + sprintf(buf + len, "PCI device number = %d\n",
6159 + board_info->pci_dev_no);
6161 + sprintf(buf + len, "PCI function number = %d\n",
6162 + board_info->pci_func_no);
6163 + len += sprintf(buf + len, "IRQ = %u\n", board_info->irq);
6165 + sprintf(buf + len,
6166 + "Count of interrupts since module was loaded = %d\n",
6167 + board_info->irq_count);
6170 + sprintf(buf + len, "Count of analog outputs = %d\n",
6171 + board_info->board_p->ao.count);
6173 + sprintf(buf + len, "Count of analog output fifos = %d\n",
6174 + board_info->board_p->ao.fifo_count);
6177 + sprintf(buf + len, "Count of analog inputs = %d\n",
6178 + board_info->board_p->ai.count);
6180 + sprintf(buf + len,
6181 + "Count of sample and hold devices for analog input = %d\n",
6182 + board_info->board_p->ai.sh_count);
6184 + sprintf(buf + len,
6185 + "Analog external trigger available for analog input = %d\n",
6186 + board_info->board_p->ai.ex_trig_analog);
6189 + sprintf(buf + len, "Count of digital ports = %d\n",
6190 + board_info->board_p->dio.count);
6193 + sprintf(buf + len, "Count of counter devices = %d\n",
6194 + board_info->board_p->cnt.count);
6196 + sprintf(buf + len, "AI control register = 0x%08X\n",
6197 + inl(board_info->me4000_regbase +
6198 + ME4000_AI_CTRL_REG));
6200 + len += sprintf(buf + len, "AO 0 control register = 0x%08X\n",
6201 + inl(board_info->me4000_regbase +
6202 + ME4000_AO_00_CTRL_REG));
6204 + sprintf(buf + len, "AO 0 status register = 0x%08X\n",
6205 + inl(board_info->me4000_regbase +
6206 + ME4000_AO_00_STATUS_REG));
6208 + sprintf(buf + len, "AO 1 control register = 0x%08X\n",
6209 + inl(board_info->me4000_regbase +
6210 + ME4000_AO_01_CTRL_REG));
6212 + sprintf(buf + len, "AO 1 status register = 0x%08X\n",
6213 + inl(board_info->me4000_regbase +
6214 + ME4000_AO_01_STATUS_REG));
6216 + sprintf(buf + len, "AO 2 control register = 0x%08X\n",
6217 + inl(board_info->me4000_regbase +
6218 + ME4000_AO_02_CTRL_REG));
6220 + sprintf(buf + len, "AO 2 status register = 0x%08X\n",
6221 + inl(board_info->me4000_regbase +
6222 + ME4000_AO_02_STATUS_REG));
6224 + sprintf(buf + len, "AO 3 control register = 0x%08X\n",
6225 + inl(board_info->me4000_regbase +
6226 + ME4000_AO_03_CTRL_REG));
6228 + sprintf(buf + len, "AO 3 status register = 0x%08X\n",
6229 + inl(board_info->me4000_regbase +
6230 + ME4000_AO_03_STATUS_REG));
6236 diff --git a/drivers/staging/me4000/me4000.h b/drivers/staging/me4000/me4000.h
6237 new file mode 100644
6238 index 0000000..c35e4b9
6240 +++ b/drivers/staging/me4000/me4000.h
6243 + * Copyright (C) 2003 Meilhaus Electronic GmbH (support@meilhaus.de)
6245 + * Source File : me4000.h
6246 + * Author : GG (Guenter Gebhardt) <g.gebhardt@meilhaus.de>
6254 +/*=============================================================================
6255 + The version of the driver release
6256 + ===========================================================================*/
6258 +#define ME4000_DRIVER_VERSION 0x10009 // Version 1.00.09
6260 +/*=============================================================================
6262 + ===========================================================================*/
6264 +#undef ME4000_CALL_DEBUG // Debug function entry and exit
6265 +#undef ME4000_ISR_DEBUG // Debug the interrupt service routine
6266 +#undef ME4000_PORT_DEBUG // Debug port access
6267 +#undef ME4000_DEBUG // General purpose debug masseges
6269 +#ifdef ME4000_CALL_DEBUG
6271 +#define CALL_PDEBUG(fmt, args...) printk(KERN_DEBUG"ME4000:" fmt, ##args)
6273 +# define CALL_PDEBUG(fmt, args...) // no debugging, do nothing
6276 +#ifdef ME4000_ISR_DEBUG
6278 +#define ISR_PDEBUG(fmt, args...) printk(KERN_DEBUG"ME4000:" fmt, ##args)
6280 +#define ISR_PDEBUG(fmt, args...) // no debugging, do nothing
6283 +#ifdef ME4000_PORT_DEBUG
6285 +#define PORT_PDEBUG(fmt, args...) printk(KERN_DEBUG"ME4000:" fmt, ##args)
6287 +#define PORT_PDEBUG(fmt, args...) // no debugging, do nothing
6290 +#ifdef ME4000_DEBUG
6292 +#define PDEBUG(fmt, args...) printk(KERN_DEBUG"ME4000:" fmt, ##args)
6294 +#define PDEBUG(fmt, args...) // no debugging, do nothing
6297 +/*=============================================================================
6298 + PCI vendor and device IDs
6299 + ===========================================================================*/
6301 +#define PCI_VENDOR_ID_MEILHAUS 0x1402
6303 +#define PCI_DEVICE_ID_MEILHAUS_ME4650 0x4650 // Low Cost version
6305 +#define PCI_DEVICE_ID_MEILHAUS_ME4660 0x4660 // Standard version
6306 +#define PCI_DEVICE_ID_MEILHAUS_ME4660I 0x4661 // Isolated version
6307 +#define PCI_DEVICE_ID_MEILHAUS_ME4660S 0x4662 // Standard version with Sample and Hold
6308 +#define PCI_DEVICE_ID_MEILHAUS_ME4660IS 0x4663 // Isolated version with Sample and Hold
6310 +#define PCI_DEVICE_ID_MEILHAUS_ME4670 0x4670 // Standard version
6311 +#define PCI_DEVICE_ID_MEILHAUS_ME4670I 0x4671 // Isolated version
6312 +#define PCI_DEVICE_ID_MEILHAUS_ME4670S 0x4672 // Standard version with Sample and Hold
6313 +#define PCI_DEVICE_ID_MEILHAUS_ME4670IS 0x4673 // Isolated version with Sample and Hold
6315 +#define PCI_DEVICE_ID_MEILHAUS_ME4680 0x4680 // Standard version
6316 +#define PCI_DEVICE_ID_MEILHAUS_ME4680I 0x4681 // Isolated version
6317 +#define PCI_DEVICE_ID_MEILHAUS_ME4680S 0x4682 // Standard version with Sample and Hold
6318 +#define PCI_DEVICE_ID_MEILHAUS_ME4680IS 0x4683 // Isolated version with Sample and Hold
6320 +/*=============================================================================
6321 + Device names, for entries in /proc/..
6322 + ===========================================================================*/
6324 +#define ME4000_NAME "me4000"
6325 +#define ME4000_AO_NAME "me4000_ao"
6326 +#define ME4000_AI_NAME "me4000_ai"
6327 +#define ME4000_DIO_NAME "me4000_dio"
6328 +#define ME4000_CNT_NAME "me4000_cnt"
6329 +#define ME4000_EXT_INT_NAME "me4000_ext_int"
6331 +/*=============================================================================
6332 + ME-4000 base register offsets
6333 + ===========================================================================*/
6335 +#define ME4000_AO_00_CTRL_REG 0x00 // R/W
6336 +#define ME4000_AO_00_STATUS_REG 0x04 // R/_
6337 +#define ME4000_AO_00_FIFO_REG 0x08 // _/W
6338 +#define ME4000_AO_00_SINGLE_REG 0x0C // R/W
6339 +#define ME4000_AO_00_TIMER_REG 0x10 // _/W
6341 +#define ME4000_AO_01_CTRL_REG 0x18 // R/W
6342 +#define ME4000_AO_01_STATUS_REG 0x1C // R/_
6343 +#define ME4000_AO_01_FIFO_REG 0x20 // _/W
6344 +#define ME4000_AO_01_SINGLE_REG 0x24 // R/W
6345 +#define ME4000_AO_01_TIMER_REG 0x28 // _/W
6347 +#define ME4000_AO_02_CTRL_REG 0x30 // R/W
6348 +#define ME4000_AO_02_STATUS_REG 0x34 // R/_
6349 +#define ME4000_AO_02_FIFO_REG 0x38 // _/W
6350 +#define ME4000_AO_02_SINGLE_REG 0x3C // R/W
6351 +#define ME4000_AO_02_TIMER_REG 0x40 // _/W
6353 +#define ME4000_AO_03_CTRL_REG 0x48 // R/W
6354 +#define ME4000_AO_03_STATUS_REG 0x4C // R/_
6355 +#define ME4000_AO_03_FIFO_REG 0x50 // _/W
6356 +#define ME4000_AO_03_SINGLE_REG 0x54 // R/W
6357 +#define ME4000_AO_03_TIMER_REG 0x58 // _/W
6359 +#define ME4000_AI_CTRL_REG 0x74 // _/W
6360 +#define ME4000_AI_STATUS_REG 0x74 // R/_
6361 +#define ME4000_AI_CHANNEL_LIST_REG 0x78 // _/W
6362 +#define ME4000_AI_DATA_REG 0x7C // R/_
6363 +#define ME4000_AI_CHAN_TIMER_REG 0x80 // _/W
6364 +#define ME4000_AI_CHAN_PRE_TIMER_REG 0x84 // _/W
6365 +#define ME4000_AI_SCAN_TIMER_LOW_REG 0x88 // _/W
6366 +#define ME4000_AI_SCAN_TIMER_HIGH_REG 0x8C // _/W
6367 +#define ME4000_AI_SCAN_PRE_TIMER_LOW_REG 0x90 // _/W
6368 +#define ME4000_AI_SCAN_PRE_TIMER_HIGH_REG 0x94 // _/W
6369 +#define ME4000_AI_START_REG 0x98 // R/_
6371 +#define ME4000_IRQ_STATUS_REG 0x9C // R/_
6373 +#define ME4000_DIO_PORT_0_REG 0xA0 // R/W
6374 +#define ME4000_DIO_PORT_1_REG 0xA4 // R/W
6375 +#define ME4000_DIO_PORT_2_REG 0xA8 // R/W
6376 +#define ME4000_DIO_PORT_3_REG 0xAC // R/W
6377 +#define ME4000_DIO_DIR_REG 0xB0 // R/W
6379 +#define ME4000_AO_LOADSETREG_XX 0xB4 // R/W
6381 +#define ME4000_DIO_CTRL_REG 0xB8 // R/W
6383 +#define ME4000_AO_DEMUX_ADJUST_REG 0xBC // -/W
6385 +#define ME4000_AI_SAMPLE_COUNTER_REG 0xC0 // _/W
6387 +/*=============================================================================
6388 + Value to adjust Demux
6389 + ===========================================================================*/
6391 +#define ME4000_AO_DEMUX_ADJUST_VALUE 0x4C
6393 +/*=============================================================================
6394 + Counter base register offsets
6395 + ===========================================================================*/
6397 +#define ME4000_CNT_COUNTER_0_REG 0x00
6398 +#define ME4000_CNT_COUNTER_1_REG 0x01
6399 +#define ME4000_CNT_COUNTER_2_REG 0x02
6400 +#define ME4000_CNT_CTRL_REG 0x03
6402 +/*=============================================================================
6403 + PLX base register offsets
6404 + ===========================================================================*/
6406 +#define PLX_INTCSR 0x4C // Interrupt control and status register
6407 +#define PLX_ICR 0x50 // Initialization control register
6409 +/*=============================================================================
6410 + Bits for the PLX_ICSR register
6411 + ===========================================================================*/
6413 +#define PLX_INTCSR_LOCAL_INT1_EN 0x01 // If set, local interrupt 1 is enabled (r/w)
6414 +#define PLX_INTCSR_LOCAL_INT1_POL 0x02 // If set, local interrupt 1 polarity is active high (r/w)
6415 +#define PLX_INTCSR_LOCAL_INT1_STATE 0x04 // If set, local interrupt 1 is active (r/_)
6416 +#define PLX_INTCSR_LOCAL_INT2_EN 0x08 // If set, local interrupt 2 is enabled (r/w)
6417 +#define PLX_INTCSR_LOCAL_INT2_POL 0x10 // If set, local interrupt 2 polarity is active high (r/w)
6418 +#define PLX_INTCSR_LOCAL_INT2_STATE 0x20 // If set, local interrupt 2 is active (r/_)
6419 +#define PLX_INTCSR_PCI_INT_EN 0x40 // If set, PCI interrupt is enabled (r/w)
6420 +#define PLX_INTCSR_SOFT_INT 0x80 // If set, a software interrupt is generated (r/w)
6422 +/*=============================================================================
6423 + Bits for the PLX_ICR register
6424 + ===========================================================================*/
6426 +#define PLX_ICR_BIT_EEPROM_CLOCK_SET 0x01000000
6427 +#define PLX_ICR_BIT_EEPROM_CHIP_SELECT 0x02000000
6428 +#define PLX_ICR_BIT_EEPROM_WRITE 0x04000000
6429 +#define PLX_ICR_BIT_EEPROM_READ 0x08000000
6430 +#define PLX_ICR_BIT_EEPROM_VALID 0x10000000
6432 +#define PLX_ICR_MASK_EEPROM 0x1F000000
6434 +#define EEPROM_DELAY 1
6436 +/*=============================================================================
6437 + Bits for the ME4000_AO_CTRL_REG register
6438 + ===========================================================================*/
6440 +#define ME4000_AO_CTRL_BIT_MODE_0 0x001
6441 +#define ME4000_AO_CTRL_BIT_MODE_1 0x002
6442 +#define ME4000_AO_CTRL_MASK_MODE 0x003
6443 +#define ME4000_AO_CTRL_BIT_STOP 0x004
6444 +#define ME4000_AO_CTRL_BIT_ENABLE_FIFO 0x008
6445 +#define ME4000_AO_CTRL_BIT_ENABLE_EX_TRIG 0x010
6446 +#define ME4000_AO_CTRL_BIT_EX_TRIG_EDGE 0x020
6447 +#define ME4000_AO_CTRL_BIT_IMMEDIATE_STOP 0x080
6448 +#define ME4000_AO_CTRL_BIT_ENABLE_DO 0x100
6449 +#define ME4000_AO_CTRL_BIT_ENABLE_IRQ 0x200
6450 +#define ME4000_AO_CTRL_BIT_RESET_IRQ 0x400
6451 +#define ME4000_AO_CTRL_BIT_EX_TRIG_BOTH 0x800
6453 +/*=============================================================================
6454 + Bits for the ME4000_AO_STATUS_REG register
6455 + ===========================================================================*/
6457 +#define ME4000_AO_STATUS_BIT_FSM 0x01
6458 +#define ME4000_AO_STATUS_BIT_FF 0x02
6459 +#define ME4000_AO_STATUS_BIT_HF 0x04
6460 +#define ME4000_AO_STATUS_BIT_EF 0x08
6462 +/*=============================================================================
6463 + Bits for the ME4000_AI_CTRL_REG register
6464 + ===========================================================================*/
6466 +#define ME4000_AI_CTRL_BIT_MODE_0 0x00000001
6467 +#define ME4000_AI_CTRL_BIT_MODE_1 0x00000002
6468 +#define ME4000_AI_CTRL_BIT_MODE_2 0x00000004
6469 +#define ME4000_AI_CTRL_BIT_SAMPLE_HOLD 0x00000008
6470 +#define ME4000_AI_CTRL_BIT_IMMEDIATE_STOP 0x00000010
6471 +#define ME4000_AI_CTRL_BIT_STOP 0x00000020
6472 +#define ME4000_AI_CTRL_BIT_CHANNEL_FIFO 0x00000040
6473 +#define ME4000_AI_CTRL_BIT_DATA_FIFO 0x00000080
6474 +#define ME4000_AI_CTRL_BIT_FULLSCALE 0x00000100
6475 +#define ME4000_AI_CTRL_BIT_OFFSET 0x00000200
6476 +#define ME4000_AI_CTRL_BIT_EX_TRIG_ANALOG 0x00000400
6477 +#define ME4000_AI_CTRL_BIT_EX_TRIG 0x00000800
6478 +#define ME4000_AI_CTRL_BIT_EX_TRIG_FALLING 0x00001000
6479 +#define ME4000_AI_CTRL_BIT_EX_IRQ 0x00002000
6480 +#define ME4000_AI_CTRL_BIT_EX_IRQ_RESET 0x00004000
6481 +#define ME4000_AI_CTRL_BIT_LE_IRQ 0x00008000
6482 +#define ME4000_AI_CTRL_BIT_LE_IRQ_RESET 0x00010000
6483 +#define ME4000_AI_CTRL_BIT_HF_IRQ 0x00020000
6484 +#define ME4000_AI_CTRL_BIT_HF_IRQ_RESET 0x00040000
6485 +#define ME4000_AI_CTRL_BIT_SC_IRQ 0x00080000
6486 +#define ME4000_AI_CTRL_BIT_SC_IRQ_RESET 0x00100000
6487 +#define ME4000_AI_CTRL_BIT_SC_RELOAD 0x00200000
6488 +#define ME4000_AI_CTRL_BIT_EX_TRIG_BOTH 0x80000000
6490 +/*=============================================================================
6491 + Bits for the ME4000_AI_STATUS_REG register
6492 + ===========================================================================*/
6494 +#define ME4000_AI_STATUS_BIT_EF_CHANNEL 0x00400000
6495 +#define ME4000_AI_STATUS_BIT_HF_CHANNEL 0x00800000
6496 +#define ME4000_AI_STATUS_BIT_FF_CHANNEL 0x01000000
6497 +#define ME4000_AI_STATUS_BIT_EF_DATA 0x02000000
6498 +#define ME4000_AI_STATUS_BIT_HF_DATA 0x04000000
6499 +#define ME4000_AI_STATUS_BIT_FF_DATA 0x08000000
6500 +#define ME4000_AI_STATUS_BIT_LE 0x10000000
6501 +#define ME4000_AI_STATUS_BIT_FSM 0x20000000
6503 +/*=============================================================================
6504 + Bits for the ME4000_IRQ_STATUS_REG register
6505 + ===========================================================================*/
6507 +#define ME4000_IRQ_STATUS_BIT_EX 0x01
6508 +#define ME4000_IRQ_STATUS_BIT_LE 0x02
6509 +#define ME4000_IRQ_STATUS_BIT_AI_HF 0x04
6510 +#define ME4000_IRQ_STATUS_BIT_AO_0_HF 0x08
6511 +#define ME4000_IRQ_STATUS_BIT_AO_1_HF 0x10
6512 +#define ME4000_IRQ_STATUS_BIT_AO_2_HF 0x20
6513 +#define ME4000_IRQ_STATUS_BIT_AO_3_HF 0x40
6514 +#define ME4000_IRQ_STATUS_BIT_SC 0x80
6516 +/*=============================================================================
6517 + Bits for the ME4000_DIO_CTRL_REG register
6518 + ===========================================================================*/
6520 +#define ME4000_DIO_CTRL_BIT_MODE_0 0X0001
6521 +#define ME4000_DIO_CTRL_BIT_MODE_1 0X0002
6522 +#define ME4000_DIO_CTRL_BIT_MODE_2 0X0004
6523 +#define ME4000_DIO_CTRL_BIT_MODE_3 0X0008
6524 +#define ME4000_DIO_CTRL_BIT_MODE_4 0X0010
6525 +#define ME4000_DIO_CTRL_BIT_MODE_5 0X0020
6526 +#define ME4000_DIO_CTRL_BIT_MODE_6 0X0040
6527 +#define ME4000_DIO_CTRL_BIT_MODE_7 0X0080
6529 +#define ME4000_DIO_CTRL_BIT_FUNCTION_0 0X0100
6530 +#define ME4000_DIO_CTRL_BIT_FUNCTION_1 0X0200
6532 +#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_0 0X0400
6533 +#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_1 0X0800
6534 +#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_2 0X1000
6535 +#define ME4000_DIO_CTRL_BIT_FIFO_HIGH_3 0X2000
6537 +/*=============================================================================
6538 + Bits for the ME4000_CNT_CTRL_REG register
6539 + ===========================================================================*/
6541 +#define ME4000_CNT_CTRL_BIT_COUNTER_0 0x00
6542 +#define ME4000_CNT_CTRL_BIT_COUNTER_1 0x40
6543 +#define ME4000_CNT_CTRL_BIT_COUNTER_2 0x80
6545 +#define ME4000_CNT_CTRL_BIT_MODE_0 0x00 // Change state if zero crossing
6546 +#define ME4000_CNT_CTRL_BIT_MODE_1 0x02 // Retriggerable One-Shot
6547 +#define ME4000_CNT_CTRL_BIT_MODE_2 0x04 // Asymmetrical divider
6548 +#define ME4000_CNT_CTRL_BIT_MODE_3 0x06 // Symmetrical divider
6549 +#define ME4000_CNT_CTRL_BIT_MODE_4 0x08 // Counter start by software trigger
6550 +#define ME4000_CNT_CTRL_BIT_MODE_5 0x0A // Counter start by hardware trigger
6552 +/*=============================================================================
6553 + Extract information from minor device number
6554 + ===========================================================================*/
6556 +#define AO_BOARD(dev) ((MINOR(dev) >> 6) & 0x3)
6557 +#define AO_PORT(dev) ((MINOR(dev) >> 2) & 0xF)
6558 +#define AO_MODE(dev) (MINOR(dev) & 0x3)
6560 +#define AI_BOARD(dev) ((MINOR(dev) >> 3) & 0x1F)
6561 +#define AI_MODE(dev) (MINOR(dev) & 0x7)
6563 +#define DIO_BOARD(dev) (MINOR(dev))
6565 +#define CNT_BOARD(dev) (MINOR(dev))
6567 +#define EXT_INT_BOARD(dev) (MINOR(dev))
6569 +/*=============================================================================
6570 + Circular buffer used for analog input/output reads/writes.
6571 + ===========================================================================*/
6573 +typedef struct me4000_circ_buf {
6575 + int volatile head;
6576 + int volatile tail;
6577 +} me4000_circ_buf_t;
6579 +/*=============================================================================
6580 + Information about the hardware capabilities
6581 + ===========================================================================*/
6583 +typedef struct me4000_ao_info {
6586 +} me4000_ao_info_t;
6588 +typedef struct me4000_ai_info {
6592 + int ex_trig_analog;
6593 +} me4000_ai_info_t;
6595 +typedef struct me4000_dio_info {
6597 +} me4000_dio_info_t;
6599 +typedef struct me4000_cnt_info {
6601 +} me4000_cnt_info_t;
6603 +typedef struct me4000_board {
6606 + me4000_ao_info_t ao;
6607 + me4000_ai_info_t ai;
6608 + me4000_dio_info_t dio;
6609 + me4000_cnt_info_t cnt;
6612 +static me4000_board_t me4000_boards[] = {
6613 + {PCI_VENDOR_ID_MEILHAUS, 0x4610, {0, 0}, {16, 0, 0, 0}, {4}, {3}},
6615 + {PCI_VENDOR_ID_MEILHAUS, 0x4650, {0, 0}, {16, 0, 0, 0}, {4}, {0}},
6617 + {PCI_VENDOR_ID_MEILHAUS, 0x4660, {2, 0}, {16, 0, 0, 0}, {4}, {3}},
6618 + {PCI_VENDOR_ID_MEILHAUS, 0x4661, {2, 0}, {16, 0, 0, 0}, {4}, {3}},
6619 + {PCI_VENDOR_ID_MEILHAUS, 0x4662, {2, 0}, {16, 8, 0, 0}, {4}, {3}},
6620 + {PCI_VENDOR_ID_MEILHAUS, 0x4663, {2, 0}, {16, 8, 0, 0}, {4}, {3}},
6622 + {PCI_VENDOR_ID_MEILHAUS, 0x4670, {4, 0}, {32, 0, 16, 1}, {4}, {3}},
6623 + {PCI_VENDOR_ID_MEILHAUS, 0x4671, {4, 0}, {32, 0, 16, 1}, {4}, {3}},
6624 + {PCI_VENDOR_ID_MEILHAUS, 0x4672, {4, 0}, {32, 8, 16, 1}, {4}, {3}},
6625 + {PCI_VENDOR_ID_MEILHAUS, 0x4673, {4, 0}, {32, 8, 16, 1}, {4}, {3}},
6627 + {PCI_VENDOR_ID_MEILHAUS, 0x4680, {4, 4}, {32, 0, 16, 1}, {4}, {3}},
6628 + {PCI_VENDOR_ID_MEILHAUS, 0x4681, {4, 4}, {32, 0, 16, 1}, {4}, {3}},
6629 + {PCI_VENDOR_ID_MEILHAUS, 0x4682, {4, 4}, {32, 8, 16, 1}, {4}, {3}},
6630 + {PCI_VENDOR_ID_MEILHAUS, 0x4683, {4, 4}, {32, 8, 16, 1}, {4}, {3}},
6635 +#define ME4000_BOARD_VERSIONS (sizeof(me4000_boards) / sizeof(me4000_board_t) - 1)
6637 +/*=============================================================================
6639 + This is used by modprobe to translate PCI IDs to drivers.
6640 + ===========================================================================*/
6642 +static struct pci_device_id me4000_pci_table[] __devinitdata = {
6643 + {PCI_VENDOR_ID_MEILHAUS, 0x4610, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6645 + {PCI_VENDOR_ID_MEILHAUS, 0x4650, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6647 + {PCI_VENDOR_ID_MEILHAUS, 0x4660, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6648 + {PCI_VENDOR_ID_MEILHAUS, 0x4661, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6649 + {PCI_VENDOR_ID_MEILHAUS, 0x4662, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6650 + {PCI_VENDOR_ID_MEILHAUS, 0x4663, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6652 + {PCI_VENDOR_ID_MEILHAUS, 0x4670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6653 + {PCI_VENDOR_ID_MEILHAUS, 0x4671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6654 + {PCI_VENDOR_ID_MEILHAUS, 0x4672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6655 + {PCI_VENDOR_ID_MEILHAUS, 0x4673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6657 + {PCI_VENDOR_ID_MEILHAUS, 0x4680, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6658 + {PCI_VENDOR_ID_MEILHAUS, 0x4681, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6659 + {PCI_VENDOR_ID_MEILHAUS, 0x4682, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6660 + {PCI_VENDOR_ID_MEILHAUS, 0x4683, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
6665 +MODULE_DEVICE_TABLE(pci, me4000_pci_table);
6667 +/*=============================================================================
6668 + Global board and subdevice information structures
6669 + ===========================================================================*/
6671 +typedef struct me4000_info {
6672 + struct list_head list; // List of all detected boards
6673 + int board_count; // Index of the board after detection
6675 + unsigned long plx_regbase; // PLX configuration space base address
6676 + unsigned long me4000_regbase; // Base address of the ME4000
6677 + unsigned long timer_regbase; // Base address of the timer circuit
6678 + unsigned long program_regbase; // Base address to set the program pin for the xilinx
6680 + unsigned long plx_regbase_size; // PLX register set space
6681 + unsigned long me4000_regbase_size; // ME4000 register set space
6682 + unsigned long timer_regbase_size; // Timer circuit register set space
6683 + unsigned long program_regbase_size; // Size of program base address of the ME4000
6685 + unsigned int serial_no; // Serial number of the board
6686 + unsigned char hw_revision; // Hardware revision of the board
6687 + unsigned short vendor_id; // Meilhaus vendor id (0x1402)
6688 + unsigned short device_id; // Device ID
6690 + int pci_bus_no; // PCI bus number
6691 + int pci_dev_no; // PCI device number
6692 + int pci_func_no; // PCI function number
6693 + struct pci_dev *pci_dev_p; // General PCI information
6695 + me4000_board_t *board_p; // Holds the board capabilities
6697 + unsigned int irq; // IRQ assigned from the PCI BIOS
6698 + unsigned int irq_count; // Count of external interrupts
6700 + spinlock_t preload_lock; // Guards the analog output preload register
6701 + spinlock_t ai_ctrl_lock; // Guards the analog input control register
6703 + struct list_head ao_context_list; // List with analog output specific context
6704 + struct me4000_ai_context *ai_context; // Analog input specific context
6705 + struct me4000_dio_context *dio_context; // Digital I/O specific context
6706 + struct me4000_cnt_context *cnt_context; // Counter specific context
6707 + struct me4000_ext_int_context *ext_int_context; // External interrupt specific context
6710 +typedef struct me4000_ao_context {
6711 + struct list_head list; // linked list of me4000_ao_context_t
6712 + int index; // Index in the list
6713 + int mode; // Indicates mode (0 = single, 1 = wraparound, 2 = continous)
6714 + int dac_in_use; // Indicates if already opend
6715 + spinlock_t use_lock; // Guards in_use
6716 + spinlock_t int_lock; // Used when locking out interrupts
6717 + me4000_circ_buf_t circ_buf; // Circular buffer
6718 + wait_queue_head_t wait_queue; // Wait queue to sleep while blocking write
6719 + me4000_info_t *board_info;
6720 + unsigned int irq; // The irq associated with this ADC
6721 + int volatile pipe_flag; // Indicates broken pipe set from me4000_ao_isr()
6722 + unsigned long ctrl_reg;
6723 + unsigned long status_reg;
6724 + unsigned long fifo_reg;
6725 + unsigned long single_reg;
6726 + unsigned long timer_reg;
6727 + unsigned long irq_status_reg;
6728 + unsigned long preload_reg;
6729 + struct fasync_struct *fasync_p; // Queue for asynchronous notification
6730 +} me4000_ao_context_t;
6732 +typedef struct me4000_ai_context {
6733 + struct list_head list; // linked list of me4000_ai_info_t
6734 + int mode; // Indicates mode
6735 + int in_use; // Indicates if already opend
6736 + spinlock_t use_lock; // Guards in_use
6737 + spinlock_t int_lock; // Used when locking out interrupts
6738 + int number; // Number of the DAC
6739 + unsigned int irq; // The irq associated with this ADC
6740 + me4000_circ_buf_t circ_buf; // Circular buffer
6741 + wait_queue_head_t wait_queue; // Wait queue to sleep while blocking read
6742 + me4000_info_t *board_info;
6744 + struct fasync_struct *fasync_p; // Queue for asynchronous notification
6746 + unsigned long ctrl_reg;
6747 + unsigned long status_reg;
6748 + unsigned long channel_list_reg;
6749 + unsigned long data_reg;
6750 + unsigned long chan_timer_reg;
6751 + unsigned long chan_pre_timer_reg;
6752 + unsigned long scan_timer_low_reg;
6753 + unsigned long scan_timer_high_reg;
6754 + unsigned long scan_pre_timer_low_reg;
6755 + unsigned long scan_pre_timer_high_reg;
6756 + unsigned long start_reg;
6757 + unsigned long irq_status_reg;
6758 + unsigned long sample_counter_reg;
6760 + unsigned long chan_timer;
6761 + unsigned long chan_pre_timer;
6762 + unsigned long scan_timer_low;
6763 + unsigned long scan_timer_high;
6764 + unsigned long channel_list_count;
6765 + unsigned long sample_counter;
6766 + int sample_counter_reload;
6767 +} me4000_ai_context_t;
6769 +typedef struct me4000_dio_context {
6770 + struct list_head list; // linked list of me4000_dio_context_t
6771 + int in_use; // Indicates if already opend
6772 + spinlock_t use_lock; // Guards in_use
6775 + me4000_info_t *board_info;
6776 + unsigned long dir_reg;
6777 + unsigned long ctrl_reg;
6778 + unsigned long port_0_reg;
6779 + unsigned long port_1_reg;
6780 + unsigned long port_2_reg;
6781 + unsigned long port_3_reg;
6782 +} me4000_dio_context_t;
6784 +typedef struct me4000_cnt_context {
6785 + struct list_head list; // linked list of me4000_dio_context_t
6786 + int in_use; // Indicates if already opend
6787 + spinlock_t use_lock; // Guards in_use
6790 + me4000_info_t *board_info;
6791 + unsigned long ctrl_reg;
6792 + unsigned long counter_0_reg;
6793 + unsigned long counter_1_reg;
6794 + unsigned long counter_2_reg;
6795 +} me4000_cnt_context_t;
6797 +typedef struct me4000_ext_int_context {
6798 + struct list_head list; // linked list of me4000_dio_context_t
6799 + int in_use; // Indicates if already opend
6800 + spinlock_t use_lock; // Guards in_use
6802 + me4000_info_t *board_info;
6804 + unsigned long int_count;
6805 + struct fasync_struct *fasync_ptr;
6806 + unsigned long ctrl_reg;
6807 + unsigned long irq_status_reg;
6808 +} me4000_ext_int_context_t;
6812 +/*=============================================================================
6813 + Application include section starts here
6814 + ===========================================================================*/
6816 +/*-----------------------------------------------------------------------------
6817 + Defines for analog input
6818 + ----------------------------------------------------------------------------*/
6820 +/* General stuff */
6821 +#define ME4000_AI_FIFO_COUNT 2048
6823 +#define ME4000_AI_MIN_TICKS 66
6824 +#define ME4000_AI_MAX_SCAN_TICKS 0xFFFFFFFFFFLL
6826 +#define ME4000_AI_BUFFER_SIZE (32 * 1024) // Size in bytes
6828 +#define ME4000_AI_BUFFER_COUNT ((ME4000_AI_BUFFER_SIZE) / 2) // Size in values
6830 +/* Channel list defines and masks */
6831 +#define ME4000_AI_CHANNEL_LIST_COUNT 1024
6833 +#define ME4000_AI_LIST_INPUT_SINGLE_ENDED 0x000
6834 +#define ME4000_AI_LIST_INPUT_DIFFERENTIAL 0x020
6836 +#define ME4000_AI_LIST_RANGE_BIPOLAR_10 0x000
6837 +#define ME4000_AI_LIST_RANGE_BIPOLAR_2_5 0x040
6838 +#define ME4000_AI_LIST_RANGE_UNIPOLAR_10 0x080
6839 +#define ME4000_AI_LIST_RANGE_UNIPOLAR_2_5 0x0C0
6841 +#define ME4000_AI_LIST_LAST_ENTRY 0x100
6843 +/* External trigger defines */
6844 +#define ME4000_AI_TRIGGER_SOFTWARE 0x0 // Use only with API
6845 +#define ME4000_AI_TRIGGER_EXT_DIGITAL 0x1
6846 +#define ME4000_AI_TRIGGER_EXT_ANALOG 0x2
6848 +#define ME4000_AI_TRIGGER_EXT_EDGE_RISING 0x0
6849 +#define ME4000_AI_TRIGGER_EXT_EDGE_FALLING 0x1
6850 +#define ME4000_AI_TRIGGER_EXT_EDGE_BOTH 0x2
6852 +/* Sample and Hold */
6853 +#define ME4000_AI_SIMULTANEOUS_DISABLE 0x0
6854 +#define ME4000_AI_SIMULTANEOUS_ENABLE 0x1
6856 +/* Defines for the Sample Counter */
6857 +#define ME4000_AI_SC_RELOAD 0x0
6858 +#define ME4000_AI_SC_ONCE 0x1
6860 +/* Modes for analog input */
6861 +#define ME4000_AI_ACQ_MODE_SINGLE 0x00 // Catch one single value
6862 +#define ME4000_AI_ACQ_MODE_SOFTWARE 0x01 // Continous sampling with software start
6863 +#define ME4000_AI_ACQ_MODE_EXT 0x02 // Continous sampling with external trigger start
6864 +#define ME4000_AI_ACQ_MODE_EXT_SINGLE_VALUE 0x03 // Sample one value by external trigger
6865 +#define ME4000_AI_ACQ_MODE_EXT_SINGLE_CHANLIST 0x04 // Sample one channel list by external trigger
6867 +/* Staus of AI FSM */
6868 +#define ME4000_AI_STATUS_IDLE 0x0
6869 +#define ME4000_AI_STATUS_BUSY 0x1
6871 +/* Voltages for calibration */
6872 +#define ME4000_AI_GAIN_1_UNI_OFFSET 10.0E-3
6873 +#define ME4000_AI_GAIN_1_UNI_FULLSCALE 9950.0E-3
6874 +#define ME4000_AI_GAIN_1_BI_OFFSET 0.0
6875 +#define ME4000_AI_GAIN_1_BI_FULLSCALE 9950.0E-3
6876 +#define ME4000_AI_GAIN_4_UNI_OFFSET 10.0E-3
6877 +#define ME4000_AI_GAIN_4_UNI_FULLSCALE 2450.0E-3
6878 +#define ME4000_AI_GAIN_4_BI_OFFSET 0.0
6879 +#define ME4000_AI_GAIN_4_BI_FULLSCALE 2450.0E-3
6881 +/* Ideal digits for calibration */
6882 +#define ME4000_AI_GAIN_1_UNI_OFFSET_DIGITS (-32702)
6883 +#define ME4000_AI_GAIN_1_UNI_FULLSCALE_DIGITS 32440
6884 +#define ME4000_AI_GAIN_1_BI_OFFSET_DIGITS 0
6885 +#define ME4000_AI_GAIN_1_BI_FULLSCALE_DIGITS 32604
6886 +#define ME4000_AI_GAIN_4_UNI_OFFSET_DIGITS (-32505)
6887 +#define ME4000_AI_GAIN_4_UNI_FULLSCALE_DIGITS 31457
6888 +#define ME4000_AI_GAIN_4_BI_OFFSET_DIGITS 0
6889 +#define ME4000_AI_GAIN_4_BI_FULLSCALE_DIGITS 32113
6891 +/*-----------------------------------------------------------------------------
6892 + Defines for analog output
6893 + ----------------------------------------------------------------------------*/
6895 +/* General stuff */
6896 +#define ME4000_AO_FIFO_COUNT (4 * 1024)
6898 +#define ME4000_AO_MIN_TICKS 66
6900 +#define ME4000_AO_BUFFER_SIZE (32 * 1024) // Size in bytes
6902 +#define ME4000_AO_BUFFER_COUNT ((ME4000_AO_BUFFER_SIZE) / 2) // Size in values
6904 +/* Conversion modes for analog output */
6905 +#define ME4000_AO_CONV_MODE_SINGLE 0x0
6906 +#define ME4000_AO_CONV_MODE_WRAPAROUND 0x1
6907 +#define ME4000_AO_CONV_MODE_CONTINUOUS 0x2
6909 +/* Trigger setup */
6910 +#define ME4000_AO_TRIGGER_EXT_EDGE_RISING 0x0
6911 +#define ME4000_AO_TRIGGER_EXT_EDGE_FALLING 0x1
6912 +#define ME4000_AO_TRIGGER_EXT_EDGE_BOTH 0x2
6914 +/* Status of AO FSM */
6915 +#define ME4000_AO_STATUS_IDLE 0x0
6916 +#define ME4000_AO_STATUS_BUSY 0x1
6918 +/*-----------------------------------------------------------------------------
6919 + Defines for eeprom
6920 + ----------------------------------------------------------------------------*/
6922 +#define ME4000_EEPROM_CMD_READ 0x180
6923 +#define ME4000_EEPROM_CMD_WRITE_ENABLE 0x130
6924 +#define ME4000_EEPROM_CMD_WRITE_DISABLE 0x100
6925 +#define ME4000_EEPROM_CMD_WRITE 0x1400000
6927 +#define ME4000_EEPROM_CMD_LENGTH_READ 9
6928 +#define ME4000_EEPROM_CMD_LENGTH_WRITE_ENABLE 9
6929 +#define ME4000_EEPROM_CMD_LENGTH_WRITE_DISABLE 9
6930 +#define ME4000_EEPROM_CMD_LENGTH_WRITE 25
6932 +#define ME4000_EEPROM_ADR_DATE_HIGH 0x32
6933 +#define ME4000_EEPROM_ADR_DATE_LOW 0x33
6935 +#define ME4000_EEPROM_ADR_GAIN_1_UNI_OFFSET 0x34
6936 +#define ME4000_EEPROM_ADR_GAIN_1_UNI_FULLSCALE 0x35
6937 +#define ME4000_EEPROM_ADR_GAIN_1_BI_OFFSET 0x36
6938 +#define ME4000_EEPROM_ADR_GAIN_1_BI_FULLSCALE 0x37
6939 +#define ME4000_EEPROM_ADR_GAIN_1_DIFF_OFFSET 0x38
6940 +#define ME4000_EEPROM_ADR_GAIN_1_DIFF_FULLSCALE 0x39
6942 +#define ME4000_EEPROM_ADR_GAIN_4_UNI_OFFSET 0x3A
6943 +#define ME4000_EEPROM_ADR_GAIN_4_UNI_FULLSCALE 0x3B
6944 +#define ME4000_EEPROM_ADR_GAIN_4_BI_OFFSET 0x3C
6945 +#define ME4000_EEPROM_ADR_GAIN_4_BI_FULLSCALE 0x3D
6946 +#define ME4000_EEPROM_ADR_GAIN_4_DIFF_OFFSET 0x3E
6947 +#define ME4000_EEPROM_ADR_GAIN_4_DIFF_FULLSCALE 0x3F
6949 +#define ME4000_EEPROM_ADR_LENGTH 6
6950 +#define ME4000_EEPROM_DATA_LENGTH 16
6952 +/*-----------------------------------------------------------------------------
6953 + Defines for digital I/O
6954 + ----------------------------------------------------------------------------*/
6956 +#define ME4000_DIO_PORT_A 0x0
6957 +#define ME4000_DIO_PORT_B 0x1
6958 +#define ME4000_DIO_PORT_C 0x2
6959 +#define ME4000_DIO_PORT_D 0x3
6961 +#define ME4000_DIO_PORT_INPUT 0x0
6962 +#define ME4000_DIO_PORT_OUTPUT 0x1
6963 +#define ME4000_DIO_FIFO_LOW 0x2
6964 +#define ME4000_DIO_FIFO_HIGH 0x3
6966 +#define ME4000_DIO_FUNCTION_PATTERN 0x0
6967 +#define ME4000_DIO_FUNCTION_DEMUX 0x1
6968 +#define ME4000_DIO_FUNCTION_MUX 0x2
6970 +/*-----------------------------------------------------------------------------
6971 + Defines for counters
6972 + ----------------------------------------------------------------------------*/
6974 +#define ME4000_CNT_COUNTER_0 0
6975 +#define ME4000_CNT_COUNTER_1 1
6976 +#define ME4000_CNT_COUNTER_2 2
6978 +#define ME4000_CNT_MODE_0 0 // Change state if zero crossing
6979 +#define ME4000_CNT_MODE_1 1 // Retriggerable One-Shot
6980 +#define ME4000_CNT_MODE_2 2 // Asymmetrical divider
6981 +#define ME4000_CNT_MODE_3 3 // Symmetrical divider
6982 +#define ME4000_CNT_MODE_4 4 // Counter start by software trigger
6983 +#define ME4000_CNT_MODE_5 5 // Counter start by hardware trigger
6985 +/*-----------------------------------------------------------------------------
6986 + General type definitions
6987 + ----------------------------------------------------------------------------*/
6989 +typedef struct me4000_user_info {
6990 + int board_count; // Index of the board after detection
6991 + unsigned long plx_regbase; // PLX configuration space base address
6992 + unsigned long me4000_regbase; // Base address of the ME4000
6993 + unsigned long plx_regbase_size; // PLX register set space
6994 + unsigned long me4000_regbase_size; // ME4000 register set space
6995 + unsigned long serial_no; // Serial number of the board
6996 + unsigned char hw_revision; // Hardware revision of the board
6997 + unsigned short vendor_id; // Meilhaus vendor id (0x1402)
6998 + unsigned short device_id; // Device ID
6999 + int pci_bus_no; // PCI bus number
7000 + int pci_dev_no; // PCI device number
7001 + int pci_func_no; // PCI function number
7002 + char irq; // IRQ assigned from the PCI BIOS
7003 + int irq_count; // Count of external interrupts
7005 + int driver_version; // Version of the driver release
7007 + int ao_count; // Count of analog output channels
7008 + int ao_fifo_count; // Count fo analog output fifos
7010 + int ai_count; // Count of analog input channels
7011 + int ai_sh_count; // Count of sample and hold devices
7012 + int ai_ex_trig_analog; // Flag to indicate if analogous external trigger is available
7014 + int dio_count; // Count of digital I/O ports
7016 + int cnt_count; // Count of counters
7017 +} me4000_user_info_t;
7019 +/*-----------------------------------------------------------------------------
7020 + Type definitions for analog output
7021 + ----------------------------------------------------------------------------*/
7023 +typedef struct me4000_ao_channel_list {
7024 + unsigned long count;
7025 + unsigned long *list;
7026 +} me4000_ao_channel_list_t;
7028 +/*-----------------------------------------------------------------------------
7029 + Type definitions for analog input
7030 + ----------------------------------------------------------------------------*/
7032 +typedef struct me4000_ai_channel_list {
7033 + unsigned long count;
7034 + unsigned long *list;
7035 +} me4000_ai_channel_list_t;
7037 +typedef struct me4000_ai_timer {
7038 + unsigned long pre_chan;
7039 + unsigned long chan;
7040 + unsigned long scan_low;
7041 + unsigned long scan_high;
7042 +} me4000_ai_timer_t;
7044 +typedef struct me4000_ai_config {
7045 + me4000_ai_timer_t timer;
7046 + me4000_ai_channel_list_t channel_list;
7048 +} me4000_ai_config_t;
7050 +typedef struct me4000_ai_single {
7055 + unsigned long timeout;
7056 +} me4000_ai_single_t;
7058 +typedef struct me4000_ai_trigger {
7061 +} me4000_ai_trigger_t;
7063 +typedef struct me4000_ai_sc {
7064 + unsigned long value;
7068 +/*-----------------------------------------------------------------------------
7069 + Type definitions for eeprom
7070 + ----------------------------------------------------------------------------*/
7072 +typedef struct me4000_eeprom {
7073 + unsigned long date;
7074 + short uni_10_offset;
7075 + short uni_10_fullscale;
7076 + short uni_2_5_offset;
7077 + short uni_2_5_fullscale;
7078 + short bi_10_offset;
7079 + short bi_10_fullscale;
7080 + short bi_2_5_offset;
7081 + short bi_2_5_fullscale;
7082 + short diff_10_offset;
7083 + short diff_10_fullscale;
7084 + short diff_2_5_offset;
7085 + short diff_2_5_fullscale;
7088 +/*-----------------------------------------------------------------------------
7089 + Type definitions for digital I/O
7090 + ----------------------------------------------------------------------------*/
7092 +typedef struct me4000_dio_config {
7096 +} me4000_dio_config_t;
7098 +typedef struct me4000_dio_byte {
7100 + unsigned char byte;
7101 +} me4000_dio_byte_t;
7103 +/*-----------------------------------------------------------------------------
7104 + Type definitions for counters
7105 + ----------------------------------------------------------------------------*/
7107 +typedef struct me4000_cnt {
7109 + unsigned short value;
7112 +typedef struct me4000_cnt_config {
7115 +} me4000_cnt_config_t;
7117 +/*-----------------------------------------------------------------------------
7118 + Type definitions for external interrupt
7119 + ----------------------------------------------------------------------------*/
7126 +/*-----------------------------------------------------------------------------
7127 + The ioctls of the board
7128 + ----------------------------------------------------------------------------*/
7130 +#define ME4000_IOCTL_MAXNR 50
7131 +#define ME4000_MAGIC 'y'
7132 +#define ME4000_GET_USER_INFO _IOR (ME4000_MAGIC, 0, me4000_user_info_t)
7134 +#define ME4000_AO_START _IOW (ME4000_MAGIC, 1, unsigned long)
7135 +#define ME4000_AO_STOP _IO (ME4000_MAGIC, 2)
7136 +#define ME4000_AO_IMMEDIATE_STOP _IO (ME4000_MAGIC, 3)
7137 +#define ME4000_AO_RESET _IO (ME4000_MAGIC, 4)
7138 +#define ME4000_AO_PRELOAD _IO (ME4000_MAGIC, 5)
7139 +#define ME4000_AO_PRELOAD_UPDATE _IO (ME4000_MAGIC, 6)
7140 +#define ME4000_AO_EX_TRIG_ENABLE _IO (ME4000_MAGIC, 7)
7141 +#define ME4000_AO_EX_TRIG_DISABLE _IO (ME4000_MAGIC, 8)
7142 +#define ME4000_AO_EX_TRIG_SETUP _IOW (ME4000_MAGIC, 9, int)
7143 +#define ME4000_AO_TIMER_SET_DIVISOR _IOW (ME4000_MAGIC, 10, unsigned long)
7144 +#define ME4000_AO_ENABLE_DO _IO (ME4000_MAGIC, 11)
7145 +#define ME4000_AO_DISABLE_DO _IO (ME4000_MAGIC, 12)
7146 +#define ME4000_AO_FSM_STATE _IOR (ME4000_MAGIC, 13, int)
7148 +#define ME4000_AI_SINGLE _IOR (ME4000_MAGIC, 14, me4000_ai_single_t)
7149 +#define ME4000_AI_START _IOW (ME4000_MAGIC, 15, unsigned long)
7150 +#define ME4000_AI_STOP _IO (ME4000_MAGIC, 16)
7151 +#define ME4000_AI_IMMEDIATE_STOP _IO (ME4000_MAGIC, 17)
7152 +#define ME4000_AI_EX_TRIG_ENABLE _IO (ME4000_MAGIC, 18)
7153 +#define ME4000_AI_EX_TRIG_DISABLE _IO (ME4000_MAGIC, 19)
7154 +#define ME4000_AI_EX_TRIG_SETUP _IOW (ME4000_MAGIC, 20, me4000_ai_trigger_t)
7155 +#define ME4000_AI_CONFIG _IOW (ME4000_MAGIC, 21, me4000_ai_config_t)
7156 +#define ME4000_AI_SC_SETUP _IOW (ME4000_MAGIC, 22, me4000_ai_sc_t)
7157 +#define ME4000_AI_FSM_STATE _IOR (ME4000_MAGIC, 23, int)
7159 +#define ME4000_DIO_CONFIG _IOW (ME4000_MAGIC, 24, me4000_dio_config_t)
7160 +#define ME4000_DIO_GET_BYTE _IOR (ME4000_MAGIC, 25, me4000_dio_byte_t)
7161 +#define ME4000_DIO_SET_BYTE _IOW (ME4000_MAGIC, 26, me4000_dio_byte_t)
7162 +#define ME4000_DIO_RESET _IO (ME4000_MAGIC, 27)
7164 +#define ME4000_CNT_READ _IOR (ME4000_MAGIC, 28, me4000_cnt_t)
7165 +#define ME4000_CNT_WRITE _IOW (ME4000_MAGIC, 29, me4000_cnt_t)
7166 +#define ME4000_CNT_CONFIG _IOW (ME4000_MAGIC, 30, me4000_cnt_config_t)
7167 +#define ME4000_CNT_RESET _IO (ME4000_MAGIC, 31)
7169 +#define ME4000_EXT_INT_DISABLE _IO (ME4000_MAGIC, 32)
7170 +#define ME4000_EXT_INT_ENABLE _IO (ME4000_MAGIC, 33)
7171 +#define ME4000_EXT_INT_COUNT _IOR (ME4000_MAGIC, 34, int)
7173 +#define ME4000_AI_OFFSET_ENABLE _IO (ME4000_MAGIC, 35)
7174 +#define ME4000_AI_OFFSET_DISABLE _IO (ME4000_MAGIC, 36)
7175 +#define ME4000_AI_FULLSCALE_ENABLE _IO (ME4000_MAGIC, 37)
7176 +#define ME4000_AI_FULLSCALE_DISABLE _IO (ME4000_MAGIC, 38)
7178 +#define ME4000_AI_EEPROM_READ _IOR (ME4000_MAGIC, 39, me4000_eeprom_t)
7179 +#define ME4000_AI_EEPROM_WRITE _IOW (ME4000_MAGIC, 40, me4000_eeprom_t)
7181 +#define ME4000_AO_SIMULTANEOUS_EX_TRIG _IO (ME4000_MAGIC, 41)
7182 +#define ME4000_AO_SIMULTANEOUS_SW _IO (ME4000_MAGIC, 42)
7183 +#define ME4000_AO_SIMULTANEOUS_DISABLE _IO (ME4000_MAGIC, 43)
7184 +#define ME4000_AO_SIMULTANEOUS_UPDATE _IOW (ME4000_MAGIC, 44, me4000_ao_channel_list_t)
7186 +#define ME4000_AO_SYNCHRONOUS_EX_TRIG _IO (ME4000_MAGIC, 45)
7187 +#define ME4000_AO_SYNCHRONOUS_SW _IO (ME4000_MAGIC, 46)
7188 +#define ME4000_AO_SYNCHRONOUS_DISABLE _IO (ME4000_MAGIC, 47)
7190 +#define ME4000_AO_EX_TRIG_TIMEOUT _IOW (ME4000_MAGIC, 48, unsigned long)
7191 +#define ME4000_AO_GET_FREE_BUFFER _IOR (ME4000_MAGIC, 49, unsigned long)
7193 +#define ME4000_AI_GET_COUNT_BUFFER _IOR (ME4000_MAGIC, 50, unsigned long)