2 * linux/drivers/video/acornfb.c
4 * Copyright (C) 1998-2001 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Frame buffer code for Acorn platforms
12 * NOTE: Most of the modes with X!=640 will disappear shortly.
13 * NOTE: Startup setting of HS & VS polarity not supported.
14 * (do we need to support it if we're coming up in 640x480?)
16 * FIXME: (things broken by the "new improved" FBCON API)
17 * - Blanking 8bpp displays with VIDC
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/errno.h>
23 #include <linux/string.h>
24 #include <linux/ctype.h>
26 #include <linux/init.h>
28 #include <linux/platform_device.h>
29 #include <linux/dma-mapping.h>
31 #include <linux/gfp.h>
33 #include <mach/hardware.h>
35 #include <asm/mach-types.h>
36 #include <asm/pgtable.h>
42 * NOTE that it has to be supported in the table towards
43 * the end of this file.
45 #define DEFAULT_XRES 640
46 #define DEFAULT_YRES 480
50 * define this to debug the video mode selection
52 #undef DEBUG_MODE_SELECTION
55 * Translation from RISC OS monitor types to actual
56 * HSYNC and VSYNC frequency ranges. These are
57 * probably not right, but they're the best info I
58 * have. Allow 1% either way on the nominal for TVs.
61 static struct fb_monspecs monspecs[NR_MONTYPES] = {
72 }, { /* Hi-res mono */
95 static struct fb_info fb_info;
96 static struct acornfb_par current_par;
97 static struct vidc_timing current_vidc;
99 extern unsigned int vram_size; /* set by setup.c */
102 #include <mach/acornfb.h>
104 #define MAX_SIZE 2*1024*1024
106 /* VIDC20 has a different set of rules from the VIDC:
107 * hcr : must be multiple of 4
108 * hswr : must be even
109 * hdsr : must be even
110 * hder : must be even
111 * vcr : >= 2, (interlace, must be odd)
116 static void acornfb_set_timing(struct fb_info *info)
118 struct fb_var_screeninfo *var = &info->var;
119 struct vidc_timing vidc;
121 u_int ext_ctl, dat_ctl;
122 u_int words_per_line;
124 memset(&vidc, 0, sizeof(vidc));
126 vidc.h_sync_width = var->hsync_len - 8;
127 vidc.h_border_start = vidc.h_sync_width + var->left_margin + 8 - 12;
128 vidc.h_display_start = vidc.h_border_start + 12 - 18;
129 vidc.h_display_end = vidc.h_display_start + var->xres;
130 vidc.h_border_end = vidc.h_display_end + 18 - 12;
131 vidc.h_cycle = vidc.h_border_end + var->right_margin + 12 - 8;
132 vidc.h_interlace = vidc.h_cycle / 2;
133 vidc.v_sync_width = var->vsync_len - 1;
134 vidc.v_border_start = vidc.v_sync_width + var->upper_margin;
135 vidc.v_display_start = vidc.v_border_start;
136 vidc.v_display_end = vidc.v_display_start + var->yres;
137 vidc.v_border_end = vidc.v_display_end;
138 vidc.control = acornfb_default_control();
140 vcr = var->vsync_len + var->upper_margin + var->yres +
143 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
144 vidc.v_cycle = (vcr - 3) / 2;
145 vidc.control |= VIDC20_CTRL_INT;
147 vidc.v_cycle = vcr - 2;
149 switch (var->bits_per_pixel) {
150 case 1: vidc.control |= VIDC20_CTRL_1BPP; break;
151 case 2: vidc.control |= VIDC20_CTRL_2BPP; break;
152 case 4: vidc.control |= VIDC20_CTRL_4BPP; break;
154 case 8: vidc.control |= VIDC20_CTRL_8BPP; break;
155 case 16: vidc.control |= VIDC20_CTRL_16BPP; break;
156 case 32: vidc.control |= VIDC20_CTRL_32BPP; break;
159 acornfb_vidc20_find_rates(&vidc, var);
160 fsize = var->vsync_len + var->upper_margin + var->lower_margin - 1;
162 if (memcmp(¤t_vidc, &vidc, sizeof(vidc))) {
165 vidc_writel(VIDC20_CTRL| vidc.control);
166 vidc_writel(0xd0000000 | vidc.pll_ctl);
167 vidc_writel(0x80000000 | vidc.h_cycle);
168 vidc_writel(0x81000000 | vidc.h_sync_width);
169 vidc_writel(0x82000000 | vidc.h_border_start);
170 vidc_writel(0x83000000 | vidc.h_display_start);
171 vidc_writel(0x84000000 | vidc.h_display_end);
172 vidc_writel(0x85000000 | vidc.h_border_end);
173 vidc_writel(0x86000000);
174 vidc_writel(0x87000000 | vidc.h_interlace);
175 vidc_writel(0x90000000 | vidc.v_cycle);
176 vidc_writel(0x91000000 | vidc.v_sync_width);
177 vidc_writel(0x92000000 | vidc.v_border_start);
178 vidc_writel(0x93000000 | vidc.v_display_start);
179 vidc_writel(0x94000000 | vidc.v_display_end);
180 vidc_writel(0x95000000 | vidc.v_border_end);
181 vidc_writel(0x96000000);
182 vidc_writel(0x97000000);
185 iomd_writel(fsize, IOMD_FSIZE);
187 ext_ctl = acornfb_default_econtrol();
189 if (var->sync & FB_SYNC_COMP_HIGH_ACT) /* should be FB_SYNC_COMP */
190 ext_ctl |= VIDC20_ECTL_HS_NCSYNC | VIDC20_ECTL_VS_NCSYNC;
192 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
193 ext_ctl |= VIDC20_ECTL_HS_HSYNC;
195 ext_ctl |= VIDC20_ECTL_HS_NHSYNC;
197 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
198 ext_ctl |= VIDC20_ECTL_VS_VSYNC;
200 ext_ctl |= VIDC20_ECTL_VS_NVSYNC;
203 vidc_writel(VIDC20_ECTL | ext_ctl);
205 words_per_line = var->xres * var->bits_per_pixel / 32;
207 if (current_par.using_vram && info->fix.smem_len == 2048*1024)
210 /* RiscPC doesn't use the VIDC's VRAM control. */
211 dat_ctl = VIDC20_DCTL_VRAM_DIS | VIDC20_DCTL_SNA | words_per_line;
213 /* The data bus width is dependent on both the type
214 * and amount of video memory.
219 if (current_par.using_vram && current_par.vram_half_sam == 2048)
220 dat_ctl |= VIDC20_DCTL_BUS_D63_0;
222 dat_ctl |= VIDC20_DCTL_BUS_D31_0;
224 vidc_writel(VIDC20_DCTL | dat_ctl);
226 #ifdef DEBUG_MODE_SELECTION
227 printk(KERN_DEBUG "VIDC registers for %dx%dx%d:\n", var->xres,
228 var->yres, var->bits_per_pixel);
229 printk(KERN_DEBUG " H-cycle : %d\n", vidc.h_cycle);
230 printk(KERN_DEBUG " H-sync-width : %d\n", vidc.h_sync_width);
231 printk(KERN_DEBUG " H-border-start : %d\n", vidc.h_border_start);
232 printk(KERN_DEBUG " H-display-start : %d\n", vidc.h_display_start);
233 printk(KERN_DEBUG " H-display-end : %d\n", vidc.h_display_end);
234 printk(KERN_DEBUG " H-border-end : %d\n", vidc.h_border_end);
235 printk(KERN_DEBUG " H-interlace : %d\n", vidc.h_interlace);
236 printk(KERN_DEBUG " V-cycle : %d\n", vidc.v_cycle);
237 printk(KERN_DEBUG " V-sync-width : %d\n", vidc.v_sync_width);
238 printk(KERN_DEBUG " V-border-start : %d\n", vidc.v_border_start);
239 printk(KERN_DEBUG " V-display-start : %d\n", vidc.v_display_start);
240 printk(KERN_DEBUG " V-display-end : %d\n", vidc.v_display_end);
241 printk(KERN_DEBUG " V-border-end : %d\n", vidc.v_border_end);
242 printk(KERN_DEBUG " Ext Ctrl (C) : 0x%08X\n", ext_ctl);
243 printk(KERN_DEBUG " PLL Ctrl (D) : 0x%08X\n", vidc.pll_ctl);
244 printk(KERN_DEBUG " Ctrl (E) : 0x%08X\n", vidc.control);
245 printk(KERN_DEBUG " Data Ctrl (F) : 0x%08X\n", dat_ctl);
246 printk(KERN_DEBUG " Fsize : 0x%08X\n", fsize);
251 * We have to take note of the VIDC20's 16-bit palette here.
252 * The VIDC20 looks up a 16 bit pixel as follows:
256 * red ++++++++ (8 bits, 7 to 0)
257 * green ++++++++ (8 bits, 11 to 4)
258 * blue ++++++++ (8 bits, 15 to 8)
260 * We use a pixel which looks like:
264 * red +++++ (5 bits, 4 to 0)
265 * green +++++ (5 bits, 9 to 5)
266 * blue +++++ (5 bits, 14 to 10)
269 acornfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
270 u_int trans, struct fb_info *info)
274 if (regno >= current_par.palette_size)
277 if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
280 pseudo_val = regno << info->var.red.offset;
281 pseudo_val |= regno << info->var.green.offset;
282 pseudo_val |= regno << info->var.blue.offset;
284 ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
288 pal.vidc20.red = red >> 8;
289 pal.vidc20.green = green >> 8;
290 pal.vidc20.blue = blue >> 8;
292 current_par.palette[regno] = pal;
294 if (info->var.bits_per_pixel == 16) {
298 vidc_writel(0x10000000);
299 for (i = 0; i < 256; i += 1) {
300 pal.vidc20.red = current_par.palette[ i & 31].vidc20.red;
301 pal.vidc20.green = current_par.palette[(i >> 1) & 31].vidc20.green;
302 pal.vidc20.blue = current_par.palette[(i >> 2) & 31].vidc20.blue;
304 /* Palette register pointer auto-increments */
307 vidc_writel(0x10000000 | regno);
316 * Before selecting the timing parameters, adjust
317 * the resolution to fit the rules.
320 acornfb_adjust_timing(struct fb_info *info, struct fb_var_screeninfo *var, u_int fontht)
322 u_int font_line_len, sam_size, min_size, size, nr_y;
324 /* xres must be even */
325 var->xres = (var->xres + 1) & ~1;
328 * We don't allow xres_virtual to differ from xres
330 var->xres_virtual = var->xres;
333 if (current_par.using_vram)
334 sam_size = current_par.vram_half_sam * 2;
339 * Now, find a value for yres_virtual which allows
340 * us to do ywrap scrolling. The value of
341 * yres_virtual must be such that the end of the
342 * displayable frame buffer must be aligned with
343 * the start of a font line.
345 font_line_len = var->xres * var->bits_per_pixel * fontht / 8;
346 min_size = var->xres * var->yres * var->bits_per_pixel / 8;
349 * If minimum screen size is greater than that we have
350 * available, reject it.
352 if (min_size > info->fix.smem_len)
355 /* Find int 'y', such that y * fll == s * sam < maxsize
356 * y = s * sam / fll; s = maxsize / sam
358 for (size = info->fix.smem_len;
359 nr_y = size / font_line_len, min_size <= size;
361 if (nr_y * font_line_len == size)
366 if (var->accel_flags & FB_ACCELF_TEXT) {
367 if (min_size > size) {
371 size = info->fix.smem_len;
372 var->yres_virtual = size / (font_line_len / fontht);
374 var->yres_virtual = nr_y;
375 } else if (var->yres_virtual > nr_y)
376 var->yres_virtual = nr_y;
378 current_par.screen_end = info->fix.smem_start + size;
381 * Fix yres & yoffset if needed.
383 if (var->yres > var->yres_virtual)
384 var->yres = var->yres_virtual;
386 if (var->vmode & FB_VMODE_YWRAP) {
387 if (var->yoffset > var->yres_virtual)
388 var->yoffset = var->yres_virtual;
390 if (var->yoffset + var->yres > var->yres_virtual)
391 var->yoffset = var->yres_virtual - var->yres;
394 /* hsync_len must be even */
395 var->hsync_len = (var->hsync_len + 1) & ~1;
397 #if defined(HAS_VIDC20)
398 /* left_margin must be even */
399 if (var->left_margin & 1) {
400 var->left_margin += 1;
401 var->right_margin -= 1;
404 /* right_margin must be even */
405 if (var->right_margin & 1)
406 var->right_margin += 1;
409 if (var->vsync_len < 1)
416 acornfb_validate_timing(struct fb_var_screeninfo *var,
417 struct fb_monspecs *monspecs)
419 unsigned long hs, vs;
422 * hs(Hz) = 10^12 / (pixclock * xtotal)
423 * vs(Hz) = hs(Hz) / ytotal
425 * No need to do long long divisions or anything
426 * like that if you factor it correctly
428 hs = 1953125000 / var->pixclock;
430 (var->xres + var->left_margin + var->right_margin + var->hsync_len);
432 (var->yres + var->upper_margin + var->lower_margin + var->vsync_len);
434 return (vs >= monspecs->vfmin && vs <= monspecs->vfmax &&
435 hs >= monspecs->hfmin && hs <= monspecs->hfmax) ? 0 : -EINVAL;
439 acornfb_update_dma(struct fb_info *info, struct fb_var_screeninfo *var)
441 u_int off = var->yoffset * info->fix.line_length;
443 #if defined(HAS_MEMC)
444 memc_write(VDMA_INIT, off >> 2);
445 #elif defined(HAS_IOMD)
446 iomd_writel(info->fix.smem_start + off, IOMD_VIDINIT);
451 acornfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
457 * FIXME: Find the font height
461 var->red.msb_right = 0;
462 var->green.msb_right = 0;
463 var->blue.msb_right = 0;
464 var->transp.msb_right = 0;
466 switch (var->bits_per_pixel) {
467 case 1: case 2: case 4: case 8:
469 var->red.length = var->bits_per_pixel;
470 var->green = var->red;
471 var->blue = var->red;
472 var->transp.offset = 0;
473 var->transp.length = 0;
480 var->green.offset = 5;
481 var->green.length = 5;
482 var->blue.offset = 10;
483 var->blue.length = 5;
484 var->transp.offset = 15;
485 var->transp.length = 1;
491 var->green.offset = 8;
492 var->green.length = 8;
493 var->blue.offset = 16;
494 var->blue.length = 8;
495 var->transp.offset = 24;
496 var->transp.length = 4;
504 * Check to see if the pixel rate is valid.
506 if (!acornfb_valid_pixrate(var))
510 * Validate and adjust the resolution to
511 * match the video generator hardware.
513 err = acornfb_adjust_timing(info, var, fontht);
518 * Validate the timing against the
521 return acornfb_validate_timing(var, &info->monspecs);
524 static int acornfb_set_par(struct fb_info *info)
526 switch (info->var.bits_per_pixel) {
528 current_par.palette_size = 2;
529 info->fix.visual = FB_VISUAL_MONO10;
532 current_par.palette_size = 4;
533 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
536 current_par.palette_size = 16;
537 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
540 current_par.palette_size = VIDC_PALETTE_SIZE;
541 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
545 current_par.palette_size = 32;
546 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
549 current_par.palette_size = VIDC_PALETTE_SIZE;
550 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
557 info->fix.line_length = (info->var.xres * info->var.bits_per_pixel) / 8;
559 #if defined(HAS_MEMC)
561 unsigned long size = info->fix.smem_len - VDMA_XFERSIZE;
563 memc_write(VDMA_START, 0);
564 memc_write(VDMA_END, size >> 2);
566 #elif defined(HAS_IOMD)
568 unsigned long start, size;
571 start = info->fix.smem_start;
572 size = current_par.screen_end;
574 if (current_par.using_vram) {
575 size -= current_par.vram_half_sam;
576 control = DMA_CR_E | (current_par.vram_half_sam / 256);
579 control = DMA_CR_E | DMA_CR_D | 16;
582 iomd_writel(start, IOMD_VIDSTART);
583 iomd_writel(size, IOMD_VIDEND);
584 iomd_writel(control, IOMD_VIDCR);
588 acornfb_update_dma(info, &info->var);
589 acornfb_set_timing(info);
595 acornfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
597 u_int y_bottom = var->yoffset;
599 if (!(var->vmode & FB_VMODE_YWRAP))
600 y_bottom += info->var.yres;
602 if (y_bottom > info->var.yres_virtual)
605 acornfb_update_dma(info, var);
610 static struct fb_ops acornfb_ops = {
611 .owner = THIS_MODULE,
612 .fb_check_var = acornfb_check_var,
613 .fb_set_par = acornfb_set_par,
614 .fb_setcolreg = acornfb_setcolreg,
615 .fb_pan_display = acornfb_pan_display,
616 .fb_fillrect = cfb_fillrect,
617 .fb_copyarea = cfb_copyarea,
618 .fb_imageblit = cfb_imageblit,
622 * Everything after here is initialisation!!!
624 static struct fb_videomode modedb[] = {
625 { /* 320x256 @ 50Hz */
626 NULL, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
627 FB_SYNC_COMP_HIGH_ACT,
628 FB_VMODE_NONINTERLACED
629 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
630 NULL, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
632 FB_VMODE_NONINTERLACED
633 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
634 NULL, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
636 FB_VMODE_NONINTERLACED
637 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
638 NULL, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
640 FB_VMODE_NONINTERLACED
641 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
642 NULL, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
644 FB_VMODE_NONINTERLACED
645 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
646 NULL, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
648 FB_VMODE_NONINTERLACED
649 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
650 NULL, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
652 FB_VMODE_NONINTERLACED
653 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
654 NULL, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
656 FB_VMODE_NONINTERLACED
657 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
658 NULL, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
660 FB_VMODE_NONINTERLACED
661 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
662 NULL, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
664 FB_VMODE_NONINTERLACED
665 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
666 NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
668 FB_VMODE_NONINTERLACED
669 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
670 NULL, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
672 FB_VMODE_NONINTERLACED
676 static struct fb_videomode acornfb_default_mode = {
689 .vmode = FB_VMODE_NONINTERLACED
692 static void acornfb_init_fbinfo(void)
694 static int first = 1;
700 fb_info.fbops = &acornfb_ops;
701 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
702 fb_info.pseudo_palette = current_par.pseudo_palette;
704 strcpy(fb_info.fix.id, "Acorn");
705 fb_info.fix.type = FB_TYPE_PACKED_PIXELS;
706 fb_info.fix.type_aux = 0;
707 fb_info.fix.xpanstep = 0;
708 fb_info.fix.ypanstep = 1;
709 fb_info.fix.ywrapstep = 1;
710 fb_info.fix.line_length = 0;
711 fb_info.fix.accel = FB_ACCEL_NONE;
714 * setup initial parameters
716 memset(&fb_info.var, 0, sizeof(fb_info.var));
718 #if defined(HAS_VIDC20)
719 fb_info.var.red.length = 8;
720 fb_info.var.transp.length = 4;
722 fb_info.var.green = fb_info.var.red;
723 fb_info.var.blue = fb_info.var.red;
724 fb_info.var.nonstd = 0;
725 fb_info.var.activate = FB_ACTIVATE_NOW;
726 fb_info.var.height = -1;
727 fb_info.var.width = -1;
728 fb_info.var.vmode = FB_VMODE_NONINTERLACED;
729 fb_info.var.accel_flags = FB_ACCELF_TEXT;
731 current_par.dram_size = 0;
732 current_par.montype = -1;
733 current_par.dpms = 0;
737 * setup acornfb options:
739 * mon:hmin-hmax:vmin-vmax:dpms:width:height
740 * Set monitor parameters:
741 * hmin = horizontal minimum frequency (Hz)
742 * hmax = horizontal maximum frequency (Hz) (optional)
743 * vmin = vertical minimum frequency (Hz)
744 * vmax = vertical maximum frequency (Hz) (optional)
745 * dpms = DPMS supported? (optional)
746 * width = width of picture in mm. (optional)
747 * height = height of picture in mm. (optional)
750 * Set RISC-OS style monitor type:
751 * 0 (or tv) - TV frequency
752 * 1 (or multi) - Multi frequency
753 * 2 (or hires) - Hi-res monochrome
756 * auto, or option missing
757 * - try hardware detect
760 * Set the amount of DRAM to use for the frame buffer
761 * (even if you have VRAM).
762 * size can optionally be followed by 'M' or 'K' for
763 * MB or KB respectively.
765 static void acornfb_parse_mon(char *opt)
769 current_par.montype = -2;
771 fb_info.monspecs.hfmin = simple_strtoul(p, &p, 0);
773 fb_info.monspecs.hfmax = simple_strtoul(p + 1, &p, 0);
775 fb_info.monspecs.hfmax = fb_info.monspecs.hfmin;
780 fb_info.monspecs.vfmin = simple_strtoul(p + 1, &p, 0);
782 fb_info.monspecs.vfmax = simple_strtoul(p + 1, &p, 0);
784 fb_info.monspecs.vfmax = fb_info.monspecs.vfmin;
789 fb_info.monspecs.dpms = simple_strtoul(p + 1, &p, 0);
794 fb_info.var.width = simple_strtoul(p + 1, &p, 0);
799 fb_info.var.height = simple_strtoul(p + 1, NULL, 0);
802 if (fb_info.monspecs.hfmax < fb_info.monspecs.hfmin ||
803 fb_info.monspecs.vfmax < fb_info.monspecs.vfmin)
808 printk(KERN_ERR "Acornfb: bad monitor settings: %s\n", opt);
809 current_par.montype = -1;
812 static void acornfb_parse_montype(char *opt)
814 current_par.montype = -2;
816 if (strncmp(opt, "tv", 2) == 0) {
818 current_par.montype = 0;
819 } else if (strncmp(opt, "multi", 5) == 0) {
821 current_par.montype = 1;
822 } else if (strncmp(opt, "hires", 5) == 0) {
824 current_par.montype = 2;
825 } else if (strncmp(opt, "vga", 3) == 0) {
827 current_par.montype = 3;
828 } else if (strncmp(opt, "svga", 4) == 0) {
830 current_par.montype = 4;
831 } else if (strncmp(opt, "auto", 4) == 0) {
833 current_par.montype = -1;
834 } else if (isdigit(*opt))
835 current_par.montype = simple_strtoul(opt, &opt, 0);
837 if (current_par.montype == -2 ||
838 current_par.montype > NR_MONTYPES) {
839 printk(KERN_ERR "acornfb: unknown monitor type: %s\n",
841 current_par.montype = -1;
844 if (strcmp(opt, ",dpms") == 0)
845 current_par.dpms = 1;
848 "acornfb: unknown monitor option: %s\n",
853 static void acornfb_parse_dram(char *opt)
857 size = simple_strtoul(opt, &opt, 0);
872 current_par.dram_size = size;
875 static struct options {
877 void (*parse)(char *opt);
879 { "mon", acornfb_parse_mon },
880 { "montype", acornfb_parse_montype },
881 { "dram", acornfb_parse_dram },
885 static int acornfb_setup(char *options)
887 struct options *optp;
890 if (!options || !*options)
893 acornfb_init_fbinfo();
895 while ((opt = strsep(&options, ",")) != NULL) {
899 for (optp = opt_table; optp->name; optp++) {
902 optlen = strlen(optp->name);
904 if (strncmp(opt, optp->name, optlen) == 0 &&
905 opt[optlen] == ':') {
906 optp->parse(opt + optlen + 1);
912 printk(KERN_ERR "acornfb: unknown parameter: %s\n",
919 * Detect type of monitor connected
920 * For now, we just assume SVGA
922 static int acornfb_detect_monitortype(void)
928 * This enables the unused memory to be freed on older Acorn machines.
929 * We are freeing memory on behalf of the architecture initialisation
933 free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
940 virtual_start = PAGE_ALIGN(virtual_start);
941 virtual_end = PAGE_ALIGN(virtual_end);
943 while (virtual_start < virtual_end) {
947 * Clear page reserved bit,
948 * set count to 1, and free
951 page = virt_to_page(virtual_start);
952 __free_reserved_page(page);
954 virtual_start += PAGE_SIZE;
955 mb_freed += PAGE_SIZE / 1024;
958 printk("acornfb: freed %dK memory\n", mb_freed);
961 static int acornfb_probe(struct platform_device *dev)
964 u_int h_sync, v_sync;
968 if (fb_get_options("acornfb", &option))
970 acornfb_setup(option);
972 acornfb_init_fbinfo();
974 current_par.dev = &dev->dev;
976 if (current_par.montype == -1)
977 current_par.montype = acornfb_detect_monitortype();
979 if (current_par.montype == -1 || current_par.montype > NR_MONTYPES)
980 current_par.montype = 4;
982 if (current_par.montype >= 0) {
983 fb_info.monspecs = monspecs[current_par.montype];
984 fb_info.monspecs.dpms = current_par.dpms;
988 * Try to select a suitable default mode
990 for (i = 0; i < ARRAY_SIZE(modedb); i++) {
993 hs = modedb[i].refresh *
994 (modedb[i].yres + modedb[i].upper_margin +
995 modedb[i].lower_margin + modedb[i].vsync_len);
996 if (modedb[i].xres == DEFAULT_XRES &&
997 modedb[i].yres == DEFAULT_YRES &&
998 modedb[i].refresh >= fb_info.monspecs.vfmin &&
999 modedb[i].refresh <= fb_info.monspecs.vfmax &&
1000 hs >= fb_info.monspecs.hfmin &&
1001 hs <= fb_info.monspecs.hfmax) {
1002 acornfb_default_mode = modedb[i];
1007 fb_info.screen_base = (char *)SCREEN_BASE;
1008 fb_info.fix.smem_start = SCREEN_START;
1009 current_par.using_vram = 0;
1012 * If vram_size is set, we are using VRAM in
1013 * a Risc PC. However, if the user has specified
1014 * an amount of DRAM then use that instead.
1016 if (vram_size && !current_par.dram_size) {
1018 current_par.vram_half_sam = vram_size / 1024;
1019 current_par.using_vram = 1;
1020 } else if (current_par.dram_size)
1021 size = current_par.dram_size;
1026 * Limit maximum screen size.
1028 if (size > MAX_SIZE)
1031 size = PAGE_ALIGN(size);
1033 #if defined(HAS_VIDC20)
1034 if (!current_par.using_vram) {
1039 * RiscPC needs to allocate the DRAM memory
1040 * for the framebuffer if we are not using
1043 base = dma_alloc_writecombine(current_par.dev, size, &handle,
1046 printk(KERN_ERR "acornfb: unable to allocate screen "
1051 fb_info.screen_base = base;
1052 fb_info.fix.smem_start = handle;
1055 fb_info.fix.smem_len = size;
1056 current_par.palette_size = VIDC_PALETTE_SIZE;
1059 * Lookup the timing for this resolution. If we can't
1060 * find it, then we can't restore it if we change
1061 * the resolution, so we disable this feature.
1064 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
1066 &acornfb_default_mode, DEFAULT_BPP);
1068 * If we found an exact match, all ok.
1073 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
1074 &acornfb_default_mode, DEFAULT_BPP);
1076 * If we found an exact match, all ok.
1081 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
1083 &acornfb_default_mode, DEFAULT_BPP);
1087 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
1088 &acornfb_default_mode, DEFAULT_BPP);
1092 * If we didn't find an exact match, try the
1096 printk("Acornfb: no valid mode found\n");
1100 h_sync = 1953125000 / fb_info.var.pixclock;
1101 h_sync = h_sync * 512 / (fb_info.var.xres + fb_info.var.left_margin +
1102 fb_info.var.right_margin + fb_info.var.hsync_len);
1103 v_sync = h_sync / (fb_info.var.yres + fb_info.var.upper_margin +
1104 fb_info.var.lower_margin + fb_info.var.vsync_len);
1106 printk(KERN_INFO "Acornfb: %dkB %cRAM, %s, using %dx%d, "
1107 "%d.%03dkHz, %dHz\n",
1108 fb_info.fix.smem_len / 1024,
1109 current_par.using_vram ? 'V' : 'D',
1110 VIDC_NAME, fb_info.var.xres, fb_info.var.yres,
1111 h_sync / 1000, h_sync % 1000, v_sync);
1113 printk(KERN_INFO "Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1114 fb_info.monspecs.hfmin / 1000, fb_info.monspecs.hfmin % 1000,
1115 fb_info.monspecs.hfmax / 1000, fb_info.monspecs.hfmax % 1000,
1116 fb_info.monspecs.vfmin, fb_info.monspecs.vfmax,
1117 fb_info.monspecs.dpms ? ", DPMS" : "");
1119 if (fb_set_var(&fb_info, &fb_info.var))
1120 printk(KERN_ERR "Acornfb: unable to set display parameters\n");
1122 if (register_framebuffer(&fb_info) < 0)
1127 static struct platform_driver acornfb_driver = {
1128 .probe = acornfb_probe,
1134 static int __init acornfb_init(void)
1136 return platform_driver_register(&acornfb_driver);
1139 module_init(acornfb_init);
1141 MODULE_AUTHOR("Russell King");
1142 MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
1143 MODULE_LICENSE("GPL");