Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * framebuffer driver for VBE 2.0 compliant graphic boards |
| 3 | * |
| 4 | * switching to graphics mode happens at boot time (while |
| 5 | * running in real mode, see arch/i386/boot/video.S). |
| 6 | * |
| 7 | * (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de> |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/string.h> |
| 15 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/delay.h> |
| 17 | #include <linux/fb.h> |
| 18 | #include <linux/ioport.h> |
| 19 | #include <linux/init.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
Jon Smirl | a8f340e | 2006-07-10 04:44:12 -0700 | [diff] [blame] | 21 | #include <linux/screen_info.h> |
Russell King | d052d1b | 2005-10-29 19:07:23 +0100 | [diff] [blame] | 22 | |
Antonino A. Daplas | d2d5838 | 2005-09-09 13:04:31 -0700 | [diff] [blame] | 23 | #include <video/vga.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/io.h> |
| 25 | #include <asm/mtrr.h> |
| 26 | |
| 27 | #define dac_reg (0x3c8) |
| 28 | #define dac_val (0x3c9) |
| 29 | |
| 30 | /* --------------------------------------------------------------------- */ |
| 31 | |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 32 | static struct fb_var_screeninfo vesafb_defined = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | .activate = FB_ACTIVATE_NOW, |
| 34 | .height = -1, |
| 35 | .width = -1, |
| 36 | .right_margin = 32, |
| 37 | .upper_margin = 16, |
| 38 | .lower_margin = 4, |
| 39 | .vsync_len = 4, |
| 40 | .vmode = FB_VMODE_NONINTERLACED, |
| 41 | }; |
| 42 | |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 43 | static struct fb_fix_screeninfo vesafb_fix = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .id = "VESA VGA", |
| 45 | .type = FB_TYPE_PACKED_PIXELS, |
| 46 | .accel = FB_ACCEL_NONE, |
| 47 | }; |
| 48 | |
Helge Deller | 4670358 | 2006-12-08 02:40:30 -0800 | [diff] [blame] | 49 | static int inverse __read_mostly; |
| 50 | static int mtrr __read_mostly; /* disable mtrr */ |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 51 | static int vram_remap; /* Set amount of memory to be used */ |
| 52 | static int vram_total; /* Set total amount of memory */ |
Helge Deller | 4670358 | 2006-12-08 02:40:30 -0800 | [diff] [blame] | 53 | static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */ |
| 54 | static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */ |
| 55 | static void (*pmi_start)(void) __read_mostly; |
| 56 | static void (*pmi_pal) (void) __read_mostly; |
| 57 | static int depth __read_mostly; |
| 58 | static int vga_compat __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* --------------------------------------------------------------------- */ |
| 60 | |
| 61 | static int vesafb_pan_display(struct fb_var_screeninfo *var, |
| 62 | struct fb_info *info) |
| 63 | { |
| 64 | #ifdef __i386__ |
| 65 | int offset; |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | offset = (var->yoffset * info->fix.line_length + var->xoffset) / 4; |
| 68 | |
| 69 | __asm__ __volatile__( |
| 70 | "call *(%%edi)" |
| 71 | : /* no return value */ |
| 72 | : "a" (0x4f07), /* EAX */ |
| 73 | "b" (0), /* EBX */ |
| 74 | "c" (offset), /* ECX */ |
| 75 | "d" (offset >> 16), /* EDX */ |
| 76 | "D" (&pmi_start)); /* EDI */ |
| 77 | #endif |
| 78 | return 0; |
| 79 | } |
| 80 | |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 81 | static int vesa_setpalette(int regno, unsigned red, unsigned green, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | unsigned blue) |
| 83 | { |
Antonino A. Daplas | 89ec4c2 | 2006-04-10 22:55:48 -0700 | [diff] [blame] | 84 | int shift = 16 - depth; |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 85 | int err = -EINVAL; |
Antonino A. Daplas | 89ec4c2 | 2006-04-10 22:55:48 -0700 | [diff] [blame] | 86 | |
Antonino A. Daplas | 6dbde38 | 2006-06-26 00:26:41 -0700 | [diff] [blame] | 87 | /* |
| 88 | * Try VGA registers first... |
| 89 | */ |
| 90 | if (vga_compat) { |
| 91 | outb_p(regno, dac_reg); |
| 92 | outb_p(red >> shift, dac_val); |
| 93 | outb_p(green >> shift, dac_val); |
| 94 | outb_p(blue >> shift, dac_val); |
| 95 | err = 0; |
| 96 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Antonino A. Daplas | 6dbde38 | 2006-06-26 00:26:41 -0700 | [diff] [blame] | 98 | #ifdef __i386__ |
| 99 | /* |
| 100 | * Fallback to the PMI.... |
| 101 | */ |
| 102 | if (err && pmi_setpal) { |
| 103 | struct { u_char blue, green, red, pad; } entry; |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | entry.red = red >> shift; |
| 106 | entry.green = green >> shift; |
| 107 | entry.blue = blue >> shift; |
| 108 | entry.pad = 0; |
| 109 | __asm__ __volatile__( |
| 110 | "call *(%%esi)" |
| 111 | : /* no return value */ |
| 112 | : "a" (0x4f09), /* EAX */ |
| 113 | "b" (0), /* EBX */ |
| 114 | "c" (1), /* ECX */ |
| 115 | "d" (regno), /* EDX */ |
| 116 | "D" (&entry), /* EDI */ |
| 117 | "S" (&pmi_pal)); /* ESI */ |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 118 | err = 0; |
Antonino A. Daplas | 89ec4c2 | 2006-04-10 22:55:48 -0700 | [diff] [blame] | 119 | } |
| 120 | #endif |
| 121 | |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 122 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 126 | unsigned blue, unsigned transp, |
| 127 | struct fb_info *info) |
| 128 | { |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 129 | int err = 0; |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* |
| 132 | * Set a single color register. The values supplied are |
| 133 | * already rounded down to the hardware's capabilities |
| 134 | * (according to the entries in the `var' structure). Return |
| 135 | * != 0 for invalid regno. |
| 136 | */ |
| 137 | |
| 138 | if (regno >= info->cmap.len) |
| 139 | return 1; |
| 140 | |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 141 | if (info->var.bits_per_pixel == 8) |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 142 | err = vesa_setpalette(regno,red,green,blue); |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 143 | else if (regno < 16) { |
| 144 | switch (info->var.bits_per_pixel) { |
| 145 | case 16: |
| 146 | if (info->var.red.offset == 10) { |
| 147 | /* 1:5:5:5 */ |
| 148 | ((u32*) (info->pseudo_palette))[regno] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | ((red & 0xf800) >> 1) | |
| 150 | ((green & 0xf800) >> 6) | |
| 151 | ((blue & 0xf800) >> 11); |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 152 | } else { |
| 153 | /* 0:5:6:5 */ |
| 154 | ((u32*) (info->pseudo_palette))[regno] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | ((red & 0xf800) ) | |
| 156 | ((green & 0xfc00) >> 5) | |
| 157 | ((blue & 0xf800) >> 11); |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 158 | } |
| 159 | break; |
| 160 | case 24: |
| 161 | case 32: |
| 162 | red >>= 8; |
| 163 | green >>= 8; |
| 164 | blue >>= 8; |
| 165 | ((u32 *)(info->pseudo_palette))[regno] = |
| 166 | (red << info->var.red.offset) | |
| 167 | (green << info->var.green.offset) | |
| 168 | (blue << info->var.blue.offset); |
| 169 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
Antonino A. Daplas | eba5085 | 2005-11-07 01:00:40 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Antonino A. Daplas | 313ca22 | 2006-06-26 00:26:40 -0700 | [diff] [blame] | 173 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 176 | static void vesafb_destroy(struct fb_info *info) |
| 177 | { |
Daniel J Blueman | 3e86f1d | 2011-06-27 23:08:53 +0000 | [diff] [blame] | 178 | fb_dealloc_cmap(&info->cmap); |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 179 | if (info->screen_base) |
| 180 | iounmap(info->screen_base); |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 181 | release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | static struct fb_ops vesafb_ops = { |
| 185 | .owner = THIS_MODULE, |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 186 | .fb_destroy = vesafb_destroy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | .fb_setcolreg = vesafb_setcolreg, |
| 188 | .fb_pan_display = vesafb_pan_display, |
| 189 | .fb_fillrect = cfb_fillrect, |
| 190 | .fb_copyarea = cfb_copyarea, |
| 191 | .fb_imageblit = cfb_imageblit, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 194 | static int vesafb_setup(char *options) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | char *this_opt; |
| 197 | |
| 198 | if (!options || !*options) |
| 199 | return 0; |
| 200 | |
| 201 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 202 | if (!*this_opt) continue; |
| 203 | |
| 204 | if (! strcmp(this_opt, "inverse")) |
| 205 | inverse=1; |
| 206 | else if (! strcmp(this_opt, "redraw")) |
| 207 | ypan=0; |
| 208 | else if (! strcmp(this_opt, "ypan")) |
| 209 | ypan=1; |
| 210 | else if (! strcmp(this_opt, "ywrap")) |
| 211 | ypan=2; |
| 212 | else if (! strcmp(this_opt, "vgapal")) |
| 213 | pmi_setpal=0; |
| 214 | else if (! strcmp(this_opt, "pmipal")) |
| 215 | pmi_setpal=1; |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 216 | else if (! strncmp(this_opt, "mtrr:", 5)) |
| 217 | mtrr = simple_strtoul(this_opt+5, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | else if (! strcmp(this_opt, "nomtrr")) |
| 219 | mtrr=0; |
| 220 | else if (! strncmp(this_opt, "vtotal:", 7)) |
| 221 | vram_total = simple_strtoul(this_opt+7, NULL, 0); |
| 222 | else if (! strncmp(this_opt, "vremap:", 7)) |
| 223 | vram_remap = simple_strtoul(this_opt+7, NULL, 0); |
| 224 | } |
| 225 | return 0; |
| 226 | } |
| 227 | |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 228 | static int vesafb_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | struct fb_info *info; |
| 231 | int i, err; |
| 232 | unsigned int size_vmode; |
| 233 | unsigned int size_remap; |
| 234 | unsigned int size_total; |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 235 | char *option = NULL; |
| 236 | |
| 237 | /* ignore error return of fb_get_options */ |
| 238 | fb_get_options("vesafb", &option); |
| 239 | vesafb_setup(option); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB) |
| 242 | return -ENODEV; |
| 243 | |
Antonino A. Daplas | 89ec4c2 | 2006-04-10 22:55:48 -0700 | [diff] [blame] | 244 | vga_compat = (screen_info.capabilities & 2) ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | vesafb_fix.smem_start = screen_info.lfb_base; |
| 246 | vesafb_defined.bits_per_pixel = screen_info.lfb_depth; |
| 247 | if (15 == vesafb_defined.bits_per_pixel) |
| 248 | vesafb_defined.bits_per_pixel = 16; |
| 249 | vesafb_defined.xres = screen_info.lfb_width; |
| 250 | vesafb_defined.yres = screen_info.lfb_height; |
| 251 | vesafb_fix.line_length = screen_info.lfb_linelength; |
| 252 | vesafb_fix.visual = (vesafb_defined.bits_per_pixel == 8) ? |
| 253 | FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
| 254 | |
| 255 | /* size_vmode -- that is the amount of memory needed for the |
| 256 | * used video mode, i.e. the minimum amount of |
| 257 | * memory we need. */ |
| 258 | size_vmode = vesafb_defined.yres * vesafb_fix.line_length; |
| 259 | |
| 260 | /* size_total -- all video memory we have. Used for mtrr |
Justin P. Mattock | 8aed628 | 2010-08-14 09:43:21 -0700 | [diff] [blame] | 261 | * entries, resource allocation and bounds |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | * checking. */ |
| 263 | size_total = screen_info.lfb_size * 65536; |
| 264 | if (vram_total) |
| 265 | size_total = vram_total * 1024 * 1024; |
| 266 | if (size_total < size_vmode) |
| 267 | size_total = size_vmode; |
| 268 | |
| 269 | /* size_remap -- the amount of video memory we are going to |
| 270 | * use for vesafb. With modern cards it is no |
| 271 | * option to simply use size_total as that |
| 272 | * wastes plenty of kernel address space. */ |
| 273 | size_remap = size_vmode * 2; |
| 274 | if (vram_remap) |
| 275 | size_remap = vram_remap * 1024 * 1024; |
| 276 | if (size_remap < size_vmode) |
| 277 | size_remap = size_vmode; |
| 278 | if (size_remap > size_total) |
| 279 | size_remap = size_total; |
| 280 | vesafb_fix.smem_len = size_remap; |
| 281 | |
| 282 | #ifndef __i386__ |
| 283 | screen_info.vesapm_seg = 0; |
| 284 | #endif |
| 285 | |
| 286 | if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) { |
| 287 | printk(KERN_WARNING |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 288 | "vesafb: cannot reserve video memory at 0x%lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | vesafb_fix.smem_start); |
| 290 | /* We cannot make this fatal. Sometimes this comes from magic |
| 291 | spaces our resource handlers simply don't know about */ |
| 292 | } |
| 293 | |
| 294 | info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev); |
| 295 | if (!info) { |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 296 | release_mem_region(vesafb_fix.smem_start, size_total); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return -ENOMEM; |
| 298 | } |
David Herrmann | 60231da | 2014-01-23 15:14:56 +0100 | [diff] [blame] | 299 | platform_set_drvdata(dev, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | info->pseudo_palette = info->par; |
| 301 | info->par = NULL; |
| 302 | |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 303 | /* set vesafb aperture size for generic probing */ |
Marcin Slusarz | 1471ca9 | 2010-05-16 17:27:03 +0200 | [diff] [blame] | 304 | info->apertures = alloc_apertures(1); |
| 305 | if (!info->apertures) { |
| 306 | err = -ENOMEM; |
| 307 | goto err; |
| 308 | } |
| 309 | info->apertures->ranges[0].base = screen_info.lfb_base; |
| 310 | info->apertures->ranges[0].size = size_total; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n", |
| 313 | vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages); |
| 314 | |
| 315 | if (screen_info.vesapm_seg) { |
| 316 | printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n", |
| 317 | screen_info.vesapm_seg,screen_info.vesapm_off); |
| 318 | } |
| 319 | |
| 320 | if (screen_info.vesapm_seg < 0xc000) |
| 321 | ypan = pmi_setpal = 0; /* not available or some DOS TSR ... */ |
| 322 | |
| 323 | if (ypan || pmi_setpal) { |
Helge Deller | 4670358 | 2006-12-08 02:40:30 -0800 | [diff] [blame] | 324 | unsigned short *pmi_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off); |
| 326 | pmi_start = (void*)((char*)pmi_base + pmi_base[1]); |
| 327 | pmi_pal = (void*)((char*)pmi_base + pmi_base[2]); |
| 328 | printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal); |
| 329 | if (pmi_base[3]) { |
| 330 | printk(KERN_INFO "vesafb: pmi: ports = "); |
| 331 | for (i = pmi_base[3]/2; pmi_base[i] != 0xffff; i++) |
| 332 | printk("%x ",pmi_base[i]); |
| 333 | printk("\n"); |
| 334 | if (pmi_base[i] != 0xffff) { |
| 335 | /* |
| 336 | * memory areas not supported (yet?) |
| 337 | * |
| 338 | * Rules are: we have to set up a descriptor for the requested |
| 339 | * memory area and pass it in the ES register to the BIOS function. |
| 340 | */ |
| 341 | printk(KERN_INFO "vesafb: can't handle memory requests, pmi disabled\n"); |
| 342 | ypan = pmi_setpal = 0; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Antonino A. Daplas | 89ec4c2 | 2006-04-10 22:55:48 -0700 | [diff] [blame] | 347 | if (vesafb_defined.bits_per_pixel == 8 && !pmi_setpal && !vga_compat) { |
| 348 | printk(KERN_WARNING "vesafb: hardware palette is unchangeable,\n" |
| 349 | " colors may be incorrect\n"); |
| 350 | vesafb_fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR; |
| 351 | } |
| 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | vesafb_defined.xres_virtual = vesafb_defined.xres; |
| 354 | vesafb_defined.yres_virtual = vesafb_fix.smem_len / vesafb_fix.line_length; |
| 355 | if (ypan && vesafb_defined.yres_virtual > vesafb_defined.yres) { |
| 356 | printk(KERN_INFO "vesafb: scrolling: %s using protected mode interface, yres_virtual=%d\n", |
| 357 | (ypan > 1) ? "ywrap" : "ypan",vesafb_defined.yres_virtual); |
| 358 | } else { |
| 359 | printk(KERN_INFO "vesafb: scrolling: redraw\n"); |
| 360 | vesafb_defined.yres_virtual = vesafb_defined.yres; |
| 361 | ypan = 0; |
| 362 | } |
| 363 | |
| 364 | /* some dummy values for timing to make fbset happy */ |
| 365 | vesafb_defined.pixclock = 10000000 / vesafb_defined.xres * 1000 / vesafb_defined.yres; |
| 366 | vesafb_defined.left_margin = (vesafb_defined.xres / 8) & 0xf8; |
| 367 | vesafb_defined.hsync_len = (vesafb_defined.xres / 8) & 0xf8; |
| 368 | |
| 369 | vesafb_defined.red.offset = screen_info.red_pos; |
| 370 | vesafb_defined.red.length = screen_info.red_size; |
| 371 | vesafb_defined.green.offset = screen_info.green_pos; |
| 372 | vesafb_defined.green.length = screen_info.green_size; |
| 373 | vesafb_defined.blue.offset = screen_info.blue_pos; |
| 374 | vesafb_defined.blue.length = screen_info.blue_size; |
| 375 | vesafb_defined.transp.offset = screen_info.rsvd_pos; |
| 376 | vesafb_defined.transp.length = screen_info.rsvd_size; |
| 377 | |
| 378 | if (vesafb_defined.bits_per_pixel <= 8) { |
| 379 | depth = vesafb_defined.green.length; |
| 380 | vesafb_defined.red.length = |
| 381 | vesafb_defined.green.length = |
| 382 | vesafb_defined.blue.length = |
| 383 | vesafb_defined.bits_per_pixel; |
| 384 | } |
| 385 | |
| 386 | printk(KERN_INFO "vesafb: %s: " |
| 387 | "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n", |
| 388 | (vesafb_defined.bits_per_pixel > 8) ? |
Antonino A. Daplas | 89ec4c2 | 2006-04-10 22:55:48 -0700 | [diff] [blame] | 389 | "Truecolor" : (vga_compat || pmi_setpal) ? |
| 390 | "Pseudocolor" : "Static Pseudocolor", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | screen_info.rsvd_size, |
| 392 | screen_info.red_size, |
| 393 | screen_info.green_size, |
| 394 | screen_info.blue_size, |
| 395 | screen_info.rsvd_pos, |
| 396 | screen_info.red_pos, |
| 397 | screen_info.green_pos, |
| 398 | screen_info.blue_pos); |
| 399 | |
| 400 | vesafb_fix.ypanstep = ypan ? 1 : 0; |
| 401 | vesafb_fix.ywrapstep = (ypan>1) ? 1 : 0; |
| 402 | |
| 403 | /* request failure does not faze us, as vgacon probably has this |
| 404 | * region already (FIXME) */ |
| 405 | request_region(0x3c0, 32, "vesafb"); |
| 406 | |
Jan Beulich | f5f4917c | 2005-11-13 16:08:12 -0800 | [diff] [blame] | 407 | #ifdef CONFIG_MTRR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | if (mtrr) { |
Gerd Knorr | 78c0371 | 2005-06-21 17:16:56 -0700 | [diff] [blame] | 409 | unsigned int temp_size = size_total; |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 410 | unsigned int type = 0; |
Dave Jones | d7496cb | 2005-06-25 14:58:30 -0700 | [diff] [blame] | 411 | |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 412 | switch (mtrr) { |
| 413 | case 1: |
| 414 | type = MTRR_TYPE_UNCACHABLE; |
| 415 | break; |
| 416 | case 2: |
| 417 | type = MTRR_TYPE_WRBACK; |
| 418 | break; |
| 419 | case 3: |
| 420 | type = MTRR_TYPE_WRCOMB; |
| 421 | break; |
| 422 | case 4: |
| 423 | type = MTRR_TYPE_WRTHROUGH; |
| 424 | break; |
| 425 | default: |
| 426 | type = 0; |
| 427 | break; |
| 428 | } |
| 429 | |
| 430 | if (type) { |
| 431 | int rc; |
| 432 | |
| 433 | /* Find the largest power-of-two */ |
Thomas Schlichter | 803a4e1 | 2010-11-27 14:17:55 +0100 | [diff] [blame] | 434 | temp_size = roundup_pow_of_two(temp_size); |
Antonino A. Daplas | 8062594 | 2005-07-29 14:03:31 -0700 | [diff] [blame] | 435 | |
| 436 | /* Try and find a power of two to add */ |
| 437 | do { |
| 438 | rc = mtrr_add(vesafb_fix.smem_start, temp_size, |
| 439 | type, 1); |
| 440 | temp_size >>= 1; |
| 441 | } while (temp_size >= PAGE_SIZE && rc == -EINVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
Jan Beulich | f5f4917c | 2005-11-13 16:08:12 -0800 | [diff] [blame] | 444 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Thomas Schlichter | 803a4e1 | 2010-11-27 14:17:55 +0100 | [diff] [blame] | 446 | switch (mtrr) { |
| 447 | case 1: /* uncachable */ |
| 448 | info->screen_base = ioremap_nocache(vesafb_fix.smem_start, vesafb_fix.smem_len); |
| 449 | break; |
| 450 | case 2: /* write-back */ |
| 451 | info->screen_base = ioremap_cache(vesafb_fix.smem_start, vesafb_fix.smem_len); |
| 452 | break; |
| 453 | case 3: /* write-combining */ |
| 454 | info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len); |
| 455 | break; |
| 456 | case 4: /* write-through */ |
| 457 | default: |
| 458 | info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len); |
| 459 | break; |
| 460 | } |
| 461 | if (!info->screen_base) { |
| 462 | printk(KERN_ERR |
| 463 | "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n", |
| 464 | vesafb_fix.smem_len, vesafb_fix.smem_start); |
| 465 | err = -EIO; |
| 466 | goto err; |
| 467 | } |
| 468 | |
| 469 | printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, " |
| 470 | "using %dk, total %dk\n", |
| 471 | vesafb_fix.smem_start, info->screen_base, |
| 472 | size_remap/1024, size_total/1024); |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | info->fbops = &vesafb_ops; |
| 475 | info->var = vesafb_defined; |
| 476 | info->fix = vesafb_fix; |
Dave Airlie | 4410f39 | 2009-06-16 15:34:38 -0700 | [diff] [blame] | 477 | info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE | |
Roel Kluin | b83734e | 2009-03-31 15:25:36 -0700 | [diff] [blame] | 478 | (ypan ? FBINFO_HWACCEL_YPAN : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Antonino A. Daplas | e53f87a | 2006-01-09 20:53:18 -0800 | [diff] [blame] | 480 | if (!ypan) |
| 481 | info->fbops->fb_pan_display = NULL; |
| 482 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { |
| 484 | err = -ENOMEM; |
| 485 | goto err; |
| 486 | } |
| 487 | if (register_framebuffer(info)<0) { |
| 488 | err = -EINVAL; |
| 489 | fb_dealloc_cmap(&info->cmap); |
| 490 | goto err; |
| 491 | } |
Joe Perches | 31b6780 | 2013-09-19 18:35:55 -0700 | [diff] [blame] | 492 | fb_info(info, "%s frame buffer device\n", info->fix.id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return 0; |
| 494 | err: |
Amol Lad | b88a57c | 2006-12-08 02:40:02 -0800 | [diff] [blame] | 495 | if (info->screen_base) |
| 496 | iounmap(info->screen_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | framebuffer_release(info); |
| 498 | release_mem_region(vesafb_fix.smem_start, size_total); |
| 499 | return err; |
| 500 | } |
| 501 | |
David Herrmann | 60231da | 2014-01-23 15:14:56 +0100 | [diff] [blame] | 502 | static int vesafb_remove(struct platform_device *pdev) |
| 503 | { |
| 504 | struct fb_info *info = platform_get_drvdata(pdev); |
| 505 | |
| 506 | unregister_framebuffer(info); |
| 507 | framebuffer_release(info); |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 512 | static struct platform_driver vesafb_driver = { |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 513 | .driver = { |
| 514 | .name = "vesa-framebuffer", |
| 515 | .owner = THIS_MODULE, |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 516 | }, |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 517 | .probe = vesafb_probe, |
David Herrmann | 60231da | 2014-01-23 15:14:56 +0100 | [diff] [blame] | 518 | .remove = vesafb_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | }; |
| 520 | |
David Herrmann | 2e5155e | 2013-08-02 14:05:25 +0200 | [diff] [blame] | 521 | module_platform_driver(vesafb_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | MODULE_LICENSE("GPL"); |