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