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