mm-only debug patch...
[mmotm.git] / drivers / staging / udlfb / udlfb.h
blob40ad85ea8e674e1ac9924dd96ae0a8889127c1ef
1 #ifndef UDLFB_H
2 #define UDLFB_H
4 #define MAX_VMODES 4
5 #define FB_BPP 16
7 #define STD_CHANNEL "\x57\xCD\xDC\xA7\x1C\x88\x5E\x15" \
8 "\x60\xFE\xC6\x97\x16\x3D\x47\xF2"
10 /* as libdlo */
11 #define BUF_HIGH_WATER_MARK 1024
12 #define BUF_SIZE (64*1024)
14 struct dlfb_data {
15 struct usb_device *udev;
16 struct usb_interface *interface;
17 struct urb *tx_urb, *ctrl_urb;
18 struct usb_ctrlrequest dr;
19 struct fb_info *info;
20 char *buf;
21 char *bufend;
22 char *backing_buffer;
23 struct mutex bulk_mutex;
24 char edid[128];
25 int screen_size;
26 int line_length;
27 struct completion done;
28 int base16;
29 int base16d;
30 int base8;
31 int base8d;
34 struct dlfb_video_mode {
35 uint8_t col;
36 uint32_t hclock;
37 uint32_t vclock;
38 uint8_t unknown1[6];
39 uint16_t xres;
40 uint8_t unknown2[6];
41 uint16_t yres;
42 uint8_t unknown3[4];
43 } __attribute__ ((__packed__));
45 static struct dlfb_video_mode dlfb_video_modes[MAX_VMODES];
47 static void dlfb_bulk_callback(struct urb *urb)
49 struct dlfb_data *dev_info = urb->context;
50 complete(&dev_info->done);
53 static void dlfb_edid(struct dlfb_data *dev_info)
55 int i;
56 int ret;
57 char rbuf[2];
59 for (i = 0; i < 128; i++) {
60 ret =
61 usb_control_msg(dev_info->udev,
62 usb_rcvctrlpipe(dev_info->udev, 0), (0x02),
63 (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2,
64 0);
65 /*printk("ret control msg edid %d: %d [%d]\n",i, ret, rbuf[1]); */
66 dev_info->edid[i] = rbuf[1];
71 static int dlfb_bulk_msg(struct dlfb_data *dev_info, int len)
73 int ret;
75 init_completion(&dev_info->done);
77 dev_info->tx_urb->actual_length = 0;
78 dev_info->tx_urb->transfer_buffer_length = len;
80 ret = usb_submit_urb(dev_info->tx_urb, GFP_KERNEL);
81 if (!wait_for_completion_timeout(&dev_info->done, 1000)) {
82 usb_kill_urb(dev_info->tx_urb);
83 printk("usb timeout !!!\n");
86 return dev_info->tx_urb->actual_length;
89 static void dlfb_init_modes(void)
91 dlfb_video_modes[0].col = 0;
92 memcpy(&dlfb_video_modes[0].hclock, "\x20\x3C\x7A\xC9", 4);
93 memcpy(&dlfb_video_modes[0].vclock, "\xF2\x6C\x48\xF9", 4);
94 memcpy(&dlfb_video_modes[0].unknown1, "\x70\x53\xFF\xFF\x21\x27", 6);
95 dlfb_video_modes[0].xres = 800;
96 memcpy(&dlfb_video_modes[0].unknown2, "\x91\xF3\xFF\xFF\xFF\xF9", 6);
97 dlfb_video_modes[0].yres = 480;
98 memcpy(&dlfb_video_modes[0].unknown3, "\x01\x02\xC8\x19", 4);
100 dlfb_video_modes[1].col = 0;
101 memcpy(&dlfb_video_modes[1].hclock, "\x36\x18\xD5\x10", 4);
102 memcpy(&dlfb_video_modes[1].vclock, "\x60\xA9\x7B\x33", 4);
103 memcpy(&dlfb_video_modes[1].unknown1, "\xA1\x2B\x27\x32\xFF\xFF", 6);
104 dlfb_video_modes[1].xres = 1024;
105 memcpy(&dlfb_video_modes[1].unknown2, "\xD9\x9A\xFF\xCA\xFF\xFF", 6);
106 dlfb_video_modes[1].yres = 768;
107 memcpy(&dlfb_video_modes[1].unknown3, "\x04\x03\xC8\x32", 4);
109 dlfb_video_modes[2].col = 0;
110 memcpy(&dlfb_video_modes[2].hclock, "\x98\xF8\x0D\x57", 4);
111 memcpy(&dlfb_video_modes[2].vclock, "\x2A\x55\x4D\x54", 4);
112 memcpy(&dlfb_video_modes[2].unknown1, "\xCA\x0D\xFF\xFF\x94\x43", 6);
113 dlfb_video_modes[2].xres = 1280;
114 memcpy(&dlfb_video_modes[2].unknown2, "\x9A\xA8\xFF\xFF\xFF\xF9", 6);
115 dlfb_video_modes[2].yres = 1024;
116 memcpy(&dlfb_video_modes[2].unknown3, "\x04\x02\x60\x54", 4);
118 dlfb_video_modes[3].col = 0;
119 memcpy(&dlfb_video_modes[3].hclock, "\x42\x24\x38\x36", 4);
120 memcpy(&dlfb_video_modes[3].vclock, "\xC1\x52\xD9\x29", 4);
121 memcpy(&dlfb_video_modes[3].unknown1, "\xEA\xB8\x32\x60\xFF\xFF", 6);
122 dlfb_video_modes[3].xres = 1400;
123 memcpy(&dlfb_video_modes[3].unknown2, "\xC9\x4E\xFF\xFF\xFF\xF2", 6);
124 dlfb_video_modes[3].yres = 1050;
125 memcpy(&dlfb_video_modes[3].unknown3, "\x04\x02\x1E\x5F", 4);
128 static char *dlfb_set_register(char *bufptr, uint8_t reg, uint8_t val)
130 *bufptr++ = 0xAF;
131 *bufptr++ = 0x20;
132 *bufptr++ = reg;
133 *bufptr++ = val;
135 return bufptr;
138 static int dlfb_set_video_mode(struct dlfb_data *dev_info, int width, int height)
140 int i, ret;
141 unsigned char j;
142 char *bufptr = dev_info->buf;
143 uint8_t *vdata;
145 for (i = 0; i < MAX_VMODES; i++) {
146 printk("INIT VIDEO %d %d %d\n", i, dlfb_video_modes[i].xres,
147 dlfb_video_modes[i].yres);
148 if (dlfb_video_modes[i].xres == width
149 && dlfb_video_modes[i].yres == height) {
151 dev_info->base16 = 0;
152 dev_info->base16d = width * height * (FB_BPP / 8);
154 //dev_info->base8 = width * height * (FB_BPP / 8);
156 dev_info->base8 = dev_info->base16;
157 dev_info->base8d = dev_info->base16d;
159 /* set encryption key (null) */
160 memcpy(dev_info->buf, STD_CHANNEL, 16);
161 ret =
162 usb_control_msg(dev_info->udev,
163 usb_sndctrlpipe(dev_info->udev, 0),
164 0x12, (0x02 << 5), 0, 0,
165 dev_info->buf, 16, 0);
166 printk("ret control msg 1 (STD_CHANNEL): %d\n", ret);
168 /* set registers */
169 bufptr = dlfb_set_register(bufptr, 0xFF, 0x00);
171 /* set color depth */
172 bufptr = dlfb_set_register(bufptr, 0x00, 0x00);
174 /* set addresses */
175 bufptr =
176 dlfb_set_register(bufptr, 0x20,
177 (char)(dev_info->base16 >> 16));
178 bufptr =
179 dlfb_set_register(bufptr, 0x21,
180 (char)(dev_info->base16 >> 8));
181 bufptr =
182 dlfb_set_register(bufptr, 0x22,
183 (char)(dev_info->base16));
185 bufptr =
186 dlfb_set_register(bufptr, 0x26,
187 (char)(dev_info->base8 >> 16));
188 bufptr =
189 dlfb_set_register(bufptr, 0x27,
190 (char)(dev_info->base8 >> 8));
191 bufptr =
192 dlfb_set_register(bufptr, 0x28,
193 (char)(dev_info->base8));
195 /* set video mode */
196 vdata = (uint8_t *)&dlfb_video_modes[i];
197 for (j = 0; j < 29; j++)
198 bufptr = dlfb_set_register(bufptr, j, vdata[j]);
200 /* blank */
201 bufptr = dlfb_set_register(bufptr, 0x1F, 0x00);
203 /* end registers */
204 bufptr = dlfb_set_register(bufptr, 0xFF, 0xFF);
206 /* send */
207 ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf);
208 printk("ret bulk 2: %d %td\n", ret,
209 bufptr - dev_info->buf);
211 /* flush */
212 ret = dlfb_bulk_msg(dev_info, 0);
213 printk("ret bulk 3: %d\n", ret);
215 dev_info->screen_size = width * height * (FB_BPP / 8);
216 dev_info->line_length = width * (FB_BPP / 8);
218 return 0;
222 return -1;
225 #endif