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>
33 #include <asm/pgtable.h>
39 * NOTE that it has to be supported in the table towards
40 * the end of this file.
42 #define DEFAULT_XRES 640
43 #define DEFAULT_YRES 480
47 * define this to debug the video mode selection
49 #undef DEBUG_MODE_SELECTION
52 * Translation from RISC OS monitor types to actual
53 * HSYNC and VSYNC frequency ranges. These are
54 * probably not right, but they're the best info I
55 * have. Allow 1% either way on the nominal for TVs.
58 static struct fb_monspecs monspecs[NR_MONTYPES] = {
69 }, { /* Hi-res mono */
92 static struct fb_info fb_info;
93 static struct acornfb_par current_par;
94 static struct vidc_timing current_vidc;
96 extern unsigned int vram_size; /* set by setup.c */
99 #include <mach/acornfb.h>
101 #define MAX_SIZE (2*1024*1024)
103 /* VIDC20 has a different set of rules from the VIDC:
104 * hcr : must be multiple of 4
105 * hswr : must be even
106 * hdsr : must be even
107 * hder : must be even
108 * vcr : >= 2, (interlace, must be odd)
113 static void acornfb_set_timing(struct fb_info *info)
115 struct fb_var_screeninfo *var = &info->var;
116 struct vidc_timing vidc;
118 u_int ext_ctl, dat_ctl;
119 u_int words_per_line;
121 memset(&vidc, 0, sizeof(vidc));
123 vidc.h_sync_width = var->hsync_len - 8;
124 vidc.h_border_start = vidc.h_sync_width + var->left_margin + 8 - 12;
125 vidc.h_display_start = vidc.h_border_start + 12 - 18;
126 vidc.h_display_end = vidc.h_display_start + var->xres;
127 vidc.h_border_end = vidc.h_display_end + 18 - 12;
128 vidc.h_cycle = vidc.h_border_end + var->right_margin + 12 - 8;
129 vidc.h_interlace = vidc.h_cycle / 2;
130 vidc.v_sync_width = var->vsync_len - 1;
131 vidc.v_border_start = vidc.v_sync_width + var->upper_margin;
132 vidc.v_display_start = vidc.v_border_start;
133 vidc.v_display_end = vidc.v_display_start + var->yres;
134 vidc.v_border_end = vidc.v_display_end;
135 vidc.control = acornfb_default_control();
137 vcr = var->vsync_len + var->upper_margin + var->yres +
140 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
141 vidc.v_cycle = (vcr - 3) / 2;
142 vidc.control |= VIDC20_CTRL_INT;
144 vidc.v_cycle = vcr - 2;
146 switch (var->bits_per_pixel) {
147 case 1: vidc.control |= VIDC20_CTRL_1BPP; break;
148 case 2: vidc.control |= VIDC20_CTRL_2BPP; break;
149 case 4: vidc.control |= VIDC20_CTRL_4BPP; break;
151 case 8: vidc.control |= VIDC20_CTRL_8BPP; break;
152 case 16: vidc.control |= VIDC20_CTRL_16BPP; break;
153 case 32: vidc.control |= VIDC20_CTRL_32BPP; break;
156 acornfb_vidc20_find_rates(&vidc, var);
157 fsize = var->vsync_len + var->upper_margin + var->lower_margin - 1;
159 if (memcmp(¤t_vidc, &vidc, sizeof(vidc))) {
162 vidc_writel(VIDC20_CTRL | vidc.control);
163 vidc_writel(0xd0000000 | vidc.pll_ctl);
164 vidc_writel(0x80000000 | vidc.h_cycle);
165 vidc_writel(0x81000000 | vidc.h_sync_width);
166 vidc_writel(0x82000000 | vidc.h_border_start);
167 vidc_writel(0x83000000 | vidc.h_display_start);
168 vidc_writel(0x84000000 | vidc.h_display_end);
169 vidc_writel(0x85000000 | vidc.h_border_end);
170 vidc_writel(0x86000000);
171 vidc_writel(0x87000000 | vidc.h_interlace);
172 vidc_writel(0x90000000 | vidc.v_cycle);
173 vidc_writel(0x91000000 | vidc.v_sync_width);
174 vidc_writel(0x92000000 | vidc.v_border_start);
175 vidc_writel(0x93000000 | vidc.v_display_start);
176 vidc_writel(0x94000000 | vidc.v_display_end);
177 vidc_writel(0x95000000 | vidc.v_border_end);
178 vidc_writel(0x96000000);
179 vidc_writel(0x97000000);
182 iomd_writel(fsize, IOMD_FSIZE);
184 ext_ctl = acornfb_default_econtrol();
186 if (var->sync & FB_SYNC_COMP_HIGH_ACT) /* should be FB_SYNC_COMP */
187 ext_ctl |= VIDC20_ECTL_HS_NCSYNC | VIDC20_ECTL_VS_NCSYNC;
189 if (var->sync & FB_SYNC_HOR_HIGH_ACT)
190 ext_ctl |= VIDC20_ECTL_HS_HSYNC;
192 ext_ctl |= VIDC20_ECTL_HS_NHSYNC;
194 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
195 ext_ctl |= VIDC20_ECTL_VS_VSYNC;
197 ext_ctl |= VIDC20_ECTL_VS_NVSYNC;
200 vidc_writel(VIDC20_ECTL | ext_ctl);
202 words_per_line = var->xres * var->bits_per_pixel / 32;
204 if (current_par.using_vram && info->fix.smem_len == 2048*1024)
207 /* RiscPC doesn't use the VIDC's VRAM control. */
208 dat_ctl = VIDC20_DCTL_VRAM_DIS | VIDC20_DCTL_SNA | words_per_line;
210 /* The data bus width is dependent on both the type
211 * and amount of video memory.
216 if (current_par.using_vram && current_par.vram_half_sam == 2048)
217 dat_ctl |= VIDC20_DCTL_BUS_D63_0;
219 dat_ctl |= VIDC20_DCTL_BUS_D31_0;
221 vidc_writel(VIDC20_DCTL | dat_ctl);
223 #ifdef DEBUG_MODE_SELECTION
224 printk(KERN_DEBUG "VIDC registers for %dx%dx%d:\n", var->xres,
225 var->yres, var->bits_per_pixel);
226 printk(KERN_DEBUG " H-cycle : %d\n", vidc.h_cycle);
227 printk(KERN_DEBUG " H-sync-width : %d\n", vidc.h_sync_width);
228 printk(KERN_DEBUG " H-border-start : %d\n", vidc.h_border_start);
229 printk(KERN_DEBUG " H-display-start : %d\n", vidc.h_display_start);
230 printk(KERN_DEBUG " H-display-end : %d\n", vidc.h_display_end);
231 printk(KERN_DEBUG " H-border-end : %d\n", vidc.h_border_end);
232 printk(KERN_DEBUG " H-interlace : %d\n", vidc.h_interlace);
233 printk(KERN_DEBUG " V-cycle : %d\n", vidc.v_cycle);
234 printk(KERN_DEBUG " V-sync-width : %d\n", vidc.v_sync_width);
235 printk(KERN_DEBUG " V-border-start : %d\n", vidc.v_border_start);
236 printk(KERN_DEBUG " V-display-start : %d\n", vidc.v_display_start);
237 printk(KERN_DEBUG " V-display-end : %d\n", vidc.v_display_end);
238 printk(KERN_DEBUG " V-border-end : %d\n", vidc.v_border_end);
239 printk(KERN_DEBUG " Ext Ctrl (C) : 0x%08X\n", ext_ctl);
240 printk(KERN_DEBUG " PLL Ctrl (D) : 0x%08X\n", vidc.pll_ctl);
241 printk(KERN_DEBUG " Ctrl (E) : 0x%08X\n", vidc.control);
242 printk(KERN_DEBUG " Data Ctrl (F) : 0x%08X\n", dat_ctl);
243 printk(KERN_DEBUG " Fsize : 0x%08X\n", fsize);
248 * We have to take note of the VIDC20's 16-bit palette here.
249 * The VIDC20 looks up a 16 bit pixel as follows:
253 * red ++++++++ (8 bits, 7 to 0)
254 * green ++++++++ (8 bits, 11 to 4)
255 * blue ++++++++ (8 bits, 15 to 8)
257 * We use a pixel which looks like:
261 * red +++++ (5 bits, 4 to 0)
262 * green +++++ (5 bits, 9 to 5)
263 * blue +++++ (5 bits, 14 to 10)
266 acornfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
267 u_int trans, struct fb_info *info)
271 if (regno >= current_par.palette_size)
274 if (regno < 16 && info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
277 pseudo_val = regno << info->var.red.offset;
278 pseudo_val |= regno << info->var.green.offset;
279 pseudo_val |= regno << info->var.blue.offset;
281 ((u32 *)info->pseudo_palette)[regno] = pseudo_val;
285 pal.vidc20.red = red >> 8;
286 pal.vidc20.green = green >> 8;
287 pal.vidc20.blue = blue >> 8;
289 current_par.palette[regno] = pal;
291 if (info->var.bits_per_pixel == 16) {
295 vidc_writel(0x10000000);
296 for (i = 0; i < 256; i += 1) {
297 pal.vidc20.red = current_par.palette[i & 31].vidc20.red;
298 pal.vidc20.green = current_par.palette[(i >> 1) & 31].vidc20.green;
299 pal.vidc20.blue = current_par.palette[(i >> 2) & 31].vidc20.blue;
301 /* Palette register pointer auto-increments */
304 vidc_writel(0x10000000 | regno);
313 * Before selecting the timing parameters, adjust
314 * the resolution to fit the rules.
317 acornfb_adjust_timing(struct fb_info *info, struct fb_var_screeninfo *var, u_int fontht)
319 u_int font_line_len, sam_size, min_size, size, nr_y;
321 /* xres must be even */
322 var->xres = (var->xres + 1) & ~1;
325 * We don't allow xres_virtual to differ from xres
327 var->xres_virtual = var->xres;
330 if (current_par.using_vram)
331 sam_size = current_par.vram_half_sam * 2;
336 * Now, find a value for yres_virtual which allows
337 * us to do ywrap scrolling. The value of
338 * yres_virtual must be such that the end of the
339 * displayable frame buffer must be aligned with
340 * the start of a font line.
342 font_line_len = var->xres * var->bits_per_pixel * fontht / 8;
343 min_size = var->xres * var->yres * var->bits_per_pixel / 8;
346 * If minimum screen size is greater than that we have
347 * available, reject it.
349 if (min_size > info->fix.smem_len)
352 /* Find int 'y', such that y * fll == s * sam < maxsize
353 * y = s * sam / fll; s = maxsize / sam
355 for (size = info->fix.smem_len;
356 nr_y = size / font_line_len, min_size <= size;
358 if (nr_y * font_line_len == size)
363 if (var->accel_flags & FB_ACCELF_TEXT) {
364 if (min_size > size) {
368 size = info->fix.smem_len;
369 var->yres_virtual = size / (font_line_len / fontht);
371 var->yres_virtual = nr_y;
372 } else if (var->yres_virtual > nr_y)
373 var->yres_virtual = nr_y;
375 current_par.screen_end = info->fix.smem_start + size;
378 * Fix yres & yoffset if needed.
380 if (var->yres > var->yres_virtual)
381 var->yres = var->yres_virtual;
383 if (var->vmode & FB_VMODE_YWRAP) {
384 if (var->yoffset > var->yres_virtual)
385 var->yoffset = var->yres_virtual;
387 if (var->yoffset + var->yres > var->yres_virtual)
388 var->yoffset = var->yres_virtual - var->yres;
391 /* hsync_len must be even */
392 var->hsync_len = (var->hsync_len + 1) & ~1;
394 #if defined(HAS_VIDC20)
395 /* left_margin must be even */
396 if (var->left_margin & 1) {
397 var->left_margin += 1;
398 var->right_margin -= 1;
401 /* right_margin must be even */
402 if (var->right_margin & 1)
403 var->right_margin += 1;
406 if (var->vsync_len < 1)
413 acornfb_validate_timing(struct fb_var_screeninfo *var,
414 struct fb_monspecs *monspecs)
416 unsigned long hs, vs;
419 * hs(Hz) = 10^12 / (pixclock * xtotal)
420 * vs(Hz) = hs(Hz) / ytotal
422 * No need to do long long divisions or anything
423 * like that if you factor it correctly
425 hs = 1953125000 / var->pixclock;
427 (var->xres + var->left_margin + var->right_margin + var->hsync_len);
429 (var->yres + var->upper_margin + var->lower_margin + var->vsync_len);
431 return (vs >= monspecs->vfmin && vs <= monspecs->vfmax &&
432 hs >= monspecs->hfmin && hs <= monspecs->hfmax) ? 0 : -EINVAL;
436 acornfb_update_dma(struct fb_info *info, struct fb_var_screeninfo *var)
438 u_int off = var->yoffset * info->fix.line_length;
440 #if defined(HAS_MEMC)
441 memc_write(VDMA_INIT, off >> 2);
442 #elif defined(HAS_IOMD)
443 iomd_writel(info->fix.smem_start + off, IOMD_VIDINIT);
448 acornfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
454 * FIXME: Find the font height
458 var->red.msb_right = 0;
459 var->green.msb_right = 0;
460 var->blue.msb_right = 0;
461 var->transp.msb_right = 0;
463 switch (var->bits_per_pixel) {
464 case 1: case 2: case 4: case 8:
466 var->red.length = var->bits_per_pixel;
467 var->green = var->red;
468 var->blue = var->red;
469 var->transp.offset = 0;
470 var->transp.length = 0;
477 var->green.offset = 5;
478 var->green.length = 5;
479 var->blue.offset = 10;
480 var->blue.length = 5;
481 var->transp.offset = 15;
482 var->transp.length = 1;
488 var->green.offset = 8;
489 var->green.length = 8;
490 var->blue.offset = 16;
491 var->blue.length = 8;
492 var->transp.offset = 24;
493 var->transp.length = 4;
501 * Check to see if the pixel rate is valid.
503 if (!acornfb_valid_pixrate(var))
507 * Validate and adjust the resolution to
508 * match the video generator hardware.
510 err = acornfb_adjust_timing(info, var, fontht);
515 * Validate the timing against the
518 return acornfb_validate_timing(var, &info->monspecs);
521 static int acornfb_set_par(struct fb_info *info)
523 switch (info->var.bits_per_pixel) {
525 current_par.palette_size = 2;
526 info->fix.visual = FB_VISUAL_MONO10;
529 current_par.palette_size = 4;
530 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
533 current_par.palette_size = 16;
534 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
537 current_par.palette_size = VIDC_PALETTE_SIZE;
538 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
542 current_par.palette_size = 32;
543 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
546 current_par.palette_size = VIDC_PALETTE_SIZE;
547 info->fix.visual = FB_VISUAL_DIRECTCOLOR;
554 info->fix.line_length = (info->var.xres * info->var.bits_per_pixel) / 8;
556 #if defined(HAS_MEMC)
558 unsigned long size = info->fix.smem_len - VDMA_XFERSIZE;
560 memc_write(VDMA_START, 0);
561 memc_write(VDMA_END, size >> 2);
563 #elif defined(HAS_IOMD)
565 unsigned long start, size;
568 start = info->fix.smem_start;
569 size = current_par.screen_end;
571 if (current_par.using_vram) {
572 size -= current_par.vram_half_sam;
573 control = DMA_CR_E | (current_par.vram_half_sam / 256);
576 control = DMA_CR_E | DMA_CR_D | 16;
579 iomd_writel(start, IOMD_VIDSTART);
580 iomd_writel(size, IOMD_VIDEND);
581 iomd_writel(control, IOMD_VIDCR);
585 acornfb_update_dma(info, &info->var);
586 acornfb_set_timing(info);
592 acornfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
594 u_int y_bottom = var->yoffset;
596 if (!(var->vmode & FB_VMODE_YWRAP))
597 y_bottom += info->var.yres;
599 if (y_bottom > info->var.yres_virtual)
602 acornfb_update_dma(info, var);
607 static struct fb_ops acornfb_ops = {
608 .owner = THIS_MODULE,
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,
613 .fb_fillrect = cfb_fillrect,
614 .fb_copyarea = cfb_copyarea,
615 .fb_imageblit = cfb_imageblit,
619 * Everything after here is initialisation!!!
621 static struct fb_videomode modedb[] = {
622 { /* 320x256 @ 50Hz */
623 NULL, 50, 320, 256, 125000, 92, 62, 35, 19, 38, 2,
624 FB_SYNC_COMP_HIGH_ACT,
625 FB_VMODE_NONINTERLACED
626 }, { /* 640x250 @ 50Hz, 15.6 kHz hsync */
627 NULL, 50, 640, 250, 62500, 185, 123, 38, 21, 76, 3,
629 FB_VMODE_NONINTERLACED
630 }, { /* 640x256 @ 50Hz, 15.6 kHz hsync */
631 NULL, 50, 640, 256, 62500, 185, 123, 35, 18, 76, 3,
633 FB_VMODE_NONINTERLACED
634 }, { /* 640x512 @ 50Hz, 26.8 kHz hsync */
635 NULL, 50, 640, 512, 41667, 113, 87, 18, 1, 56, 3,
637 FB_VMODE_NONINTERLACED
638 }, { /* 640x250 @ 70Hz, 31.5 kHz hsync */
639 NULL, 70, 640, 250, 39722, 48, 16, 109, 88, 96, 2,
641 FB_VMODE_NONINTERLACED
642 }, { /* 640x256 @ 70Hz, 31.5 kHz hsync */
643 NULL, 70, 640, 256, 39722, 48, 16, 106, 85, 96, 2,
645 FB_VMODE_NONINTERLACED
646 }, { /* 640x352 @ 70Hz, 31.5 kHz hsync */
647 NULL, 70, 640, 352, 39722, 48, 16, 58, 37, 96, 2,
649 FB_VMODE_NONINTERLACED
650 }, { /* 640x480 @ 60Hz, 31.5 kHz hsync */
651 NULL, 60, 640, 480, 39722, 48, 16, 32, 11, 96, 2,
653 FB_VMODE_NONINTERLACED
654 }, { /* 800x600 @ 56Hz, 35.2 kHz hsync */
655 NULL, 56, 800, 600, 27778, 101, 23, 22, 1, 100, 2,
657 FB_VMODE_NONINTERLACED
658 }, { /* 896x352 @ 60Hz, 21.8 kHz hsync */
659 NULL, 60, 896, 352, 41667, 59, 27, 9, 0, 118, 3,
661 FB_VMODE_NONINTERLACED
662 }, { /* 1024x 768 @ 60Hz, 48.4 kHz hsync */
663 NULL, 60, 1024, 768, 15385, 160, 24, 29, 3, 136, 6,
665 FB_VMODE_NONINTERLACED
666 }, { /* 1280x1024 @ 60Hz, 63.8 kHz hsync */
667 NULL, 60, 1280, 1024, 9090, 186, 96, 38, 1, 160, 3,
669 FB_VMODE_NONINTERLACED
673 static struct fb_videomode acornfb_default_mode = {
686 .vmode = FB_VMODE_NONINTERLACED
689 static void acornfb_init_fbinfo(void)
691 static int first = 1;
697 fb_info.fbops = &acornfb_ops;
698 fb_info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
699 fb_info.pseudo_palette = current_par.pseudo_palette;
701 strcpy(fb_info.fix.id, "Acorn");
702 fb_info.fix.type = FB_TYPE_PACKED_PIXELS;
703 fb_info.fix.type_aux = 0;
704 fb_info.fix.xpanstep = 0;
705 fb_info.fix.ypanstep = 1;
706 fb_info.fix.ywrapstep = 1;
707 fb_info.fix.line_length = 0;
708 fb_info.fix.accel = FB_ACCEL_NONE;
711 * setup initial parameters
713 memset(&fb_info.var, 0, sizeof(fb_info.var));
715 #if defined(HAS_VIDC20)
716 fb_info.var.red.length = 8;
717 fb_info.var.transp.length = 4;
719 fb_info.var.green = fb_info.var.red;
720 fb_info.var.blue = fb_info.var.red;
721 fb_info.var.nonstd = 0;
722 fb_info.var.activate = FB_ACTIVATE_NOW;
723 fb_info.var.height = -1;
724 fb_info.var.width = -1;
725 fb_info.var.vmode = FB_VMODE_NONINTERLACED;
726 fb_info.var.accel_flags = FB_ACCELF_TEXT;
728 current_par.dram_size = 0;
729 current_par.montype = -1;
730 current_par.dpms = 0;
734 * setup acornfb options:
736 * mon:hmin-hmax:vmin-vmax:dpms:width:height
737 * Set monitor parameters:
738 * hmin = horizontal minimum frequency (Hz)
739 * hmax = horizontal maximum frequency (Hz) (optional)
740 * vmin = vertical minimum frequency (Hz)
741 * vmax = vertical maximum frequency (Hz) (optional)
742 * dpms = DPMS supported? (optional)
743 * width = width of picture in mm. (optional)
744 * height = height of picture in mm. (optional)
747 * Set RISC-OS style monitor type:
748 * 0 (or tv) - TV frequency
749 * 1 (or multi) - Multi frequency
750 * 2 (or hires) - Hi-res monochrome
753 * auto, or option missing
754 * - try hardware detect
757 * Set the amount of DRAM to use for the frame buffer
758 * (even if you have VRAM).
759 * size can optionally be followed by 'M' or 'K' for
760 * MB or KB respectively.
762 static void acornfb_parse_mon(char *opt)
766 current_par.montype = -2;
768 fb_info.monspecs.hfmin = simple_strtoul(p, &p, 0);
770 fb_info.monspecs.hfmax = simple_strtoul(p + 1, &p, 0);
772 fb_info.monspecs.hfmax = fb_info.monspecs.hfmin;
777 fb_info.monspecs.vfmin = simple_strtoul(p + 1, &p, 0);
779 fb_info.monspecs.vfmax = simple_strtoul(p + 1, &p, 0);
781 fb_info.monspecs.vfmax = fb_info.monspecs.vfmin;
786 fb_info.monspecs.dpms = simple_strtoul(p + 1, &p, 0);
791 fb_info.var.width = simple_strtoul(p + 1, &p, 0);
796 fb_info.var.height = simple_strtoul(p + 1, NULL, 0);
799 if (fb_info.monspecs.hfmax < fb_info.monspecs.hfmin ||
800 fb_info.monspecs.vfmax < fb_info.monspecs.vfmin)
805 printk(KERN_ERR "Acornfb: bad monitor settings: %s\n", opt);
806 current_par.montype = -1;
809 static void acornfb_parse_montype(char *opt)
811 current_par.montype = -2;
813 if (strncmp(opt, "tv", 2) == 0) {
815 current_par.montype = 0;
816 } else if (strncmp(opt, "multi", 5) == 0) {
818 current_par.montype = 1;
819 } else if (strncmp(opt, "hires", 5) == 0) {
821 current_par.montype = 2;
822 } else if (strncmp(opt, "vga", 3) == 0) {
824 current_par.montype = 3;
825 } else if (strncmp(opt, "svga", 4) == 0) {
827 current_par.montype = 4;
828 } else if (strncmp(opt, "auto", 4) == 0) {
830 current_par.montype = -1;
831 } else if (isdigit(*opt))
832 current_par.montype = simple_strtoul(opt, &opt, 0);
834 if (current_par.montype == -2 ||
835 current_par.montype > NR_MONTYPES) {
836 printk(KERN_ERR "acornfb: unknown monitor type: %s\n",
838 current_par.montype = -1;
841 if (strcmp(opt, ",dpms") == 0)
842 current_par.dpms = 1;
845 "acornfb: unknown monitor option: %s\n",
850 static void acornfb_parse_dram(char *opt)
854 size = simple_strtoul(opt, &opt, 0);
869 current_par.dram_size = size;
872 static struct options {
874 void (*parse)(char *opt);
876 { "mon", acornfb_parse_mon },
877 { "montype", acornfb_parse_montype },
878 { "dram", acornfb_parse_dram },
882 static int acornfb_setup(char *options)
884 struct options *optp;
887 if (!options || !*options)
890 acornfb_init_fbinfo();
892 while ((opt = strsep(&options, ",")) != NULL) {
896 for (optp = opt_table; optp->name; optp++) {
899 optlen = strlen(optp->name);
901 if (strncmp(opt, optp->name, optlen) == 0 &&
902 opt[optlen] == ':') {
903 optp->parse(opt + optlen + 1);
909 printk(KERN_ERR "acornfb: unknown parameter: %s\n",
916 * Detect type of monitor connected
917 * For now, we just assume SVGA
919 static int acornfb_detect_monitortype(void)
925 * This enables the unused memory to be freed on older Acorn machines.
926 * We are freeing memory on behalf of the architecture initialisation
930 free_unused_pages(unsigned int virtual_start, unsigned int virtual_end)
937 virtual_start = PAGE_ALIGN(virtual_start);
938 virtual_end = PAGE_ALIGN(virtual_end);
940 while (virtual_start < virtual_end) {
944 * Clear page reserved bit,
945 * set count to 1, and free
948 page = virt_to_page(virtual_start);
949 __free_reserved_page(page);
951 virtual_start += PAGE_SIZE;
952 mb_freed += PAGE_SIZE / 1024;
955 printk("acornfb: freed %dK memory\n", mb_freed);
958 static int acornfb_probe(struct platform_device *dev)
961 u_int h_sync, v_sync;
965 if (fb_get_options("acornfb", &option))
967 acornfb_setup(option);
969 acornfb_init_fbinfo();
971 current_par.dev = &dev->dev;
973 if (current_par.montype == -1)
974 current_par.montype = acornfb_detect_monitortype();
976 if (current_par.montype == -1 || current_par.montype > NR_MONTYPES)
977 current_par.montype = 4;
979 if (current_par.montype >= 0) {
980 fb_info.monspecs = monspecs[current_par.montype];
981 fb_info.monspecs.dpms = current_par.dpms;
985 * Try to select a suitable default mode
987 for (i = 0; i < ARRAY_SIZE(modedb); i++) {
990 hs = modedb[i].refresh *
991 (modedb[i].yres + modedb[i].upper_margin +
992 modedb[i].lower_margin + modedb[i].vsync_len);
993 if (modedb[i].xres == DEFAULT_XRES &&
994 modedb[i].yres == DEFAULT_YRES &&
995 modedb[i].refresh >= fb_info.monspecs.vfmin &&
996 modedb[i].refresh <= fb_info.monspecs.vfmax &&
997 hs >= fb_info.monspecs.hfmin &&
998 hs <= fb_info.monspecs.hfmax) {
999 acornfb_default_mode = modedb[i];
1004 fb_info.screen_base = (char *)SCREEN_BASE;
1005 fb_info.fix.smem_start = SCREEN_START;
1006 current_par.using_vram = 0;
1009 * If vram_size is set, we are using VRAM in
1010 * a Risc PC. However, if the user has specified
1011 * an amount of DRAM then use that instead.
1013 if (vram_size && !current_par.dram_size) {
1015 current_par.vram_half_sam = vram_size / 1024;
1016 current_par.using_vram = 1;
1017 } else if (current_par.dram_size)
1018 size = current_par.dram_size;
1023 * Limit maximum screen size.
1025 if (size > MAX_SIZE)
1028 size = PAGE_ALIGN(size);
1030 #if defined(HAS_VIDC20)
1031 if (!current_par.using_vram) {
1036 * RiscPC needs to allocate the DRAM memory
1037 * for the framebuffer if we are not using
1040 base = dma_alloc_wc(current_par.dev, size, &handle,
1043 printk(KERN_ERR "acornfb: unable to allocate screen memory\n");
1047 fb_info.screen_base = base;
1048 fb_info.fix.smem_start = handle;
1051 fb_info.fix.smem_len = size;
1052 current_par.palette_size = VIDC_PALETTE_SIZE;
1055 * Lookup the timing for this resolution. If we can't
1056 * find it, then we can't restore it if we change
1057 * the resolution, so we disable this feature.
1060 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
1062 &acornfb_default_mode, DEFAULT_BPP);
1064 * If we found an exact match, all ok.
1069 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
1070 &acornfb_default_mode, DEFAULT_BPP);
1072 * If we found an exact match, all ok.
1077 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, modedb,
1079 &acornfb_default_mode, DEFAULT_BPP);
1083 rc = fb_find_mode(&fb_info.var, &fb_info, NULL, NULL, 0,
1084 &acornfb_default_mode, DEFAULT_BPP);
1088 * If we didn't find an exact match, try the
1092 printk("Acornfb: no valid mode found\n");
1096 h_sync = 1953125000 / fb_info.var.pixclock;
1097 h_sync = h_sync * 512 / (fb_info.var.xres + fb_info.var.left_margin +
1098 fb_info.var.right_margin + fb_info.var.hsync_len);
1099 v_sync = h_sync / (fb_info.var.yres + fb_info.var.upper_margin +
1100 fb_info.var.lower_margin + fb_info.var.vsync_len);
1102 printk(KERN_INFO "Acornfb: %dkB %cRAM, %s, using %dx%d, %d.%03dkHz, %dHz\n",
1103 fb_info.fix.smem_len / 1024,
1104 current_par.using_vram ? 'V' : 'D',
1105 VIDC_NAME, fb_info.var.xres, fb_info.var.yres,
1106 h_sync / 1000, h_sync % 1000, v_sync);
1108 printk(KERN_INFO "Acornfb: Monitor: %d.%03d-%d.%03dkHz, %d-%dHz%s\n",
1109 fb_info.monspecs.hfmin / 1000, fb_info.monspecs.hfmin % 1000,
1110 fb_info.monspecs.hfmax / 1000, fb_info.monspecs.hfmax % 1000,
1111 fb_info.monspecs.vfmin, fb_info.monspecs.vfmax,
1112 fb_info.monspecs.dpms ? ", DPMS" : "");
1114 if (fb_set_var(&fb_info, &fb_info.var))
1115 printk(KERN_ERR "Acornfb: unable to set display parameters\n");
1117 if (register_framebuffer(&fb_info) < 0)
1122 static struct platform_driver acornfb_driver = {
1123 .probe = acornfb_probe,
1129 static int __init acornfb_init(void)
1131 return platform_driver_register(&acornfb_driver);
1134 module_init(acornfb_init);
1136 MODULE_AUTHOR("Russell King");
1137 MODULE_DESCRIPTION("VIDC 1/1a/20 framebuffer driver");
1138 MODULE_LICENSE("GPL");