2 * linux/drivers/video/acornfb.c
4 * Copyright (C) 1998-2000 Russell King
6 * Frame buffer code for Acorn platforms
8 * NOTE: Most of the modes with X!=640 will disappear shortly.
9 * NOTE: Startup setting of HS & VS polarity not supported.
10 * (do we need to support it if we're coming up in 640x480?)
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/sched.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/ctype.h>
21 #include <linux/tty.h>
22 #include <linux/malloc.h>
23 #include <linux/init.h>
26 #include <asm/hardware.h>
29 #include <asm/uaccess.h>
31 #include <video/fbcon.h>
32 #include <video/fbcon-mfb.h>
33 #include <video/fbcon-cfb2.h>
34 #include <video/fbcon-cfb4.h>
35 #include <video/fbcon-cfb8.h>
36 #include <video/fbcon-cfb16.h>
37 #include <video/fbcon-cfb32.h>
43 * NOTE that it has to be supported in the table towards
44 * the end of this file.
46 #define DEFAULT_XRES 640
47 #define DEFAULT_YRES 480
49 * The order here defines which BPP we
50 * pick depending on which resolutions
53 #if defined(FBCON_HAS_CFB4)
54 # define DEFAULT_BPP 4
55 #elif defined(FBCON_HAS_CFB8)
56 # define DEFAULT_BPP 8
57 #elif defined(FBCON_HAS_CFB16)
58 # define DEFAULT_BPP 16
59 #elif defined(FBCON_HAS_CFB2)
60 # define DEFAULT_BPP 2
61 #elif defined(FBCON_HAS_MFB)
62 # define DEFAULT_BPP 1
64 #error No suitable framebuffers configured
69 * define this to debug the video mode selection
71 #undef DEBUG_MODE_SELECTION
74 * Translation from RISC OS monitor types to actual
75 * HSYNC and VSYNC frequency ranges. These are
76 * probably not right, but they're the best info I
77 * have. Allow 1% either way on the nominal for TVs.
80 static struct fb_monspecs monspecs
[NR_MONTYPES
] __initdata
= {
81 { 15469, 15781, 49, 51, 0 }, /* TV */
82 { 0, 99999, 0, 99, 0 }, /* Multi Freq */
83 { 58608, 58608, 64, 64, 0 }, /* Hi-res mono */
84 { 30000, 70000, 60, 60, 0 }, /* VGA */
85 { 30000, 70000, 56, 75, 0 }, /* SVGA */
86 { 30000, 70000, 60, 60, 0 }
89 static struct display global_disp
;
90 static struct fb_info fb_info
;
91 static struct acornfb_par current_par
;
92 static struct vidc_timing current_vidc
;
93 static struct fb_var_screeninfo __initdata init_var
= {};
95 extern int acornfb_depth
; /* set by setup.c */
96 extern unsigned int vram_size
; /* set by setup.c */
114 static struct pixclock
{
120 /* we allow +/-1% on these */
121 { 123750, 126250, VIDC_CTRL_DIV3
, VID_CTL_24MHz
}, /* 8.000MHz */
122 { 82500, 84167, VIDC_CTRL_DIV2
, VID_CTL_24MHz
}, /* 12.000MHz */
123 { 61875, 63125, VIDC_CTRL_DIV1_5
, VID_CTL_24MHz
}, /* 16.000MHz */
124 { 41250, 42083, VIDC_CTRL_DIV1
, VID_CTL_24MHz
}, /* 24.000MHz */
125 #ifdef CONFIG_ARCH_A5K
126 { 117974, 120357, VIDC_CTRL_DIV3
, VID_CTL_25MHz
}, /* 8.392MHz */
127 { 78649, 80238, VIDC_CTRL_DIV2
, VID_CTL_25MHz
}, /* 12.588MHz */
128 { 58987, 60178, VIDC_CTRL_DIV1_5
, VID_CTL_25MHz
}, /* 16.588MHz */
129 { 55000, 56111, VIDC_CTRL_DIV2
, VID_CTL_36MHz
}, /* 18.000MHz */
130 { 39325, 40119, VIDC_CTRL_DIV1
, VID_CTL_25MHz
}, /* 25.175MHz */
131 { 27500, 28055, VIDC_CTRL_DIV1
, VID_CTL_36MHz
}, /* 36.000MHz */
136 static struct pixclock
*
137 acornfb_valid_pixrate(u_long pixclock
)
141 for (i
= 0; pixclocks
[i
].min_clock
; i
++)
142 if (pixclock
> pixclocks
[i
].min_clock
&&
143 pixclock
< pixclocks
[i
].max_clock
)
144 return pixclocks
+ i
;
150 * hcr : must be even (interlace, hcr/2 must be even)
151 * hswr : must be even
159 * if interlaced, then hcr/2 must be even
162 acornfb_set_timing(struct fb_var_screeninfo
*var
)
164 struct pixclock
*pclk
;
165 struct vidc_timing vidc
;
166 u_int horiz_correction
;
167 u_int sync_len
, display_start
, display_end
, cycle
;
169 u_int vid_ctl
, vidc_ctl
;
172 memset(&vidc
, 0, sizeof(vidc
));
174 pclk
= acornfb_valid_pixrate(var
->pixclock
);
175 vidc_ctl
= pclk
->vidc_ctl
;
176 vid_ctl
= pclk
->vid_ctl
;
178 bandwidth
= var
->pixclock
* 8 / var
->bits_per_pixel
;
179 /* 25.175, 4bpp = 79.444ns per byte, 317.776ns per word: fifo = 2,6 */
180 if (bandwidth
> 143500)
181 vidc_ctl
|= VIDC_CTRL_FIFO_3_7
;
182 else if (bandwidth
> 71750)
183 vidc_ctl
|= VIDC_CTRL_FIFO_2_6
;
184 else if (bandwidth
> 35875)
185 vidc_ctl
|= VIDC_CTRL_FIFO_1_5
;
187 vidc_ctl
|= VIDC_CTRL_FIFO_0_4
;
189 switch (var
->bits_per_pixel
) {
191 horiz_correction
= 19;
192 vidc_ctl
|= VIDC_CTRL_1BPP
;
196 horiz_correction
= 11;
197 vidc_ctl
|= VIDC_CTRL_2BPP
;
201 horiz_correction
= 7;
202 vidc_ctl
|= VIDC_CTRL_4BPP
;
207 horiz_correction
= 5;
208 vidc_ctl
|= VIDC_CTRL_8BPP
;
212 if (!(var
->sync
& FB_SYNC_HOR_HIGH_ACT
))
213 vid_ctl
|= VID_CTL_HS_NHSYNC
;
215 if (!(var
->sync
& FB_SYNC_VERT_HIGH_ACT
))
216 vid_ctl
|= VID_CTL_VS_NVSYNC
;
218 sync_len
= var
->hsync_len
;
219 display_start
= sync_len
+ var
->left_margin
;
220 display_end
= display_start
+ var
->xres
;
221 cycle
= display_end
+ var
->right_margin
;
223 /* if interlaced, then hcr/2 must be even */
224 is_interlaced
= (var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
;
227 vidc_ctl
|= VIDC_CTRL_INTERLACE
;
230 var
->right_margin
+= 2;
234 vidc
.h_cycle
= (cycle
- 2) / 2;
235 vidc
.h_sync_width
= (sync_len
- 2) / 2;
236 vidc
.h_border_start
= (display_start
- 1) / 2;
237 vidc
.h_display_start
= (display_start
- horiz_correction
) / 2;
238 vidc
.h_display_end
= (display_end
- horiz_correction
) / 2;
239 vidc
.h_border_end
= (display_end
- 1) / 2;
240 vidc
.h_interlace
= (vidc
.h_cycle
+ 1) / 2;
242 sync_len
= var
->vsync_len
;
243 display_start
= sync_len
+ var
->upper_margin
;
244 display_end
= display_start
+ var
->yres
;
245 cycle
= display_end
+ var
->lower_margin
;
248 cycle
= (cycle
- 3) / 2;
252 vidc
.v_cycle
= cycle
;
253 vidc
.v_sync_width
= sync_len
- 1;
254 vidc
.v_border_start
= display_start
- 1;
255 vidc
.v_display_start
= vidc
.v_border_start
;
256 vidc
.v_display_end
= display_end
- 1;
257 vidc
.v_border_end
= vidc
.v_display_end
;
259 #ifdef CONFIG_ARCH_A5K
260 outb(vid_ctl
, IOEB_VID_CTL
);
262 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
265 outl(0xe0000000 | vidc_ctl
, IO_VIDC_BASE
);
266 outl(0x80000000 | (vidc
.h_cycle
<< 14), IO_VIDC_BASE
);
267 outl(0x84000000 | (vidc
.h_sync_width
<< 14), IO_VIDC_BASE
);
268 outl(0x88000000 | (vidc
.h_border_start
<< 14), IO_VIDC_BASE
);
269 outl(0x8c000000 | (vidc
.h_display_start
<< 14), IO_VIDC_BASE
);
270 outl(0x90000000 | (vidc
.h_display_end
<< 14), IO_VIDC_BASE
);
271 outl(0x94000000 | (vidc
.h_border_end
<< 14), IO_VIDC_BASE
);
272 outl(0x98000000, IO_VIDC_BASE
);
273 outl(0x9c000000 | (vidc
.h_interlace
<< 14), IO_VIDC_BASE
);
274 outl(0xa0000000 | (vidc
.v_cycle
<< 14), IO_VIDC_BASE
);
275 outl(0xa4000000 | (vidc
.v_sync_width
<< 14), IO_VIDC_BASE
);
276 outl(0xa8000000 | (vidc
.v_border_start
<< 14), IO_VIDC_BASE
);
277 outl(0xac000000 | (vidc
.v_display_start
<< 14), IO_VIDC_BASE
);
278 outl(0xb0000000 | (vidc
.v_display_end
<< 14), IO_VIDC_BASE
);
279 outl(0xb4000000 | (vidc
.v_border_end
<< 14), IO_VIDC_BASE
);
280 outl(0xb8000000, IO_VIDC_BASE
);
281 outl(0xbc000000, IO_VIDC_BASE
);
283 #ifdef DEBUG_MODE_SELECTION
284 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
285 var
->yres
, var
->bits_per_pixel
);
286 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
287 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
288 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
289 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
290 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
291 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
292 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
293 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
294 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
295 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
296 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
297 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
298 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
299 printk(KERN_DEBUG
" VIDC Ctrl (E) : 0x%08X\n", vidc_ctl
);
300 printk(KERN_DEBUG
" IOEB Ctrl : 0x%08X\n", vid_ctl
);
305 acornfb_palette_write(u_int regno
, union palette pal
)
307 outl(pal
.p
, IO_VIDC_BASE
);
310 static inline union palette
311 acornfb_palette_encode(u_int regno
, u_int red
, u_int green
, u_int blue
,
317 pal
.vidc
.reg
= regno
;
318 pal
.vidc
.red
= red
>> 12;
319 pal
.vidc
.green
= green
>> 12;
320 pal
.vidc
.blue
= blue
>> 12;
325 acornfb_palette_decode(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
328 *red
= EXTEND4(current_par
.palette
[regno
].vidc
.red
);
329 *green
= EXTEND4(current_par
.palette
[regno
].vidc
.green
);
330 *blue
= EXTEND4(current_par
.palette
[regno
].vidc
.blue
);
331 *trans
= current_par
.palette
[regno
].vidc
.trans
? -1 : 0;
336 #include <asm/arch/acornfb.h>
338 /* VIDC20 has a different set of rules from the VIDC:
339 * hcr : must be multiple of 4
340 * hswr : must be even
341 * hdsr : must be even
342 * hder : must be even
343 * vcr : >= 2, (interlace, must be odd)
349 acornfb_set_timing(struct fb_var_screeninfo
*var
)
351 struct vidc_timing vidc
;
353 u_int ext_ctl
, dat_ctl
;
354 u_int words_per_line
;
356 memset(&vidc
, 0, sizeof(vidc
));
358 vidc
.h_sync_width
= var
->hsync_len
- 8;
359 vidc
.h_border_start
= vidc
.h_sync_width
+ var
->left_margin
+ 8 - 12;
360 vidc
.h_display_start
= vidc
.h_border_start
+ 12 - 18;
361 vidc
.h_display_end
= vidc
.h_display_start
+ var
->xres
;
362 vidc
.h_border_end
= vidc
.h_display_end
+ 18 - 12;
363 vidc
.h_cycle
= vidc
.h_border_end
+ var
->right_margin
+ 12 - 8;
364 vidc
.h_interlace
= vidc
.h_cycle
/ 2;
365 vidc
.v_sync_width
= var
->vsync_len
- 1;
366 vidc
.v_border_start
= vidc
.v_sync_width
+ var
->upper_margin
;
367 vidc
.v_display_start
= vidc
.v_border_start
;
368 vidc
.v_display_end
= vidc
.v_display_start
+ var
->yres
;
369 vidc
.v_border_end
= vidc
.v_display_end
;
370 vidc
.control
= acornfb_default_control();
372 vcr
= var
->vsync_len
+ var
->upper_margin
+ var
->yres
+
375 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
376 vidc
.v_cycle
= (vcr
- 3) / 2;
377 vidc
.control
|= VIDC20_CTRL_INT
;
379 vidc
.v_cycle
= vcr
- 2;
381 switch (var
->bits_per_pixel
) {
382 case 1: vidc
.control
|= VIDC20_CTRL_1BPP
; break;
383 case 2: vidc
.control
|= VIDC20_CTRL_2BPP
; break;
384 case 4: vidc
.control
|= VIDC20_CTRL_4BPP
; break;
386 case 8: vidc
.control
|= VIDC20_CTRL_8BPP
; break;
387 case 16: vidc
.control
|= VIDC20_CTRL_16BPP
; break;
388 case 32: vidc
.control
|= VIDC20_CTRL_32BPP
; break;
391 acornfb_vidc20_find_rates(&vidc
, var
);
392 fsize
= var
->vsync_len
+ var
->upper_margin
+ var
->lower_margin
- 1;
394 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
397 outl(VIDC20_CTRL
| vidc
.control
, IO_VIDC_BASE
);
398 outl(0xd0000000 | vidc
.pll_ctl
, IO_VIDC_BASE
);
399 outl(0x80000000 | vidc
.h_cycle
, IO_VIDC_BASE
);
400 outl(0x81000000 | vidc
.h_sync_width
, IO_VIDC_BASE
);
401 outl(0x82000000 | vidc
.h_border_start
, IO_VIDC_BASE
);
402 outl(0x83000000 | vidc
.h_display_start
, IO_VIDC_BASE
);
403 outl(0x84000000 | vidc
.h_display_end
, IO_VIDC_BASE
);
404 outl(0x85000000 | vidc
.h_border_end
, IO_VIDC_BASE
);
405 outl(0x86000000, IO_VIDC_BASE
);
406 outl(0x87000000 | vidc
.h_interlace
, IO_VIDC_BASE
);
407 outl(0x90000000 | vidc
.v_cycle
, IO_VIDC_BASE
);
408 outl(0x91000000 | vidc
.v_sync_width
, IO_VIDC_BASE
);
409 outl(0x92000000 | vidc
.v_border_start
, IO_VIDC_BASE
);
410 outl(0x93000000 | vidc
.v_display_start
, IO_VIDC_BASE
);
411 outl(0x94000000 | vidc
.v_display_end
, IO_VIDC_BASE
);
412 outl(0x95000000 | vidc
.v_border_end
, IO_VIDC_BASE
);
413 outl(0x96000000, IO_VIDC_BASE
);
414 outl(0x97000000, IO_VIDC_BASE
);
417 outl(fsize
, IOMD_FSIZE
);
419 ext_ctl
= acornfb_default_econtrol();
421 if (var
->sync
& FB_SYNC_COMP_HIGH_ACT
) /* should be FB_SYNC_COMP */
422 ext_ctl
|= VIDC20_ECTL_HS_NCSYNC
| VIDC20_ECTL_VS_NCSYNC
;
424 if (var
->sync
& FB_SYNC_HOR_HIGH_ACT
)
425 ext_ctl
|= VIDC20_ECTL_HS_HSYNC
;
427 ext_ctl
|= VIDC20_ECTL_HS_NHSYNC
;
429 if (var
->sync
& FB_SYNC_VERT_HIGH_ACT
)
430 ext_ctl
|= VIDC20_ECTL_VS_VSYNC
;
432 ext_ctl
|= VIDC20_ECTL_VS_NVSYNC
;
435 outl(VIDC20_ECTL
| ext_ctl
, IO_VIDC_BASE
);
437 words_per_line
= var
->xres
* var
->bits_per_pixel
/ 32;
439 if (current_par
.using_vram
&& current_par
.screen_size
== 2048*1024)
442 /* RiscPC doesn't use the VIDC's VRAM control. */
443 dat_ctl
= VIDC20_DCTL_VRAM_DIS
| VIDC20_DCTL_SNA
| words_per_line
;
445 /* The data bus width is dependent on both the type
446 * and amount of video memory.
451 if (current_par
.using_vram
&& current_par
.vram_half_sam
== 2048) {
452 dat_ctl
|= VIDC20_DCTL_BUS_D63_0
;
454 dat_ctl
|= VIDC20_DCTL_BUS_D31_0
;
456 outl(VIDC20_DCTL
| dat_ctl
, IO_VIDC_BASE
);
458 #ifdef DEBUG_MODE_SELECTION
459 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
460 var
->yres
, var
->bits_per_pixel
);
461 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
462 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
463 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
464 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
465 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
466 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
467 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
468 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
469 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
470 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
471 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
472 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
473 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
474 printk(KERN_DEBUG
" Ext Ctrl (C) : 0x%08X\n", ext_ctl
);
475 printk(KERN_DEBUG
" PLL Ctrl (D) : 0x%08X\n", vidc
.pll_ctl
);
476 printk(KERN_DEBUG
" Ctrl (E) : 0x%08X\n", vidc
.control
);
477 printk(KERN_DEBUG
" Data Ctrl (F) : 0x%08X\n", dat_ctl
);
478 printk(KERN_DEBUG
" Fsize : 0x%08X\n", fsize
);
483 acornfb_palette_write(u_int regno
, union palette pal
)
485 outl(0x10000000 | regno
, IO_VIDC_BASE
);
486 outl(pal
.p
, IO_VIDC_BASE
);
489 static inline union palette
490 acornfb_palette_encode(u_int regno
, u_int red
, u_int green
, u_int blue
,
496 pal
.vidc20
.red
= red
>> 8;
497 pal
.vidc20
.green
= green
>> 8;
498 pal
.vidc20
.blue
= blue
>> 8;
503 acornfb_palette_decode(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
506 *red
= EXTEND8(current_par
.palette
[regno
].vidc20
.red
);
507 *green
= EXTEND8(current_par
.palette
[regno
].vidc20
.green
);
508 *blue
= EXTEND8(current_par
.palette
[regno
].vidc20
.blue
);
509 *trans
= EXTEND4(current_par
.palette
[regno
].vidc20
.ext
);
514 * Before selecting the timing parameters, adjust
515 * the resolution to fit the rules.
518 acornfb_adjust_timing(struct fb_var_screeninfo
*var
, int con
)
522 u_int sam_size
, min_size
, size
;
525 /* xres must be even */
526 var
->xres
= (var
->xres
+ 1) & ~1;
529 * We don't allow xres_virtual to differ from xres
531 var
->xres_virtual
= var
->xres
;
535 * Find the font height
538 fontht
= fontheight(&global_disp
);
540 fontht
= fontheight(fb_display
+ con
);
545 if (current_par
.using_vram
)
546 sam_size
= current_par
.vram_half_sam
* 2;
551 * Now, find a value for yres_virtual which allows
552 * us to do ywrap scrolling. The value of
553 * yres_virtual must be such that the end of the
554 * displayable frame buffer must be aligned with
555 * the start of a font line.
557 font_line_len
= var
->xres
* var
->bits_per_pixel
* fontht
/ 8;
558 min_size
= var
->xres
* var
->yres
* var
->bits_per_pixel
/ 8;
561 * If minimum screen size is greater than that we have
562 * available, reject it.
564 if (min_size
> current_par
.screen_size
)
567 /* Find int 'y', such that y * fll == s * sam < maxsize
568 * y = s * sam / fll; s = maxsize / sam
570 for (size
= current_par
.screen_size
; min_size
<= size
;
572 nr_y
= size
/ font_line_len
;
574 if (nr_y
* font_line_len
== size
)
578 if (var
->accel_flags
& FB_ACCELF_TEXT
) {
579 if (min_size
> size
) {
583 size
= current_par
.screen_size
;
584 var
->yres_virtual
= size
/ (font_line_len
/ fontht
);
586 var
->yres_virtual
= nr_y
* fontht
;
589 current_par
.screen_end
= current_par
.screen_base_p
+ size
;
592 * Fix yres & yoffset if needed.
594 if (var
->yres
> var
->yres_virtual
)
595 var
->yres
= var
->yres_virtual
;
597 if (var
->vmode
& FB_VMODE_YWRAP
) {
598 if (var
->yoffset
> var
->yres_virtual
)
599 var
->yoffset
= var
->yres_virtual
;
601 if (var
->yoffset
+ var
->yres
> var
->yres_virtual
)
602 var
->yoffset
= var
->yres_virtual
- var
->yres
;
605 /* hsync_len must be even */
606 var
->hsync_len
= (var
->hsync_len
+ 1) & ~1;
609 /* left_margin must be odd */
610 if ((var
->left_margin
& 1) == 0) {
611 var
->left_margin
-= 1;
612 var
->right_margin
+= 1;
615 /* right_margin must be odd */
616 var
->right_margin
|= 1;
617 #elif defined(HAS_VIDC20)
618 /* left_margin must be even */
619 if (var
->left_margin
& 1) {
620 var
->left_margin
+= 1;
621 var
->right_margin
-= 1;
624 /* right_margin must be even */
625 if (var
->right_margin
& 1)
626 var
->right_margin
+= 1;
629 if (var
->vsync_len
< 1)
636 acornfb_validate_timing(struct fb_var_screeninfo
*var
,
637 struct fb_monspecs
*monspecs
)
639 unsigned long hs
, vs
;
642 * hs(Hz) = 10^12 / (pixclock * xtotal)
643 * vs(Hz) = hs(Hz) / ytotal
645 * No need to do long long divisions or anything
646 * like that if you factor it correctly
648 hs
= 1953125000 / var
->pixclock
;
650 (var
->xres
+ var
->left_margin
+ var
->right_margin
+ var
->hsync_len
);
652 (var
->yres
+ var
->upper_margin
+ var
->lower_margin
+ var
->vsync_len
);
654 return (vs
>= monspecs
->vfmin
&& vs
<= monspecs
->vfmax
&&
655 hs
>= monspecs
->hfmin
&& hs
<= monspecs
->hfmax
) ? 0 : -EINVAL
;
659 acornfb_update_dma(struct fb_var_screeninfo
*var
)
661 int off
= (var
->yoffset
* var
->xres_virtual
*
662 var
->bits_per_pixel
) >> 3;
664 #if defined(HAS_MEMC)
665 memc_write(VDMA_INIT
, off
>> 2);
666 #elif defined(HAS_IOMD)
667 outl(current_par
.screen_base_p
+ off
, IOMD_VIDINIT
);
672 acornfb_open(struct fb_info
*info
, int user
)
679 acornfb_release(struct fb_info
*info
, int user
)
686 acornfb_getcolreg(u_int regno
, u_int
*red
, u_int
*green
, u_int
*blue
,
687 u_int
*trans
, struct fb_info
*info
)
689 if (regno
>= current_par
.palette_size
)
692 acornfb_palette_decode(regno
, red
, green
, blue
, trans
);
698 * We have to take note of the VIDC20's 16-bit palette here.
699 * The VIDC20 looks up a 16 bit pixel as follows:
703 * red ++++++++ (8 bits, 7 to 0)
704 * green ++++++++ (8 bits, 11 to 4)
705 * blue ++++++++ (8 bits, 15 to 8)
707 * We use a pixel which looks like:
711 * red +++++ (5 bits, 4 to 0)
712 * green +++++ (5 bits, 9 to 5)
713 * blue +++++ (5 bits, 14 to 10)
716 acornfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
717 u_int trans
, struct fb_info
*info
)
720 int bpp
= fb_display
[current_par
.currcon
].var
.bits_per_pixel
;
722 if (regno
>= current_par
.palette_size
)
725 pal
= acornfb_palette_encode(regno
, red
, green
, blue
, trans
);
726 current_par
.palette
[regno
] = pal
;
731 #ifdef FBCON_HAS_CFB16
733 current_par
.cmap
.cfb16
[regno
] =
734 regno
| regno
<< 5 | regno
<< 10;
737 #ifdef FBCON_HAS_CFB32
739 current_par
.cmap
.cfb32
[regno
] =
740 regno
| regno
<< 8 | regno
<< 16;
748 #ifdef FBCON_HAS_CFB16
753 outl(0x10000000, IO_VIDC_BASE
);
754 for (i
= 0; i
< 256; i
+= 1) {
755 pal
.vidc20
.red
= current_par
.palette
[ i
& 31].vidc20
.red
;
756 pal
.vidc20
.green
= current_par
.palette
[(i
>> 1) & 31].vidc20
.green
;
757 pal
.vidc20
.blue
= current_par
.palette
[(i
>> 2) & 31].vidc20
.blue
;
758 outl(pal
.p
, IO_VIDC_BASE
);
759 /* Palette register pointer auto-increments */
764 acornfb_palette_write(regno
, pal
);
770 acornfb_get_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
771 struct fb_info
*info
)
775 if (con
== current_par
.currcon
)
776 err
= fb_get_cmap(cmap
, kspc
, acornfb_getcolreg
, info
);
777 else if (fb_display
[con
].cmap
.len
)
778 fb_copy_cmap(&fb_display
[con
].cmap
, cmap
, kspc
? 0 : 2);
780 fb_copy_cmap(fb_default_cmap(current_par
.palette_size
),
786 acornfb_set_cmap(struct fb_cmap
*cmap
, int kspc
, int con
,
787 struct fb_info
*info
)
791 if (!fb_display
[con
].cmap
.len
)
792 err
= fb_alloc_cmap(&fb_display
[con
].cmap
,
793 current_par
.palette_size
, 0);
795 if (con
== current_par
.currcon
)
796 err
= fb_set_cmap(cmap
, kspc
, acornfb_setcolreg
,
799 fb_copy_cmap(cmap
, &fb_display
[con
].cmap
,
806 acornfb_decode_var(struct fb_var_screeninfo
*var
, int con
, int *visual
)
810 switch (var
->bits_per_pixel
) {
813 *visual
= FB_VISUAL_MONO10
;
816 #ifdef FBCON_HAS_CFB8
819 *visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
821 *visual
= FB_VISUAL_PSEUDOCOLOR
;
825 #ifdef FBCON_HAS_CFB4
827 *visual
= FB_VISUAL_PSEUDOCOLOR
;
830 #ifdef FBCON_HAS_CFB2
832 *visual
= FB_VISUAL_PSEUDOCOLOR
;
836 #ifdef FBCON_HAS_CFB16
838 *visual
= FB_VISUAL_DIRECTCOLOR
;
841 #ifdef FBCON_HAS_CFB32
843 *visual
= FB_VISUAL_TRUECOLOR
;
851 if (!acornfb_valid_pixrate(var
->pixclock
))
855 * Validate and adjust the resolution to
856 * match the video generator hardware.
858 err
= acornfb_adjust_timing(var
, con
);
863 * Validate the timing against the
866 err
= acornfb_validate_timing(var
, &fb_info
.monspecs
);
870 #if defined(HAS_VIDC20)
871 switch (var
->bits_per_pixel
) {
872 case 1: case 2: case 4: case 8:
875 var
->green
= var
->red
;
876 var
->blue
= var
->red
;
877 var
->transp
.offset
= 0;
878 var
->transp
.length
= 4;
884 var
->green
.offset
= 5;
885 var
->green
.length
= 5;
886 var
->blue
.offset
= 10;
887 var
->blue
.length
= 5;
888 var
->transp
.offset
= 15;
889 var
->transp
.length
= 1;
895 var
->green
.offset
= 8;
896 var
->green
.length
= 8;
897 var
->blue
.offset
= 16;
898 var
->blue
.length
= 8;
899 var
->transp
.offset
= 24;
900 var
->transp
.length
= 4;
903 #elif defined(HAS_VIDC)
905 var
->green
= var
->red
;
906 var
->blue
= var
->red
;
907 var
->transp
.length
= 1;
913 acornfb_get_fix(struct fb_fix_screeninfo
*fix
, int con
, struct fb_info
*info
)
915 struct display
*display
;
917 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
918 strcpy(fix
->id
, "Acorn");
921 display
= fb_display
+ con
;
923 display
= &global_disp
;
925 fix
->smem_start
= current_par
.screen_base_p
;
926 fix
->smem_len
= current_par
.screen_size
;
927 fix
->type
= display
->type
;
928 fix
->type_aux
= display
->type_aux
;
930 fix
->ypanstep
= display
->ypanstep
;
931 fix
->ywrapstep
= display
->ywrapstep
;
932 fix
->visual
= display
->visual
;
933 fix
->line_length
= display
->line_length
;
934 fix
->accel
= FB_ACCEL_NONE
;
940 acornfb_get_var(struct fb_var_screeninfo
*var
, int con
, struct fb_info
*info
)
943 *var
= global_disp
.var
;
945 *var
= fb_display
[con
].var
;
951 acornfb_set_var(struct fb_var_screeninfo
*var
, int con
, struct fb_info
*info
)
953 struct display
*display
;
954 int err
, chgvar
= 0, visual
;
957 display
= fb_display
+ con
;
959 display
= &global_disp
;
961 err
= acornfb_decode_var(var
, con
, &visual
);
965 switch (var
->activate
& FB_ACTIVATE_MASK
) {
966 case FB_ACTIVATE_TEST
:
969 case FB_ACTIVATE_NXTOPEN
:
970 case FB_ACTIVATE_NOW
:
978 if (display
->var
.xres
!= var
->xres
)
980 if (display
->var
.yres
!= var
->yres
)
982 if (display
->var
.xres_virtual
!= var
->xres_virtual
)
984 if (display
->var
.yres_virtual
!= var
->yres_virtual
)
986 if (memcmp(&display
->var
.red
, &var
->red
, sizeof(var
->red
)))
988 if (memcmp(&display
->var
.green
, &var
->green
, sizeof(var
->green
)))
990 if (memcmp(&display
->var
.blue
, &var
->blue
, sizeof(var
->blue
)))
995 display
->var
.activate
&= ~FB_ACTIVATE_ALL
;
997 if (var
->activate
& FB_ACTIVATE_ALL
)
998 global_disp
.var
= display
->var
;
1000 display
->screen_base
= (char *)current_par
.screen_base
;
1001 display
->visual
= visual
;
1002 display
->type
= FB_TYPE_PACKED_PIXELS
;
1003 display
->type_aux
= 0;
1004 display
->ypanstep
= 1;
1005 display
->ywrapstep
= 1;
1006 display
->line_length
=
1007 display
->next_line
= (var
->xres
* var
->bits_per_pixel
) / 8;
1008 display
->can_soft_blank
= visual
== FB_VISUAL_PSEUDOCOLOR
? 1 : 0;
1009 display
->inverse
= 0;
1011 switch (display
->var
.bits_per_pixel
) {
1012 #ifdef FBCON_HAS_MFB
1014 current_par
.palette_size
= 2;
1015 display
->dispsw
= &fbcon_mfb
;
1018 #ifdef FBCON_HAS_CFB2
1020 current_par
.palette_size
= 4;
1021 display
->dispsw
= &fbcon_cfb2
;
1024 #ifdef FBCON_HAS_CFB4
1026 current_par
.palette_size
= 16;
1027 display
->dispsw
= &fbcon_cfb4
;
1030 #ifdef FBCON_HAS_CFB8
1032 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1033 display
->dispsw
= &fbcon_cfb8
;
1036 #ifdef FBCON_HAS_CFB16
1038 current_par
.palette_size
= 32;
1039 display
->dispsw
= &fbcon_cfb16
;
1040 display
->dispsw_data
= current_par
.cmap
.cfb16
;
1043 #ifdef FBCON_HAS_CFB32
1045 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1046 display
->dispsw
= &fbcon_cfb32
;
1047 display
->dispsw_data
= current_par
.cmap
.cfb32
;
1051 display
->dispsw
= &fbcon_dummy
;
1055 if (chgvar
&& info
&& info
->changevar
)
1056 info
->changevar(con
);
1058 if (con
== current_par
.currcon
) {
1059 struct fb_cmap
*cmap
;
1060 unsigned long start
, size
;
1063 #if defined(HAS_MEMC)
1065 size
= current_par
.screen_size
- VDMA_XFERSIZE
;
1068 memc_write(VDMA_START
, start
);
1069 memc_write(VDMA_END
, size
>> 2);
1070 #elif defined(HAS_IOMD)
1072 start
= current_par
.screen_base_p
;
1073 size
= current_par
.screen_end
;
1075 if (current_par
.using_vram
) {
1076 size
-= current_par
.vram_half_sam
;
1077 control
= DMA_CR_E
| (current_par
.vram_half_sam
/ 256);
1080 control
= DMA_CR_E
| DMA_CR_D
| 16;
1083 outl(start
, IOMD_VIDSTART
);
1084 outl(size
, IOMD_VIDEND
);
1085 outl(control
, IOMD_VIDCR
);
1087 acornfb_update_dma(var
);
1088 acornfb_set_timing(var
);
1090 if (display
->cmap
.len
)
1091 cmap
= &display
->cmap
;
1093 cmap
= fb_default_cmap(current_par
.palette_size
);
1095 fb_set_cmap(cmap
, 1, acornfb_setcolreg
, info
);
1101 acornfb_pan_display(struct fb_var_screeninfo
*var
, int con
,
1102 struct fb_info
*info
)
1109 y_bottom
= var
->yoffset
;
1111 if (!(var
->vmode
& FB_VMODE_YWRAP
))
1112 y_bottom
+= var
->yres
;
1114 if (y_bottom
> fb_display
[con
].var
.yres_virtual
)
1117 acornfb_update_dma(var
);
1119 fb_display
[con
].var
.yoffset
= var
->yoffset
;
1120 if (var
->vmode
& FB_VMODE_YWRAP
)
1121 fb_display
[con
].var
.vmode
|= FB_VMODE_YWRAP
;
1123 fb_display
[con
].var
.vmode
&= ~FB_VMODE_YWRAP
;
1129 acornfb_ioctl(struct inode
*ino
, struct file
*file
, unsigned int cmd
,
1130 unsigned long arg
, int con
, struct fb_info
*info
)
1132 return -ENOIOCTLCMD
;
1135 static struct fb_ops acornfb_ops
= {
1143 acornfb_pan_display
,
1148 acornfb_updatevar(int con
, struct fb_info
*info
)
1150 if (con
== current_par
.currcon
)
1151 acornfb_update_dma(&fb_display
[con
].var
);
1157 acornfb_switch(int con
, struct fb_info
*info
)
1159 struct fb_cmap
*cmap
;
1161 if (current_par
.currcon
>= 0) {
1162 cmap
= &fb_display
[current_par
.currcon
].cmap
;
1165 fb_get_cmap(cmap
, 1, acornfb_getcolreg
, info
);
1168 current_par
.currcon
= con
;
1170 fb_display
[con
].var
.activate
= FB_ACTIVATE_NOW
;
1172 acornfb_set_var(&fb_display
[con
].var
, con
, info
);
1178 acornfb_blank(int blank
, struct fb_info
*info
)
1181 int i
, bpp
= fb_display
[current_par
.currcon
].var
.bits_per_pixel
;
1184 for (i
= 0; i
< current_par
.palette_size
; i
++) {
1186 p
= acornfb_palette_encode(i
, 0, 0, 0, 0);
1188 p
= current_par
.palette
[i
];
1190 acornfb_palette_write(i
, p
);
1193 #ifdef FBCON_HAS_CFB16
1197 for (i
= 0; i
< 256; i
++) {
1199 p
= acornfb_palette_encode(i
, 0, 0, 0, 0);
1201 p
.vidc20
.red
= current_par
.palette
[ i
& 31].vidc20
.red
;
1202 p
.vidc20
.green
= current_par
.palette
[(i
>> 1) & 31].vidc20
.green
;
1203 p
.vidc20
.blue
= current_par
.palette
[(i
>> 2) & 31].vidc20
.blue
;
1205 acornfb_palette_write(i
, current_par
.palette
[i
]);
1212 * Everything after here is initialisation!!!
1214 static struct fb_videomode modedb
[] __initdata
= {
1215 { /* 320x256 @ 50Hz */
1216 NULL
, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
1217 FB_SYNC_COMP_HIGH_ACT
,
1218 FB_VMODE_NONINTERLACED
1219 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
1220 NULL
, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
1222 FB_VMODE_NONINTERLACED
1223 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
1224 NULL
, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
1226 FB_VMODE_NONINTERLACED
1227 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
1228 NULL
, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
1230 FB_VMODE_NONINTERLACED
1231 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
1232 NULL
, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
1234 FB_VMODE_NONINTERLACED
1235 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
1236 NULL
, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
1238 FB_VMODE_NONINTERLACED
1239 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
1240 NULL
, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
1242 FB_VMODE_NONINTERLACED
1243 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
1244 NULL
, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
1246 FB_VMODE_NONINTERLACED
1247 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
1248 NULL
, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
1250 FB_VMODE_NONINTERLACED
1251 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
1252 NULL
, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
1254 FB_VMODE_NONINTERLACED
1255 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
1256 NULL
, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
1258 FB_VMODE_NONINTERLACED
1259 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
1260 NULL
, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
1262 FB_VMODE_NONINTERLACED
1266 static struct fb_videomode __initdata
1267 acornfb_default_mode
= {
1280 vmode
: FB_VMODE_NONINTERLACED
1284 acornfb_init_fbinfo(void)
1286 static int first
= 1;
1292 strcpy(fb_info
.modename
, "Acorn");
1293 strcpy(fb_info
.fontname
, "Acorn8x8");
1296 fb_info
.fbops
= &acornfb_ops
;
1297 fb_info
.disp
= &global_disp
;
1298 fb_info
.changevar
= NULL
;
1299 fb_info
.switch_con
= acornfb_switch
;
1300 fb_info
.updatevar
= acornfb_updatevar
;
1301 fb_info
.blank
= acornfb_blank
;
1302 fb_info
.flags
= FBINFO_FLAG_DEFAULT
;
1304 global_disp
.dispsw
= &fbcon_dummy
;
1307 * setup initial parameters
1309 memset(&init_var
, 0, sizeof(init_var
));
1311 #if defined(HAS_VIDC20)
1312 init_var
.red
.length
= 8;
1313 init_var
.transp
.length
= 4;
1314 #elif defined(HAS_VIDC)
1315 init_var
.red
.length
= 4;
1316 init_var
.transp
.length
= 1;
1318 init_var
.green
= init_var
.red
;
1319 init_var
.blue
= init_var
.red
;
1320 init_var
.nonstd
= 0;
1321 init_var
.activate
= FB_ACTIVATE_NOW
;
1322 init_var
.height
= -1;
1323 init_var
.width
= -1;
1324 init_var
.vmode
= FB_VMODE_NONINTERLACED
;
1325 init_var
.accel_flags
= FB_ACCELF_TEXT
;
1327 current_par
.dram_size
= 0;
1328 current_par
.montype
= -1;
1329 current_par
.dpms
= 0;
1333 * setup acornfb options:
1338 * mon:hmin-hmax:vmin-vmax:dpms:width:height
1339 * Set monitor parameters:
1340 * hmin = horizontal minimum frequency (Hz)
1341 * hmax = horizontal maximum frequency (Hz) (optional)
1342 * vmin = vertical minimum frequency (Hz)
1343 * vmax = vertical maximum frequency (Hz) (optional)
1344 * dpms = DPMS supported? (optional)
1345 * width = width of picture in mm. (optional)
1346 * height = height of picture in mm. (optional)
1349 * Set RISC-OS style monitor type:
1350 * 0 (or tv) - TV frequency
1351 * 1 (or multi) - Multi frequency
1352 * 2 (or hires) - Hi-res monochrome
1354 * 4 (or svga) - SVGA
1355 * auto, or option missing
1356 * - try hardware detect
1359 * Set the amount of DRAM to use for the frame buffer
1360 * (even if you have VRAM).
1361 * size can optionally be followed by 'M' or 'K' for
1362 * MB or KB respectively.
1365 acornfb_parse_font(char *opt
)
1367 strcpy(fb_info
.fontname
, opt
);
1371 acornfb_parse_mon(char *opt
)
1375 current_par
.montype
= -2;
1377 fb_info
.monspecs
.hfmin
= simple_strtoul(p
, &p
, 0);
1379 fb_info
.monspecs
.hfmax
= simple_strtoul(p
+ 1, &p
, 0);
1381 fb_info
.monspecs
.hfmax
= fb_info
.monspecs
.hfmin
;
1386 fb_info
.monspecs
.vfmin
= simple_strtoul(p
+ 1, &p
, 0);
1388 fb_info
.monspecs
.vfmax
= simple_strtoul(p
+ 1, &p
, 0);
1390 fb_info
.monspecs
.vfmax
= fb_info
.monspecs
.vfmin
;
1395 fb_info
.monspecs
.dpms
= simple_strtoul(p
+ 1, &p
, 0);
1400 init_var
.width
= simple_strtoul(p
+ 1, &p
, 0);
1405 init_var
.height
= simple_strtoul(p
+ 1, NULL
, 0);
1408 if (fb_info
.monspecs
.hfmax
< fb_info
.monspecs
.hfmin
||
1409 fb_info
.monspecs
.vfmax
< fb_info
.monspecs
.vfmin
)
1414 printk(KERN_ERR
"Acornfb: bad monitor settings: %s\n", opt
);
1415 current_par
.montype
= -1;
1419 acornfb_parse_montype(char *opt
)
1421 current_par
.montype
= -2;
1423 if (strncmp(opt
, "tv", 2) == 0) {
1425 current_par
.montype
= 0;
1426 } else if (strncmp(opt
, "multi", 5) == 0) {
1428 current_par
.montype
= 1;
1429 } else if (strncmp(opt
, "hires", 5) == 0) {
1431 current_par
.montype
= 2;
1432 } else if (strncmp(opt
, "vga", 3) == 0) {
1434 current_par
.montype
= 3;
1435 } else if (strncmp(opt
, "svga", 4) == 0) {
1437 current_par
.montype
= 4;
1438 } else if (strncmp(opt
, "auto", 4) == 0) {
1440 current_par
.montype
= -1;
1441 } else if (isdigit(*opt
))
1442 current_par
.montype
= simple_strtoul(opt
, &opt
, 0);
1444 if (current_par
.montype
== -2 ||
1445 current_par
.montype
> NR_MONTYPES
) {
1446 printk(KERN_ERR
"acornfb: unknown monitor type: %s\n",
1448 current_par
.montype
= -1;
1451 if (strcmp(opt
, ",dpms") == 0)
1452 current_par
.dpms
= 1;
1455 "acornfb: unknown monitor option: %s\n",
1461 acornfb_parse_dram(char *opt
)
1465 size
= simple_strtoul(opt
, &opt
, 0);
1480 current_par
.dram_size
= size
;
1483 static struct options
{
1485 void (*parse
)(char *opt
);
1486 } opt_table
[] __initdata
= {
1487 { "font", acornfb_parse_font
},
1488 { "mon", acornfb_parse_mon
},
1489 { "montype", acornfb_parse_montype
},
1490 { "dram", acornfb_parse_dram
},
1495 acornfb_setup(char *options
)
1497 struct options
*optp
;
1500 if (!options
|| !*options
)
1503 acornfb_init_fbinfo();
1505 for (opt
= strtok(options
, ","); opt
; opt
= strtok(NULL
, ",")) {
1509 for (optp
= opt_table
; optp
->name
; optp
++) {
1512 optlen
= strlen(optp
->name
);
1514 if (strncmp(opt
, optp
->name
, optlen
) == 0 &&
1515 opt
[optlen
] == ':') {
1516 optp
->parse(opt
+ optlen
+ 1);
1522 printk(KERN_ERR
"acornfb: unknown parameter: %s\n",
1529 * Detect type of monitor connected
1530 * For now, we just assume SVGA
1533 acornfb_detect_monitortype(void)
1539 * This enables the unused memory to be freed on older Acorn machines.
1542 free_unused_pages(unsigned int virtual_start
, unsigned int virtual_end
)
1549 virtual_start
= PAGE_ALIGN(virtual_start
);
1550 virtual_end
= PAGE_ALIGN(virtual_end
);
1552 while (virtual_start
< virtual_end
) {
1554 * Clear page reserved bit,
1555 * set count to 1, and free
1558 clear_bit(PG_reserved
, &mem_map
[MAP_NR(virtual_start
)].flags
);
1559 atomic_set(&mem_map
[MAP_NR(virtual_start
)].count
, 1);
1560 free_page(virtual_start
);
1562 virtual_start
+= PAGE_SIZE
;
1563 mb_freed
+= PAGE_SIZE
/ 1024;
1566 printk("acornfb: freed %dK memory\n", mb_freed
);
1573 u_int h_sync
, v_sync
;
1576 acornfb_init_fbinfo();
1578 if (current_par
.montype
== -1)
1579 current_par
.montype
= acornfb_detect_monitortype();
1581 if (current_par
.montype
== -1 || current_par
.montype
> NR_MONTYPES
)
1582 current_par
.montype
= 4;
1584 if (current_par
.montype
> 0) {
1585 fb_info
.monspecs
= monspecs
[current_par
.montype
];
1586 fb_info
.monspecs
.dpms
= current_par
.dpms
;
1590 * Try to select a suitable default mode
1592 for (i
= 0; i
< sizeof(modedb
) / sizeof(*modedb
); i
++) {
1595 hs
= modedb
[i
].refresh
*
1596 (modedb
[i
].yres
+ modedb
[i
].upper_margin
+
1597 modedb
[i
].lower_margin
+ modedb
[i
].vsync_len
);
1598 if (modedb
[i
].xres
== DEFAULT_XRES
&&
1599 modedb
[i
].yres
== DEFAULT_YRES
&&
1600 modedb
[i
].refresh
>= fb_info
.monspecs
.vfmin
&&
1601 modedb
[i
].refresh
<= fb_info
.monspecs
.vfmax
&&
1602 hs
>= fb_info
.monspecs
.hfmin
&&
1603 hs
<= fb_info
.monspecs
.hfmax
) {
1604 acornfb_default_mode
= modedb
[i
];
1609 current_par
.currcon
= -1;
1610 current_par
.screen_base
= SCREEN_BASE
;
1611 current_par
.screen_base_p
= SCREEN_START
;
1612 current_par
.using_vram
= 0;
1615 * If vram_size is set, we are using VRAM in
1616 * a Risc PC. However, if the user has specified
1617 * an amount of DRAM then use that instead.
1619 if (vram_size
&& !current_par
.dram_size
) {
1621 current_par
.vram_half_sam
= vram_size
/ 1024;
1622 current_par
.using_vram
= 1;
1623 } else if (current_par
.dram_size
)
1624 size
= current_par
.dram_size
;
1626 size
= (init_var
.xres
* init_var
.yres
*
1627 init_var
.bits_per_pixel
) / 8;
1629 size
= PAGE_ALIGN(size
);
1631 #if defined(HAS_VIDC20)
1632 if (!current_par
.using_vram
) {
1634 * RiscPC needs to allocate the DRAM memory
1635 * for the framebuffer if we are not using
1636 * VRAM. Archimedes/A5000 machines use a
1637 * fixed address for their framebuffers.
1640 unsigned long page
, top
;
1641 while (size
> (PAGE_SIZE
* (1 << order
)))
1643 current_par
.screen_base
= __get_free_pages(GFP_KERNEL
, order
);
1644 if (current_par
.screen_base
== 0) {
1645 printk(KERN_ERR
"acornfb: unable to allocate screen "
1649 top
= current_par
.screen_base
+ (PAGE_SIZE
* (1 << order
));
1650 /* Mark the framebuffer pages as reserved so mmap will work. */
1651 for (page
= current_par
.screen_base
;
1652 page
< PAGE_ALIGN(current_par
.screen_base
+ size
);
1654 mem_map
[MAP_NR(page
)].flags
|= (1 << PG_reserved
);
1655 /* Hand back any excess pages that we allocated. */
1656 for (page
= current_par
.screen_base
+ size
; page
< top
; page
+= PAGE_SIZE
)
1658 current_par
.screen_base_p
=
1659 virt_to_phys((void *)current_par
.screen_base
);
1662 #if defined(HAS_VIDC)
1663 #define MAX_SIZE 480*1024
1665 * Limit maximum screen size.
1667 if (size
> MAX_SIZE
)
1673 free_unused_pages(PAGE_OFFSET
+ size
, PAGE_OFFSET
+ MAX_SIZE
);
1676 current_par
.screen_size
= size
;
1677 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1680 * Lookup the timing for this resolution. If we can't
1681 * find it, then we can't restore it if we change
1682 * the resolution, so we disable this feature.
1684 rc
= fb_find_mode(&init_var
, &fb_info
, NULL
, modedb
,
1685 sizeof(modedb
) / sizeof(*modedb
),
1686 &acornfb_default_mode
, DEFAULT_BPP
);
1688 if (!rc
&& fb_find_mode(&init_var
, &fb_info
, NULL
, NULL
, 0,
1689 &acornfb_default_mode
, DEFAULT_BPP
)) {
1690 printk("Acornfb: no valid mode found\n");
1693 h_sync
= 1953125000 / init_var
.pixclock
;
1694 h_sync
= h_sync
* 512 / (init_var
.xres
+ init_var
.left_margin
+
1695 init_var
.right_margin
+ init_var
.hsync_len
);
1696 v_sync
= h_sync
/ (init_var
.yres
+ init_var
.upper_margin
+
1697 init_var
.lower_margin
+ init_var
.vsync_len
);
1699 printk(KERN_INFO
"Acornfb: %ldkB %cRAM, %s, using %dx%d, "
1700 "%d.%03dkHz, %dHz\n",
1701 current_par
.screen_size
/ 1024,
1702 current_par
.using_vram
? 'V' : 'D',
1703 VIDC_NAME
, init_var
.xres
, init_var
.yres
,
1704 h_sync
/ 1000, h_sync
% 1000, v_sync
);
1706 printk(KERN_INFO
"Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1707 fb_info
.monspecs
.hfmin
/ 1000, fb_info
.monspecs
.hfmin
% 1000,
1708 fb_info
.monspecs
.hfmax
/ 1000, fb_info
.monspecs
.hfmax
% 1000,
1709 fb_info
.monspecs
.vfmin
, fb_info
.monspecs
.vfmax
,
1710 fb_info
.monspecs
.dpms
? ", DPMS" : "");
1712 if (acornfb_set_var(&init_var
, -1, &fb_info
))
1713 printk(KERN_ERR
"Acornfb: unable to set display parameters\n");
1715 if (register_framebuffer(&fb_info
) < 0)