1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/acornfb.c
5 * Copyright (C) 1998-2001 Russell King
7 * Frame buffer code for Acorn platforms
9 * NOTE: Most of the modes with X!=640 will disappear shortly.
10 * NOTE: Startup setting of HS & VS polarity not supported.
11 * (do we need to support it if we're coming up in 640x480?)
13 * FIXME: (things broken by the "new improved" FBCON API)
14 * - Blanking 8bpp displays with VIDC
17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/string.h>
21 #include <linux/ctype.h>
23 #include <linux/init.h>
25 #include <linux/platform_device.h>
26 #include <linux/dma-mapping.h>
28 #include <linux/gfp.h>
30 #include <mach/hardware.h>
32 #include <asm/mach-types.h>
38 * NOTE that it has to be supported in the table towards
39 * the end of this file.
41 #define DEFAULT_XRES 640
42 #define DEFAULT_YRES 480
46 * define this to debug the video mode selection
48 #undef DEBUG_MODE_SELECTION
51 * Translation from RISC OS monitor types to actual
52 * HSYNC and VSYNC frequency ranges. These are
53 * probably not right, but they're the best info I
54 * have. Allow 1% either way on the nominal for TVs.
57 static struct fb_monspecs monspecs
[NR_MONTYPES
] = {
68 }, { /* Hi-res mono */
91 static struct fb_info fb_info
;
92 static struct acornfb_par current_par
;
93 static struct vidc_timing current_vidc
;
95 extern unsigned int vram_size
; /* set by setup.c */
98 #include <mach/acornfb.h>
100 #define MAX_SIZE (2*1024*1024)
102 /* VIDC20 has a different set of rules from the VIDC:
103 * hcr : must be multiple of 4
104 * hswr : must be even
105 * hdsr : must be even
106 * hder : must be even
107 * vcr : >= 2, (interlace, must be odd)
112 static void acornfb_set_timing(struct fb_info
*info
)
114 struct fb_var_screeninfo
*var
= &info
->var
;
115 struct vidc_timing vidc
;
117 u_int ext_ctl
, dat_ctl
;
118 u_int words_per_line
;
120 memset(&vidc
, 0, sizeof(vidc
));
122 vidc
.h_sync_width
= var
->hsync_len
- 8;
123 vidc
.h_border_start
= vidc
.h_sync_width
+ var
->left_margin
+ 8 - 12;
124 vidc
.h_display_start
= vidc
.h_border_start
+ 12 - 18;
125 vidc
.h_display_end
= vidc
.h_display_start
+ var
->xres
;
126 vidc
.h_border_end
= vidc
.h_display_end
+ 18 - 12;
127 vidc
.h_cycle
= vidc
.h_border_end
+ var
->right_margin
+ 12 - 8;
128 vidc
.h_interlace
= vidc
.h_cycle
/ 2;
129 vidc
.v_sync_width
= var
->vsync_len
- 1;
130 vidc
.v_border_start
= vidc
.v_sync_width
+ var
->upper_margin
;
131 vidc
.v_display_start
= vidc
.v_border_start
;
132 vidc
.v_display_end
= vidc
.v_display_start
+ var
->yres
;
133 vidc
.v_border_end
= vidc
.v_display_end
;
134 vidc
.control
= acornfb_default_control();
136 vcr
= var
->vsync_len
+ var
->upper_margin
+ var
->yres
+
139 if ((var
->vmode
& FB_VMODE_MASK
) == FB_VMODE_INTERLACED
) {
140 vidc
.v_cycle
= (vcr
- 3) / 2;
141 vidc
.control
|= VIDC20_CTRL_INT
;
143 vidc
.v_cycle
= vcr
- 2;
145 switch (var
->bits_per_pixel
) {
146 case 1: vidc
.control
|= VIDC20_CTRL_1BPP
; break;
147 case 2: vidc
.control
|= VIDC20_CTRL_2BPP
; break;
148 case 4: vidc
.control
|= VIDC20_CTRL_4BPP
; break;
150 case 8: vidc
.control
|= VIDC20_CTRL_8BPP
; break;
151 case 16: vidc
.control
|= VIDC20_CTRL_16BPP
; break;
152 case 32: vidc
.control
|= VIDC20_CTRL_32BPP
; break;
155 acornfb_vidc20_find_rates(&vidc
, var
);
156 fsize
= var
->vsync_len
+ var
->upper_margin
+ var
->lower_margin
- 1;
158 if (memcmp(¤t_vidc
, &vidc
, sizeof(vidc
))) {
161 vidc_writel(VIDC20_CTRL
| vidc
.control
);
162 vidc_writel(0xd0000000 | vidc
.pll_ctl
);
163 vidc_writel(0x80000000 | vidc
.h_cycle
);
164 vidc_writel(0x81000000 | vidc
.h_sync_width
);
165 vidc_writel(0x82000000 | vidc
.h_border_start
);
166 vidc_writel(0x83000000 | vidc
.h_display_start
);
167 vidc_writel(0x84000000 | vidc
.h_display_end
);
168 vidc_writel(0x85000000 | vidc
.h_border_end
);
169 vidc_writel(0x86000000);
170 vidc_writel(0x87000000 | vidc
.h_interlace
);
171 vidc_writel(0x90000000 | vidc
.v_cycle
);
172 vidc_writel(0x91000000 | vidc
.v_sync_width
);
173 vidc_writel(0x92000000 | vidc
.v_border_start
);
174 vidc_writel(0x93000000 | vidc
.v_display_start
);
175 vidc_writel(0x94000000 | vidc
.v_display_end
);
176 vidc_writel(0x95000000 | vidc
.v_border_end
);
177 vidc_writel(0x96000000);
178 vidc_writel(0x97000000);
181 iomd_writel(fsize
, IOMD_FSIZE
);
183 ext_ctl
= acornfb_default_econtrol();
185 if (var
->sync
& FB_SYNC_COMP_HIGH_ACT
) /* should be FB_SYNC_COMP */
186 ext_ctl
|= VIDC20_ECTL_HS_NCSYNC
| VIDC20_ECTL_VS_NCSYNC
;
188 if (var
->sync
& FB_SYNC_HOR_HIGH_ACT
)
189 ext_ctl
|= VIDC20_ECTL_HS_HSYNC
;
191 ext_ctl
|= VIDC20_ECTL_HS_NHSYNC
;
193 if (var
->sync
& FB_SYNC_VERT_HIGH_ACT
)
194 ext_ctl
|= VIDC20_ECTL_VS_VSYNC
;
196 ext_ctl
|= VIDC20_ECTL_VS_NVSYNC
;
199 vidc_writel(VIDC20_ECTL
| ext_ctl
);
201 words_per_line
= var
->xres
* var
->bits_per_pixel
/ 32;
203 if (current_par
.using_vram
&& info
->fix
.smem_len
== 2048*1024)
206 /* RiscPC doesn't use the VIDC's VRAM control. */
207 dat_ctl
= VIDC20_DCTL_VRAM_DIS
| VIDC20_DCTL_SNA
| words_per_line
;
209 /* The data bus width is dependent on both the type
210 * and amount of video memory.
215 if (current_par
.using_vram
&& current_par
.vram_half_sam
== 2048)
216 dat_ctl
|= VIDC20_DCTL_BUS_D63_0
;
218 dat_ctl
|= VIDC20_DCTL_BUS_D31_0
;
220 vidc_writel(VIDC20_DCTL
| dat_ctl
);
222 #ifdef DEBUG_MODE_SELECTION
223 printk(KERN_DEBUG
"VIDC registers for %dx%dx%d:\n", var
->xres
,
224 var
->yres
, var
->bits_per_pixel
);
225 printk(KERN_DEBUG
" H-cycle : %d\n", vidc
.h_cycle
);
226 printk(KERN_DEBUG
" H-sync-width : %d\n", vidc
.h_sync_width
);
227 printk(KERN_DEBUG
" H-border-start : %d\n", vidc
.h_border_start
);
228 printk(KERN_DEBUG
" H-display-start : %d\n", vidc
.h_display_start
);
229 printk(KERN_DEBUG
" H-display-end : %d\n", vidc
.h_display_end
);
230 printk(KERN_DEBUG
" H-border-end : %d\n", vidc
.h_border_end
);
231 printk(KERN_DEBUG
" H-interlace : %d\n", vidc
.h_interlace
);
232 printk(KERN_DEBUG
" V-cycle : %d\n", vidc
.v_cycle
);
233 printk(KERN_DEBUG
" V-sync-width : %d\n", vidc
.v_sync_width
);
234 printk(KERN_DEBUG
" V-border-start : %d\n", vidc
.v_border_start
);
235 printk(KERN_DEBUG
" V-display-start : %d\n", vidc
.v_display_start
);
236 printk(KERN_DEBUG
" V-display-end : %d\n", vidc
.v_display_end
);
237 printk(KERN_DEBUG
" V-border-end : %d\n", vidc
.v_border_end
);
238 printk(KERN_DEBUG
" Ext Ctrl (C) : 0x%08X\n", ext_ctl
);
239 printk(KERN_DEBUG
" PLL Ctrl (D) : 0x%08X\n", vidc
.pll_ctl
);
240 printk(KERN_DEBUG
" Ctrl (E) : 0x%08X\n", vidc
.control
);
241 printk(KERN_DEBUG
" Data Ctrl (F) : 0x%08X\n", dat_ctl
);
242 printk(KERN_DEBUG
" Fsize : 0x%08X\n", fsize
);
247 * We have to take note of the VIDC20's 16-bit palette here.
248 * The VIDC20 looks up a 16 bit pixel as follows:
252 * red ++++++++ (8 bits, 7 to 0)
253 * green ++++++++ (8 bits, 11 to 4)
254 * blue ++++++++ (8 bits, 15 to 8)
256 * We use a pixel which looks like:
260 * red +++++ (5 bits, 4 to 0)
261 * green +++++ (5 bits, 9 to 5)
262 * blue +++++ (5 bits, 14 to 10)
265 acornfb_setcolreg(u_int regno
, u_int red
, u_int green
, u_int blue
,
266 u_int trans
, struct fb_info
*info
)
270 if (regno
>= current_par
.palette_size
)
273 if (regno
< 16 && info
->fix
.visual
== FB_VISUAL_DIRECTCOLOR
) {
276 pseudo_val
= regno
<< info
->var
.red
.offset
;
277 pseudo_val
|= regno
<< info
->var
.green
.offset
;
278 pseudo_val
|= regno
<< info
->var
.blue
.offset
;
280 ((u32
*)info
->pseudo_palette
)[regno
] = pseudo_val
;
284 pal
.vidc20
.red
= red
>> 8;
285 pal
.vidc20
.green
= green
>> 8;
286 pal
.vidc20
.blue
= blue
>> 8;
288 current_par
.palette
[regno
] = pal
;
290 if (info
->var
.bits_per_pixel
== 16) {
294 vidc_writel(0x10000000);
295 for (i
= 0; i
< 256; i
+= 1) {
296 pal
.vidc20
.red
= current_par
.palette
[i
& 31].vidc20
.red
;
297 pal
.vidc20
.green
= current_par
.palette
[(i
>> 1) & 31].vidc20
.green
;
298 pal
.vidc20
.blue
= current_par
.palette
[(i
>> 2) & 31].vidc20
.blue
;
300 /* Palette register pointer auto-increments */
303 vidc_writel(0x10000000 | regno
);
312 * Before selecting the timing parameters, adjust
313 * the resolution to fit the rules.
316 acornfb_adjust_timing(struct fb_info
*info
, struct fb_var_screeninfo
*var
, u_int fontht
)
318 u_int font_line_len
, sam_size
, min_size
, size
, nr_y
;
320 /* xres must be even */
321 var
->xres
= (var
->xres
+ 1) & ~1;
324 * We don't allow xres_virtual to differ from xres
326 var
->xres_virtual
= var
->xres
;
329 if (current_par
.using_vram
)
330 sam_size
= current_par
.vram_half_sam
* 2;
335 * Now, find a value for yres_virtual which allows
336 * us to do ywrap scrolling. The value of
337 * yres_virtual must be such that the end of the
338 * displayable frame buffer must be aligned with
339 * the start of a font line.
341 font_line_len
= var
->xres
* var
->bits_per_pixel
* fontht
/ 8;
342 min_size
= var
->xres
* var
->yres
* var
->bits_per_pixel
/ 8;
345 * If minimum screen size is greater than that we have
346 * available, reject it.
348 if (min_size
> info
->fix
.smem_len
)
351 /* Find int 'y', such that y * fll == s * sam < maxsize
352 * y = s * sam / fll; s = maxsize / sam
354 for (size
= info
->fix
.smem_len
;
355 nr_y
= size
/ font_line_len
, min_size
<= size
;
357 if (nr_y
* font_line_len
== size
)
362 if (var
->accel_flags
& FB_ACCELF_TEXT
) {
363 if (min_size
> size
) {
367 size
= info
->fix
.smem_len
;
368 var
->yres_virtual
= size
/ (font_line_len
/ fontht
);
370 var
->yres_virtual
= nr_y
;
371 } else if (var
->yres_virtual
> nr_y
)
372 var
->yres_virtual
= nr_y
;
374 current_par
.screen_end
= info
->fix
.smem_start
+ size
;
377 * Fix yres & yoffset if needed.
379 if (var
->yres
> var
->yres_virtual
)
380 var
->yres
= var
->yres_virtual
;
382 if (var
->vmode
& FB_VMODE_YWRAP
) {
383 if (var
->yoffset
> var
->yres_virtual
)
384 var
->yoffset
= var
->yres_virtual
;
386 if (var
->yoffset
+ var
->yres
> var
->yres_virtual
)
387 var
->yoffset
= var
->yres_virtual
- var
->yres
;
390 /* hsync_len must be even */
391 var
->hsync_len
= (var
->hsync_len
+ 1) & ~1;
393 #if defined(HAS_VIDC20)
394 /* left_margin must be even */
395 if (var
->left_margin
& 1) {
396 var
->left_margin
+= 1;
397 var
->right_margin
-= 1;
400 /* right_margin must be even */
401 if (var
->right_margin
& 1)
402 var
->right_margin
+= 1;
405 if (var
->vsync_len
< 1)
412 acornfb_validate_timing(struct fb_var_screeninfo
*var
,
413 struct fb_monspecs
*monspecs
)
415 unsigned long hs
, vs
;
418 * hs(Hz) = 10^12 / (pixclock * xtotal)
419 * vs(Hz) = hs(Hz) / ytotal
421 * No need to do long long divisions or anything
422 * like that if you factor it correctly
424 hs
= 1953125000 / var
->pixclock
;
426 (var
->xres
+ var
->left_margin
+ var
->right_margin
+ var
->hsync_len
);
428 (var
->yres
+ var
->upper_margin
+ var
->lower_margin
+ var
->vsync_len
);
430 return (vs
>= monspecs
->vfmin
&& vs
<= monspecs
->vfmax
&&
431 hs
>= monspecs
->hfmin
&& hs
<= monspecs
->hfmax
) ? 0 : -EINVAL
;
435 acornfb_update_dma(struct fb_info
*info
, struct fb_var_screeninfo
*var
)
437 u_int off
= var
->yoffset
* info
->fix
.line_length
;
439 #if defined(HAS_MEMC)
440 memc_write(VDMA_INIT
, off
>> 2);
441 #elif defined(HAS_IOMD)
442 iomd_writel(info
->fix
.smem_start
+ off
, IOMD_VIDINIT
);
447 acornfb_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
453 * FIXME: Find the font height
457 var
->red
.msb_right
= 0;
458 var
->green
.msb_right
= 0;
459 var
->blue
.msb_right
= 0;
460 var
->transp
.msb_right
= 0;
462 switch (var
->bits_per_pixel
) {
463 case 1: case 2: case 4: case 8:
465 var
->red
.length
= var
->bits_per_pixel
;
466 var
->green
= var
->red
;
467 var
->blue
= var
->red
;
468 var
->transp
.offset
= 0;
469 var
->transp
.length
= 0;
476 var
->green
.offset
= 5;
477 var
->green
.length
= 5;
478 var
->blue
.offset
= 10;
479 var
->blue
.length
= 5;
480 var
->transp
.offset
= 15;
481 var
->transp
.length
= 1;
487 var
->green
.offset
= 8;
488 var
->green
.length
= 8;
489 var
->blue
.offset
= 16;
490 var
->blue
.length
= 8;
491 var
->transp
.offset
= 24;
492 var
->transp
.length
= 4;
500 * Check to see if the pixel rate is valid.
502 if (!acornfb_valid_pixrate(var
))
506 * Validate and adjust the resolution to
507 * match the video generator hardware.
509 err
= acornfb_adjust_timing(info
, var
, fontht
);
514 * Validate the timing against the
517 return acornfb_validate_timing(var
, &info
->monspecs
);
520 static int acornfb_set_par(struct fb_info
*info
)
522 switch (info
->var
.bits_per_pixel
) {
524 current_par
.palette_size
= 2;
525 info
->fix
.visual
= FB_VISUAL_MONO10
;
528 current_par
.palette_size
= 4;
529 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
532 current_par
.palette_size
= 16;
533 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
536 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
537 info
->fix
.visual
= FB_VISUAL_PSEUDOCOLOR
;
541 current_par
.palette_size
= 32;
542 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
545 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
546 info
->fix
.visual
= FB_VISUAL_DIRECTCOLOR
;
553 info
->fix
.line_length
= (info
->var
.xres
* info
->var
.bits_per_pixel
) / 8;
555 #if defined(HAS_MEMC)
557 unsigned long size
= info
->fix
.smem_len
- VDMA_XFERSIZE
;
559 memc_write(VDMA_START
, 0);
560 memc_write(VDMA_END
, size
>> 2);
562 #elif defined(HAS_IOMD)
564 unsigned long start
, size
;
567 start
= info
->fix
.smem_start
;
568 size
= current_par
.screen_end
;
570 if (current_par
.using_vram
) {
571 size
-= current_par
.vram_half_sam
;
572 control
= DMA_CR_E
| (current_par
.vram_half_sam
/ 256);
575 control
= DMA_CR_E
| DMA_CR_D
| 16;
578 iomd_writel(start
, IOMD_VIDSTART
);
579 iomd_writel(size
, IOMD_VIDEND
);
580 iomd_writel(control
, IOMD_VIDCR
);
584 acornfb_update_dma(info
, &info
->var
);
585 acornfb_set_timing(info
);
591 acornfb_pan_display(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
593 u_int y_bottom
= var
->yoffset
;
595 if (!(var
->vmode
& FB_VMODE_YWRAP
))
596 y_bottom
+= info
->var
.yres
;
598 if (y_bottom
> info
->var
.yres_virtual
)
601 acornfb_update_dma(info
, var
);
606 static const struct fb_ops acornfb_ops
= {
607 .owner
= THIS_MODULE
,
608 .fb_check_var
= acornfb_check_var
,
609 .fb_set_par
= acornfb_set_par
,
610 .fb_setcolreg
= acornfb_setcolreg
,
611 .fb_pan_display
= acornfb_pan_display
,
612 .fb_fillrect
= cfb_fillrect
,
613 .fb_copyarea
= cfb_copyarea
,
614 .fb_imageblit
= cfb_imageblit
,
618 * Everything after here is initialisation!!!
620 static struct fb_videomode modedb
[] = {
621 { /* 320x256 @ 50Hz */
622 NULL
, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
623 FB_SYNC_COMP_HIGH_ACT
,
624 FB_VMODE_NONINTERLACED
625 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
626 NULL
, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
628 FB_VMODE_NONINTERLACED
629 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
630 NULL
, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
632 FB_VMODE_NONINTERLACED
633 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
634 NULL
, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
636 FB_VMODE_NONINTERLACED
637 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
638 NULL
, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
640 FB_VMODE_NONINTERLACED
641 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
642 NULL
, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
644 FB_VMODE_NONINTERLACED
645 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
646 NULL
, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
648 FB_VMODE_NONINTERLACED
649 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
650 NULL
, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
652 FB_VMODE_NONINTERLACED
653 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
654 NULL
, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
656 FB_VMODE_NONINTERLACED
657 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
658 NULL
, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
660 FB_VMODE_NONINTERLACED
661 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
662 NULL
, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
664 FB_VMODE_NONINTERLACED
665 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
666 NULL
, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
668 FB_VMODE_NONINTERLACED
672 static struct fb_videomode acornfb_default_mode
= {
685 .vmode
= FB_VMODE_NONINTERLACED
688 static void acornfb_init_fbinfo(void)
690 static int first
= 1;
696 fb_info
.fbops
= &acornfb_ops
;
697 fb_info
.flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
698 fb_info
.pseudo_palette
= current_par
.pseudo_palette
;
700 strcpy(fb_info
.fix
.id
, "Acorn");
701 fb_info
.fix
.type
= FB_TYPE_PACKED_PIXELS
;
702 fb_info
.fix
.type_aux
= 0;
703 fb_info
.fix
.xpanstep
= 0;
704 fb_info
.fix
.ypanstep
= 1;
705 fb_info
.fix
.ywrapstep
= 1;
706 fb_info
.fix
.line_length
= 0;
707 fb_info
.fix
.accel
= FB_ACCEL_NONE
;
710 * setup initial parameters
712 memset(&fb_info
.var
, 0, sizeof(fb_info
.var
));
714 #if defined(HAS_VIDC20)
715 fb_info
.var
.red
.length
= 8;
716 fb_info
.var
.transp
.length
= 4;
718 fb_info
.var
.green
= fb_info
.var
.red
;
719 fb_info
.var
.blue
= fb_info
.var
.red
;
720 fb_info
.var
.nonstd
= 0;
721 fb_info
.var
.activate
= FB_ACTIVATE_NOW
;
722 fb_info
.var
.height
= -1;
723 fb_info
.var
.width
= -1;
724 fb_info
.var
.vmode
= FB_VMODE_NONINTERLACED
;
725 fb_info
.var
.accel_flags
= FB_ACCELF_TEXT
;
727 current_par
.dram_size
= 0;
728 current_par
.montype
= -1;
729 current_par
.dpms
= 0;
733 * setup acornfb options:
735 * mon:hmin-hmax:vmin-vmax:dpms:width:height
736 * Set monitor parameters:
737 * hmin = horizontal minimum frequency (Hz)
738 * hmax = horizontal maximum frequency (Hz) (optional)
739 * vmin = vertical minimum frequency (Hz)
740 * vmax = vertical maximum frequency (Hz) (optional)
741 * dpms = DPMS supported? (optional)
742 * width = width of picture in mm. (optional)
743 * height = height of picture in mm. (optional)
746 * Set RISC-OS style monitor type:
747 * 0 (or tv) - TV frequency
748 * 1 (or multi) - Multi frequency
749 * 2 (or hires) - Hi-res monochrome
752 * auto, or option missing
753 * - try hardware detect
756 * Set the amount of DRAM to use for the frame buffer
757 * (even if you have VRAM).
758 * size can optionally be followed by 'M' or 'K' for
759 * MB or KB respectively.
761 static void acornfb_parse_mon(char *opt
)
765 current_par
.montype
= -2;
767 fb_info
.monspecs
.hfmin
= simple_strtoul(p
, &p
, 0);
769 fb_info
.monspecs
.hfmax
= simple_strtoul(p
+ 1, &p
, 0);
771 fb_info
.monspecs
.hfmax
= fb_info
.monspecs
.hfmin
;
776 fb_info
.monspecs
.vfmin
= simple_strtoul(p
+ 1, &p
, 0);
778 fb_info
.monspecs
.vfmax
= simple_strtoul(p
+ 1, &p
, 0);
780 fb_info
.monspecs
.vfmax
= fb_info
.monspecs
.vfmin
;
785 fb_info
.monspecs
.dpms
= simple_strtoul(p
+ 1, &p
, 0);
790 fb_info
.var
.width
= simple_strtoul(p
+ 1, &p
, 0);
795 fb_info
.var
.height
= simple_strtoul(p
+ 1, NULL
, 0);
798 if (fb_info
.monspecs
.hfmax
< fb_info
.monspecs
.hfmin
||
799 fb_info
.monspecs
.vfmax
< fb_info
.monspecs
.vfmin
)
804 printk(KERN_ERR
"Acornfb: bad monitor settings: %s\n", opt
);
805 current_par
.montype
= -1;
808 static void acornfb_parse_montype(char *opt
)
810 current_par
.montype
= -2;
812 if (strncmp(opt
, "tv", 2) == 0) {
814 current_par
.montype
= 0;
815 } else if (strncmp(opt
, "multi", 5) == 0) {
817 current_par
.montype
= 1;
818 } else if (strncmp(opt
, "hires", 5) == 0) {
820 current_par
.montype
= 2;
821 } else if (strncmp(opt
, "vga", 3) == 0) {
823 current_par
.montype
= 3;
824 } else if (strncmp(opt
, "svga", 4) == 0) {
826 current_par
.montype
= 4;
827 } else if (strncmp(opt
, "auto", 4) == 0) {
829 current_par
.montype
= -1;
830 } else if (isdigit(*opt
))
831 current_par
.montype
= simple_strtoul(opt
, &opt
, 0);
833 if (current_par
.montype
== -2 ||
834 current_par
.montype
> NR_MONTYPES
) {
835 printk(KERN_ERR
"acornfb: unknown monitor type: %s\n",
837 current_par
.montype
= -1;
840 if (strcmp(opt
, ",dpms") == 0)
841 current_par
.dpms
= 1;
844 "acornfb: unknown monitor option: %s\n",
849 static void acornfb_parse_dram(char *opt
)
853 size
= simple_strtoul(opt
, &opt
, 0);
869 current_par
.dram_size
= size
;
872 static struct options
{
874 void (*parse
)(char *opt
);
876 { "mon", acornfb_parse_mon
},
877 { "montype", acornfb_parse_montype
},
878 { "dram", acornfb_parse_dram
},
882 static int acornfb_setup(char *options
)
884 struct options
*optp
;
887 if (!options
|| !*options
)
890 acornfb_init_fbinfo();
892 while ((opt
= strsep(&options
, ",")) != NULL
) {
896 for (optp
= opt_table
; optp
->name
; optp
++) {
899 optlen
= strlen(optp
->name
);
901 if (strncmp(opt
, optp
->name
, optlen
) == 0 &&
902 opt
[optlen
] == ':') {
903 optp
->parse(opt
+ optlen
+ 1);
909 printk(KERN_ERR
"acornfb: unknown parameter: %s\n",
916 * Detect type of monitor connected
917 * For now, we just assume SVGA
919 static int acornfb_detect_monitortype(void)
925 * This enables the unused memory to be freed on older Acorn machines.
926 * We are freeing memory on behalf of the architecture initialisation
930 free_unused_pages(unsigned int virtual_start
, unsigned int virtual_end
)
937 virtual_start
= PAGE_ALIGN(virtual_start
);
938 virtual_end
= PAGE_ALIGN(virtual_end
);
940 while (virtual_start
< virtual_end
) {
944 * Clear page reserved bit,
945 * set count to 1, and free
948 page
= virt_to_page(virtual_start
);
949 __free_reserved_page(page
);
951 virtual_start
+= PAGE_SIZE
;
952 mb_freed
+= PAGE_SIZE
/ 1024;
955 printk("acornfb: freed %dK memory\n", mb_freed
);
958 static int acornfb_probe(struct platform_device
*dev
)
961 u_int h_sync
, v_sync
;
965 if (fb_get_options("acornfb", &option
))
967 acornfb_setup(option
);
969 acornfb_init_fbinfo();
971 current_par
.dev
= &dev
->dev
;
973 if (current_par
.montype
== -1)
974 current_par
.montype
= acornfb_detect_monitortype();
976 if (current_par
.montype
== -1 || current_par
.montype
> NR_MONTYPES
)
977 current_par
.montype
= 4;
979 if (current_par
.montype
>= 0) {
980 fb_info
.monspecs
= monspecs
[current_par
.montype
];
981 fb_info
.monspecs
.dpms
= current_par
.dpms
;
985 * Try to select a suitable default mode
987 for (i
= 0; i
< ARRAY_SIZE(modedb
); i
++) {
990 hs
= modedb
[i
].refresh
*
991 (modedb
[i
].yres
+ modedb
[i
].upper_margin
+
992 modedb
[i
].lower_margin
+ modedb
[i
].vsync_len
);
993 if (modedb
[i
].xres
== DEFAULT_XRES
&&
994 modedb
[i
].yres
== DEFAULT_YRES
&&
995 modedb
[i
].refresh
>= fb_info
.monspecs
.vfmin
&&
996 modedb
[i
].refresh
<= fb_info
.monspecs
.vfmax
&&
997 hs
>= fb_info
.monspecs
.hfmin
&&
998 hs
<= fb_info
.monspecs
.hfmax
) {
999 acornfb_default_mode
= modedb
[i
];
1004 fb_info
.screen_base
= (char *)SCREEN_BASE
;
1005 fb_info
.fix
.smem_start
= SCREEN_START
;
1006 current_par
.using_vram
= 0;
1009 * If vram_size is set, we are using VRAM in
1010 * a Risc PC. However, if the user has specified
1011 * an amount of DRAM then use that instead.
1013 if (vram_size
&& !current_par
.dram_size
) {
1015 current_par
.vram_half_sam
= vram_size
/ 1024;
1016 current_par
.using_vram
= 1;
1017 } else if (current_par
.dram_size
)
1018 size
= current_par
.dram_size
;
1023 * Limit maximum screen size.
1025 if (size
> MAX_SIZE
)
1028 size
= PAGE_ALIGN(size
);
1030 #if defined(HAS_VIDC20)
1031 if (!current_par
.using_vram
) {
1036 * RiscPC needs to allocate the DRAM memory
1037 * for the framebuffer if we are not using
1040 base
= dma_alloc_wc(current_par
.dev
, size
, &handle
,
1043 printk(KERN_ERR
"acornfb: unable to allocate screen memory\n");
1047 fb_info
.screen_base
= base
;
1048 fb_info
.fix
.smem_start
= handle
;
1051 fb_info
.fix
.smem_len
= size
;
1052 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1055 * Lookup the timing for this resolution. If we can't
1056 * find it, then we can't restore it if we change
1057 * the resolution, so we disable this feature.
1060 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1062 &acornfb_default_mode
, DEFAULT_BPP
);
1064 * If we found an exact match, all ok.
1069 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1070 &acornfb_default_mode
, DEFAULT_BPP
);
1072 * If we found an exact match, all ok.
1077 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1079 &acornfb_default_mode
, DEFAULT_BPP
);
1083 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1084 &acornfb_default_mode
, DEFAULT_BPP
);
1088 * If we didn't find an exact match, try the
1092 printk("Acornfb: no valid mode found\n");
1096 h_sync
= 1953125000 / fb_info
.var
.pixclock
;
1097 h_sync
= h_sync
* 512 / (fb_info
.var
.xres
+ fb_info
.var
.left_margin
+
1098 fb_info
.var
.right_margin
+ fb_info
.var
.hsync_len
);
1099 v_sync
= h_sync
/ (fb_info
.var
.yres
+ fb_info
.var
.upper_margin
+
1100 fb_info
.var
.lower_margin
+ fb_info
.var
.vsync_len
);
1102 printk(KERN_INFO
"Acornfb: %dkB %cRAM, %s, using %dx%d, %d.%03dkHz, %dHz\n",
1103 fb_info
.fix
.smem_len
/ 1024,
1104 current_par
.using_vram
? 'V' : 'D',
1105 VIDC_NAME
, fb_info
.var
.xres
, fb_info
.var
.yres
,
1106 h_sync
/ 1000, h_sync
% 1000, v_sync
);
1108 printk(KERN_INFO
"Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1109 fb_info
.monspecs
.hfmin
/ 1000, fb_info
.monspecs
.hfmin
% 1000,
1110 fb_info
.monspecs
.hfmax
/ 1000, fb_info
.monspecs
.hfmax
% 1000,
1111 fb_info
.monspecs
.vfmin
, fb_info
.monspecs
.vfmax
,
1112 fb_info
.monspecs
.dpms
? ", DPMS" : "");
1114 if (fb_set_var(&fb_info
, &fb_info
.var
))
1115 printk(KERN_ERR
"Acornfb: unable to set display parameters\n");
1117 if (register_framebuffer(&fb_info
) < 0)
1122 static struct platform_driver acornfb_driver
= {
1123 .probe
= acornfb_probe
,
1129 static int __init
acornfb_init(void)
1131 return platform_driver_register(&acornfb_driver
);
1134 module_init(acornfb_init
);
1136 MODULE_AUTHOR("Russell King");
1137 MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
1138 MODULE_LICENSE("GPL");