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