Linux-2.6.12-rc2
[linux-2.6] / drivers / usb / misc / sisusbvga / sisusb.h
1 /*
2  * sisusb - usb kernel driver for Net2280/SiS315 based USB2VGA dongles
3  *
4  * Copyright (C) 2005 by Thomas Winischhofer, Vienna, Austria
5  *
6  * If distributed as part of the Linux kernel, this code is licensed under the
7  * terms of the GPL v2.
8  *
9  * Otherwise, the following license terms apply:
10  *
11  * * Redistribution and use in source and binary forms, with or without
12  * * modification, are permitted provided that the following conditions
13  * * are met:
14  * * 1) Redistributions of source code must retain the above copyright
15  * *    notice, this list of conditions and the following disclaimer.
16  * * 2) Redistributions in binary form must reproduce the above copyright
17  * *    notice, this list of conditions and the following disclaimer in the
18  * *    documentation and/or other materials provided with the distribution.
19  * * 3) The name of the author may not be used to endorse or promote products
20  * *    derived from this software without specific prior written permission.
21  * *
22  * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
23  * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * Author:      Thomas Winischhofer <thomas@winischhofer.net>
34  *
35  */
36
37 #ifndef _SISUSB_H_
38 #define _SISUSB_H_
39
40 #ifdef CONFIG_COMPAT
41 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
42 #include <linux/ioctl32.h>
43 #define SISUSB_OLD_CONFIG_COMPAT
44 #else
45 #define SISUSB_NEW_CONFIG_COMPAT
46 #endif
47 #endif
48
49 /* Version Information */
50
51 #define SISUSB_VERSION          0
52 #define SISUSB_REVISION         0
53 #define SISUSB_PATCHLEVEL       7
54
55 /* USB related */
56
57 #define SISUSB_MINOR    133             /* FIXME */
58
59 /* Size of the sisusb input/output buffers */
60 #define SISUSB_IBUF_SIZE  0x01000
61 #define SISUSB_OBUF_SIZE  0x10000       /* fixed */
62
63 #define NUMOBUFS 8                      /* max number of output buffers/output URBs */
64
65 /* About endianness:
66  *
67  * 1) I/O ports, PCI config registers. The read/write()
68  *    calls emulate inX/outX. Hence, the data is
69  *    expected/delivered in machine endiannes by this
70  *    driver.
71  * 2) Video memory. The data is copied 1:1. There is
72  *    no swapping. Ever. This means for userland that
73  *    the data has to be prepared properly. (Hint:
74  *    think graphics data format, command queue,
75  *    hardware cursor.)
76  * 3) MMIO. Data is copied 1:1. MMIO must be swapped
77  *    properly by userland.
78  *
79  */
80
81 #ifdef __BIG_ENDIAN
82 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)             \
83         do {                                            \
84                 p->header  = cpu_to_le16(p->header);    \
85                 p->address = cpu_to_le32(p->address);   \
86                 p->data    = cpu_to_le32(p->data);      \
87         } while(0)
88 #else
89 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)
90 #endif
91
92 struct sisusb_usb_data;
93
94 struct sisusb_urb_context {             /* urb->context for outbound bulk URBs */
95         struct sisusb_usb_data *sisusb;
96         int urbindex;
97         int *actual_length;
98 };
99
100 struct sisusb_usb_data {
101         struct usb_device *sisusb_dev;
102         struct usb_interface *interface;
103         struct kref kref;
104         wait_queue_head_t wait_q;       /* for syncind and timeouts */
105         struct semaphore lock;          /* general race avoidance */
106         unsigned int ifnum;             /* interface number of the USB device */
107         int minor;                      /* minor (for logging clarity) */
108         int isopen;                     /* !=0 if open */
109         int present;                    /* !=0 if device is present on the bus */
110         int ready;                      /* !=0 if device is ready for userland */
111 #ifdef SISUSB_OLD_CONFIG_COMPAT
112         int ioctl32registered;
113 #endif
114         int numobufs;                   /* number of obufs = number of out urbs */
115         char *obuf[NUMOBUFS], *ibuf;    /* transfer buffers */
116         int obufsize, ibufsize;
117         dma_addr_t transfer_dma_out[NUMOBUFS];
118         dma_addr_t transfer_dma_in;
119         struct urb *sisurbout[NUMOBUFS];
120         struct urb *sisurbin;
121         unsigned char urbstatus[NUMOBUFS];
122         unsigned char completein;
123         struct sisusb_urb_context urbout_context[NUMOBUFS];
124         unsigned long flagb0;
125         unsigned long vrambase;         /* framebuffer base */
126         unsigned int vramsize;          /* framebuffer size (bytes) */
127         unsigned long mmiobase;
128         unsigned int mmiosize;
129         unsigned long ioportbase;
130         unsigned char devinit;          /* device initialized? */
131         unsigned char gfxinit;          /* graphics core initialized? */
132         unsigned short chipid, chipvendor;
133         unsigned short chiprevision;
134 };
135
136 #define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
137
138 /* USB transport related */
139
140 /* urbstatus */
141 #define SU_URB_BUSY   1
142 #define SU_URB_ALLOC  2
143
144 /* Endpoints */
145
146 #define SISUSB_EP_GFX_IN        0x0e    /* gfx std packet out(0e)/in(8e) */
147 #define SISUSB_EP_GFX_OUT       0x0e
148
149 #define SISUSB_EP_GFX_BULK_OUT  0x01    /* gfx mem bulk out/in */
150 #define SISUSB_EP_GFX_BULK_IN   0x02    /* ? 2 is "OUT" ? */
151
152 #define SISUSB_EP_GFX_LBULK_OUT 0x03    /* gfx large mem bulk out */
153
154 #define SISUSB_EP_UNKNOWN_04    0x04    /* ? 4 is "OUT" ? - unused */
155
156 #define SISUSB_EP_BRIDGE_IN     0x0d    /* Net2280 out(0d)/in(8d) */
157 #define SISUSB_EP_BRIDGE_OUT    0x0d
158
159 #define SISUSB_TYPE_MEM         0
160 #define SISUSB_TYPE_IO          1
161
162 struct sisusb_packet {
163         unsigned short header;
164         u32 address;
165         u32 data;
166 } __attribute__((__packed__));
167
168 #define CLEARPACKET(packet) memset(packet, 0, 10)
169
170 /* PCI bridge related */
171
172 #define SISUSB_PCI_MEMBASE      0xd0000000
173 #define SISUSB_PCI_MMIOBASE     0xe4000000
174 #define SISUSB_PCI_IOPORTBASE   0x0000d000
175
176 #define SISUSB_PCI_PSEUDO_MEMBASE       0x10000000
177 #define SISUSB_PCI_PSEUDO_MMIOBASE      0x20000000
178 #define SISUSB_PCI_PSEUDO_IOPORTBASE    0x0000d000
179 #define SISUSB_PCI_PSEUDO_PCIBASE       0x00010000
180
181 #define SISUSB_PCI_MMIOSIZE     (128*1024)
182 #define SISUSB_PCI_PCONFSIZE    0x5c
183
184 /* graphics core related */
185
186 #define AROFFSET        0x40
187 #define ARROFFSET       0x41
188 #define GROFFSET        0x4e
189 #define SROFFSET        0x44
190 #define CROFFSET        0x54
191 #define MISCROFFSET     0x4c
192 #define MISCWOFFSET     0x42
193 #define INPUTSTATOFFSET 0x5A
194 #define PART1OFFSET     0x04
195 #define PART2OFFSET     0x10
196 #define PART3OFFSET     0x12
197 #define PART4OFFSET     0x14
198 #define PART5OFFSET     0x16
199 #define CAPTUREOFFSET   0x00
200 #define VIDEOOFFSET     0x02
201 #define COLREGOFFSET    0x48
202 #define PELMASKOFFSET   0x46
203 #define VGAENABLE       0x43
204
205 #define SISAR           SISUSB_PCI_IOPORTBASE + AROFFSET
206 #define SISARR          SISUSB_PCI_IOPORTBASE + ARROFFSET
207 #define SISGR           SISUSB_PCI_IOPORTBASE + GROFFSET
208 #define SISSR           SISUSB_PCI_IOPORTBASE + SROFFSET
209 #define SISCR           SISUSB_PCI_IOPORTBASE + CROFFSET
210 #define SISMISCR        SISUSB_PCI_IOPORTBASE + MISCROFFSET
211 #define SISMISCW        SISUSB_PCI_IOPORTBASE + MISCWOFFSET
212 #define SISINPSTAT      SISUSB_PCI_IOPORTBASE + INPUTSTATOFFSET
213 #define SISPART1        SISUSB_PCI_IOPORTBASE + PART1OFFSET
214 #define SISPART2        SISUSB_PCI_IOPORTBASE + PART2OFFSET
215 #define SISPART3        SISUSB_PCI_IOPORTBASE + PART3OFFSET
216 #define SISPART4        SISUSB_PCI_IOPORTBASE + PART4OFFSET
217 #define SISPART5        SISUSB_PCI_IOPORTBASE + PART5OFFSET
218 #define SISCAP          SISUSB_PCI_IOPORTBASE + CAPTUREOFFSET
219 #define SISVID          SISUSB_PCI_IOPORTBASE + VIDEOOFFSET
220 #define SISCOLIDXR      SISUSB_PCI_IOPORTBASE + COLREGOFFSET - 1
221 #define SISCOLIDX       SISUSB_PCI_IOPORTBASE + COLREGOFFSET
222 #define SISCOLDATA      SISUSB_PCI_IOPORTBASE + COLREGOFFSET + 1
223 #define SISCOL2IDX      SISPART5
224 #define SISCOL2DATA     SISPART5 + 1
225 #define SISPEL          SISUSB_PCI_IOPORTBASE + PELMASKOFFSET
226 #define SISVGAEN        SISUSB_PCI_IOPORTBASE + VGAENABLE
227 #define SISDACA         SISCOLIDX
228 #define SISDACD         SISCOLDATA
229
230 /* ioctl related */
231
232 /* Structure argument for SISUSB_GET_INFO ioctl  */
233 struct sisusb_info {
234         __u32   sisusb_id;              /* for identifying sisusb */
235 #define SISUSB_ID  0x53495355           /* Identify myself with 'SISU' */
236         __u8    sisusb_version;
237         __u8    sisusb_revision;
238         __u8    sisusb_patchlevel;
239         __u8    sisusb_gfxinit;         /* graphics core initialized? */
240
241         __u32   sisusb_vrambase;
242         __u32   sisusb_mmiobase;
243         __u32   sisusb_iobase;
244         __u32   sisusb_pcibase;
245
246         __u32   sisusb_vramsize;        /* framebuffer size in bytes */
247
248         __u32   sisusb_minor;
249
250         __u32   sisusb_fbdevactive;     /* != 0 if framebuffer device active */
251
252         __u8    sisusb_reserved[32];    /* for future use */
253 };
254
255 struct sisusb_command {
256         __u8   operation;       /* see below */
257         __u8   data0;           /* operation dependent */
258         __u8   data1;           /* operation dependent */
259         __u8   data2;           /* operation dependent */
260         __u32  data3;           /* operation dependent */
261         __u32  data4;           /* for future use */
262 };
263
264 #define SUCMD_GET      0x01     /* for all: data0 = index, data3 = port */
265 #define SUCMD_SET      0x02     /* data1 = value */
266 #define SUCMD_SETOR    0x03     /* data1 = or */
267 #define SUCMD_SETAND   0x04     /* data1 = and */
268 #define SUCMD_SETANDOR 0x05     /* data1 = and, data2 = or */
269 #define SUCMD_SETMASK  0x06     /* data1 = data, data2 = mask */
270
271 #define SUCMD_CLRSCR   0x07     /* data0:1:2 = length, data3 = address */
272
273 #define SISUSB_COMMAND          _IOWR(0xF3,0x3D,struct sisusb_command)
274 #define SISUSB_GET_CONFIG_SIZE  _IOR(0xF3,0x3E,__u32)
275 #define SISUSB_GET_CONFIG       _IOR(0xF3,0x3F,struct sisusb_info)
276
277 #endif /* SISUSB_H */
278