Linux-libre 3.16.41-gnu
[librecmc/linux-libre.git] / drivers / staging / ced1401 / ced_ioctl.h
1 /*
2  * IOCTL calls for the CED1401 driver
3  * Copyright (C) 2010 Cambridge Electronic Design Ltd
4  * Author Greg P Smith (greg@ced.co.uk)
5  *
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.
10  *
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.
15  */
16 #ifndef __CED_IOCTL_H__
17 #define __CED_IOCTL_H__
18
19 #include <linux/ioctl.h>
20
21 /* dma modes, only MODE_CHAR and MODE_LINEAR are used in this driver */
22 #define MODE_CHAR               0
23 #define MODE_LINEAR             1
24
25 /****************************************************************************
26 ** TypeDefs
27 *****************************************************************************/
28
29 struct transfer_area_desc {
30         long long lpvBuff;      /* address of transfer area (for 64 or 32 bit) */
31         unsigned int dwLength;  /* length of the area */
32         unsigned short wAreaNum;        /* number of transfer area to set up */
33         short eSize;            /* element size - is tohost flag for circular */
34 };
35
36
37 struct transfer_event {
38         unsigned int dwStart;           /* offset into the area */
39         unsigned int dwLength;          /* length of the region */
40         unsigned short wAreaNum;        /* the area number */
41         unsigned short wFlags;          /* bit 0 set for toHost */
42         int iSetEvent;                  /* could be dummy in LINUX */
43 };
44
45 #define MAX_TRANSFER_SIZE       0x4000          /* Maximum data bytes per IRP */
46 #define MAX_AREA_LENGTH         0x100000        /* Maximum size of transfer area */
47 #define MAX_TRANSAREAS          8               /* definitions for dma set up  */
48
49 typedef struct TGetSelfTest {
50         int code;                       /* self-test error code */
51         int x, y;                       /* additional information */
52 } TGET_SELFTEST;
53
54 /* Debug block used for several commands. Not all fields are used for all commands. */
55 typedef struct TDbgBlock {
56         int iAddr;                      /* the address in the 1401 */
57         int iRepeats;                   /* number of repeats */
58         int iWidth;                     /* width in bytes 1, 2, 4 */
59         int iDefault;                   /* default value */
60         int iMask;                      /* mask to apply */
61         int iData;                      /* data for poke, result for peek */
62 } TDBGBLOCK;
63
64 /* Used to collect information about a circular block from the device driver */
65 typedef struct TCircBlock {
66         unsigned int nArea;             /* the area to collect information from */
67         unsigned int dwOffset;          /* offset into the area to the available block */
68         unsigned int dwSize;            /* size of the area */
69 } TCIRCBLOCK;
70
71 /* Used to clollect the 1401 status */
72 typedef struct TCSBlock {
73         unsigned int uiState;
74         unsigned int uiError;
75 } TCSBLOCK;
76
77 /*
78  * As seen by the user, an ioctl call looks like: int ioctl(int fd, unsigned
79  * long cmd, char* argp); We will then have all sorts of variants on this that
80  * can be used to pass stuff to our driver. We will generate macros for each
81  * type of call so as to provide some sort of type safety in the calling:
82  */
83 #define CED_MAGIC_IOC 0xce
84
85 #define IOCTL_CED_SENDSTRING(n)         _IOC(_IOC_WRITE, CED_MAGIC_IOC, 2, n)
86
87 #define IOCTL_CED_RESET1401             _IO(CED_MAGIC_IOC, 3)
88 #define IOCTL_CED_GETCHAR               _IO(CED_MAGIC_IOC, 4)
89 #define IOCTL_CED_SENDCHAR              _IO(CED_MAGIC_IOC, 5)
90 #define IOCTL_CED_STAT1401              _IO(CED_MAGIC_IOC, 6)
91 #define IOCTL_CED_LINECOUNT             _IO(CED_MAGIC_IOC, 7)
92 #define IOCTL_CED_GETSTRING(nMax)       _IOC(_IOC_READ, CED_MAGIC_IOC, 8, nMax)
93
94 #define IOCTL_CED_SETTRANSFER           _IOW(CED_MAGIC_IOC, 11, struct transfer_area_desc)
95 #define IOCTL_CED_UNSETTRANSFER         _IO(CED_MAGIC_IOC, 12)
96 #define IOCTL_CED_SETEVENT              _IOW(CED_MAGIC_IOC, 13, struct transfer_event)
97 #define IOCTL_CED_GETOUTBUFSPACE        _IO(CED_MAGIC_IOC, 14)
98 #define IOCTL_CED_GETBASEADDRESS        _IO(CED_MAGIC_IOC, 15)
99 #define IOCTL_CED_GETDRIVERREVISION     _IO(CED_MAGIC_IOC, 16)
100
101 #define IOCTL_CED_GETTRANSFER           _IOR(CED_MAGIC_IOC, 17, TGET_TX_BLOCK)
102 #define IOCTL_CED_KILLIO1401            _IO(CED_MAGIC_IOC, 18)
103 #define IOCTL_CED_BLKTRANSSTATE         _IO(CED_MAGIC_IOC, 19)
104
105 #define IOCTL_CED_STATEOF1401           _IO(CED_MAGIC_IOC, 23)
106 #define IOCTL_CED_GRAB1401              _IO(CED_MAGIC_IOC, 25)
107 #define IOCTL_CED_FREE1401              _IO(CED_MAGIC_IOC, 26)
108 #define IOCTL_CED_STARTSELFTEST         _IO(CED_MAGIC_IOC, 31)
109 #define IOCTL_CED_CHECKSELFTEST         _IOR(CED_MAGIC_IOC, 32, TGET_SELFTEST)
110 #define IOCTL_CED_TYPEOF1401            _IO(CED_MAGIC_IOC, 33)
111 #define IOCTL_CED_TRANSFERFLAGS         _IO(CED_MAGIC_IOC, 34)
112
113 #define IOCTL_CED_DBGPEEK               _IOW(CED_MAGIC_IOC, 35, TDBGBLOCK)
114 #define IOCTL_CED_DBGPOKE               _IOW(CED_MAGIC_IOC, 36, TDBGBLOCK)
115 #define IOCTL_CED_DBGRAMPDATA           _IOW(CED_MAGIC_IOC, 37, TDBGBLOCK)
116 #define IOCTL_CED_DBGRAMPADDR           _IOW(CED_MAGIC_IOC, 38, TDBGBLOCK)
117 #define IOCTL_CED_DBGGETDATA            _IOR(CED_MAGIC_IOC, 39, TDBGBLOCK)
118 #define IOCTL_CED_DBGSTOPLOOP           _IO(CED_MAGIC_IOC, 40)
119 #define IOCTL_CED_FULLRESET             _IO(CED_MAGIC_IOC, 41)
120 #define IOCTL_CED_SETCIRCULAR           _IOW(CED_MAGIC_IOC, 42, struct transfer_area_desc)
121 #define IOCTL_CED_GETCIRCBLOCK          _IOWR(CED_MAGIC_IOC, 43, TCIRCBLOCK)
122 #define IOCTL_CED_FREECIRCBLOCK         _IOWR(CED_MAGIC_IOC, 44, TCIRCBLOCK)
123 #define IOCTL_CED_WAITEVENT             _IO(CED_MAGIC_IOC, 45)
124 #define IOCTL_CED_TESTEVENT             _IO(CED_MAGIC_IOC, 46)
125
126 #ifndef __KERNEL__
127 /*
128  * If nothing said about return value, it is a U14ERR_... error code
129  * (U14ERR_NOERROR for none)
130  */
131 inline int CED_SendString(int fh, const char *szText, int n)
132 {
133         return ioctl(fh, IOCTL_CED_SENDSTRING(n), szText);
134 }
135
136 inline int CED_Reset1401(int fh)
137 {
138         return ioctl(fh, IOCTL_CED_RESET1401);
139 }
140
141 /* Return the singe character or a -ve error code. */
142 inline int CED_GetChar(int fh)
143 {
144         return ioctl(fh, IOCTL_CED_GETCHAR);
145 }
146
147 /* Return character count in input buffer */
148 inline int CED_Stat1401(int fh)
149 {
150         return ioctl(fh, IOCTL_CED_STAT1401);
151 }
152
153 inline int CED_SendChar(int fh, char c)
154 {
155         return ioctl(fh, IOCTL_CED_SENDCHAR, c);
156 }
157
158 inline int CED_LineCount(int fh)
159 {
160         return ioctl(fh, IOCTL_CED_LINECOUNT);
161 }
162
163 /*
164  * return the count of characters returned. If the string was terminated by CR
165  * or 0, then the 0 is part of the count. Otherwise, we will add a zero if
166  * there is room, but it is not included in the count.  The return value is 0
167  * if there was nothing to read.
168  */
169 inline int CED_GetString(int fh, char *szText, int nMax)
170 {
171         return ioctl(fh, IOCTL_CED_GETSTRING(nMax), szText);
172 }
173
174 /* returns space in the output buffer. */
175 inline int CED_GetOutBufSpace(int fh)
176 {
177         return ioctl(fh, IOCTL_CED_GETOUTBUFSPACE);
178 }
179
180 /* This always returns -1 as not implemented. */
181 inline int CED_GetBaseAddress(int fh)
182 {
183         return ioctl(fh, IOCTL_CED_GETBASEADDRESS);
184 }
185
186 /* returns the major revision <<16 | minor revision. */
187 inline int CED_GetDriverRevision(int fh)
188 {
189         return ioctl(fh, IOCTL_CED_GETDRIVERREVISION);
190 }
191
192 inline int CED_SetTransfer(int fh, struct transfer_area_desc *pTD)
193 {
194         return ioctl(fh, IOCTL_CED_SETTRANSFER, pTD);
195 }
196
197 inline int CED_UnsetTransfer(int fh, int nArea)
198 {
199         return ioctl(fh, IOCTL_CED_UNSETTRANSFER, nArea);
200 }
201
202 inline int CED_SetEvent(int fh, struct transfer_event *pTE)
203 {
204         return ioctl(fh, IOCTL_CED_SETEVENT, pTE);
205 }
206
207 inline int CED_GetTransfer(int fh, TGET_TX_BLOCK *pTX)
208 {
209         return ioctl(fh, IOCTL_CED_GETTRANSFER, pTX);
210 }
211
212 inline int CED_KillIO1401(int fh)
213 {
214         return ioctl(fh, IOCTL_CED_KILLIO1401);
215 }
216
217 /* returns 0 if no active DMA, 1 if active */
218 inline int CED_BlkTransState(int fh)
219 {
220         return ioctl(fh, IOCTL_CED_BLKTRANSSTATE);
221 }
222
223 inline int CED_StateOf1401(int fh)
224 {
225         return ioctl(fh, IOCTL_CED_STATEOF1401);
226 }
227
228 inline int CED_Grab1401(int fh)
229 {
230         return ioctl(fh, IOCTL_CED_GRAB1401);
231 }
232
233 inline int CED_Free1401(int fh)
234 {
235         return ioctl(fh, IOCTL_CED_FREE1401);
236 }
237
238 inline int CED_StartSelfTest(int fh)
239 {
240         return ioctl(fh, IOCTL_CED_STARTSELFTEST);
241 }
242
243 inline int CED_CheckSelfTest(int fh, TGET_SELFTEST *pGST)
244 {
245         return ioctl(fh, IOCTL_CED_CHECKSELFTEST, pGST);
246 }
247
248 inline int CED_TypeOf1401(int fh)
249 {
250         return ioctl(fh, IOCTL_CED_TYPEOF1401);
251 }
252
253 inline int CED_TransferFlags(int fh)
254 {
255         return ioctl(fh, IOCTL_CED_TRANSFERFLAGS);
256 }
257
258 inline int CED_DbgPeek(int fh, TDBGBLOCK *pDB)
259 {
260         return ioctl(fh, IOCTL_CED_DBGPEEK, pDB);
261 }
262
263 inline int CED_DbgPoke(int fh, TDBGBLOCK *pDB)
264 {
265         return ioctl(fh, IOCTL_CED_DBGPOKE, pDB);
266 }
267
268 inline int CED_DbgRampData(int fh, TDBGBLOCK *pDB)
269 {
270         return ioctl(fh, IOCTL_CED_DBGRAMPDATA, pDB);
271 }
272
273 inline int CED_DbgRampAddr(int fh, TDBGBLOCK *pDB)
274 {
275         return ioctl(fh, IOCTL_CED_DBGRAMPADDR, pDB);
276 }
277
278 inline int CED_DbgGetData(int fh, TDBGBLOCK *pDB)
279 {
280         return ioctl(fh, IOCTL_CED_DBGGETDATA, pDB);
281 }
282
283 inline int CED_DbgStopLoop(int fh)
284 {
285         return ioctl(fh, IOCTL_CED_DBGSTOPLOOP);
286 }
287
288 inline int CED_FullReset(int fh)
289 {
290         return ioctl(fh, IOCTL_CED_FULLRESET);
291 }
292
293 inline int CED_SetCircular(int fh, struct transfer_area_desc *pTD)
294 {
295         return ioctl(fh, IOCTL_CED_SETCIRCULAR, pTD);
296 }
297
298 inline int CED_GetCircBlock(int fh, TCIRCBLOCK *pCB)
299 {
300         return ioctl(fh, IOCTL_CED_GETCIRCBLOCK, pCB);
301 }
302
303 inline int CED_FreeCircBlock(int fh, TCIRCBLOCK *pCB)
304 {
305         return ioctl(fh, IOCTL_CED_FREECIRCBLOCK, pCB);
306 }
307
308 inline int CED_WaitEvent(int fh, int nArea, int msTimeOut)
309 {
310         return ioctl(fh, IOCTL_CED_WAITEVENT, (nArea & 0xff)|(msTimeOut << 8));
311 }
312
313 inline int CED_TestEvent(int fh, int nArea)
314 {
315         return ioctl(fh, IOCTL_CED_TESTEVENT, nArea);
316 }
317 #endif
318
319 #ifdef NOTWANTEDYET
320 #define IOCTL_CED_REGCALLBACK           _IO(CED_MAGIC_IOC, 9)   /* Not used */
321 #define IOCTL_CED_GETMONITORBUF         _IO(CED_MAGIC_IOC, 10)  /* Not used */
322
323 #define IOCTL_CED_BYTECOUNT             _IO(CED_MAGIC_IOC, 20)  /* Not used */
324 #define IOCTL_CED_ZEROBLOCKCOUNT        _IO(CED_MAGIC_IOC, 21)  /* Not used */
325 #define IOCTL_CED_STOPCIRCULAR          _IO(CED_MAGIC_IOC, 22)  /* Not used */
326
327 #define IOCTL_CED_REGISTERS1401         _IO(CED_MAGIC_IOC, 24)  /* Not used */
328 #define IOCTL_CED_STEP1401              _IO(CED_MAGIC_IOC, 27)  /* Not used */
329 #define IOCTL_CED_SET1401REGISTERS      _IO(CED_MAGIC_IOC, 28)  /* Not used */
330 #define IOCTL_CED_STEPTILL1401          _IO(CED_MAGIC_IOC, 29)  /* Not used */
331 #define IOCTL_CED_SETORIN               _IO(CED_MAGIC_IOC, 30)  /* Not used */
332
333 #endif
334
335 /* __CED_IOCTL_H__ */
336 #endif