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