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 static struct pixclock
*
142 acornfb_valid_pixrate(struct fb_var_screeninfo
*var
)
144 u_long pixclock
= var
->pixclock
;
150 for (i
= 0; i
< ARRAY_SIZE(arc_clocks
); i
++)
151 if (pixclock
> arc_clocks
[i
].min_clock
&&
152 pixclock
< arc_clocks
[i
].max_clock
)
153 return arc_clocks
+ i
;
159 * hcr : must be even (interlace, hcr/2 must be even)
160 * hswr : must be even
168 * if interlaced, then hcr/2 must be even
171 acornfb_set_timing(struct fb_var_screeninfo
*var
)
173 struct pixclock
*pclk
;
174 struct vidc_timing vidc
;
175 u_int horiz_correction
;
176 u_int sync_len
, display_start
, display_end
, cycle
;
178 u_int vid_ctl
, vidc_ctl
;
181 memset(&vidc
, 0, sizeof(vidc
));
183 pclk
= acornfb_valid_pixrate(var
);
184 vidc_ctl
= pclk
->vidc_ctl
;
185 vid_ctl
= pclk
->vid_ctl
;
187 bandwidth
= var
->pixclock
* 8 / var
->bits_per_pixel
;
188 /* 25.175, 4bpp = 79.444ns per byte, 317.776ns per word: fifo = 2,6 */
189 if (bandwidth
> 143500)
190 vidc_ctl
|= VIDC_CTRL_FIFO_3_7
;
191 else if (bandwidth
> 71750)
192 vidc_ctl
|= VIDC_CTRL_FIFO_2_6
;
193 else if (bandwidth
> 35875)
194 vidc_ctl
|= VIDC_CTRL_FIFO_1_5
;
196 vidc_ctl
|= VIDC_CTRL_FIFO_0_4
;
198 switch (var
->bits_per_pixel
) {
200 horiz_correction
= 19;
201 vidc_ctl
|= VIDC_CTRL_1BPP
;
205 horiz_correction
= 11;
206 vidc_ctl
|= VIDC_CTRL_2BPP
;
210 horiz_correction
= 7;
211 vidc_ctl
|= VIDC_CTRL_4BPP
;
216 horiz_correction
= 5;
217 vidc_ctl
|= VIDC_CTRL_8BPP
;
221 if (var
->sync
& FB_SYNC_COMP_HIGH_ACT
) /* should be FB_SYNC_COMP */
222 vidc_ctl
|= VIDC_CTRL_CSYNC
;
224 if (!(var
->sync
& FB_SYNC_HOR_HIGH_ACT
))
225 vid_ctl
|= VID_CTL_HS_NHSYNC
;
227 if (!(var
->sync
& FB_SYNC_VERT_HIGH_ACT
))
228 vid_ctl
|= VID_CTL_VS_NVSYNC
;
231 sync_len
= var
->hsync_len
;
232 display_start
= sync_len
+ var
->left_margin
;
233 display_end
= display_start
+ var
->xres
;
234 cycle
= display_end
+ var
->right_margin
;
236 /* if interlaced, then hcr/2 must be even */
237 is_interlaced
= (var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
;
240 vidc_ctl
|= VIDC_CTRL_INTERLACE
;
243 var
->right_margin
+= 2;
247 vidc
.h_cycle
= (cycle
- 2) / 2;
248 vidc
.h_sync_width
= (sync_len
- 2) / 2;
249 vidc
.h_border_start
= (display_start
- 1) / 2;
250 vidc
.h_display_start
= (display_start
- horiz_correction
) / 2;
251 vidc
.h_display_end
= (display_end
- horiz_correction
) / 2;
252 vidc
.h_border_end
= (display_end
- 1) / 2;
253 vidc
.h_interlace
= (vidc
.h_cycle
+ 1) / 2;
255 sync_len
= var
->vsync_len
;
256 display_start
= sync_len
+ var
->upper_margin
;
257 display_end
= display_start
+ var
->yres
;
258 cycle
= display_end
+ var
->lower_margin
;
261 cycle
= (cycle
- 3) / 2;
265 vidc
.v_cycle
= cycle
;
266 vidc
.v_sync_width
= sync_len
- 1;
267 vidc
.v_border_start
= display_start
- 1;
268 vidc
.v_display_start
= vidc
.v_border_start
;
269 vidc
.v_display_end
= display_end
- 1;
270 vidc
.v_border_end
= vidc
.v_display_end
;
272 if (machine_is_a5k())
273 __raw_writeb(vid_ctl
, IOEB_VID_CTL
);
275 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
278 vidc_writel(0xe0000000 | vidc_ctl
);
279 vidc_writel(0x80000000 | (vidc
.h_cycle
<< 14));
280 vidc_writel(0x84000000 | (vidc
.h_sync_width
<< 14));
281 vidc_writel(0x88000000 | (vidc
.h_border_start
<< 14));
282 vidc_writel(0x8c000000 | (vidc
.h_display_start
<< 14));
283 vidc_writel(0x90000000 | (vidc
.h_display_end
<< 14));
284 vidc_writel(0x94000000 | (vidc
.h_border_end
<< 14));
285 vidc_writel(0x98000000);
286 vidc_writel(0x9c000000 | (vidc
.h_interlace
<< 14));
287 vidc_writel(0xa0000000 | (vidc
.v_cycle
<< 14));
288 vidc_writel(0xa4000000 | (vidc
.v_sync_width
<< 14));
289 vidc_writel(0xa8000000 | (vidc
.v_border_start
<< 14));
290 vidc_writel(0xac000000 | (vidc
.v_display_start
<< 14));
291 vidc_writel(0xb0000000 | (vidc
.v_display_end
<< 14));
292 vidc_writel(0xb4000000 | (vidc
.v_border_end
<< 14));
293 vidc_writel(0xb8000000);
294 vidc_writel(0xbc000000);
296 #ifdef DEBUG_MODE_SELECTION
297 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
298 var
->yres
, var
->bits_per_pixel
);
299 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
300 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
301 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
302 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
303 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
304 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
305 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
306 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
307 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
308 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
309 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
310 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
311 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
312 printk(KERN_DEBUG
" VIDC Ctrl (E) : 0x%08X\n", vidc_ctl
);
313 printk(KERN_DEBUG
" IOEB Ctrl : 0x%08X\n", vid_ctl
);
318 acornfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
319 u_int trans
, struct fb_info
*info
)
323 if (regno
>= current_par
.palette_size
)
327 pal
.vidc
.reg
= regno
;
328 pal
.vidc
.red
= red
>> 12;
329 pal
.vidc
.green
= green
>> 12;
330 pal
.vidc
.blue
= blue
>> 12;
332 current_par
.palette
[regno
] = pal
;
341 #include <asm/arch/acornfb.h>
343 #define MAX_SIZE 2*1024*1024
345 /* VIDC20 has a different set of rules from the VIDC:
346 * hcr : must be multiple of 4
347 * hswr : must be even
348 * hdsr : must be even
349 * hder : must be even
350 * vcr : >= 2, (interlace, must be odd)
355 static void acornfb_set_timing(struct fb_info
*info
)
357 struct fb_var_screeninfo
*var
= &info
->var
;
358 struct vidc_timing vidc
;
360 u_int ext_ctl
, dat_ctl
;
361 u_int words_per_line
;
363 memset(&vidc
, 0, sizeof(vidc
));
365 vidc
.h_sync_width
= var
->hsync_len
- 8;
366 vidc
.h_border_start
= vidc
.h_sync_width
+ var
->left_margin
+ 8 - 12;
367 vidc
.h_display_start
= vidc
.h_border_start
+ 12 - 18;
368 vidc
.h_display_end
= vidc
.h_display_start
+ var
->xres
;
369 vidc
.h_border_end
= vidc
.h_display_end
+ 18 - 12;
370 vidc
.h_cycle
= vidc
.h_border_end
+ var
->right_margin
+ 12 - 8;
371 vidc
.h_interlace
= vidc
.h_cycle
/ 2;
372 vidc
.v_sync_width
= var
->vsync_len
- 1;
373 vidc
.v_border_start
= vidc
.v_sync_width
+ var
->upper_margin
;
374 vidc
.v_display_start
= vidc
.v_border_start
;
375 vidc
.v_display_end
= vidc
.v_display_start
+ var
->yres
;
376 vidc
.v_border_end
= vidc
.v_display_end
;
377 vidc
.control
= acornfb_default_control();
379 vcr
= var
->vsync_len
+ var
->upper_margin
+ var
->yres
+
382 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
383 vidc
.v_cycle
= (vcr
- 3) / 2;
384 vidc
.control
|= VIDC20_CTRL_INT
;
386 vidc
.v_cycle
= vcr
- 2;
388 switch (var
->bits_per_pixel
) {
389 case 1: vidc
.control
|= VIDC20_CTRL_1BPP
; break;
390 case 2: vidc
.control
|= VIDC20_CTRL_2BPP
; break;
391 case 4: vidc
.control
|= VIDC20_CTRL_4BPP
; break;
393 case 8: vidc
.control
|= VIDC20_CTRL_8BPP
; break;
394 case 16: vidc
.control
|= VIDC20_CTRL_16BPP
; break;
395 case 32: vidc
.control
|= VIDC20_CTRL_32BPP
; break;
398 acornfb_vidc20_find_rates(&vidc
, var
);
399 fsize
= var
->vsync_len
+ var
->upper_margin
+ var
->lower_margin
- 1;
401 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
404 vidc_writel(VIDC20_CTRL
| vidc
.control
);
405 vidc_writel(0xd0000000 | vidc
.pll_ctl
);
406 vidc_writel(0x80000000 | vidc
.h_cycle
);
407 vidc_writel(0x81000000 | vidc
.h_sync_width
);
408 vidc_writel(0x82000000 | vidc
.h_border_start
);
409 vidc_writel(0x83000000 | vidc
.h_display_start
);
410 vidc_writel(0x84000000 | vidc
.h_display_end
);
411 vidc_writel(0x85000000 | vidc
.h_border_end
);
412 vidc_writel(0x86000000);
413 vidc_writel(0x87000000 | vidc
.h_interlace
);
414 vidc_writel(0x90000000 | vidc
.v_cycle
);
415 vidc_writel(0x91000000 | vidc
.v_sync_width
);
416 vidc_writel(0x92000000 | vidc
.v_border_start
);
417 vidc_writel(0x93000000 | vidc
.v_display_start
);
418 vidc_writel(0x94000000 | vidc
.v_display_end
);
419 vidc_writel(0x95000000 | vidc
.v_border_end
);
420 vidc_writel(0x96000000);
421 vidc_writel(0x97000000);
424 iomd_writel(fsize
, IOMD_FSIZE
);
426 ext_ctl
= acornfb_default_econtrol();
428 if (var
->sync
& FB_SYNC_COMP_HIGH_ACT
) /* should be FB_SYNC_COMP */
429 ext_ctl
|= VIDC20_ECTL_HS_NCSYNC
| VIDC20_ECTL_VS_NCSYNC
;
431 if (var
->sync
& FB_SYNC_HOR_HIGH_ACT
)
432 ext_ctl
|= VIDC20_ECTL_HS_HSYNC
;
434 ext_ctl
|= VIDC20_ECTL_HS_NHSYNC
;
436 if (var
->sync
& FB_SYNC_VERT_HIGH_ACT
)
437 ext_ctl
|= VIDC20_ECTL_VS_VSYNC
;
439 ext_ctl
|= VIDC20_ECTL_VS_NVSYNC
;
442 vidc_writel(VIDC20_ECTL
| ext_ctl
);
444 words_per_line
= var
->xres
* var
->bits_per_pixel
/ 32;
446 if (current_par
.using_vram
&& info
->fix
.smem_len
== 2048*1024)
449 /* RiscPC doesn't use the VIDC's VRAM control. */
450 dat_ctl
= VIDC20_DCTL_VRAM_DIS
| VIDC20_DCTL_SNA
| words_per_line
;
452 /* The data bus width is dependent on both the type
453 * and amount of video memory.
458 if (current_par
.using_vram
&& current_par
.vram_half_sam
== 2048)
459 dat_ctl
|= VIDC20_DCTL_BUS_D63_0
;
461 dat_ctl
|= VIDC20_DCTL_BUS_D31_0
;
463 vidc_writel(VIDC20_DCTL
| dat_ctl
);
465 #ifdef DEBUG_MODE_SELECTION
466 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
467 var
->yres
, var
->bits_per_pixel
);
468 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
469 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
470 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
471 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
472 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
473 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
474 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
475 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
476 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
477 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
478 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
479 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
480 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
481 printk(KERN_DEBUG
" Ext Ctrl (C) : 0x%08X\n", ext_ctl
);
482 printk(KERN_DEBUG
" PLL Ctrl (D) : 0x%08X\n", vidc
.pll_ctl
);
483 printk(KERN_DEBUG
" Ctrl (E) : 0x%08X\n", vidc
.control
);
484 printk(KERN_DEBUG
" Data Ctrl (F) : 0x%08X\n", dat_ctl
);
485 printk(KERN_DEBUG
" Fsize : 0x%08X\n", fsize
);
490 * We have to take note of the VIDC20's 16-bit palette here.
491 * The VIDC20 looks up a 16 bit pixel as follows:
495 * red ++++++++ (8 bits, 7 to 0)
496 * green ++++++++ (8 bits, 11 to 4)
497 * blue ++++++++ (8 bits, 15 to 8)
499 * We use a pixel which looks like:
503 * red +++++ (5 bits, 4 to 0)
504 * green +++++ (5 bits, 9 to 5)
505 * blue +++++ (5 bits, 14 to 10)
508 acornfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
509 u_int trans
, struct fb_info
*info
)
513 if (regno
>= current_par
.palette_size
)
516 if (regno
< 16 && info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
519 pseudo_val
= regno
<< info
->var
.red
.offset
;
520 pseudo_val
|= regno
<< info
->var
.green
.offset
;
521 pseudo_val
|= regno
<< info
->var
.blue
.offset
;
523 ((u32
*)info
->pseudo_palette
)[regno
] = pseudo_val
;
527 pal
.vidc20
.red
= red
>> 8;
528 pal
.vidc20
.green
= green
>> 8;
529 pal
.vidc20
.blue
= blue
>> 8;
531 current_par
.palette
[regno
] = pal
;
533 if (info
->var
.bits_per_pixel
== 16) {
537 vidc_writel(0x10000000);
538 for (i
= 0; i
< 256; i
+= 1) {
539 pal
.vidc20
.red
= current_par
.palette
[ i
& 31].vidc20
.red
;
540 pal
.vidc20
.green
= current_par
.palette
[(i
>> 1) & 31].vidc20
.green
;
541 pal
.vidc20
.blue
= current_par
.palette
[(i
>> 2) & 31].vidc20
.blue
;
543 /* Palette register pointer auto-increments */
546 vidc_writel(0x10000000 | regno
);
555 * Before selecting the timing parameters, adjust
556 * the resolution to fit the rules.
559 acornfb_adjust_timing(struct fb_info
*info
, struct fb_var_screeninfo
*var
, u_int fontht
)
561 u_int font_line_len
, sam_size
, min_size
, size
, nr_y
;
563 /* xres must be even */
564 var
->xres
= (var
->xres
+ 1) & ~1;
567 * We don't allow xres_virtual to differ from xres
569 var
->xres_virtual
= var
->xres
;
572 if (current_par
.using_vram
)
573 sam_size
= current_par
.vram_half_sam
* 2;
578 * Now, find a value for yres_virtual which allows
579 * us to do ywrap scrolling. The value of
580 * yres_virtual must be such that the end of the
581 * displayable frame buffer must be aligned with
582 * the start of a font line.
584 font_line_len
= var
->xres
* var
->bits_per_pixel
* fontht
/ 8;
585 min_size
= var
->xres
* var
->yres
* var
->bits_per_pixel
/ 8;
588 * If minimum screen size is greater than that we have
589 * available, reject it.
591 if (min_size
> info
->fix
.smem_len
)
594 /* Find int 'y', such that y * fll == s * sam < maxsize
595 * y = s * sam / fll; s = maxsize / sam
597 for (size
= info
->fix
.smem_len
;
598 nr_y
= size
/ font_line_len
, min_size
<= size
;
600 if (nr_y
* font_line_len
== size
)
605 if (var
->accel_flags
& FB_ACCELF_TEXT
) {
606 if (min_size
> size
) {
610 size
= info
->fix
.smem_len
;
611 var
->yres_virtual
= size
/ (font_line_len
/ fontht
);
613 var
->yres_virtual
= nr_y
;
614 } else if (var
->yres_virtual
> nr_y
)
615 var
->yres_virtual
= nr_y
;
617 current_par
.screen_end
= info
->fix
.smem_start
+ size
;
620 * Fix yres & yoffset if needed.
622 if (var
->yres
> var
->yres_virtual
)
623 var
->yres
= var
->yres_virtual
;
625 if (var
->vmode
& FB_VMODE_YWRAP
) {
626 if (var
->yoffset
> var
->yres_virtual
)
627 var
->yoffset
= var
->yres_virtual
;
629 if (var
->yoffset
+ var
->yres
> var
->yres_virtual
)
630 var
->yoffset
= var
->yres_virtual
- var
->yres
;
633 /* hsync_len must be even */
634 var
->hsync_len
= (var
->hsync_len
+ 1) & ~1;
637 /* left_margin must be odd */
638 if ((var
->left_margin
& 1) == 0) {
639 var
->left_margin
-= 1;
640 var
->right_margin
+= 1;
643 /* right_margin must be odd */
644 var
->right_margin
|= 1;
645 #elif defined(HAS_VIDC20)
646 /* left_margin must be even */
647 if (var
->left_margin
& 1) {
648 var
->left_margin
+= 1;
649 var
->right_margin
-= 1;
652 /* right_margin must be even */
653 if (var
->right_margin
& 1)
654 var
->right_margin
+= 1;
657 if (var
->vsync_len
< 1)
664 acornfb_validate_timing(struct fb_var_screeninfo
*var
,
665 struct fb_monspecs
*monspecs
)
667 unsigned long hs
, vs
;
670 * hs(Hz) = 10^12 / (pixclock * xtotal)
671 * vs(Hz) = hs(Hz) / ytotal
673 * No need to do long long divisions or anything
674 * like that if you factor it correctly
676 hs
= 1953125000 / var
->pixclock
;
678 (var
->xres
+ var
->left_margin
+ var
->right_margin
+ var
->hsync_len
);
680 (var
->yres
+ var
->upper_margin
+ var
->lower_margin
+ var
->vsync_len
);
682 return (vs
>= monspecs
->vfmin
&& vs
<= monspecs
->vfmax
&&
683 hs
>= monspecs
->hfmin
&& hs
<= monspecs
->hfmax
) ? 0 : -EINVAL
;
687 acornfb_update_dma(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
689 u_int off
= var
->yoffset
* info
->fix
.line_length
;
691 #if defined(HAS_MEMC)
692 memc_write(VDMA_INIT
, off
>> 2);
693 #elif defined(HAS_IOMD)
694 iomd_writel(info
->fix
.smem_start
+ off
, IOMD_VIDINIT
);
699 acornfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
705 * FIXME: Find the font height
709 var
->red
.msb_right
= 0;
710 var
->green
.msb_right
= 0;
711 var
->blue
.msb_right
= 0;
712 var
->transp
.msb_right
= 0;
714 switch (var
->bits_per_pixel
) {
715 case 1: case 2: case 4: case 8:
717 var
->red
.length
= var
->bits_per_pixel
;
718 var
->green
= var
->red
;
719 var
->blue
= var
->red
;
720 var
->transp
.offset
= 0;
721 var
->transp
.length
= 0;
728 var
->green
.offset
= 5;
729 var
->green
.length
= 5;
730 var
->blue
.offset
= 10;
731 var
->blue
.length
= 5;
732 var
->transp
.offset
= 15;
733 var
->transp
.length
= 1;
739 var
->green
.offset
= 8;
740 var
->green
.length
= 8;
741 var
->blue
.offset
= 16;
742 var
->blue
.length
= 8;
743 var
->transp
.offset
= 24;
744 var
->transp
.length
= 4;
752 * Check to see if the pixel rate is valid.
754 if (!acornfb_valid_pixrate(var
))
758 * Validate and adjust the resolution to
759 * match the video generator hardware.
761 err
= acornfb_adjust_timing(info
, var
, fontht
);
766 * Validate the timing against the
769 return acornfb_validate_timing(var
, &info
->monspecs
);
772 static int acornfb_set_par(struct fb_info
*info
)
774 switch (info
->var
.bits_per_pixel
) {
776 current_par
.palette_size
= 2;
777 info
->fix
.visual
= FB_VISUAL_MONO10
;
780 current_par
.palette_size
= 4;
781 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
784 current_par
.palette_size
= 16;
785 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
788 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
790 info
->fix
.visual
= FB_VISUAL_STATIC_PSEUDOCOLOR
;
792 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
797 current_par
.palette_size
= 32;
798 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
801 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
802 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
809 info
->fix
.line_length
= (info
->var
.xres
* info
->var
.bits_per_pixel
) / 8;
811 #if defined(HAS_MEMC)
813 unsigned long size
= info
->fix
.smem_len
- VDMA_XFERSIZE
;
815 memc_write(VDMA_START
, 0);
816 memc_write(VDMA_END
, size
>> 2);
818 #elif defined(HAS_IOMD)
820 unsigned long start
, size
;
823 start
= info
->fix
.smem_start
;
824 size
= current_par
.screen_end
;
826 if (current_par
.using_vram
) {
827 size
-= current_par
.vram_half_sam
;
828 control
= DMA_CR_E
| (current_par
.vram_half_sam
/ 256);
831 control
= DMA_CR_E
| DMA_CR_D
| 16;
834 iomd_writel(start
, IOMD_VIDSTART
);
835 iomd_writel(size
, IOMD_VIDEND
);
836 iomd_writel(control
, IOMD_VIDCR
);
840 acornfb_update_dma(info
, &info
->var
);
841 acornfb_set_timing(info
);
847 acornfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
849 u_int y_bottom
= var
->yoffset
;
851 if (!(var
->vmode
& FB_VMODE_YWRAP
))
852 y_bottom
+= var
->yres
;
854 BUG_ON(y_bottom
> var
->yres_virtual
);
856 acornfb_update_dma(info
, var
);
862 * Note that we are entered with the kernel locked.
865 acornfb_mmap(struct fb_info
*info
, struct vm_area_struct
*vma
)
867 unsigned long off
, start
;
870 off
= vma
->vm_pgoff
<< PAGE_SHIFT
;
872 start
= info
->fix
.smem_start
;
873 len
= PAGE_ALIGN(start
& ~PAGE_MASK
) + info
->fix
.smem_len
;
875 if ((vma
->vm_end
- vma
->vm_start
+ off
) > len
)
878 vma
->vm_pgoff
= off
>> PAGE_SHIFT
;
880 /* This is an IO map - tell maydump to skip this VMA */
881 vma
->vm_flags
|= VM_IO
;
883 vma
->vm_page_prot
= pgprot_writecombine(vma
->vm_page_prot
);
886 * Don't alter the page protection flags; we want to keep the area
887 * cached for better performance. This does mean that we may miss
888 * some updates to the screen occasionally, but process switches
889 * should cause the caches and buffers to be flushed often enough.
891 if (io_remap_pfn_range(vma
, vma
->vm_start
, off
>> PAGE_SHIFT
,
892 vma
->vm_end
- vma
->vm_start
,
898 static struct fb_ops acornfb_ops
= {
899 .owner
= THIS_MODULE
,
900 .fb_check_var
= acornfb_check_var
,
901 .fb_set_par
= acornfb_set_par
,
902 .fb_setcolreg
= acornfb_setcolreg
,
903 .fb_pan_display
= acornfb_pan_display
,
904 .fb_fillrect
= cfb_fillrect
,
905 .fb_copyarea
= cfb_copyarea
,
906 .fb_imageblit
= cfb_imageblit
,
907 .fb_mmap
= acornfb_mmap
,
911 * Everything after here is initialisation!!!
913 static struct fb_videomode modedb
[] __initdata
= {
914 { /* 320x256 @ 50Hz */
915 NULL
, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
916 FB_SYNC_COMP_HIGH_ACT
,
917 FB_VMODE_NONINTERLACED
918 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
919 NULL
, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
921 FB_VMODE_NONINTERLACED
922 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
923 NULL
, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
925 FB_VMODE_NONINTERLACED
926 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
927 NULL
, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
929 FB_VMODE_NONINTERLACED
930 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
931 NULL
, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
933 FB_VMODE_NONINTERLACED
934 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
935 NULL
, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
937 FB_VMODE_NONINTERLACED
938 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
939 NULL
, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
941 FB_VMODE_NONINTERLACED
942 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
943 NULL
, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
945 FB_VMODE_NONINTERLACED
946 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
947 NULL
, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
949 FB_VMODE_NONINTERLACED
950 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
951 NULL
, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
953 FB_VMODE_NONINTERLACED
954 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
955 NULL
, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
957 FB_VMODE_NONINTERLACED
958 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
959 NULL
, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
961 FB_VMODE_NONINTERLACED
965 static struct fb_videomode __initdata
966 acornfb_default_mode
= {
979 .vmode
= FB_VMODE_NONINTERLACED
982 static void __init
acornfb_init_fbinfo(void)
984 static int first
= 1;
990 fb_info
.fbops
= &acornfb_ops
;
991 fb_info
.flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
992 fb_info
.pseudo_palette
= current_par
.pseudo_palette
;
994 strcpy(fb_info
.fix
.id
, "Acorn");
995 fb_info
.fix
.type
= FB_TYPE_PACKED_PIXELS
;
996 fb_info
.fix
.type_aux
= 0;
997 fb_info
.fix
.xpanstep
= 0;
998 fb_info
.fix
.ypanstep
= 1;
999 fb_info
.fix
.ywrapstep
= 1;
1000 fb_info
.fix
.line_length
= 0;
1001 fb_info
.fix
.accel
= FB_ACCEL_NONE
;
1004 * setup initial parameters
1006 memset(&fb_info
.var
, 0, sizeof(fb_info
.var
));
1008 #if defined(HAS_VIDC20)
1009 fb_info
.var
.red
.length
= 8;
1010 fb_info
.var
.transp
.length
= 4;
1011 #elif defined(HAS_VIDC)
1012 fb_info
.var
.red
.length
= 4;
1013 fb_info
.var
.transp
.length
= 1;
1015 fb_info
.var
.green
= fb_info
.var
.red
;
1016 fb_info
.var
.blue
= fb_info
.var
.red
;
1017 fb_info
.var
.nonstd
= 0;
1018 fb_info
.var
.activate
= FB_ACTIVATE_NOW
;
1019 fb_info
.var
.height
= -1;
1020 fb_info
.var
.width
= -1;
1021 fb_info
.var
.vmode
= FB_VMODE_NONINTERLACED
;
1022 fb_info
.var
.accel_flags
= FB_ACCELF_TEXT
;
1024 current_par
.dram_size
= 0;
1025 current_par
.montype
= -1;
1026 current_par
.dpms
= 0;
1030 * setup acornfb options:
1032 * mon:hmin-hmax:vmin-vmax:dpms:width:height
1033 * Set monitor parameters:
1034 * hmin = horizontal minimum frequency (Hz)
1035 * hmax = horizontal maximum frequency (Hz) (optional)
1036 * vmin = vertical minimum frequency (Hz)
1037 * vmax = vertical maximum frequency (Hz) (optional)
1038 * dpms = DPMS supported? (optional)
1039 * width = width of picture in mm. (optional)
1040 * height = height of picture in mm. (optional)
1043 * Set RISC-OS style monitor type:
1044 * 0 (or tv) - TV frequency
1045 * 1 (or multi) - Multi frequency
1046 * 2 (or hires) - Hi-res monochrome
1048 * 4 (or svga) - SVGA
1049 * auto, or option missing
1050 * - try hardware detect
1053 * Set the amount of DRAM to use for the frame buffer
1054 * (even if you have VRAM).
1055 * size can optionally be followed by 'M' or 'K' for
1056 * MB or KB respectively.
1059 acornfb_parse_mon(char *opt
)
1063 current_par
.montype
= -2;
1065 fb_info
.monspecs
.hfmin
= simple_strtoul(p
, &p
, 0);
1067 fb_info
.monspecs
.hfmax
= simple_strtoul(p
+ 1, &p
, 0);
1069 fb_info
.monspecs
.hfmax
= fb_info
.monspecs
.hfmin
;
1074 fb_info
.monspecs
.vfmin
= simple_strtoul(p
+ 1, &p
, 0);
1076 fb_info
.monspecs
.vfmax
= simple_strtoul(p
+ 1, &p
, 0);
1078 fb_info
.monspecs
.vfmax
= fb_info
.monspecs
.vfmin
;
1083 fb_info
.monspecs
.dpms
= simple_strtoul(p
+ 1, &p
, 0);
1088 fb_info
.var
.width
= simple_strtoul(p
+ 1, &p
, 0);
1093 fb_info
.var
.height
= simple_strtoul(p
+ 1, NULL
, 0);
1096 if (fb_info
.monspecs
.hfmax
< fb_info
.monspecs
.hfmin
||
1097 fb_info
.monspecs
.vfmax
< fb_info
.monspecs
.vfmin
)
1102 printk(KERN_ERR
"Acornfb: bad monitor settings: %s\n", opt
);
1103 current_par
.montype
= -1;
1107 acornfb_parse_montype(char *opt
)
1109 current_par
.montype
= -2;
1111 if (strncmp(opt
, "tv", 2) == 0) {
1113 current_par
.montype
= 0;
1114 } else if (strncmp(opt
, "multi", 5) == 0) {
1116 current_par
.montype
= 1;
1117 } else if (strncmp(opt
, "hires", 5) == 0) {
1119 current_par
.montype
= 2;
1120 } else if (strncmp(opt
, "vga", 3) == 0) {
1122 current_par
.montype
= 3;
1123 } else if (strncmp(opt
, "svga", 4) == 0) {
1125 current_par
.montype
= 4;
1126 } else if (strncmp(opt
, "auto", 4) == 0) {
1128 current_par
.montype
= -1;
1129 } else if (isdigit(*opt
))
1130 current_par
.montype
= simple_strtoul(opt
, &opt
, 0);
1132 if (current_par
.montype
== -2 ||
1133 current_par
.montype
> NR_MONTYPES
) {
1134 printk(KERN_ERR
"acornfb: unknown monitor type: %s\n",
1136 current_par
.montype
= -1;
1139 if (strcmp(opt
, ",dpms") == 0)
1140 current_par
.dpms
= 1;
1143 "acornfb: unknown monitor option: %s\n",
1149 acornfb_parse_dram(char *opt
)
1153 size
= simple_strtoul(opt
, &opt
, 0);
1168 current_par
.dram_size
= size
;
1171 static struct options
{
1173 void (*parse
)(char *opt
);
1174 } opt_table
[] __initdata
= {
1175 { "mon", acornfb_parse_mon
},
1176 { "montype", acornfb_parse_montype
},
1177 { "dram", acornfb_parse_dram
},
1182 acornfb_setup(char *options
)
1184 struct options
*optp
;
1187 if (!options
|| !*options
)
1190 acornfb_init_fbinfo();
1192 while ((opt
= strsep(&options
, ",")) != NULL
) {
1196 for (optp
= opt_table
; optp
->name
; optp
++) {
1199 optlen
= strlen(optp
->name
);
1201 if (strncmp(opt
, optp
->name
, optlen
) == 0 &&
1202 opt
[optlen
] == ':') {
1203 optp
->parse(opt
+ optlen
+ 1);
1209 printk(KERN_ERR
"acornfb: unknown parameter: %s\n",
1216 * Detect type of monitor connected
1217 * For now, we just assume SVGA
1220 acornfb_detect_monitortype(void)
1226 * This enables the unused memory to be freed on older Acorn machines.
1227 * We are freeing memory on behalf of the architecture initialisation
1231 free_unused_pages(unsigned int virtual_start
, unsigned int virtual_end
)
1238 virtual_start
= PAGE_ALIGN(virtual_start
);
1239 virtual_end
= PAGE_ALIGN(virtual_end
);
1241 while (virtual_start
< virtual_end
) {
1245 * Clear page reserved bit,
1246 * set count to 1, and free
1249 page
= virt_to_page(virtual_start
);
1250 ClearPageReserved(page
);
1251 init_page_count(page
);
1252 free_page(virtual_start
);
1254 virtual_start
+= PAGE_SIZE
;
1255 mb_freed
+= PAGE_SIZE
/ 1024;
1258 printk("acornfb: freed %dK memory\n", mb_freed
);
1261 static int __init
acornfb_probe(struct platform_device
*dev
)
1264 u_int h_sync
, v_sync
;
1266 char *option
= NULL
;
1268 if (fb_get_options("acornfb", &option
))
1270 acornfb_setup(option
);
1272 acornfb_init_fbinfo();
1274 current_par
.dev
= &dev
->dev
;
1276 if (current_par
.montype
== -1)
1277 current_par
.montype
= acornfb_detect_monitortype();
1279 if (current_par
.montype
== -1 || current_par
.montype
> NR_MONTYPES
)
1280 current_par
.montype
= 4;
1282 if (current_par
.montype
>= 0) {
1283 fb_info
.monspecs
= monspecs
[current_par
.montype
];
1284 fb_info
.monspecs
.dpms
= current_par
.dpms
;
1288 * Try to select a suitable default mode
1290 for (i
= 0; i
< ARRAY_SIZE(modedb
); i
++) {
1293 hs
= modedb
[i
].refresh
*
1294 (modedb
[i
].yres
+ modedb
[i
].upper_margin
+
1295 modedb
[i
].lower_margin
+ modedb
[i
].vsync_len
);
1296 if (modedb
[i
].xres
== DEFAULT_XRES
&&
1297 modedb
[i
].yres
== DEFAULT_YRES
&&
1298 modedb
[i
].refresh
>= fb_info
.monspecs
.vfmin
&&
1299 modedb
[i
].refresh
<= fb_info
.monspecs
.vfmax
&&
1300 hs
>= fb_info
.monspecs
.hfmin
&&
1301 hs
<= fb_info
.monspecs
.hfmax
) {
1302 acornfb_default_mode
= modedb
[i
];
1307 fb_info
.screen_base
= (char *)SCREEN_BASE
;
1308 fb_info
.fix
.smem_start
= SCREEN_START
;
1309 current_par
.using_vram
= 0;
1312 * If vram_size is set, we are using VRAM in
1313 * a Risc PC. However, if the user has specified
1314 * an amount of DRAM then use that instead.
1316 if (vram_size
&& !current_par
.dram_size
) {
1318 current_par
.vram_half_sam
= vram_size
/ 1024;
1319 current_par
.using_vram
= 1;
1320 } else if (current_par
.dram_size
)
1321 size
= current_par
.dram_size
;
1326 * Limit maximum screen size.
1328 if (size
> MAX_SIZE
)
1331 size
= PAGE_ALIGN(size
);
1333 #if defined(HAS_VIDC20)
1334 if (!current_par
.using_vram
) {
1339 * RiscPC needs to allocate the DRAM memory
1340 * for the framebuffer if we are not using
1343 base
= dma_alloc_writecombine(current_par
.dev
, size
, &handle
,
1346 printk(KERN_ERR
"acornfb: unable to allocate screen "
1351 fb_info
.screen_base
= base
;
1352 fb_info
.fix
.smem_start
= handle
;
1355 #if defined(HAS_VIDC)
1357 * Archimedes/A5000 machines use a fixed address for their
1358 * framebuffers. Free unused pages
1360 free_unused_pages(PAGE_OFFSET
+ size
, PAGE_OFFSET
+ MAX_SIZE
);
1363 fb_info
.fix
.smem_len
= size
;
1364 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1367 * Lookup the timing for this resolution. If we can't
1368 * find it, then we can't restore it if we change
1369 * the resolution, so we disable this feature.
1372 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1374 &acornfb_default_mode
, DEFAULT_BPP
);
1376 * If we found an exact match, all ok.
1381 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1382 &acornfb_default_mode
, DEFAULT_BPP
);
1384 * If we found an exact match, all ok.
1389 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1391 &acornfb_default_mode
, DEFAULT_BPP
);
1395 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1396 &acornfb_default_mode
, DEFAULT_BPP
);
1400 * If we didn't find an exact match, try the
1404 printk("Acornfb: no valid mode found\n");
1408 h_sync
= 1953125000 / fb_info
.var
.pixclock
;
1409 h_sync
= h_sync
* 512 / (fb_info
.var
.xres
+ fb_info
.var
.left_margin
+
1410 fb_info
.var
.right_margin
+ fb_info
.var
.hsync_len
);
1411 v_sync
= h_sync
/ (fb_info
.var
.yres
+ fb_info
.var
.upper_margin
+
1412 fb_info
.var
.lower_margin
+ fb_info
.var
.vsync_len
);
1414 printk(KERN_INFO
"Acornfb: %dkB %cRAM, %s, using %dx%d, "
1415 "%d.%03dkHz, %dHz\n",
1416 fb_info
.fix
.smem_len
/ 1024,
1417 current_par
.using_vram
? 'V' : 'D',
1418 VIDC_NAME
, fb_info
.var
.xres
, fb_info
.var
.yres
,
1419 h_sync
/ 1000, h_sync
% 1000, v_sync
);
1421 printk(KERN_INFO
"Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1422 fb_info
.monspecs
.hfmin
/ 1000, fb_info
.monspecs
.hfmin
% 1000,
1423 fb_info
.monspecs
.hfmax
/ 1000, fb_info
.monspecs
.hfmax
% 1000,
1424 fb_info
.monspecs
.vfmin
, fb_info
.monspecs
.vfmax
,
1425 fb_info
.monspecs
.dpms
? ", DPMS" : "");
1427 if (fb_set_var(&fb_info
, &fb_info
.var
))
1428 printk(KERN_ERR
"Acornfb: unable to set display parameters\n");
1430 if (register_framebuffer(&fb_info
) < 0)
1435 static struct platform_driver acornfb_driver
= {
1436 .probe
= acornfb_probe
,
1442 static int __init
acornfb_init(void)
1444 return platform_driver_register(&acornfb_driver
);
1447 module_init(acornfb_init
);
1449 MODULE_AUTHOR("Russell King");
1450 MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
1451 MODULE_LICENSE("GPL");