Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Copyright 1996,2002,2005 Gregory D. Hager, Alfred A. Rizzi, Noah J. Cowan, |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 4 | Jason Lapenta, Scott Smedley |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 5 | |
| 6 | This file is part of the DT3155 Device Driver. |
| 7 | |
| 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. |
| 12 | |
| 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. |
| 17 | |
| 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, |
| 21 | MA 02111-1307 USA |
| 22 | |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 23 | -- Changes -- |
| 24 | |
| 25 | Date Programmer Description of changes made |
| 26 | ------------------------------------------------------------------- |
| 27 | 03-Jul-2000 JML n/a |
| 28 | 10-Oct-2001 SS port to 2.4 kernel. |
| 29 | 24-Jul-2002 SS remove unused code & added GPL licence. |
| 30 | 05-Aug-2005 SS port to 2.6 kernel; make CCIR mode default. |
| 31 | |
| 32 | */ |
| 33 | |
| 34 | #ifndef _DT3155_INC |
| 35 | #define _DT3155_INC |
| 36 | |
| 37 | #ifdef __KERNEL__ |
Greg Kroah-Hartman | dcff74c | 2010-02-09 12:41:38 -0800 | [diff] [blame] | 38 | #include <linux/types.h> |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 39 | #include <linux/time.h> /* struct timeval */ |
| 40 | #else |
| 41 | #include <sys/ioctl.h> |
| 42 | #include <sys/param.h> |
| 43 | #include <sys/time.h> |
| 44 | #include <unistd.h> |
| 45 | #endif |
| 46 | |
| 47 | |
| 48 | #define TRUE 1 |
| 49 | #define FALSE 0 |
| 50 | |
| 51 | /* Uncomment this for 50Hz CCIR */ |
| 52 | #define CCIR 1 |
| 53 | |
| 54 | /* Can be 1 or 2 */ |
| 55 | #define MAXBOARDS 1 |
| 56 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 57 | #define BOARD_MAX_BUFFS 3 |
| 58 | #define MAXBUFFERS (BOARD_MAX_BUFFS*MAXBOARDS) |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 59 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 60 | #define PCI_PAGE_SIZE (1 << 12) |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 61 | |
| 62 | #ifdef CCIR |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 63 | #define DT3155_MAX_ROWS 576 |
| 64 | #define DT3155_MAX_COLS 768 |
| 65 | #define FORMAT50HZ TRUE |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 66 | #else |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 67 | #define DT3155_MAX_ROWS 480 |
| 68 | #define DT3155_MAX_COLS 640 |
| 69 | #define FORMAT50HZ FALSE |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | /* Configuration structure */ |
| 73 | struct dt3155_config_s { |
Greg Kroah-Hartman | dcff74c | 2010-02-09 12:41:38 -0800 | [diff] [blame] | 74 | u32 acq_mode; |
| 75 | u32 cols, rows; |
| 76 | u32 continuous; |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | |
| 80 | /* hold data for each frame */ |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 81 | typedef struct { |
H Hartley Sweeten | 3a8954e | 2010-02-26 17:58:07 -0700 | [diff] [blame] | 82 | u32 addr; /* address of the buffer with the frame */ |
| 83 | u32 tag; /* unique number for the frame */ |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 84 | struct timeval time; /* time that capture took place */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 85 | } frame_info_t; |
| 86 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 87 | /* |
| 88 | * Structure for interrupt and buffer handling. |
| 89 | * This is the setup for 1 card |
| 90 | */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 91 | struct dt3155_fbuffer_s { |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 92 | int nbuffers; |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 93 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 94 | frame_info_t frame_info[BOARD_MAX_BUFFS]; |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 95 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 96 | int empty_buffers[BOARD_MAX_BUFFS]; /* indexes empty frames */ |
| 97 | int empty_len; /* Number of empty buffers */ |
| 98 | /* Zero means empty */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 99 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 100 | int active_buf; /* Where data is currently dma'ing */ |
| 101 | int locked_buf; /* Buffers used by user */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 102 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 103 | int ready_que[BOARD_MAX_BUFFS]; |
H Hartley Sweeten | 3a8954e | 2010-02-26 17:58:07 -0700 | [diff] [blame] | 104 | u32 ready_head; /* The most recent buffer located here */ |
| 105 | u32 ready_len; /* The number of ready buffers */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 106 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 107 | int even_happened; |
| 108 | int even_stopped; |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 109 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 110 | int stop_acquire; /* Flag to stop interrupts */ |
H Hartley Sweeten | 3a8954e | 2010-02-26 17:58:07 -0700 | [diff] [blame] | 111 | u32 frame_count; /* Counter for frames acquired by this card */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | |
| 115 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 116 | #define DT3155_MODE_FRAME 1 |
| 117 | #define DT3155_MODE_FIELD 2 |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 118 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 119 | #define DT3155_SNAP 1 |
| 120 | #define DT3155_ACQ 2 |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 121 | |
| 122 | /* There is one status structure for each card. */ |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 123 | typedef struct dt3155_status_s { |
| 124 | int fixed_mode; /* if 1, we are in fixed frame mode */ |
H Hartley Sweeten | 3a8954e | 2010-02-26 17:58:07 -0700 | [diff] [blame] | 125 | u32 reg_addr; /* Register address for a single card */ |
| 126 | u32 mem_addr; /* Buffer start addr for this card */ |
| 127 | u32 mem_size; /* This is the amount of mem available */ |
Greg Kroah-Hartman | dcff74c | 2010-02-09 12:41:38 -0800 | [diff] [blame] | 128 | u32 irq; /* this card's irq */ |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 129 | struct dt3155_config_s config; /* configuration struct */ |
| 130 | struct dt3155_fbuffer_s fbuffer; /* frame buffer state struct */ |
H Hartley Sweeten | 3a8954e | 2010-02-26 17:58:07 -0700 | [diff] [blame] | 131 | u32 state; /* this card's state */ |
Greg Kroah-Hartman | dcff74c | 2010-02-09 12:41:38 -0800 | [diff] [blame] | 132 | u32 device_installed; /* Flag if installed. 1=installed */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 133 | } dt3155_status_t; |
| 134 | |
| 135 | /* Reference to global status structure */ |
| 136 | extern struct dt3155_status_s dt3155_status[MAXBOARDS]; |
| 137 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 138 | #define DT3155_STATE_IDLE 0x00 |
| 139 | #define DT3155_STATE_FRAME 0x01 |
| 140 | #define DT3155_STATE_FLD 0x02 |
| 141 | #define DT3155_STATE_STOP 0x100 |
| 142 | #define DT3155_STATE_ERROR 0x200 |
| 143 | #define DT3155_STATE_MODE 0x0ff |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 144 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 145 | #define DT3155_IOC_MAGIC '!' |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 146 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 147 | #define DT3155_SET_CONFIG _IOW(DT3155_IOC_MAGIC, 1, struct dt3155_config_s) |
| 148 | #define DT3155_GET_CONFIG _IOR(DT3155_IOC_MAGIC, 2, struct dt3155_status_s) |
| 149 | #define DT3155_STOP _IO(DT3155_IOC_MAGIC, 3) |
| 150 | #define DT3155_START _IO(DT3155_IOC_MAGIC, 4) |
| 151 | #define DT3155_FLUSH _IO(DT3155_IOC_MAGIC, 5) |
| 152 | #define DT3155_IOC_MAXNR 5 |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 153 | |
| 154 | /* Error codes */ |
| 155 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 156 | #define DT_ERR_NO_BUFFERS 0x10000 /* not used but it might be one day */ |
| 157 | #define DT_ERR_CORRUPT 0x20000 |
| 158 | #define DT_ERR_OVERRUN 0x30000 |
| 159 | #define DT_ERR_I2C_TIMEOUT 0x40000 |
| 160 | #define DT_ERR_MASK 0xff0000/* not used but it might be one day */ |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 161 | |
| 162 | /* User code will probably want to declare one of these for each card */ |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 163 | typedef struct dt3155_read_s { |
H Hartley Sweeten | 3a8954e | 2010-02-26 17:58:07 -0700 | [diff] [blame] | 164 | u32 offset; |
| 165 | u32 frame_seq; |
| 166 | u32 state; |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 167 | |
Greg Kroah-Hartman | 8c6356e | 2009-12-22 15:19:21 -0800 | [diff] [blame] | 168 | frame_info_t frame_info; |
Scott Smedley | aa337ef | 2009-12-18 10:54:26 -0800 | [diff] [blame] | 169 | } dt3155_read_t; |
| 170 | |
| 171 | #endif /* _DT3155_inc */ |