2 * linux/drivers/video/offb.c -- Open Firmware based frame buffer device
4 * Copyright (C) 1997 Geert Uytterhoeven
6 * This driver is partly based on the PowerMac console driver:
8 * Copyright (C) 1996 Paul Mackerras
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for
15 #include <linux/config.h>
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/errno.h>
19 #include <linux/string.h>
21 #include <linux/tty.h>
22 #include <linux/slab.h>
23 #include <linux/vmalloc.h>
24 #include <linux/delay.h>
25 #include <linux/interrupt.h>
27 #include <linux/init.h>
28 #include <linux/ioport.h>
33 #include <asm/pci-bridge.h>
37 #include <asm/bootx.h>
42 /* Supported palette hacks */
45 cmap_m64, /* ATI Mach64 */
46 cmap_r128, /* ATI Rage128 */
47 cmap_M3A, /* ATI Rage Mobility M3 Head A */
48 cmap_M3B, /* ATI Rage Mobility M3 Head B */
49 cmap_radeon, /* ATI Radeon */
50 cmap_gxt2000, /* IBM GXT2000 */
54 volatile void __iomem *cmap_adr;
55 volatile void __iomem *cmap_data;
60 struct offb_par default_par;
63 * Interface used by the world
68 static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
69 u_int transp, struct fb_info *info);
70 static int offb_blank(int blank, struct fb_info *info);
73 extern boot_infos_t *boot_infos;
76 static void offb_init_nodriver(struct device_node *);
77 static void offb_init_fb(const char *name, const char *full_name,
78 int width, int height, int depth, int pitch,
79 unsigned long address, struct device_node *dp);
81 static struct fb_ops offb_ops = {
83 .fb_setcolreg = offb_setcolreg,
84 .fb_blank = offb_blank,
85 .fb_fillrect = cfb_fillrect,
86 .fb_copyarea = cfb_copyarea,
87 .fb_imageblit = cfb_imageblit,
91 * Set a single color register. The values supplied are already
92 * rounded down to the hardware's capabilities (according to the
93 * entries in the var structure). Return != 0 for invalid regno.
96 static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
97 u_int transp, struct fb_info *info)
99 struct offb_par *par = (struct offb_par *) info->par;
101 if (!par->cmap_adr || regno > 255)
108 switch (par->cmap_type) {
110 writeb(regno, par->cmap_adr);
111 writeb(red, par->cmap_data);
112 writeb(green, par->cmap_data);
113 writeb(blue, par->cmap_data);
116 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
117 out_le32(par->cmap_adr + 0x58,
118 in_le32(par->cmap_adr + 0x58) & ~0x20);
120 /* Set palette index & data */
121 out_8(par->cmap_adr + 0xb0, regno);
122 out_le32(par->cmap_adr + 0xb4,
123 (red << 16 | green << 8 | blue));
126 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
127 out_le32(par->cmap_adr + 0x58,
128 in_le32(par->cmap_adr + 0x58) | 0x20);
129 /* Set palette index & data */
130 out_8(par->cmap_adr + 0xb0, regno);
131 out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
134 /* Set palette index & data (could be smarter) */
135 out_8(par->cmap_adr + 0xb0, regno);
136 out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
139 out_le32((unsigned __iomem *) par->cmap_adr + regno,
140 (red << 16 | green << 8 | blue));
145 switch (info->var.bits_per_pixel) {
147 ((u16 *) (info->pseudo_palette))[regno] =
148 (regno << 10) | (regno << 5) | regno;
152 int i = (regno << 8) | regno;
153 ((u32 *) (info->pseudo_palette))[regno] =
165 static int offb_blank(int blank, struct fb_info *info)
167 struct offb_par *par = (struct offb_par *) info->par;
177 par->blanked = blank;
180 for (i = 0; i < 256; i++) {
181 switch (par->cmap_type) {
183 writeb(i, par->cmap_adr);
184 for (j = 0; j < 3; j++)
185 writeb(0, par->cmap_data);
188 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
189 out_le32(par->cmap_adr + 0x58,
190 in_le32(par->cmap_adr + 0x58) & ~0x20);
192 /* Set palette index & data */
193 out_8(par->cmap_adr + 0xb0, i);
194 out_le32(par->cmap_adr + 0xb4, 0);
197 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
198 out_le32(par->cmap_adr + 0x58,
199 in_le32(par->cmap_adr + 0x58) | 0x20);
200 /* Set palette index & data */
201 out_8(par->cmap_adr + 0xb0, i);
202 out_le32(par->cmap_adr + 0xb4, 0);
205 out_8(par->cmap_adr + 0xb0, i);
206 out_le32(par->cmap_adr + 0xb4, 0);
209 out_le32((unsigned __iomem *) par->cmap_adr + i,
214 fb_set_cmap(&info->cmap, info);
222 int __init offb_init(void)
224 struct device_node *dp = NULL, *boot_disp = NULL;
225 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
226 struct device_node *macos_display = NULL;
228 if (fb_get_options("offb", NULL))
231 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
232 /* If we're booted from BootX... */
233 if (boot_infos != 0) {
235 (unsigned long) boot_infos->dispDeviceBase;
236 /* find the device node corresponding to the macos display */
237 while ((dp = of_find_node_by_type(dp, "display"))) {
240 * Grrr... It looks like the MacOS ATI driver
241 * munges the assigned-addresses property (but
242 * the AAPL,address value is OK).
244 if (strncmp(dp->name, "ATY,", 4) == 0
245 && dp->n_addrs == 1) {
247 (unsigned int *) get_property(dp,
251 dp->addrs[0].address = *ap;
252 dp->addrs[0].size = 0x01000000;
257 * The LTPro on the Lombard powerbook has no addresses
258 * on the display nodes, they are on their parent.
261 && device_is_compatible(dp, "ATY,264LTPro")) {
263 unsigned int *ap = (unsigned int *)
264 get_property(dp, "AAPL,address", &na);
266 for (na /= sizeof(unsigned int);
275 * See if the display address is in one of the address
276 * ranges for this display.
278 for (i = 0; i < dp->n_addrs; ++i) {
279 if (dp->addrs[i].address <= addr
281 dp->addrs[i].address +
285 if (i < dp->n_addrs) {
287 printk(KERN_INFO "MacOS display is %s\n",
295 offb_init_fb(macos_display ? macos_display->
296 name : "MacOS display",
297 macos_display ? macos_display->
298 full_name : "MacOS display",
299 boot_infos->dispDeviceRect[2],
300 boot_infos->dispDeviceRect[3],
301 boot_infos->dispDeviceDepth,
302 boot_infos->dispDeviceRowBytes, addr, NULL);
304 #endif /* defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) */
306 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
307 if (get_property(dp, "linux,opened", NULL) &&
308 get_property(dp, "linux,boot-display", NULL)) {
310 offb_init_nodriver(dp);
313 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
314 if (get_property(dp, "linux,opened", NULL) &&
316 offb_init_nodriver(dp);
323 static void __init offb_init_nodriver(struct device_node *dp)
327 int width = 640, height = 480, depth = 8, pitch;
329 unsigned long address;
331 if ((pp = (int *) get_property(dp, "depth", &len)) != NULL
332 && len == sizeof(int))
334 if ((pp = (int *) get_property(dp, "width", &len)) != NULL
335 && len == sizeof(int))
337 if ((pp = (int *) get_property(dp, "height", &len)) != NULL
338 && len == sizeof(int))
340 if ((pp = (int *) get_property(dp, "linebytes", &len)) != NULL
341 && len == sizeof(int)) {
347 if ((up = (unsigned *) get_property(dp, "address", &len)) != NULL
348 && len == sizeof(unsigned))
349 address = (u_long) * up;
351 for (i = 0; i < dp->n_addrs; ++i)
352 if (dp->addrs[i].size >=
353 pitch * height * depth / 8)
355 if (i >= dp->n_addrs) {
357 "no framebuffer address found for %s\n",
362 address = (u_long) dp->addrs[i].address;
365 address += ((struct pci_dn *)dp->data)->phb->pci_mem_offset;
368 /* kludge for valkyrie */
369 if (strcmp(dp->name, "valkyrie") == 0)
372 offb_init_fb(dp->name, dp->full_name, width, height, depth,
377 static void __init offb_init_fb(const char *name, const char *full_name,
378 int width, int height, int depth,
379 int pitch, unsigned long address,
380 struct device_node *dp)
382 unsigned long res_size = pitch * height * depth / 8;
383 struct offb_par *par = &default_par;
384 unsigned long res_start = address;
385 struct fb_fix_screeninfo *fix;
386 struct fb_var_screeninfo *var;
387 struct fb_info *info;
390 if (!request_mem_region(res_start, res_size, "offb"))
394 "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
395 width, height, name, address, depth, pitch);
396 if (depth != 8 && depth != 16 && depth != 32) {
397 printk(KERN_ERR "%s: can't use depth = %d\n", full_name,
399 release_mem_region(res_start, res_size);
403 size = sizeof(struct fb_info) + sizeof(u32) * 17;
405 info = kmalloc(size, GFP_ATOMIC);
408 release_mem_region(res_start, res_size);
411 memset(info, 0, size);
416 strcpy(fix->id, "OFfb ");
417 strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb "));
418 fix->id[sizeof(fix->id) - 1] = '\0';
420 var->xres = var->xres_virtual = width;
421 var->yres = var->yres_virtual = height;
422 fix->line_length = pitch;
424 fix->smem_start = address;
425 fix->smem_len = pitch * height;
426 fix->type = FB_TYPE_PACKED_PIXELS;
429 par->cmap_type = cmap_unknown;
431 /* XXX kludge for ati */
432 if (dp && !strncmp(name, "ATY,Rage128", 11)) {
433 unsigned long regbase = dp->addrs[2].address;
434 par->cmap_adr = ioremap(regbase, 0x1FFF);
435 par->cmap_type = cmap_r128;
436 } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
437 || !strncmp(name, "ATY,RageM3p12A", 14))) {
438 unsigned long regbase =
439 dp->parent->addrs[2].address;
440 par->cmap_adr = ioremap(regbase, 0x1FFF);
441 par->cmap_type = cmap_M3A;
442 } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
443 unsigned long regbase =
444 dp->parent->addrs[2].address;
445 par->cmap_adr = ioremap(regbase, 0x1FFF);
446 par->cmap_type = cmap_M3B;
447 } else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
448 unsigned long regbase = dp->addrs[1].address;
449 par->cmap_adr = ioremap(regbase, 0x1FFF);
450 par->cmap_type = cmap_radeon;
451 } else if (!strncmp(name, "ATY,", 4)) {
452 unsigned long base = address & 0xff000000UL;
454 ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
455 par->cmap_data = par->cmap_adr + 1;
456 par->cmap_type = cmap_m64;
457 } else if (device_is_compatible(dp, "pci1014,b7")) {
458 unsigned long regbase = dp->addrs[0].address;
459 par->cmap_adr = ioremap(regbase + 0x6000, 0x1000);
460 par->cmap_type = cmap_gxt2000;
462 fix->visual = par->cmap_adr ? FB_VISUAL_PSEUDOCOLOR
463 : FB_VISUAL_STATIC_PSEUDOCOLOR;
465 fix->visual = /* par->cmap_adr ? FB_VISUAL_DIRECTCOLOR
466 : */ FB_VISUAL_TRUECOLOR;
468 var->xoffset = var->yoffset = 0;
469 var->bits_per_pixel = depth;
472 var->bits_per_pixel = 8;
475 var->green.offset = 0;
476 var->green.length = 8;
477 var->blue.offset = 0;
478 var->blue.length = 8;
479 var->transp.offset = 0;
480 var->transp.length = 0;
482 case 16: /* RGB 555 */
483 var->bits_per_pixel = 16;
484 var->red.offset = 10;
486 var->green.offset = 5;
487 var->green.length = 5;
488 var->blue.offset = 0;
489 var->blue.length = 5;
490 var->transp.offset = 0;
491 var->transp.length = 0;
493 case 32: /* RGB 888 */
494 var->bits_per_pixel = 32;
495 var->red.offset = 16;
497 var->green.offset = 8;
498 var->green.length = 8;
499 var->blue.offset = 0;
500 var->blue.length = 8;
501 var->transp.offset = 24;
502 var->transp.length = 8;
505 var->red.msb_right = var->green.msb_right = var->blue.msb_right =
506 var->transp.msb_right = 0;
510 var->height = var->width = -1;
511 var->pixclock = 10000;
512 var->left_margin = var->right_margin = 16;
513 var->upper_margin = var->lower_margin = 16;
514 var->hsync_len = var->vsync_len = 8;
516 var->vmode = FB_VMODE_NONINTERLACED;
518 info->fbops = &offb_ops;
519 info->screen_base = ioremap(address, fix->smem_len);
521 info->pseudo_palette = (void *) (info + 1);
522 info->flags = FBINFO_DEFAULT;
524 fb_alloc_cmap(&info->cmap, 256, 0);
526 if (register_framebuffer(info) < 0) {
528 release_mem_region(res_start, res_size);
532 printk(KERN_INFO "fb%d: Open Firmware frame buffer device on %s\n",
533 info->node, full_name);
536 module_init(offb_init);
537 MODULE_LICENSE("GPL");