xref: /OK3568_Linux_fs/kernel/drivers/video/fbdev/offb.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  linux/drivers/video/offb.c -- Open Firmware based frame buffer device
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *	Copyright (C) 1997 Geert Uytterhoeven
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *  This driver is partly based on the PowerMac console driver:
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *	Copyright (C) 1996 Paul Mackerras
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  *  This file is subject to the terms and conditions of the GNU General Public
11*4882a593Smuzhiyun  *  License. See the file COPYING in the main directory of this archive for
12*4882a593Smuzhiyun  *  more details.
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <linux/module.h>
16*4882a593Smuzhiyun #include <linux/kernel.h>
17*4882a593Smuzhiyun #include <linux/errno.h>
18*4882a593Smuzhiyun #include <linux/string.h>
19*4882a593Smuzhiyun #include <linux/mm.h>
20*4882a593Smuzhiyun #include <linux/vmalloc.h>
21*4882a593Smuzhiyun #include <linux/delay.h>
22*4882a593Smuzhiyun #include <linux/of.h>
23*4882a593Smuzhiyun #include <linux/of_address.h>
24*4882a593Smuzhiyun #include <linux/interrupt.h>
25*4882a593Smuzhiyun #include <linux/fb.h>
26*4882a593Smuzhiyun #include <linux/init.h>
27*4882a593Smuzhiyun #include <linux/ioport.h>
28*4882a593Smuzhiyun #include <linux/pci.h>
29*4882a593Smuzhiyun #include <asm/io.h>
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef CONFIG_PPC32
32*4882a593Smuzhiyun #include <asm/bootx.h>
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun #include "macmodes.h"
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /* Supported palette hacks */
38*4882a593Smuzhiyun enum {
39*4882a593Smuzhiyun 	cmap_unknown,
40*4882a593Smuzhiyun 	cmap_simple,		/* ATI Mach64 */
41*4882a593Smuzhiyun 	cmap_r128,		/* ATI Rage128 */
42*4882a593Smuzhiyun 	cmap_M3A,		/* ATI Rage Mobility M3 Head A */
43*4882a593Smuzhiyun 	cmap_M3B,		/* ATI Rage Mobility M3 Head B */
44*4882a593Smuzhiyun 	cmap_radeon,		/* ATI Radeon */
45*4882a593Smuzhiyun 	cmap_gxt2000,		/* IBM GXT2000 */
46*4882a593Smuzhiyun 	cmap_avivo,		/* ATI R5xx */
47*4882a593Smuzhiyun 	cmap_qemu,		/* qemu vga */
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun struct offb_par {
51*4882a593Smuzhiyun 	volatile void __iomem *cmap_adr;
52*4882a593Smuzhiyun 	volatile void __iomem *cmap_data;
53*4882a593Smuzhiyun 	int cmap_type;
54*4882a593Smuzhiyun 	int blanked;
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun struct offb_par default_par;
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #ifdef CONFIG_PPC32
60*4882a593Smuzhiyun extern boot_infos_t *boot_infos;
61*4882a593Smuzhiyun #endif
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /* Definitions used by the Avivo palette hack */
64*4882a593Smuzhiyun #define AVIVO_DC_LUT_RW_SELECT                  0x6480
65*4882a593Smuzhiyun #define AVIVO_DC_LUT_RW_MODE                    0x6484
66*4882a593Smuzhiyun #define AVIVO_DC_LUT_RW_INDEX                   0x6488
67*4882a593Smuzhiyun #define AVIVO_DC_LUT_SEQ_COLOR                  0x648c
68*4882a593Smuzhiyun #define AVIVO_DC_LUT_PWL_DATA                   0x6490
69*4882a593Smuzhiyun #define AVIVO_DC_LUT_30_COLOR                   0x6494
70*4882a593Smuzhiyun #define AVIVO_DC_LUT_READ_PIPE_SELECT           0x6498
71*4882a593Smuzhiyun #define AVIVO_DC_LUT_WRITE_EN_MASK              0x649c
72*4882a593Smuzhiyun #define AVIVO_DC_LUT_AUTOFILL                   0x64a0
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun #define AVIVO_DC_LUTA_CONTROL                   0x64c0
75*4882a593Smuzhiyun #define AVIVO_DC_LUTA_BLACK_OFFSET_BLUE         0x64c4
76*4882a593Smuzhiyun #define AVIVO_DC_LUTA_BLACK_OFFSET_GREEN        0x64c8
77*4882a593Smuzhiyun #define AVIVO_DC_LUTA_BLACK_OFFSET_RED          0x64cc
78*4882a593Smuzhiyun #define AVIVO_DC_LUTA_WHITE_OFFSET_BLUE         0x64d0
79*4882a593Smuzhiyun #define AVIVO_DC_LUTA_WHITE_OFFSET_GREEN        0x64d4
80*4882a593Smuzhiyun #define AVIVO_DC_LUTA_WHITE_OFFSET_RED          0x64d8
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #define AVIVO_DC_LUTB_CONTROL                   0x6cc0
83*4882a593Smuzhiyun #define AVIVO_DC_LUTB_BLACK_OFFSET_BLUE         0x6cc4
84*4882a593Smuzhiyun #define AVIVO_DC_LUTB_BLACK_OFFSET_GREEN        0x6cc8
85*4882a593Smuzhiyun #define AVIVO_DC_LUTB_BLACK_OFFSET_RED          0x6ccc
86*4882a593Smuzhiyun #define AVIVO_DC_LUTB_WHITE_OFFSET_BLUE         0x6cd0
87*4882a593Smuzhiyun #define AVIVO_DC_LUTB_WHITE_OFFSET_GREEN        0x6cd4
88*4882a593Smuzhiyun #define AVIVO_DC_LUTB_WHITE_OFFSET_RED          0x6cd8
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun     /*
91*4882a593Smuzhiyun      *  Set a single color register. The values supplied are already
92*4882a593Smuzhiyun      *  rounded down to the hardware's capabilities (according to the
93*4882a593Smuzhiyun      *  entries in the var structure). Return != 0 for invalid regno.
94*4882a593Smuzhiyun      */
95*4882a593Smuzhiyun 
offb_setcolreg(u_int regno,u_int red,u_int green,u_int blue,u_int transp,struct fb_info * info)96*4882a593Smuzhiyun static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
97*4882a593Smuzhiyun 			  u_int transp, struct fb_info *info)
98*4882a593Smuzhiyun {
99*4882a593Smuzhiyun 	struct offb_par *par = (struct offb_par *) info->par;
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun 	if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
102*4882a593Smuzhiyun 		u32 *pal = info->pseudo_palette;
103*4882a593Smuzhiyun 		u32 cr = red >> (16 - info->var.red.length);
104*4882a593Smuzhiyun 		u32 cg = green >> (16 - info->var.green.length);
105*4882a593Smuzhiyun 		u32 cb = blue >> (16 - info->var.blue.length);
106*4882a593Smuzhiyun 		u32 value;
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 		if (regno >= 16)
109*4882a593Smuzhiyun 			return -EINVAL;
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 		value = (cr << info->var.red.offset) |
112*4882a593Smuzhiyun 			(cg << info->var.green.offset) |
113*4882a593Smuzhiyun 			(cb << info->var.blue.offset);
114*4882a593Smuzhiyun 		if (info->var.transp.length > 0) {
115*4882a593Smuzhiyun 			u32 mask = (1 << info->var.transp.length) - 1;
116*4882a593Smuzhiyun 			mask <<= info->var.transp.offset;
117*4882a593Smuzhiyun 			value |= mask;
118*4882a593Smuzhiyun 		}
119*4882a593Smuzhiyun 		pal[regno] = value;
120*4882a593Smuzhiyun 		return 0;
121*4882a593Smuzhiyun 	}
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 	if (regno > 255)
124*4882a593Smuzhiyun 		return -EINVAL;
125*4882a593Smuzhiyun 
126*4882a593Smuzhiyun 	red >>= 8;
127*4882a593Smuzhiyun 	green >>= 8;
128*4882a593Smuzhiyun 	blue >>= 8;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	if (!par->cmap_adr)
131*4882a593Smuzhiyun 		return 0;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun 	switch (par->cmap_type) {
134*4882a593Smuzhiyun 	case cmap_simple:
135*4882a593Smuzhiyun 		writeb(regno, par->cmap_adr);
136*4882a593Smuzhiyun 		writeb(red, par->cmap_data);
137*4882a593Smuzhiyun 		writeb(green, par->cmap_data);
138*4882a593Smuzhiyun 		writeb(blue, par->cmap_data);
139*4882a593Smuzhiyun 		break;
140*4882a593Smuzhiyun 	case cmap_M3A:
141*4882a593Smuzhiyun 		/* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
142*4882a593Smuzhiyun 		out_le32(par->cmap_adr + 0x58,
143*4882a593Smuzhiyun 			 in_le32(par->cmap_adr + 0x58) & ~0x20);
144*4882a593Smuzhiyun 		fallthrough;
145*4882a593Smuzhiyun 	case cmap_r128:
146*4882a593Smuzhiyun 		/* Set palette index & data */
147*4882a593Smuzhiyun 		out_8(par->cmap_adr + 0xb0, regno);
148*4882a593Smuzhiyun 		out_le32(par->cmap_adr + 0xb4,
149*4882a593Smuzhiyun 			 (red << 16 | green << 8 | blue));
150*4882a593Smuzhiyun 		break;
151*4882a593Smuzhiyun 	case cmap_M3B:
152*4882a593Smuzhiyun 		/* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
153*4882a593Smuzhiyun 		out_le32(par->cmap_adr + 0x58,
154*4882a593Smuzhiyun 			 in_le32(par->cmap_adr + 0x58) | 0x20);
155*4882a593Smuzhiyun 		/* Set palette index & data */
156*4882a593Smuzhiyun 		out_8(par->cmap_adr + 0xb0, regno);
157*4882a593Smuzhiyun 		out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
158*4882a593Smuzhiyun 		break;
159*4882a593Smuzhiyun 	case cmap_radeon:
160*4882a593Smuzhiyun 		/* Set palette index & data (could be smarter) */
161*4882a593Smuzhiyun 		out_8(par->cmap_adr + 0xb0, regno);
162*4882a593Smuzhiyun 		out_le32(par->cmap_adr + 0xb4, (red << 16 | green << 8 | blue));
163*4882a593Smuzhiyun 		break;
164*4882a593Smuzhiyun 	case cmap_gxt2000:
165*4882a593Smuzhiyun 		out_le32(((unsigned __iomem *) par->cmap_adr) + regno,
166*4882a593Smuzhiyun 			 (red << 16 | green << 8 | blue));
167*4882a593Smuzhiyun 		break;
168*4882a593Smuzhiyun 	case cmap_avivo:
169*4882a593Smuzhiyun 		/* Write to both LUTs for now */
170*4882a593Smuzhiyun 		writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
171*4882a593Smuzhiyun 		writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
172*4882a593Smuzhiyun 		writel(((red) << 22) | ((green) << 12) | ((blue) << 2),
173*4882a593Smuzhiyun 		       par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
174*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
175*4882a593Smuzhiyun 		writeb(regno, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
176*4882a593Smuzhiyun 		writel(((red) << 22) | ((green) << 12) | ((blue) << 2),
177*4882a593Smuzhiyun 		       par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
178*4882a593Smuzhiyun 		break;
179*4882a593Smuzhiyun 	}
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 	return 0;
182*4882a593Smuzhiyun }
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun     /*
185*4882a593Smuzhiyun      *  Blank the display.
186*4882a593Smuzhiyun      */
187*4882a593Smuzhiyun 
offb_blank(int blank,struct fb_info * info)188*4882a593Smuzhiyun static int offb_blank(int blank, struct fb_info *info)
189*4882a593Smuzhiyun {
190*4882a593Smuzhiyun 	struct offb_par *par = (struct offb_par *) info->par;
191*4882a593Smuzhiyun 	int i, j;
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun 	if (!par->cmap_adr)
194*4882a593Smuzhiyun 		return 0;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	if (!par->blanked)
197*4882a593Smuzhiyun 		if (!blank)
198*4882a593Smuzhiyun 			return 0;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 	par->blanked = blank;
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	if (blank)
203*4882a593Smuzhiyun 		for (i = 0; i < 256; i++) {
204*4882a593Smuzhiyun 			switch (par->cmap_type) {
205*4882a593Smuzhiyun 			case cmap_simple:
206*4882a593Smuzhiyun 				writeb(i, par->cmap_adr);
207*4882a593Smuzhiyun 				for (j = 0; j < 3; j++)
208*4882a593Smuzhiyun 					writeb(0, par->cmap_data);
209*4882a593Smuzhiyun 				break;
210*4882a593Smuzhiyun 			case cmap_M3A:
211*4882a593Smuzhiyun 				/* Clear PALETTE_ACCESS_CNTL in DAC_CNTL */
212*4882a593Smuzhiyun 				out_le32(par->cmap_adr + 0x58,
213*4882a593Smuzhiyun 					 in_le32(par->cmap_adr + 0x58) & ~0x20);
214*4882a593Smuzhiyun 				fallthrough;
215*4882a593Smuzhiyun 			case cmap_r128:
216*4882a593Smuzhiyun 				/* Set palette index & data */
217*4882a593Smuzhiyun 				out_8(par->cmap_adr + 0xb0, i);
218*4882a593Smuzhiyun 				out_le32(par->cmap_adr + 0xb4, 0);
219*4882a593Smuzhiyun 				break;
220*4882a593Smuzhiyun 			case cmap_M3B:
221*4882a593Smuzhiyun 				/* Set PALETTE_ACCESS_CNTL in DAC_CNTL */
222*4882a593Smuzhiyun 				out_le32(par->cmap_adr + 0x58,
223*4882a593Smuzhiyun 					 in_le32(par->cmap_adr + 0x58) | 0x20);
224*4882a593Smuzhiyun 				/* Set palette index & data */
225*4882a593Smuzhiyun 				out_8(par->cmap_adr + 0xb0, i);
226*4882a593Smuzhiyun 				out_le32(par->cmap_adr + 0xb4, 0);
227*4882a593Smuzhiyun 				break;
228*4882a593Smuzhiyun 			case cmap_radeon:
229*4882a593Smuzhiyun 				out_8(par->cmap_adr + 0xb0, i);
230*4882a593Smuzhiyun 				out_le32(par->cmap_adr + 0xb4, 0);
231*4882a593Smuzhiyun 				break;
232*4882a593Smuzhiyun 			case cmap_gxt2000:
233*4882a593Smuzhiyun 				out_le32(((unsigned __iomem *) par->cmap_adr) + i,
234*4882a593Smuzhiyun 					 0);
235*4882a593Smuzhiyun 				break;
236*4882a593Smuzhiyun 			case cmap_avivo:
237*4882a593Smuzhiyun 				writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
238*4882a593Smuzhiyun 				writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
239*4882a593Smuzhiyun 				writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
240*4882a593Smuzhiyun 				writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
241*4882a593Smuzhiyun 				writeb(i, par->cmap_adr + AVIVO_DC_LUT_RW_INDEX);
242*4882a593Smuzhiyun 				writel(0, par->cmap_adr + AVIVO_DC_LUT_30_COLOR);
243*4882a593Smuzhiyun 				break;
244*4882a593Smuzhiyun 			}
245*4882a593Smuzhiyun 	} else
246*4882a593Smuzhiyun 		fb_set_cmap(&info->cmap, info);
247*4882a593Smuzhiyun 	return 0;
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun 
offb_set_par(struct fb_info * info)250*4882a593Smuzhiyun static int offb_set_par(struct fb_info *info)
251*4882a593Smuzhiyun {
252*4882a593Smuzhiyun 	struct offb_par *par = (struct offb_par *) info->par;
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun 	/* On avivo, initialize palette control */
255*4882a593Smuzhiyun 	if (par->cmap_type == cmap_avivo) {
256*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTA_CONTROL);
257*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_BLUE);
258*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_GREEN);
259*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTA_BLACK_OFFSET_RED);
260*4882a593Smuzhiyun 		writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_BLUE);
261*4882a593Smuzhiyun 		writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_GREEN);
262*4882a593Smuzhiyun 		writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTA_WHITE_OFFSET_RED);
263*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTB_CONTROL);
264*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_BLUE);
265*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_GREEN);
266*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUTB_BLACK_OFFSET_RED);
267*4882a593Smuzhiyun 		writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_BLUE);
268*4882a593Smuzhiyun 		writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_GREEN);
269*4882a593Smuzhiyun 		writel(0x0000ffff, par->cmap_adr + AVIVO_DC_LUTB_WHITE_OFFSET_RED);
270*4882a593Smuzhiyun 		writel(1, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
271*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE);
272*4882a593Smuzhiyun 		writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK);
273*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_SELECT);
274*4882a593Smuzhiyun 		writel(0, par->cmap_adr + AVIVO_DC_LUT_RW_MODE);
275*4882a593Smuzhiyun 		writel(0x0000003f, par->cmap_adr + AVIVO_DC_LUT_WRITE_EN_MASK);
276*4882a593Smuzhiyun 	}
277*4882a593Smuzhiyun 	return 0;
278*4882a593Smuzhiyun }
279*4882a593Smuzhiyun 
offb_destroy(struct fb_info * info)280*4882a593Smuzhiyun static void offb_destroy(struct fb_info *info)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun 	if (info->screen_base)
283*4882a593Smuzhiyun 		iounmap(info->screen_base);
284*4882a593Smuzhiyun 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
285*4882a593Smuzhiyun 	fb_dealloc_cmap(&info->cmap);
286*4882a593Smuzhiyun 	framebuffer_release(info);
287*4882a593Smuzhiyun }
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun static const struct fb_ops offb_ops = {
290*4882a593Smuzhiyun 	.owner		= THIS_MODULE,
291*4882a593Smuzhiyun 	.fb_destroy	= offb_destroy,
292*4882a593Smuzhiyun 	.fb_setcolreg	= offb_setcolreg,
293*4882a593Smuzhiyun 	.fb_set_par	= offb_set_par,
294*4882a593Smuzhiyun 	.fb_blank	= offb_blank,
295*4882a593Smuzhiyun 	.fb_fillrect	= cfb_fillrect,
296*4882a593Smuzhiyun 	.fb_copyarea	= cfb_copyarea,
297*4882a593Smuzhiyun 	.fb_imageblit	= cfb_imageblit,
298*4882a593Smuzhiyun };
299*4882a593Smuzhiyun 
offb_map_reg(struct device_node * np,int index,unsigned long offset,unsigned long size)300*4882a593Smuzhiyun static void __iomem *offb_map_reg(struct device_node *np, int index,
301*4882a593Smuzhiyun 				  unsigned long offset, unsigned long size)
302*4882a593Smuzhiyun {
303*4882a593Smuzhiyun 	const __be32 *addrp;
304*4882a593Smuzhiyun 	u64 asize, taddr;
305*4882a593Smuzhiyun 	unsigned int flags;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	addrp = of_get_pci_address(np, index, &asize, &flags);
308*4882a593Smuzhiyun 	if (addrp == NULL)
309*4882a593Smuzhiyun 		addrp = of_get_address(np, index, &asize, &flags);
310*4882a593Smuzhiyun 	if (addrp == NULL)
311*4882a593Smuzhiyun 		return NULL;
312*4882a593Smuzhiyun 	if ((flags & (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
313*4882a593Smuzhiyun 		return NULL;
314*4882a593Smuzhiyun 	if ((offset + size) > asize)
315*4882a593Smuzhiyun 		return NULL;
316*4882a593Smuzhiyun 	taddr = of_translate_address(np, addrp);
317*4882a593Smuzhiyun 	if (taddr == OF_BAD_ADDR)
318*4882a593Smuzhiyun 		return NULL;
319*4882a593Smuzhiyun 	return ioremap(taddr + offset, size);
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun 
offb_init_palette_hacks(struct fb_info * info,struct device_node * dp,unsigned long address)322*4882a593Smuzhiyun static void offb_init_palette_hacks(struct fb_info *info, struct device_node *dp,
323*4882a593Smuzhiyun 				    unsigned long address)
324*4882a593Smuzhiyun {
325*4882a593Smuzhiyun 	struct offb_par *par = (struct offb_par *) info->par;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	if (of_node_name_prefix(dp, "ATY,Rage128")) {
328*4882a593Smuzhiyun 		par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
329*4882a593Smuzhiyun 		if (par->cmap_adr)
330*4882a593Smuzhiyun 			par->cmap_type = cmap_r128;
331*4882a593Smuzhiyun 	} else if (of_node_name_prefix(dp, "ATY,RageM3pA") ||
332*4882a593Smuzhiyun 		   of_node_name_prefix(dp, "ATY,RageM3p12A")) {
333*4882a593Smuzhiyun 		par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
334*4882a593Smuzhiyun 		if (par->cmap_adr)
335*4882a593Smuzhiyun 			par->cmap_type = cmap_M3A;
336*4882a593Smuzhiyun 	} else if (of_node_name_prefix(dp, "ATY,RageM3pB")) {
337*4882a593Smuzhiyun 		par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
338*4882a593Smuzhiyun 		if (par->cmap_adr)
339*4882a593Smuzhiyun 			par->cmap_type = cmap_M3B;
340*4882a593Smuzhiyun 	} else if (of_node_name_prefix(dp, "ATY,Rage6")) {
341*4882a593Smuzhiyun 		par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
342*4882a593Smuzhiyun 		if (par->cmap_adr)
343*4882a593Smuzhiyun 			par->cmap_type = cmap_radeon;
344*4882a593Smuzhiyun 	} else if (of_node_name_prefix(dp, "ATY,")) {
345*4882a593Smuzhiyun 		unsigned long base = address & 0xff000000UL;
346*4882a593Smuzhiyun 		par->cmap_adr =
347*4882a593Smuzhiyun 			ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
348*4882a593Smuzhiyun 		par->cmap_data = par->cmap_adr + 1;
349*4882a593Smuzhiyun 		par->cmap_type = cmap_simple;
350*4882a593Smuzhiyun 	} else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
351*4882a593Smuzhiyun 			  of_device_is_compatible(dp, "pci1014,21c"))) {
352*4882a593Smuzhiyun 		par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
353*4882a593Smuzhiyun 		if (par->cmap_adr)
354*4882a593Smuzhiyun 			par->cmap_type = cmap_gxt2000;
355*4882a593Smuzhiyun 	} else if (of_node_name_prefix(dp, "vga,Display-")) {
356*4882a593Smuzhiyun 		/* Look for AVIVO initialized by SLOF */
357*4882a593Smuzhiyun 		struct device_node *pciparent = of_get_parent(dp);
358*4882a593Smuzhiyun 		const u32 *vid, *did;
359*4882a593Smuzhiyun 		vid = of_get_property(pciparent, "vendor-id", NULL);
360*4882a593Smuzhiyun 		did = of_get_property(pciparent, "device-id", NULL);
361*4882a593Smuzhiyun 		/* This will match most R5xx */
362*4882a593Smuzhiyun 		if (vid && did && *vid == 0x1002 &&
363*4882a593Smuzhiyun 		    ((*did >= 0x7100 && *did < 0x7800) ||
364*4882a593Smuzhiyun 		     (*did >= 0x9400))) {
365*4882a593Smuzhiyun 			par->cmap_adr = offb_map_reg(pciparent, 2, 0, 0x10000);
366*4882a593Smuzhiyun 			if (par->cmap_adr)
367*4882a593Smuzhiyun 				par->cmap_type = cmap_avivo;
368*4882a593Smuzhiyun 		}
369*4882a593Smuzhiyun 		of_node_put(pciparent);
370*4882a593Smuzhiyun 	} else if (dp && of_device_is_compatible(dp, "qemu,std-vga")) {
371*4882a593Smuzhiyun #ifdef __BIG_ENDIAN
372*4882a593Smuzhiyun 		const __be32 io_of_addr[3] = { 0x01000000, 0x0, 0x0 };
373*4882a593Smuzhiyun #else
374*4882a593Smuzhiyun 		const __be32 io_of_addr[3] = { 0x00000001, 0x0, 0x0 };
375*4882a593Smuzhiyun #endif
376*4882a593Smuzhiyun 		u64 io_addr = of_translate_address(dp, io_of_addr);
377*4882a593Smuzhiyun 		if (io_addr != OF_BAD_ADDR) {
378*4882a593Smuzhiyun 			par->cmap_adr = ioremap(io_addr + 0x3c8, 2);
379*4882a593Smuzhiyun 			if (par->cmap_adr) {
380*4882a593Smuzhiyun 				par->cmap_type = cmap_simple;
381*4882a593Smuzhiyun 				par->cmap_data = par->cmap_adr + 1;
382*4882a593Smuzhiyun 			}
383*4882a593Smuzhiyun 		}
384*4882a593Smuzhiyun 	}
385*4882a593Smuzhiyun 	info->fix.visual = (par->cmap_type != cmap_unknown) ?
386*4882a593Smuzhiyun 		FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
387*4882a593Smuzhiyun }
388*4882a593Smuzhiyun 
offb_init_fb(const char * name,int width,int height,int depth,int pitch,unsigned long address,int foreign_endian,struct device_node * dp)389*4882a593Smuzhiyun static void __init offb_init_fb(const char *name,
390*4882a593Smuzhiyun 				int width, int height, int depth,
391*4882a593Smuzhiyun 				int pitch, unsigned long address,
392*4882a593Smuzhiyun 				int foreign_endian, struct device_node *dp)
393*4882a593Smuzhiyun {
394*4882a593Smuzhiyun 	unsigned long res_size = pitch * height;
395*4882a593Smuzhiyun 	struct offb_par *par = &default_par;
396*4882a593Smuzhiyun 	unsigned long res_start = address;
397*4882a593Smuzhiyun 	struct fb_fix_screeninfo *fix;
398*4882a593Smuzhiyun 	struct fb_var_screeninfo *var;
399*4882a593Smuzhiyun 	struct fb_info *info;
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun 	if (!request_mem_region(res_start, res_size, "offb"))
402*4882a593Smuzhiyun 		return;
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun 	printk(KERN_INFO
405*4882a593Smuzhiyun 	       "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d\n",
406*4882a593Smuzhiyun 	       width, height, name, address, depth, pitch);
407*4882a593Smuzhiyun 	if (depth != 8 && depth != 15 && depth != 16 && depth != 32) {
408*4882a593Smuzhiyun 		printk(KERN_ERR "%pOF: can't use depth = %d\n", dp, depth);
409*4882a593Smuzhiyun 		release_mem_region(res_start, res_size);
410*4882a593Smuzhiyun 		return;
411*4882a593Smuzhiyun 	}
412*4882a593Smuzhiyun 
413*4882a593Smuzhiyun 	info = framebuffer_alloc(sizeof(u32) * 16, NULL);
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun 	if (info == 0) {
416*4882a593Smuzhiyun 		release_mem_region(res_start, res_size);
417*4882a593Smuzhiyun 		return;
418*4882a593Smuzhiyun 	}
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun 	fix = &info->fix;
421*4882a593Smuzhiyun 	var = &info->var;
422*4882a593Smuzhiyun 	info->par = par;
423*4882a593Smuzhiyun 
424*4882a593Smuzhiyun 	if (name) {
425*4882a593Smuzhiyun 		strcpy(fix->id, "OFfb ");
426*4882a593Smuzhiyun 		strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb "));
427*4882a593Smuzhiyun 		fix->id[sizeof(fix->id) - 1] = '\0';
428*4882a593Smuzhiyun 	} else
429*4882a593Smuzhiyun 		snprintf(fix->id, sizeof(fix->id), "OFfb %pOFn", dp);
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 
432*4882a593Smuzhiyun 	var->xres = var->xres_virtual = width;
433*4882a593Smuzhiyun 	var->yres = var->yres_virtual = height;
434*4882a593Smuzhiyun 	fix->line_length = pitch;
435*4882a593Smuzhiyun 
436*4882a593Smuzhiyun 	fix->smem_start = address;
437*4882a593Smuzhiyun 	fix->smem_len = pitch * height;
438*4882a593Smuzhiyun 	fix->type = FB_TYPE_PACKED_PIXELS;
439*4882a593Smuzhiyun 	fix->type_aux = 0;
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun 	par->cmap_type = cmap_unknown;
442*4882a593Smuzhiyun 	if (depth == 8)
443*4882a593Smuzhiyun 		offb_init_palette_hacks(info, dp, address);
444*4882a593Smuzhiyun 	else
445*4882a593Smuzhiyun 		fix->visual = FB_VISUAL_TRUECOLOR;
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun 	var->xoffset = var->yoffset = 0;
448*4882a593Smuzhiyun 	switch (depth) {
449*4882a593Smuzhiyun 	case 8:
450*4882a593Smuzhiyun 		var->bits_per_pixel = 8;
451*4882a593Smuzhiyun 		var->red.offset = 0;
452*4882a593Smuzhiyun 		var->red.length = 8;
453*4882a593Smuzhiyun 		var->green.offset = 0;
454*4882a593Smuzhiyun 		var->green.length = 8;
455*4882a593Smuzhiyun 		var->blue.offset = 0;
456*4882a593Smuzhiyun 		var->blue.length = 8;
457*4882a593Smuzhiyun 		var->transp.offset = 0;
458*4882a593Smuzhiyun 		var->transp.length = 0;
459*4882a593Smuzhiyun 		break;
460*4882a593Smuzhiyun 	case 15:		/* RGB 555 */
461*4882a593Smuzhiyun 		var->bits_per_pixel = 16;
462*4882a593Smuzhiyun 		var->red.offset = 10;
463*4882a593Smuzhiyun 		var->red.length = 5;
464*4882a593Smuzhiyun 		var->green.offset = 5;
465*4882a593Smuzhiyun 		var->green.length = 5;
466*4882a593Smuzhiyun 		var->blue.offset = 0;
467*4882a593Smuzhiyun 		var->blue.length = 5;
468*4882a593Smuzhiyun 		var->transp.offset = 0;
469*4882a593Smuzhiyun 		var->transp.length = 0;
470*4882a593Smuzhiyun 		break;
471*4882a593Smuzhiyun 	case 16:		/* RGB 565 */
472*4882a593Smuzhiyun 		var->bits_per_pixel = 16;
473*4882a593Smuzhiyun 		var->red.offset = 11;
474*4882a593Smuzhiyun 		var->red.length = 5;
475*4882a593Smuzhiyun 		var->green.offset = 5;
476*4882a593Smuzhiyun 		var->green.length = 6;
477*4882a593Smuzhiyun 		var->blue.offset = 0;
478*4882a593Smuzhiyun 		var->blue.length = 5;
479*4882a593Smuzhiyun 		var->transp.offset = 0;
480*4882a593Smuzhiyun 		var->transp.length = 0;
481*4882a593Smuzhiyun 		break;
482*4882a593Smuzhiyun 	case 32:		/* RGB 888 */
483*4882a593Smuzhiyun 		var->bits_per_pixel = 32;
484*4882a593Smuzhiyun 		var->red.offset = 16;
485*4882a593Smuzhiyun 		var->red.length = 8;
486*4882a593Smuzhiyun 		var->green.offset = 8;
487*4882a593Smuzhiyun 		var->green.length = 8;
488*4882a593Smuzhiyun 		var->blue.offset = 0;
489*4882a593Smuzhiyun 		var->blue.length = 8;
490*4882a593Smuzhiyun 		var->transp.offset = 24;
491*4882a593Smuzhiyun 		var->transp.length = 8;
492*4882a593Smuzhiyun 		break;
493*4882a593Smuzhiyun 	}
494*4882a593Smuzhiyun 	var->red.msb_right = var->green.msb_right = var->blue.msb_right =
495*4882a593Smuzhiyun 	    var->transp.msb_right = 0;
496*4882a593Smuzhiyun 	var->grayscale = 0;
497*4882a593Smuzhiyun 	var->nonstd = 0;
498*4882a593Smuzhiyun 	var->activate = 0;
499*4882a593Smuzhiyun 	var->height = var->width = -1;
500*4882a593Smuzhiyun 	var->pixclock = 10000;
501*4882a593Smuzhiyun 	var->left_margin = var->right_margin = 16;
502*4882a593Smuzhiyun 	var->upper_margin = var->lower_margin = 16;
503*4882a593Smuzhiyun 	var->hsync_len = var->vsync_len = 8;
504*4882a593Smuzhiyun 	var->sync = 0;
505*4882a593Smuzhiyun 	var->vmode = FB_VMODE_NONINTERLACED;
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun 	/* set offb aperture size for generic probing */
508*4882a593Smuzhiyun 	info->apertures = alloc_apertures(1);
509*4882a593Smuzhiyun 	if (!info->apertures)
510*4882a593Smuzhiyun 		goto out_aper;
511*4882a593Smuzhiyun 	info->apertures->ranges[0].base = address;
512*4882a593Smuzhiyun 	info->apertures->ranges[0].size = fix->smem_len;
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun 	info->fbops = &offb_ops;
515*4882a593Smuzhiyun 	info->screen_base = ioremap(address, fix->smem_len);
516*4882a593Smuzhiyun 	info->pseudo_palette = (void *) (info + 1);
517*4882a593Smuzhiyun 	info->flags = FBINFO_DEFAULT | FBINFO_MISC_FIRMWARE | foreign_endian;
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun 	fb_alloc_cmap(&info->cmap, 256, 0);
520*4882a593Smuzhiyun 
521*4882a593Smuzhiyun 	if (register_framebuffer(info) < 0)
522*4882a593Smuzhiyun 		goto out_err;
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun 	fb_info(info, "Open Firmware frame buffer device on %pOF\n", dp);
525*4882a593Smuzhiyun 	return;
526*4882a593Smuzhiyun 
527*4882a593Smuzhiyun out_err:
528*4882a593Smuzhiyun 	fb_dealloc_cmap(&info->cmap);
529*4882a593Smuzhiyun 	iounmap(info->screen_base);
530*4882a593Smuzhiyun out_aper:
531*4882a593Smuzhiyun 	iounmap(par->cmap_adr);
532*4882a593Smuzhiyun 	par->cmap_adr = NULL;
533*4882a593Smuzhiyun 	framebuffer_release(info);
534*4882a593Smuzhiyun 	release_mem_region(res_start, res_size);
535*4882a593Smuzhiyun }
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun 
offb_init_nodriver(struct device_node * dp,int no_real_node)538*4882a593Smuzhiyun static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
539*4882a593Smuzhiyun {
540*4882a593Smuzhiyun 	unsigned int len;
541*4882a593Smuzhiyun 	int i, width = 640, height = 480, depth = 8, pitch = 640;
542*4882a593Smuzhiyun 	unsigned int flags, rsize, addr_prop = 0;
543*4882a593Smuzhiyun 	unsigned long max_size = 0;
544*4882a593Smuzhiyun 	u64 rstart, address = OF_BAD_ADDR;
545*4882a593Smuzhiyun 	const __be32 *pp, *addrp, *up;
546*4882a593Smuzhiyun 	u64 asize;
547*4882a593Smuzhiyun 	int foreign_endian = 0;
548*4882a593Smuzhiyun 
549*4882a593Smuzhiyun #ifdef __BIG_ENDIAN
550*4882a593Smuzhiyun 	if (of_get_property(dp, "little-endian", NULL))
551*4882a593Smuzhiyun 		foreign_endian = FBINFO_FOREIGN_ENDIAN;
552*4882a593Smuzhiyun #else
553*4882a593Smuzhiyun 	if (of_get_property(dp, "big-endian", NULL))
554*4882a593Smuzhiyun 		foreign_endian = FBINFO_FOREIGN_ENDIAN;
555*4882a593Smuzhiyun #endif
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun 	pp = of_get_property(dp, "linux,bootx-depth", &len);
558*4882a593Smuzhiyun 	if (pp == NULL)
559*4882a593Smuzhiyun 		pp = of_get_property(dp, "depth", &len);
560*4882a593Smuzhiyun 	if (pp && len == sizeof(u32))
561*4882a593Smuzhiyun 		depth = be32_to_cpup(pp);
562*4882a593Smuzhiyun 
563*4882a593Smuzhiyun 	pp = of_get_property(dp, "linux,bootx-width", &len);
564*4882a593Smuzhiyun 	if (pp == NULL)
565*4882a593Smuzhiyun 		pp = of_get_property(dp, "width", &len);
566*4882a593Smuzhiyun 	if (pp && len == sizeof(u32))
567*4882a593Smuzhiyun 		width = be32_to_cpup(pp);
568*4882a593Smuzhiyun 
569*4882a593Smuzhiyun 	pp = of_get_property(dp, "linux,bootx-height", &len);
570*4882a593Smuzhiyun 	if (pp == NULL)
571*4882a593Smuzhiyun 		pp = of_get_property(dp, "height", &len);
572*4882a593Smuzhiyun 	if (pp && len == sizeof(u32))
573*4882a593Smuzhiyun 		height = be32_to_cpup(pp);
574*4882a593Smuzhiyun 
575*4882a593Smuzhiyun 	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
576*4882a593Smuzhiyun 	if (pp == NULL)
577*4882a593Smuzhiyun 		pp = of_get_property(dp, "linebytes", &len);
578*4882a593Smuzhiyun 	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
579*4882a593Smuzhiyun 		pitch = be32_to_cpup(pp);
580*4882a593Smuzhiyun 	else
581*4882a593Smuzhiyun 		pitch = width * ((depth + 7) / 8);
582*4882a593Smuzhiyun 
583*4882a593Smuzhiyun 	rsize = (unsigned long)pitch * (unsigned long)height;
584*4882a593Smuzhiyun 
585*4882a593Smuzhiyun 	/* Ok, now we try to figure out the address of the framebuffer.
586*4882a593Smuzhiyun 	 *
587*4882a593Smuzhiyun 	 * Unfortunately, Open Firmware doesn't provide a standard way to do
588*4882a593Smuzhiyun 	 * so. All we can do is a dodgy heuristic that happens to work in
589*4882a593Smuzhiyun 	 * practice. On most machines, the "address" property contains what
590*4882a593Smuzhiyun 	 * we need, though not on Matrox cards found in IBM machines. What I've
591*4882a593Smuzhiyun 	 * found that appears to give good results is to go through the PCI
592*4882a593Smuzhiyun 	 * ranges and pick one that is both big enough and if possible encloses
593*4882a593Smuzhiyun 	 * the "address" property. If none match, we pick the biggest
594*4882a593Smuzhiyun 	 */
595*4882a593Smuzhiyun 	up = of_get_property(dp, "linux,bootx-addr", &len);
596*4882a593Smuzhiyun 	if (up == NULL)
597*4882a593Smuzhiyun 		up = of_get_property(dp, "address", &len);
598*4882a593Smuzhiyun 	if (up && len == sizeof(u32))
599*4882a593Smuzhiyun 		addr_prop = *up;
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	/* Hack for when BootX is passing us */
602*4882a593Smuzhiyun 	if (no_real_node)
603*4882a593Smuzhiyun 		goto skip_addr;
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun 	for (i = 0; (addrp = of_get_address(dp, i, &asize, &flags))
606*4882a593Smuzhiyun 		     != NULL; i++) {
607*4882a593Smuzhiyun 		int match_addrp = 0;
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun 		if (!(flags & IORESOURCE_MEM))
610*4882a593Smuzhiyun 			continue;
611*4882a593Smuzhiyun 		if (asize < rsize)
612*4882a593Smuzhiyun 			continue;
613*4882a593Smuzhiyun 		rstart = of_translate_address(dp, addrp);
614*4882a593Smuzhiyun 		if (rstart == OF_BAD_ADDR)
615*4882a593Smuzhiyun 			continue;
616*4882a593Smuzhiyun 		if (addr_prop && (rstart <= addr_prop) &&
617*4882a593Smuzhiyun 		    ((rstart + asize) >= (addr_prop + rsize)))
618*4882a593Smuzhiyun 			match_addrp = 1;
619*4882a593Smuzhiyun 		if (match_addrp) {
620*4882a593Smuzhiyun 			address = addr_prop;
621*4882a593Smuzhiyun 			break;
622*4882a593Smuzhiyun 		}
623*4882a593Smuzhiyun 		if (rsize > max_size) {
624*4882a593Smuzhiyun 			max_size = rsize;
625*4882a593Smuzhiyun 			address = OF_BAD_ADDR;
626*4882a593Smuzhiyun  		}
627*4882a593Smuzhiyun 
628*4882a593Smuzhiyun 		if (address == OF_BAD_ADDR)
629*4882a593Smuzhiyun 			address = rstart;
630*4882a593Smuzhiyun 	}
631*4882a593Smuzhiyun  skip_addr:
632*4882a593Smuzhiyun 	if (address == OF_BAD_ADDR && addr_prop)
633*4882a593Smuzhiyun 		address = (u64)addr_prop;
634*4882a593Smuzhiyun 	if (address != OF_BAD_ADDR) {
635*4882a593Smuzhiyun #ifdef CONFIG_PCI
636*4882a593Smuzhiyun 		const __be32 *vidp, *didp;
637*4882a593Smuzhiyun 		u32 vid, did;
638*4882a593Smuzhiyun 		struct pci_dev *pdev;
639*4882a593Smuzhiyun 
640*4882a593Smuzhiyun 		vidp = of_get_property(dp, "vendor-id", NULL);
641*4882a593Smuzhiyun 		didp = of_get_property(dp, "device-id", NULL);
642*4882a593Smuzhiyun 		if (vidp && didp) {
643*4882a593Smuzhiyun 			vid = be32_to_cpup(vidp);
644*4882a593Smuzhiyun 			did = be32_to_cpup(didp);
645*4882a593Smuzhiyun 			pdev = pci_get_device(vid, did, NULL);
646*4882a593Smuzhiyun 			if (!pdev || pci_enable_device(pdev))
647*4882a593Smuzhiyun 				return;
648*4882a593Smuzhiyun 		}
649*4882a593Smuzhiyun #endif
650*4882a593Smuzhiyun 		/* kludge for valkyrie */
651*4882a593Smuzhiyun 		if (of_node_name_eq(dp, "valkyrie"))
652*4882a593Smuzhiyun 			address += 0x1000;
653*4882a593Smuzhiyun 		offb_init_fb(no_real_node ? "bootx" : NULL,
654*4882a593Smuzhiyun 			     width, height, depth, pitch, address,
655*4882a593Smuzhiyun 			     foreign_endian, no_real_node ? NULL : dp);
656*4882a593Smuzhiyun 	}
657*4882a593Smuzhiyun }
658*4882a593Smuzhiyun 
offb_init(void)659*4882a593Smuzhiyun static int __init offb_init(void)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun 	struct device_node *dp = NULL, *boot_disp = NULL;
662*4882a593Smuzhiyun 
663*4882a593Smuzhiyun 	if (fb_get_options("offb", NULL))
664*4882a593Smuzhiyun 		return -ENODEV;
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun 	/* Check if we have a MacOS display without a node spec */
667*4882a593Smuzhiyun 	if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) {
668*4882a593Smuzhiyun 		/* The old code tried to work out which node was the MacOS
669*4882a593Smuzhiyun 		 * display based on the address. I'm dropping that since the
670*4882a593Smuzhiyun 		 * lack of a node spec only happens with old BootX versions
671*4882a593Smuzhiyun 		 * (users can update) and with this code, they'll still get
672*4882a593Smuzhiyun 		 * a display (just not the palette hacks).
673*4882a593Smuzhiyun 		 */
674*4882a593Smuzhiyun 		offb_init_nodriver(of_chosen, 1);
675*4882a593Smuzhiyun 	}
676*4882a593Smuzhiyun 
677*4882a593Smuzhiyun 	for_each_node_by_type(dp, "display") {
678*4882a593Smuzhiyun 		if (of_get_property(dp, "linux,opened", NULL) &&
679*4882a593Smuzhiyun 		    of_get_property(dp, "linux,boot-display", NULL)) {
680*4882a593Smuzhiyun 			boot_disp = dp;
681*4882a593Smuzhiyun 			offb_init_nodriver(dp, 0);
682*4882a593Smuzhiyun 		}
683*4882a593Smuzhiyun 	}
684*4882a593Smuzhiyun 	for_each_node_by_type(dp, "display") {
685*4882a593Smuzhiyun 		if (of_get_property(dp, "linux,opened", NULL) &&
686*4882a593Smuzhiyun 		    dp != boot_disp)
687*4882a593Smuzhiyun 			offb_init_nodriver(dp, 0);
688*4882a593Smuzhiyun 	}
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun 	return 0;
691*4882a593Smuzhiyun }
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun 
694*4882a593Smuzhiyun module_init(offb_init);
695*4882a593Smuzhiyun MODULE_LICENSE("GPL");
696