Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 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> |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 6 | * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com> |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License v2. See the file COPYING in the main directory of this archive for |
| 10 | * more details. |
| 11 | * |
| 12 | * Layout is based on skeletonfb by James Simmons and Geert Uytterhoeven, |
| 13 | * usb-skeleton by GregKH. |
| 14 | * |
| 15 | * Device-specific portions based on information from Displaylink, with work |
| 16 | * from Florian Echtler, Henrik Bjerregaard Pedersen, and others. |
| 17 | */ |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 18 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/usb.h> |
| 25 | #include <linux/uaccess.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/fb.h> |
Amit Kucheria | fb29900 | 2009-07-27 12:01:03 +0300 | [diff] [blame] | 28 | #include <linux/vmalloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Linus Torvalds | 268bb0c | 2011-05-20 12:50:29 -0700 | [diff] [blame] | 30 | #include <linux/prefetch.h> |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 31 | #include <linux/delay.h> |
Paul Mundt | 96f8d864 | 2010-11-16 14:00:24 +0900 | [diff] [blame] | 32 | #include <video/udlfb.h> |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 33 | #include "edid.h" |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 34 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 35 | static struct fb_fix_screeninfo dlfb_fix = { |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 36 | .id = "udlfb", |
Bernie Thompson | 1d31a9e | 2010-02-15 06:45:43 -0800 | [diff] [blame] | 37 | .type = FB_TYPE_PACKED_PIXELS, |
| 38 | .visual = FB_VISUAL_TRUECOLOR, |
| 39 | .xpanstep = 0, |
| 40 | .ypanstep = 0, |
| 41 | .ywrapstep = 0, |
| 42 | .accel = FB_ACCEL_NONE, |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 43 | }; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 44 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 45 | static const u32 udlfb_info_flags = FBINFO_DEFAULT | FBINFO_READS_FAST | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 46 | FBINFO_VIRTFB | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 47 | FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT | |
| 48 | FBINFO_HWACCEL_COPYAREA | FBINFO_MISC_ALWAYS_SETPAR; |
| 49 | |
Bernie Thompson | cc403dc | 2010-02-15 06:45:49 -0800 | [diff] [blame] | 50 | /* |
| 51 | * There are many DisplayLink-based products, all with unique PIDs. We are able |
| 52 | * to support all volume ones (circa 2009) with a single driver, so we match |
| 53 | * globally on VID. TODO: Probe() needs to detect when we might be running |
| 54 | * "future" chips, and bail on those, so a compatible driver can match. |
| 55 | */ |
| 56 | static struct usb_device_id id_table[] = { |
| 57 | {.idVendor = 0x17e9, .match_flags = USB_DEVICE_ID_MATCH_VENDOR,}, |
| 58 | {}, |
| 59 | }; |
| 60 | MODULE_DEVICE_TABLE(usb, id_table); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 61 | |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 62 | /* module options */ |
| 63 | static int console; /* Optionally allow fbcon to consume first framebuffer */ |
| 64 | static int fb_defio; /* Optionally enable experimental fb_defio mmap support */ |
Bernie Thompson | dd8015f | 2010-02-15 06:46:35 -0800 | [diff] [blame] | 65 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 66 | /* dlfb keeps a list of urbs for efficient bulk transfers */ |
| 67 | static void dlfb_urb_completion(struct urb *urb); |
| 68 | static struct urb *dlfb_get_urb(struct dlfb_data *dev); |
| 69 | static int dlfb_submit_urb(struct dlfb_data *dev, struct urb * urb, size_t len); |
| 70 | static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size); |
| 71 | static void dlfb_free_urb_list(struct dlfb_data *dev); |
| 72 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 73 | /* |
Bernie Thompson | bd80816 | 2010-02-15 06:46:48 -0800 | [diff] [blame] | 74 | * All DisplayLink bulk operations start with 0xAF, followed by specific code |
| 75 | * All operations are written to buffers which then later get sent to device |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 76 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 77 | static char *dlfb_set_register(char *buf, u8 reg, u8 val) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 78 | { |
Bernie Thompson | 1d31a9e | 2010-02-15 06:45:43 -0800 | [diff] [blame] | 79 | *buf++ = 0xAF; |
| 80 | *buf++ = 0x20; |
| 81 | *buf++ = reg; |
| 82 | *buf++ = val; |
| 83 | return buf; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 86 | static char *dlfb_vidreg_lock(char *buf) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 87 | { |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 88 | return dlfb_set_register(buf, 0xFF, 0x00); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 89 | } |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 90 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 91 | static char *dlfb_vidreg_unlock(char *buf) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 92 | { |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 93 | return dlfb_set_register(buf, 0xFF, 0xFF); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 94 | } |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 95 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 96 | /* |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 97 | * On/Off for driving the DisplayLink framebuffer to the display |
Bernie Thompson | 9825f70 | 2010-09-05 16:35:10 -0700 | [diff] [blame] | 98 | * 0x00 H and V sync on |
| 99 | * 0x01 H and V sync off (screen blank but powered) |
| 100 | * 0x07 DPMS powerdown (requires modeset to come back) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 101 | */ |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 102 | static char *dlfb_enable_hvsync(char *buf, bool enable) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 103 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 104 | if (enable) |
| 105 | return dlfb_set_register(buf, 0x1F, 0x00); |
| 106 | else |
Bernie Thompson | 9825f70 | 2010-09-05 16:35:10 -0700 | [diff] [blame] | 107 | return dlfb_set_register(buf, 0x1F, 0x07); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 110 | static char *dlfb_set_color_depth(char *buf, u8 selection) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 111 | { |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 112 | return dlfb_set_register(buf, 0x00, selection); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 113 | } |
| 114 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 115 | static char *dlfb_set_base16bpp(char *wrptr, u32 base) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 116 | { |
Bernie Thompson | 1d31a9e | 2010-02-15 06:45:43 -0800 | [diff] [blame] | 117 | /* the base pointer is 16 bits wide, 0x20 is hi byte. */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 118 | wrptr = dlfb_set_register(wrptr, 0x20, base >> 16); |
| 119 | wrptr = dlfb_set_register(wrptr, 0x21, base >> 8); |
| 120 | return dlfb_set_register(wrptr, 0x22, base); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Bernie Thompson | bd80816 | 2010-02-15 06:46:48 -0800 | [diff] [blame] | 123 | /* |
| 124 | * DisplayLink HW has separate 16bpp and 8bpp framebuffers. |
| 125 | * In 24bpp modes, the low 323 RGB bits go in the 8bpp framebuffer |
| 126 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 127 | static char *dlfb_set_base8bpp(char *wrptr, u32 base) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 128 | { |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 129 | wrptr = dlfb_set_register(wrptr, 0x26, base >> 16); |
| 130 | wrptr = dlfb_set_register(wrptr, 0x27, base >> 8); |
| 131 | return dlfb_set_register(wrptr, 0x28, base); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 134 | static char *dlfb_set_register_16(char *wrptr, u8 reg, u16 value) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 135 | { |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 136 | wrptr = dlfb_set_register(wrptr, reg, value >> 8); |
| 137 | return dlfb_set_register(wrptr, reg+1, value); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* |
| 141 | * This is kind of weird because the controller takes some |
| 142 | * register values in a different byte order than other registers. |
| 143 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 144 | static char *dlfb_set_register_16be(char *wrptr, u8 reg, u16 value) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 145 | { |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 146 | wrptr = dlfb_set_register(wrptr, reg, value); |
| 147 | return dlfb_set_register(wrptr, reg+1, value >> 8); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | /* |
| 151 | * LFSR is linear feedback shift register. The reason we have this is |
| 152 | * because the display controller needs to minimize the clock depth of |
| 153 | * various counters used in the display path. So this code reverses the |
| 154 | * provided value into the lfsr16 value by counting backwards to get |
| 155 | * the value that needs to be set in the hardware comparator to get the |
| 156 | * same actual count. This makes sense once you read above a couple of |
| 157 | * times and think about it from a hardware perspective. |
| 158 | */ |
Bernie Thompson | bd80816 | 2010-02-15 06:46:48 -0800 | [diff] [blame] | 159 | static u16 dlfb_lfsr16(u16 actual_count) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 160 | { |
| 161 | u32 lv = 0xFFFF; /* This is the lfsr value that the hw starts with */ |
| 162 | |
| 163 | while (actual_count--) { |
| 164 | lv = ((lv << 1) | |
| 165 | (((lv >> 15) ^ (lv >> 4) ^ (lv >> 2) ^ (lv >> 1)) & 1)) |
| 166 | & 0xFFFF; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 167 | } |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 168 | |
| 169 | return (u16) lv; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * This does LFSR conversion on the value that is to be written. |
| 174 | * See LFSR explanation above for more detail. |
| 175 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 176 | static char *dlfb_set_register_lfsr16(char *wrptr, u8 reg, u16 value) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 177 | { |
Bernie Thompson | bd80816 | 2010-02-15 06:46:48 -0800 | [diff] [blame] | 178 | return dlfb_set_register_16(wrptr, reg, dlfb_lfsr16(value)); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | /* |
| 182 | * This takes a standard fbdev screeninfo struct and all of its monitor mode |
| 183 | * details and converts them into the DisplayLink equivalent register commands. |
| 184 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 185 | static char *dlfb_set_vid_cmds(char *wrptr, struct fb_var_screeninfo *var) |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 186 | { |
| 187 | u16 xds, yds; |
| 188 | u16 xde, yde; |
| 189 | u16 yec; |
| 190 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 191 | /* x display start */ |
| 192 | xds = var->left_margin + var->hsync_len; |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 193 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x01, xds); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 194 | /* x display end */ |
| 195 | xde = xds + var->xres; |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 196 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x03, xde); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 197 | |
| 198 | /* y display start */ |
| 199 | yds = var->upper_margin + var->vsync_len; |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 200 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x05, yds); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 201 | /* y display end */ |
| 202 | yde = yds + var->yres; |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 203 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x07, yde); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 204 | |
| 205 | /* x end count is active + blanking - 1 */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 206 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x09, |
| 207 | xde + var->right_margin - 1); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 208 | |
| 209 | /* libdlo hardcodes hsync start to 1 */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 210 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x0B, 1); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 211 | |
| 212 | /* hsync end is width of sync pulse + 1 */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 213 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x0D, var->hsync_len + 1); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 214 | |
| 215 | /* hpixels is active pixels */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 216 | wrptr = dlfb_set_register_16(wrptr, 0x0F, var->xres); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 217 | |
| 218 | /* yendcount is vertical active + vertical blanking */ |
| 219 | yec = var->yres + var->upper_margin + var->lower_margin + |
| 220 | var->vsync_len; |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 221 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x11, yec); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 222 | |
| 223 | /* libdlo hardcodes vsync start to 0 */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 224 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x13, 0); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 225 | |
| 226 | /* vsync end is width of vsync pulse */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 227 | wrptr = dlfb_set_register_lfsr16(wrptr, 0x15, var->vsync_len); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 228 | |
| 229 | /* vpixels is active pixels */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 230 | wrptr = dlfb_set_register_16(wrptr, 0x17, var->yres); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 231 | |
| 232 | /* convert picoseconds to 5kHz multiple for pclk5k = x * 1E12/5k */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 233 | wrptr = dlfb_set_register_16be(wrptr, 0x1B, |
| 234 | 200*1000*1000/var->pixclock); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 235 | |
| 236 | return wrptr; |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * This takes a standard fbdev screeninfo struct that was fetched or prepared |
| 241 | * and then generates the appropriate command sequence that then drives the |
| 242 | * display controller. |
| 243 | */ |
| 244 | static int dlfb_set_video_mode(struct dlfb_data *dev, |
| 245 | struct fb_var_screeninfo *var) |
| 246 | { |
| 247 | char *buf; |
| 248 | char *wrptr; |
| 249 | int retval = 0; |
| 250 | int writesize; |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 251 | struct urb *urb; |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 252 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 253 | if (!atomic_read(&dev->usb_active)) |
| 254 | return -EPERM; |
| 255 | |
| 256 | urb = dlfb_get_urb(dev); |
| 257 | if (!urb) |
| 258 | return -ENOMEM; |
Bernie Thompson | 2685cff | 2010-09-05 18:29:56 -0700 | [diff] [blame] | 259 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 260 | buf = (char *) urb->transfer_buffer; |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * This first section has to do with setting the base address on the |
| 264 | * controller * associated with the display. There are 2 base |
| 265 | * pointers, currently, we only * use the 16 bpp segment. |
| 266 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 267 | wrptr = dlfb_vidreg_lock(buf); |
| 268 | wrptr = dlfb_set_color_depth(wrptr, 0x00); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 269 | /* set base for 16bpp segment to 0 */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 270 | wrptr = dlfb_set_base16bpp(wrptr, 0); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 271 | /* set base for 8bpp segment to end of fb */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 272 | wrptr = dlfb_set_base8bpp(wrptr, dev->info->fix.smem_len); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 273 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 274 | wrptr = dlfb_set_vid_cmds(wrptr, var); |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 275 | wrptr = dlfb_enable_hvsync(wrptr, true); |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 276 | wrptr = dlfb_vidreg_unlock(wrptr); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 277 | |
| 278 | writesize = wrptr - buf; |
| 279 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 280 | retval = dlfb_submit_urb(dev, urb, writesize); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 281 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 282 | return retval; |
| 283 | } |
| 284 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 285 | static int dlfb_ops_mmap(struct fb_info *info, struct vm_area_struct *vma) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 286 | { |
| 287 | unsigned long start = vma->vm_start; |
| 288 | unsigned long size = vma->vm_end - vma->vm_start; |
| 289 | unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; |
| 290 | unsigned long page, pos; |
| 291 | |
Greg Kroah-Hartman | f05e057 | 2009-06-03 14:47:08 -0700 | [diff] [blame] | 292 | if (offset + size > info->fix.smem_len) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 293 | return -EINVAL; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 294 | |
| 295 | pos = (unsigned long)info->fix.smem_start + offset; |
| 296 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 297 | pr_notice("mmap() framebuffer addr:%lu size:%lu\n", |
Bernie Thompson | 2685cff | 2010-09-05 18:29:56 -0700 | [diff] [blame] | 298 | pos, size); |
| 299 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 300 | while (size > 0) { |
| 301 | page = vmalloc_to_pfn((void *)pos); |
Greg Kroah-Hartman | f05e057 | 2009-06-03 14:47:08 -0700 | [diff] [blame] | 302 | if (remap_pfn_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 303 | return -EAGAIN; |
Greg Kroah-Hartman | f05e057 | 2009-06-03 14:47:08 -0700 | [diff] [blame] | 304 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 305 | start += PAGE_SIZE; |
| 306 | pos += PAGE_SIZE; |
| 307 | if (size > PAGE_SIZE) |
| 308 | size -= PAGE_SIZE; |
| 309 | else |
| 310 | size = 0; |
| 311 | } |
| 312 | |
| 313 | vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */ |
| 314 | return 0; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 315 | } |
| 316 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 317 | /* |
| 318 | * Trims identical data from front and back of line |
| 319 | * Sets new front buffer address and width |
| 320 | * And returns byte count of identical pixels |
| 321 | * Assumes CPU natural alignment (unsigned long) |
| 322 | * for back and front buffer ptrs and width |
| 323 | */ |
| 324 | static int dlfb_trim_hline(const u8 *bback, const u8 **bfront, int *width_bytes) |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 325 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 326 | int j, k; |
| 327 | const unsigned long *back = (const unsigned long *) bback; |
| 328 | const unsigned long *front = (const unsigned long *) *bfront; |
| 329 | const int width = *width_bytes / sizeof(unsigned long); |
| 330 | int identical = width; |
| 331 | int start = width; |
| 332 | int end = width; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 333 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 334 | prefetch((void *) front); |
| 335 | prefetch((void *) back); |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 336 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 337 | for (j = 0; j < width; j++) { |
| 338 | if (back[j] != front[j]) { |
| 339 | start = j; |
| 340 | break; |
| 341 | } |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 344 | for (k = width - 1; k > j; k--) { |
| 345 | if (back[k] != front[k]) { |
| 346 | end = k+1; |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | identical = start + (width - end); |
| 352 | *bfront = (u8 *) &front[start]; |
| 353 | *width_bytes = (end - start) * sizeof(unsigned long); |
| 354 | |
| 355 | return identical * sizeof(unsigned long); |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | /* |
Pavel Machek | 3b7b31f | 2010-04-03 07:00:37 +0200 | [diff] [blame] | 359 | * Render a command stream for an encoded horizontal line segment of pixels. |
| 360 | * |
| 361 | * A command buffer holds several commands. |
| 362 | * It always begins with a fresh command header |
| 363 | * (the protocol doesn't require this, but we enforce it to allow |
| 364 | * multiple buffers to be potentially encoded and sent in parallel). |
| 365 | * A single command encodes one contiguous horizontal line of pixels |
| 366 | * |
| 367 | * The function relies on the client to do all allocation, so that |
| 368 | * rendering can be done directly to output buffers (e.g. USB URBs). |
| 369 | * The function fills the supplied command buffer, providing information |
| 370 | * on where it left off, so the client may call in again with additional |
| 371 | * buffers if the line will take several buffers to complete. |
| 372 | * |
| 373 | * A single command can transmit a maximum of 256 pixels, |
| 374 | * regardless of the compression ratio (protocol design limit). |
| 375 | * To the hardware, 0 for a size byte means 256 |
Bernie Thompson | 2685cff | 2010-09-05 18:29:56 -0700 | [diff] [blame] | 376 | * |
Pavel Machek | 3b7b31f | 2010-04-03 07:00:37 +0200 | [diff] [blame] | 377 | * Rather than 256 pixel commands which are either rl or raw encoded, |
| 378 | * the rlx command simply assumes alternating raw and rl spans within one cmd. |
| 379 | * This has a slightly larger header overhead, but produces more even results. |
| 380 | * It also processes all data (read and write) in a single pass. |
| 381 | * Performance benchmarks of common cases show it having just slightly better |
Bernie Thompson | 2685cff | 2010-09-05 18:29:56 -0700 | [diff] [blame] | 382 | * compression than 256 pixel raw or rle commands, with similar CPU consumpion. |
Pavel Machek | 3b7b31f | 2010-04-03 07:00:37 +0200 | [diff] [blame] | 383 | * But for very rl friendly data, will compress not quite as well. |
| 384 | */ |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 385 | static void dlfb_compress_hline( |
| 386 | const uint16_t **pixel_start_ptr, |
| 387 | const uint16_t *const pixel_end, |
| 388 | uint32_t *device_address_ptr, |
| 389 | uint8_t **command_buffer_ptr, |
| 390 | const uint8_t *const cmd_buffer_end) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 391 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 392 | const uint16_t *pixel = *pixel_start_ptr; |
| 393 | uint32_t dev_addr = *device_address_ptr; |
| 394 | uint8_t *cmd = *command_buffer_ptr; |
| 395 | const int bpp = 2; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 396 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 397 | while ((pixel_end > pixel) && |
| 398 | (cmd_buffer_end - MIN_RLX_CMD_BYTES > cmd)) { |
| 399 | uint8_t *raw_pixels_count_byte = 0; |
| 400 | uint8_t *cmd_pixels_count_byte = 0; |
| 401 | const uint16_t *raw_pixel_start = 0; |
| 402 | const uint16_t *cmd_pixel_start, *cmd_pixel_end = 0; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 403 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 404 | prefetchw((void *) cmd); /* pull in one cache line at least */ |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 405 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 406 | *cmd++ = 0xAF; |
| 407 | *cmd++ = 0x6B; |
Bernie Thompson | 1572f91 | 2010-09-05 16:35:27 -0700 | [diff] [blame] | 408 | *cmd++ = (uint8_t) ((dev_addr >> 16) & 0xFF); |
| 409 | *cmd++ = (uint8_t) ((dev_addr >> 8) & 0xFF); |
| 410 | *cmd++ = (uint8_t) ((dev_addr) & 0xFF); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 411 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 412 | cmd_pixels_count_byte = cmd++; /* we'll know this later */ |
| 413 | cmd_pixel_start = pixel; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 414 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 415 | raw_pixels_count_byte = cmd++; /* we'll know this later */ |
| 416 | raw_pixel_start = pixel; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 417 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 418 | cmd_pixel_end = pixel + min(MAX_CMD_PIXELS + 1, |
| 419 | min((int)(pixel_end - pixel), |
| 420 | (int)(cmd_buffer_end - cmd) / bpp)); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 421 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 422 | prefetch_range((void *) pixel, (cmd_pixel_end - pixel) * bpp); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 423 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 424 | while (pixel < cmd_pixel_end) { |
| 425 | const uint16_t * const repeating_pixel = pixel; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 426 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 427 | *(uint16_t *)cmd = cpu_to_be16p(pixel); |
| 428 | cmd += 2; |
| 429 | pixel++; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 430 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 431 | if (unlikely((pixel < cmd_pixel_end) && |
| 432 | (*pixel == *repeating_pixel))) { |
| 433 | /* go back and fill in raw pixel count */ |
| 434 | *raw_pixels_count_byte = ((repeating_pixel - |
| 435 | raw_pixel_start) + 1) & 0xFF; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 436 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 437 | while ((pixel < cmd_pixel_end) |
| 438 | && (*pixel == *repeating_pixel)) { |
| 439 | pixel++; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 440 | } |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 441 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 442 | /* immediately after raw data is repeat byte */ |
| 443 | *cmd++ = ((pixel - repeating_pixel) - 1) & 0xFF; |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 444 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 445 | /* Then start another raw pixel span */ |
| 446 | raw_pixel_start = pixel; |
| 447 | raw_pixels_count_byte = cmd++; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 448 | } |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 451 | if (pixel > raw_pixel_start) { |
| 452 | /* finalize last RAW span */ |
| 453 | *raw_pixels_count_byte = (pixel-raw_pixel_start) & 0xFF; |
| 454 | } |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 455 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 456 | *cmd_pixels_count_byte = (pixel - cmd_pixel_start) & 0xFF; |
| 457 | dev_addr += (pixel - cmd_pixel_start) * bpp; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 458 | } |
| 459 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 460 | if (cmd_buffer_end <= MIN_RLX_CMD_BYTES + cmd) { |
| 461 | /* Fill leftover bytes with no-ops */ |
| 462 | if (cmd_buffer_end > cmd) |
| 463 | memset(cmd, 0xAF, cmd_buffer_end - cmd); |
| 464 | cmd = (uint8_t *) cmd_buffer_end; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 465 | } |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 466 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 467 | *command_buffer_ptr = cmd; |
| 468 | *pixel_start_ptr = pixel; |
| 469 | *device_address_ptr = dev_addr; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 470 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 471 | return; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 474 | /* |
| 475 | * There are 3 copies of every pixel: The front buffer that the fbdev |
| 476 | * client renders to, the actual framebuffer across the USB bus in hardware |
| 477 | * (that we can only write to, slowly, and can never read), and (optionally) |
| 478 | * our shadow copy that tracks what's been sent to that hardware buffer. |
| 479 | */ |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 480 | static int dlfb_render_hline(struct dlfb_data *dev, struct urb **urb_ptr, |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 481 | const char *front, char **urb_buf_ptr, |
| 482 | u32 byte_offset, u32 byte_width, |
| 483 | int *ident_ptr, int *sent_ptr) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 484 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 485 | const u8 *line_start, *line_end, *next_pixel; |
| 486 | u32 dev_addr = dev->base16 + byte_offset; |
| 487 | struct urb *urb = *urb_ptr; |
| 488 | u8 *cmd = *urb_buf_ptr; |
| 489 | u8 *cmd_end = (u8 *) urb->transfer_buffer + urb->transfer_buffer_length; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 490 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 491 | line_start = (u8 *) (front + byte_offset); |
| 492 | next_pixel = line_start; |
| 493 | line_end = next_pixel + byte_width; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 494 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 495 | if (dev->backing_buffer) { |
| 496 | int offset; |
| 497 | const u8 *back_start = (u8 *) (dev->backing_buffer |
| 498 | + byte_offset); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 499 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 500 | *ident_ptr += dlfb_trim_hline(back_start, &next_pixel, |
| 501 | &byte_width); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 502 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 503 | offset = next_pixel - line_start; |
| 504 | line_end = next_pixel + byte_width; |
| 505 | dev_addr += offset; |
| 506 | back_start += offset; |
| 507 | line_start += offset; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 508 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 509 | memcpy((char *)back_start, (char *) line_start, |
| 510 | byte_width); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 511 | } |
| 512 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 513 | while (next_pixel < line_end) { |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 514 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 515 | dlfb_compress_hline((const uint16_t **) &next_pixel, |
| 516 | (const uint16_t *) line_end, &dev_addr, |
| 517 | (u8 **) &cmd, (u8 *) cmd_end); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 518 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 519 | if (cmd >= cmd_end) { |
| 520 | int len = cmd - (u8 *) urb->transfer_buffer; |
| 521 | if (dlfb_submit_urb(dev, urb, len)) |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 522 | return 1; /* lost pixels is set */ |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 523 | *sent_ptr += len; |
| 524 | urb = dlfb_get_urb(dev); |
| 525 | if (!urb) |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 526 | return 1; /* lost_pixels is set */ |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 527 | *urb_ptr = urb; |
| 528 | cmd = urb->transfer_buffer; |
| 529 | cmd_end = &cmd[urb->transfer_buffer_length]; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | *urb_buf_ptr = cmd; |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 534 | |
| 535 | return 0; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 538 | int dlfb_handle_damage(struct dlfb_data *dev, int x, int y, |
| 539 | int width, int height, char *data) |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 540 | { |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 541 | int i, ret; |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 542 | char *cmd; |
| 543 | cycles_t start_cycles, end_cycles; |
| 544 | int bytes_sent = 0; |
| 545 | int bytes_identical = 0; |
| 546 | struct urb *urb; |
| 547 | int aligned_x; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 548 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 549 | start_cycles = get_cycles(); |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 550 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 551 | aligned_x = DL_ALIGN_DOWN(x, sizeof(unsigned long)); |
| 552 | width = DL_ALIGN_UP(width + (x-aligned_x), sizeof(unsigned long)); |
| 553 | x = aligned_x; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 554 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 555 | if ((width <= 0) || |
| 556 | (x + width > dev->info->var.xres) || |
| 557 | (y + height > dev->info->var.yres)) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 558 | return -EINVAL; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 559 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 560 | if (!atomic_read(&dev->usb_active)) |
| 561 | return 0; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 562 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 563 | urb = dlfb_get_urb(dev); |
| 564 | if (!urb) |
| 565 | return 0; |
| 566 | cmd = urb->transfer_buffer; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 567 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 568 | for (i = y; i < y + height ; i++) { |
| 569 | const int line_offset = dev->info->fix.line_length * i; |
| 570 | const int byte_offset = line_offset + (x * BPP); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 571 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 572 | if (dlfb_render_hline(dev, &urb, |
| 573 | (char *) dev->info->fix.smem_start, |
Bernie Thompson | 2685cff | 2010-09-05 18:29:56 -0700 | [diff] [blame] | 574 | &cmd, byte_offset, width * BPP, |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 575 | &bytes_identical, &bytes_sent)) |
| 576 | goto error; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 579 | if (cmd > (char *) urb->transfer_buffer) { |
| 580 | /* Send partial buffer remaining before exiting */ |
| 581 | int len = cmd - (char *) urb->transfer_buffer; |
| 582 | ret = dlfb_submit_urb(dev, urb, len); |
| 583 | bytes_sent += len; |
| 584 | } else |
| 585 | dlfb_urb_completion(urb); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 586 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 587 | error: |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 588 | atomic_add(bytes_sent, &dev->bytes_sent); |
| 589 | atomic_add(bytes_identical, &dev->bytes_identical); |
| 590 | atomic_add(width*height*2, &dev->bytes_rendered); |
| 591 | end_cycles = get_cycles(); |
| 592 | atomic_add(((unsigned int) ((end_cycles - start_cycles) |
| 593 | >> 10)), /* Kcycles */ |
| 594 | &dev->cpu_kcycles_used); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 595 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 596 | return 0; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Bernie Thompson | d46ecb9 | 2010-09-05 16:35:04 -0700 | [diff] [blame] | 599 | /* |
| 600 | * Path triggered by usermode clients who write to filesystem |
| 601 | * e.g. cat filename > /dev/fb1 |
| 602 | * Not used by X Windows or text-mode console. But useful for testing. |
| 603 | * Slow because of extra copy and we must assume all pixels dirty. |
| 604 | */ |
| 605 | static ssize_t dlfb_ops_write(struct fb_info *info, const char __user *buf, |
| 606 | size_t count, loff_t *ppos) |
| 607 | { |
Paul Mundt | 1a3e528 | 2011-01-06 17:29:24 +0900 | [diff] [blame] | 608 | ssize_t result; |
Bernie Thompson | d46ecb9 | 2010-09-05 16:35:04 -0700 | [diff] [blame] | 609 | struct dlfb_data *dev = info->par; |
| 610 | u32 offset = (u32) *ppos; |
| 611 | |
Bernie Thompson | d46ecb9 | 2010-09-05 16:35:04 -0700 | [diff] [blame] | 612 | result = fb_sys_write(info, buf, count, ppos); |
| 613 | |
| 614 | if (result > 0) { |
| 615 | int start = max((int)(offset / info->fix.line_length) - 1, 0); |
| 616 | int lines = min((u32)((result / info->fix.line_length) + 1), |
| 617 | (u32)info->var.yres); |
| 618 | |
| 619 | dlfb_handle_damage(dev, 0, start, info->var.xres, |
| 620 | lines, info->screen_base); |
| 621 | } |
Bernie Thompson | d46ecb9 | 2010-09-05 16:35:04 -0700 | [diff] [blame] | 622 | |
| 623 | return result; |
| 624 | } |
| 625 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 626 | /* hardware has native COPY command (see libdlo), but not worth it for fbcon */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 627 | static void dlfb_ops_copyarea(struct fb_info *info, |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 628 | const struct fb_copyarea *area) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 629 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 630 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 631 | struct dlfb_data *dev = info->par; |
| 632 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 633 | sys_copyarea(info, area); |
| 634 | |
| 635 | dlfb_handle_damage(dev, area->dx, area->dy, |
| 636 | area->width, area->height, info->screen_base); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 639 | static void dlfb_ops_imageblit(struct fb_info *info, |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 640 | const struct fb_image *image) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 641 | { |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 642 | struct dlfb_data *dev = info->par; |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 643 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 644 | sys_imageblit(info, image); |
| 645 | |
| 646 | dlfb_handle_damage(dev, image->dx, image->dy, |
| 647 | image->width, image->height, info->screen_base); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 648 | } |
| 649 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 650 | static void dlfb_ops_fillrect(struct fb_info *info, |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 651 | const struct fb_fillrect *rect) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 652 | { |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 653 | struct dlfb_data *dev = info->par; |
| 654 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 655 | sys_fillrect(info, rect); |
| 656 | |
| 657 | dlfb_handle_damage(dev, rect->dx, rect->dy, rect->width, |
| 658 | rect->height, info->screen_base); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 659 | } |
| 660 | |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 661 | /* |
| 662 | * NOTE: fb_defio.c is holding info->fbdefio.mutex |
| 663 | * Touching ANY framebuffer memory that triggers a page fault |
| 664 | * in fb_defio will cause a deadlock, when it also tries to |
| 665 | * grab the same mutex. |
| 666 | */ |
| 667 | static void dlfb_dpy_deferred_io(struct fb_info *info, |
| 668 | struct list_head *pagelist) |
| 669 | { |
| 670 | struct page *cur; |
| 671 | struct fb_deferred_io *fbdefio = info->fbdefio; |
| 672 | struct dlfb_data *dev = info->par; |
| 673 | struct urb *urb; |
| 674 | char *cmd; |
| 675 | cycles_t start_cycles, end_cycles; |
| 676 | int bytes_sent = 0; |
| 677 | int bytes_identical = 0; |
| 678 | int bytes_rendered = 0; |
| 679 | |
| 680 | if (!fb_defio) |
| 681 | return; |
| 682 | |
| 683 | if (!atomic_read(&dev->usb_active)) |
| 684 | return; |
| 685 | |
| 686 | start_cycles = get_cycles(); |
| 687 | |
| 688 | urb = dlfb_get_urb(dev); |
| 689 | if (!urb) |
| 690 | return; |
| 691 | |
| 692 | cmd = urb->transfer_buffer; |
| 693 | |
| 694 | /* walk the written page list and render each to device */ |
| 695 | list_for_each_entry(cur, &fbdefio->pagelist, lru) { |
| 696 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 697 | if (dlfb_render_hline(dev, &urb, (char *) info->fix.smem_start, |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 698 | &cmd, cur->index << PAGE_SHIFT, |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 699 | PAGE_SIZE, &bytes_identical, &bytes_sent)) |
| 700 | goto error; |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 701 | bytes_rendered += PAGE_SIZE; |
| 702 | } |
| 703 | |
| 704 | if (cmd > (char *) urb->transfer_buffer) { |
| 705 | /* Send partial buffer remaining before exiting */ |
| 706 | int len = cmd - (char *) urb->transfer_buffer; |
| 707 | dlfb_submit_urb(dev, urb, len); |
| 708 | bytes_sent += len; |
| 709 | } else |
| 710 | dlfb_urb_completion(urb); |
| 711 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 712 | error: |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 713 | atomic_add(bytes_sent, &dev->bytes_sent); |
| 714 | atomic_add(bytes_identical, &dev->bytes_identical); |
| 715 | atomic_add(bytes_rendered, &dev->bytes_rendered); |
| 716 | end_cycles = get_cycles(); |
| 717 | atomic_add(((unsigned int) ((end_cycles - start_cycles) |
| 718 | >> 10)), /* Kcycles */ |
| 719 | &dev->cpu_kcycles_used); |
| 720 | } |
| 721 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 722 | static int dlfb_get_edid(struct dlfb_data *dev, char *edid, int len) |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 723 | { |
| 724 | int i; |
| 725 | int ret; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 726 | char *rbuf; |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 727 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 728 | rbuf = kmalloc(2, GFP_KERNEL); |
| 729 | if (!rbuf) |
| 730 | return 0; |
| 731 | |
| 732 | for (i = 0; i < len; i++) { |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 733 | ret = usb_control_msg(dev->udev, |
| 734 | usb_rcvctrlpipe(dev->udev, 0), (0x02), |
| 735 | (0x80 | (0x02 << 5)), i << 8, 0xA1, rbuf, 2, |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 736 | HZ); |
| 737 | if (ret < 1) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 738 | pr_err("Read EDID byte %d failed err %x\n", i, ret); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 739 | i--; |
| 740 | break; |
| 741 | } |
| 742 | edid[i] = rbuf[1]; |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 743 | } |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 744 | |
| 745 | kfree(rbuf); |
| 746 | |
| 747 | return i; |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 750 | static int dlfb_ops_ioctl(struct fb_info *info, unsigned int cmd, |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 751 | unsigned long arg) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 752 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 753 | |
| 754 | struct dlfb_data *dev = info->par; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 755 | struct dloarea *area = NULL; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 756 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 757 | if (!atomic_read(&dev->usb_active)) |
| 758 | return 0; |
| 759 | |
| 760 | /* TODO: Update X server to get this from sysfs instead */ |
| 761 | if (cmd == DLFB_IOCTL_RETURN_EDID) { |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 762 | char *edid = (char *)arg; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 763 | if (copy_to_user(edid, dev->edid, dev->edid_size)) |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 764 | return -EFAULT; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 768 | /* TODO: Help propose a standard fb.h ioctl to report mmap damage */ |
| 769 | if (cmd == DLFB_IOCTL_REPORT_DAMAGE) { |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 770 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 771 | /* |
| 772 | * If we have a damage-aware client, turn fb_defio "off" |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 773 | * To avoid perf imact of unnecessary page fault handling. |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 774 | * Done by resetting the delay for this fb_info to a very |
| 775 | * long period. Pages will become writable and stay that way. |
| 776 | * Reset to normal value when all clients have closed this fb. |
| 777 | */ |
| 778 | if (info->fbdefio) |
| 779 | info->fbdefio->delay = DL_DEFIO_WRITE_DISABLE; |
| 780 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 781 | area = (struct dloarea *)arg; |
| 782 | |
| 783 | if (area->x < 0) |
| 784 | area->x = 0; |
| 785 | |
| 786 | if (area->x > info->var.xres) |
| 787 | area->x = info->var.xres; |
| 788 | |
| 789 | if (area->y < 0) |
| 790 | area->y = 0; |
| 791 | |
| 792 | if (area->y > info->var.yres) |
| 793 | area->y = info->var.yres; |
| 794 | |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 795 | dlfb_handle_damage(dev, area->x, area->y, area->w, area->h, |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 796 | info->screen_base); |
| 797 | } |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 798 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 799 | return 0; |
| 800 | } |
| 801 | |
Greg Kroah-Hartman | f05e057 | 2009-06-03 14:47:08 -0700 | [diff] [blame] | 802 | /* taken from vesafb */ |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 803 | static int |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 804 | dlfb_ops_setcolreg(unsigned regno, unsigned red, unsigned green, |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 805 | unsigned blue, unsigned transp, struct fb_info *info) |
| 806 | { |
| 807 | int err = 0; |
| 808 | |
| 809 | if (regno >= info->cmap.len) |
| 810 | return 1; |
| 811 | |
| 812 | if (regno < 16) { |
| 813 | if (info->var.red.offset == 10) { |
| 814 | /* 1:5:5:5 */ |
| 815 | ((u32 *) (info->pseudo_palette))[regno] = |
| 816 | ((red & 0xf800) >> 1) | |
| 817 | ((green & 0xf800) >> 6) | ((blue & 0xf800) >> 11); |
| 818 | } else { |
| 819 | /* 0:5:6:5 */ |
| 820 | ((u32 *) (info->pseudo_palette))[regno] = |
| 821 | ((red & 0xf800)) | |
| 822 | ((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | return err; |
| 827 | } |
| 828 | |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 829 | /* |
| 830 | * It's common for several clients to have framebuffer open simultaneously. |
| 831 | * e.g. both fbcon and X. Makes things interesting. |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 832 | * Assumes caller is holding info->lock (for open and release at least) |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 833 | */ |
| 834 | static int dlfb_ops_open(struct fb_info *info, int user) |
| 835 | { |
| 836 | struct dlfb_data *dev = info->par; |
| 837 | |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 838 | /* |
| 839 | * fbcon aggressively connects to first framebuffer it finds, |
| 840 | * preventing other clients (X) from working properly. Usually |
| 841 | * not what the user wants. Fail by default with option to enable. |
| 842 | */ |
| 843 | if ((user == 0) & (!console)) |
| 844 | return -EBUSY; |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 845 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 846 | /* If the USB device is gone, we don't accept new opens */ |
| 847 | if (dev->virtualized) |
| 848 | return -ENODEV; |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 849 | |
| 850 | dev->fb_count++; |
| 851 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 852 | kref_get(&dev->kref); |
| 853 | |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 854 | if (fb_defio && (info->fbdefio == NULL)) { |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 855 | /* enable defio at last moment if not disabled by client */ |
| 856 | |
| 857 | struct fb_deferred_io *fbdefio; |
| 858 | |
Joe Perches | 31a9f47 | 2010-10-31 15:33:55 -0700 | [diff] [blame] | 859 | fbdefio = kmalloc(sizeof(struct fb_deferred_io), GFP_KERNEL); |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 860 | |
| 861 | if (fbdefio) { |
| 862 | fbdefio->delay = DL_DEFIO_WRITE_DELAY; |
| 863 | fbdefio->deferred_io = dlfb_dpy_deferred_io; |
| 864 | } |
| 865 | |
| 866 | info->fbdefio = fbdefio; |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 867 | fb_deferred_io_init(info); |
| 868 | } |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 869 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 870 | pr_notice("open /dev/fb%d user=%d fb_info=%p count=%d\n", |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 871 | info->node, user, info, dev->fb_count); |
| 872 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 873 | return 0; |
| 874 | } |
| 875 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 876 | /* |
| 877 | * Called when all client interfaces to start transactions have been disabled, |
| 878 | * and all references to our device instance (dlfb_data) are released. |
| 879 | * Every transaction must have a reference, so we know are fully spun down |
| 880 | */ |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 881 | static void dlfb_free(struct kref *kref) |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 882 | { |
| 883 | struct dlfb_data *dev = container_of(kref, struct dlfb_data, kref); |
| 884 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 885 | /* this function will wait for all in-flight urbs to complete */ |
| 886 | if (dev->urbs.count > 0) |
| 887 | dlfb_free_urb_list(dev); |
| 888 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 889 | if (dev->backing_buffer) |
| 890 | vfree(dev->backing_buffer); |
| 891 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 892 | kfree(dev->edid); |
| 893 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 894 | pr_warn("freeing dlfb_data %p\n", dev); |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 895 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 896 | kfree(dev); |
| 897 | } |
| 898 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 899 | static void dlfb_release_urb_work(struct work_struct *work) |
| 900 | { |
| 901 | struct urb_node *unode = container_of(work, struct urb_node, |
| 902 | release_urb_work.work); |
| 903 | |
| 904 | up(&unode->dev->urbs.limit_sem); |
| 905 | } |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 906 | |
| 907 | static void dlfb_free_framebuffer_work(struct work_struct *work) |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 908 | { |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 909 | struct dlfb_data *dev = container_of(work, struct dlfb_data, |
| 910 | free_framebuffer_work.work); |
| 911 | struct fb_info *info = dev->info; |
| 912 | int node = info->node; |
| 913 | |
| 914 | unregister_framebuffer(info); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 915 | |
| 916 | if (info->cmap.len != 0) |
| 917 | fb_dealloc_cmap(&info->cmap); |
| 918 | if (info->monspecs.modedb) |
| 919 | fb_destroy_modedb(info->monspecs.modedb); |
| 920 | if (info->screen_base) |
| 921 | vfree(info->screen_base); |
| 922 | |
| 923 | fb_destroy_modelist(&info->modelist); |
| 924 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 925 | dev->info = 0; |
| 926 | |
| 927 | /* Assume info structure is freed after this point */ |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 928 | framebuffer_release(info); |
| 929 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 930 | pr_warn("fb_info for /dev/fb%d has been freed\n", node); |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 931 | |
| 932 | /* ref taken in probe() as part of registering framebfufer */ |
| 933 | kref_put(&dev->kref, dlfb_free); |
| 934 | } |
| 935 | |
| 936 | /* |
| 937 | * Assumes caller is holding info->lock mutex (for open and release at least) |
| 938 | */ |
| 939 | static int dlfb_ops_release(struct fb_info *info, int user) |
| 940 | { |
| 941 | struct dlfb_data *dev = info->par; |
| 942 | |
| 943 | dev->fb_count--; |
| 944 | |
| 945 | /* We can't free fb_info here - fbmem will touch it when we return */ |
| 946 | if (dev->virtualized && (dev->fb_count == 0)) |
| 947 | schedule_delayed_work(&dev->free_framebuffer_work, HZ); |
| 948 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 949 | if ((dev->fb_count == 0) && (info->fbdefio)) { |
| 950 | fb_deferred_io_cleanup(info); |
| 951 | kfree(info->fbdefio); |
| 952 | info->fbdefio = NULL; |
| 953 | info->fbops->fb_mmap = dlfb_ops_mmap; |
| 954 | } |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 955 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 956 | pr_warn("released /dev/fb%d user=%d count=%d\n", |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 957 | info->node, user, dev->fb_count); |
| 958 | |
| 959 | kref_put(&dev->kref, dlfb_free); |
| 960 | |
| 961 | return 0; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /* |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 965 | * Check whether a video mode is supported by the DisplayLink chip |
| 966 | * We start from monitor's modes, so don't need to filter that here |
| 967 | */ |
| 968 | static int dlfb_is_valid_mode(struct fb_videomode *mode, |
| 969 | struct fb_info *info) |
| 970 | { |
| 971 | struct dlfb_data *dev = info->par; |
| 972 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 973 | if (mode->xres * mode->yres > dev->sku_pixel_limit) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 974 | pr_warn("%dx%d beyond chip capabilities\n", |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 975 | mode->xres, mode->yres); |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 976 | return 0; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 979 | pr_info("%dx%d valid mode\n", mode->xres, mode->yres); |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 980 | |
| 981 | return 1; |
| 982 | } |
| 983 | |
| 984 | static void dlfb_var_color_format(struct fb_var_screeninfo *var) |
| 985 | { |
| 986 | const struct fb_bitfield red = { 11, 5, 0 }; |
| 987 | const struct fb_bitfield green = { 5, 6, 0 }; |
| 988 | const struct fb_bitfield blue = { 0, 5, 0 }; |
| 989 | |
| 990 | var->bits_per_pixel = 16; |
| 991 | var->red = red; |
| 992 | var->green = green; |
| 993 | var->blue = blue; |
| 994 | } |
| 995 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 996 | static int dlfb_ops_check_var(struct fb_var_screeninfo *var, |
| 997 | struct fb_info *info) |
| 998 | { |
| 999 | struct fb_videomode mode; |
| 1000 | |
| 1001 | /* TODO: support dynamically changing framebuffer size */ |
| 1002 | if ((var->xres * var->yres * 2) > info->fix.smem_len) |
| 1003 | return -EINVAL; |
| 1004 | |
| 1005 | /* set device-specific elements of var unrelated to mode */ |
| 1006 | dlfb_var_color_format(var); |
| 1007 | |
| 1008 | fb_var_to_videomode(&mode, var); |
| 1009 | |
| 1010 | if (!dlfb_is_valid_mode(&mode, info)) |
| 1011 | return -EINVAL; |
| 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | static int dlfb_ops_set_par(struct fb_info *info) |
| 1017 | { |
| 1018 | struct dlfb_data *dev = info->par; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1019 | int result; |
| 1020 | u16 *pix_framebuffer; |
| 1021 | int i; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1022 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1023 | pr_notice("set_par mode %dx%d\n", info->var.xres, info->var.yres); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1024 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1025 | result = dlfb_set_video_mode(dev, &info->var); |
| 1026 | |
| 1027 | if ((result == 0) && (dev->fb_count == 0)) { |
| 1028 | |
| 1029 | /* paint greenscreen */ |
| 1030 | |
| 1031 | pix_framebuffer = (u16 *) info->screen_base; |
| 1032 | for (i = 0; i < info->fix.smem_len / 2; i++) |
| 1033 | pix_framebuffer[i] = 0x37e6; |
| 1034 | |
| 1035 | dlfb_handle_damage(dev, 0, 0, info->var.xres, info->var.yres, |
| 1036 | info->screen_base); |
| 1037 | } |
| 1038 | |
| 1039 | return result; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
Bernie Thompson | 9825f70 | 2010-09-05 16:35:10 -0700 | [diff] [blame] | 1042 | /* |
| 1043 | * In order to come back from full DPMS off, we need to set the mode again |
| 1044 | */ |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 1045 | static int dlfb_ops_blank(int blank_mode, struct fb_info *info) |
Greg Kroah-Hartman | f05e057 | 2009-06-03 14:47:08 -0700 | [diff] [blame] | 1046 | { |
Bernie Thompson | 530f43a | 2010-02-15 06:46:21 -0800 | [diff] [blame] | 1047 | struct dlfb_data *dev = info->par; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 1048 | |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 1049 | if (blank_mode != FB_BLANK_UNBLANK) { |
Bernie Thompson | 9825f70 | 2010-09-05 16:35:10 -0700 | [diff] [blame] | 1050 | char *bufptr; |
| 1051 | struct urb *urb; |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 1052 | |
Bernie Thompson | 9825f70 | 2010-09-05 16:35:10 -0700 | [diff] [blame] | 1053 | urb = dlfb_get_urb(dev); |
| 1054 | if (!urb) |
| 1055 | return 0; |
| 1056 | |
| 1057 | bufptr = (char *) urb->transfer_buffer; |
| 1058 | bufptr = dlfb_vidreg_lock(bufptr); |
| 1059 | bufptr = dlfb_enable_hvsync(bufptr, false); |
| 1060 | bufptr = dlfb_vidreg_unlock(bufptr); |
| 1061 | |
| 1062 | dlfb_submit_urb(dev, urb, bufptr - |
| 1063 | (char *) urb->transfer_buffer); |
| 1064 | } else { |
| 1065 | dlfb_set_video_mode(dev, &info->var); |
| 1066 | } |
Roberto De Ioris | 7316bc5 | 2009-06-10 23:02:19 -0700 | [diff] [blame] | 1067 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static struct fb_ops dlfb_ops = { |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1072 | .owner = THIS_MODULE, |
Paul Mundt | 1a3e528 | 2011-01-06 17:29:24 +0900 | [diff] [blame] | 1073 | .fb_read = fb_sys_read, |
Bernie Thompson | d46ecb9 | 2010-09-05 16:35:04 -0700 | [diff] [blame] | 1074 | .fb_write = dlfb_ops_write, |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 1075 | .fb_setcolreg = dlfb_ops_setcolreg, |
| 1076 | .fb_fillrect = dlfb_ops_fillrect, |
| 1077 | .fb_copyarea = dlfb_ops_copyarea, |
| 1078 | .fb_imageblit = dlfb_ops_imageblit, |
| 1079 | .fb_mmap = dlfb_ops_mmap, |
| 1080 | .fb_ioctl = dlfb_ops_ioctl, |
Bernie Thompson | 3e8f3d6 | 2010-02-15 06:46:26 -0800 | [diff] [blame] | 1081 | .fb_open = dlfb_ops_open, |
Bernie Thompson | 4574203 | 2010-02-15 06:46:04 -0800 | [diff] [blame] | 1082 | .fb_release = dlfb_ops_release, |
| 1083 | .fb_blank = dlfb_ops_blank, |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1084 | .fb_check_var = dlfb_ops_check_var, |
| 1085 | .fb_set_par = dlfb_ops_set_par, |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1086 | }; |
| 1087 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1088 | |
Bernie Thompson | cc403dc | 2010-02-15 06:45:49 -0800 | [diff] [blame] | 1089 | /* |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1090 | * Assumes &info->lock held by caller |
| 1091 | * Assumes no active clients have framebuffer open |
| 1092 | */ |
| 1093 | static int dlfb_realloc_framebuffer(struct dlfb_data *dev, struct fb_info *info) |
| 1094 | { |
| 1095 | int retval = -ENOMEM; |
| 1096 | int old_len = info->fix.smem_len; |
| 1097 | int new_len; |
| 1098 | unsigned char *old_fb = info->screen_base; |
| 1099 | unsigned char *new_fb; |
| 1100 | unsigned char *new_back; |
| 1101 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1102 | pr_warn("Reallocating framebuffer. Addresses will change!\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1103 | |
| 1104 | new_len = info->fix.line_length * info->var.yres; |
| 1105 | |
| 1106 | if (PAGE_ALIGN(new_len) > old_len) { |
| 1107 | /* |
| 1108 | * Alloc system memory for virtual framebuffer |
| 1109 | */ |
| 1110 | new_fb = vmalloc(new_len); |
| 1111 | if (!new_fb) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1112 | pr_err("Virtual framebuffer alloc failed\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1113 | goto error; |
| 1114 | } |
| 1115 | |
| 1116 | if (info->screen_base) { |
| 1117 | memcpy(new_fb, old_fb, old_len); |
| 1118 | vfree(info->screen_base); |
| 1119 | } |
| 1120 | |
| 1121 | info->screen_base = new_fb; |
| 1122 | info->fix.smem_len = PAGE_ALIGN(new_len); |
| 1123 | info->fix.smem_start = (unsigned long) new_fb; |
| 1124 | info->flags = udlfb_info_flags; |
| 1125 | |
| 1126 | /* |
| 1127 | * Second framebuffer copy to mirror the framebuffer state |
| 1128 | * on the physical USB device. We can function without this. |
| 1129 | * But with imperfect damage info we may send pixels over USB |
| 1130 | * that were, in fact, unchanged - wasting limited USB bandwidth |
| 1131 | */ |
Joe Perches | 5b84cc7 | 2010-11-04 20:07:59 -0700 | [diff] [blame] | 1132 | new_back = vzalloc(new_len); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1133 | if (!new_back) |
Linus Torvalds | 949f671 | 2011-01-10 16:04:53 -0800 | [diff] [blame] | 1134 | pr_info("No shadow/backing buffer allocated\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1135 | else { |
| 1136 | if (dev->backing_buffer) |
| 1137 | vfree(dev->backing_buffer); |
| 1138 | dev->backing_buffer = new_back; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | retval = 0; |
| 1143 | |
| 1144 | error: |
| 1145 | return retval; |
| 1146 | } |
| 1147 | |
| 1148 | /* |
| 1149 | * 1) Get EDID from hw, or use sw default |
| 1150 | * 2) Parse into various fb_info structs |
| 1151 | * 3) Allocate virtual framebuffer memory to back highest res mode |
| 1152 | * |
| 1153 | * Parses EDID into three places used by various parts of fbdev: |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1154 | * fb_var_screeninfo contains the timing of the monitor's preferred mode |
| 1155 | * fb_info.monspecs is full parsed EDID info, including monspecs.modedb |
| 1156 | * fb_info.modelist is a linked list of all monitor & VESA modes which work |
| 1157 | * |
| 1158 | * If EDID is not readable/valid, then modelist is all VESA modes, |
| 1159 | * monspecs is NULL, and fb_var_screeninfo is set to safe VESA mode |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1160 | * Returns 0 if successful |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1161 | */ |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1162 | static int dlfb_setup_modes(struct dlfb_data *dev, |
| 1163 | struct fb_info *info, |
| 1164 | char *default_edid, size_t default_edid_size) |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1165 | { |
| 1166 | int i; |
| 1167 | const struct fb_videomode *default_vmode = NULL; |
| 1168 | int result = 0; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1169 | char *edid; |
| 1170 | int tries = 3; |
| 1171 | |
| 1172 | if (info->dev) /* only use mutex if info has been registered */ |
| 1173 | mutex_lock(&info->lock); |
| 1174 | |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 1175 | edid = kmalloc(EDID_LENGTH, GFP_KERNEL); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1176 | if (!edid) { |
| 1177 | result = -ENOMEM; |
| 1178 | goto error; |
| 1179 | } |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1180 | |
| 1181 | fb_destroy_modelist(&info->modelist); |
| 1182 | memset(&info->monspecs, 0, sizeof(info->monspecs)); |
| 1183 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1184 | /* |
| 1185 | * Try to (re)read EDID from hardware first |
| 1186 | * EDID data may return, but not parse as valid |
| 1187 | * Try again a few times, in case of e.g. analog cable noise |
| 1188 | */ |
| 1189 | while (tries--) { |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1190 | |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 1191 | i = dlfb_get_edid(dev, edid, EDID_LENGTH); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1192 | |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 1193 | if (i >= EDID_LENGTH) |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1194 | fb_edid_to_monspecs(edid, &info->monspecs); |
| 1195 | |
| 1196 | if (info->monspecs.modedb_len > 0) { |
| 1197 | dev->edid = edid; |
| 1198 | dev->edid_size = i; |
| 1199 | break; |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | /* If that fails, use a previously returned EDID if available */ |
| 1204 | if (info->monspecs.modedb_len == 0) { |
| 1205 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1206 | pr_err("Unable to get valid EDID from device/display\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1207 | |
| 1208 | if (dev->edid) { |
| 1209 | fb_edid_to_monspecs(dev->edid, &info->monspecs); |
| 1210 | if (info->monspecs.modedb_len > 0) |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1211 | pr_err("Using previously queried EDID\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
| 1215 | /* If that fails, use the default EDID we were handed */ |
| 1216 | if (info->monspecs.modedb_len == 0) { |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 1217 | if (default_edid_size >= EDID_LENGTH) { |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1218 | fb_edid_to_monspecs(default_edid, &info->monspecs); |
| 1219 | if (info->monspecs.modedb_len > 0) { |
| 1220 | memcpy(edid, default_edid, default_edid_size); |
| 1221 | dev->edid = edid; |
| 1222 | dev->edid_size = default_edid_size; |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1223 | pr_err("Using default/backup EDID\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | /* If we've got modes, let's pick a best default mode */ |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1229 | if (info->monspecs.modedb_len > 0) { |
| 1230 | |
| 1231 | for (i = 0; i < info->monspecs.modedb_len; i++) { |
| 1232 | if (dlfb_is_valid_mode(&info->monspecs.modedb[i], info)) |
| 1233 | fb_add_videomode(&info->monspecs.modedb[i], |
| 1234 | &info->modelist); |
William Katsak | 9377c51 | 2011-06-23 13:16:29 +0000 | [diff] [blame] | 1235 | else { |
| 1236 | if (i == 0) |
| 1237 | /* if we've removed top/best mode */ |
| 1238 | info->monspecs.misc |
| 1239 | &= ~FB_MISC_1ST_DETAIL; |
| 1240 | } |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1241 | } |
| 1242 | |
| 1243 | default_vmode = fb_find_best_display(&info->monspecs, |
| 1244 | &info->modelist); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1245 | } |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1246 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1247 | /* If everything else has failed, fall back to safe default mode */ |
| 1248 | if (default_vmode == NULL) { |
| 1249 | |
| 1250 | struct fb_videomode fb_vmode = {0}; |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1251 | |
| 1252 | /* |
| 1253 | * Add the standard VESA modes to our modelist |
| 1254 | * Since we don't have EDID, there may be modes that |
| 1255 | * overspec monitor and/or are incorrect aspect ratio, etc. |
| 1256 | * But at least the user has a chance to choose |
| 1257 | */ |
| 1258 | for (i = 0; i < VESA_MODEDB_SIZE; i++) { |
| 1259 | if (dlfb_is_valid_mode((struct fb_videomode *) |
| 1260 | &vesa_modes[i], info)) |
| 1261 | fb_add_videomode(&vesa_modes[i], |
| 1262 | &info->modelist); |
| 1263 | } |
| 1264 | |
| 1265 | /* |
| 1266 | * default to resolution safe for projectors |
| 1267 | * (since they are most common case without EDID) |
| 1268 | */ |
| 1269 | fb_vmode.xres = 800; |
| 1270 | fb_vmode.yres = 600; |
| 1271 | fb_vmode.refresh = 60; |
| 1272 | default_vmode = fb_find_nearest_mode(&fb_vmode, |
| 1273 | &info->modelist); |
| 1274 | } |
| 1275 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1276 | /* If we have good mode and no active clients*/ |
| 1277 | if ((default_vmode != NULL) && (dev->fb_count == 0)) { |
| 1278 | |
| 1279 | fb_videomode_to_var(&info->var, default_vmode); |
| 1280 | dlfb_var_color_format(&info->var); |
| 1281 | |
| 1282 | /* |
| 1283 | * with mode size info, we can now alloc our framebuffer. |
| 1284 | */ |
| 1285 | memcpy(&info->fix, &dlfb_fix, sizeof(dlfb_fix)); |
| 1286 | info->fix.line_length = info->var.xres * |
| 1287 | (info->var.bits_per_pixel / 8); |
| 1288 | |
| 1289 | result = dlfb_realloc_framebuffer(dev, info); |
| 1290 | |
| 1291 | } else |
| 1292 | result = -EINVAL; |
| 1293 | |
| 1294 | error: |
| 1295 | if (edid && (dev->edid != edid)) |
| 1296 | kfree(edid); |
| 1297 | |
| 1298 | if (info->dev) |
| 1299 | mutex_unlock(&info->lock); |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1300 | |
| 1301 | return result; |
| 1302 | } |
| 1303 | |
| 1304 | static ssize_t metrics_bytes_rendered_show(struct device *fbdev, |
| 1305 | struct device_attribute *a, char *buf) { |
| 1306 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1307 | struct dlfb_data *dev = fb_info->par; |
| 1308 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 1309 | atomic_read(&dev->bytes_rendered)); |
| 1310 | } |
| 1311 | |
| 1312 | static ssize_t metrics_bytes_identical_show(struct device *fbdev, |
| 1313 | struct device_attribute *a, char *buf) { |
| 1314 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1315 | struct dlfb_data *dev = fb_info->par; |
| 1316 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 1317 | atomic_read(&dev->bytes_identical)); |
| 1318 | } |
| 1319 | |
| 1320 | static ssize_t metrics_bytes_sent_show(struct device *fbdev, |
| 1321 | struct device_attribute *a, char *buf) { |
| 1322 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1323 | struct dlfb_data *dev = fb_info->par; |
| 1324 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 1325 | atomic_read(&dev->bytes_sent)); |
| 1326 | } |
| 1327 | |
| 1328 | static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev, |
| 1329 | struct device_attribute *a, char *buf) { |
| 1330 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1331 | struct dlfb_data *dev = fb_info->par; |
| 1332 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 1333 | atomic_read(&dev->cpu_kcycles_used)); |
| 1334 | } |
| 1335 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1336 | static ssize_t edid_show( |
| 1337 | struct file *filp, |
| 1338 | struct kobject *kobj, struct bin_attribute *a, |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1339 | char *buf, loff_t off, size_t count) { |
| 1340 | struct device *fbdev = container_of(kobj, struct device, kobj); |
| 1341 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1342 | struct dlfb_data *dev = fb_info->par; |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1343 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1344 | if (dev->edid == NULL) |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1345 | return 0; |
| 1346 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1347 | if ((off >= dev->edid_size) || (count > dev->edid_size)) |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1348 | return 0; |
| 1349 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1350 | if (off + count > dev->edid_size) |
| 1351 | count = dev->edid_size - off; |
| 1352 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1353 | pr_info("sysfs edid copy %p to %p, %d bytes\n", |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1354 | dev->edid, buf, (int) count); |
| 1355 | |
| 1356 | memcpy(buf, dev->edid, count); |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1357 | |
| 1358 | return count; |
| 1359 | } |
| 1360 | |
Bernie Thompson | 8ef8cc4 | 2010-09-05 16:35:31 -0700 | [diff] [blame] | 1361 | static ssize_t edid_store( |
| 1362 | struct file *filp, |
| 1363 | struct kobject *kobj, struct bin_attribute *a, |
| 1364 | char *src, loff_t src_off, size_t src_size) { |
| 1365 | struct device *fbdev = container_of(kobj, struct device, kobj); |
| 1366 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1367 | struct dlfb_data *dev = fb_info->par; |
| 1368 | |
| 1369 | /* We only support write of entire EDID at once, no offset*/ |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 1370 | if ((src_size != EDID_LENGTH) || (src_off != 0)) |
Bernie Thompson | 8ef8cc4 | 2010-09-05 16:35:31 -0700 | [diff] [blame] | 1371 | return 0; |
| 1372 | |
| 1373 | dlfb_setup_modes(dev, fb_info, src, src_size); |
| 1374 | |
| 1375 | if (dev->edid && (memcmp(src, dev->edid, src_size) == 0)) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1376 | pr_info("sysfs written EDID is new default\n"); |
Bernie Thompson | 8ef8cc4 | 2010-09-05 16:35:31 -0700 | [diff] [blame] | 1377 | dlfb_ops_set_par(fb_info); |
| 1378 | return src_size; |
| 1379 | } else |
| 1380 | return 0; |
| 1381 | } |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1382 | |
| 1383 | static ssize_t metrics_reset_store(struct device *fbdev, |
| 1384 | struct device_attribute *attr, |
| 1385 | const char *buf, size_t count) |
| 1386 | { |
| 1387 | struct fb_info *fb_info = dev_get_drvdata(fbdev); |
| 1388 | struct dlfb_data *dev = fb_info->par; |
| 1389 | |
| 1390 | atomic_set(&dev->bytes_rendered, 0); |
| 1391 | atomic_set(&dev->bytes_identical, 0); |
| 1392 | atomic_set(&dev->bytes_sent, 0); |
| 1393 | atomic_set(&dev->cpu_kcycles_used, 0); |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1394 | |
| 1395 | return count; |
| 1396 | } |
| 1397 | |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1398 | static struct bin_attribute edid_attr = { |
| 1399 | .attr.name = "edid", |
Bernie Thompson | 8ef8cc4 | 2010-09-05 16:35:31 -0700 | [diff] [blame] | 1400 | .attr.mode = 0666, |
Paul Mundt | b9f03a3 | 2011-01-06 18:04:02 +0900 | [diff] [blame] | 1401 | .size = EDID_LENGTH, |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1402 | .read = edid_show, |
Bernie Thompson | 8ef8cc4 | 2010-09-05 16:35:31 -0700 | [diff] [blame] | 1403 | .write = edid_store |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1404 | }; |
| 1405 | |
| 1406 | static struct device_attribute fb_device_attrs[] = { |
| 1407 | __ATTR_RO(metrics_bytes_rendered), |
| 1408 | __ATTR_RO(metrics_bytes_identical), |
| 1409 | __ATTR_RO(metrics_bytes_sent), |
| 1410 | __ATTR_RO(metrics_cpu_kcycles_used), |
Greg Kroah-Hartman | 926c111 | 2010-11-18 11:21:04 -0800 | [diff] [blame] | 1411 | __ATTR(metrics_reset, S_IWUSR, NULL, metrics_reset_store), |
Bernie Thompson | 7d9485e | 2010-02-15 06:46:08 -0800 | [diff] [blame] | 1412 | }; |
| 1413 | |
| 1414 | /* |
Bernie Thompson | cc403dc | 2010-02-15 06:45:49 -0800 | [diff] [blame] | 1415 | * This is necessary before we can communicate with the display controller. |
| 1416 | */ |
| 1417 | static int dlfb_select_std_channel(struct dlfb_data *dev) |
| 1418 | { |
| 1419 | int ret; |
| 1420 | u8 set_def_chn[] = { 0x57, 0xCD, 0xDC, 0xA7, |
| 1421 | 0x1C, 0x88, 0x5E, 0x15, |
| 1422 | 0x60, 0xFE, 0xC6, 0x97, |
| 1423 | 0x16, 0x3D, 0x47, 0xF2 }; |
| 1424 | |
| 1425 | ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), |
| 1426 | NR_USB_REQUEST_CHANNEL, |
| 1427 | (USB_DIR_OUT | USB_TYPE_VENDOR), 0, 0, |
| 1428 | set_def_chn, sizeof(set_def_chn), USB_CTRL_SET_TIMEOUT); |
| 1429 | return ret; |
| 1430 | } |
| 1431 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1432 | static int dlfb_parse_vendor_descriptor(struct dlfb_data *dev, |
| 1433 | struct usb_device *usbdev) |
| 1434 | { |
| 1435 | char *desc; |
| 1436 | char *buf; |
| 1437 | char *desc_end; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1438 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1439 | u8 total_len = 0; |
| 1440 | |
| 1441 | buf = kzalloc(MAX_VENDOR_DESCRIPTOR_SIZE, GFP_KERNEL); |
| 1442 | if (!buf) |
| 1443 | return false; |
| 1444 | desc = buf; |
| 1445 | |
| 1446 | total_len = usb_get_descriptor(usbdev, 0x5f, /* vendor specific */ |
| 1447 | 0, desc, MAX_VENDOR_DESCRIPTOR_SIZE); |
| 1448 | if (total_len > 5) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1449 | pr_info("vendor descriptor length:%x data:%02x %02x %02x %02x" \ |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1450 | "%02x %02x %02x %02x %02x %02x %02x\n", |
| 1451 | total_len, desc[0], |
| 1452 | desc[1], desc[2], desc[3], desc[4], desc[5], desc[6], |
| 1453 | desc[7], desc[8], desc[9], desc[10]); |
| 1454 | |
| 1455 | if ((desc[0] != total_len) || /* descriptor length */ |
| 1456 | (desc[1] != 0x5f) || /* vendor descriptor type */ |
| 1457 | (desc[2] != 0x01) || /* version (2 bytes) */ |
| 1458 | (desc[3] != 0x00) || |
| 1459 | (desc[4] != total_len - 2)) /* length after type */ |
| 1460 | goto unrecognized; |
| 1461 | |
| 1462 | desc_end = desc + total_len; |
| 1463 | desc += 5; /* the fixed header we've already parsed */ |
| 1464 | |
| 1465 | while (desc < desc_end) { |
| 1466 | u8 length; |
| 1467 | u16 key; |
| 1468 | |
| 1469 | key = *((u16 *) desc); |
| 1470 | desc += sizeof(u16); |
| 1471 | length = *desc; |
| 1472 | desc++; |
| 1473 | |
| 1474 | switch (key) { |
| 1475 | case 0x0200: { /* max_area */ |
| 1476 | u32 max_area; |
| 1477 | max_area = le32_to_cpu(*((u32 *)desc)); |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1478 | pr_warn("DL chip limited to %d pixel modes\n", |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1479 | max_area); |
| 1480 | dev->sku_pixel_limit = max_area; |
| 1481 | break; |
| 1482 | } |
| 1483 | default: |
| 1484 | break; |
| 1485 | } |
| 1486 | desc += length; |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | goto success; |
| 1491 | |
| 1492 | unrecognized: |
| 1493 | /* allow udlfb to load for now even if firmware unrecognized */ |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1494 | pr_err("Unrecognized vendor firmware descriptor\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1495 | |
| 1496 | success: |
| 1497 | kfree(buf); |
| 1498 | return true; |
| 1499 | } |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1500 | static int dlfb_usb_probe(struct usb_interface *interface, |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1501 | const struct usb_device_id *id) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1502 | { |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1503 | struct usb_device *usbdev; |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1504 | struct dlfb_data *dev = 0; |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1505 | struct fb_info *info = 0; |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1506 | int retval = -ENOMEM; |
Bernie Thompson | 2685cff | 2010-09-05 18:29:56 -0700 | [diff] [blame] | 1507 | int i; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1508 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1509 | /* usb initialization */ |
| 1510 | |
| 1511 | usbdev = interface_to_usbdev(interface); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1512 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1513 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 1514 | if (dev == NULL) { |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1515 | err("dlfb_usb_probe: failed alloc of dev struct\n"); |
| 1516 | goto error; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1519 | /* we need to wait for both usb and fbdev to spin down on disconnect */ |
| 1520 | kref_init(&dev->kref); /* matching kref_put in usb .disconnect fn */ |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1521 | kref_get(&dev->kref); /* matching kref_put in free_framebuffer_work */ |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1522 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1523 | dev->udev = usbdev; |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1524 | dev->gdev = &usbdev->dev; /* our generic struct device * */ |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1525 | usb_set_intfdata(interface, dev); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1526 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1527 | pr_info("%s %s - serial #%s\n", |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1528 | usbdev->manufacturer, usbdev->product, usbdev->serial); |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1529 | pr_info("vid_%04x&pid_%04x&rev_%04x driver's dlfb_data struct at %p\n", |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1530 | usbdev->descriptor.idVendor, usbdev->descriptor.idProduct, |
| 1531 | usbdev->descriptor.bcdDevice, dev); |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1532 | pr_info("console enable=%d\n", console); |
| 1533 | pr_info("fb_defio enable=%d\n", fb_defio); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1534 | |
| 1535 | dev->sku_pixel_limit = 2048 * 1152; /* default to maximum */ |
| 1536 | |
| 1537 | if (!dlfb_parse_vendor_descriptor(dev, usbdev)) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1538 | pr_err("firmware not recognized. Assume incompatible device\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1539 | goto error; |
| 1540 | } |
| 1541 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1542 | if (!dlfb_alloc_urb_list(dev, WRITES_IN_FLIGHT, MAX_TRANSFER)) { |
| 1543 | retval = -ENOMEM; |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1544 | pr_err("dlfb_alloc_urb_list failed\n"); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1545 | goto error; |
| 1546 | } |
| 1547 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1548 | /* We don't register a new USB class. Our client interface is fbdev */ |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1549 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1550 | /* allocates framebuffer driver structure, not framebuffer memory */ |
| 1551 | info = framebuffer_alloc(0, &usbdev->dev); |
| 1552 | if (!info) { |
| 1553 | retval = -ENOMEM; |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1554 | pr_err("framebuffer_alloc failed\n"); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1555 | goto error; |
| 1556 | } |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1557 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1558 | dev->info = info; |
| 1559 | info->par = dev; |
| 1560 | info->pseudo_palette = dev->pseudo_palette; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1561 | info->fbops = &dlfb_ops; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1562 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1563 | retval = fb_alloc_cmap(&info->cmap, 256, 0); |
| 1564 | if (retval < 0) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1565 | pr_err("fb_alloc_cmap failed %x\n", retval); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1566 | goto error; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1567 | } |
| 1568 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1569 | INIT_DELAYED_WORK(&dev->free_framebuffer_work, |
| 1570 | dlfb_free_framebuffer_work); |
| 1571 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1572 | INIT_LIST_HEAD(&info->modelist); |
| 1573 | |
| 1574 | retval = dlfb_setup_modes(dev, info, NULL, 0); |
| 1575 | if (retval != 0) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1576 | pr_err("unable to find common mode for display and adapter\n"); |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1577 | goto error; |
| 1578 | } |
| 1579 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1580 | /* ready to begin using device */ |
| 1581 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1582 | atomic_set(&dev->usb_active, 1); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1583 | dlfb_select_std_channel(dev); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1584 | |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1585 | dlfb_ops_check_var(&info->var, info); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1586 | dlfb_ops_set_par(info); |
| 1587 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1588 | retval = register_framebuffer(info); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1589 | if (retval < 0) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1590 | pr_err("register_framebuffer failed %d\n", retval); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1591 | goto error; |
| 1592 | } |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1593 | |
Liu Yuan | 94cd1ae | 2011-04-18 10:44:38 +0000 | [diff] [blame] | 1594 | for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++) { |
| 1595 | retval = device_create_file(info->dev, &fb_device_attrs[i]); |
| 1596 | if (retval) { |
| 1597 | pr_err("device_create_file failed %d\n", retval); |
| 1598 | goto err_del_attrs; |
| 1599 | } |
| 1600 | } |
Greg Kroah-Hartman | f05e057 | 2009-06-03 14:47:08 -0700 | [diff] [blame] | 1601 | |
Liu Yuan | 94cd1ae | 2011-04-18 10:44:38 +0000 | [diff] [blame] | 1602 | retval = device_create_bin_file(info->dev, &edid_attr); |
| 1603 | if (retval) { |
| 1604 | pr_err("device_create_bin_file failed %d\n", retval); |
| 1605 | goto err_del_attrs; |
| 1606 | } |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1607 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1608 | pr_info("DisplayLink USB device /dev/fb%d attached. %dx%d resolution." |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1609 | " Using %dK framebuffer memory\n", info->node, |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1610 | info->var.xres, info->var.yres, |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1611 | ((dev->backing_buffer) ? |
Bernie Thompson | 18dffdf | 2010-09-05 16:35:23 -0700 | [diff] [blame] | 1612 | info->fix.smem_len * 2 : info->fix.smem_len) >> 10); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1613 | return 0; |
| 1614 | |
Liu Yuan | 94cd1ae | 2011-04-18 10:44:38 +0000 | [diff] [blame] | 1615 | err_del_attrs: |
| 1616 | for (i -= 1; i >= 0; i--) |
| 1617 | device_remove_file(info->dev, &fb_device_attrs[i]); |
| 1618 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1619 | error: |
| 1620 | if (dev) { |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1621 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1622 | if (info) { |
| 1623 | if (info->cmap.len != 0) |
| 1624 | fb_dealloc_cmap(&info->cmap); |
| 1625 | if (info->monspecs.modedb) |
| 1626 | fb_destroy_modedb(info->monspecs.modedb); |
| 1627 | if (info->screen_base) |
| 1628 | vfree(info->screen_base); |
| 1629 | |
| 1630 | fb_destroy_modelist(&info->modelist); |
| 1631 | |
| 1632 | framebuffer_release(info); |
| 1633 | } |
| 1634 | |
| 1635 | if (dev->backing_buffer) |
| 1636 | vfree(dev->backing_buffer); |
| 1637 | |
| 1638 | kref_put(&dev->kref, dlfb_free); /* ref for framebuffer */ |
| 1639 | kref_put(&dev->kref, dlfb_free); /* last ref from kref_init */ |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1640 | |
| 1641 | /* dev has been deallocated. Do not dereference */ |
| 1642 | } |
| 1643 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1644 | return retval; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1647 | static void dlfb_usb_disconnect(struct usb_interface *interface) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1648 | { |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1649 | struct dlfb_data *dev; |
| 1650 | struct fb_info *info; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1651 | int i; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1652 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1653 | dev = usb_get_intfdata(interface); |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1654 | info = dev->info; |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1655 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1656 | pr_info("USB disconnect starting\n"); |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1657 | |
| 1658 | /* we virtualize until all fb clients release. Then we free */ |
| 1659 | dev->virtualized = true; |
| 1660 | |
| 1661 | /* When non-active we'll update virtual framebuffer, but no new urbs */ |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1662 | atomic_set(&dev->usb_active, 0); |
| 1663 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1664 | /* remove udlfb's sysfs interfaces */ |
| 1665 | for (i = 0; i < ARRAY_SIZE(fb_device_attrs); i++) |
| 1666 | device_remove_file(info->dev, &fb_device_attrs[i]); |
| 1667 | device_remove_bin_file(info->dev, &edid_attr); |
| 1668 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1669 | usb_set_intfdata(interface, NULL); |
| 1670 | |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1671 | /* if clients still have us open, will be freed on last close */ |
| 1672 | if (dev->fb_count == 0) |
| 1673 | schedule_delayed_work(&dev->free_framebuffer_work, 0); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1674 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1675 | /* release reference taken by kref_init in probe() */ |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1676 | kref_put(&dev->kref, dlfb_free); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1677 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1678 | /* consider dlfb_data freed */ |
| 1679 | |
| 1680 | return; |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | static struct usb_driver dlfb_driver = { |
| 1684 | .name = "udlfb", |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1685 | .probe = dlfb_usb_probe, |
| 1686 | .disconnect = dlfb_usb_disconnect, |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1687 | .id_table = id_table, |
| 1688 | }; |
| 1689 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1690 | static int __init dlfb_module_init(void) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1691 | { |
| 1692 | int res; |
| 1693 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1694 | res = usb_register(&dlfb_driver); |
| 1695 | if (res) |
| 1696 | err("usb_register failed. Error number %d", res); |
| 1697 | |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1698 | return res; |
| 1699 | } |
| 1700 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1701 | static void __exit dlfb_module_exit(void) |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1702 | { |
| 1703 | usb_deregister(&dlfb_driver); |
| 1704 | } |
| 1705 | |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1706 | module_init(dlfb_module_init); |
| 1707 | module_exit(dlfb_module_exit); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1708 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1709 | static void dlfb_urb_completion(struct urb *urb) |
| 1710 | { |
| 1711 | struct urb_node *unode = urb->context; |
| 1712 | struct dlfb_data *dev = unode->dev; |
| 1713 | unsigned long flags; |
| 1714 | |
| 1715 | /* sync/async unlink faults aren't errors */ |
| 1716 | if (urb->status) { |
| 1717 | if (!(urb->status == -ENOENT || |
| 1718 | urb->status == -ECONNRESET || |
| 1719 | urb->status == -ESHUTDOWN)) { |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1720 | pr_err("%s - nonzero write bulk status received: %d\n", |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1721 | __func__, urb->status); |
| 1722 | atomic_set(&dev->lost_pixels, 1); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | urb->transfer_buffer_length = dev->urbs.size; /* reset to actual */ |
| 1727 | |
| 1728 | spin_lock_irqsave(&dev->urbs.lock, flags); |
| 1729 | list_add_tail(&unode->entry, &dev->urbs.list); |
| 1730 | dev->urbs.available++; |
| 1731 | spin_unlock_irqrestore(&dev->urbs.lock, flags); |
| 1732 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 1733 | /* |
| 1734 | * When using fb_defio, we deadlock if up() is called |
| 1735 | * while another is waiting. So queue to another process. |
| 1736 | */ |
| 1737 | if (fb_defio) |
| 1738 | schedule_delayed_work(&unode->release_urb_work, 0); |
| 1739 | else |
| 1740 | up(&dev->urbs.limit_sem); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | static void dlfb_free_urb_list(struct dlfb_data *dev) |
| 1744 | { |
| 1745 | int count = dev->urbs.count; |
| 1746 | struct list_head *node; |
| 1747 | struct urb_node *unode; |
| 1748 | struct urb *urb; |
| 1749 | int ret; |
| 1750 | unsigned long flags; |
| 1751 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1752 | pr_notice("Waiting for completes and freeing all render urbs\n"); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1753 | |
| 1754 | /* keep waiting and freeing, until we've got 'em all */ |
| 1755 | while (count--) { |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1756 | |
| 1757 | /* Getting interrupted means a leak, but ok at shutdown*/ |
| 1758 | ret = down_interruptible(&dev->urbs.limit_sem); |
| 1759 | if (ret) |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1760 | break; |
Bernie Thompson | 33077b8 | 2010-09-05 16:35:19 -0700 | [diff] [blame] | 1761 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1762 | spin_lock_irqsave(&dev->urbs.lock, flags); |
| 1763 | |
| 1764 | node = dev->urbs.list.next; /* have reserved one with sem */ |
| 1765 | list_del_init(node); |
| 1766 | |
| 1767 | spin_unlock_irqrestore(&dev->urbs.lock, flags); |
| 1768 | |
| 1769 | unode = list_entry(node, struct urb_node, entry); |
| 1770 | urb = unode->urb; |
| 1771 | |
| 1772 | /* Free each separately allocated piece */ |
Greg Kroah-Hartman | c220cc3 | 2010-04-29 15:36:29 -0700 | [diff] [blame] | 1773 | usb_free_coherent(urb->dev, dev->urbs.size, |
| 1774 | urb->transfer_buffer, urb->transfer_dma); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1775 | usb_free_urb(urb); |
| 1776 | kfree(node); |
| 1777 | } |
| 1778 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | static int dlfb_alloc_urb_list(struct dlfb_data *dev, int count, size_t size) |
| 1782 | { |
| 1783 | int i = 0; |
| 1784 | struct urb *urb; |
| 1785 | struct urb_node *unode; |
| 1786 | char *buf; |
| 1787 | |
| 1788 | spin_lock_init(&dev->urbs.lock); |
| 1789 | |
| 1790 | dev->urbs.size = size; |
| 1791 | INIT_LIST_HEAD(&dev->urbs.list); |
| 1792 | |
| 1793 | while (i < count) { |
| 1794 | unode = kzalloc(sizeof(struct urb_node), GFP_KERNEL); |
| 1795 | if (!unode) |
| 1796 | break; |
| 1797 | unode->dev = dev; |
| 1798 | |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 1799 | INIT_DELAYED_WORK(&unode->release_urb_work, |
| 1800 | dlfb_release_urb_work); |
| 1801 | |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1802 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 1803 | if (!urb) { |
| 1804 | kfree(unode); |
| 1805 | break; |
| 1806 | } |
| 1807 | unode->urb = urb; |
| 1808 | |
Greg Kroah-Hartman | c220cc3 | 2010-04-29 15:36:29 -0700 | [diff] [blame] | 1809 | buf = usb_alloc_coherent(dev->udev, MAX_TRANSFER, GFP_KERNEL, |
| 1810 | &urb->transfer_dma); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1811 | if (!buf) { |
| 1812 | kfree(unode); |
| 1813 | usb_free_urb(urb); |
| 1814 | break; |
| 1815 | } |
| 1816 | |
| 1817 | /* urb->transfer_buffer_length set to actual before submit */ |
| 1818 | usb_fill_bulk_urb(urb, dev->udev, usb_sndbulkpipe(dev->udev, 1), |
| 1819 | buf, size, dlfb_urb_completion, unode); |
| 1820 | urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1821 | |
| 1822 | list_add_tail(&unode->entry, &dev->urbs.list); |
| 1823 | |
| 1824 | i++; |
| 1825 | } |
| 1826 | |
| 1827 | sema_init(&dev->urbs.limit_sem, i); |
| 1828 | dev->urbs.count = i; |
| 1829 | dev->urbs.available = i; |
| 1830 | |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1831 | pr_notice("allocated %d %d byte urbs\n", i, (int) size); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1832 | |
| 1833 | return i; |
| 1834 | } |
| 1835 | |
| 1836 | static struct urb *dlfb_get_urb(struct dlfb_data *dev) |
| 1837 | { |
| 1838 | int ret = 0; |
| 1839 | struct list_head *entry; |
| 1840 | struct urb_node *unode; |
| 1841 | struct urb *urb = NULL; |
| 1842 | unsigned long flags; |
| 1843 | |
| 1844 | /* Wait for an in-flight buffer to complete and get re-queued */ |
| 1845 | ret = down_timeout(&dev->urbs.limit_sem, GET_URB_TIMEOUT); |
| 1846 | if (ret) { |
| 1847 | atomic_set(&dev->lost_pixels, 1); |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1848 | pr_warn("wait for urb interrupted: %x available: %d\n", |
Bernie Thompson | 5bea1fb | 2010-09-05 18:28:29 -0700 | [diff] [blame] | 1849 | ret, dev->urbs.available); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1850 | goto error; |
| 1851 | } |
| 1852 | |
| 1853 | spin_lock_irqsave(&dev->urbs.lock, flags); |
| 1854 | |
| 1855 | BUG_ON(list_empty(&dev->urbs.list)); /* reserved one with limit_sem */ |
| 1856 | entry = dev->urbs.list.next; |
| 1857 | list_del_init(entry); |
| 1858 | dev->urbs.available--; |
| 1859 | |
| 1860 | spin_unlock_irqrestore(&dev->urbs.lock, flags); |
| 1861 | |
| 1862 | unode = list_entry(entry, struct urb_node, entry); |
| 1863 | urb = unode->urb; |
| 1864 | |
| 1865 | error: |
| 1866 | return urb; |
| 1867 | } |
| 1868 | |
| 1869 | static int dlfb_submit_urb(struct dlfb_data *dev, struct urb *urb, size_t len) |
| 1870 | { |
| 1871 | int ret; |
| 1872 | |
| 1873 | BUG_ON(len > dev->urbs.size); |
| 1874 | |
| 1875 | urb->transfer_buffer_length = len; /* set to actual payload len */ |
| 1876 | ret = usb_submit_urb(urb, GFP_KERNEL); |
| 1877 | if (ret) { |
| 1878 | dlfb_urb_completion(urb); /* because no one else will */ |
| 1879 | atomic_set(&dev->lost_pixels, 1); |
Paul Mundt | 81f6f3c | 2011-01-06 18:07:54 +0900 | [diff] [blame] | 1880 | pr_err("usb_submit_urb error %x\n", ret); |
Bernie Thompson | 4a4854d | 2010-02-15 06:45:55 -0800 | [diff] [blame] | 1881 | } |
| 1882 | return ret; |
| 1883 | } |
| 1884 | |
Bernie Thompson | d5ed543 | 2010-09-05 16:35:39 -0700 | [diff] [blame] | 1885 | module_param(console, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP); |
| 1886 | MODULE_PARM_DESC(console, "Allow fbcon to consume first framebuffer found"); |
| 1887 | |
| 1888 | module_param(fb_defio, bool, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP); |
| 1889 | MODULE_PARM_DESC(fb_defio, "Enable fb_defio mmap support. *Experimental*"); |
| 1890 | |
Bernie Thompson | 59277b6 | 2009-11-24 15:52:21 -0800 | [diff] [blame] | 1891 | MODULE_AUTHOR("Roberto De Ioris <roberto@unbit.it>, " |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1892 | "Jaya Kumar <jayakumar.lkml@gmail.com>, " |
| 1893 | "Bernie Thompson <bernie@plugable.com>"); |
| 1894 | MODULE_DESCRIPTION("DisplayLink kernel framebuffer driver"); |
Roberto De Ioris | 88e58b1 | 2009-06-03 14:03:06 -0700 | [diff] [blame] | 1895 | MODULE_LICENSE("GPL"); |
Bernie Thompson | 2469d5d | 2010-02-15 06:46:13 -0800 | [diff] [blame] | 1896 | |