#include <linux/fb.h>
#include <linux/init.h>
#include <linux/ioport.h>
+#include <linux/pci.h>
#include <asm/io.h>
#include <asm/prom.h>
+#ifdef CONFIG_PPC64
+#include <asm/pci-bridge.h>
+#endif
+
#ifdef CONFIG_PPC32
#include <asm/bootx.h>
#endif
};
struct offb_par {
- volatile unsigned char *cmap_adr;
- volatile unsigned char *cmap_data;
+ volatile void __iomem *cmap_adr;
+ volatile void __iomem *cmap_data;
int cmap_type;
int blanked;
};
struct offb_par default_par;
-#ifdef __powerpc__
-#define mach_eieio() eieio()
-#else
-#define mach_eieio() do {} while (0)
-#endif
-
/*
* Interface used by the world
*/
.fb_fillrect = cfb_fillrect,
.fb_copyarea = cfb_copyarea,
.fb_imageblit = cfb_imageblit,
- .fb_cursor = soft_cursor,
};
/*
switch (par->cmap_type) {
case cmap_m64:
- *par->cmap_adr = regno;
- mach_eieio();
- *par->cmap_data = red;
- mach_eieio();
- *par->cmap_data = green;
- mach_eieio();
- *par->cmap_data = blue;
- mach_eieio();
+ writeb(regno, par->cmap_adr);
+ writeb(red, par->cmap_data);
+ writeb(green, par->cmap_data);
+ writeb(blue, par->cmap_data);
break;
case cmap_M3A:
/* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
- out_le32((unsigned *) (par->cmap_adr + 0x58),
- in_le32((unsigned *) (par->cmap_adr +
- 0x58)) & ~0x20);
+ out_le32(par->cmap_adr + 0x58,
+ in_le32(par->cmap_adr + 0x58) & ~0x20);
case cmap_r128:
/* Set palette index & data */
out_8(par->cmap_adr + 0xb0, regno);
- out_le32((unsigned *) (par->cmap_adr + 0xb4),
+ out_le32(par->cmap_adr + 0xb4,
(red << 16 | green << 8 | blue));
break;
case cmap_M3B:
/* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
- out_le32((unsigned *) (par->cmap_adr + 0x58),
- in_le32((unsigned *) (par->cmap_adr +
- 0x58)) | 0x20);
+ out_le32(par->cmap_adr + 0x58,
+ in_le32(par->cmap_adr + 0x58) | 0x20);
/* Set palette index & data */
out_8(par->cmap_adr + 0xb0, regno);
- out_le32((unsigned *) (par->cmap_adr + 0xb4),
- (red << 16 | green << 8 | blue));
+ out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
break;
case cmap_radeon:
/* Set palette index & data (could be smarter) */
out_8(par->cmap_adr + 0xb0, regno);
- out_le32((unsigned *) (par->cmap_adr + 0xb4),
- (red << 16 | green << 8 | blue));
+ out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
break;
case cmap_gxt2000:
- out_le32((unsigned *) par->cmap_adr + regno,
+ out_le32((unsigned __iomem *) par->cmap_adr + regno,
(red << 16 | green << 8 | blue));
break;
}
for (i = 0; i < 256; i++) {
switch (par->cmap_type) {
case cmap_m64:
- *par->cmap_adr = i;
- mach_eieio();
- for (j = 0; j < 3; j++) {
- *par->cmap_data = 0;
- mach_eieio();
- }
+ writeb(i, par->cmap_adr);
+ for (j = 0; j < 3; j++)
+ writeb(0, par->cmap_data);
break;
case cmap_M3A:
/* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
- out_le32((unsigned *) (par->cmap_adr +
- 0x58),
- in_le32((unsigned *) (par->
- cmap_adr +
- 0x58)) &
- ~0x20);
+ out_le32(par->cmap_adr + 0x58,
+ in_le32(par->cmap_adr + 0x58) & ~0x20);
case cmap_r128:
/* Set palette index & data */
out_8(par->cmap_adr + 0xb0, i);
- out_le32((unsigned *) (par->cmap_adr +
- 0xb4), 0);
+ out_le32(par->cmap_adr + 0xb4, 0);
break;
case cmap_M3B:
/* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
- out_le32((unsigned *) (par->cmap_adr +
- 0x58),
- in_le32((unsigned *) (par->
- cmap_adr +
- 0x58)) |
- 0x20);
+ out_le32(par->cmap_adr + 0x58,
+ in_le32(par->cmap_adr + 0x58) | 0x20);
/* Set palette index & data */
out_8(par->cmap_adr + 0xb0, i);
- out_le32((unsigned *) (par->cmap_adr +
- 0xb4), 0);
+ out_le32(par->cmap_adr + 0xb4, 0);
break;
case cmap_radeon:
out_8(par->cmap_adr + 0xb0, i);
- out_le32((unsigned *) (par->cmap_adr +
- 0xb4), 0);
+ out_le32(par->cmap_adr + 0xb4, 0);
break;
case cmap_gxt2000:
- out_le32((unsigned *) par->cmap_adr + i,
+ out_le32((unsigned __iomem *) par->cmap_adr + i,
0);
break;
}
int __init offb_init(void)
{
struct device_node *dp = NULL, *boot_disp = NULL;
+
#if defined(CONFIG_BOOTX_TEXT) && defined(CONFIG_PPC32)
struct device_node *macos_display = NULL;
#endif
if (boot_infos != 0) {
unsigned long addr =
(unsigned long) boot_infos->dispDeviceBase;
+ u32 *addrp;
+ u64 daddr, dsize;
+ unsigned int flags;
+
/* find the device node corresponding to the macos display */
while ((dp = of_find_node_by_type(dp, "display"))) {
int i;
- /*
- * Grrr... It looks like the MacOS ATI driver
- * munges the assigned-addresses property (but
- * the AAPL,address value is OK).
- */
- if (strncmp(dp->name, "ATY,", 4) == 0
- && dp->n_addrs == 1) {
- unsigned int *ap =
- (unsigned int *) get_property(dp,
- "AAPL,address",
- NULL);
- if (ap != NULL) {
- dp->addrs[0].address = *ap;
- dp->addrs[0].size = 0x01000000;
- }
- }
/*
- * The LTPro on the Lombard powerbook has no addresses
- * on the display nodes, they are on their parent.
+ * Look for an AAPL,address property first.
*/
- if (dp->n_addrs == 0
- && device_is_compatible(dp, "ATY,264LTPro")) {
- int na;
- unsigned int *ap = (unsigned int *)
- get_property(dp, "AAPL,address", &na);
- if (ap != 0)
- for (na /= sizeof(unsigned int);
- na > 0; --na, ++ap)
- if (*ap <= addr
- && addr <
- *ap + 0x1000000)
- goto foundit;
+ unsigned int na;
+ unsigned int *ap =
+ (unsigned int *)get_property(dp, "AAPL,address",
+ &na);
+ if (ap != 0) {
+ for (na /= sizeof(unsigned int); na > 0;
+ --na, ++ap)
+ if (*ap <= addr &&
+ addr < *ap + 0x1000000) {
+ macos_display = dp;
+ goto foundit;
+ }
}
/*
* See if the display address is in one of the address
* ranges for this display.
*/
- for (i = 0; i < dp->n_addrs; ++i) {
- if (dp->addrs[i].address <= addr
- && addr <
- dp->addrs[i].address +
- dp->addrs[i].size)
+ i = 0;
+ for (;;) {
+ addrp = of_get_address(dp, i++, &dsize, &flags);
+ if (addrp == NULL)
break;
+ if (!(flags & IORESOURCE_MEM))
+ continue;
+ daddr = of_translate_address(dp, addrp);
+ if (daddr == OF_BAD_ADDR)
+ continue;
+ if (daddr <= addr && addr < (daddr + dsize)) {
+ macos_display = dp;
+ goto foundit;
+ }
}
- if (i < dp->n_addrs) {
- foundit:
+ foundit:
+ if (macos_display) {
printk(KERN_INFO "MacOS display is %s\n",
dp->full_name);
- macos_display = dp;
break;
}
}
int *pp, i;
unsigned int len;
int width = 640, height = 480, depth = 8, pitch;
- unsigned *up, address;
+ unsigned flags, rsize, *up, addr_prop = 0;
+ unsigned long max_size = 0;
+ u64 rstart, address = OF_BAD_ADDR;
+ u32 *addrp;
+ u64 asize;
if ((pp = (int *) get_property(dp, "depth", &len)) != NULL
&& len == sizeof(int))
pitch = 0x1000;
} else
pitch = width;
- if ((up = (unsigned *) get_property(dp, "address", &len)) != NULL
- && len == sizeof(unsigned))
- address = (u_long) * up;
- else {
- for (i = 0; i < dp->n_addrs; ++i)
- if (dp->addrs[i].size >=
- pitch * height * depth / 8)
- break;
- if (i >= dp->n_addrs) {
- printk(KERN_ERR
- "no framebuffer address found for %s\n",
- dp->full_name);
- return;
- }
-
- address = (u_long) dp->addrs[i].address;
+ rsize = (unsigned long)pitch * (unsigned long)height *
+ (unsigned long)(depth / 8);
+
+ /* Ok, now we try to figure out the address of the framebuffer.
+ *
+ * Unfortunately, Open Firmware doesn't provide a standard way to do
+ * so. All we can do is a dodgy heuristic that happens to work in
+ * practice. On most machines, the "address" property contains what
+ * we need, though not on Matrox cards found in IBM machines. What I've
+ * found that appears to give good results is to go through the PCI
+ * ranges and pick one that is both big enough and if possible encloses
+ * the "address" property. If none match, we pick the biggest
+ */
+ up = (unsigned int *) get_property(dp, "address", &len);
+ if (up && len == sizeof(unsigned int))
+ addr_prop = *up;
+
+ for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
+ != NULL; i++) {
+ int match_addrp = 0;
+
+ if (!(flags & IORESOURCE_MEM))
+ continue;
+ if (asize < rsize)
+ continue;
+ rstart = of_translate_address(dp, addrp);
+ if (rstart == OF_BAD_ADDR)
+ continue;
+ if (addr_prop && (rstart <= addr_prop) &&
+ ((rstart + rsize) > addr_prop))
+ match_addrp = 1;
+ if (match_addrp) {
+ address = addr_prop;
+ break;
+ }
+ if (rsize > max_size) {
+ max_size = rsize;
+ address = OF_BAD_ADDR;
+ }
+ if (address == OF_BAD_ADDR)
+ address = rstart;
+ }
+ if (address == OF_BAD_ADDR && addr_prop)
+ address = (u_long)addr_prop;
+ if (address != OF_BAD_ADDR) {
/* kludge for valkyrie */
if (strcmp(dp->name, "valkyrie") == 0)
address += 0x1000;
+ offb_init_fb(dp->name, dp->full_name, width, height, depth,
+ pitch, address, dp);
}
- offb_init_fb(dp->name, dp->full_name, width, height, depth,
- pitch, address, dp);
-
}
static void __init offb_init_fb(const char *name, const char *full_name,
par->cmap_type = cmap_unknown;
if (depth == 8) {
- /* XXX kludge for ati */
+
+ /* Palette hacks disabled for now */
+#if 0
if (dp && !strncmp(name, "ATY,Rage128", 11)) {
unsigned long regbase = dp->addrs[2].address;
par->cmap_adr = ioremap(regbase, 0x1FFF);
par->cmap_adr = ioremap(regbase + 0x6000, 0x1000);
par->cmap_type = cmap_gxt2000;
}
+#endif
fix->visual = par->cmap_adr ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_STATIC_PSEUDOCOLOR;
} else