2 Header file for the CED 1401 USB device driver for Linux
3 Copyright (C) 2010 Cambridge Electronic Design Ltd
4 Author Greg P Smith (greg@ced.co.uk)
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "ced_ioctl.h"
26 #define UINT unsigned int
29 /** Device type codes, but these don't need to be extended - a succession is assumed
30 ** These are set for usb from the bcdDevice field (suitably mangled). Future devices
31 ** will be added in order of device creation to the list, so the names here are just
32 ** to help use remember which device is which. The U14ERR_... values follow the same
33 ** pattern for modern devices.a
35 #define TYPEUNKNOWN -1 /* dont know */
36 #define TYPE1401 0 /* standard 1401 */
37 #define TYPEPLUS 1 /* 1401 plus */
38 #define TYPEU1401 2 /* u1401 */
39 #define TYPEPOWER 3 /* Power1401 */
40 #define TYPEU14012 4 /* u1401 mkII */
41 #define TYPEPOWER2 5 /* Power1401 mk II */
42 #define TYPEMICRO3 6 /* Micro1401-3 */
43 #define TYPEPOWER3 7 /* Power1401-3 */
45 /* Some useful defines of constants. DONT FORGET to change the version in the */
46 /* resources whenever you change it here!. */
47 #define DRIVERMAJREV 2 /* driver revision level major (match windows) */
48 #define DRIVERMINREV 0 /* driver revision level minor */
50 /* Definitions of the various block transfer command codes */
51 #define TM_EXTTOHOST 8 /* extended tohost */
52 #define TM_EXTTO1401 9 /* extended to1401 */
54 /* Definitions of values in usbReqtype. Used in sorting out setup actions */
62 /* Definition of values in usbRequest, again used to sort out setup */
63 #define GET_STATUS 0x00
64 #define CLEAR_FEATURE 0x01
65 #define SET_FEATURE 0x03
66 #define SET_ADDRESS 0x05
71 #define GET_INTERFACE 0x0a
72 #define SET_INTERFACE 0x0b
73 #define SYNCH_FRAME 0x0c
75 /* Definitions of the various debug command codes understood by the 1401. These */
76 /* are used in various vendor-specific commands to achieve the desired effect */
77 #define DB_GRAB 0x50 /* Grab is a NOP for USB */
78 #define DB_FREE 0x51 /* Free is a NOP for the USB */
79 #define DB_SETADD 0x52 /* Set debug address (double) */
80 #define DB_SELFTEST 0x53 /* Start self test */
81 #define DB_SETMASK 0x54 /* Set enable mask (double) */
82 #define DB_SETDEF 0x55 /* Set default mask (double) */
83 #define DB_PEEK 0x56 /* Peek address, save result */
84 #define DB_POKE 0x57 /* Poke address with data (double) */
85 #define DB_RAMPD 0x58 /* Ramp data at debug address */
86 #define DB_RAMPA 0x59 /* Ramp address bus */
87 #define DB_REPEATS 0x5A /* Set repeats for operations (double) */
88 #define DB_WIDTH 0x5B /* Set width for operations (byte) */
89 #define DB_DATA 0x5C /* Get 4-byte data read by PEEK */
90 #define DB_CHARS 0x5D /* Send chars via EP0 control write */
92 #define CR_CHAR 0x0D /* The carriage return character */
93 #define CR_CHAR_80 0x8d /* and with bit 7 set */
95 /* A structure holding information about a block */
96 /* of memory for use in circular transfers */
98 volatile UINT offset
; /* Offset within area of block start */
99 volatile UINT size
; /* Size of the block, in bytes (0 = unused) */
102 /* A structure holding all of the information about a transfer area - an area of */
103 /* memory set up for use either as a source or destination in DMA transfers. */
105 void __user
*lpvBuff
; /* User address of xfer area saved for completeness */
106 UINT dwBaseOffset
; /* offset to start of xfer area in first page */
107 UINT dwLength
; /* Length of xfer area, in bytes */
108 struct page
**pPages
; /* Points at array of locked down pages */
109 int nPages
; /* number of pages that are locked down */
110 bool bUsed
; /* Is this structure in use? */
111 bool bCircular
; /* Is this area for circular transfers? */
112 bool bCircToHost
; /* Flag for direction of circular transfer */
113 bool bEventToHost
; /* Set event on transfer to host? */
114 int iWakeUp
; /* Set 1 on event, cleared by TestEvent() */
115 UINT dwEventSt
; /* Defines section within xfer area for... */
116 UINT dwEventSz
; /* ...notification by the event SZ is 0 if unset */
117 struct circ_blk aBlocks
[2]; /* Info on a pair of circular blocks */
118 wait_queue_head_t wqEvent
; /* The wait queue for events in this area MUST BE LAST */
121 /* The DMADESC structure is used to hold information on the transfer in progress. It */
122 /* is set up by ReadDMAInfo, using information sent by the 1401 in an escape sequence. */
124 unsigned short wTransType
; /* transfer type as TM_xxx above */
125 unsigned short wIdent
; /* identifier word */
126 unsigned int dwSize
; /* bytes to transfer */
127 unsigned int dwOffset
; /* offset into transfer area for trans */
128 bool bOutWard
; /* true when data is going TO 1401 */
131 #define INBUF_SZ 256 /* input buffer size */
132 #define OUTBUF_SZ 256 /* output buffer size */
133 #define STAGED_SZ 0x10000 /* size of coherent buffer for staged transfers */
135 /* Structure to hold all of our device specific stuff. We are making this as similar as we */
136 /* can to the Windows driver to help in our understanding of what is going on. */
138 char inputBuffer
[INBUF_SZ
]; /* The two buffers */
139 char outputBuffer
[OUTBUF_SZ
]; /* accessed by the host functions */
140 volatile unsigned int dwNumInput
; /* num of chars in input buffer */
141 volatile unsigned int dwInBuffGet
; /* where to get from input buffer */
142 volatile unsigned int dwInBuffPut
; /* where to put into input buffer */
143 volatile unsigned int dwNumOutput
; /* num of chars in output buffer */
144 volatile unsigned int dwOutBuffGet
; /* where to get from output buffer*/
145 volatile unsigned int dwOutBuffPut
; /* where to put into output buffer*/
147 volatile bool bSendCharsPending
; /* Flag to indicate sendchar active */
148 volatile bool bReadCharsPending
; /* Flag to indicate a read is primed */
149 char *pCoherCharOut
; /* special aligned buffer for chars to 1401 */
150 struct urb
*pUrbCharOut
; /* urb used for chars to 1401 */
151 char *pCoherCharIn
; /* special aligned buffer for chars to host */
152 struct urb
*pUrbCharIn
; /* urb used for chars to host */
154 spinlock_t charOutLock
; /* to protect the outputBuffer and outputting */
155 spinlock_t charInLock
; /* to protect the inputBuffer and char reads */
156 __u8 bInterval
; /* Interrupt end point interval */
158 volatile unsigned int dwDMAFlag
; /* state of DMA */
159 struct transarea rTransDef
[MAX_TRANSAREAS
]; /* transfer area info */
160 volatile struct dmadesc rDMAInfo
; /* info on current DMA transfer */
161 volatile bool bXFerWaiting
; /* Flag set if DMA transfer stalled */
162 volatile bool bInDrawDown
; /* Flag that we want to halt transfers */
164 /* Parameters relating to a block read\write that is in progress. Some of these values */
165 /* are equivalent to values in rDMAInfo. The values here are those in use, while those */
166 /* in rDMAInfo are those received from the 1401 via an escape sequence. If another */
167 /* escape sequence arrives before the previous xfer ends, rDMAInfo values are updated while these */
168 /* are used to finish off the current transfer. */
169 volatile short StagedId
; /* The transfer area id for this transfer */
170 volatile bool StagedRead
; /* Flag TRUE for read from 1401, FALSE for write */
171 volatile unsigned int StagedLength
; /* Total length of this transfer */
172 volatile unsigned int StagedOffset
; /* Offset within memory area for transfer start */
173 volatile unsigned int StagedDone
; /* Bytes transferred so far */
174 volatile bool bStagedUrbPending
; /* Flag to indicate active */
175 char *pCoherStagedIO
; /* buffer used for block transfers */
176 struct urb
*pStagedUrb
; /* The URB to use */
177 spinlock_t stagedLock
; /* protects ReadWriteMem() and circular buffer stuff */
179 short s1401Type
; /* type of 1401 attached */
180 short sCurrentState
; /* current error state */
181 bool bIsUSB2
; /* type of the interface we connect to */
182 bool bForceReset
; /* Flag to make sure we get a real reset */
183 __u32 statBuf
[2]; /* buffer for 1401 state info */
185 unsigned long ulSelfTestTime
; /* used to timeout self test */
187 int nPipes
; /* Should be 3 or 4 depending on 1401 usb chip */
188 int bPipeError
[4]; /* set non-zero if an error on one of the pipe */
189 __u8 epAddr
[4]; /* addresses of the 3/4 end points */
191 struct usb_device
*udev
; /* the usb device for this device */
192 struct usb_interface
*interface
; /* the interface for this device, NULL if removed */
193 struct usb_anchor submitted
; /* in case we need to retract our submissions */
194 struct mutex io_mutex
; /* synchronize I/O with disconnect, one user-mode caller at a time */
196 int errors
; /* the last request tanked */
197 int open_count
; /* count the number of openers */
198 spinlock_t err_lock
; /* lock for errors */
202 #define to_ced_data(d) container_of(d, struct ced_data, kref)
204 /* Definitions of routimes used between compilation object files */
206 extern int ced_allowi(struct ced_data
* ced
);
207 extern int ced_send_chars(struct ced_data
*ced
);
208 extern void ced_draw_down(struct ced_data
*ced
);
209 extern int ced_read_write_mem(struct ced_data
*ced
, bool Read
, unsigned short wIdent
,
210 unsigned int dwOffs
, unsigned int dwLen
);
213 extern int ced_clear_area(struct ced_data
*ced
, int nArea
);
214 extern int ced_send_string(struct ced_data
*ced
, const char __user
*pData
, unsigned int n
);
215 extern int ced_send_char(struct ced_data
*ced
, char c
);
216 extern int ced_get_state(struct ced_data
*ced
, __u32
*state
, __u32
*error
);
217 extern int ced_read_write_cancel(struct ced_data
*ced
);
218 extern int ced_reset(struct ced_data
*ced
);
219 extern int ced_get_char(struct ced_data
*ced
);
220 extern int ced_get_string(struct ced_data
*ced
, char __user
*pUser
, int n
);
221 extern int ced_set_transfer(struct ced_data
*ced
, struct transfer_area_desc __user
*pTD
);
222 extern int ced_unset_transfer(struct ced_data
*ced
, int nArea
);
223 extern int ced_set_event(struct ced_data
*ced
, struct transfer_event __user
*pTE
);
224 extern int ced_stat_1401(struct ced_data
*ced
);
225 extern int ced_line_count(struct ced_data
*ced
);
226 extern int ced_get_out_buf_space(struct ced_data
*ced
);
227 extern int ced_get_transfer(struct ced_data
*ced
, TGET_TX_BLOCK __user
*pGTB
);
228 extern int ced_kill_io(struct ced_data
*ced
);
229 extern int ced_state_of_1401(struct ced_data
*ced
);
230 extern int ced_start_self_test(struct ced_data
*ced
);
231 extern int ced_check_self_test(struct ced_data
*ced
, TGET_SELFTEST __user
*pGST
);
232 extern int ced_type_of_1401(struct ced_data
*ced
);
233 extern int ced_transfer_flags(struct ced_data
*ced
);
234 extern int ced_dbg_peek(struct ced_data
*ced
, TDBGBLOCK __user
*pDB
);
235 extern int ced_dbg_poke(struct ced_data
*ced
, TDBGBLOCK __user
*pDB
);
236 extern int ced_dbg_ramp_data(struct ced_data
*ced
, TDBGBLOCK __user
*pDB
);
237 extern int ced_dbg_ramp_addr(struct ced_data
*ced
, TDBGBLOCK __user
*pDB
);
238 extern int ced_dbg_get_data(struct ced_data
*ced
, TDBGBLOCK __user
*pDB
);
239 extern int ced_dbg_stop_loop(struct ced_data
*ced
);
240 extern int ced_set_circular(struct ced_data
*ced
, struct transfer_area_desc __user
*pTD
);
241 extern int ced_get_circ_block(struct ced_data
*ced
, TCIRCBLOCK __user
*pCB
);
242 extern int ced_free_circ_block(struct ced_data
*ced
, TCIRCBLOCK __user
*pCB
);
243 extern int ced_wait_event(struct ced_data
*ced
, int nArea
, int msTimeOut
);
244 extern int ced_test_event(struct ced_data
*ced
, int nArea
);