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 unsigned char *cmap_adr
;
51 volatile unsigned char *cmap_data
;
56 struct offb_par default_par
;
59 #define mach_eieio() eieio()
61 #define mach_eieio() do {} while (0)
65 * Interface used by the world
70 static int offb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
71 u_int transp
, struct fb_info
*info
);
72 static int offb_blank(int blank
, struct fb_info
*info
);
75 extern boot_infos_t
*boot_infos
;
78 static void offb_init_nodriver(struct device_node
*);
79 static void offb_init_fb(const char *name
, const char *full_name
,
80 int width
, int height
, int depth
, int pitch
,
81 unsigned long address
, struct device_node
*dp
);
83 static struct fb_ops offb_ops
= {
85 .fb_setcolreg
= offb_setcolreg
,
86 .fb_blank
= offb_blank
,
87 .fb_fillrect
= cfb_fillrect
,
88 .fb_copyarea
= cfb_copyarea
,
89 .fb_imageblit
= cfb_imageblit
,
90 .fb_cursor
= soft_cursor
,
94 * Set a single color register. The values supplied are already
95 * rounded down to the hardware's capabilities (according to the
96 * entries in the var structure). Return != 0 for invalid regno.
99 static int offb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
100 u_int transp
, struct fb_info
*info
)
102 struct offb_par
*par
= (struct offb_par
*) info
->par
;
104 if (!par
->cmap_adr
|| regno
> 255)
111 switch (par
->cmap_type
) {
113 *par
->cmap_adr
= regno
;
115 *par
->cmap_data
= red
;
117 *par
->cmap_data
= green
;
119 *par
->cmap_data
= blue
;
123 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
124 out_le32((unsigned *) (par
->cmap_adr
+ 0x58),
125 in_le32((unsigned *) (par
->cmap_adr
+
128 /* Set palette index & data */
129 out_8(par
->cmap_adr
+ 0xb0, regno
);
130 out_le32((unsigned *) (par
->cmap_adr
+ 0xb4),
131 (red
<< 16 | green
<< 8 | blue
));
134 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
135 out_le32((unsigned *) (par
->cmap_adr
+ 0x58),
136 in_le32((unsigned *) (par
->cmap_adr
+
138 /* Set palette index & data */
139 out_8(par
->cmap_adr
+ 0xb0, regno
);
140 out_le32((unsigned *) (par
->cmap_adr
+ 0xb4),
141 (red
<< 16 | green
<< 8 | blue
));
144 /* Set palette index & data (could be smarter) */
145 out_8(par
->cmap_adr
+ 0xb0, regno
);
146 out_le32((unsigned *) (par
->cmap_adr
+ 0xb4),
147 (red
<< 16 | green
<< 8 | blue
));
150 out_le32((unsigned *) par
->cmap_adr
+ regno
,
151 (red
<< 16 | green
<< 8 | blue
));
156 switch (info
->var
.bits_per_pixel
) {
158 ((u16
*) (info
->pseudo_palette
))[regno
] =
159 (regno
<< 10) | (regno
<< 5) | regno
;
163 int i
= (regno
<< 8) | regno
;
164 ((u32
*) (info
->pseudo_palette
))[regno
] =
176 static int offb_blank(int blank
, struct fb_info
*info
)
178 struct offb_par
*par
= (struct offb_par
*) info
->par
;
188 par
->blanked
= blank
;
191 for (i
= 0; i
< 256; i
++) {
192 switch (par
->cmap_type
) {
196 for (j
= 0; j
< 3; j
++) {
202 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
203 out_le32((unsigned *) (par
->cmap_adr
+
205 in_le32((unsigned *) (par
->
210 /* Set palette index & data */
211 out_8(par
->cmap_adr
+ 0xb0, i
);
212 out_le32((unsigned *) (par
->cmap_adr
+
216 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
217 out_le32((unsigned *) (par
->cmap_adr
+
219 in_le32((unsigned *) (par
->
223 /* Set palette index & data */
224 out_8(par
->cmap_adr
+ 0xb0, i
);
225 out_le32((unsigned *) (par
->cmap_adr
+
229 out_8(par
->cmap_adr
+ 0xb0, i
);
230 out_le32((unsigned *) (par
->cmap_adr
+
234 out_le32((unsigned *) par
->cmap_adr
+ i
,
239 fb_set_cmap(&info
->cmap
, info
);
247 int __init
offb_init(void)
249 struct device_node
*dp
= NULL
, *boot_disp
= NULL
;
250 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
251 struct device_node
*macos_display
= NULL
;
253 if (fb_get_options("offb", NULL
))
256 #if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
257 /* If we're booted from BootX... */
258 if (boot_infos
!= 0) {
260 (unsigned long) boot_infos
->dispDeviceBase
;
261 /* find the device node corresponding to the macos display */
262 while ((dp
= of_find_node_by_type(dp
, "display"))) {
265 * Grrr... It looks like the MacOS ATI driver
266 * munges the assigned-addresses property (but
267 * the AAPL,address value is OK).
269 if (strncmp(dp
->name
, "ATY,", 4) == 0
270 && dp
->n_addrs
== 1) {
272 (unsigned int *) get_property(dp
,
276 dp
->addrs
[0].address
= *ap
;
277 dp
->addrs
[0].size
= 0x01000000;
282 * The LTPro on the Lombard powerbook has no addresses
283 * on the display nodes, they are on their parent.
286 && device_is_compatible(dp
, "ATY,264LTPro")) {
288 unsigned int *ap
= (unsigned int *)
289 get_property(dp
, "AAPL,address", &na
);
291 for (na
/= sizeof(unsigned int);
300 * See if the display address is in one of the address
301 * ranges for this display.
303 for (i
= 0; i
< dp
->n_addrs
; ++i
) {
304 if (dp
->addrs
[i
].address
<= addr
306 dp
->addrs
[i
].address
+
310 if (i
< dp
->n_addrs
) {
312 printk(KERN_INFO
"MacOS display is %s\n",
320 offb_init_fb(macos_display
? macos_display
->
321 name
: "MacOS display",
322 macos_display
? macos_display
->
323 full_name
: "MacOS display",
324 boot_infos
->dispDeviceRect
[2],
325 boot_infos
->dispDeviceRect
[3],
326 boot_infos
->dispDeviceDepth
,
327 boot_infos
->dispDeviceRowBytes
, addr
, NULL
);
329 #endif /* defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32) */
331 for (dp
= NULL
; (dp
= of_find_node_by_type(dp
, "display"));) {
332 if (get_property(dp
, "linux,opened", NULL
) &&
333 get_property(dp
, "linux,boot-display", NULL
)) {
335 offb_init_nodriver(dp
);
338 for (dp
= NULL
; (dp
= of_find_node_by_type(dp
, "display"));) {
339 if (get_property(dp
, "linux,opened", NULL
) &&
341 offb_init_nodriver(dp
);
348 static void __init
offb_init_nodriver(struct device_node
*dp
)
352 int width
= 640, height
= 480, depth
= 8, pitch
;
353 unsigned *up
, address
;
355 if ((pp
= (int *) get_property(dp
, "depth", &len
)) != NULL
356 && len
== sizeof(int))
358 if ((pp
= (int *) get_property(dp
, "width", &len
)) != NULL
359 && len
== sizeof(int))
361 if ((pp
= (int *) get_property(dp
, "height", &len
)) != NULL
362 && len
== sizeof(int))
364 if ((pp
= (int *) get_property(dp
, "linebytes", &len
)) != NULL
365 && len
== sizeof(int)) {
371 if ((up
= (unsigned *) get_property(dp
, "address", &len
)) != NULL
372 && len
== sizeof(unsigned))
373 address
= (u_long
) * up
;
375 for (i
= 0; i
< dp
->n_addrs
; ++i
)
376 if (dp
->addrs
[i
].size
>=
377 pitch
* height
* depth
/ 8)
379 if (i
>= dp
->n_addrs
) {
381 "no framebuffer address found for %s\n",
386 address
= (u_long
) dp
->addrs
[i
].address
;
388 /* kludge for valkyrie */
389 if (strcmp(dp
->name
, "valkyrie") == 0)
392 offb_init_fb(dp
->name
, dp
->full_name
, width
, height
, depth
,
397 static void __init
offb_init_fb(const char *name
, const char *full_name
,
398 int width
, int height
, int depth
,
399 int pitch
, unsigned long address
,
400 struct device_node
*dp
)
402 unsigned long res_size
= pitch
* height
* depth
/ 8;
403 struct offb_par
*par
= &default_par
;
404 unsigned long res_start
= address
;
405 struct fb_fix_screeninfo
*fix
;
406 struct fb_var_screeninfo
*var
;
407 struct fb_info
*info
;
410 if (!request_mem_region(res_start
, res_size
, "offb"))
414 "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
415 width
, height
, name
, address
, depth
, pitch
);
416 if (depth
!= 8 && depth
!= 16 && depth
!= 32) {
417 printk(KERN_ERR
"%s: can't use depth = %d\n", full_name
,
419 release_mem_region(res_start
, res_size
);
423 size
= sizeof(struct fb_info
) + sizeof(u32
) * 17;
425 info
= kmalloc(size
, GFP_ATOMIC
);
428 release_mem_region(res_start
, res_size
);
431 memset(info
, 0, size
);
436 strcpy(fix
->id
, "OFfb ");
437 strncat(fix
->id
, name
, sizeof(fix
->id
) - sizeof("OFfb "));
438 fix
->id
[sizeof(fix
->id
) - 1] = '\0';
440 var
->xres
= var
->xres_virtual
= width
;
441 var
->yres
= var
->yres_virtual
= height
;
442 fix
->line_length
= pitch
;
444 fix
->smem_start
= address
;
445 fix
->smem_len
= pitch
* height
;
446 fix
->type
= FB_TYPE_PACKED_PIXELS
;
449 par
->cmap_type
= cmap_unknown
;
451 /* XXX kludge for ati */
452 if (dp
&& !strncmp(name
, "ATY,Rage128", 11)) {
453 unsigned long regbase
= dp
->addrs
[2].address
;
454 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
455 par
->cmap_type
= cmap_r128
;
456 } else if (dp
&& (!strncmp(name
, "ATY,RageM3pA", 12)
457 || !strncmp(name
, "ATY,RageM3p12A", 14))) {
458 unsigned long regbase
=
459 dp
->parent
->addrs
[2].address
;
460 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
461 par
->cmap_type
= cmap_M3A
;
462 } else if (dp
&& !strncmp(name
, "ATY,RageM3pB", 12)) {
463 unsigned long regbase
=
464 dp
->parent
->addrs
[2].address
;
465 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
466 par
->cmap_type
= cmap_M3B
;
467 } else if (dp
&& !strncmp(name
, "ATY,Rage6", 9)) {
468 unsigned long regbase
= dp
->addrs
[1].address
;
469 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
470 par
->cmap_type
= cmap_radeon
;
471 } else if (!strncmp(name
, "ATY,", 4)) {
472 unsigned long base
= address
& 0xff000000UL
;
474 ioremap(base
+ 0x7ff000, 0x1000) + 0xcc0;
475 par
->cmap_data
= par
->cmap_adr
+ 1;
476 par
->cmap_type
= cmap_m64
;
477 } else if (device_is_compatible(dp
, "pci1014,b7")) {
478 unsigned long regbase
= dp
->addrs
[0].address
;
479 par
->cmap_adr
= ioremap(regbase
+ 0x6000, 0x1000);
480 par
->cmap_type
= cmap_gxt2000
;
482 fix
->visual
= par
->cmap_adr
? FB_VISUAL_PSEUDOCOLOR
483 : FB_VISUAL_STATIC_PSEUDOCOLOR
;
485 fix
->visual
= /* par->cmap_adr ? FB_VISUAL_DIRECTCOLOR
486 : */ FB_VISUAL_TRUECOLOR
;
488 var
->xoffset
= var
->yoffset
= 0;
489 var
->bits_per_pixel
= depth
;
492 var
->bits_per_pixel
= 8;
495 var
->green
.offset
= 0;
496 var
->green
.length
= 8;
497 var
->blue
.offset
= 0;
498 var
->blue
.length
= 8;
499 var
->transp
.offset
= 0;
500 var
->transp
.length
= 0;
502 case 16: /* RGB 555 */
503 var
->bits_per_pixel
= 16;
504 var
->red
.offset
= 10;
506 var
->green
.offset
= 5;
507 var
->green
.length
= 5;
508 var
->blue
.offset
= 0;
509 var
->blue
.length
= 5;
510 var
->transp
.offset
= 0;
511 var
->transp
.length
= 0;
513 case 32: /* RGB 888 */
514 var
->bits_per_pixel
= 32;
515 var
->red
.offset
= 16;
517 var
->green
.offset
= 8;
518 var
->green
.length
= 8;
519 var
->blue
.offset
= 0;
520 var
->blue
.length
= 8;
521 var
->transp
.offset
= 24;
522 var
->transp
.length
= 8;
525 var
->red
.msb_right
= var
->green
.msb_right
= var
->blue
.msb_right
=
526 var
->transp
.msb_right
= 0;
530 var
->height
= var
->width
= -1;
531 var
->pixclock
= 10000;
532 var
->left_margin
= var
->right_margin
= 16;
533 var
->upper_margin
= var
->lower_margin
= 16;
534 var
->hsync_len
= var
->vsync_len
= 8;
536 var
->vmode
= FB_VMODE_NONINTERLACED
;
538 info
->fbops
= &offb_ops
;
539 info
->screen_base
= ioremap(address
, fix
->smem_len
);
541 info
->pseudo_palette
= (void *) (info
+ 1);
542 info
->flags
= FBINFO_DEFAULT
;
544 fb_alloc_cmap(&info
->cmap
, 256, 0);
546 if (register_framebuffer(info
) < 0) {
548 release_mem_region(res_start
, res_size
);
552 printk(KERN_INFO
"fb%d: Open Firmware frame buffer device on %s\n",
553 info
->node
, full_name
);
556 module_init(offb_init
);
557 MODULE_LICENSE("GPL");