3 Copyright 1996,2002,2005 Gregory D. Hager, Alfred A. Rizzi, Noah J. Cowan,
4 Jason Lapenta, Scott Smedley, Greg Sharp
6 This file is part of the DT3155 Device Driver.
8 The DT3155 Device Driver is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The DT3155 Device Driver is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the DT3155 Device Driver; if not, write to the Free
20 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 Date Programmer Description of changes made
26 -------------------------------------------------------------------
28 10-Oct-2001 SS port to 2.4 kernel
29 02-Apr-2002 SS Mods to use allocator as a standalone module;
30 Merged John Roll's changes (john@cfa.harvard.edu)
31 to make work with multiple boards.
32 02-Jul-2002 SS Merged James Rose's chages (rosejr@purdue.edu) to:
33 * fix successive interrupt-driven captures
34 * add select/poll support.
35 10-Jul-2002 GCS Add error check when ndevices > MAXBOARDS.
36 02-Aug-2002 GCS Fix field mode so that odd (lower) field is stored
37 in lower half of buffer.
38 05-Aug-2005 SS port to 2.6 kernel.
39 26-Oct-2009 SS port to 2.6.30 kernel.
43 ** appended "mem=124" in lilo.conf to allow for 4megs free on my 128meg system.
44 * using allocator.c and allocator.h from o'reilly book (alessandro rubini)
45 ftp://ftp.systemy.it/pub/develop (see README.allocator)
47 + might want to get rid of MAXboards for allocating initial buffer.
48 confusing and not necessary
50 + in cleanup_module the MOD_IN_USE looks like it is check after it should
52 * GFP_DMA should not be set with a PCI system (pg 291)
54 - NJC why are only two buffers allowed? (see isr, approx line 358)
58 extern void printques(int);
60 #include <linux/module.h>
61 #include <linux/interrupt.h>
62 #include <linux/pci.h>
63 #include <linux/types.h>
64 #include <linux/poll.h>
65 #include <linux/sched.h>
66 #include <linux/smp_lock.h>
69 #include <asm/uaccess.h>
72 #include "dt3155_drv.h"
73 #include "dt3155_isr.h"
74 #include "dt3155_io.h"
75 #include "allocator.h"
78 MODULE_LICENSE("GPL");
80 /* Error variable. Zero means no error. */
83 #ifndef PCI_DEVICE_ID_INTEL_7116
84 #define PCI_DEVICE_ID_INTEL_7116 0x1223
87 #define DT3155_VENDORID PCI_VENDOR_ID_INTEL
88 #define DT3155_DEVICEID PCI_DEVICE_ID_INTEL_7116
92 #define DT_3155_DEBUG_MSG(x,y) printk(x,y)
94 #define DT_3155_DEBUG_MSG(x,y)
97 /* wait queue for interrupts */
98 wait_queue_head_t dt3155_read_wait_queue[MAXBOARDS];
100 /* set to dynamicaly allocate, but it is tunable: */
101 /* insmod DT_3155 dt3155 dt3155_major=XX */
102 int dt3155_major = 0;
104 /* The minor numbers are 0 and 1 ... they are not tunable.
105 * They are used as the indices for the structure vectors,
106 * and register address vectors
109 /* Global structures and variables */
111 /* Status of each device */
112 struct dt3155_status dt3155_status[MAXBOARDS];
114 /* kernel logical address of the board */
115 static void __iomem *dt3155_lbase[MAXBOARDS] = { NULL
121 u32 dt3155_dev_open[MAXBOARDS] = {0
132 * Stops interrupt generation right away and resets the status
133 * to idle. I don't know why this works and the other way doesn't.
136 static void quick_stop (int minor)
138 struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
140 // TODO: scott was here
142 int_csr_r.reg = readl(dt3155_lbase[minor] + INT_CSR);
143 /* disable interrupts */
144 int_csr_r.fld.FLD_END_EVE_EN = 0;
145 int_csr_r.fld.FLD_END_ODD_EN = 0;
146 writel(int_csr_r.reg, dt3155_lbase[minor] + INT_CSR);
148 dt3155_status[minor].state &= ~(DT3155_STATE_STOP|0xff);
149 /* mark the system stopped: */
150 dt3155_status[minor].state |= DT3155_STATE_IDLE;
151 fb->stop_acquire = 0;
152 fb->even_stopped = 0;
154 dt3155_status[minor].state |= DT3155_STATE_STOP;
155 fb->stop_acquire = 1;
161 /*****************************************************
162 * dt3155_isr() Interrupt service routien
164 * - looks like this isr supports IRQ sharing (or could) JML
165 * - Assumes irq's are disabled, via SA_INTERRUPT flag
166 * being set in request_irq() call from init_module()
167 *****************************************************/
168 static void dt3155_isr(int irq, void *dev_id, struct pt_regs *regs)
175 struct dt3155_fbuffer *fb;
177 /* find out who issued the interrupt */
178 for (index = 0; index < ndevices; index++) {
179 if(dev_id == (void*) &dt3155_status[index])
186 /* hopefully we should not get here */
187 if (minor < 0 || minor >= MAXBOARDS) {
188 printk(KERN_ERR "dt3155_isr called with invalid dev_id\n");
192 mmio = dt3155_lbase[minor];
193 fb = &dt3155_status[minor].fbuffer;
195 /* Check for corruption and set a flag if so */
196 csr1_r.reg = readl(mmio + CSR1);
198 if ((csr1_r.fld.FLD_CRPT_EVE) || (csr1_r.fld.FLD_CRPT_ODD))
200 /* TODO: this should probably stop acquisition */
201 /* and set some flags so that dt3155_read */
202 /* returns an error next time it is called */
203 dt3155_errno = DT_ERR_CORRUPT;
204 printk("dt3155: corrupt field\n");
208 int_csr_r.reg = readl(mmio + INT_CSR);
210 /* Handle the even field ... */
211 if (int_csr_r.fld.FLD_END_EVE)
213 if ((dt3155_status[minor].state & DT3155_STATE_MODE) ==
219 ReadI2C(mmio, EVEN_CSR, &i2c_even_csr.reg);
221 /* Clear the interrupt? */
222 int_csr_r.fld.FLD_END_EVE = 1;
224 /* disable the interrupt if last field */
225 if (fb->stop_acquire)
227 printk("dt3155: even stopped.\n");
228 fb->even_stopped = 1;
229 if (i2c_even_csr.fld.SNGL_EVE)
231 int_csr_r.fld.FLD_END_EVE_EN = 0;
235 i2c_even_csr.fld.SNGL_EVE = 1;
239 writel(int_csr_r.reg, mmio + INT_CSR);
241 /* Set up next DMA if we are doing FIELDS */
242 if ((dt3155_status[minor].state & DT3155_STATE_MODE) ==
245 /* GCS (Aug 2, 2002) -- In field mode, dma the odd field
246 into the lower half of the buffer */
247 const u32 stride = dt3155_status[minor].config.cols;
248 buffer_addr = fb->frame_info[fb->active_buf].addr +
249 (DT3155_MAX_ROWS / 2) * stride;
250 local_save_flags(flags);
252 wake_up_interruptible(&dt3155_read_wait_queue[minor]);
254 /* Set up the DMA address for the next field */
255 local_irq_restore(flags);
256 writel(buffer_addr, mmio + ODD_DMA_START);
259 /* Check for errors. */
260 i2c_even_csr.fld.DONE_EVE = 1;
261 if (i2c_even_csr.fld.ERROR_EVE)
262 dt3155_errno = DT_ERR_OVERRUN;
264 WriteI2C(mmio, EVEN_CSR, i2c_even_csr.reg);
266 /* Note that we actually saw an even field meaning */
267 /* that subsequent odd field complete the frame */
268 fb->even_happened = 1;
270 /* recording the time that the even field finished, this should be */
271 /* about time in the middle of the frame */
272 do_gettimeofday(&fb->frame_info[fb->active_buf].time);
276 /* ... now handle the odd field */
277 if (int_csr_r.fld.FLD_END_ODD)
279 ReadI2C(mmio, ODD_CSR, &i2c_odd_csr.reg);
281 /* Clear the interrupt? */
282 int_csr_r.fld.FLD_END_ODD = 1;
284 if (fb->even_happened ||
285 (dt3155_status[minor].state & DT3155_STATE_MODE) ==
291 if (fb->stop_acquire && fb->even_stopped)
293 printk(KERN_DEBUG "dt3155: stopping odd..\n");
294 if (i2c_odd_csr.fld.SNGL_ODD)
296 /* disable interrupts */
297 int_csr_r.fld.FLD_END_ODD_EN = 0;
298 dt3155_status[minor].state &= ~(DT3155_STATE_STOP|0xff);
300 /* mark the system stopped: */
301 dt3155_status[minor].state |= DT3155_STATE_IDLE;
302 fb->stop_acquire = 0;
303 fb->even_stopped = 0;
305 printk(KERN_DEBUG "dt3155: state is now %x\n",
306 dt3155_status[minor].state);
310 i2c_odd_csr.fld.SNGL_ODD = 1;
314 writel(int_csr_r.reg, mmio + INT_CSR);
316 /* if the odd field has been acquired, then */
317 /* change the next dma location for both fields */
318 /* and wake up the process if sleeping */
319 if (fb->even_happened ||
320 (dt3155_status[minor].state & DT3155_STATE_MODE) ==
324 local_save_flags(flags);
330 if (fb->nbuffers > 2)
332 if (!are_empty_buffers(minor))
334 /* The number of active + locked buffers is
335 * at most 2, and since there are none empty, there
336 * must be at least nbuffers-2 ready buffers.
337 * This is where we 'drop frames', oldest first. */
338 push_empty(pop_ready(minor), minor);
341 /* The ready_que can't be full, since we know
342 * there is one active buffer right now, so it's safe
343 * to push the active buf on the ready_que. */
344 push_ready(minor, fb->active_buf);
345 /* There's at least 1 empty -- make it active */
346 fb->active_buf = pop_empty(minor);
347 fb->frame_info[fb->active_buf].tag = ++unique_tag;
349 else /* nbuffers == 2, special case */
350 { /* There is 1 active buffer.
351 * If there is a locked buffer, keep the active buffer
352 * the same -- that means we drop a frame.
354 if (fb->locked_buf < 0)
356 push_ready(minor, fb->active_buf);
357 if (are_empty_buffers(minor))
359 fb->active_buf = pop_empty(minor);
362 { /* no empty or locked buffers, so use a readybuf */
363 fb->active_buf = pop_ready(minor);
372 fb->even_happened = 0;
374 wake_up_interruptible(&dt3155_read_wait_queue[minor]);
376 local_irq_restore(flags);
380 /* Set up the DMA address for the next frame/field */
381 buffer_addr = fb->frame_info[fb->active_buf].addr;
382 if ((dt3155_status[minor].state & DT3155_STATE_MODE) ==
385 writel(buffer_addr, mmio + EVEN_DMA_START);
389 writel(buffer_addr, mmio + EVEN_DMA_START);
391 writel(buffer_addr + dt3155_status[minor].config.cols,
392 mmio + ODD_DMA_START);
395 /* Do error checking */
396 i2c_odd_csr.fld.DONE_ODD = 1;
397 if (i2c_odd_csr.fld.ERROR_ODD)
398 dt3155_errno = DT_ERR_OVERRUN;
400 WriteI2C(mmio, ODD_CSR, i2c_odd_csr.reg);
404 /* If we get here, the Odd Field wasn't it either... */
405 printk("neither even nor odd. shared perhaps?\n");
408 /*****************************************************
409 * init_isr(int minor)
410 * turns on interupt generation for the card
411 * designated by "minor".
412 * It is called *only* from inside ioctl().
413 *****************************************************/
414 static void dt3155_init_isr(int minor)
416 const u32 stride = dt3155_status[minor].config.cols;
417 void __iomem *mmio = dt3155_lbase[minor];
418 struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
420 switch (dt3155_status[minor].state & DT3155_STATE_MODE)
422 case DT3155_STATE_FLD:
424 even_dma_start_r = fb->frame_info[fb->active_buf].addr;
425 even_dma_stride_r = 0;
426 odd_dma_stride_r = 0;
428 writel(even_dma_start_r, mmio + EVEN_DMA_START);
429 writel(even_dma_stride_r, mmio + EVEN_DMA_STRIDE);
430 writel(odd_dma_stride_r, mmio + ODD_DMA_STRIDE);
434 case DT3155_STATE_FRAME:
437 even_dma_start_r = fb->frame_info[fb->active_buf].addr;
438 odd_dma_start_r = even_dma_start_r + stride;
439 even_dma_stride_r = stride;
440 odd_dma_stride_r = stride;
442 writel(even_dma_start_r, mmio + EVEN_DMA_START);
443 writel(odd_dma_start_r, mmio + ODD_DMA_START);
444 writel(even_dma_stride_r, mmio + EVEN_DMA_STRIDE);
445 writel(odd_dma_stride_r, mmio + ODD_DMA_STRIDE);
450 /* 50/60 Hz should be set before this point but let's make sure it is */
453 ReadI2C(mmio, CSR2, &i2c_csr2.reg);
454 i2c_csr2.fld.HZ50 = FORMAT50HZ;
455 WriteI2C(mmio, CSR2, i2c_csr2.reg);
457 /* enable busmaster chip, clear flags */
461 * shouldn't we be concered with continuous values of
462 * DT3155_SNAP & DT3155_ACQ here? (SS)
466 csr1_r.fld.CAP_CONT_EVE = 1; /* use continuous capture bits to */
467 csr1_r.fld.CAP_CONT_ODD = 1; /* enable */
468 csr1_r.fld.FLD_DN_EVE = 1; /* writing a 1 clears flags */
469 csr1_r.fld.FLD_DN_ODD = 1;
470 csr1_r.fld.SRST = 1; /* reset - must be 1 */
471 csr1_r.fld.FIFO_EN = 1; /* fifo control - must be 1 */
472 csr1_r.fld.FLD_CRPT_EVE = 1; /* writing a 1 clears flags */
473 csr1_r.fld.FLD_CRPT_ODD = 1;
475 writel(csr1_r.reg, mmio + CSR1);
477 /* Enable interrupts at the end of each field */
480 int_csr_r.fld.FLD_END_EVE_EN = 1;
481 int_csr_r.fld.FLD_END_ODD_EN = 1;
482 int_csr_r.fld.FLD_START_EN = 0;
484 writel(int_csr_r.reg, mmio + INT_CSR);
486 /* start internal BUSY bits */
488 ReadI2C(mmio, CSR2, &i2c_csr2.reg);
489 i2c_csr2.fld.BUSY_ODD = 1;
490 i2c_csr2.fld.BUSY_EVE = 1;
491 WriteI2C(mmio, CSR2, i2c_csr2.reg);
493 /* Now its up to the interrupt routine!! */
499 /*****************************************************
502 *****************************************************/
503 static int dt3155_ioctl(struct inode *inode,
508 int minor = MINOR(inode->i_rdev); /* What device are we ioctl()'ing? */
509 void __user *up = (void __user *)arg;
510 struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
512 if (minor >= MAXBOARDS || minor < 0)
515 /* make sure it is valid command */
516 if (_IOC_NR(cmd) > DT3155_IOC_MAXNR)
518 printk("DT3155: invalid IOCTL(0x%x)\n",cmd);
519 printk("DT3155: Valid commands (0x%x), (0x%x), (0x%x), (0x%x), (0x%x)\n",
520 (unsigned int)DT3155_GET_CONFIG,
521 (unsigned int)DT3155_SET_CONFIG,
522 (unsigned int)DT3155_START,
523 (unsigned int)DT3155_STOP,
524 (unsigned int)DT3155_FLUSH);
530 case DT3155_SET_CONFIG:
532 if (dt3155_status[minor].state != DT3155_STATE_IDLE)
536 struct dt3155_config tmp;
537 if (copy_from_user(&tmp, up, sizeof(tmp)))
539 /* check for valid settings */
540 if (tmp.rows > DT3155_MAX_ROWS ||
541 tmp.cols > DT3155_MAX_COLS ||
542 (tmp.acq_mode != DT3155_MODE_FRAME &&
543 tmp.acq_mode != DT3155_MODE_FIELD) ||
544 (tmp.continuous != DT3155_SNAP &&
545 tmp.continuous != DT3155_ACQ))
549 dt3155_status[minor].config = tmp;
553 case DT3155_GET_CONFIG:
555 if (copy_to_user(up, &dt3155_status[minor],
556 sizeof(struct dt3155_status)))
560 case DT3155_FLUSH: /* Flushes the buffers -- ensures fresh data */
562 if (dt3155_status[minor].state != DT3155_STATE_IDLE)
564 return dt3155_flush(minor);
568 if (dt3155_status[minor].state & DT3155_STATE_STOP ||
572 if (dt3155_status[minor].state == DT3155_STATE_IDLE)
576 if (copy_to_user(up, &dt3155_status[minor],
577 sizeof(struct dt3155_status)))
583 if (dt3155_status[minor].state != DT3155_STATE_IDLE)
586 fb->stop_acquire = 0;
589 /* Set the MODE in the status -- we default to FRAME */
590 if (dt3155_status[minor].config.acq_mode == DT3155_MODE_FIELD)
592 dt3155_status[minor].state = DT3155_STATE_FLD;
596 dt3155_status[minor].state = DT3155_STATE_FRAME;
599 dt3155_init_isr(minor);
600 if (copy_to_user(up, &dt3155_status[minor],
601 sizeof(struct dt3155_status)))
607 printk("DT3155: invalid IOCTL(0x%x)\n",cmd);
608 printk("DT3155: Valid commands (0x%x), (0x%x), (0x%x), (0x%x), (0x%x)\n",
609 (unsigned int)DT3155_GET_CONFIG,
610 (unsigned int)DT3155_SET_CONFIG,
611 DT3155_START, DT3155_STOP, DT3155_FLUSH);
618 /*****************************************************
621 * only allow the user to mmap the registers and buffer
622 * It is quite possible that this is broken, since the
623 * addition of of the capacity for two cards!!!!!!!!
624 * It *looks* like it should work but since I'm not
625 * sure how to use it, I'm not actually sure. (NJC? ditto by SS)
626 *****************************************************/
627 static int dt3155_mmap (struct file * file, struct vm_area_struct * vma)
629 /* which device are we mmapping? */
630 int minor = MINOR(file->f_dentry->d_inode->i_rdev);
631 unsigned long offset;
632 offset = vma->vm_pgoff << PAGE_SHIFT;
634 if (offset >= __pa(high_memory) || (file->f_flags & O_SYNC))
635 vma->vm_flags |= VM_IO;
637 /* Don't try to swap out physical pages.. */
638 vma->vm_flags |= VM_RESERVED;
640 /* they are mapping the registers or the buffer */
641 if ((offset == dt3155_status[minor].reg_addr &&
642 vma->vm_end - vma->vm_start == PCI_PAGE_SIZE) ||
643 (offset == dt3155_status[minor].mem_addr &&
644 vma->vm_end - vma->vm_start == dt3155_status[minor].mem_size))
646 if (remap_pfn_range(vma,
648 offset >> PAGE_SHIFT,
649 vma->vm_end - vma->vm_start,
650 vma->vm_page_prot)) {
651 printk("DT3155: remap_page_range() failed.\n");
657 printk("DT3155: dt3155_mmap() bad call.\n");
665 /*****************************************************
668 * Our special open code.
669 * MOD_INC_USE_COUNT make sure that the driver memory is not freed
670 * while the device is in use.
671 *****************************************************/
672 static int dt3155_open(struct inode* inode, struct file* filep)
674 int minor = MINOR(inode->i_rdev); /* what device are we opening? */
675 if (dt3155_dev_open[minor]) {
676 printk ("DT3155: Already opened by another process.\n");
680 if (dt3155_status[minor].device_installed==0)
682 printk("DT3155 Open Error: No such device dt3155 minor number %d\n",
687 if (dt3155_status[minor].state != DT3155_STATE_IDLE) {
688 printk ("DT3155: Not in idle state (state = %x)\n",
689 dt3155_status[minor].state);
693 printk("DT3155: Device opened.\n");
695 dt3155_dev_open[minor] = 1 ;
699 /* Disable ALL interrupts */
701 writel(int_csr_r.reg, dt3155_lbase[minor] + INT_CSR);
703 init_waitqueue_head(&(dt3155_read_wait_queue[minor]));
709 /*****************************************************
712 * Now decrement the use count.
714 *****************************************************/
715 static int dt3155_close(struct inode *inode, struct file *filep)
719 minor = MINOR(inode->i_rdev); /* which device are we closing */
720 if (!dt3155_dev_open[minor])
722 printk("DT3155: attempt to CLOSE a not OPEN device\n");
726 dt3155_dev_open[minor] = 0;
728 if (dt3155_status[minor].state != DT3155_STATE_IDLE)
736 /*****************************************************
739 *****************************************************/
740 static ssize_t dt3155_read(struct file *filep, char __user *buf,
741 size_t count, loff_t *ppos)
743 /* which device are we reading from? */
744 int minor = MINOR(filep->f_dentry->d_inode->i_rdev);
747 struct dt3155_fbuffer *fb = &dt3155_status[minor].fbuffer;
748 struct frame_info *frame_info;
750 /* TODO: this should check the error flag and */
751 /* return an error on hardware failures */
752 if (count != sizeof(struct dt3155_read))
754 printk("DT3155 ERROR (NJC): count is not right\n");
759 /* Hack here -- I'm going to allow reading even when idle.
760 * this is so that the frames can be read after STOP has
761 * been called. Leaving it here, commented out, as a reminder
762 * for a short while to make sure there are no problems.
763 * Note that if the driver is not opened in non_blocking mode,
764 * and the device is idle, then it could sit here forever! */
766 /* if (dt3155_status[minor].state == DT3155_STATE_IDLE)*/
769 /* non-blocking reads should return if no data */
770 if (filep->f_flags & O_NDELAY)
772 if ((frame_index = dt3155_get_ready_buffer(minor)) < 0) {
773 /*printk("dt3155: no buffers available (?)\n");*/
774 /* printques(minor); */
781 * sleep till data arrives , or we get interrupted.
782 * Note that wait_event_interruptible() does not actually
783 * sleep/wait if it's condition evaluates to true upon entry.
785 wait_event_interruptible(dt3155_read_wait_queue[minor],
786 (frame_index = dt3155_get_ready_buffer(minor))
791 printk ("DT3155: read: interrupted\n");
798 frame_info = &fb->frame_info[frame_index];
800 /* make this an offset */
801 offset = frame_info->addr - dt3155_status[minor].mem_addr;
803 put_user(offset, (unsigned int __user *)buf);
805 put_user(fb->frame_count, (unsigned int __user *)buf);
807 put_user(dt3155_status[minor].state, (unsigned int __user *)buf);
809 if (copy_to_user(buf, frame_info, sizeof(*frame_info)))
812 return sizeof(struct dt3155_read);
815 static unsigned int dt3155_poll (struct file * filp, poll_table *wait)
817 int minor = MINOR(filp->f_dentry->d_inode->i_rdev);
819 if (!is_ready_buf_empty(minor))
820 return POLLIN | POLLRDNORM;
822 poll_wait (filp, &dt3155_read_wait_queue[minor], wait);
828 dt3155_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
833 ret = dt3155_ioctl(file->f_path.dentry->d_inode, file, cmd, arg);
839 /*****************************************************
840 * file operations supported by DT3155 driver
841 * needed by init_module
843 *****************************************************/
844 static struct file_operations dt3155_fops = {
846 .unlocked_ioctl = dt3155_unlocked_ioctl,
850 .release = dt3155_close
854 /*****************************************************
857 * PCI has been totally reworked in 2.1..
858 *****************************************************/
859 static int find_PCI (void)
861 struct pci_dev *pci_dev = NULL;
862 int error, pci_index = 0;
863 unsigned short rev_device;
867 while ((pci_dev = pci_get_device
868 (DT3155_VENDORID, DT3155_DEVICEID, pci_dev)) != NULL)
872 /* Is it really there? */
874 pci_read_config_word(pci_dev, PCI_CLASS_DEVICE, &rev_device)))
878 DT_3155_DEBUG_MSG("DT3155: Device number %d \n", pci_index);
880 /* Make sure the driver was compiled with enough buffers to handle
882 if (pci_index > MAXBOARDS) {
883 printk("DT3155: ERROR - found %d devices, but driver only configured "
885 "DT3155: Please change MAXBOARDS in dt3155.h\n",
886 pci_index, MAXBOARDS);
890 /* Now, just go out and make sure that this/these device(s) is/are
891 actually mapped into the kernel address space */
892 if ((error = pci_read_config_dword(pci_dev, PCI_BASE_ADDRESS_0,
895 printk("DT3155: Was not able to find device \n");
899 DT_3155_DEBUG_MSG("DT3155: Base address 0 for device is %lx \n", base);
900 dt3155_status[pci_index-1].reg_addr = base;
902 /* Remap the base address to a logical address through which we
904 dt3155_lbase[pci_index - 1] = ioremap(base, PCI_PAGE_SIZE);
905 dt3155_status[pci_index - 1].reg_addr = base;
906 DT_3155_DEBUG_MSG("DT3155: New logical address is %p \n",
907 dt3155_lbase[pci_index-1]);
908 if (!dt3155_lbase[pci_index-1])
910 printk("DT3155: Unable to remap control registers\n");
914 if ((error = pci_read_config_byte(pci_dev, PCI_INTERRUPT_LINE, &irq)))
916 printk("DT3155: Was not able to find device \n");
920 DT_3155_DEBUG_MSG("DT3155: IRQ is %d \n",irq);
921 dt3155_status[pci_index-1].irq = irq;
922 /* Set flag: kth device found! */
923 dt3155_status[pci_index-1].device_installed = 1;
924 printk("DT3155: Installing device %d w/irq %d and address %p\n",
926 dt3155_status[pci_index-1].irq,
927 dt3155_lbase[pci_index-1]);
930 ndevices = pci_index;
935 pci_dev_put(pci_dev);
939 u32 allocatorAddr = 0;
941 /*****************************************************
943 *****************************************************/
944 int init_module(void)
948 char *devname[MAXBOARDS];
950 devname[0] = "dt3155a";
952 devname[1] = "dt3155b";
955 printk("DT3155: Loading module...\n");
957 /* Register the device driver */
958 rcode = register_chrdev(dt3155_major, "dt3155", &dt3155_fops);
961 printk(KERN_INFO "DT3155: register_chrdev failed \n");
965 if(dt3155_major == 0)
966 dt3155_major = rcode; /* dynamic */
969 /* init the status variables. */
970 /* DMA memory is taken care of in setup_buffers() */
971 for (index = 0; index < MAXBOARDS; index++)
973 dt3155_status[index].config.acq_mode = DT3155_MODE_FRAME;
974 dt3155_status[index].config.continuous = DT3155_ACQ;
975 dt3155_status[index].config.cols = DT3155_MAX_COLS;
976 dt3155_status[index].config.rows = DT3155_MAX_ROWS;
977 dt3155_status[index].state = DT3155_STATE_IDLE;
979 /* find_PCI() will check if devices are installed; */
980 /* first assume they're not: */
981 dt3155_status[index].mem_addr = 0;
982 dt3155_status[index].mem_size = 0;
983 dt3155_status[index].state = DT3155_STATE_IDLE;
984 dt3155_status[index].device_installed = 0;
987 /* Now let's find the hardware. find_PCI() will set ndevices to the
988 * number of cards found in this machine. */
990 if ((rcode = find_PCI()) != 0)
992 printk("DT3155 error: find_PCI() failed to find dt3155 board(s)\n");
993 unregister_chrdev(dt3155_major, "dt3155");
998 /* Ok, time to setup the frame buffers */
999 if((rcode = dt3155_setup_buffers(&allocatorAddr)) < 0)
1001 printk("DT3155: Error: setting up buffer not large enough.");
1002 unregister_chrdev(dt3155_major, "dt3155");
1006 /* If we are this far, then there is enough RAM */
1007 /* for the buffers: Print the configuration. */
1008 for( index = 0; index < ndevices; index++)
1010 printk("DT3155: Device = %d; acq_mode = %d; "
1011 "continuous = %d; cols = %d; rows = %d;\n",
1013 dt3155_status[index].config.acq_mode,
1014 dt3155_status[index].config.continuous,
1015 dt3155_status[index].config.cols,
1016 dt3155_status[index].config.rows);
1017 printk("DT3155: m_addr = 0x%x; m_size = %ld; "
1018 "state = %d; device_installed = %d\n",
1019 dt3155_status[index].mem_addr,
1020 (long int)dt3155_status[index].mem_size,
1021 dt3155_status[index].state,
1022 dt3155_status[index].device_installed);
1025 /* Disable ALL interrupts */
1027 for( index = 0; index < ndevices; index++)
1029 writel(int_csr_r.reg, dt3155_lbase[index] + INT_CSR);
1030 if(dt3155_status[index].device_installed)
1033 * This driver *looks* like it can handle sharing interrupts,
1034 * but I can't actually test myself. I've had reports that it
1035 * DOES work so I'll enable it for now. This comment will remain
1036 * as a reminder in case any problems arise. (SS)
1038 /* in older kernels flags are: SA_SHIRQ | SA_INTERRUPT */
1039 rcode = request_irq(dt3155_status[index].irq, (void *)dt3155_isr,
1040 IRQF_SHARED | IRQF_DISABLED, devname[index],
1041 (void*) &dt3155_status[index]);
1044 printk("DT3155: minor %d request_irq failed for IRQ %d\n",
1045 index, dt3155_status[index].irq);
1046 unregister_chrdev(dt3155_major, "dt3155");
1052 printk("DT3155: finished loading\n");
1057 /*****************************************************
1058 * cleanup_module(void)
1060 *****************************************************/
1061 void cleanup_module(void)
1065 printk("DT3155: cleanup_module called\n");
1067 /* removed DMA allocated with the allocator */
1068 #ifdef STANDALONE_ALLOCATOR
1069 if (allocatorAddr != 0)
1070 allocator_free_dma(allocatorAddr);
1072 allocator_cleanup();
1075 unregister_chrdev(dt3155_major, "dt3155");
1077 for(index = 0; index < ndevices; index++)
1079 if(dt3155_status[index].device_installed == 1)
1081 printk("DT3155: Freeing irq %d for device %d\n",
1082 dt3155_status[index].irq, index);
1083 free_irq(dt3155_status[index].irq, (void*)&dt3155_status[index]);