2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/drivers/video/offb.c -- Open Firmware based frame buffer device
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Geert Uytterhoeven
|
|
|
|
*
|
|
|
|
* This driver is partly based on the PowerMac console driver:
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996 Paul Mackerras
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
|
|
* License. See the file COPYING in the main directory of this archive for
|
|
|
|
* more details.
|
|
|
|
*/
|
|
|
|
|
2022-12-20 00:05:11 +08:00
|
|
|
#include <linux/aperture.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/delay.h>
|
2010-07-30 01:49:01 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_address.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/fb.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/ioport.h>
|
2005-11-18 13:41:49 +08:00
|
|
|
#include <linux/pci.h>
|
2022-07-08 15:11:05 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC32
|
|
|
|
#include <asm/bootx.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "macmodes.h"
|
|
|
|
|
|
|
|
/* Supported palette hacks */
|
|
|
|
enum {
|
|
|
|
cmap_unknown,
|
2011-12-14 21:58:29 +08:00
|
|
|
cmap_simple, /* ATI Mach64 */
|
2005-04-17 06:20:36 +08:00
|
|
|
cmap_r128, /* ATI Rage128 */
|
|
|
|
cmap_M3A, /* ATI Rage Mobility M3 Head A */
|
|
|
|
cmap_M3B, /* ATI Rage Mobility M3 Head B */
|
|
|
|
cmap_radeon, /* ATI Radeon */
|
|
|
|
cmap_gxt2000, /* IBM GXT2000 */
|
2008-07-17 13:05:22 +08:00
|
|
|
cmap_avivo, /* ATI R5xx */
|
2011-12-14 21:58:29 +08:00
|
|
|
cmap_qemu, /* qemu vga */
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct offb_par {
|
|
|
|
volatile void __iomem *cmap_adr;
|
|
|
|
volatile void __iomem *cmap_data;
|
|
|
|
int cmap_type;
|
|
|
|
int blanked;
|
2022-12-20 00:05:10 +08:00
|
|
|
u32 pseudo_palette[16];
|
2022-12-20 00:05:11 +08:00
|
|
|
resource_size_t base;
|
|
|
|
resource_size_t size;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_PPC32
|
|
|
|
extern boot_infos_t *boot_infos;
|
|
|
|
#endif
|
|
|
|
|
2008-07-17 13:05:22 +08:00
|
|
|
/* Definitions used by the Avivo palette hack */
|
|
|
|
#define AVIVO_DC_LUT_RW_SELECT 0x6480
|
|
|
|
#define AVIVO_DC_LUT_RW_MODE 0x6484
|
|
|
|
#define AVIVO_DC_LUT_RW_INDEX 0x6488
|
|
|
|
#define AVIVO_DC_LUT_SEQ_COLOR 0x648c
|
|
|
|
#define AVIVO_DC_LUT_PWL_DATA 0x6490
|
|
|
|
#define AVIVO_DC_LUT_30_COLOR 0x6494
|
|
|
|
#define AVIVO_DC_LUT_READ_PIPE_SELECT 0x6498
|
|
|
|
#define AVIVO_DC_LUT_WRITE_EN_MASK 0x649c
|
|
|
|
#define AVIVO_DC_LUT_AUTOFILL 0x64a0
|
|
|
|
|
|
|
|
#define AVIVO_DC_LUTA_CONTROL 0x64c0
|
|
|
|
#define AVIVO_DC_LUTA_BLACK_OFFSET_BLUE 0x64c4
|
|
|
|
#define AVIVO_DC_LUTA_BLACK_OFFSET_GREEN 0x64c8
|
|
|
|
#define AVIVO_DC_LUTA_BLACK_OFFSET_RED 0x64cc
|
|
|
|
#define AVIVO_DC_LUTA_WHITE_OFFSET_BLUE 0x64d0
|
|
|
|
#define AVIVO_DC_LUTA_WHITE_OFFSET_GREEN 0x64d4
|
|
|
|
#define AVIVO_DC_LUTA_WHITE_OFFSET_RED 0x64d8
|
|
|
|
|
|
|
|
#define AVIVO_DC_LUTB_CONTROL 0x6cc0
|
|
|
|
#define AVIVO_DC_LUTB_BLACK_OFFSET_BLUE 0x6cc4
|
|
|
|
#define AVIVO_DC_LUTB_BLACK_OFFSET_GREEN 0x6cc8
|
|
|
|
#define AVIVO_DC_LUTB_BLACK_OFFSET_RED 0x6ccc
|
|
|
|
#define AVIVO_DC_LUTB_WHITE_OFFSET_BLUE 0x6cd0
|
|
|
|
#define AVIVO_DC_LUTB_WHITE_OFFSET_GREEN 0x6cd4
|
|
|
|
#define AVIVO_DC_LUTB_WHITE_OFFSET_RED 0x6cd8
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a single color register. The values supplied are already
|
|
|
|
* rounded down to the hardware's capabilities (according to the
|
|
|
|
* entries in the var structure). Return != 0 for invalid regno.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
|
|
|
|
u_int transp, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct offb_par *par = (struct offb_par *) info->par;
|
2011-12-28 08:10:16 +08:00
|
|
|
|
|
|
|
if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
|
|
|
|
u32 *pal = info->pseudo_palette;
|
|
|
|
u32 cr = red >> (16 - info->var.red.length);
|
|
|
|
u32 cg = green >> (16 - info->var.green.length);
|
|
|
|
u32 cb = blue >> (16 - info->var.blue.length);
|
|
|
|
u32 value;
|
|
|
|
|
|
|
|
if (regno >= 16)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
value = (cr << info->var.red.offset) |
|
|
|
|
(cg << info->var.green.offset) |
|
|
|
|
(cb << info->var.blue.offset);
|
|
|
|
if (info->var.transp.length > 0) {
|
|
|
|
u32 mask = (1 << info->var.transp.length) - 1;
|
|
|
|
mask <<= info->var.transp.offset;
|
|
|
|
value |= mask;
|
2006-07-03 15:19:48 +08:00
|
|
|
}
|
2014-06-16 17:40:20 +08:00
|
|
|
pal[regno] = value;
|
2011-12-28 08:10:16 +08:00
|
|
|
return 0;
|
2006-07-03 15:19:48 +08:00
|
|
|
}
|
|
|
|
|
2011-12-28 08:10:16 +08:00
|
|
|
if (regno > 255)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
red >>= 8;
|
|
|
|
green >>= 8;
|
|
|
|
blue >>= 8;
|
|
|
|
|
2006-07-03 15:19:48 +08:00
|
|
|
if (!par->cmap_adr)
|
|
|
|
return 0;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (par->cmap_type) {
|
2011-12-14 21:58:29 +08:00
|
|
|
case cmap_simple:
|
2005-04-17 06:20:36 +08:00
|
|
|
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(par->cmap_adr + 0x58,
|
|
|
|
in_le32(par->cmap_adr + 0x58) & ~0x20);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
case cmap_r128:
|
|
|
|
/* Set palette index & data */
|
|
|
|
out_8(par->cmap_adr + 0xb0, regno);
|
|
|
|
out_le32(par->cmap_adr + 0xb4,
|
|
|
|
(red << 16 | green << 8 | blue));
|
|
|
|
break;
|
|
|
|
case cmap_M3B:
|
|
|
|
/* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
|
|
|
|
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(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(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
|
|
|
|
break;
|
|
|
|
case cmap_gxt2000:
|
2006-10-26 13:38:10 +08:00
|
|
|
out_le32(((unsigned __iomem *) par->cmap_adr) + regno,
|
2005-04-17 06:20:36 +08:00
|
|
|
(red << 16 | green << 8 | blue));
|
|
|
|
break;
|
2008-07-17 13:05:22 +08:00
|
|
|
case cmap_avivo:
|
|
|
|
/* Write to both LUTs for now */
|
|
|
|
writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
|
|
|
|
writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
|
|
|
|
writel(((red) << 22) | ((green) << 12) | ((blue) << 2),
|
|
|
|
par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
|
|
|
|
writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
|
|
|
|
writel(((red) << 22) | ((green) << 12) | ((blue) << 2),
|
|
|
|
par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Blank the display.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int offb_blank(int blank, struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct offb_par *par = (struct offb_par *) info->par;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (!par->cmap_adr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!par->blanked)
|
|
|
|
if (!blank)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
par->blanked = blank;
|
|
|
|
|
|
|
|
if (blank)
|
|
|
|
for (i = 0; i < 256; i++) {
|
|
|
|
switch (par->cmap_type) {
|
2011-12-14 21:58:29 +08:00
|
|
|
case cmap_simple:
|
2005-04-17 06:20:36 +08:00
|
|
|
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(par->cmap_adr + 0x58,
|
|
|
|
in_le32(par->cmap_adr + 0x58) & ~0x20);
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2005-04-17 06:20:36 +08:00
|
|
|
case cmap_r128:
|
|
|
|
/* Set palette index & data */
|
|
|
|
out_8(par->cmap_adr + 0xb0, i);
|
|
|
|
out_le32(par->cmap_adr + 0xb4, 0);
|
|
|
|
break;
|
|
|
|
case cmap_M3B:
|
|
|
|
/* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
|
|
|
|
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(par->cmap_adr + 0xb4, 0);
|
|
|
|
break;
|
|
|
|
case cmap_radeon:
|
|
|
|
out_8(par->cmap_adr + 0xb0, i);
|
|
|
|
out_le32(par->cmap_adr + 0xb4, 0);
|
|
|
|
break;
|
|
|
|
case cmap_gxt2000:
|
2006-10-26 13:38:10 +08:00
|
|
|
out_le32(((unsigned __iomem *) par->cmap_adr) + i,
|
2005-04-17 06:20:36 +08:00
|
|
|
0);
|
|
|
|
break;
|
2008-07-17 13:05:22 +08:00
|
|
|
case cmap_avivo:
|
|
|
|
writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
|
|
|
|
writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
|
|
|
|
writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
fb_set_cmap(&info->cmap, info);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-17 13:05:22 +08:00
|
|
|
static int offb_set_par(struct fb_info *info)
|
|
|
|
{
|
|
|
|
struct offb_par *par = (struct offb_par *) info->par;
|
|
|
|
|
|
|
|
/* On avivo, initialize palette control */
|
|
|
|
if (par->cmap_type == cmap_avivo) {
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTA_CONTROL);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_BLUE);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_GREEN);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_RED);
|
|
|
|
writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_BLUE);
|
|
|
|
writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_GREEN);
|
|
|
|
writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_RED);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTB_CONTROL);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_BLUE);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_GREEN);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_RED);
|
|
|
|
writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_BLUE);
|
|
|
|
writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_GREEN);
|
|
|
|
writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_RED);
|
|
|
|
writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE);
|
|
|
|
writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
|
|
|
|
writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE);
|
|
|
|
writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-07 04:01:26 +08:00
|
|
|
static void offb_destroy(struct fb_info *info)
|
|
|
|
{
|
2022-12-20 00:05:11 +08:00
|
|
|
struct offb_par *par = info->par;
|
|
|
|
|
2009-12-07 04:01:26 +08:00
|
|
|
if (info->screen_base)
|
|
|
|
iounmap(info->screen_base);
|
2022-12-20 00:05:11 +08:00
|
|
|
release_mem_region(par->base, par->size);
|
2018-03-13 00:06:54 +08:00
|
|
|
fb_dealloc_cmap(&info->cmap);
|
2009-12-07 04:01:26 +08:00
|
|
|
framebuffer_release(info);
|
|
|
|
}
|
|
|
|
|
2019-12-04 00:38:50 +08:00
|
|
|
static const struct fb_ops offb_ops = {
|
2008-07-17 13:05:22 +08:00
|
|
|
.owner = THIS_MODULE,
|
2023-08-04 02:35:53 +08:00
|
|
|
FB_DEFAULT_IOMEM_OPS,
|
2009-12-07 04:01:26 +08:00
|
|
|
.fb_destroy = offb_destroy,
|
2008-07-17 13:05:22 +08:00
|
|
|
.fb_setcolreg = offb_setcolreg,
|
|
|
|
.fb_set_par = offb_set_par,
|
|
|
|
.fb_blank = offb_blank,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-04 15:07:18 +08:00
|
|
|
static void __iomem *offb_map_reg(struct device_node *np, int index,
|
|
|
|
unsigned long offset, unsigned long size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-12-05 00:49:51 +08:00
|
|
|
const __be32 *addrp;
|
2006-10-26 13:38:10 +08:00
|
|
|
u64 asize, taddr;
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
addrp = of_get_pci_address(np, index, &asize, &flags);
|
|
|
|
if (addrp == NULL)
|
|
|
|
addrp = of_get_address(np, index, &asize, &flags);
|
|
|
|
if (addrp == NULL)
|
|
|
|
return NULL;
|
|
|
|
if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
|
|
|
|
return NULL;
|
|
|
|
if ((offset + size) > asize)
|
|
|
|
return NULL;
|
|
|
|
taddr = of_translate_address(np, addrp);
|
|
|
|
if (taddr == OF_BAD_ADDR)
|
|
|
|
return NULL;
|
|
|
|
return ioremap(taddr + offset, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-07-17 13:05:22 +08:00
|
|
|
static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp,
|
2019-01-11 21:34:39 +08:00
|
|
|
unsigned long address)
|
2008-07-17 13:05:22 +08:00
|
|
|
{
|
|
|
|
struct offb_par *par = (struct offb_par *) info->par;
|
|
|
|
|
2019-01-11 21:34:39 +08:00
|
|
|
if (of_node_name_prefix(dp, "ATY,Rage128")) {
|
2008-07-17 13:05:22 +08:00
|
|
|
par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
|
|
|
|
if (par->cmap_adr)
|
|
|
|
par->cmap_type = cmap_r128;
|
2019-01-11 21:34:39 +08:00
|
|
|
} else if (of_node_name_prefix(dp, "ATY,RageM3pA") ||
|
|
|
|
of_node_name_prefix(dp, "ATY,RageM3p12A")) {
|
2008-07-17 13:05:22 +08:00
|
|
|
par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
|
|
|
|
if (par->cmap_adr)
|
|
|
|
par->cmap_type = cmap_M3A;
|
2019-01-11 21:34:39 +08:00
|
|
|
} else if (of_node_name_prefix(dp, "ATY,RageM3pB")) {
|
2008-07-17 13:05:22 +08:00
|
|
|
par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
|
|
|
|
if (par->cmap_adr)
|
|
|
|
par->cmap_type = cmap_M3B;
|
2019-01-11 21:34:39 +08:00
|
|
|
} else if (of_node_name_prefix(dp, "ATY,Rage6")) {
|
2008-07-17 13:05:22 +08:00
|
|
|
par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
|
|
|
|
if (par->cmap_adr)
|
|
|
|
par->cmap_type = cmap_radeon;
|
2019-01-11 21:34:39 +08:00
|
|
|
} else if (of_node_name_prefix(dp, "ATY,")) {
|
2008-07-17 13:05:22 +08:00
|
|
|
unsigned long base = address & 0xff000000UL;
|
|
|
|
par->cmap_adr =
|
|
|
|
ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
|
|
|
|
par->cmap_data = par->cmap_adr + 1;
|
2011-12-14 21:58:29 +08:00
|
|
|
par->cmap_type = cmap_simple;
|
2008-07-17 13:05:22 +08:00
|
|
|
} else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
|
|
|
|
of_device_is_compatible(dp, "pci1014,21c"))) {
|
|
|
|
par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
|
|
|
|
if (par->cmap_adr)
|
|
|
|
par->cmap_type = cmap_gxt2000;
|
2019-01-11 21:34:39 +08:00
|
|
|
} else if (of_node_name_prefix(dp, "vga,Display-")) {
|
2008-07-17 13:05:22 +08:00
|
|
|
/* Look for AVIVO initialized by SLOF */
|
2024-04-23 09:20:21 +08:00
|
|
|
struct device_node *pciparent __free(device_node) = of_get_parent(dp);
|
2008-07-17 13:05:22 +08:00
|
|
|
const u32 *vid, *did;
|
|
|
|
vid = of_get_property(pciparent, "vendor-id", NULL);
|
|
|
|
did = of_get_property(pciparent, "device-id", NULL);
|
|
|
|
/* This will match most R5xx */
|
|
|
|
if (vid && did && *vid == 0x1002 &&
|
|
|
|
((*did >= 0x7100 && *did < 0x7800) ||
|
|
|
|
(*did >= 0x9400))) {
|
|
|
|
par->cmap_adr = offb_map_reg(pciparent, 2, 0, 0x10000);
|
|
|
|
if (par->cmap_adr)
|
|
|
|
par->cmap_type = cmap_avivo;
|
|
|
|
}
|
2011-12-14 21:58:29 +08:00
|
|
|
} else if (dp && of_device_is_compatible(dp, "qemu,std-vga")) {
|
2013-12-05 00:49:51 +08:00
|
|
|
#ifdef __BIG_ENDIAN
|
|
|
|
const __be32 io_of_addr[3] = { 0x01000000, 0x0, 0x0 };
|
|
|
|
#else
|
|
|
|
const __be32 io_of_addr[3] = { 0x00000001, 0x0, 0x0 };
|
|
|
|
#endif
|
2011-12-14 21:58:29 +08:00
|
|
|
u64 io_addr = of_translate_address(dp, io_of_addr);
|
|
|
|
if (io_addr != OF_BAD_ADDR) {
|
|
|
|
par->cmap_adr = ioremap(io_addr + 0x3c8, 2);
|
|
|
|
if (par->cmap_adr) {
|
|
|
|
par->cmap_type = cmap_simple;
|
|
|
|
par->cmap_data = par->cmap_adr + 1;
|
|
|
|
}
|
|
|
|
}
|
2008-07-17 13:05:22 +08:00
|
|
|
}
|
|
|
|
info->fix.visual = (par->cmap_type != cmap_unknown) ?
|
|
|
|
FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:04:04 +08:00
|
|
|
static void offb_init_fb(struct platform_device *parent, const char *name,
|
|
|
|
int width, int height, int depth,
|
|
|
|
int pitch, unsigned long address,
|
|
|
|
int foreign_endian, struct device_node *dp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-01-03 09:09:15 +08:00
|
|
|
unsigned long res_size = pitch * height;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long res_start = address;
|
|
|
|
struct fb_fix_screeninfo *fix;
|
|
|
|
struct fb_var_screeninfo *var;
|
|
|
|
struct fb_info *info;
|
2022-12-20 00:05:10 +08:00
|
|
|
struct offb_par *par;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!request_mem_region(res_start, res_size, "offb"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
|
|
|
|
width, height, name, address, depth, pitch);
|
2006-07-03 15:19:48 +08:00
|
|
|
if (depth != 8 && depth != 15 && depth != 16 && depth != 32) {
|
2017-08-07 23:22:13 +08:00
|
|
|
printk(KERN_ERR "%pOF: can't use depth = %d\n", dp, depth);
|
2005-04-17 06:20:36 +08:00
|
|
|
release_mem_region(res_start, res_size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-20 00:05:10 +08:00
|
|
|
info = framebuffer_alloc(sizeof(*par), &parent->dev);
|
2022-03-11 10:56:48 +08:00
|
|
|
if (!info) {
|
2005-04-17 06:20:36 +08:00
|
|
|
release_mem_region(res_start, res_size);
|
|
|
|
return;
|
|
|
|
}
|
2022-04-19 18:04:04 +08:00
|
|
|
platform_set_drvdata(parent, info);
|
2022-12-20 00:05:10 +08:00
|
|
|
par = info->par;
|
2005-04-17 06:20:36 +08:00
|
|
|
fix = &info->fix;
|
|
|
|
var = &info->var;
|
|
|
|
|
2023-10-21 14:53:37 +08:00
|
|
|
if (name)
|
|
|
|
snprintf(fix->id, sizeof(fix->id), "OFfb %s", name);
|
|
|
|
else
|
2018-10-08 18:57:36 +08:00
|
|
|
snprintf(fix->id, sizeof(fix->id), "OFfb %pOFn", dp);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
var->xres = var->xres_virtual = width;
|
|
|
|
var->yres = var->yres_virtual = height;
|
|
|
|
fix->line_length = pitch;
|
|
|
|
|
|
|
|
fix->smem_start = address;
|
|
|
|
fix->smem_len = pitch * height;
|
|
|
|
fix->type = FB_TYPE_PACKED_PIXELS;
|
|
|
|
fix->type_aux = 0;
|
|
|
|
|
|
|
|
par->cmap_type = cmap_unknown;
|
2008-07-17 13:05:22 +08:00
|
|
|
if (depth == 8)
|
2019-01-11 21:34:39 +08:00
|
|
|
offb_init_palette_hacks(info, dp, address);
|
2008-07-17 13:05:22 +08:00
|
|
|
else
|
2006-07-04 15:07:18 +08:00
|
|
|
fix->visual = FB_VISUAL_TRUECOLOR;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
var->xoffset = var->yoffset = 0;
|
|
|
|
switch (depth) {
|
|
|
|
case 8:
|
|
|
|
var->bits_per_pixel = 8;
|
|
|
|
var->red.offset = 0;
|
|
|
|
var->red.length = 8;
|
|
|
|
var->green.offset = 0;
|
|
|
|
var->green.length = 8;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 8;
|
|
|
|
var->transp.offset = 0;
|
|
|
|
var->transp.length = 0;
|
|
|
|
break;
|
2006-07-03 15:19:48 +08:00
|
|
|
case 15: /* RGB 555 */
|
2005-04-17 06:20:36 +08:00
|
|
|
var->bits_per_pixel = 16;
|
|
|
|
var->red.offset = 10;
|
|
|
|
var->red.length = 5;
|
|
|
|
var->green.offset = 5;
|
|
|
|
var->green.length = 5;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 5;
|
|
|
|
var->transp.offset = 0;
|
|
|
|
var->transp.length = 0;
|
|
|
|
break;
|
2006-07-03 15:19:48 +08:00
|
|
|
case 16: /* RGB 565 */
|
|
|
|
var->bits_per_pixel = 16;
|
|
|
|
var->red.offset = 11;
|
|
|
|
var->red.length = 5;
|
|
|
|
var->green.offset = 5;
|
|
|
|
var->green.length = 6;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 5;
|
|
|
|
var->transp.offset = 0;
|
|
|
|
var->transp.length = 0;
|
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
case 32: /* RGB 888 */
|
|
|
|
var->bits_per_pixel = 32;
|
|
|
|
var->red.offset = 16;
|
|
|
|
var->red.length = 8;
|
|
|
|
var->green.offset = 8;
|
|
|
|
var->green.length = 8;
|
|
|
|
var->blue.offset = 0;
|
|
|
|
var->blue.length = 8;
|
|
|
|
var->transp.offset = 24;
|
|
|
|
var->transp.length = 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var->red.msb_right = var->green.msb_right = var->blue.msb_right =
|
|
|
|
var->transp.msb_right = 0;
|
|
|
|
var->grayscale = 0;
|
|
|
|
var->nonstd = 0;
|
|
|
|
var->activate = 0;
|
|
|
|
var->height = var->width = -1;
|
|
|
|
var->pixclock = 10000;
|
|
|
|
var->left_margin = var->right_margin = 16;
|
|
|
|
var->upper_margin = var->lower_margin = 16;
|
|
|
|
var->hsync_len = var->vsync_len = 8;
|
|
|
|
var->sync = 0;
|
|
|
|
var->vmode = FB_VMODE_NONINTERLACED;
|
|
|
|
|
2022-12-20 00:05:11 +08:00
|
|
|
par->base = address;
|
|
|
|
par->size = fix->smem_len;
|
2009-12-07 04:01:26 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
info->fbops = &offb_ops;
|
|
|
|
info->screen_base = ioremap(address, fix->smem_len);
|
2022-12-20 00:05:10 +08:00
|
|
|
info->pseudo_palette = par->pseudo_palette;
|
2023-07-16 02:51:47 +08:00
|
|
|
info->flags = foreign_endian;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
fb_alloc_cmap(&info->cmap, 256, 0);
|
|
|
|
|
2022-12-20 00:05:11 +08:00
|
|
|
if (devm_aperture_acquire_for_platform_device(parent, par->base, par->size) < 0)
|
|
|
|
goto out_err;
|
2010-05-16 23:27:03 +08:00
|
|
|
if (register_framebuffer(info) < 0)
|
|
|
|
goto out_err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2017-08-07 23:22:13 +08:00
|
|
|
fb_info(info, "Open Firmware frame buffer device on %pOF\n", dp);
|
2010-05-16 23:27:03 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
out_err:
|
2018-03-13 00:06:54 +08:00
|
|
|
fb_dealloc_cmap(&info->cmap);
|
2010-05-16 23:27:03 +08:00
|
|
|
iounmap(info->screen_base);
|
|
|
|
iounmap(par->cmap_adr);
|
|
|
|
par->cmap_adr = NULL;
|
|
|
|
framebuffer_release(info);
|
|
|
|
release_mem_region(res_start, res_size);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2022-04-19 18:04:04 +08:00
|
|
|
static void offb_init_nodriver(struct platform_device *parent, struct device_node *dp,
|
|
|
|
int no_real_node)
|
2006-07-04 15:07:18 +08:00
|
|
|
{
|
|
|
|
unsigned int len;
|
|
|
|
int i, width = 640, height = 480, depth = 8, pitch = 640;
|
|
|
|
unsigned int flags, rsize, addr_prop = 0;
|
|
|
|
unsigned long max_size = 0;
|
|
|
|
u64 rstart, address = OF_BAD_ADDR;
|
2013-12-05 00:49:51 +08:00
|
|
|
const __be32 *pp, *addrp, *up;
|
2006-07-04 15:07:18 +08:00
|
|
|
u64 asize;
|
2008-04-28 17:14:50 +08:00
|
|
|
int foreign_endian = 0;
|
|
|
|
|
|
|
|
#ifdef __BIG_ENDIAN
|
2023-03-10 22:47:30 +08:00
|
|
|
if (of_property_read_bool(dp, "little-endian"))
|
2008-04-28 17:14:50 +08:00
|
|
|
foreign_endian = FBINFO_FOREIGN_ENDIAN;
|
|
|
|
#else
|
2023-03-10 22:47:30 +08:00
|
|
|
if (of_property_read_bool(dp, "big-endian"))
|
2008-04-28 17:14:50 +08:00
|
|
|
foreign_endian = FBINFO_FOREIGN_ENDIAN;
|
|
|
|
#endif
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "linux,bootx-depth", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp == NULL)
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "depth", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp && len == sizeof(u32))
|
2013-12-05 00:49:51 +08:00
|
|
|
depth = be32_to_cpup(pp);
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "linux,bootx-width", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp == NULL)
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "width", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp && len == sizeof(u32))
|
2013-12-05 00:49:51 +08:00
|
|
|
width = be32_to_cpup(pp);
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "linux,bootx-height", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp == NULL)
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "height", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp && len == sizeof(u32))
|
2013-12-05 00:49:51 +08:00
|
|
|
height = be32_to_cpup(pp);
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "linux,bootx-linebytes", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (pp == NULL)
|
2007-05-01 11:54:02 +08:00
|
|
|
pp = of_get_property(dp, "linebytes", &len);
|
2006-10-26 13:38:10 +08:00
|
|
|
if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
|
2013-12-05 00:49:51 +08:00
|
|
|
pitch = be32_to_cpup(pp);
|
2006-07-04 15:07:18 +08:00
|
|
|
else
|
|
|
|
pitch = width * ((depth + 7) / 8);
|
|
|
|
|
|
|
|
rsize = (unsigned long)pitch * (unsigned long)height;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
2007-05-01 11:54:02 +08:00
|
|
|
up = of_get_property(dp, "linux,bootx-addr", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (up == NULL)
|
2007-05-01 11:54:02 +08:00
|
|
|
up = of_get_property(dp, "address", &len);
|
2006-07-04 15:07:18 +08:00
|
|
|
if (up && len == sizeof(u32))
|
|
|
|
addr_prop = *up;
|
|
|
|
|
|
|
|
/* Hack for when BootX is passing us */
|
|
|
|
if (no_real_node)
|
|
|
|
goto skip_addr;
|
|
|
|
|
|
|
|
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 + asize) >= (addr_prop + rsize)))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
skip_addr:
|
|
|
|
if (address == OF_BAD_ADDR && addr_prop)
|
|
|
|
address = (u64)addr_prop;
|
|
|
|
if (address != OF_BAD_ADDR) {
|
2016-09-13 13:53:46 +08:00
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
const __be32 *vidp, *didp;
|
|
|
|
u32 vid, did;
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
|
|
|
|
vidp = of_get_property(dp, "vendor-id", NULL);
|
|
|
|
didp = of_get_property(dp, "device-id", NULL);
|
|
|
|
if (vidp && didp) {
|
|
|
|
vid = be32_to_cpup(vidp);
|
|
|
|
did = be32_to_cpup(didp);
|
|
|
|
pdev = pci_get_device(vid, did, NULL);
|
|
|
|
if (!pdev || pci_enable_device(pdev))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2006-07-04 15:07:18 +08:00
|
|
|
/* kludge for valkyrie */
|
2019-02-09 02:24:45 +08:00
|
|
|
if (of_node_name_eq(dp, "valkyrie"))
|
2006-07-04 15:07:18 +08:00
|
|
|
address += 0x1000;
|
2022-04-19 18:04:04 +08:00
|
|
|
offb_init_fb(parent, no_real_node ? "bootx" : NULL,
|
2006-07-04 15:07:18 +08:00
|
|
|
width, height, depth, pitch, address,
|
2008-04-28 17:14:50 +08:00
|
|
|
foreign_endian, no_real_node ? NULL : dp);
|
2006-07-04 15:07:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-19 07:54:06 +08:00
|
|
|
static void offb_remove(struct platform_device *pdev)
|
2006-07-04 15:07:18 +08:00
|
|
|
{
|
2022-04-19 18:04:04 +08:00
|
|
|
struct fb_info *info = platform_get_drvdata(pdev);
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2022-04-19 18:04:04 +08:00
|
|
|
if (info)
|
|
|
|
unregister_framebuffer(info);
|
|
|
|
}
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2022-04-19 18:04:04 +08:00
|
|
|
static int offb_probe_bootx_noscreen(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
offb_init_nodriver(pdev, of_chosen, 1);
|
2006-07-04 15:07:18 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-19 18:04:04 +08:00
|
|
|
static struct platform_driver offb_driver_bootx_noscreen = {
|
|
|
|
.driver = {
|
|
|
|
.name = "bootx-noscreen",
|
|
|
|
},
|
|
|
|
.probe = offb_probe_bootx_noscreen,
|
2023-03-19 07:54:06 +08:00
|
|
|
.remove_new = offb_remove,
|
2022-04-19 18:04:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int offb_probe_display(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
offb_init_nodriver(pdev, pdev->dev.of_node, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-07-04 15:07:18 +08:00
|
|
|
|
2022-04-19 18:04:04 +08:00
|
|
|
static const struct of_device_id offb_of_match_display[] = {
|
|
|
|
{ .compatible = "display", },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, offb_of_match_display);
|
|
|
|
|
|
|
|
static struct platform_driver offb_driver_display = {
|
|
|
|
.driver = {
|
|
|
|
.name = "of-display",
|
|
|
|
.of_match_table = offb_of_match_display,
|
|
|
|
},
|
|
|
|
.probe = offb_probe_display,
|
2023-03-19 07:54:06 +08:00
|
|
|
.remove_new = offb_remove,
|
2022-04-19 18:04:04 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init offb_init(void)
|
|
|
|
{
|
|
|
|
if (fb_get_options("offb", NULL))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
platform_driver_register(&offb_driver_bootx_noscreen);
|
|
|
|
platform_driver_register(&offb_driver_display);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
module_init(offb_init);
|
2022-04-19 18:04:04 +08:00
|
|
|
|
|
|
|
static void __exit offb_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&offb_driver_display);
|
|
|
|
platform_driver_unregister(&offb_driver_bootx_noscreen);
|
|
|
|
}
|
|
|
|
module_exit(offb_exit);
|
|
|
|
|
2024-06-15 14:25:00 +08:00
|
|
|
MODULE_DESCRIPTION("Open Firmware frame buffer device driver");
|
2005-04-17 06:20:36 +08:00
|
|
|
MODULE_LICENSE("GPL");
|