2 * linux/drivers/video/acornfb.c
4 * Copyright (C) 1998-2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Frame buffer code for Acorn platforms
12 * NOTE: Most of the modes with X!=640 will disappear shortly.
13 * NOTE: Startup setting of HS & VS polarity not supported.
14 * (do we need to support it if we're coming up in 640x480?)
16 * FIXME: (things broken by the "new improved" FBCON API)
17 * - Blanking 8bpp displays with VIDC
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
24 #include <linux/ctype.h>
25 #include <linux/slab.h>
26 #include <linux/init.h>
28 #include <linux/platform_device.h>
29 #include <linux/dma-mapping.h>
31 #include <asm/hardware.h>
34 #include <asm/mach-types.h>
35 #include <asm/pgtable.h>
40 * VIDC machines can't do 16 or 32BPP modes.
43 #undef FBCON_HAS_CFB16
44 #undef FBCON_HAS_CFB32
49 * NOTE that it has to be supported in the table towards
50 * the end of this file.
52 #define DEFAULT_XRES 640
53 #define DEFAULT_YRES 480
57 * define this to debug the video mode selection
59 #undef DEBUG_MODE_SELECTION
62 * Translation from RISC OS monitor types to actual
63 * HSYNC and VSYNC frequency ranges. These are
64 * probably not right, but they're the best info I
65 * have. Allow 1% either way on the nominal for TVs.
68 static struct fb_monspecs monspecs
[NR_MONTYPES
] __initdata
= {
79 }, { /* Hi-res mono */
102 static struct fb_info fb_info
;
103 static struct acornfb_par current_par
;
104 static struct vidc_timing current_vidc
;
106 extern unsigned int vram_size
; /* set by setup.c */
110 #define MAX_SIZE 480*1024
133 static struct pixclock arc_clocks
[] = {
134 /* we allow +/-1% on these */
135 { 123750, 126250, VIDC_CTRL_DIV3
, VID_CTL_24MHz
}, /* 8.000MHz */
136 { 82500, 84167, VIDC_CTRL_DIV2
, VID_CTL_24MHz
}, /* 12.000MHz */
137 { 61875, 63125, VIDC_CTRL_DIV1_5
, VID_CTL_24MHz
}, /* 16.000MHz */
138 { 41250, 42083, VIDC_CTRL_DIV1
, VID_CTL_24MHz
}, /* 24.000MHz */
141 #ifdef CONFIG_ARCH_A5K
142 static struct pixclock a5k_clocks
[] = {
143 { 117974, 120357, VIDC_CTRL_DIV3
, VID_CTL_25MHz
}, /* 8.392MHz */
144 { 78649, 80238, VIDC_CTRL_DIV2
, VID_CTL_25MHz
}, /* 12.588MHz */
145 { 58987, 60178, VIDC_CTRL_DIV1_5
, VID_CTL_25MHz
}, /* 16.588MHz */
146 { 55000, 56111, VIDC_CTRL_DIV2
, VID_CTL_36MHz
}, /* 18.000MHz */
147 { 39325, 40119, VIDC_CTRL_DIV1
, VID_CTL_25MHz
}, /* 25.175MHz */
148 { 27500, 28055, VIDC_CTRL_DIV1
, VID_CTL_36MHz
}, /* 36.000MHz */
152 static struct pixclock
*
153 acornfb_valid_pixrate(struct fb_var_screeninfo
*var
)
155 u_long pixclock
= var
->pixclock
;
161 for (i
= 0; i
< ARRAY_SIZE(arc_clocks
); i
++)
162 if (pixclock
> arc_clocks
[i
].min_clock
&&
163 pixclock
< arc_clocks
[i
].max_clock
)
164 return arc_clocks
+ i
;
166 #ifdef CONFIG_ARCH_A5K
167 if (machine_is_a5k()) {
168 for (i
= 0; i
< ARRAY_SIZE(a5k_clocks
); i
++)
169 if (pixclock
> a5k_clocks
[i
].min_clock
&&
170 pixclock
< a5k_clocks
[i
].max_clock
)
171 return a5k_clocks
+ i
;
179 * hcr : must be even (interlace, hcr/2 must be even)
180 * hswr : must be even
188 * if interlaced, then hcr/2 must be even
191 acornfb_set_timing(struct fb_var_screeninfo
*var
)
193 struct pixclock
*pclk
;
194 struct vidc_timing vidc
;
195 u_int horiz_correction
;
196 u_int sync_len
, display_start
, display_end
, cycle
;
198 u_int vid_ctl
, vidc_ctl
;
201 memset(&vidc
, 0, sizeof(vidc
));
203 pclk
= acornfb_valid_pixrate(var
);
204 vidc_ctl
= pclk
->vidc_ctl
;
205 vid_ctl
= pclk
->vid_ctl
;
207 bandwidth
= var
->pixclock
* 8 / var
->bits_per_pixel
;
208 /* 25.175, 4bpp = 79.444ns per byte, 317.776ns per word: fifo = 2,6 */
209 if (bandwidth
> 143500)
210 vidc_ctl
|= VIDC_CTRL_FIFO_3_7
;
211 else if (bandwidth
> 71750)
212 vidc_ctl
|= VIDC_CTRL_FIFO_2_6
;
213 else if (bandwidth
> 35875)
214 vidc_ctl
|= VIDC_CTRL_FIFO_1_5
;
216 vidc_ctl
|= VIDC_CTRL_FIFO_0_4
;
218 switch (var
->bits_per_pixel
) {
220 horiz_correction
= 19;
221 vidc_ctl
|= VIDC_CTRL_1BPP
;
225 horiz_correction
= 11;
226 vidc_ctl
|= VIDC_CTRL_2BPP
;
230 horiz_correction
= 7;
231 vidc_ctl
|= VIDC_CTRL_4BPP
;
236 horiz_correction
= 5;
237 vidc_ctl
|= VIDC_CTRL_8BPP
;
241 if (var
->sync
& FB_SYNC_COMP_HIGH_ACT
) /* should be FB_SYNC_COMP */
242 vidc_ctl
|= VIDC_CTRL_CSYNC
;
244 if (!(var
->sync
& FB_SYNC_HOR_HIGH_ACT
))
245 vid_ctl
|= VID_CTL_HS_NHSYNC
;
247 if (!(var
->sync
& FB_SYNC_VERT_HIGH_ACT
))
248 vid_ctl
|= VID_CTL_VS_NVSYNC
;
251 sync_len
= var
->hsync_len
;
252 display_start
= sync_len
+ var
->left_margin
;
253 display_end
= display_start
+ var
->xres
;
254 cycle
= display_end
+ var
->right_margin
;
256 /* if interlaced, then hcr/2 must be even */
257 is_interlaced
= (var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
;
260 vidc_ctl
|= VIDC_CTRL_INTERLACE
;
263 var
->right_margin
+= 2;
267 vidc
.h_cycle
= (cycle
- 2) / 2;
268 vidc
.h_sync_width
= (sync_len
- 2) / 2;
269 vidc
.h_border_start
= (display_start
- 1) / 2;
270 vidc
.h_display_start
= (display_start
- horiz_correction
) / 2;
271 vidc
.h_display_end
= (display_end
- horiz_correction
) / 2;
272 vidc
.h_border_end
= (display_end
- 1) / 2;
273 vidc
.h_interlace
= (vidc
.h_cycle
+ 1) / 2;
275 sync_len
= var
->vsync_len
;
276 display_start
= sync_len
+ var
->upper_margin
;
277 display_end
= display_start
+ var
->yres
;
278 cycle
= display_end
+ var
->lower_margin
;
281 cycle
= (cycle
- 3) / 2;
285 vidc
.v_cycle
= cycle
;
286 vidc
.v_sync_width
= sync_len
- 1;
287 vidc
.v_border_start
= display_start
- 1;
288 vidc
.v_display_start
= vidc
.v_border_start
;
289 vidc
.v_display_end
= display_end
- 1;
290 vidc
.v_border_end
= vidc
.v_display_end
;
292 if (machine_is_a5k())
293 __raw_writeb(vid_ctl
, IOEB_VID_CTL
);
295 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
298 vidc_writel(0xe0000000 | vidc_ctl
);
299 vidc_writel(0x80000000 | (vidc
.h_cycle
<< 14));
300 vidc_writel(0x84000000 | (vidc
.h_sync_width
<< 14));
301 vidc_writel(0x88000000 | (vidc
.h_border_start
<< 14));
302 vidc_writel(0x8c000000 | (vidc
.h_display_start
<< 14));
303 vidc_writel(0x90000000 | (vidc
.h_display_end
<< 14));
304 vidc_writel(0x94000000 | (vidc
.h_border_end
<< 14));
305 vidc_writel(0x98000000);
306 vidc_writel(0x9c000000 | (vidc
.h_interlace
<< 14));
307 vidc_writel(0xa0000000 | (vidc
.v_cycle
<< 14));
308 vidc_writel(0xa4000000 | (vidc
.v_sync_width
<< 14));
309 vidc_writel(0xa8000000 | (vidc
.v_border_start
<< 14));
310 vidc_writel(0xac000000 | (vidc
.v_display_start
<< 14));
311 vidc_writel(0xb0000000 | (vidc
.v_display_end
<< 14));
312 vidc_writel(0xb4000000 | (vidc
.v_border_end
<< 14));
313 vidc_writel(0xb8000000);
314 vidc_writel(0xbc000000);
316 #ifdef DEBUG_MODE_SELECTION
317 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
318 var
->yres
, var
->bits_per_pixel
);
319 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
320 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
321 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
322 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
323 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
324 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
325 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
326 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
327 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
328 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
329 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
330 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
331 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
332 printk(KERN_DEBUG
" VIDC Ctrl (E) : 0x%08X\n", vidc_ctl
);
333 printk(KERN_DEBUG
" IOEB Ctrl : 0x%08X\n", vid_ctl
);
338 acornfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
339 u_int trans
, struct fb_info
*info
)
343 if (regno
>= current_par
.palette_size
)
347 pal
.vidc
.reg
= regno
;
348 pal
.vidc
.red
= red
>> 12;
349 pal
.vidc
.green
= green
>> 12;
350 pal
.vidc
.blue
= blue
>> 12;
352 current_par
.palette
[regno
] = pal
;
361 #include <asm/arch/acornfb.h>
363 #define MAX_SIZE 2*1024*1024
365 /* VIDC20 has a different set of rules from the VIDC:
366 * hcr : must be multiple of 4
367 * hswr : must be even
368 * hdsr : must be even
369 * hder : must be even
370 * vcr : >= 2, (interlace, must be odd)
375 static void acornfb_set_timing(struct fb_info
*info
)
377 struct fb_var_screeninfo
*var
= &info
->var
;
378 struct vidc_timing vidc
;
380 u_int ext_ctl
, dat_ctl
;
381 u_int words_per_line
;
383 memset(&vidc
, 0, sizeof(vidc
));
385 vidc
.h_sync_width
= var
->hsync_len
- 8;
386 vidc
.h_border_start
= vidc
.h_sync_width
+ var
->left_margin
+ 8 - 12;
387 vidc
.h_display_start
= vidc
.h_border_start
+ 12 - 18;
388 vidc
.h_display_end
= vidc
.h_display_start
+ var
->xres
;
389 vidc
.h_border_end
= vidc
.h_display_end
+ 18 - 12;
390 vidc
.h_cycle
= vidc
.h_border_end
+ var
->right_margin
+ 12 - 8;
391 vidc
.h_interlace
= vidc
.h_cycle
/ 2;
392 vidc
.v_sync_width
= var
->vsync_len
- 1;
393 vidc
.v_border_start
= vidc
.v_sync_width
+ var
->upper_margin
;
394 vidc
.v_display_start
= vidc
.v_border_start
;
395 vidc
.v_display_end
= vidc
.v_display_start
+ var
->yres
;
396 vidc
.v_border_end
= vidc
.v_display_end
;
397 vidc
.control
= acornfb_default_control();
399 vcr
= var
->vsync_len
+ var
->upper_margin
+ var
->yres
+
402 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
403 vidc
.v_cycle
= (vcr
- 3) / 2;
404 vidc
.control
|= VIDC20_CTRL_INT
;
406 vidc
.v_cycle
= vcr
- 2;
408 switch (var
->bits_per_pixel
) {
409 case 1: vidc
.control
|= VIDC20_CTRL_1BPP
; break;
410 case 2: vidc
.control
|= VIDC20_CTRL_2BPP
; break;
411 case 4: vidc
.control
|= VIDC20_CTRL_4BPP
; break;
413 case 8: vidc
.control
|= VIDC20_CTRL_8BPP
; break;
414 case 16: vidc
.control
|= VIDC20_CTRL_16BPP
; break;
415 case 32: vidc
.control
|= VIDC20_CTRL_32BPP
; break;
418 acornfb_vidc20_find_rates(&vidc
, var
);
419 fsize
= var
->vsync_len
+ var
->upper_margin
+ var
->lower_margin
- 1;
421 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
424 vidc_writel(VIDC20_CTRL
| vidc
.control
);
425 vidc_writel(0xd0000000 | vidc
.pll_ctl
);
426 vidc_writel(0x80000000 | vidc
.h_cycle
);
427 vidc_writel(0x81000000 | vidc
.h_sync_width
);
428 vidc_writel(0x82000000 | vidc
.h_border_start
);
429 vidc_writel(0x83000000 | vidc
.h_display_start
);
430 vidc_writel(0x84000000 | vidc
.h_display_end
);
431 vidc_writel(0x85000000 | vidc
.h_border_end
);
432 vidc_writel(0x86000000);
433 vidc_writel(0x87000000 | vidc
.h_interlace
);
434 vidc_writel(0x90000000 | vidc
.v_cycle
);
435 vidc_writel(0x91000000 | vidc
.v_sync_width
);
436 vidc_writel(0x92000000 | vidc
.v_border_start
);
437 vidc_writel(0x93000000 | vidc
.v_display_start
);
438 vidc_writel(0x94000000 | vidc
.v_display_end
);
439 vidc_writel(0x95000000 | vidc
.v_border_end
);
440 vidc_writel(0x96000000);
441 vidc_writel(0x97000000);
444 iomd_writel(fsize
, IOMD_FSIZE
);
446 ext_ctl
= acornfb_default_econtrol();
448 if (var
->sync
& FB_SYNC_COMP_HIGH_ACT
) /* should be FB_SYNC_COMP */
449 ext_ctl
|= VIDC20_ECTL_HS_NCSYNC
| VIDC20_ECTL_VS_NCSYNC
;
451 if (var
->sync
& FB_SYNC_HOR_HIGH_ACT
)
452 ext_ctl
|= VIDC20_ECTL_HS_HSYNC
;
454 ext_ctl
|= VIDC20_ECTL_HS_NHSYNC
;
456 if (var
->sync
& FB_SYNC_VERT_HIGH_ACT
)
457 ext_ctl
|= VIDC20_ECTL_VS_VSYNC
;
459 ext_ctl
|= VIDC20_ECTL_VS_NVSYNC
;
462 vidc_writel(VIDC20_ECTL
| ext_ctl
);
464 words_per_line
= var
->xres
* var
->bits_per_pixel
/ 32;
466 if (current_par
.using_vram
&& info
->fix
.smem_len
== 2048*1024)
469 /* RiscPC doesn't use the VIDC's VRAM control. */
470 dat_ctl
= VIDC20_DCTL_VRAM_DIS
| VIDC20_DCTL_SNA
| words_per_line
;
472 /* The data bus width is dependent on both the type
473 * and amount of video memory.
478 if (current_par
.using_vram
&& current_par
.vram_half_sam
== 2048)
479 dat_ctl
|= VIDC20_DCTL_BUS_D63_0
;
481 dat_ctl
|= VIDC20_DCTL_BUS_D31_0
;
483 vidc_writel(VIDC20_DCTL
| dat_ctl
);
485 #ifdef DEBUG_MODE_SELECTION
486 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
487 var
->yres
, var
->bits_per_pixel
);
488 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
489 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
490 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
491 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
492 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
493 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
494 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
495 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
496 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
497 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
498 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
499 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
500 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
501 printk(KERN_DEBUG
" Ext Ctrl (C) : 0x%08X\n", ext_ctl
);
502 printk(KERN_DEBUG
" PLL Ctrl (D) : 0x%08X\n", vidc
.pll_ctl
);
503 printk(KERN_DEBUG
" Ctrl (E) : 0x%08X\n", vidc
.control
);
504 printk(KERN_DEBUG
" Data Ctrl (F) : 0x%08X\n", dat_ctl
);
505 printk(KERN_DEBUG
" Fsize : 0x%08X\n", fsize
);
510 * We have to take note of the VIDC20's 16-bit palette here.
511 * The VIDC20 looks up a 16 bit pixel as follows:
515 * red ++++++++ (8 bits, 7 to 0)
516 * green ++++++++ (8 bits, 11 to 4)
517 * blue ++++++++ (8 bits, 15 to 8)
519 * We use a pixel which looks like:
523 * red +++++ (5 bits, 4 to 0)
524 * green +++++ (5 bits, 9 to 5)
525 * blue +++++ (5 bits, 14 to 10)
528 acornfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
529 u_int trans
, struct fb_info
*info
)
533 if (regno
>= current_par
.palette_size
)
536 if (regno
< 16 && info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
539 pseudo_val
= regno
<< info
->var
.red
.offset
;
540 pseudo_val
|= regno
<< info
->var
.green
.offset
;
541 pseudo_val
|= regno
<< info
->var
.blue
.offset
;
543 ((u32
*)info
->pseudo_palette
)[regno
] = pseudo_val
;
547 pal
.vidc20
.red
= red
>> 8;
548 pal
.vidc20
.green
= green
>> 8;
549 pal
.vidc20
.blue
= blue
>> 8;
551 current_par
.palette
[regno
] = pal
;
553 if (info
->var
.bits_per_pixel
== 16) {
557 vidc_writel(0x10000000);
558 for (i
= 0; i
< 256; i
+= 1) {
559 pal
.vidc20
.red
= current_par
.palette
[ i
& 31].vidc20
.red
;
560 pal
.vidc20
.green
= current_par
.palette
[(i
>> 1) & 31].vidc20
.green
;
561 pal
.vidc20
.blue
= current_par
.palette
[(i
>> 2) & 31].vidc20
.blue
;
563 /* Palette register pointer auto-increments */
566 vidc_writel(0x10000000 | regno
);
575 * Before selecting the timing parameters, adjust
576 * the resolution to fit the rules.
579 acornfb_adjust_timing(struct fb_info
*info
, struct fb_var_screeninfo
*var
, u_int fontht
)
581 u_int font_line_len
, sam_size
, min_size
, size
, nr_y
;
583 /* xres must be even */
584 var
->xres
= (var
->xres
+ 1) & ~1;
587 * We don't allow xres_virtual to differ from xres
589 var
->xres_virtual
= var
->xres
;
592 if (current_par
.using_vram
)
593 sam_size
= current_par
.vram_half_sam
* 2;
598 * Now, find a value for yres_virtual which allows
599 * us to do ywrap scrolling. The value of
600 * yres_virtual must be such that the end of the
601 * displayable frame buffer must be aligned with
602 * the start of a font line.
604 font_line_len
= var
->xres
* var
->bits_per_pixel
* fontht
/ 8;
605 min_size
= var
->xres
* var
->yres
* var
->bits_per_pixel
/ 8;
608 * If minimum screen size is greater than that we have
609 * available, reject it.
611 if (min_size
> info
->fix
.smem_len
)
614 /* Find int 'y', such that y * fll == s * sam < maxsize
615 * y = s * sam / fll; s = maxsize / sam
617 for (size
= info
->fix
.smem_len
;
618 nr_y
= size
/ font_line_len
, min_size
<= size
;
620 if (nr_y
* font_line_len
== size
)
625 if (var
->accel_flags
& FB_ACCELF_TEXT
) {
626 if (min_size
> size
) {
630 size
= info
->fix
.smem_len
;
631 var
->yres_virtual
= size
/ (font_line_len
/ fontht
);
633 var
->yres_virtual
= nr_y
;
634 } else if (var
->yres_virtual
> nr_y
)
635 var
->yres_virtual
= nr_y
;
637 current_par
.screen_end
= info
->fix
.smem_start
+ size
;
640 * Fix yres & yoffset if needed.
642 if (var
->yres
> var
->yres_virtual
)
643 var
->yres
= var
->yres_virtual
;
645 if (var
->vmode
& FB_VMODE_YWRAP
) {
646 if (var
->yoffset
> var
->yres_virtual
)
647 var
->yoffset
= var
->yres_virtual
;
649 if (var
->yoffset
+ var
->yres
> var
->yres_virtual
)
650 var
->yoffset
= var
->yres_virtual
- var
->yres
;
653 /* hsync_len must be even */
654 var
->hsync_len
= (var
->hsync_len
+ 1) & ~1;
657 /* left_margin must be odd */
658 if ((var
->left_margin
& 1) == 0) {
659 var
->left_margin
-= 1;
660 var
->right_margin
+= 1;
663 /* right_margin must be odd */
664 var
->right_margin
|= 1;
665 #elif defined(HAS_VIDC20)
666 /* left_margin must be even */
667 if (var
->left_margin
& 1) {
668 var
->left_margin
+= 1;
669 var
->right_margin
-= 1;
672 /* right_margin must be even */
673 if (var
->right_margin
& 1)
674 var
->right_margin
+= 1;
677 if (var
->vsync_len
< 1)
684 acornfb_validate_timing(struct fb_var_screeninfo
*var
,
685 struct fb_monspecs
*monspecs
)
687 unsigned long hs
, vs
;
690 * hs(Hz) = 10^12 / (pixclock * xtotal)
691 * vs(Hz) = hs(Hz) / ytotal
693 * No need to do long long divisions or anything
694 * like that if you factor it correctly
696 hs
= 1953125000 / var
->pixclock
;
698 (var
->xres
+ var
->left_margin
+ var
->right_margin
+ var
->hsync_len
);
700 (var
->yres
+ var
->upper_margin
+ var
->lower_margin
+ var
->vsync_len
);
702 return (vs
>= monspecs
->vfmin
&& vs
<= monspecs
->vfmax
&&
703 hs
>= monspecs
->hfmin
&& hs
<= monspecs
->hfmax
) ? 0 : -EINVAL
;
707 acornfb_update_dma(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
709 u_int off
= var
->yoffset
* info
->fix
.line_length
;
711 #if defined(HAS_MEMC)
712 memc_write(VDMA_INIT
, off
>> 2);
713 #elif defined(HAS_IOMD)
714 iomd_writel(info
->fix
.smem_start
+ off
, IOMD_VIDINIT
);
719 acornfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
725 * FIXME: Find the font height
729 var
->red
.msb_right
= 0;
730 var
->green
.msb_right
= 0;
731 var
->blue
.msb_right
= 0;
732 var
->transp
.msb_right
= 0;
734 switch (var
->bits_per_pixel
) {
735 case 1: case 2: case 4: case 8:
737 var
->red
.length
= var
->bits_per_pixel
;
738 var
->green
= var
->red
;
739 var
->blue
= var
->red
;
740 var
->transp
.offset
= 0;
741 var
->transp
.length
= 0;
748 var
->green
.offset
= 5;
749 var
->green
.length
= 5;
750 var
->blue
.offset
= 10;
751 var
->blue
.length
= 5;
752 var
->transp
.offset
= 15;
753 var
->transp
.length
= 1;
759 var
->green
.offset
= 8;
760 var
->green
.length
= 8;
761 var
->blue
.offset
= 16;
762 var
->blue
.length
= 8;
763 var
->transp
.offset
= 24;
764 var
->transp
.length
= 4;
772 * Check to see if the pixel rate is valid.
774 if (!acornfb_valid_pixrate(var
))
778 * Validate and adjust the resolution to
779 * match the video generator hardware.
781 err
= acornfb_adjust_timing(info
, var
, fontht
);
786 * Validate the timing against the
789 return acornfb_validate_timing(var
, &info
->monspecs
);
792 static int acornfb_set_par(struct fb_info
*info
)
794 switch (info
->var
.bits_per_pixel
) {
796 current_par
.palette_size
= 2;
797 info
->fix
.visual
= FB_VISUAL_MONO10
;
800 current_par
.palette_size
= 4;
801 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
804 current_par
.palette_size
= 16;
805 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
808 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
810 info
->fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
812 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
817 current_par
.palette_size
= 32;
818 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
821 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
822 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
829 info
->fix
.line_length
= (info
->var
.xres
* info
->var
.bits_per_pixel
) / 8;
831 #if defined(HAS_MEMC)
833 unsigned long size
= info
->fix
.smem_len
- VDMA_XFERSIZE
;
835 memc_write(VDMA_START
, 0);
836 memc_write(VDMA_END
, size
>> 2);
838 #elif defined(HAS_IOMD)
840 unsigned long start
, size
;
843 start
= info
->fix
.smem_start
;
844 size
= current_par
.screen_end
;
846 if (current_par
.using_vram
) {
847 size
-= current_par
.vram_half_sam
;
848 control
= DMA_CR_E
| (current_par
.vram_half_sam
/ 256);
851 control
= DMA_CR_E
| DMA_CR_D
| 16;
854 iomd_writel(start
, IOMD_VIDSTART
);
855 iomd_writel(size
, IOMD_VIDEND
);
856 iomd_writel(control
, IOMD_VIDCR
);
860 acornfb_update_dma(info
, &info
->var
);
861 acornfb_set_timing(info
);
867 acornfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
869 u_int y_bottom
= var
->yoffset
;
871 if (!(var
->vmode
& FB_VMODE_YWRAP
))
872 y_bottom
+= var
->yres
;
874 BUG_ON(y_bottom
> var
->yres_virtual
);
876 acornfb_update_dma(info
, var
);
882 * Note that we are entered with the kernel locked.
885 acornfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
887 unsigned long off
, start
;
890 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
892 start
= info
->fix
.smem_start
;
893 len
= PAGE_ALIGN(start
& ~PAGE_MASK
) + info
->fix
.smem_len
;
895 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
898 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
900 /* This is an IO map - tell maydump to skip this VMA */
901 vma
->vm_flags
|= VM_IO
;
903 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
906 * Don't alter the page protection flags; we want to keep the area
907 * cached for better performance. This does mean that we may miss
908 * some updates to the screen occasionally, but process switches
909 * should cause the caches and buffers to be flushed often enough.
911 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
912 vma
->vm_end
- vma
->vm_start
,
918 static struct fb_ops acornfb_ops
= {
919 .owner
= THIS_MODULE
,
920 .fb_check_var
= acornfb_check_var
,
921 .fb_set_par
= acornfb_set_par
,
922 .fb_setcolreg
= acornfb_setcolreg
,
923 .fb_pan_display
= acornfb_pan_display
,
924 .fb_fillrect
= cfb_fillrect
,
925 .fb_copyarea
= cfb_copyarea
,
926 .fb_imageblit
= cfb_imageblit
,
927 .fb_mmap
= acornfb_mmap
,
931 * Everything after here is initialisation!!!
933 static struct fb_videomode modedb
[] __initdata
= {
934 { /* 320x256 @ 50Hz */
935 NULL
, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
936 FB_SYNC_COMP_HIGH_ACT
,
937 FB_VMODE_NONINTERLACED
938 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
939 NULL
, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
941 FB_VMODE_NONINTERLACED
942 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
943 NULL
, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
945 FB_VMODE_NONINTERLACED
946 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
947 NULL
, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
949 FB_VMODE_NONINTERLACED
950 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
951 NULL
, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
953 FB_VMODE_NONINTERLACED
954 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
955 NULL
, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
957 FB_VMODE_NONINTERLACED
958 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
959 NULL
, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
961 FB_VMODE_NONINTERLACED
962 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
963 NULL
, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
965 FB_VMODE_NONINTERLACED
966 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
967 NULL
, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
969 FB_VMODE_NONINTERLACED
970 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
971 NULL
, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
973 FB_VMODE_NONINTERLACED
974 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
975 NULL
, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
977 FB_VMODE_NONINTERLACED
978 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
979 NULL
, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
981 FB_VMODE_NONINTERLACED
985 static struct fb_videomode __initdata
986 acornfb_default_mode
= {
999 .vmode
= FB_VMODE_NONINTERLACED
1002 static void __init
acornfb_init_fbinfo(void)
1004 static int first
= 1;
1010 fb_info
.fbops
= &acornfb_ops
;
1011 fb_info
.flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
1012 fb_info
.pseudo_palette
= current_par
.pseudo_palette
;
1014 strcpy(fb_info
.fix
.id
, "Acorn");
1015 fb_info
.fix
.type
= FB_TYPE_PACKED_PIXELS
;
1016 fb_info
.fix
.type_aux
= 0;
1017 fb_info
.fix
.xpanstep
= 0;
1018 fb_info
.fix
.ypanstep
= 1;
1019 fb_info
.fix
.ywrapstep
= 1;
1020 fb_info
.fix
.line_length
= 0;
1021 fb_info
.fix
.accel
= FB_ACCEL_NONE
;
1024 * setup initial parameters
1026 memset(&fb_info
.var
, 0, sizeof(fb_info
.var
));
1028 #if defined(HAS_VIDC20)
1029 fb_info
.var
.red
.length
= 8;
1030 fb_info
.var
.transp
.length
= 4;
1031 #elif defined(HAS_VIDC)
1032 fb_info
.var
.red
.length
= 4;
1033 fb_info
.var
.transp
.length
= 1;
1035 fb_info
.var
.green
= fb_info
.var
.red
;
1036 fb_info
.var
.blue
= fb_info
.var
.red
;
1037 fb_info
.var
.nonstd
= 0;
1038 fb_info
.var
.activate
= FB_ACTIVATE_NOW
;
1039 fb_info
.var
.height
= -1;
1040 fb_info
.var
.width
= -1;
1041 fb_info
.var
.vmode
= FB_VMODE_NONINTERLACED
;
1042 fb_info
.var
.accel_flags
= FB_ACCELF_TEXT
;
1044 current_par
.dram_size
= 0;
1045 current_par
.montype
= -1;
1046 current_par
.dpms
= 0;
1050 * setup acornfb options:
1052 * mon:hmin-hmax:vmin-vmax:dpms:width:height
1053 * Set monitor parameters:
1054 * hmin = horizontal minimum frequency (Hz)
1055 * hmax = horizontal maximum frequency (Hz) (optional)
1056 * vmin = vertical minimum frequency (Hz)
1057 * vmax = vertical maximum frequency (Hz) (optional)
1058 * dpms = DPMS supported? (optional)
1059 * width = width of picture in mm. (optional)
1060 * height = height of picture in mm. (optional)
1063 * Set RISC-OS style monitor type:
1064 * 0 (or tv) - TV frequency
1065 * 1 (or multi) - Multi frequency
1066 * 2 (or hires) - Hi-res monochrome
1068 * 4 (or svga) - SVGA
1069 * auto, or option missing
1070 * - try hardware detect
1073 * Set the amount of DRAM to use for the frame buffer
1074 * (even if you have VRAM).
1075 * size can optionally be followed by 'M' or 'K' for
1076 * MB or KB respectively.
1079 acornfb_parse_mon(char *opt
)
1083 current_par
.montype
= -2;
1085 fb_info
.monspecs
.hfmin
= simple_strtoul(p
, &p
, 0);
1087 fb_info
.monspecs
.hfmax
= simple_strtoul(p
+ 1, &p
, 0);
1089 fb_info
.monspecs
.hfmax
= fb_info
.monspecs
.hfmin
;
1094 fb_info
.monspecs
.vfmin
= simple_strtoul(p
+ 1, &p
, 0);
1096 fb_info
.monspecs
.vfmax
= simple_strtoul(p
+ 1, &p
, 0);
1098 fb_info
.monspecs
.vfmax
= fb_info
.monspecs
.vfmin
;
1103 fb_info
.monspecs
.dpms
= simple_strtoul(p
+ 1, &p
, 0);
1108 fb_info
.var
.width
= simple_strtoul(p
+ 1, &p
, 0);
1113 fb_info
.var
.height
= simple_strtoul(p
+ 1, NULL
, 0);
1116 if (fb_info
.monspecs
.hfmax
< fb_info
.monspecs
.hfmin
||
1117 fb_info
.monspecs
.vfmax
< fb_info
.monspecs
.vfmin
)
1122 printk(KERN_ERR
"Acornfb: bad monitor settings: %s\n", opt
);
1123 current_par
.montype
= -1;
1127 acornfb_parse_montype(char *opt
)
1129 current_par
.montype
= -2;
1131 if (strncmp(opt
, "tv", 2) == 0) {
1133 current_par
.montype
= 0;
1134 } else if (strncmp(opt
, "multi", 5) == 0) {
1136 current_par
.montype
= 1;
1137 } else if (strncmp(opt
, "hires", 5) == 0) {
1139 current_par
.montype
= 2;
1140 } else if (strncmp(opt
, "vga", 3) == 0) {
1142 current_par
.montype
= 3;
1143 } else if (strncmp(opt
, "svga", 4) == 0) {
1145 current_par
.montype
= 4;
1146 } else if (strncmp(opt
, "auto", 4) == 0) {
1148 current_par
.montype
= -1;
1149 } else if (isdigit(*opt
))
1150 current_par
.montype
= simple_strtoul(opt
, &opt
, 0);
1152 if (current_par
.montype
== -2 ||
1153 current_par
.montype
> NR_MONTYPES
) {
1154 printk(KERN_ERR
"acornfb: unknown monitor type: %s\n",
1156 current_par
.montype
= -1;
1159 if (strcmp(opt
, ",dpms") == 0)
1160 current_par
.dpms
= 1;
1163 "acornfb: unknown monitor option: %s\n",
1169 acornfb_parse_dram(char *opt
)
1173 size
= simple_strtoul(opt
, &opt
, 0);
1188 current_par
.dram_size
= size
;
1191 static struct options
{
1193 void (*parse
)(char *opt
);
1194 } opt_table
[] __initdata
= {
1195 { "mon", acornfb_parse_mon
},
1196 { "montype", acornfb_parse_montype
},
1197 { "dram", acornfb_parse_dram
},
1202 acornfb_setup(char *options
)
1204 struct options
*optp
;
1207 if (!options
|| !*options
)
1210 acornfb_init_fbinfo();
1212 while ((opt
= strsep(&options
, ",")) != NULL
) {
1216 for (optp
= opt_table
; optp
->name
; optp
++) {
1219 optlen
= strlen(optp
->name
);
1221 if (strncmp(opt
, optp
->name
, optlen
) == 0 &&
1222 opt
[optlen
] == ':') {
1223 optp
->parse(opt
+ optlen
+ 1);
1229 printk(KERN_ERR
"acornfb: unknown parameter: %s\n",
1236 * Detect type of monitor connected
1237 * For now, we just assume SVGA
1240 acornfb_detect_monitortype(void)
1246 * This enables the unused memory to be freed on older Acorn machines.
1247 * We are freeing memory on behalf of the architecture initialisation
1251 free_unused_pages(unsigned int virtual_start
, unsigned int virtual_end
)
1258 virtual_start
= PAGE_ALIGN(virtual_start
);
1259 virtual_end
= PAGE_ALIGN(virtual_end
);
1261 while (virtual_start
< virtual_end
) {
1265 * Clear page reserved bit,
1266 * set count to 1, and free
1269 page
= virt_to_page(virtual_start
);
1270 ClearPageReserved(page
);
1271 init_page_count(page
);
1272 free_page(virtual_start
);
1274 virtual_start
+= PAGE_SIZE
;
1275 mb_freed
+= PAGE_SIZE
/ 1024;
1278 printk("acornfb: freed %dK memory\n", mb_freed
);
1281 static int __init
acornfb_probe(struct platform_device
*dev
)
1284 u_int h_sync
, v_sync
;
1286 char *option
= NULL
;
1288 if (fb_get_options("acornfb", &option
))
1290 acornfb_setup(option
);
1292 acornfb_init_fbinfo();
1294 current_par
.dev
= &dev
->dev
;
1296 if (current_par
.montype
== -1)
1297 current_par
.montype
= acornfb_detect_monitortype();
1299 if (current_par
.montype
== -1 || current_par
.montype
> NR_MONTYPES
)
1300 current_par
.montype
= 4;
1302 if (current_par
.montype
>= 0) {
1303 fb_info
.monspecs
= monspecs
[current_par
.montype
];
1304 fb_info
.monspecs
.dpms
= current_par
.dpms
;
1308 * Try to select a suitable default mode
1310 for (i
= 0; i
< ARRAY_SIZE(modedb
); i
++) {
1313 hs
= modedb
[i
].refresh
*
1314 (modedb
[i
].yres
+ modedb
[i
].upper_margin
+
1315 modedb
[i
].lower_margin
+ modedb
[i
].vsync_len
);
1316 if (modedb
[i
].xres
== DEFAULT_XRES
&&
1317 modedb
[i
].yres
== DEFAULT_YRES
&&
1318 modedb
[i
].refresh
>= fb_info
.monspecs
.vfmin
&&
1319 modedb
[i
].refresh
<= fb_info
.monspecs
.vfmax
&&
1320 hs
>= fb_info
.monspecs
.hfmin
&&
1321 hs
<= fb_info
.monspecs
.hfmax
) {
1322 acornfb_default_mode
= modedb
[i
];
1327 fb_info
.screen_base
= (char *)SCREEN_BASE
;
1328 fb_info
.fix
.smem_start
= SCREEN_START
;
1329 current_par
.using_vram
= 0;
1332 * If vram_size is set, we are using VRAM in
1333 * a Risc PC. However, if the user has specified
1334 * an amount of DRAM then use that instead.
1336 if (vram_size
&& !current_par
.dram_size
) {
1338 current_par
.vram_half_sam
= vram_size
/ 1024;
1339 current_par
.using_vram
= 1;
1340 } else if (current_par
.dram_size
)
1341 size
= current_par
.dram_size
;
1346 * Limit maximum screen size.
1348 if (size
> MAX_SIZE
)
1351 size
= PAGE_ALIGN(size
);
1353 #if defined(HAS_VIDC20)
1354 if (!current_par
.using_vram
) {
1359 * RiscPC needs to allocate the DRAM memory
1360 * for the framebuffer if we are not using
1363 base
= dma_alloc_writecombine(current_par
.dev
, size
, &handle
,
1366 printk(KERN_ERR
"acornfb: unable to allocate screen "
1371 fb_info
.screen_base
= base
;
1372 fb_info
.fix
.smem_start
= handle
;
1375 #if defined(HAS_VIDC)
1377 * Archimedes/A5000 machines use a fixed address for their
1378 * framebuffers. Free unused pages
1380 free_unused_pages(PAGE_OFFSET
+ size
, PAGE_OFFSET
+ MAX_SIZE
);
1383 fb_info
.fix
.smem_len
= size
;
1384 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1387 * Lookup the timing for this resolution. If we can't
1388 * find it, then we can't restore it if we change
1389 * the resolution, so we disable this feature.
1392 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1394 &acornfb_default_mode
, DEFAULT_BPP
);
1396 * If we found an exact match, all ok.
1401 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1402 &acornfb_default_mode
, DEFAULT_BPP
);
1404 * If we found an exact match, all ok.
1409 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1411 &acornfb_default_mode
, DEFAULT_BPP
);
1415 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1416 &acornfb_default_mode
, DEFAULT_BPP
);
1420 * If we didn't find an exact match, try the
1424 printk("Acornfb: no valid mode found\n");
1428 h_sync
= 1953125000 / fb_info
.var
.pixclock
;
1429 h_sync
= h_sync
* 512 / (fb_info
.var
.xres
+ fb_info
.var
.left_margin
+
1430 fb_info
.var
.right_margin
+ fb_info
.var
.hsync_len
);
1431 v_sync
= h_sync
/ (fb_info
.var
.yres
+ fb_info
.var
.upper_margin
+
1432 fb_info
.var
.lower_margin
+ fb_info
.var
.vsync_len
);
1434 printk(KERN_INFO
"Acornfb: %dkB %cRAM, %s, using %dx%d, "
1435 "%d.%03dkHz, %dHz\n",
1436 fb_info
.fix
.smem_len
/ 1024,
1437 current_par
.using_vram
? 'V' : 'D',
1438 VIDC_NAME
, fb_info
.var
.xres
, fb_info
.var
.yres
,
1439 h_sync
/ 1000, h_sync
% 1000, v_sync
);
1441 printk(KERN_INFO
"Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1442 fb_info
.monspecs
.hfmin
/ 1000, fb_info
.monspecs
.hfmin
% 1000,
1443 fb_info
.monspecs
.hfmax
/ 1000, fb_info
.monspecs
.hfmax
% 1000,
1444 fb_info
.monspecs
.vfmin
, fb_info
.monspecs
.vfmax
,
1445 fb_info
.monspecs
.dpms
? ", DPMS" : "");
1447 if (fb_set_var(&fb_info
, &fb_info
.var
))
1448 printk(KERN_ERR
"Acornfb: unable to set display parameters\n");
1450 if (register_framebuffer(&fb_info
) < 0)
1455 static struct platform_driver acornfb_driver
= {
1456 .probe
= acornfb_probe
,
1462 static int __init
acornfb_init(void)
1464 return platform_driver_register(&acornfb_driver
);
1467 module_init(acornfb_init
);
1469 MODULE_AUTHOR("Russell King");
1470 MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
1471 MODULE_LICENSE("GPL");