Commit | Line | Data |
---|---|---|
59277b67 BT |
1 | /* |
2 | * udlfb.c -- Framebuffer driver for DisplayLink USB controller | |
3 | * | |
4 | * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it> | |
5 | * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com> | |
6 | * | |
7 | * This file is subject to the terms and conditions of the GNU General Public | |
8 | * License v2. See the file COPYING in the main directory of this archive for | |
9 | * more details. | |
10 | * | |
11 | * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven, | |
12 | * usb-skeleton by GregKH. | |
13 | * | |
14 | * Device-specific portions based on information from Displaylink, with work | |
15 | * from Florian Echtler, Henrik Bjerregaard Pedersen, and others. | |
16 | */ | |
88e58b1a RDI |
17 | |
18 | #include <linux/module.h> | |
19 | #include <linux/kernel.h> | |
20 | #include <linux/init.h> | |
21 | #include <linux/usb.h> | |
22 | #include <linux/uaccess.h> | |
23 | #include <linux/mm.h> | |
24 | #include <linux/fb.h> | |
25 | #include <linux/mutex.h> | |
fb299002 | 26 | #include <linux/vmalloc.h> |
88e58b1a RDI |
27 | |
28 | #include "udlfb.h" | |
29 | ||
59277b67 BT |
30 | #define DRIVER_VERSION "DisplayLink Framebuffer Driver 0.4.1" |
31 | ||
32 | static struct fb_fix_screeninfo dlfb_fix = { | |
1d31a9ee BT |
33 | .id = "displaylinkfb", |
34 | .type = FB_TYPE_PACKED_PIXELS, | |
35 | .visual = FB_VISUAL_TRUECOLOR, | |
36 | .xpanstep = 0, | |
37 | .ypanstep = 0, | |
38 | .ywrapstep = 0, | |
39 | .accel = FB_ACCEL_NONE, | |
59277b67 | 40 | }; |
88e58b1a | 41 | |
cc403dc6 BT |
42 | /* |
43 | * There are many DisplayLink-based products, all with unique PIDs. We are able | |
44 | * to support all volume ones (circa 2009) with a single driver, so we match | |
45 | * globally on VID. TODO: Probe() needs to detect when we might be running | |
46 | * "future" chips, and bail on those, so a compatible driver can match. | |
47 | */ | |
48 | static struct usb_device_id id_table[] = { | |
49 | {.idVendor = 0x17e9, .match_flags = USB_DEVICE_ID_MATCH_VENDOR,}, | |
50 | {}, | |
51 | }; | |
52 | MODULE_DEVICE_TABLE(usb, id_table); | |
88e58b1a | 53 | |
59277b67 BT |
54 | /* |
55 | * Inserts a specific DisplayLink controller command into the provided | |
56 | * buffer. | |
57 | */ | |
58 | static char *insert_command(char *buf, u8 reg, u8 val) | |
88e58b1a | 59 | { |
1d31a9ee BT |
60 | *buf++ = 0xAF; |
61 | *buf++ = 0x20; | |
62 | *buf++ = reg; | |
63 | *buf++ = val; | |
64 | return buf; | |
59277b67 | 65 | } |
88e58b1a | 66 | |
59277b67 BT |
67 | static char *insert_vidreg_lock(char *buf) |
68 | { | |
1d31a9ee | 69 | return insert_command(buf, 0xFF, 0x00); |
59277b67 | 70 | } |
88e58b1a | 71 | |
59277b67 BT |
72 | static char *insert_vidreg_unlock(char *buf) |
73 | { | |
1d31a9ee | 74 | return insert_command(buf, 0xFF, 0xFF); |
59277b67 BT |
75 | } |
76 | ||
77 | /* | |
78 | * Once you send this command, the DisplayLink framebuffer gets driven to the | |
79 | * display. | |
80 | */ | |
81 | static char *insert_enable_hvsync(char *buf) | |
82 | { | |
1d31a9ee | 83 | return insert_command(buf, 0x1F, 0x00); |
59277b67 BT |
84 | } |
85 | ||
86 | static char *insert_set_color_depth(char *buf, u8 selection) | |
87 | { | |
1d31a9ee | 88 | return insert_command(buf, 0x00, selection); |
59277b67 BT |
89 | } |
90 | ||
91 | static char *insert_set_base16bpp(char *wrptr, u32 base) | |
92 | { | |
1d31a9ee BT |
93 | /* the base pointer is 16 bits wide, 0x20 is hi byte. */ |
94 | wrptr = insert_command(wrptr, 0x20, base >> 16); | |
95 | wrptr = insert_command(wrptr, 0x21, base >> 8); | |
96 | return insert_command(wrptr, 0x22, base); | |
59277b67 BT |
97 | } |
98 | ||
99 | static char *insert_set_base8bpp(char *wrptr, u32 base) | |
100 | { | |
1d31a9ee BT |
101 | wrptr = insert_command(wrptr, 0x26, base >> 16); |
102 | wrptr = insert_command(wrptr, 0x27, base >> 8); | |
103 | return insert_command(wrptr, 0x28, base); | |
59277b67 BT |
104 | } |
105 | ||
106 | static char *insert_command_16(char *wrptr, u8 reg, u16 value) | |
107 | { | |
1d31a9ee BT |
108 | wrptr = insert_command(wrptr, reg, value >> 8); |
109 | return insert_command(wrptr, reg+1, value); | |
59277b67 BT |
110 | } |
111 | ||
112 | /* | |
113 | * This is kind of weird because the controller takes some | |
114 | * register values in a different byte order than other registers. | |
115 | */ | |
116 | static char *insert_command_16be(char *wrptr, u8 reg, u16 value) | |
117 | { | |
1d31a9ee BT |
118 | wrptr = insert_command(wrptr, reg, value); |
119 | return insert_command(wrptr, reg+1, value >> 8); | |
59277b67 BT |
120 | } |
121 | ||
122 | /* | |
123 | * LFSR is linear feedback shift register. The reason we have this is | |
124 | * because the display controller needs to minimize the clock depth of | |
125 | * various counters used in the display path. So this code reverses the | |
126 | * provided value into the lfsr16 value by counting backwards to get | |
127 | * the value that needs to be set in the hardware comparator to get the | |
128 | * same actual count. This makes sense once you read above a couple of | |
129 | * times and think about it from a hardware perspective. | |
130 | */ | |
131 | static u16 lfsr16(u16 actual_count) | |
132 | { | |
133 | u32 lv = 0xFFFF; /* This is the lfsr value that the hw starts with */ | |
134 | ||
135 | while (actual_count--) { | |
136 | lv = ((lv << 1) | | |
137 | (((lv >> 15) ^ (lv >> 4) ^ (lv >> 2) ^ (lv >> 1)) & 1)) | |
138 | & 0xFFFF; | |
88e58b1a RDI |
139 | } |
140 | ||
59277b67 BT |
141 | return (u16) lv; |
142 | } | |
143 | ||
144 | /* | |
145 | * This does LFSR conversion on the value that is to be written. | |
146 | * See LFSR explanation above for more detail. | |
147 | */ | |
148 | static char *insert_command_lfsr16(char *wrptr, u8 reg, u16 value) | |
149 | { | |
150 | return insert_command_16(wrptr, reg, lfsr16(value)); | |
88e58b1a RDI |
151 | } |
152 | ||
59277b67 BT |
153 | /* |
154 | * This takes a standard fbdev screeninfo struct and all of its monitor mode | |
155 | * details and converts them into the DisplayLink equivalent register commands. | |
156 | */ | |
157 | static char *insert_set_vid_cmds(char *wrptr, struct fb_var_screeninfo *var) | |
88e58b1a | 158 | { |
59277b67 BT |
159 | u16 xds, yds; |
160 | u16 xde, yde; | |
161 | u16 yec; | |
162 | ||
163 | ||
164 | /* x display start */ | |
165 | xds = var->left_margin + var->hsync_len; | |
166 | wrptr = insert_command_lfsr16(wrptr, 0x01, xds); | |
167 | /* x display end */ | |
168 | xde = xds + var->xres; | |
169 | wrptr = insert_command_lfsr16(wrptr, 0x03, xde); | |
170 | ||
171 | /* y display start */ | |
172 | yds = var->upper_margin + var->vsync_len; | |
173 | wrptr = insert_command_lfsr16(wrptr, 0x05, yds); | |
174 | /* y display end */ | |
175 | yde = yds + var->yres; | |
176 | wrptr = insert_command_lfsr16(wrptr, 0x07, yde); | |
177 | ||
178 | /* x end count is active + blanking - 1 */ | |
179 | wrptr = insert_command_lfsr16(wrptr, 0x09, xde + var->right_margin - 1); | |
180 | ||
181 | /* libdlo hardcodes hsync start to 1 */ | |
182 | wrptr = insert_command_lfsr16(wrptr, 0x0B, 1); | |
183 | ||
184 | /* hsync end is width of sync pulse + 1 */ | |
185 | wrptr = insert_command_lfsr16(wrptr, 0x0D, var->hsync_len + 1); | |
186 | ||
187 | /* hpixels is active pixels */ | |
188 | wrptr = insert_command_16(wrptr, 0x0F, var->xres); | |
88e58b1a | 189 | |
59277b67 BT |
190 | /* yendcount is vertical active + vertical blanking */ |
191 | yec = var->yres + var->upper_margin + var->lower_margin + | |
192 | var->vsync_len; | |
193 | wrptr = insert_command_lfsr16(wrptr, 0x11, yec); | |
88e58b1a | 194 | |
59277b67 BT |
195 | /* libdlo hardcodes vsync start to 0 */ |
196 | wrptr = insert_command_lfsr16(wrptr, 0x13, 0); | |
197 | ||
198 | /* vsync end is width of vsync pulse */ | |
199 | wrptr = insert_command_lfsr16(wrptr, 0x15, var->vsync_len); | |
200 | ||
201 | /* vpixels is active pixels */ | |
202 | wrptr = insert_command_16(wrptr, 0x17, var->yres); | |
203 | ||
204 | /* convert picoseconds to 5kHz multiple for pclk5k = x * 1E12/5k */ | |
205 | wrptr = insert_command_16be(wrptr, 0x1B, 200*1000*1000/var->pixclock); | |
206 | ||
207 | return wrptr; | |
208 | } | |
209 | ||
210 | /* | |
211 | * This takes a standard fbdev screeninfo struct that was fetched or prepared | |
212 | * and then generates the appropriate command sequence that then drives the | |
213 | * display controller. | |
214 | */ | |
215 | static int dlfb_set_video_mode(struct dlfb_data *dev, | |
216 | struct fb_var_screeninfo *var) | |
217 | { | |
218 | char *buf; | |
219 | char *wrptr; | |
220 | int retval = 0; | |
221 | int writesize; | |
222 | ||
223 | buf = dev->buf; | |
224 | ||
225 | /* | |
226 | * This first section has to do with setting the base address on the | |
227 | * controller * associated with the display. There are 2 base | |
228 | * pointers, currently, we only * use the 16 bpp segment. | |
229 | */ | |
230 | wrptr = insert_vidreg_lock(buf); | |
231 | wrptr = insert_set_color_depth(wrptr, 0x00); | |
232 | /* set base for 16bpp segment to 0 */ | |
233 | wrptr = insert_set_base16bpp(wrptr, 0); | |
234 | /* set base for 8bpp segment to end of fb */ | |
235 | wrptr = insert_set_base8bpp(wrptr, dev->info->fix.smem_len); | |
236 | ||
237 | wrptr = insert_set_vid_cmds(wrptr, var); | |
238 | wrptr = insert_enable_hvsync(wrptr); | |
239 | wrptr = insert_vidreg_unlock(wrptr); | |
240 | ||
241 | writesize = wrptr - buf; | |
242 | ||
243 | mutex_lock(&dev->bulk_mutex); | |
244 | if (!dev->interface) { /* disconnect() was called */ | |
245 | mutex_unlock(&dev->bulk_mutex); | |
246 | retval = -ENODEV; | |
247 | goto error; | |
88e58b1a | 248 | } |
59277b67 BT |
249 | |
250 | retval = dlfb_bulk_msg(dev, writesize); | |
251 | mutex_unlock(&dev->bulk_mutex); | |
252 | if (retval) { | |
253 | dev_err(&dev->udev->dev, "Problem %d with submit write bulk.\n", | |
254 | retval); | |
255 | goto error; | |
256 | } | |
257 | ||
258 | return 0; | |
259 | ||
260 | error: | |
261 | return retval; | |
262 | } | |
263 | ||
59277b67 BT |
264 | |
265 | /* | |
266 | * Query EDID from the handware, then hand it off to fbdev's edid parse | |
267 | * routine which should give us back a filled in screeninfo structure. | |
268 | */ | |
269 | static int dlfb_get_var_from_edid(struct dlfb_data *dev, | |
270 | struct fb_var_screeninfo *var) | |
271 | { | |
272 | int ret; | |
273 | ||
274 | dlfb_edid(dev); | |
275 | ret = fb_parse_edid(dev->edid, var); | |
276 | ||
277 | return ret; | |
88e58b1a RDI |
278 | } |
279 | ||
280 | static int dlfb_mmap(struct fb_info *info, struct vm_area_struct *vma) | |
281 | { | |
282 | unsigned long start = vma->vm_start; | |
283 | unsigned long size = vma->vm_end - vma->vm_start; | |
284 | unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; | |
285 | unsigned long page, pos; | |
286 | ||
287 | printk("MMAP: %lu %u\n", offset + size, info->fix.smem_len); | |
288 | ||
f05e0575 | 289 | if (offset + size > info->fix.smem_len) |
88e58b1a | 290 | return -EINVAL; |
88e58b1a RDI |
291 | |
292 | pos = (unsigned long)info->fix.smem_start + offset; | |
293 | ||
294 | while (size > 0) { | |
295 | page = vmalloc_to_pfn((void *)pos); | |
f05e0575 | 296 | if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) |
88e58b1a | 297 | return -EAGAIN; |
f05e0575 | 298 | |
88e58b1a RDI |
299 | start += PAGE_SIZE; |
300 | pos += PAGE_SIZE; | |
301 | if (size > PAGE_SIZE) | |
302 | size -= PAGE_SIZE; | |
303 | else | |
304 | size = 0; | |
305 | } | |
306 | ||
307 | vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ | |
308 | return 0; | |
309 | ||
310 | } | |
311 | ||
f05e0575 | 312 | /* ioctl structure */ |
88e58b1a RDI |
313 | struct dloarea { |
314 | int x, y; | |
315 | int w, h; | |
7316bc55 | 316 | int x2, y2; |
88e58b1a RDI |
317 | }; |
318 | ||
88e58b1a RDI |
319 | static struct usb_driver dlfb_driver; |
320 | ||
1d31a9ee | 321 | /* thanks to Henrik Bjerregaard Pedersen for this function */ |
7316bc55 RDI |
322 | static char *rle_compress16(uint16_t * src, char *dst, int rem) |
323 | { | |
324 | ||
325 | int rl; | |
326 | uint16_t pix0; | |
327 | char *end_if_raw = dst + 6 + 2 * rem; | |
328 | ||
1d31a9ee | 329 | dst += 6; /* header will be filled in if RLE is worth it */ |
7316bc55 RDI |
330 | |
331 | while (rem && dst < end_if_raw) { | |
332 | char *start = (char *)src; | |
333 | ||
334 | pix0 = *src++; | |
335 | rl = 1; | |
336 | rem--; | |
337 | while (rem && *src == pix0) | |
338 | rem--, rl++, src++; | |
339 | *dst++ = rl; | |
340 | *dst++ = start[1]; | |
341 | *dst++ = start[0]; | |
342 | } | |
343 | ||
344 | return dst; | |
345 | } | |
346 | ||
347 | /* | |
1d31a9ee BT |
348 | Thanks to Henrik Bjerregaard Pedersen for rle implementation |
349 | and code refactoring. Next step is huffman compression. | |
7316bc55 RDI |
350 | */ |
351 | ||
88e58b1a RDI |
352 | static int |
353 | image_blit(struct dlfb_data *dev_info, int x, int y, int width, int height, | |
354 | char *data) | |
355 | { | |
356 | ||
357 | int i, j, base; | |
358 | int rem = width; | |
359 | int ret; | |
360 | ||
7316bc55 | 361 | int firstdiff, thistime; |
88e58b1a RDI |
362 | |
363 | char *bufptr; | |
364 | ||
f05e0575 | 365 | if (x + width > dev_info->info->var.xres) |
88e58b1a | 366 | return -EINVAL; |
88e58b1a | 367 | |
f05e0575 | 368 | if (y + height > dev_info->info->var.yres) |
88e58b1a | 369 | return -EINVAL; |
88e58b1a RDI |
370 | |
371 | mutex_lock(&dev_info->bulk_mutex); | |
372 | ||
7316bc55 RDI |
373 | base = |
374 | dev_info->base16 + ((dev_info->info->var.xres * 2 * y) + (x * 2)); | |
88e58b1a RDI |
375 | |
376 | data += (dev_info->info->var.xres * 2 * y) + (x * 2); | |
377 | ||
f05e0575 | 378 | /* printk("IMAGE_BLIT\n"); */ |
88e58b1a RDI |
379 | |
380 | bufptr = dev_info->buf; | |
381 | ||
382 | for (i = y; i < y + height; i++) { | |
383 | ||
384 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
385 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
386 | bufptr = dev_info->buf; | |
387 | } | |
388 | ||
389 | rem = width; | |
390 | ||
f05e0575 | 391 | /* printk("WRITING LINE %d\n", i); */ |
88e58b1a RDI |
392 | |
393 | while (rem) { | |
394 | ||
395 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
396 | ret = | |
397 | dlfb_bulk_msg(dev_info, | |
398 | bufptr - dev_info->buf); | |
399 | bufptr = dev_info->buf; | |
400 | } | |
1d31a9ee | 401 | /* number of pixels to consider this time */ |
7316bc55 RDI |
402 | thistime = rem; |
403 | if (thistime > 255) | |
404 | thistime = 255; | |
405 | ||
59277b67 BT |
406 | if (dev_info->backing_buffer) { |
407 | /* find first pixel that has changed */ | |
408 | firstdiff = -1; | |
409 | for (j = 0; j < thistime * 2; j++) { | |
410 | if (dev_info->backing_buffer | |
411 | [base - dev_info->base16 + j] | |
412 | != data[j]) { | |
413 | firstdiff = j / 2; | |
414 | break; | |
415 | } | |
88e58b1a | 416 | } |
59277b67 BT |
417 | |
418 | } else { | |
419 | firstdiff = 0; | |
420 | ||
7316bc55 | 421 | } |
88e58b1a | 422 | |
7316bc55 RDI |
423 | if (firstdiff >= 0) { |
424 | char *end_of_rle; | |
425 | ||
426 | end_of_rle = | |
427 | rle_compress16((uint16_t *) (data + | |
428 | firstdiff * 2), | |
429 | bufptr, | |
430 | thistime - firstdiff); | |
431 | ||
432 | if (end_of_rle < | |
433 | bufptr + 6 + 2 * (thistime - firstdiff)) { | |
434 | bufptr[0] = 0xAF; | |
435 | bufptr[1] = 0x69; | |
436 | ||
437 | bufptr[2] = | |
438 | (char)((base + | |
439 | firstdiff * 2) >> 16); | |
440 | bufptr[3] = | |
441 | (char)((base + firstdiff * 2) >> 8); | |
442 | bufptr[4] = | |
443 | (char)(base + firstdiff * 2); | |
444 | bufptr[5] = thistime - firstdiff; | |
445 | ||
446 | bufptr = end_of_rle; | |
447 | ||
448 | } else { | |
1d31a9ee | 449 | /* fallback to raw (or other?) */ |
88e58b1a RDI |
450 | *bufptr++ = 0xAF; |
451 | *bufptr++ = 0x68; | |
452 | ||
7316bc55 RDI |
453 | *bufptr++ = |
454 | (char)((base + | |
455 | firstdiff * 2) >> 16); | |
456 | *bufptr++ = | |
457 | (char)((base + firstdiff * 2) >> 8); | |
458 | *bufptr++ = | |
459 | (char)(base + firstdiff * 2); | |
460 | *bufptr++ = thistime - firstdiff; | |
7316bc55 RDI |
461 | for (j = firstdiff * 2; |
462 | j < thistime * 2; j += 2) { | |
463 | *bufptr++ = data[j + 1]; | |
464 | *bufptr++ = data[j]; | |
88e58b1a | 465 | } |
88e58b1a | 466 | } |
88e58b1a RDI |
467 | } |
468 | ||
7316bc55 RDI |
469 | base += thistime * 2; |
470 | data += thistime * 2; | |
471 | rem -= thistime; | |
88e58b1a RDI |
472 | } |
473 | ||
59277b67 BT |
474 | if (dev_info->backing_buffer) |
475 | memcpy(dev_info->backing_buffer + | |
476 | (base - dev_info->base16) - | |
477 | (width * 2), data - (width * 2), width * 2); | |
88e58b1a RDI |
478 | |
479 | base += (dev_info->info->var.xres * 2) - (width * 2); | |
480 | data += (dev_info->info->var.xres * 2) - (width * 2); | |
481 | ||
482 | } | |
483 | ||
7316bc55 | 484 | if (bufptr > dev_info->buf) { |
88e58b1a | 485 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); |
7316bc55 | 486 | } |
88e58b1a RDI |
487 | |
488 | mutex_unlock(&dev_info->bulk_mutex); | |
489 | ||
490 | return base; | |
491 | ||
492 | } | |
493 | ||
494 | static int | |
495 | draw_rect(struct dlfb_data *dev_info, int x, int y, int width, int height, | |
496 | unsigned char red, unsigned char green, unsigned char blue) | |
497 | { | |
498 | ||
499 | int i, j, base; | |
500 | int ret; | |
501 | unsigned short col = | |
502 | (((((red) & 0xF8) | ((green) >> 5)) & 0xFF) << 8) + | |
503 | (((((green) & 0x1C) << 3) | ((blue) >> 3)) & 0xFF); | |
504 | int rem = width; | |
505 | ||
506 | char *bufptr; | |
507 | ||
f05e0575 | 508 | if (x + width > dev_info->info->var.xres) |
88e58b1a | 509 | return -EINVAL; |
88e58b1a | 510 | |
f05e0575 | 511 | if (y + height > dev_info->info->var.yres) |
88e58b1a | 512 | return -EINVAL; |
88e58b1a RDI |
513 | |
514 | mutex_lock(&dev_info->bulk_mutex); | |
515 | ||
516 | base = dev_info->base16 + (dev_info->info->var.xres * 2 * y) + (x * 2); | |
517 | ||
518 | bufptr = dev_info->buf; | |
519 | ||
520 | for (i = y; i < y + height; i++) { | |
521 | ||
59277b67 BT |
522 | if (dev_info->backing_buffer) { |
523 | for (j = 0; j < width * 2; j += 2) { | |
524 | dev_info->backing_buffer | |
525 | [base - dev_info->base16 + j] = | |
526 | (char)(col >> 8); | |
527 | dev_info->backing_buffer | |
528 | [base - dev_info->base16 + j + 1] = | |
529 | (char)(col); | |
530 | } | |
88e58b1a | 531 | } |
59277b67 | 532 | |
88e58b1a RDI |
533 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { |
534 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
535 | bufptr = dev_info->buf; | |
536 | } | |
537 | ||
538 | rem = width; | |
539 | ||
540 | while (rem) { | |
541 | ||
542 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
543 | ret = | |
544 | dlfb_bulk_msg(dev_info, | |
545 | bufptr - dev_info->buf); | |
546 | bufptr = dev_info->buf; | |
547 | } | |
548 | ||
549 | *bufptr++ = 0xAF; | |
550 | *bufptr++ = 0x69; | |
551 | ||
552 | *bufptr++ = (char)(base >> 16); | |
553 | *bufptr++ = (char)(base >> 8); | |
554 | *bufptr++ = (char)(base); | |
555 | ||
556 | if (rem > 255) { | |
557 | *bufptr++ = 255; | |
558 | *bufptr++ = 255; | |
559 | rem -= 255; | |
560 | base += 255 * 2; | |
561 | } else { | |
562 | *bufptr++ = rem; | |
563 | *bufptr++ = rem; | |
564 | base += rem * 2; | |
565 | rem = 0; | |
566 | } | |
567 | ||
568 | *bufptr++ = (char)(col >> 8); | |
569 | *bufptr++ = (char)(col); | |
570 | ||
571 | } | |
572 | ||
573 | base += (dev_info->info->var.xres * 2) - (width * 2); | |
574 | ||
575 | } | |
576 | ||
f05e0575 | 577 | if (bufptr > dev_info->buf) |
88e58b1a | 578 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); |
88e58b1a RDI |
579 | |
580 | mutex_unlock(&dev_info->bulk_mutex); | |
581 | ||
582 | return 1; | |
583 | } | |
584 | ||
7316bc55 RDI |
585 | static void swapfb(struct dlfb_data *dev_info) |
586 | { | |
587 | ||
588 | int tmpbase; | |
589 | char *bufptr; | |
590 | ||
591 | mutex_lock(&dev_info->bulk_mutex); | |
592 | ||
593 | tmpbase = dev_info->base16; | |
594 | ||
595 | dev_info->base16 = dev_info->base16d; | |
596 | dev_info->base16d = tmpbase; | |
597 | ||
598 | bufptr = dev_info->buf; | |
599 | ||
600 | bufptr = dlfb_set_register(bufptr, 0xFF, 0x00); | |
601 | ||
1d31a9ee | 602 | /* set addresses */ |
7316bc55 RDI |
603 | bufptr = |
604 | dlfb_set_register(bufptr, 0x20, (char)(dev_info->base16 >> 16)); | |
605 | bufptr = dlfb_set_register(bufptr, 0x21, (char)(dev_info->base16 >> 8)); | |
606 | bufptr = dlfb_set_register(bufptr, 0x22, (char)(dev_info->base16)); | |
607 | ||
608 | bufptr = dlfb_set_register(bufptr, 0xFF, 0x00); | |
609 | ||
610 | dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
611 | ||
612 | mutex_unlock(&dev_info->bulk_mutex); | |
613 | } | |
614 | ||
615 | static int copyfb(struct dlfb_data *dev_info) | |
616 | { | |
617 | int base; | |
618 | int source; | |
619 | int rem; | |
620 | int i, ret; | |
621 | ||
622 | char *bufptr; | |
623 | ||
624 | base = dev_info->base16d; | |
625 | ||
626 | mutex_lock(&dev_info->bulk_mutex); | |
627 | ||
628 | source = dev_info->base16; | |
629 | ||
630 | bufptr = dev_info->buf; | |
631 | ||
632 | for (i = 0; i < dev_info->info->var.yres; i++) { | |
633 | ||
634 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
635 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
636 | bufptr = dev_info->buf; | |
637 | } | |
638 | ||
639 | rem = dev_info->info->var.xres; | |
640 | ||
641 | while (rem) { | |
642 | ||
643 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
644 | ret = | |
645 | dlfb_bulk_msg(dev_info, | |
646 | bufptr - dev_info->buf); | |
647 | bufptr = dev_info->buf; | |
648 | ||
649 | } | |
650 | ||
651 | *bufptr++ = 0xAF; | |
652 | *bufptr++ = 0x6A; | |
653 | ||
654 | *bufptr++ = (char)(base >> 16); | |
655 | *bufptr++ = (char)(base >> 8); | |
656 | *bufptr++ = (char)(base); | |
657 | ||
658 | if (rem > 255) { | |
659 | *bufptr++ = 255; | |
660 | *bufptr++ = (char)(source >> 16); | |
661 | *bufptr++ = (char)(source >> 8); | |
662 | *bufptr++ = (char)(source); | |
663 | ||
664 | rem -= 255; | |
665 | base += 255 * 2; | |
666 | source += 255 * 2; | |
667 | ||
668 | } else { | |
669 | *bufptr++ = rem; | |
670 | *bufptr++ = (char)(source >> 16); | |
671 | *bufptr++ = (char)(source >> 8); | |
672 | *bufptr++ = (char)(source); | |
673 | ||
674 | base += rem * 2; | |
675 | source += rem * 2; | |
676 | rem = 0; | |
677 | } | |
678 | } | |
679 | } | |
680 | ||
681 | if (bufptr > dev_info->buf) | |
682 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
683 | ||
684 | mutex_unlock(&dev_info->bulk_mutex); | |
685 | ||
686 | return 1; | |
687 | ||
688 | } | |
689 | ||
88e58b1a RDI |
690 | static int |
691 | copyarea(struct dlfb_data *dev_info, int dx, int dy, int sx, int sy, | |
692 | int width, int height) | |
693 | { | |
88e58b1a RDI |
694 | int base; |
695 | int source; | |
696 | int rem; | |
697 | int i, ret; | |
698 | ||
699 | char *bufptr; | |
700 | ||
f05e0575 | 701 | if (dx + width > dev_info->info->var.xres) |
88e58b1a | 702 | return -EINVAL; |
88e58b1a | 703 | |
f05e0575 | 704 | if (dy + height > dev_info->info->var.yres) |
88e58b1a | 705 | return -EINVAL; |
88e58b1a RDI |
706 | |
707 | mutex_lock(&dev_info->bulk_mutex); | |
708 | ||
709 | base = | |
710 | dev_info->base16 + (dev_info->info->var.xres * 2 * dy) + (dx * 2); | |
711 | source = (dev_info->info->var.xres * 2 * sy) + (sx * 2); | |
712 | ||
713 | bufptr = dev_info->buf; | |
714 | ||
715 | for (i = sy; i < sy + height; i++) { | |
716 | ||
7316bc55 | 717 | memcpy(dev_info->backing_buffer + base - dev_info->base16, |
88e58b1a RDI |
718 | dev_info->backing_buffer + source, width * 2); |
719 | ||
720 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
721 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
722 | bufptr = dev_info->buf; | |
723 | } | |
724 | ||
725 | rem = width; | |
726 | ||
727 | while (rem) { | |
728 | ||
729 | if (dev_info->bufend - bufptr < BUF_HIGH_WATER_MARK) { | |
730 | ret = | |
731 | dlfb_bulk_msg(dev_info, | |
732 | bufptr - dev_info->buf); | |
733 | bufptr = dev_info->buf; | |
734 | } | |
735 | ||
736 | *bufptr++ = 0xAF; | |
737 | *bufptr++ = 0x6A; | |
738 | ||
739 | *bufptr++ = (char)(base >> 16); | |
740 | *bufptr++ = (char)(base >> 8); | |
741 | *bufptr++ = (char)(base); | |
742 | ||
743 | if (rem > 255) { | |
744 | *bufptr++ = 255; | |
745 | *bufptr++ = (char)(source >> 16); | |
746 | *bufptr++ = (char)(source >> 8); | |
747 | *bufptr++ = (char)(source); | |
748 | ||
749 | rem -= 255; | |
750 | base += 255 * 2; | |
751 | source += 255 * 2; | |
752 | ||
753 | } else { | |
754 | *bufptr++ = rem; | |
755 | *bufptr++ = (char)(source >> 16); | |
756 | *bufptr++ = (char)(source >> 8); | |
757 | *bufptr++ = (char)(source); | |
758 | ||
759 | base += rem * 2; | |
760 | source += rem * 2; | |
761 | rem = 0; | |
762 | } | |
88e58b1a RDI |
763 | } |
764 | ||
765 | base += (dev_info->info->var.xres * 2) - (width * 2); | |
766 | source += (dev_info->info->var.xres * 2) - (width * 2); | |
88e58b1a RDI |
767 | } |
768 | ||
f05e0575 | 769 | if (bufptr > dev_info->buf) |
88e58b1a | 770 | ret = dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); |
88e58b1a RDI |
771 | |
772 | mutex_unlock(&dev_info->bulk_mutex); | |
773 | ||
774 | return 1; | |
775 | } | |
776 | ||
4b6a4856 | 777 | static void dlfb_copyarea(struct fb_info *info, const struct fb_copyarea *area) |
88e58b1a RDI |
778 | { |
779 | ||
780 | struct dlfb_data *dev = info->par; | |
781 | ||
782 | copyarea(dev, area->dx, area->dy, area->sx, area->sy, area->width, | |
783 | area->height); | |
88e58b1a RDI |
784 | } |
785 | ||
4b6a4856 | 786 | static void dlfb_imageblit(struct fb_info *info, const struct fb_image *image) |
88e58b1a RDI |
787 | { |
788 | ||
789 | int ret; | |
790 | struct dlfb_data *dev = info->par; | |
88e58b1a RDI |
791 | cfb_imageblit(info, image); |
792 | ret = | |
793 | image_blit(dev, image->dx, image->dy, image->width, image->height, | |
794 | info->screen_base); | |
88e58b1a RDI |
795 | } |
796 | ||
7316bc55 RDI |
797 | static void dlfb_fillrect(struct fb_info *info, |
798 | const struct fb_fillrect *region) | |
88e58b1a RDI |
799 | { |
800 | ||
801 | unsigned char red, green, blue; | |
802 | struct dlfb_data *dev = info->par; | |
803 | ||
804 | memcpy(&red, ®ion->color, 1); | |
805 | memcpy(&green, ®ion->color + 1, 1); | |
806 | memcpy(&blue, ®ion->color + 2, 1); | |
807 | draw_rect(dev, region->dx, region->dy, region->width, region->height, | |
808 | red, green, blue); | |
f05e0575 | 809 | /* printk("FILL RECT %d %d !!!\n", region->dx, region->dy); */ |
88e58b1a RDI |
810 | |
811 | } | |
812 | ||
813 | static int dlfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) | |
814 | { | |
815 | ||
816 | struct dlfb_data *dev_info = info->par; | |
7316bc55 | 817 | struct dloarea *area = NULL; |
88e58b1a | 818 | |
7316bc55 RDI |
819 | if (cmd == 0xAD) { |
820 | char *edid = (char *)arg; | |
821 | dlfb_edid(dev_info); | |
822 | if (copy_to_user(edid, dev_info->edid, 128)) { | |
823 | return -EFAULT; | |
824 | } | |
825 | return 0; | |
826 | } | |
827 | ||
828 | if (cmd == 0xAA || cmd == 0xAB || cmd == 0xAC) { | |
88e58b1a RDI |
829 | |
830 | area = (struct dloarea *)arg; | |
831 | ||
832 | if (area->x < 0) | |
833 | area->x = 0; | |
834 | ||
835 | if (area->x > info->var.xres) | |
836 | area->x = info->var.xres; | |
837 | ||
838 | if (area->y < 0) | |
839 | area->y = 0; | |
840 | ||
841 | if (area->y > info->var.yres) | |
842 | area->y = info->var.yres; | |
7316bc55 | 843 | } |
88e58b1a | 844 | |
7316bc55 | 845 | if (cmd == 0xAA) { |
88e58b1a RDI |
846 | image_blit(dev_info, area->x, area->y, area->w, area->h, |
847 | info->screen_base); | |
848 | } | |
7316bc55 RDI |
849 | if (cmd == 0xAC) { |
850 | copyfb(dev_info); | |
851 | image_blit(dev_info, area->x, area->y, area->w, area->h, | |
852 | info->screen_base); | |
853 | swapfb(dev_info); | |
854 | } else if (cmd == 0xAB) { | |
855 | ||
856 | if (area->x2 < 0) | |
857 | area->x2 = 0; | |
858 | ||
859 | if (area->y2 < 0) | |
860 | area->y2 = 0; | |
861 | ||
862 | copyarea(dev_info, | |
863 | area->x2, area->y2, area->x, area->y, area->w, | |
864 | area->h); | |
865 | } | |
88e58b1a RDI |
866 | return 0; |
867 | } | |
868 | ||
f05e0575 | 869 | /* taken from vesafb */ |
88e58b1a RDI |
870 | static int |
871 | dlfb_setcolreg(unsigned regno, unsigned red, unsigned green, | |
872 | unsigned blue, unsigned transp, struct fb_info *info) | |
873 | { | |
874 | int err = 0; | |
875 | ||
876 | if (regno >= info->cmap.len) | |
877 | return 1; | |
878 | ||
879 | if (regno < 16) { | |
880 | if (info->var.red.offset == 10) { | |
881 | /* 1:5:5:5 */ | |
882 | ((u32 *) (info->pseudo_palette))[regno] = | |
883 | ((red & 0xf800) >> 1) | | |
884 | ((green & 0xf800) >> 6) | ((blue & 0xf800) >> 11); | |
885 | } else { | |
886 | /* 0:5:6:5 */ | |
887 | ((u32 *) (info->pseudo_palette))[regno] = | |
888 | ((red & 0xf800)) | | |
889 | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); | |
890 | } | |
891 | } | |
892 | ||
893 | return err; | |
894 | } | |
895 | ||
896 | static int dlfb_release(struct fb_info *info, int user) | |
897 | { | |
898 | struct dlfb_data *dev_info = info->par; | |
899 | image_blit(dev_info, 0, 0, info->var.xres, info->var.yres, | |
900 | info->screen_base); | |
901 | return 0; | |
902 | } | |
903 | ||
f05e0575 GKH |
904 | static int dlfb_blank(int blank_mode, struct fb_info *info) |
905 | { | |
7316bc55 RDI |
906 | struct dlfb_data *dev_info = info->par; |
907 | char *bufptr = dev_info->buf; | |
908 | ||
909 | bufptr = dlfb_set_register(bufptr, 0xFF, 0x00); | |
910 | if (blank_mode != FB_BLANK_UNBLANK) { | |
911 | bufptr = dlfb_set_register(bufptr, 0x1F, 0x01); | |
912 | } else { | |
913 | bufptr = dlfb_set_register(bufptr, 0x1F, 0x00); | |
914 | } | |
915 | bufptr = dlfb_set_register(bufptr, 0xFF, 0xFF); | |
916 | ||
917 | dlfb_bulk_msg(dev_info, bufptr - dev_info->buf); | |
918 | ||
88e58b1a RDI |
919 | return 0; |
920 | } | |
921 | ||
922 | static struct fb_ops dlfb_ops = { | |
88e58b1a RDI |
923 | .fb_setcolreg = dlfb_setcolreg, |
924 | .fb_fillrect = dlfb_fillrect, | |
925 | .fb_copyarea = dlfb_copyarea, | |
926 | .fb_imageblit = dlfb_imageblit, | |
927 | .fb_mmap = dlfb_mmap, | |
928 | .fb_ioctl = dlfb_ioctl, | |
929 | .fb_release = dlfb_release, | |
930 | .fb_blank = dlfb_blank, | |
931 | }; | |
932 | ||
cc403dc6 BT |
933 | /* |
934 | * This is necessary before we can communicate with the display controller. | |
935 | */ | |
936 | static int dlfb_select_std_channel(struct dlfb_data *dev) | |
937 | { | |
938 | int ret; | |
939 | u8 set_def_chn[] = { 0x57, 0xCD, 0xDC, 0xA7, | |
940 | 0x1C, 0x88, 0x5E, 0x15, | |
941 | 0x60, 0xFE, 0xC6, 0x97, | |
942 | 0x16, 0x3D, 0x47, 0xF2 }; | |
943 | ||
944 | ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), | |
945 | NR_USB_REQUEST_CHANNEL, | |
946 | (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0, | |
947 | set_def_chn, sizeof(set_def_chn), USB_CTRL_SET_TIMEOUT); | |
948 | return ret; | |
949 | } | |
950 | ||
59277b67 BT |
951 | static int dlfb_probe(struct usb_interface *interface, |
952 | const struct usb_device_id *id) | |
88e58b1a | 953 | { |
59277b67 BT |
954 | struct device *mydev; |
955 | struct usb_device *usbdev; | |
956 | struct dlfb_data *dev; | |
88e58b1a | 957 | struct fb_info *info; |
59277b67 BT |
958 | int videomemorysize; |
959 | unsigned char *videomemory; | |
960 | int retval = -ENOMEM; | |
961 | struct fb_var_screeninfo *var; | |
962 | struct fb_bitfield red = { 11, 5, 0 }; | |
963 | struct fb_bitfield green = { 5, 6, 0 }; | |
964 | struct fb_bitfield blue = { 0, 5, 0 }; | |
965 | ||
966 | usbdev = usb_get_dev(interface_to_usbdev(interface)); | |
967 | mydev = &usbdev->dev; | |
968 | ||
969 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); | |
970 | if (dev == NULL) { | |
971 | dev_err(mydev, "failed alloc of dev struct\n"); | |
972 | goto err_devalloc; | |
88e58b1a | 973 | } |
88e58b1a | 974 | |
59277b67 BT |
975 | mutex_init(&dev->bulk_mutex); |
976 | dev->udev = usbdev; | |
977 | dev->interface = interface; | |
978 | usb_set_intfdata(interface, dev); | |
979 | ||
980 | dev_info(mydev, "dlfb_probe: setting up DisplayLink device\n"); | |
981 | ||
982 | /* | |
983 | * TODO: replace single 64K buffer with buffer list | |
984 | * and async dispatch | |
985 | */ | |
986 | dev->buf = kmalloc(BUF_SIZE, GFP_KERNEL); | |
987 | if (dev->buf == NULL) { | |
988 | dev_err(mydev, "unable to allocate memory for dlfb commands\n"); | |
989 | goto err_usballoc; | |
88e58b1a | 990 | } |
59277b67 BT |
991 | dev->bufend = dev->buf + BUF_SIZE; |
992 | ||
993 | dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL); | |
994 | usb_fill_bulk_urb(dev->tx_urb, dev->udev, | |
995 | usb_sndbulkpipe(dev->udev, 1), dev->buf, 0, | |
996 | dlfb_bulk_callback, dev); | |
997 | ||
998 | /* allocates framebuffer driver structure, not framebuffer memory */ | |
999 | info = framebuffer_alloc(0, mydev); | |
1000 | if (!info) | |
1001 | goto err_fballoc; | |
1002 | ||
1003 | dev->info = info; | |
1004 | info->par = dev; | |
1005 | info->pseudo_palette = dev->pseudo_palette; | |
1006 | ||
1007 | var = &info->var; | |
1008 | retval = dlfb_get_var_from_edid(dev, var); | |
1009 | if (retval) { | |
1010 | /* had a problem getting edid. so fallback to 640x480 */ | |
1011 | dev_err(mydev, "Problem %d with EDID.\n", retval); | |
1012 | var->xres = 640; | |
1013 | var->yres = 480; | |
7316bc55 | 1014 | } |
88e58b1a | 1015 | |
59277b67 BT |
1016 | /* |
1017 | * ok, now that we've got the size info, we can alloc our framebuffer. | |
1018 | * We are using 16bpp. | |
1019 | */ | |
1020 | info->var.bits_per_pixel = 16; | |
1021 | info->fix = dlfb_fix; | |
1022 | info->fix.line_length = var->xres * (var->bits_per_pixel / 8); | |
1023 | videomemorysize = info->fix.line_length * var->yres; | |
1024 | ||
1025 | /* | |
1026 | * The big chunk of system memory we use as a virtual framebuffer. | |
1027 | * Pages don't need to be set RESERVED (non-swap) immediately on 2.6 | |
1028 | * remap_pfn_page() syscall in our mmap and/or defio will handle. | |
1029 | */ | |
1030 | videomemory = vmalloc(videomemorysize); | |
1031 | if (!videomemory) | |
1032 | goto err_vidmem; | |
1033 | memset(videomemory, 0, videomemorysize); | |
1034 | ||
1035 | info->screen_base = videomemory; | |
1036 | info->fix.smem_len = PAGE_ALIGN(videomemorysize); | |
1037 | info->fix.smem_start = (unsigned long) videomemory; | |
88e58b1a RDI |
1038 | info->flags = |
1039 | FBINFO_DEFAULT | FBINFO_READS_FAST | FBINFO_HWACCEL_IMAGEBLIT | | |
1040 | FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT; | |
88e58b1a | 1041 | |
59277b67 BT |
1042 | /* |
1043 | * Second framebuffer copy, mirroring the state of the framebuffer | |
1044 | * on the physical USB device. We can function without this. | |
1045 | * But with imperfect damage info we may end up sending pixels over USB | |
1046 | * that were, in fact, unchanged -- wasting limited USB bandwidth | |
1047 | */ | |
1048 | dev->backing_buffer = vmalloc(dev->screen_size); | |
1049 | if (!dev->backing_buffer) | |
1050 | dev_info(mydev, "No backing buffer allocated!\n"); | |
f05e0575 | 1051 | |
59277b67 | 1052 | info->fbops = &dlfb_ops; |
88e58b1a | 1053 | |
59277b67 BT |
1054 | var->vmode = FB_VMODE_NONINTERLACED; |
1055 | var->red = red; | |
1056 | var->green = green; | |
1057 | var->blue = blue; | |
88e58b1a | 1058 | |
59277b67 BT |
1059 | /* |
1060 | * TODO: Enable FB_CONFIG_DEFIO support | |
88e58b1a | 1061 | |
59277b67 BT |
1062 | info->fbdefio = &dlfb_defio; |
1063 | fb_deferred_io_init(info); | |
88e58b1a | 1064 | |
59277b67 | 1065 | */ |
88e58b1a | 1066 | |
59277b67 BT |
1067 | retval = fb_alloc_cmap(&info->cmap, 256, 0); |
1068 | if (retval < 0) { | |
1069 | dev_err(mydev, "Failed to allocate colormap\n"); | |
1070 | goto err_cmap; | |
7316bc55 | 1071 | } |
88e58b1a | 1072 | |
59277b67 BT |
1073 | dlfb_select_std_channel(dev); |
1074 | dlfb_set_video_mode(dev, var); | |
1075 | /* TODO: dlfb_dpy_update(dev); */ | |
88e58b1a | 1076 | |
59277b67 BT |
1077 | retval = register_framebuffer(info); |
1078 | if (retval < 0) | |
1079 | goto err_regfb; | |
88e58b1a | 1080 | |
59277b67 BT |
1081 | /* paint "successful" green screen */ |
1082 | draw_rect(dev, 0, 0, dev->info->var.xres, | |
1083 | dev->info->var.yres, 0x30, 0xff, 0x30); | |
88e58b1a | 1084 | |
59277b67 BT |
1085 | dev_info(mydev, "DisplayLink USB device %d now attached, " |
1086 | "using %dK of memory\n", info->node, | |
1087 | ((dev->backing_buffer) ? | |
1088 | videomemorysize * 2 : videomemorysize) >> 10); | |
88e58b1a RDI |
1089 | return 0; |
1090 | ||
59277b67 | 1091 | err_regfb: |
88e58b1a | 1092 | fb_dealloc_cmap(&info->cmap); |
59277b67 BT |
1093 | err_cmap: |
1094 | /* TODO: fb_deferred_io_cleanup(info); */ | |
1095 | vfree(videomemory); | |
1096 | err_vidmem: | |
88e58b1a | 1097 | framebuffer_release(info); |
59277b67 BT |
1098 | err_fballoc: |
1099 | kfree(dev->buf); | |
1100 | err_usballoc: | |
88e58b1a | 1101 | usb_set_intfdata(interface, NULL); |
59277b67 BT |
1102 | usb_put_dev(dev->udev); |
1103 | kfree(dev); | |
1104 | err_devalloc: | |
1105 | return retval; | |
88e58b1a RDI |
1106 | } |
1107 | ||
1108 | static void dlfb_disconnect(struct usb_interface *interface) | |
1109 | { | |
59277b67 BT |
1110 | struct dlfb_data *dev; |
1111 | struct fb_info *info; | |
88e58b1a | 1112 | |
59277b67 | 1113 | dev = usb_get_intfdata(interface); |
88e58b1a | 1114 | usb_set_intfdata(interface, NULL); |
59277b67 BT |
1115 | usb_put_dev(dev->udev); |
1116 | ||
1117 | /* | |
1118 | * TODO: since, upon usb disconnect(), usb will cancel in-flight urbs | |
1119 | * and error out any new ones, look at eliminating need for mutex | |
1120 | */ | |
1121 | mutex_lock(&dev->bulk_mutex); | |
1122 | dev->interface = NULL; | |
1123 | info = dev->info; | |
1124 | mutex_unlock(&dev->bulk_mutex); | |
1125 | ||
1126 | if (info) { | |
1127 | dev_info(&interface->dev, "Detaching DisplayLink device %d.\n", | |
1128 | info->node); | |
1129 | unregister_framebuffer(info); | |
1130 | fb_dealloc_cmap(&info->cmap); | |
1131 | /* TODO: fb_deferred_io_cleanup(info); */ | |
1132 | fb_dealloc_cmap(&info->cmap); | |
1133 | vfree((void __force *)info->screen_base); | |
1134 | framebuffer_release(info); | |
88e58b1a RDI |
1135 | } |
1136 | ||
59277b67 BT |
1137 | if (dev->backing_buffer) |
1138 | vfree(dev->backing_buffer); | |
88e58b1a | 1139 | |
59277b67 | 1140 | kfree(dev); |
88e58b1a RDI |
1141 | } |
1142 | ||
1143 | static struct usb_driver dlfb_driver = { | |
1144 | .name = "udlfb", | |
1145 | .probe = dlfb_probe, | |
1146 | .disconnect = dlfb_disconnect, | |
1147 | .id_table = id_table, | |
1148 | }; | |
1149 | ||
1150 | static int __init dlfb_init(void) | |
1151 | { | |
1152 | int res; | |
1153 | ||
88e58b1a RDI |
1154 | res = usb_register(&dlfb_driver); |
1155 | if (res) | |
1156 | err("usb_register failed. Error number %d", res); | |
1157 | ||
1158 | printk("VMODES initialized\n"); | |
1159 | ||
1160 | return res; | |
1161 | } | |
1162 | ||
1163 | static void __exit dlfb_exit(void) | |
1164 | { | |
1165 | usb_deregister(&dlfb_driver); | |
1166 | } | |
1167 | ||
1168 | module_init(dlfb_init); | |
1169 | module_exit(dlfb_exit); | |
1170 | ||
59277b67 BT |
1171 | MODULE_AUTHOR("Roberto De Ioris <roberto@unbit.it>, " |
1172 | "Jaya Kumar <jayakumar.lkml@gmail.com>"); | |
88e58b1a RDI |
1173 | MODULE_DESCRIPTION(DRIVER_VERSION); |
1174 | MODULE_LICENSE("GPL"); |