Blame view

drivers/video/offb.c 14.5 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
  /*
   *  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.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
17
18
  #include <linux/module.h>
  #include <linux/kernel.h>
  #include <linux/errno.h>
  #include <linux/string.h>
  #include <linux/mm.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
23
24
25
  #include <linux/slab.h>
  #include <linux/vmalloc.h>
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/fb.h>
  #include <linux/init.h>
  #include <linux/ioport.h>
f365cfd0d   Paul Mackerras   offb: Fix compile...
26
  #include <linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  #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
  
  #include "macmodes.h"
  
  /* Supported palette hacks */
  enum {
  	cmap_unknown,
  	cmap_m64,		/* ATI Mach64 */
  	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 */
  };
  
  struct offb_par {
  	volatile void __iomem *cmap_adr;
  	volatile void __iomem *cmap_data;
  	int cmap_type;
  	int blanked;
  };
  
  struct offb_par default_par;
  
      /*
       *  Interface used by the world
       */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
66
67
68
69
  static int offb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
  			  u_int transp, struct fb_info *info);
  static int offb_blank(int blank, struct fb_info *info);
  
  #ifdef CONFIG_PPC32
  extern boot_infos_t *boot_infos;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
71
72
73
74
75
76
  static struct fb_ops offb_ops = {
  	.owner		= THIS_MODULE,
  	.fb_setcolreg	= offb_setcolreg,
  	.fb_blank	= offb_blank,
  	.fb_fillrect	= cfb_fillrect,
  	.fb_copyarea	= cfb_copyarea,
  	.fb_imageblit	= cfb_imageblit,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
77
78
79
80
81
82
83
84
85
86
87
88
  };
  
      /*
       *  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;
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
89
90
  	int i, depth;
  	u32 *pal = info->pseudo_palette;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91

ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
92
93
94
95
96
97
98
  	depth = info->var.bits_per_pixel;
  	if (depth == 16)
  		depth = (info->var.green.length == 5) ? 15 : 16;
  
  	if (regno > 255 ||
  	    (depth == 16 && regno > 63) ||
  	    (depth == 15 && regno > 31))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
  		return 1;
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
  	if (regno < 16) {
  		switch (depth) {
  		case 15:
  			pal[regno] = (regno << 10) | (regno << 5) | regno;
  			break;
  		case 16:
  			pal[regno] = (regno << 11) | (regno << 5) | regno;
  			break;
  		case 24:
  			pal[regno] = (regno << 16) | (regno << 8) | regno;
  			break;
  		case 32:
  			i = (regno << 8) | regno;
  			pal[regno] = (i << 16) | i;
  			break;
  		}
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
  	red >>= 8;
  	green >>= 8;
  	blue >>= 8;
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
120
121
  	if (!par->cmap_adr)
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  	switch (par->cmap_type) {
  	case cmap_m64:
  		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);
  	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:
441cbd8da   Benjamin Herrenschmidt   [POWERPC] Fix var...
153
  		out_le32(((unsigned __iomem *) par->cmap_adr) + regno,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154
155
156
  			 (red << 16 | green << 8 | blue));
  		break;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
  	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) {
  			case cmap_m64:
  				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);
  			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:
441cbd8da   Benjamin Herrenschmidt   [POWERPC] Fix var...
208
  				out_le32(((unsigned __iomem *) par->cmap_adr) + i,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
209
210
211
212
213
214
215
  					 0);
  				break;
  			}
  	} else
  		fb_set_cmap(&info->cmap, info);
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216

73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
217
218
  static void __iomem *offb_map_reg(struct device_node *np, int index,
  				  unsigned long offset, unsigned long size)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
  {
441cbd8da   Benjamin Herrenschmidt   [POWERPC] Fix var...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  	const u32 *addrp;
  	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);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
239
240
241
  }
  
  static void __init offb_init_fb(const char *name, const char *full_name,
  				int width, int height, int depth,
  				int pitch, unsigned long address,
7f29b87a7   Anton Vorontsov   powerpc: offb: ad...
242
  				int foreign_endian, struct device_node *dp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
243
  {
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
244
  	unsigned long res_size = pitch * height * (depth + 7) / 8;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
246
247
248
249
250
251
252
253
254
255
256
257
258
  	struct offb_par *par = &default_par;
  	unsigned long res_start = address;
  	struct fb_fix_screeninfo *fix;
  	struct fb_var_screeninfo *var;
  	struct fb_info *info;
  	int size;
  
  	if (!request_mem_region(res_start, res_size, "offb"))
  		return;
  
  	printk(KERN_INFO
  	       "Using unsupported %dx%d %s at %lx, depth=%d, pitch=%d
  ",
  	       width, height, name, address, depth, pitch);
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
259
  	if (depth != 8 && depth != 15 && depth != 16 && depth != 32) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
261
262
263
264
265
  		printk(KERN_ERR "%s: can't use depth = %d
  ", full_name,
  		       depth);
  		release_mem_region(res_start, res_size);
  		return;
  	}
d01184c8d   Antonino A. Daplas   offb: the pseudo_...
266
  	size = sizeof(struct fb_info) + sizeof(u32) * 16;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
  
  	info = kmalloc(size, GFP_ATOMIC);
  	
  	if (info == 0) {
  		release_mem_region(res_start, res_size);
  		return;
  	}
  	memset(info, 0, size);
  
  	fix = &info->fix;
  	var = &info->var;
  
  	strcpy(fix->id, "OFfb ");
  	strncat(fix->id, name, sizeof(fix->id) - sizeof("OFfb "));
  	fix->id[sizeof(fix->id) - 1] = '\0';
  
  	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;
  	if (depth == 8) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
294
  		if (dp && !strncmp(name, "ATY,Rage128", 11)) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
295
296
297
  			par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
  			if (par->cmap_adr)
  				par->cmap_type = cmap_r128;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
  		} else if (dp && (!strncmp(name, "ATY,RageM3pA", 12)
  				  || !strncmp(name, "ATY,RageM3p12A", 14))) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
300
301
302
  			par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
  			if (par->cmap_adr)
  				par->cmap_type = cmap_M3A;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
303
  		} else if (dp && !strncmp(name, "ATY,RageM3pB", 12)) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
304
305
306
  			par->cmap_adr = offb_map_reg(dp, 2, 0, 0x1fff);
  			if (par->cmap_adr)
  				par->cmap_type = cmap_M3B;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
  		} else if (dp && !strncmp(name, "ATY,Rage6", 9)) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
308
309
310
  			par->cmap_adr = offb_map_reg(dp, 1, 0, 0x1fff);
  			if (par->cmap_adr)
  				par->cmap_type = cmap_radeon;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
312
313
314
315
316
  		} else if (!strncmp(name, "ATY,", 4)) {
  			unsigned long base = address & 0xff000000UL;
  			par->cmap_adr =
  			    ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
  			par->cmap_data = par->cmap_adr + 1;
  			par->cmap_type = cmap_m64;
55b61fec2   Stephen Rothwell   [POWERPC] Rename ...
317
318
  		} else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
  				  of_device_is_compatible(dp, "pci1014,21c"))) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
319
320
321
  			par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
  			if (par->cmap_adr)
  				par->cmap_type = cmap_gxt2000;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
322
  		}
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
323
324
  		fix->visual = (par->cmap_type != cmap_unknown) ?
  			FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_STATIC_PSEUDOCOLOR;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325
  	} else
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
326
  		fix->visual = FB_VISUAL_TRUECOLOR;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
327
328
  
  	var->xoffset = var->yoffset = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
330
331
332
333
334
335
336
337
338
339
340
  	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;
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
341
  	case 15:		/* RGB 555 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
342
343
344
345
346
347
348
349
350
351
  		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;
ab1344661   Benjamin Herrenschmidt   [POWERPC] Fix var...
352
353
354
355
356
357
358
359
360
361
362
  	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;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
  	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;
  
  	info->fbops = &offb_ops;
  	info->screen_base = ioremap(address, fix->smem_len);
  	info->par = par;
  	info->pseudo_palette = (void *) (info + 1);
7f29b87a7   Anton Vorontsov   powerpc: offb: ad...
392
  	info->flags = FBINFO_DEFAULT | foreign_endian;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
394
395
396
  
  	fb_alloc_cmap(&info->cmap, 256, 0);
  
  	if (register_framebuffer(info) < 0) {
f190017b8   Amol Lad   [PATCH] ioremap b...
397
398
399
  		iounmap(par->cmap_adr);
  		par->cmap_adr = NULL;
  		iounmap(info->screen_base);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
402
403
404
405
406
407
408
  		kfree(info);
  		release_mem_region(res_start, res_size);
  		return;
  	}
  
  	printk(KERN_INFO "fb%d: Open Firmware frame buffer device on %s
  ",
  	       info->node, full_name);
  }
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
409
410
411
412
413
414
415
416
  
  static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
  {
  	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;
b04e3dd4a   Jeremy Kerr   [POWERPC] video &...
417
  	const u32 *pp, *addrp, *up;
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
418
  	u64 asize;
7f29b87a7   Anton Vorontsov   powerpc: offb: ad...
419
420
421
422
423
424
425
426
427
  	int foreign_endian = 0;
  
  #ifdef __BIG_ENDIAN
  	if (of_get_property(dp, "little-endian", NULL))
  		foreign_endian = FBINFO_FOREIGN_ENDIAN;
  #else
  	if (of_get_property(dp, "big-endian", NULL))
  		foreign_endian = FBINFO_FOREIGN_ENDIAN;
  #endif
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
428

40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
429
  	pp = of_get_property(dp, "linux,bootx-depth", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
430
  	if (pp == NULL)
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
431
  		pp = of_get_property(dp, "depth", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
432
433
  	if (pp && len == sizeof(u32))
  		depth = *pp;
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
434
  	pp = of_get_property(dp, "linux,bootx-width", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
435
  	if (pp == NULL)
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
436
  		pp = of_get_property(dp, "width", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
437
438
  	if (pp && len == sizeof(u32))
  		width = *pp;
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
439
  	pp = of_get_property(dp, "linux,bootx-height", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
440
  	if (pp == NULL)
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
441
  		pp = of_get_property(dp, "height", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
442
443
  	if (pp && len == sizeof(u32))
  		height = *pp;
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
444
  	pp = of_get_property(dp, "linux,bootx-linebytes", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
445
  	if (pp == NULL)
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
446
  		pp = of_get_property(dp, "linebytes", &len);
441cbd8da   Benjamin Herrenschmidt   [POWERPC] Fix var...
447
  	if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
  		pitch = *pp;
  	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
  	 */
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
464
  	up = of_get_property(dp, "linux,bootx-addr", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
465
  	if (up == NULL)
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
466
  		up = of_get_property(dp, "address", &len);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
  	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) {
  		/* kludge for valkyrie */
  		if (strcmp(dp->name, "valkyrie") == 0)
  			address += 0x1000;
  		offb_init_fb(no_real_node ? "bootx" : dp->name,
  			     no_real_node ? "display" : dp->full_name,
  			     width, height, depth, pitch, address,
7f29b87a7   Anton Vorontsov   powerpc: offb: ad...
510
  			     foreign_endian, no_real_node ? NULL : dp);
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
511
512
513
514
515
516
517
518
519
520
521
  	}
  }
  
  static int __init offb_init(void)
  {
  	struct device_node *dp = NULL, *boot_disp = NULL;
  
  	if (fb_get_options("offb", NULL))
  		return -ENODEV;
  
  	/* Check if we have a MacOS display without a node spec */
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
522
  	if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
523
524
525
526
527
528
529
530
531
532
  		/* The old code tried to work out which node was the MacOS
  		 * display based on the address. I'm dropping that since the
  		 * lack of a node spec only happens with old BootX versions
  		 * (users can update) and with this code, they'll still get
  		 * a display (just not the palette hacks).
  		 */
  		offb_init_nodriver(of_chosen, 1);
  	}
  
  	for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
533
534
  		if (of_get_property(dp, "linux,opened", NULL) &&
  		    of_get_property(dp, "linux,boot-display", NULL)) {
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
535
536
537
538
539
  			boot_disp = dp;
  			offb_init_nodriver(dp, 0);
  		}
  	}
  	for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
40cd3a456   Stephen Rothwell   [POWERPC] Rename ...
540
  		if (of_get_property(dp, "linux,opened", NULL) &&
73ea6959b   Benjamin Herrenschmidt   [POWERPC] More of...
541
542
543
544
545
546
  		    dp != boot_disp)
  			offb_init_nodriver(dp, 0);
  	}
  
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
547
548
  module_init(offb_init);
  MODULE_LICENSE("GPL");