]> err.no Git - linux-2.6/blob - drivers/usb/misc/sisusbvga/sisusb.h
[PATCH] USB: sisusb[vga] update
[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 /* For older kernels, support for text consoles is by default
50  * off. To ensable text console support, change the following:
51  */
52 #if 0
53 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,13)
54 #define CONFIG_USB_SISUSBVGA_CON
55 #endif
56 #endif
57
58 /* Version Information */
59
60 #define SISUSB_VERSION          0
61 #define SISUSB_REVISION         0
62 #define SISUSB_PATCHLEVEL       8
63
64 /* Include console and mode switching code? */
65
66 #ifdef CONFIG_USB_SISUSBVGA_CON
67 #define INCL_SISUSB_CON         1
68 #endif
69
70 #ifdef INCL_SISUSB_CON
71 #include <linux/console.h>
72 #include <linux/vt_kern.h>
73 #include "sisusb_struct.h"
74 #endif
75
76 /* USB related */
77
78 #define SISUSB_MINOR            133     /* official */
79
80 /* Size of the sisusb input/output buffers */
81 #define SISUSB_IBUF_SIZE  0x01000
82 #define SISUSB_OBUF_SIZE  0x10000       /* fixed */
83
84 #define NUMOBUFS 8                      /* max number of output buffers/output URBs */
85
86 /* About endianness:
87  *
88  * 1) I/O ports, PCI config registers. The read/write()
89  *    calls emulate inX/outX. Hence, the data is
90  *    expected/delivered in machine endiannes by this
91  *    driver.
92  * 2) Video memory. The data is copied 1:1. There is
93  *    no swapping. Ever. This means for userland that
94  *    the data has to be prepared properly. (Hint:
95  *    think graphics data format, command queue,
96  *    hardware cursor.)
97  * 3) MMIO. Data is copied 1:1. MMIO must be swapped
98  *    properly by userland.
99  *
100  */
101
102 #ifdef __BIG_ENDIAN
103 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)             \
104         do {                                            \
105                 p->header  = cpu_to_le16(p->header);    \
106                 p->address = cpu_to_le32(p->address);   \
107                 p->data    = cpu_to_le32(p->data);      \
108         } while(0)
109 #else
110 #define SISUSB_CORRECT_ENDIANNESS_PACKET(p)
111 #endif
112
113 struct sisusb_usb_data;
114
115 struct sisusb_urb_context {             /* urb->context for outbound bulk URBs */
116         struct sisusb_usb_data *sisusb;
117         int urbindex;
118         int *actual_length;
119 };
120
121 struct sisusb_usb_data {
122         struct usb_device *sisusb_dev;
123         struct usb_interface *interface;
124         struct kref kref;
125         wait_queue_head_t wait_q;       /* for syncind and timeouts */
126         struct semaphore lock;          /* general race avoidance */
127         unsigned int ifnum;             /* interface number of the USB device */
128         int minor;                      /* minor (for logging clarity) */
129         int isopen;                     /* !=0 if open */
130         int present;                    /* !=0 if device is present on the bus */
131         int ready;                      /* !=0 if device is ready for userland */
132 #ifdef SISUSB_OLD_CONFIG_COMPAT
133         int ioctl32registered;
134 #endif
135         int numobufs;                   /* number of obufs = number of out urbs */
136         char *obuf[NUMOBUFS], *ibuf;    /* transfer buffers */
137         int obufsize, ibufsize;
138         dma_addr_t transfer_dma_out[NUMOBUFS];
139         dma_addr_t transfer_dma_in;
140         struct urb *sisurbout[NUMOBUFS];
141         struct urb *sisurbin;
142         unsigned char urbstatus[NUMOBUFS];
143         unsigned char completein;
144         struct sisusb_urb_context urbout_context[NUMOBUFS];
145         unsigned long flagb0;
146         unsigned long vrambase;         /* framebuffer base */
147         unsigned int vramsize;          /* framebuffer size (bytes) */
148         unsigned long mmiobase;
149         unsigned int mmiosize;
150         unsigned long ioportbase;
151         unsigned char devinit;          /* device initialized? */
152         unsigned char gfxinit;          /* graphics core initialized? */
153         unsigned short chipid, chipvendor;
154         unsigned short chiprevision;
155 #ifdef INCL_SISUSB_CON
156         struct SiS_Private *SiS_Pr;
157         unsigned long scrbuf;
158         unsigned int scrbuf_size;
159         int haveconsole, con_first, con_last;
160         int havethisconsole[MAX_NR_CONSOLES];
161         int textmodedestroyed;
162         unsigned int sisusb_num_columns; /* real number, not vt's idea */
163         int cur_start_addr, con_rolled_over;
164         int sisusb_cursor_loc, bad_cursor_pos;
165         int sisusb_cursor_size_from;
166         int sisusb_cursor_size_to;
167         int current_font_height, current_font_512;
168         int font_backup_size, font_backup_height, font_backup_512;
169         char *font_backup;
170         int font_slot;
171         struct vc_data *sisusb_display_fg;
172         int is_gfx;
173         int con_blanked;
174 #endif
175 };
176
177 #define to_sisusb_dev(d) container_of(d, struct sisusb_usb_data, kref)
178
179 /* USB transport related */
180
181 /* urbstatus */
182 #define SU_URB_BUSY   1
183 #define SU_URB_ALLOC  2
184
185 /* Endpoints */
186
187 #define SISUSB_EP_GFX_IN        0x0e    /* gfx std packet out(0e)/in(8e) */
188 #define SISUSB_EP_GFX_OUT       0x0e
189
190 #define SISUSB_EP_GFX_BULK_OUT  0x01    /* gfx mem bulk out/in */
191 #define SISUSB_EP_GFX_BULK_IN   0x02    /* ? 2 is "OUT" ? */
192
193 #define SISUSB_EP_GFX_LBULK_OUT 0x03    /* gfx large mem bulk out */
194
195 #define SISUSB_EP_UNKNOWN_04    0x04    /* ? 4 is "OUT" ? - unused */
196
197 #define SISUSB_EP_BRIDGE_IN     0x0d    /* Net2280 out(0d)/in(8d) */
198 #define SISUSB_EP_BRIDGE_OUT    0x0d
199
200 #define SISUSB_TYPE_MEM         0
201 #define SISUSB_TYPE_IO          1
202
203 struct sisusb_packet {
204         unsigned short header;
205         u32 address;
206         u32 data;
207 } __attribute__((__packed__));
208
209 #define CLEARPACKET(packet) memset(packet, 0, 10)
210
211 /* PCI bridge related */
212
213 #define SISUSB_PCI_MEMBASE      0xd0000000
214 #define SISUSB_PCI_MMIOBASE     0xe4000000
215 #define SISUSB_PCI_IOPORTBASE   0x0000d000
216
217 #define SISUSB_PCI_PSEUDO_MEMBASE       0x10000000
218 #define SISUSB_PCI_PSEUDO_MMIOBASE      0x20000000
219 #define SISUSB_PCI_PSEUDO_IOPORTBASE    0x0000d000
220 #define SISUSB_PCI_PSEUDO_PCIBASE       0x00010000
221
222 #define SISUSB_PCI_MMIOSIZE     (128*1024)
223 #define SISUSB_PCI_PCONFSIZE    0x5c
224
225 /* graphics core related */
226
227 #define AROFFSET        0x40
228 #define ARROFFSET       0x41
229 #define GROFFSET        0x4e
230 #define SROFFSET        0x44
231 #define CROFFSET        0x54
232 #define MISCROFFSET     0x4c
233 #define MISCWOFFSET     0x42
234 #define INPUTSTATOFFSET 0x5A
235 #define PART1OFFSET     0x04
236 #define PART2OFFSET     0x10
237 #define PART3OFFSET     0x12
238 #define PART4OFFSET     0x14
239 #define PART5OFFSET     0x16
240 #define CAPTUREOFFSET   0x00
241 #define VIDEOOFFSET     0x02
242 #define COLREGOFFSET    0x48
243 #define PELMASKOFFSET   0x46
244 #define VGAENABLE       0x43
245
246 #define SISAR           SISUSB_PCI_IOPORTBASE + AROFFSET
247 #define SISARR          SISUSB_PCI_IOPORTBASE + ARROFFSET
248 #define SISGR           SISUSB_PCI_IOPORTBASE + GROFFSET
249 #define SISSR           SISUSB_PCI_IOPORTBASE + SROFFSET
250 #define SISCR           SISUSB_PCI_IOPORTBASE + CROFFSET
251 #define SISMISCR        SISUSB_PCI_IOPORTBASE + MISCROFFSET
252 #define SISMISCW        SISUSB_PCI_IOPORTBASE + MISCWOFFSET
253 #define SISINPSTAT      SISUSB_PCI_IOPORTBASE + INPUTSTATOFFSET
254 #define SISPART1        SISUSB_PCI_IOPORTBASE + PART1OFFSET
255 #define SISPART2        SISUSB_PCI_IOPORTBASE + PART2OFFSET
256 #define SISPART3        SISUSB_PCI_IOPORTBASE + PART3OFFSET
257 #define SISPART4        SISUSB_PCI_IOPORTBASE + PART4OFFSET
258 #define SISPART5        SISUSB_PCI_IOPORTBASE + PART5OFFSET
259 #define SISCAP          SISUSB_PCI_IOPORTBASE + CAPTUREOFFSET
260 #define SISVID          SISUSB_PCI_IOPORTBASE + VIDEOOFFSET
261 #define SISCOLIDXR      SISUSB_PCI_IOPORTBASE + COLREGOFFSET - 1
262 #define SISCOLIDX       SISUSB_PCI_IOPORTBASE + COLREGOFFSET
263 #define SISCOLDATA      SISUSB_PCI_IOPORTBASE + COLREGOFFSET + 1
264 #define SISCOL2IDX      SISPART5
265 #define SISCOL2DATA     SISPART5 + 1
266 #define SISPEL          SISUSB_PCI_IOPORTBASE + PELMASKOFFSET
267 #define SISVGAEN        SISUSB_PCI_IOPORTBASE + VGAENABLE
268 #define SISDACA         SISCOLIDX
269 #define SISDACD         SISCOLDATA
270
271 /* ioctl related */
272
273 /* Structure argument for SISUSB_GET_INFO ioctl  */
274 struct sisusb_info {
275         __u32   sisusb_id;              /* for identifying sisusb */
276 #define SISUSB_ID  0x53495355           /* Identify myself with 'SISU' */
277         __u8    sisusb_version;
278         __u8    sisusb_revision;
279         __u8    sisusb_patchlevel;
280         __u8    sisusb_gfxinit;         /* graphics core initialized? */
281
282         __u32   sisusb_vrambase;
283         __u32   sisusb_mmiobase;
284         __u32   sisusb_iobase;
285         __u32   sisusb_pcibase;
286
287         __u32   sisusb_vramsize;        /* framebuffer size in bytes */
288
289         __u32   sisusb_minor;
290
291         __u32   sisusb_fbdevactive;     /* != 0 if framebuffer device active */
292
293         __u32   sisusb_conactive;       /* != 0 if console driver active */
294
295         __u8    sisusb_reserved[28];    /* for future use */
296 };
297
298 struct sisusb_command {
299         __u8   operation;       /* see below */
300         __u8   data0;           /* operation dependent */
301         __u8   data1;           /* operation dependent */
302         __u8   data2;           /* operation dependent */
303         __u32  data3;           /* operation dependent */
304         __u32  data4;           /* for future use */
305 };
306
307 #define SUCMD_GET       0x01    /* for all: data0 = index, data3 = port */
308 #define SUCMD_SET       0x02    /* data1 = value */
309 #define SUCMD_SETOR     0x03    /* data1 = or */
310 #define SUCMD_SETAND    0x04    /* data1 = and */
311 #define SUCMD_SETANDOR  0x05    /* data1 = and, data2 = or */
312 #define SUCMD_SETMASK   0x06    /* data1 = data, data2 = mask */
313
314 #define SUCMD_CLRSCR    0x07    /* data0:1:2 = length, data3 = address */
315
316 #define SUCMD_HANDLETEXTMODE 0x08 /* Reset/destroy text mode */
317
318 #define SUCMD_SETMODE   0x09    /* Set a display mode (data3 = SiS mode) */
319 #define SUCMD_SETVESAMODE 0x0a  /* Set a display mode (data3 = VESA mode) */
320
321 #define SISUSB_COMMAND          _IOWR(0xF3,0x3D,struct sisusb_command)
322 #define SISUSB_GET_CONFIG_SIZE  _IOR(0xF3,0x3E,__u32)
323 #define SISUSB_GET_CONFIG       _IOR(0xF3,0x3F,struct sisusb_info)
324
325
326 #endif /* SISUSB_H */
327