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>
31 #ifdef CONFIG_BOOTX_TEXT
32 #include <asm/bootx.h>
37 /* Supported palette hacks */
40 cmap_m64
, /* ATI Mach64 */
41 cmap_r128
, /* ATI Rage128 */
42 cmap_M3A
, /* ATI Rage Mobility M3 Head A */
43 cmap_M3B
, /* ATI Rage Mobility M3 Head B */
44 cmap_radeon
, /* ATI Radeon */
45 cmap_gxt2000
, /* IBM GXT2000 */
49 volatile unsigned char *cmap_adr
;
50 volatile unsigned char *cmap_data
;
55 struct offb_par default_par
;
58 #define mach_eieio() eieio()
60 #define mach_eieio() do {} while (0)
64 * Interface used by the world
69 static int offb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
70 u_int transp
, struct fb_info
*info
);
71 static int offb_blank(int blank
, struct fb_info
*info
);
73 #ifdef CONFIG_BOOTX_TEXT
74 extern boot_infos_t
*boot_infos
;
77 static void offb_init_nodriver(struct device_node
*);
78 static void offb_init_fb(const char *name
, const char *full_name
,
79 int width
, int height
, int depth
, int pitch
,
80 unsigned long address
, struct device_node
*dp
);
82 static struct fb_ops offb_ops
= {
84 .fb_setcolreg
= offb_setcolreg
,
85 .fb_blank
= offb_blank
,
86 .fb_fillrect
= cfb_fillrect
,
87 .fb_copyarea
= cfb_copyarea
,
88 .fb_imageblit
= cfb_imageblit
,
89 .fb_cursor
= soft_cursor
,
93 * Set a single color register. The values supplied are already
94 * rounded down to the hardware's capabilities (according to the
95 * entries in the var structure). Return != 0 for invalid regno.
98 static int offb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
99 u_int transp
, struct fb_info
*info
)
101 struct offb_par
*par
= (struct offb_par
*) info
->par
;
103 if (!par
->cmap_adr
|| regno
> 255)
110 switch (par
->cmap_type
) {
112 *par
->cmap_adr
= regno
;
114 *par
->cmap_data
= red
;
116 *par
->cmap_data
= green
;
118 *par
->cmap_data
= blue
;
122 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
123 out_le32((unsigned *) (par
->cmap_adr
+ 0x58),
124 in_le32((unsigned *) (par
->cmap_adr
+
127 /* Set palette index & data */
128 out_8(par
->cmap_adr
+ 0xb0, regno
);
129 out_le32((unsigned *) (par
->cmap_adr
+ 0xb4),
130 (red
<< 16 | green
<< 8 | blue
));
133 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
134 out_le32((unsigned *) (par
->cmap_adr
+ 0x58),
135 in_le32((unsigned *) (par
->cmap_adr
+
137 /* Set palette index & data */
138 out_8(par
->cmap_adr
+ 0xb0, regno
);
139 out_le32((unsigned *) (par
->cmap_adr
+ 0xb4),
140 (red
<< 16 | green
<< 8 | blue
));
143 /* Set palette index & data (could be smarter) */
144 out_8(par
->cmap_adr
+ 0xb0, regno
);
145 out_le32((unsigned *) (par
->cmap_adr
+ 0xb4),
146 (red
<< 16 | green
<< 8 | blue
));
149 out_le32((unsigned *) par
->cmap_adr
+ regno
,
150 (red
<< 16 | green
<< 8 | blue
));
155 switch (info
->var
.bits_per_pixel
) {
157 ((u16
*) (info
->pseudo_palette
))[regno
] =
158 (regno
<< 10) | (regno
<< 5) | regno
;
162 int i
= (regno
<< 8) | regno
;
163 ((u32
*) (info
->pseudo_palette
))[regno
] =
175 static int offb_blank(int blank
, struct fb_info
*info
)
177 struct offb_par
*par
= (struct offb_par
*) info
->par
;
187 par
->blanked
= blank
;
190 for (i
= 0; i
< 256; i
++) {
191 switch (par
->cmap_type
) {
195 for (j
= 0; j
< 3; j
++) {
201 /* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
202 out_le32((unsigned *) (par
->cmap_adr
+
204 in_le32((unsigned *) (par
->
209 /* Set palette index & data */
210 out_8(par
->cmap_adr
+ 0xb0, i
);
211 out_le32((unsigned *) (par
->cmap_adr
+
215 /* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
216 out_le32((unsigned *) (par
->cmap_adr
+
218 in_le32((unsigned *) (par
->
222 /* Set palette index & data */
223 out_8(par
->cmap_adr
+ 0xb0, i
);
224 out_le32((unsigned *) (par
->cmap_adr
+
228 out_8(par
->cmap_adr
+ 0xb0, i
);
229 out_le32((unsigned *) (par
->cmap_adr
+
233 out_le32((unsigned *) par
->cmap_adr
+ i
,
238 fb_set_cmap(&info
->cmap
, 1, info
);
246 int __init
offb_init(void)
248 struct device_node
*dp
;
250 #ifdef CONFIG_BOOTX_TEXT
251 struct device_node
*displays
= find_type_devices("display");
252 struct device_node
*macos_display
= NULL
;
254 /* If we're booted from BootX... */
255 if (prom_num_displays
== 0 && boot_infos
!= 0) {
257 (unsigned long) boot_infos
->dispDeviceBase
;
258 /* find the device node corresponding to the macos display */
259 for (dp
= displays
; dp
!= NULL
; dp
= dp
->next
) {
262 * Grrr... It looks like the MacOS ATI driver
263 * munges the assigned-addresses property (but
264 * the AAPL,address value is OK).
266 if (strncmp(dp
->name
, "ATY,", 4) == 0
267 && dp
->n_addrs
== 1) {
269 (unsigned int *) get_property(dp
,
273 dp
->addrs
[0].address
= *ap
;
274 dp
->addrs
[0].size
= 0x01000000;
279 * The LTPro on the Lombard powerbook has no addresses
280 * on the display nodes, they are on their parent.
283 && device_is_compatible(dp
, "ATY,264LTPro")) {
285 unsigned int *ap
= (unsigned int *)
286 get_property(dp
, "AAPL,address", &na
);
288 for (na
/= sizeof(unsigned int);
297 * See if the display address is in one of the address
298 * ranges for this display.
300 for (i
= 0; i
< dp
->n_addrs
; ++i
) {
301 if (dp
->addrs
[i
].address
<= addr
303 dp
->addrs
[i
].address
+
307 if (i
< dp
->n_addrs
) {
309 printk(KERN_INFO
"MacOS display is %s\n",
317 offb_init_fb(macos_display
? macos_display
->
318 name
: "MacOS display",
319 macos_display
? macos_display
->
320 full_name
: "MacOS display",
321 boot_infos
->dispDeviceRect
[2],
322 boot_infos
->dispDeviceRect
[3],
323 boot_infos
->dispDeviceDepth
,
324 boot_infos
->dispDeviceRowBytes
, addr
, NULL
);
328 for (dpy
= 0; dpy
< prom_num_displays
; dpy
++) {
329 if ((dp
= find_path_device(prom_display_paths
[dpy
])))
330 offb_init_nodriver(dp
);
336 static void __init
offb_init_nodriver(struct device_node
*dp
)
340 int width
= 640, height
= 480, depth
= 8, pitch
;
341 unsigned *up
, address
;
343 if ((pp
= (int *) get_property(dp
, "depth", &len
)) != NULL
344 && len
== sizeof(int))
346 if ((pp
= (int *) get_property(dp
, "width", &len
)) != NULL
347 && len
== sizeof(int))
349 if ((pp
= (int *) get_property(dp
, "height", &len
)) != NULL
350 && len
== sizeof(int))
352 if ((pp
= (int *) get_property(dp
, "linebytes", &len
)) != NULL
353 && len
== sizeof(int)) {
359 if ((up
= (unsigned *) get_property(dp
, "address", &len
)) != NULL
360 && len
== sizeof(unsigned))
361 address
= (u_long
) * up
;
363 for (i
= 0; i
< dp
->n_addrs
; ++i
)
364 if (dp
->addrs
[i
].size
>=
365 pitch
* height
* depth
/ 8)
367 if (i
>= dp
->n_addrs
) {
369 "no framebuffer address found for %s\n",
374 address
= (u_long
) dp
->addrs
[i
].address
;
376 /* kludge for valkyrie */
377 if (strcmp(dp
->name
, "valkyrie") == 0)
380 offb_init_fb(dp
->name
, dp
->full_name
, width
, height
, depth
,
385 static void __init
offb_init_fb(const char *name
, const char *full_name
,
386 int width
, int height
, int depth
,
387 int pitch
, unsigned long address
,
388 struct device_node
*dp
)
390 unsigned long res_size
= pitch
* height
* depth
/ 8;
391 struct offb_par
*par
= &default_par
;
392 unsigned long res_start
= address
;
393 struct fb_fix_screeninfo
*fix
;
394 struct fb_var_screeninfo
*var
;
395 struct fb_info
*info
;
398 if (!request_mem_region(res_start
, res_size
, "offb"))
402 "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
403 width
, height
, name
, address
, depth
, pitch
);
404 if (depth
!= 8 && depth
!= 16 && depth
!= 32) {
405 printk(KERN_ERR
"%s: can't use depth = %d\n", full_name
,
407 release_mem_region(res_start
, res_size
);
411 size
= sizeof(struct fb_info
) + sizeof(u32
) * 17;
413 info
= kmalloc(size
, GFP_ATOMIC
);
416 release_mem_region(res_start
, res_size
);
419 memset(info
, 0, size
);
424 strcpy(fix
->id
, "OFfb ");
425 strncat(fix
->id
, name
, sizeof(fix
->id
) - sizeof("OFfb "));
426 fix
->id
[sizeof(fix
->id
) - 1] = '\0';
428 var
->xres
= var
->xres_virtual
= width
;
429 var
->yres
= var
->yres_virtual
= height
;
430 fix
->line_length
= pitch
;
432 fix
->smem_start
= address
;
433 fix
->smem_len
= pitch
* height
;
434 fix
->type
= FB_TYPE_PACKED_PIXELS
;
437 par
->cmap_type
= cmap_unknown
;
439 /* XXX kludge for ati */
440 if (dp
&& !strncmp(name
, "ATY,Rage128", 11)) {
441 unsigned long regbase
= dp
->addrs
[2].address
;
442 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
443 par
->cmap_type
= cmap_r128
;
444 } else if (dp
&& (!strncmp(name
, "ATY,RageM3pA", 12)
445 || !strncmp(name
, "ATY,RageM3p12A", 14))) {
446 unsigned long regbase
=
447 dp
->parent
->addrs
[2].address
;
448 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
449 par
->cmap_type
= cmap_M3A
;
450 } else if (dp
&& !strncmp(name
, "ATY,RageM3pB", 12)) {
451 unsigned long regbase
=
452 dp
->parent
->addrs
[2].address
;
453 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
454 par
->cmap_type
= cmap_M3B
;
455 } else if (dp
&& !strncmp(name
, "ATY,Rage6", 9)) {
456 unsigned long regbase
= dp
->addrs
[1].address
;
457 par
->cmap_adr
= ioremap(regbase
, 0x1FFF);
458 par
->cmap_type
= cmap_radeon
;
459 } else if (!strncmp(name
, "ATY,", 4)) {
460 unsigned long base
= address
& 0xff000000UL
;
462 ioremap(base
+ 0x7ff000, 0x1000) + 0xcc0;
463 par
->cmap_data
= par
->cmap_adr
+ 1;
464 par
->cmap_type
= cmap_m64
;
465 } else if (device_is_compatible(dp
, "pci1014,b7")) {
466 unsigned long regbase
= dp
->addrs
[0].address
;
467 par
->cmap_adr
= ioremap(regbase
+ 0x6000, 0x1000);
468 par
->cmap_type
= cmap_gxt2000
;
470 fix
->visual
= par
->cmap_adr
? FB_VISUAL_PSEUDOCOLOR
471 : FB_VISUAL_STATIC_PSEUDOCOLOR
;
473 fix
->visual
= /* par->cmap_adr ? FB_VISUAL_DIRECTCOLOR
474 : */ FB_VISUAL_TRUECOLOR
;
476 var
->xoffset
= var
->yoffset
= 0;
477 var
->bits_per_pixel
= depth
;
480 var
->bits_per_pixel
= 8;
483 var
->green
.offset
= 0;
484 var
->green
.length
= 8;
485 var
->blue
.offset
= 0;
486 var
->blue
.length
= 8;
487 var
->transp
.offset
= 0;
488 var
->transp
.length
= 0;
490 case 16: /* RGB 555 */
491 var
->bits_per_pixel
= 16;
492 var
->red
.offset
= 10;
494 var
->green
.offset
= 5;
495 var
->green
.length
= 5;
496 var
->blue
.offset
= 0;
497 var
->blue
.length
= 5;
498 var
->transp
.offset
= 0;
499 var
->transp
.length
= 0;
501 case 32: /* RGB 888 */
502 var
->bits_per_pixel
= 32;
503 var
->red
.offset
= 16;
505 var
->green
.offset
= 8;
506 var
->green
.length
= 8;
507 var
->blue
.offset
= 0;
508 var
->blue
.length
= 8;
509 var
->transp
.offset
= 24;
510 var
->transp
.length
= 8;
513 var
->red
.msb_right
= var
->green
.msb_right
= var
->blue
.msb_right
=
514 var
->transp
.msb_right
= 0;
518 var
->height
= var
->width
= -1;
519 var
->pixclock
= 10000;
520 var
->left_margin
= var
->right_margin
= 16;
521 var
->upper_margin
= var
->lower_margin
= 16;
522 var
->hsync_len
= var
->vsync_len
= 8;
524 var
->vmode
= FB_VMODE_NONINTERLACED
;
526 info
->fbops
= &offb_ops
;
527 info
->screen_base
= ioremap(address
, fix
->smem_len
);
529 info
->pseudo_palette
= (void *) (info
+ 1);
530 info
->flags
= FBINFO_FLAG_DEFAULT
;
532 fb_alloc_cmap(&info
->cmap
, 256, 0);
534 if (register_framebuffer(info
) < 0) {
536 release_mem_region(res_start
, res_size
);
540 printk(KERN_INFO
"fb%d: Open Firmware frame buffer device on %s\n",
541 info
->node
, full_name
);
544 MODULE_LICENSE("GPL");