]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/ced1401/usb1401.h
Merge branch 'for-3.11-cpuset' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[karo-tx-linux.git] / drivers / staging / ced1401 / usb1401.h
1 /* usb1401.h
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)
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  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.
19 */
20 #ifndef __USB1401_H__
21 #define __USB1401_H__
22 #include "use1401.h"
23 #include "ced_ioctl.h"
24
25 #ifndef UINT
26 #define UINT unsigned int
27 #endif
28
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
34 **/
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 */
44
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 */
49
50 /*  Definitions of the various block transfer command codes */
51 #define TM_EXTTOHOST    8               /*  extended tohost */
52 #define TM_EXTTO1401    9               /*  extended to1401 */
53
54 /*  Definitions of values in usbReqtype. Used in sorting out setup actions */
55 #define H_TO_D 0x00
56 #define D_TO_H 0x80
57 #define VENDOR 0x40
58 #define DEVREQ 0x00
59 #define INTREQ 0x01
60 #define ENDREQ 0x02
61
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
67 #define GET_DESC        0x06
68 #define SET_DESC        0x07
69 #define GET_CONF        0x08
70 #define SET_CONF        0x09
71 #define GET_INTERFACE   0x0a
72 #define SET_INTERFACE   0x0b
73 #define SYNCH_FRAME     0x0c
74
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 */
91
92 #define CR_CHAR          0x0D           /* The carriage return character */
93 #define CR_CHAR_80       0x8d           /*  and with bit 7 set */
94
95 /*  A structure holding information about a block of memory for use in circular transfers */
96 typedef struct circBlk {
97         volatile UINT dwOffset;             /* Offset within area of block start */
98         volatile UINT dwSize;               /* Size of the block, in bytes (0 = unused) */
99 } CIRCBLK;
100
101 /*  A structure holding all of the information about a transfer area - an area of */
102 /*   memory set up for use either as a source or destination in DMA transfers. */
103 typedef struct transarea {
104         void    *lpvBuff;                /*  User address of xfer area saved for completeness */
105         UINT        dwBaseOffset;           /*  offset to start of xfer area in first page */
106         UINT        dwLength;               /*  Length of xfer area, in bytes */
107         struct page **pPages;               /*  Points at array of locked down pages */
108         int         nPages;                 /*  number of pages that are locked down */
109         bool        bUsed;                  /*  Is this structure in use? */
110         bool        bCircular;              /*  Is this area for circular transfers? */
111         bool        bCircToHost;            /*  Flag for direction of circular transfer */
112         bool        bEventToHost;           /*  Set event on transfer to host? */
113         int         iWakeUp;                /*  Set 1 on event, cleared by TestEvent() */
114         UINT        dwEventSt;              /*  Defines section within xfer area for... */
115         UINT        dwEventSz;              /*  ...notification by the event SZ is 0 if unset */
116         CIRCBLK     aBlocks[2];             /*  Info on a pair of circular blocks */
117         wait_queue_head_t wqEvent;          /*  The wait queue for events in this area MUST BE LAST */
118 } TRANSAREA;
119
120 /*  The DMADESC structure is used to hold information on the transfer in progress. It */
121 /*  is set up by ReadDMAInfo, using information sent by the 1401 in an escape sequence. */
122 typedef struct dmadesc {
123         unsigned short wTransType;          /* transfer type as TM_xxx above        */
124         unsigned short wIdent;              /* identifier word                      */
125         unsigned int   dwSize;              /* bytes to transfer                    */
126         unsigned int   dwOffset;            /* offset into transfer area for trans  */
127         bool           bOutWard;            /* true when data is going TO 1401      */
128 } DMADESC;
129
130 #define INBUF_SZ         256            /* input buffer size */
131 #define OUTBUF_SZ        256            /* output buffer size */
132 #define STAGED_SZ 0x10000               /*  size of coherent buffer for staged transfers */
133
134 /*  Structure to hold all of our device specific stuff. We are making this as similar as we */
135 /*  can to the Windows driver to help in our understanding of what is going on. */
136 typedef struct _DEVICE_EXTENSION {
137         char inputBuffer[INBUF_SZ];         /* The two buffers */
138         char outputBuffer[OUTBUF_SZ];       /* accessed by the host functions */
139         volatile unsigned int dwNumInput;   /* num of chars in input buffer   */
140         volatile unsigned int dwInBuffGet;  /* where to get from input buffer */
141         volatile unsigned int dwInBuffPut;  /* where to put into input buffer */
142         volatile unsigned int dwNumOutput;  /* num of chars in output buffer  */
143         volatile unsigned int dwOutBuffGet; /* where to get from output buffer*/
144         volatile unsigned int dwOutBuffPut; /* where to put into output buffer*/
145
146         volatile bool bSendCharsPending;    /* Flag to indicate sendchar active */
147         volatile bool bReadCharsPending;    /* Flag to indicate a read is primed */
148         char *pCoherCharOut;                /* special aligned buffer for chars to 1401 */
149         struct urb *pUrbCharOut;            /* urb used for chars to 1401 */
150         char *pCoherCharIn;                 /* special aligned buffer for chars to host */
151         struct urb *pUrbCharIn;             /* urb used for chars to host */
152
153         spinlock_t charOutLock;             /* to protect the outputBuffer and outputting */
154         spinlock_t charInLock;              /* to protect the inputBuffer and char reads */
155         __u8 bInterval;                     /* Interrupt end point interval */
156
157         volatile unsigned int dwDMAFlag;    /* state of DMA */
158         TRANSAREA rTransDef[MAX_TRANSAREAS];/* transfer area info */
159         volatile DMADESC rDMAInfo;          /*  info on current DMA transfer */
160         volatile bool bXFerWaiting;         /*  Flag set if DMA transfer stalled */
161         volatile bool bInDrawDown;          /*  Flag that we want to halt transfers */
162
163         /*  Parameters relating to a block read\write that is in progress. Some of these values */
164         /*   are equivalent to values in rDMAInfo. The values here are those in use, while those */
165         /*   in rDMAInfo are those received from the 1401 via an escape sequence. If another */
166         /*   escape sequence arrives before the previous xfer ends, rDMAInfo values are updated while these */
167         /*   are used to finish off the current transfer. */
168         volatile short StagedId;            /*  The transfer area id for this transfer */
169         volatile bool StagedRead;           /*  Flag TRUE for read from 1401, FALSE for write */
170         volatile unsigned int StagedLength; /*  Total length of this transfer */
171         volatile unsigned int StagedOffset; /*  Offset within memory area for transfer start */
172         volatile unsigned int StagedDone;   /*  Bytes transferred so far */
173         volatile bool bStagedUrbPending;    /*  Flag to indicate active */
174         char *pCoherStagedIO;               /*  buffer used for block transfers */
175         struct urb *pStagedUrb;             /*  The URB to use */
176         spinlock_t stagedLock;              /*  protects ReadWriteMem() and circular buffer stuff */
177
178         short s1401Type;                    /*  type of 1401 attached */
179         short sCurrentState;                /*  current error state */
180         bool bIsUSB2;                       /*  type of the interface we connect to */
181         bool bForceReset;                   /*  Flag to make sure we get a real reset */
182         __u32 statBuf[2];                   /*  buffer for 1401 state info */
183
184         unsigned long ulSelfTestTime;       /*  used to timeout self test */
185
186         int nPipes;                         /*  Should be 3 or 4 depending on 1401 usb chip */
187         int bPipeError[4];                  /*  set non-zero if an error on one of the pipe */
188         __u8 epAddr[4];                     /*  addresses of the 3/4 end points */
189
190         struct usb_device *udev;            /*  the usb device for this device */
191         struct usb_interface *interface;    /*  the interface for this device, NULL if removed */
192         struct usb_anchor submitted;        /*  in case we need to retract our submissions */
193         struct mutex io_mutex;              /*  synchronize I/O with disconnect, one user-mode caller at a time */
194
195         int    errors;                      /*  the last request tanked */
196         int    open_count;                  /*  count the number of openers */
197         spinlock_t err_lock;                /*  lock for errors */
198         struct kref kref;
199 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
200 #define to_DEVICE_EXTENSION(d) container_of(d, DEVICE_EXTENSION, kref)
201
202 /*  Definitions of routimes used between compilation object files */
203 /*  in usb1401.c */
204 extern int Allowi(DEVICE_EXTENSION *pdx);
205 extern int SendChars(DEVICE_EXTENSION *pdx);
206 extern void ced_draw_down(DEVICE_EXTENSION *pdx);
207 extern int ReadWriteMem(DEVICE_EXTENSION *pdx, bool Read, unsigned short wIdent,
208                                 unsigned int dwOffs, unsigned int dwLen);
209
210 /*  in ced_ioc.c */
211 extern int ClearArea(DEVICE_EXTENSION *pdx, int nArea);
212 extern int SendString(DEVICE_EXTENSION *pdx, const char __user *pData, unsigned int n);
213 extern int SendChar(DEVICE_EXTENSION *pdx, char c);
214 extern int Get1401State(DEVICE_EXTENSION *pdx, __u32 *state, __u32 *error);
215 extern int ReadWrite_Cancel(DEVICE_EXTENSION *pdx);
216 extern bool Is1401(DEVICE_EXTENSION *pdx);
217 extern bool QuickCheck(DEVICE_EXTENSION *pdx, bool bTestBuff, bool bCanReset);
218 extern int Reset1401(DEVICE_EXTENSION *pdx);
219 extern int GetChar(DEVICE_EXTENSION *pdx);
220 extern int GetString(DEVICE_EXTENSION *pdx, char __user *pUser, int n);
221 extern int SetTransfer(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD);
222 extern int UnsetTransfer(DEVICE_EXTENSION *pdx, int nArea);
223 extern int SetEvent(DEVICE_EXTENSION *pdx, TRANSFEREVENT __user *pTE);
224 extern int Stat1401(DEVICE_EXTENSION *pdx);
225 extern int LineCount(DEVICE_EXTENSION *pdx);
226 extern int GetOutBufSpace(DEVICE_EXTENSION *pdx);
227 extern int GetTransfer(DEVICE_EXTENSION *pdx, TGET_TX_BLOCK __user *pGTB);
228 extern int KillIO1401(DEVICE_EXTENSION *pdx);
229 extern int BlkTransState(DEVICE_EXTENSION *pdx);
230 extern int StateOf1401(DEVICE_EXTENSION *pdx);
231 extern int StartSelfTest(DEVICE_EXTENSION *pdx);
232 extern int CheckSelfTest(DEVICE_EXTENSION *pdx, TGET_SELFTEST __user *pGST);
233 extern int TypeOf1401(DEVICE_EXTENSION *pdx);
234 extern int TransferFlags(DEVICE_EXTENSION *pdx);
235 extern int DbgPeek(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB);
236 extern int DbgPoke(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB);
237 extern int DbgRampData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB);
238 extern int DbgRampAddr(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB);
239 extern int DbgGetData(DEVICE_EXTENSION *pdx, TDBGBLOCK __user *pDB);
240 extern int DbgStopLoop(DEVICE_EXTENSION *pdx);
241 extern int SetCircular(DEVICE_EXTENSION *pdx, TRANSFERDESC __user *pTD);
242 extern int GetCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB);
243 extern int FreeCircBlock(DEVICE_EXTENSION *pdx, TCIRCBLOCK __user *pCB);
244 extern int WaitEvent(DEVICE_EXTENSION *pdx, int nArea, int msTimeOut);
245 extern int TestEvent(DEVICE_EXTENSION *pdx, int nArea);
246 #endif