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_DEFAULT_IOMEM_OPS
,
609 .fb_check_var
= acornfb_check_var
,
610 .fb_set_par
= acornfb_set_par
,
611 .fb_setcolreg
= acornfb_setcolreg
,
612 .fb_pan_display
= acornfb_pan_display
,
616 * Everything after here is initialisation!!!
618 static struct fb_videomode modedb
[] = {
619 { /* 320x256 @ 50Hz */
620 NULL
, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
621 FB_SYNC_COMP_HIGH_ACT
,
622 FB_VMODE_NONINTERLACED
623 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
624 NULL
, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
626 FB_VMODE_NONINTERLACED
627 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
628 NULL
, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
630 FB_VMODE_NONINTERLACED
631 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
632 NULL
, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
634 FB_VMODE_NONINTERLACED
635 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
636 NULL
, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
638 FB_VMODE_NONINTERLACED
639 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
640 NULL
, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
642 FB_VMODE_NONINTERLACED
643 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
644 NULL
, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
646 FB_VMODE_NONINTERLACED
647 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
648 NULL
, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
650 FB_VMODE_NONINTERLACED
651 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
652 NULL
, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
654 FB_VMODE_NONINTERLACED
655 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
656 NULL
, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
658 FB_VMODE_NONINTERLACED
659 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
660 NULL
, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
662 FB_VMODE_NONINTERLACED
663 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
664 NULL
, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
666 FB_VMODE_NONINTERLACED
670 static struct fb_videomode acornfb_default_mode
= {
683 .vmode
= FB_VMODE_NONINTERLACED
686 static void acornfb_init_fbinfo(void)
688 static int first
= 1;
694 fb_info
.fbops
= &acornfb_ops
;
695 fb_info
.flags
= FBINFO_HWACCEL_YPAN
;
696 fb_info
.pseudo_palette
= current_par
.pseudo_palette
;
698 strcpy(fb_info
.fix
.id
, "Acorn");
699 fb_info
.fix
.type
= FB_TYPE_PACKED_PIXELS
;
700 fb_info
.fix
.type_aux
= 0;
701 fb_info
.fix
.xpanstep
= 0;
702 fb_info
.fix
.ypanstep
= 1;
703 fb_info
.fix
.ywrapstep
= 1;
704 fb_info
.fix
.line_length
= 0;
705 fb_info
.fix
.accel
= FB_ACCEL_NONE
;
708 * setup initial parameters
710 memset(&fb_info
.var
, 0, sizeof(fb_info
.var
));
712 #if defined(HAS_VIDC20)
713 fb_info
.var
.red
.length
= 8;
714 fb_info
.var
.transp
.length
= 4;
716 fb_info
.var
.green
= fb_info
.var
.red
;
717 fb_info
.var
.blue
= fb_info
.var
.red
;
718 fb_info
.var
.nonstd
= 0;
719 fb_info
.var
.activate
= FB_ACTIVATE_NOW
;
720 fb_info
.var
.height
= -1;
721 fb_info
.var
.width
= -1;
722 fb_info
.var
.vmode
= FB_VMODE_NONINTERLACED
;
723 fb_info
.var
.accel_flags
= FB_ACCELF_TEXT
;
725 current_par
.dram_size
= 0;
726 current_par
.montype
= -1;
727 current_par
.dpms
= 0;
731 * setup acornfb options:
733 * mon:hmin-hmax:vmin-vmax:dpms:width:height
734 * Set monitor parameters:
735 * hmin = horizontal minimum frequency (Hz)
736 * hmax = horizontal maximum frequency (Hz) (optional)
737 * vmin = vertical minimum frequency (Hz)
738 * vmax = vertical maximum frequency (Hz) (optional)
739 * dpms = DPMS supported? (optional)
740 * width = width of picture in mm. (optional)
741 * height = height of picture in mm. (optional)
744 * Set RISC-OS style monitor type:
745 * 0 (or tv) - TV frequency
746 * 1 (or multi) - Multi frequency
747 * 2 (or hires) - Hi-res monochrome
750 * auto, or option missing
751 * - try hardware detect
754 * Set the amount of DRAM to use for the frame buffer
755 * (even if you have VRAM).
756 * size can optionally be followed by 'M' or 'K' for
757 * MB or KB respectively.
759 static void acornfb_parse_mon(char *opt
)
763 current_par
.montype
= -2;
765 fb_info
.monspecs
.hfmin
= simple_strtoul(p
, &p
, 0);
767 fb_info
.monspecs
.hfmax
= simple_strtoul(p
+ 1, &p
, 0);
769 fb_info
.monspecs
.hfmax
= fb_info
.monspecs
.hfmin
;
774 fb_info
.monspecs
.vfmin
= simple_strtoul(p
+ 1, &p
, 0);
776 fb_info
.monspecs
.vfmax
= simple_strtoul(p
+ 1, &p
, 0);
778 fb_info
.monspecs
.vfmax
= fb_info
.monspecs
.vfmin
;
783 fb_info
.monspecs
.dpms
= simple_strtoul(p
+ 1, &p
, 0);
788 fb_info
.var
.width
= simple_strtoul(p
+ 1, &p
, 0);
793 fb_info
.var
.height
= simple_strtoul(p
+ 1, NULL
, 0);
796 if (fb_info
.monspecs
.hfmax
< fb_info
.monspecs
.hfmin
||
797 fb_info
.monspecs
.vfmax
< fb_info
.monspecs
.vfmin
)
802 printk(KERN_ERR
"Acornfb: bad monitor settings: %s\n", opt
);
803 current_par
.montype
= -1;
806 static void acornfb_parse_montype(char *opt
)
808 current_par
.montype
= -2;
810 if (strncmp(opt
, "tv", 2) == 0) {
812 current_par
.montype
= 0;
813 } else if (strncmp(opt
, "multi", 5) == 0) {
815 current_par
.montype
= 1;
816 } else if (strncmp(opt
, "hires", 5) == 0) {
818 current_par
.montype
= 2;
819 } else if (strncmp(opt
, "vga", 3) == 0) {
821 current_par
.montype
= 3;
822 } else if (strncmp(opt
, "svga", 4) == 0) {
824 current_par
.montype
= 4;
825 } else if (strncmp(opt
, "auto", 4) == 0) {
827 current_par
.montype
= -1;
828 } else if (isdigit(*opt
))
829 current_par
.montype
= simple_strtoul(opt
, &opt
, 0);
831 if (current_par
.montype
== -2 ||
832 current_par
.montype
> NR_MONTYPES
) {
833 printk(KERN_ERR
"acornfb: unknown monitor type: %s\n",
835 current_par
.montype
= -1;
838 if (strcmp(opt
, ",dpms") == 0)
839 current_par
.dpms
= 1;
842 "acornfb: unknown monitor option: %s\n",
847 static void acornfb_parse_dram(char *opt
)
851 size
= simple_strtoul(opt
, &opt
, 0);
867 current_par
.dram_size
= size
;
870 static struct options
{
872 void (*parse
)(char *opt
);
874 { "mon", acornfb_parse_mon
},
875 { "montype", acornfb_parse_montype
},
876 { "dram", acornfb_parse_dram
},
880 static int acornfb_setup(char *options
)
882 struct options
*optp
;
885 if (!options
|| !*options
)
888 acornfb_init_fbinfo();
890 while ((opt
= strsep(&options
, ",")) != NULL
) {
894 for (optp
= opt_table
; optp
->name
; optp
++) {
897 optlen
= strlen(optp
->name
);
899 if (strncmp(opt
, optp
->name
, optlen
) == 0 &&
900 opt
[optlen
] == ':') {
901 optp
->parse(opt
+ optlen
+ 1);
907 printk(KERN_ERR
"acornfb: unknown parameter: %s\n",
914 * Detect type of monitor connected
915 * For now, we just assume SVGA
917 static int acornfb_detect_monitortype(void)
922 static int acornfb_probe(struct platform_device
*dev
)
925 u_int h_sync
, v_sync
;
929 if (fb_get_options("acornfb", &option
))
931 acornfb_setup(option
);
933 acornfb_init_fbinfo();
935 current_par
.dev
= &dev
->dev
;
937 if (current_par
.montype
== -1)
938 current_par
.montype
= acornfb_detect_monitortype();
940 if (current_par
.montype
== -1 || current_par
.montype
> NR_MONTYPES
)
941 current_par
.montype
= 4;
943 if (current_par
.montype
>= 0) {
944 fb_info
.monspecs
= monspecs
[current_par
.montype
];
945 fb_info
.monspecs
.dpms
= current_par
.dpms
;
949 * Try to select a suitable default mode
951 for (i
= 0; i
< ARRAY_SIZE(modedb
); i
++) {
954 hs
= modedb
[i
].refresh
*
955 (modedb
[i
].yres
+ modedb
[i
].upper_margin
+
956 modedb
[i
].lower_margin
+ modedb
[i
].vsync_len
);
957 if (modedb
[i
].xres
== DEFAULT_XRES
&&
958 modedb
[i
].yres
== DEFAULT_YRES
&&
959 modedb
[i
].refresh
>= fb_info
.monspecs
.vfmin
&&
960 modedb
[i
].refresh
<= fb_info
.monspecs
.vfmax
&&
961 hs
>= fb_info
.monspecs
.hfmin
&&
962 hs
<= fb_info
.monspecs
.hfmax
) {
963 acornfb_default_mode
= modedb
[i
];
968 fb_info
.screen_base
= (char *)SCREEN_BASE
;
969 fb_info
.fix
.smem_start
= SCREEN_START
;
970 current_par
.using_vram
= 0;
973 * If vram_size is set, we are using VRAM in
974 * a Risc PC. However, if the user has specified
975 * an amount of DRAM then use that instead.
977 if (vram_size
&& !current_par
.dram_size
) {
979 current_par
.vram_half_sam
= vram_size
/ 1024;
980 current_par
.using_vram
= 1;
981 } else if (current_par
.dram_size
)
982 size
= current_par
.dram_size
;
987 * Limit maximum screen size.
992 size
= PAGE_ALIGN(size
);
994 #if defined(HAS_VIDC20)
995 if (!current_par
.using_vram
) {
1000 * RiscPC needs to allocate the DRAM memory
1001 * for the framebuffer if we are not using
1004 base
= dma_alloc_wc(current_par
.dev
, size
, &handle
,
1007 printk(KERN_ERR
"acornfb: unable to allocate screen memory\n");
1011 fb_info
.screen_base
= base
;
1012 fb_info
.fix
.smem_start
= handle
;
1015 fb_info
.fix
.smem_len
= size
;
1016 current_par
.palette_size
= VIDC_PALETTE_SIZE
;
1019 * Lookup the timing for this resolution. If we can't
1020 * find it, then we can't restore it if we change
1021 * the resolution, so we disable this feature.
1024 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1026 &acornfb_default_mode
, DEFAULT_BPP
);
1028 * If we found an exact match, all ok.
1033 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1034 &acornfb_default_mode
, DEFAULT_BPP
);
1036 * If we found an exact match, all ok.
1041 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, modedb
,
1043 &acornfb_default_mode
, DEFAULT_BPP
);
1047 rc
= fb_find_mode(&fb_info
.var
, &fb_info
, NULL
, NULL
, 0,
1048 &acornfb_default_mode
, DEFAULT_BPP
);
1052 * If we didn't find an exact match, try the
1056 printk("Acornfb: no valid mode found\n");
1060 h_sync
= 1953125000 / fb_info
.var
.pixclock
;
1061 h_sync
= h_sync
* 512 / (fb_info
.var
.xres
+ fb_info
.var
.left_margin
+
1062 fb_info
.var
.right_margin
+ fb_info
.var
.hsync_len
);
1063 v_sync
= h_sync
/ (fb_info
.var
.yres
+ fb_info
.var
.upper_margin
+
1064 fb_info
.var
.lower_margin
+ fb_info
.var
.vsync_len
);
1066 printk(KERN_INFO
"Acornfb: %dkB %cRAM, %s, using %dx%d, %d.%03dkHz, %dHz\n",
1067 fb_info
.fix
.smem_len
/ 1024,
1068 current_par
.using_vram
? 'V' : 'D',
1069 VIDC_NAME
, fb_info
.var
.xres
, fb_info
.var
.yres
,
1070 h_sync
/ 1000, h_sync
% 1000, v_sync
);
1072 printk(KERN_INFO
"Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1073 fb_info
.monspecs
.hfmin
/ 1000, fb_info
.monspecs
.hfmin
% 1000,
1074 fb_info
.monspecs
.hfmax
/ 1000, fb_info
.monspecs
.hfmax
% 1000,
1075 fb_info
.monspecs
.vfmin
, fb_info
.monspecs
.vfmax
,
1076 fb_info
.monspecs
.dpms
? ", DPMS" : "");
1078 if (fb_set_var(&fb_info
, &fb_info
.var
))
1079 printk(KERN_ERR
"Acornfb: unable to set display parameters\n");
1081 if (register_framebuffer(&fb_info
) < 0)
1086 static struct platform_driver acornfb_driver
= {
1087 .probe
= acornfb_probe
,
1093 static int __init
acornfb_init(void)
1095 return platform_driver_register(&acornfb_driver
);
1098 module_init(acornfb_init
);
1100 MODULE_AUTHOR("Russell King");
1101 MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
1102 MODULE_LICENSE("GPL");