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/bootx.h>
38 /* Supported palette hacks */
41 cmap_m64, /* ATI Mach64 */
42 cmap_r128, /* ATI Rage128 */
43 cmap_M3A, /* ATI Rage Mobility M3 Head A */
44 cmap_M3B, /* ATI Rage Mobility M3 Head B */
45 cmap_radeon, /* ATI Radeon */
46 cmap_gxt2000, /* IBM GXT2000 */
50 volatile void __iomem *cmap_adr;
51 volatile void __iomem *cmap_data;
56 struct offb_par default_par;
59 * Interface used by the world
64 static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
65 u_int transp, struct fb_info *info);
66 static int offb_blank(int blank, struct fb_info *info);
69 extern boot_infos_t *boot_infos;
72 static void offb_init_nodriver(struct device_node *);
73 static void offb_init_fb(const char *name, const char *full_name,
74 int width, int height, int depth, int pitch,
75 unsigned long address, struct device_node *dp);
77 static struct fb_ops offb_ops = {
79 .fb_setcolreg = offb_setcolreg,
80 .fb_blank = offb_blank,
81 .fb_fillrect = cfb_fillrect,
82 .fb_copyarea = cfb_copyarea,
83 .fb_imageblit = cfb_imageblit,
84 .fb_cursor = soft_cursor,
88 * Set a single color register. The values supplied are already
89 * rounded down to the hardware's capabilities (according to the
90 * entries in the var structure). Return != 0 for invalid regno.
93 static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
94 u_int transp, struct fb_info *info)
96 struct offb_par *par = (struct offb_par *) info->par;
98 if (!par->cmap_adr || regno > 255)
105 switch (par->cmap_type) {
107 writeb(regno, par->cmap_adr);
108 writeb(red, par->cmap_data);
109 writeb(green, par->cmap_data);
110 writeb(blue, par->cmap_data);
113 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
114 out_le32(par->cmap_adr + 0x58,
115 in_le32(par->cmap_adr + 0x58) & ~0x20);
117 /* Set palette index & data */
118 out_8(par->cmap_adr + 0xb0, regno);
119 out_le32(par->cmap_adr + 0xb4,
120 (red << 16 | green << 8 | blue));
123 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
124 out_le32(par->cmap_adr + 0x58,
125 in_le32(par->cmap_adr + 0x58) | 0x20);
126 /* Set palette index & data */
127 out_8(par->cmap_adr + 0xb0, regno);
128 out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
131 /* Set palette index & data (could be smarter) */
132 out_8(par->cmap_adr + 0xb0, regno);
133 out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
136 out_le32((unsigned __iomem *) par->cmap_adr + regno,
137 (red << 16 | green << 8 | blue));
142 switch (info->var.bits_per_pixel) {
144 ((u16 *) (info->pseudo_palette))[regno] =
145 (regno << 10) | (regno << 5) | regno;
149 int i = (regno << 8) | regno;
150 ((u32 *) (info->pseudo_palette))[regno] =
162 static int offb_blank(int blank, struct fb_info *info)
164 struct offb_par *par = (struct offb_par *) info->par;
174 par->blanked = blank;
177 for (i = 0; i < 256; i++) {
178 switch (par->cmap_type) {
180 writeb(i, par->cmap_adr);
181 for (j = 0; j < 3; j++)
182 writeb(0, par->cmap_data);
185 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
186 out_le32(par->cmap_adr + 0x58,
187 in_le32(par->cmap_adr + 0x58) & ~0x20);
189 /* Set palette index & data */
190 out_8(par->cmap_adr + 0xb0, i);
191 out_le32(par->cmap_adr + 0xb4, 0);
194 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
195 out_le32(par->cmap_adr + 0x58,
196 in_le32(par->cmap_adr + 0x58) | 0x20);
197 /* Set palette index & data */
198 out_8(par->cmap_adr + 0xb0, i);
199 out_le32(par->cmap_adr + 0xb4, 0);
202 out_8(par->cmap_adr + 0xb0, i);
203 out_le32(par->cmap_adr + 0xb4, 0);
206 out_le32((unsigned __iomem *) par->cmap_adr + i,
211 fb_set_cmap(&info->cmap, info);
219 int __init offb_init(void)
221 struct device_node *dp = NULL, *boot_disp = NULL;
222 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
223 struct device_node *macos_display = NULL;
225 if (fb_get_options("offb", NULL))
228 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
229 /* If we're booted from BootX... */
230 if (boot_infos != 0) {
232 (unsigned long) boot_infos->dispDeviceBase;
233 /* find the device node corresponding to the macos display */
234 while ((dp = of_find_node_by_type(dp, "display"))) {
237 * Grrr... It looks like the MacOS ATI driver
238 * munges the assigned-addresses property (but
239 * the AAPL,address value is OK).
241 if (strncmp(dp->name, "ATY,", 4) == 0
242 && dp->n_addrs == 1) {
244 (unsigned int *) get_property(dp,
248 dp->addrs[0].address = *ap;
249 dp->addrs[0].size = 0x01000000;
254 * The LTPro on the Lombard powerbook has no addresses
255 * on the display nodes, they are on their parent.
258 && device_is_compatible(dp, "ATY,264LTPro")) {
260 unsigned int *ap = (unsigned int *)
261 get_property(dp, "AAPL,address", &na);
263 for (na /= sizeof(unsigned int);
272 * See if the display address is in one of the address
273 * ranges for this display.
275 for (i = 0; i < dp->n_addrs; ++i) {
276 if (dp->addrs[i].address <= addr
278 dp->addrs[i].address +
282 if (i < dp->n_addrs) {
284 printk(KERN_INFO "MacOS display is %s\n",
292 offb_init_fb(macos_display ? macos_display->
293 name : "MacOS display",
294 macos_display ? macos_display->
295 full_name : "MacOS display",
296 boot_infos->dispDeviceRect[2],
297 boot_infos->dispDeviceRect[3],
298 boot_infos->dispDeviceDepth,
299 boot_infos->dispDeviceRowBytes, addr, NULL);
301 #endif /* defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) */
303 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
304 if (get_property(dp, "linux,opened", NULL) &&
305 get_property(dp, "linux,boot-display", NULL)) {
307 offb_init_nodriver(dp);
310 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
311 if (get_property(dp, "linux,opened", NULL) &&
313 offb_init_nodriver(dp);
320 static void __init offb_init_nodriver(struct device_node *dp)
324 int width = 640, height = 480, depth = 8, pitch;
325 unsigned *up, address;
327 if ((pp = (int *) get_property(dp, "depth", &len)) != NULL
328 && len == sizeof(int))
330 if ((pp = (int *) get_property(dp, "width", &len)) != NULL
331 && len == sizeof(int))
333 if ((pp = (int *) get_property(dp, "height", &len)) != NULL
334 && len == sizeof(int))
336 if ((pp = (int *) get_property(dp, "linebytes", &len)) != NULL
337 && len == sizeof(int)) {
343 if ((up = (unsigned *) get_property(dp, "address", &len)) != NULL
344 && len == sizeof(unsigned))
345 address = (u_long) * up;
347 for (i = 0; i < dp->n_addrs; ++i)
348 if (dp->addrs[i].size >=
349 pitch * height * depth / 8)
351 if (i >= dp->n_addrs) {
353 "no framebuffer address found for %s\n",
358 address = (u_long) dp->addrs[i].address;
360 /* kludge for valkyrie */
361 if (strcmp(dp->name, "valkyrie") == 0)
364 offb_init_fb(dp->name, dp->full_name, width, height, depth,
369 static void __init offb_init_fb(const char *name, const char *full_name,
370 int width, int height, int depth,
371 int pitch, unsigned long address,
372 struct device_node *dp)
374 unsigned long res_size = pitch * height * depth / 8;
375 struct offb_par *par = &default_par;
376 unsigned long res_start = address;
377 struct fb_fix_screeninfo *fix;
378 struct fb_var_screeninfo *var;
379 struct fb_info *info;
382 if (!request_mem_region(res_start, res_size, "offb"))
386 "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
387 width, height, name, address, depth, pitch);
388 if (depth != 8 && depth != 16 && depth != 32) {
389 printk(KERN_ERR "%s: can't use depth = %d\n", full_name,
391 release_mem_region(res_start, res_size);
395 size = sizeof(struct fb_info) + sizeof(u32) * 17;
397 info = kmalloc(size, GFP_ATOMIC);
400 release_mem_region(res_start, res_size);
403 memset(info, 0, size);
408 strcpy(fix->id, "OFfb ");
409 strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb "));
410 fix->id[sizeof(fix->id) - 1] = '\0';
412 var->xres = var->xres_virtual = width;
413 var->yres = var->yres_virtual = height;
414 fix->line_length = pitch;
416 fix->smem_start = address;
417 fix->smem_len = pitch * height;
418 fix->type = FB_TYPE_PACKED_PIXELS;
421 par->cmap_type = cmap_unknown;
423 /* XXX kludge for ati */
424 if (dp && !strncmp(name, "ATY,Rage128", 11)) {
425 unsigned long regbase = dp->addrs[2].address;
426 par->cmap_adr = ioremap(regbase, 0x1FFF);
427 par->cmap_type = cmap_r128;
428 } else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
429 || !strncmp(name, "ATY,RageM3p12A", 14))) {
430 unsigned long regbase =
431 dp->parent->addrs[2].address;
432 par->cmap_adr = ioremap(regbase, 0x1FFF);
433 par->cmap_type = cmap_M3A;
434 } else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
435 unsigned long regbase =
436 dp->parent->addrs[2].address;
437 par->cmap_adr = ioremap(regbase, 0x1FFF);
438 par->cmap_type = cmap_M3B;
439 } else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
440 unsigned long regbase = dp->addrs[1].address;
441 par->cmap_adr = ioremap(regbase, 0x1FFF);
442 par->cmap_type = cmap_radeon;
443 } else if (!strncmp(name, "ATY,", 4)) {
444 unsigned long base = address & 0xff000000UL;
446 ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
447 par->cmap_data = par->cmap_adr + 1;
448 par->cmap_type = cmap_m64;
449 } else if (device_is_compatible(dp, "pci1014,b7")) {
450 unsigned long regbase = dp->addrs[0].address;
451 par->cmap_adr = ioremap(regbase + 0x6000, 0x1000);
452 par->cmap_type = cmap_gxt2000;
454 fix->visual = par->cmap_adr ? FB_VISUAL_PSEUDOCOLOR
455 : FB_VISUAL_STATIC_PSEUDOCOLOR;
457 fix->visual = /* par->cmap_adr ? FB_VISUAL_DIRECTCOLOR
458 : */ FB_VISUAL_TRUECOLOR;
460 var->xoffset = var->yoffset = 0;
461 var->bits_per_pixel = depth;
464 var->bits_per_pixel = 8;
467 var->green.offset = 0;
468 var->green.length = 8;
469 var->blue.offset = 0;
470 var->blue.length = 8;
471 var->transp.offset = 0;
472 var->transp.length = 0;
474 case 16: /* RGB 555 */
475 var->bits_per_pixel = 16;
476 var->red.offset = 10;
478 var->green.offset = 5;
479 var->green.length = 5;
480 var->blue.offset = 0;
481 var->blue.length = 5;
482 var->transp.offset = 0;
483 var->transp.length = 0;
485 case 32: /* RGB 888 */
486 var->bits_per_pixel = 32;
487 var->red.offset = 16;
489 var->green.offset = 8;
490 var->green.length = 8;
491 var->blue.offset = 0;
492 var->blue.length = 8;
493 var->transp.offset = 24;
494 var->transp.length = 8;
497 var->red.msb_right = var->green.msb_right = var->blue.msb_right =
498 var->transp.msb_right = 0;
502 var->height = var->width = -1;
503 var->pixclock = 10000;
504 var->left_margin = var->right_margin = 16;
505 var->upper_margin = var->lower_margin = 16;
506 var->hsync_len = var->vsync_len = 8;
508 var->vmode = FB_VMODE_NONINTERLACED;
510 info->fbops = &offb_ops;
511 info->screen_base = ioremap(address, fix->smem_len);
513 info->pseudo_palette = (void *) (info + 1);
514 info->flags = FBINFO_DEFAULT;
516 fb_alloc_cmap(&info->cmap, 256, 0);
518 if (register_framebuffer(info) < 0) {
520 release_mem_region(res_start, res_size);
524 printk(KERN_INFO "fb%d: Open Firmware frame buffer device on %s\n",
525 info->node, full_name);
528 module_init(offb_init);
529 MODULE_LICENSE("GPL");