2 * controlfb.c -- frame buffer device for the PowerMac 'control' display
4 * Created 12 July 1998 by Dan Jacobowitz <dan@debian.org>
5 * Copyright (C) 1998 Dan Jacobowitz
6 * Copyright (C) 2001 Takashi Oe
8 * Mmap code by Michel Lanners <mlan@cpu.lu>
10 * Frame buffer structure from:
11 * drivers/video/chipsfb.c -- frame buffer device for
12 * Chips & Technologies 65550 chip.
14 * Copyright (C) 1998 Paul Mackerras
16 * This file is derived from the Powermac "chips" driver:
17 * Copyright (C) 1997 Fabio Riccardi.
18 * And from the frame buffer device for Open Firmware-initialized devices:
19 * Copyright (C) 1997 Geert Uytterhoeven.
21 * Hardware information from:
22 * control.c: Console support for PowerMac "control" display adaptor.
23 * Copyright (C) 1996 Paul Mackerras
25 * Updated to 2.5 framebuffer API by Ben Herrenschmidt
26 * <benh@kernel.crashing.org>, Paul Mackerras <paulus@samba.org>,
27 * and James Simmons <jsimmons@infradead.org>.
29 * This file is subject to the terms and conditions of the GNU General Public
30 * License. See the file COPYING in the main directory of this archive for
34 #include <linux/kernel.h>
35 #include <linux/errno.h>
36 #include <linux/string.h>
38 #include <linux/slab.h>
39 #include <linux/vmalloc.h>
40 #include <linux/delay.h>
41 #include <linux/interrupt.h>
43 #include <linux/of_address.h>
45 #include <linux/init.h>
46 #include <linux/pci.h>
47 #include <linux/nvram.h>
48 #include <linux/adb.h>
49 #include <linux/cuda.h>
50 #ifdef CONFIG_BOOTX_TEXT
51 #include <asm/btext.h>
55 #include "controlfb.h"
57 #if !defined(CONFIG_PPC_PMAC) || !defined(CONFIG_PPC32)
58 #define invalid_vram_cache(addr)
64 #define out_8(addr, val) (void)(val)
65 #define in_le32(addr) 0
66 #define out_le32(addr, val) (void)(val)
67 #ifndef pgprot_cached_wthru
68 #define pgprot_cached_wthru(prot) (prot)
71 static void invalid_vram_cache(void __force *addr)
82 struct fb_par_control {
88 struct control_regvals regvals;
93 #define DIRTY(z) ((x)->z != (y)->z)
94 #define DIRTY_CMAP(z) (memcmp(&((x)->z), &((y)->z), sizeof((y)->z)))
95 static inline int PAR_EQUAL(struct fb_par_control *x, struct fb_par_control *y)
100 for (i = 0; i < 3; i++)
101 results &= !DIRTY(regvals.clock_params[i]);
104 for (i = 0; i < 16; i++)
105 results &= !DIRTY(regvals.regs[i]);
108 return (!DIRTY(cmode) && !DIRTY(xres) && !DIRTY(yres)
109 && !DIRTY(vxres) && !DIRTY(vyres));
112 struct fb_info_control {
114 struct fb_par_control par;
115 u32 pseudo_palette[16];
117 struct cmap_regs __iomem *cmap_regs;
118 unsigned long cmap_regs_phys;
120 struct control_regs __iomem *control_regs;
121 unsigned long control_regs_phys;
122 unsigned long control_regs_size;
124 __u8 __iomem *frame_buffer;
125 unsigned long frame_buffer_phys;
126 unsigned long fb_orig_base;
127 unsigned long fb_orig_size;
129 int control_use_bank2;
130 unsigned long total_vram;
131 unsigned char vram_attr;
134 /* control register access macro */
135 #define CNTRL_REG(INFO,REG) (&(((INFO)->control_regs->REG).r))
138 /************************** Internal variables *******************************/
140 static struct fb_info_control *control_fb;
142 static int default_vmode __initdata = VMODE_NVRAM;
143 static int default_cmode __initdata = CMODE_NVRAM;
146 static int controlfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
147 u_int transp, struct fb_info *info)
149 struct fb_info_control *p =
150 container_of(info, struct fb_info_control, info);
160 out_8(&p->cmap_regs->addr, regno); /* tell clut what addr to fill */
161 out_8(&p->cmap_regs->lut, r); /* send one color channel at */
162 out_8(&p->cmap_regs->lut, g); /* a time... */
163 out_8(&p->cmap_regs->lut, b);
167 switch (p->par.cmode) {
169 p->pseudo_palette[regno] =
170 (regno << 10) | (regno << 5) | regno;
173 i = (regno << 8) | regno;
174 p->pseudo_palette[regno] = (i << 16) | i;
183 /******************** End of controlfb_ops implementation ******************/
187 static void set_control_clock(unsigned char *params)
189 #ifdef CONFIG_ADB_CUDA
190 struct adb_request req;
193 for (i = 0; i < 3; ++i) {
194 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
195 0x50, i + 1, params[i]);
196 while (!req.complete)
203 * Set screen start address according to var offset values
205 static inline void set_screen_start(int xoffset, int yoffset,
206 struct fb_info_control *p)
208 struct fb_par_control *par = &p->par;
210 par->xoffset = xoffset;
211 par->yoffset = yoffset;
212 out_le32(CNTRL_REG(p,start_addr),
213 par->yoffset * par->pitch + (par->xoffset << par->cmode));
216 #define RADACAL_WRITE(a,d) \
217 out_8(&p->cmap_regs->addr, (a)); \
218 out_8(&p->cmap_regs->dat, (d))
220 /* Now how about actually saying, Make it so! */
221 /* Some things in here probably don't need to be done each time. */
222 static void control_set_hardware(struct fb_info_control *p, struct fb_par_control *par)
224 struct control_regvals *r;
225 volatile struct preg __iomem *rp;
228 if (PAR_EQUAL(&p->par, par)) {
230 * check if only xoffset or yoffset differs.
231 * this prevents flickers in typical VT switch case.
233 if (p->par.xoffset != par->xoffset ||
234 p->par.yoffset != par->yoffset)
235 set_screen_start(par->xoffset, par->yoffset, p);
241 cmode = p->par.cmode;
244 /* Turn off display */
245 out_le32(CNTRL_REG(p,ctrl), 0x400 | par->ctrl);
247 set_control_clock(r->clock_params);
249 RADACAL_WRITE(0x20, r->radacal_ctrl);
250 RADACAL_WRITE(0x21, p->control_use_bank2 ? 0 : 1);
251 RADACAL_WRITE(0x10, 0);
252 RADACAL_WRITE(0x11, 0);
254 rp = &p->control_regs->vswin;
255 for (i = 0; i < 16; ++i, ++rp)
256 out_le32(&rp->r, r->regs[i]);
258 out_le32(CNTRL_REG(p,pitch), par->pitch);
259 out_le32(CNTRL_REG(p,mode), r->mode);
260 out_le32(CNTRL_REG(p,vram_attr), p->vram_attr);
261 out_le32(CNTRL_REG(p,start_addr), par->yoffset * par->pitch
262 + (par->xoffset << cmode));
263 out_le32(CNTRL_REG(p,rfrcnt), 0x1e5);
264 out_le32(CNTRL_REG(p,intr_ena), 0);
266 /* Turn on display */
267 out_le32(CNTRL_REG(p,ctrl), par->ctrl);
269 #ifdef CONFIG_BOOTX_TEXT
270 btext_update_display(p->frame_buffer_phys + CTRLFB_OFF,
271 p->par.xres, p->par.yres,
272 (cmode == CMODE_32? 32: cmode == CMODE_16? 16: 8),
274 #endif /* CONFIG_BOOTX_TEXT */
277 /* Work out which banks of VRAM we have installed. */
278 /* danj: I guess the card just ignores writes to nonexistant VRAM... */
280 static void __init find_vram_size(struct fb_info_control *p)
285 * Set VRAM in 2MB (bank 1) mode
286 * VRAM Bank 2 will be accessible through offset 0x600000 if present
287 * and VRAM Bank 1 will not respond at that offset even if present
289 out_le32(CNTRL_REG(p,vram_attr), 0x31);
291 out_8(&p->frame_buffer[0x600000], 0xb3);
292 out_8(&p->frame_buffer[0x600001], 0x71);
293 invalid_vram_cache(&p->frame_buffer[0x600000]);
295 bank2 = (in_8(&p->frame_buffer[0x600000]) == 0xb3)
296 && (in_8(&p->frame_buffer[0x600001]) == 0x71);
299 * Set VRAM in 2MB (bank 2) mode
300 * VRAM Bank 1 will be accessible through offset 0x000000 if present
301 * and VRAM Bank 2 will not respond at that offset even if present
303 out_le32(CNTRL_REG(p,vram_attr), 0x39);
305 out_8(&p->frame_buffer[0], 0x5a);
306 out_8(&p->frame_buffer[1], 0xc7);
307 invalid_vram_cache(&p->frame_buffer[0]);
309 bank1 = (in_8(&p->frame_buffer[0]) == 0x5a)
310 && (in_8(&p->frame_buffer[1]) == 0xc7);
317 p->control_use_bank2 = 1;
319 p->frame_buffer += 0x600000;
320 p->frame_buffer_phys += 0x600000;
334 p->total_vram = (bank1 + bank2) * 0x200000;
336 printk(KERN_INFO "controlfb: VRAM Total = %dMB "
337 "(%dMB @ bank 1, %dMB @ bank 2)\n",
338 (bank1 + bank2) << 1, bank1 << 1, bank2 << 1);
342 * Get the monitor sense value.
343 * Note that this can be called before calibrate_delay,
344 * so we can't use udelay.
346 static int read_control_sense(struct fb_info_control *p)
350 out_le32(CNTRL_REG(p,mon_sense), 7); /* drive all lines high */
352 out_le32(CNTRL_REG(p,mon_sense), 077); /* turn off drivers */
354 sense = (in_le32(CNTRL_REG(p,mon_sense)) & 0x1c0) << 2;
356 /* drive each sense line low in turn and collect the other 2 */
357 out_le32(CNTRL_REG(p,mon_sense), 033); /* drive A low */
359 sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0xc0) >> 2;
360 out_le32(CNTRL_REG(p,mon_sense), 055); /* drive B low */
362 sense |= ((in_le32(CNTRL_REG(p,mon_sense)) & 0x100) >> 5)
363 | ((in_le32(CNTRL_REG(p,mon_sense)) & 0x40) >> 4);
364 out_le32(CNTRL_REG(p,mon_sense), 066); /* drive C low */
366 sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0x180) >> 7;
368 out_le32(CNTRL_REG(p,mon_sense), 077); /* turn off drivers */
373 /********************** Various translation functions **********************/
375 #define CONTROL_PIXCLOCK_BASE 256016
376 #define CONTROL_PIXCLOCK_MIN 5000 /* ~ 200 MHz dot clock */
379 * calculate the clock paramaters to be sent to CUDA according to given
380 * pixclock in pico second.
382 static int calc_clock_params(unsigned long clk, unsigned char *param)
384 unsigned long p0, p1, p2, k, l, m, n, min;
386 if (clk > (CONTROL_PIXCLOCK_BASE << 3))
389 p2 = ((clk << 4) < CONTROL_PIXCLOCK_BASE)? 3: 2;
393 for (k = 1, min = l; k < 32; k++) {
396 m = CONTROL_PIXCLOCK_BASE * k;
399 if (n && (n < 128) && rem < min) {
417 * This routine takes a user-supplied var, and picks the best vmode/cmode
421 static int control_var_to_par(struct fb_var_screeninfo *var,
422 struct fb_par_control *par, const struct fb_info *fb_info)
424 int cmode, piped_diff, hstep;
425 unsigned hperiod, hssync, hsblank, hesync, heblank, piped, heq, hlfln,
426 hserr, vperiod, vssync, vesync, veblank, vsblank, vswin, vewin;
427 unsigned long pixclock;
428 struct fb_info_control *p =
429 container_of(fb_info, struct fb_info_control, info);
430 struct control_regvals *r = &par->regvals;
432 switch (var->bits_per_pixel) {
434 par->cmode = CMODE_8;
435 if (p->total_vram > 0x200000) {
437 r->radacal_ctrl = 0x20;
441 r->radacal_ctrl = 0x10;
447 par->cmode = CMODE_16;
448 if (p->total_vram > 0x200000) {
450 r->radacal_ctrl = 0x24;
454 r->radacal_ctrl = 0x14;
459 par->cmode = CMODE_32;
460 if (p->total_vram > 0x200000) {
462 r->radacal_ctrl = 0x28;
465 r->radacal_ctrl = 0x18;
474 * adjust xres and vxres so that the corresponding memory widths are
477 hstep = 31 >> par->cmode;
478 par->xres = (var->xres + hstep) & ~hstep;
479 par->vxres = (var->xres_virtual + hstep) & ~hstep;
480 par->xoffset = (var->xoffset + hstep) & ~hstep;
481 if (par->vxres < par->xres)
482 par->vxres = par->xres;
483 par->pitch = par->vxres << par->cmode;
485 par->yres = var->yres;
486 par->vyres = var->yres_virtual;
487 par->yoffset = var->yoffset;
488 if (par->vyres < par->yres)
489 par->vyres = par->yres;
491 par->sync = var->sync;
493 if (par->pitch * par->vyres + CTRLFB_OFF > p->total_vram)
496 if (par->xoffset + par->xres > par->vxres)
497 par->xoffset = par->vxres - par->xres;
498 if (par->yoffset + par->yres > par->vyres)
499 par->yoffset = par->vyres - par->yres;
501 pixclock = (var->pixclock < CONTROL_PIXCLOCK_MIN)? CONTROL_PIXCLOCK_MIN:
503 if (calc_clock_params(pixclock, r->clock_params))
506 hperiod = ((var->left_margin + par->xres + var->right_margin
507 + var->hsync_len) >> 1) - 2;
508 hssync = hperiod + 1;
509 hsblank = hssync - (var->right_margin >> 1);
510 hesync = (var->hsync_len >> 1) - 1;
511 heblank = (var->left_margin >> 1) + hesync;
512 piped = heblank - piped_diff;
513 heq = var->hsync_len >> 2;
514 hlfln = (hperiod+2) >> 1;
515 hserr = hssync-hesync;
516 vperiod = (var->vsync_len + var->lower_margin + par->yres
517 + var->upper_margin) << 1;
518 vssync = vperiod - 2;
519 vesync = (var->vsync_len << 1) - vperiod + vssync;
520 veblank = (var->upper_margin << 1) + vesync;
521 vsblank = vssync - (var->lower_margin << 1);
522 vswin = (vsblank+vssync) >> 1;
523 vewin = (vesync+veblank) >> 1;
526 r->regs[1] = vsblank;
527 r->regs[2] = veblank;
531 r->regs[6] = vperiod;
533 r->regs[8] = hperiod;
534 r->regs[9] = hsblank;
535 r->regs[10] = heblank;
536 r->regs[11] = hesync;
537 r->regs[12] = hssync;
542 if (par->xres >= 1280 && par->cmode >= CMODE_16)
547 if (mac_var_to_vmode(var, &par->vmode, &cmode))
555 * Convert hardware data in par to an fb_var_screeninfo
558 static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeninfo *var)
560 struct control_regints *rv;
562 rv = (struct control_regints *) par->regvals.regs;
564 memset(var, 0, sizeof(*var));
565 var->xres = par->xres;
566 var->yres = par->yres;
567 var->xres_virtual = par->vxres;
568 var->yres_virtual = par->vyres;
569 var->xoffset = par->xoffset;
570 var->yoffset = par->yoffset;
575 var->bits_per_pixel = 8;
577 var->green.length = 8;
578 var->blue.length = 8;
580 case CMODE_16: /* RGB 555 */
581 var->bits_per_pixel = 16;
582 var->red.offset = 10;
584 var->green.offset = 5;
585 var->green.length = 5;
586 var->blue.length = 5;
588 case CMODE_32: /* RGB 888 */
589 var->bits_per_pixel = 32;
590 var->red.offset = 16;
592 var->green.offset = 8;
593 var->green.length = 8;
594 var->blue.length = 8;
595 var->transp.offset = 24;
596 var->transp.length = 8;
601 var->vmode = FB_VMODE_NONINTERLACED;
603 var->left_margin = (rv->heblank - rv->hesync) << 1;
604 var->right_margin = (rv->hssync - rv->hsblank) << 1;
605 var->hsync_len = (rv->hperiod + 2 - rv->hssync + rv->hesync) << 1;
607 var->upper_margin = (rv->veblank - rv->vesync) >> 1;
608 var->lower_margin = (rv->vssync - rv->vsblank) >> 1;
609 var->vsync_len = (rv->vperiod - rv->vssync + rv->vesync) >> 1;
611 var->sync = par->sync;
614 * 10^12 * clock_params[0] / (3906400 * clock_params[1]
615 * * 2^clock_params[2])
616 * (10^12 * clock_params[0] / (3906400 * clock_params[1]))
619 /* (255990.17 * clock_params[0] / clock_params[1]) >> clock_params[2] */
620 var->pixclock = CONTROL_PIXCLOCK_BASE * par->regvals.clock_params[0];
621 var->pixclock /= par->regvals.clock_params[1];
622 var->pixclock >>= par->regvals.clock_params[2];
625 /******************** The functions for controlfb_ops ********************/
628 * Checks a var structure
630 static int controlfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
632 struct fb_par_control par;
635 err = control_var_to_par(var, &par, info);
638 control_par_to_var(&par, var);
644 * Applies current var to display
646 static int controlfb_set_par (struct fb_info *info)
648 struct fb_info_control *p =
649 container_of(info, struct fb_info_control, info);
650 struct fb_par_control par;
653 if((err = control_var_to_par(&info->var, &par, info))) {
654 printk (KERN_ERR "controlfb_set_par: error calling"
655 " control_var_to_par: %d.\n", err);
659 control_set_hardware(p, &par);
661 info->fix.visual = (p->par.cmode == CMODE_8) ?
662 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
663 info->fix.line_length = p->par.pitch;
664 info->fix.xpanstep = 32 >> p->par.cmode;
665 info->fix.ypanstep = 1;
670 static int controlfb_pan_display(struct fb_var_screeninfo *var,
671 struct fb_info *info)
673 unsigned int xoffset, hstep;
674 struct fb_info_control *p =
675 container_of(info, struct fb_info_control, info);
676 struct fb_par_control *par = &p->par;
679 * make sure start addr will be 32-byte aligned
681 hstep = 0x1f >> par->cmode;
682 xoffset = (var->xoffset + hstep) & ~hstep;
684 if (xoffset+par->xres > par->vxres ||
685 var->yoffset+par->yres > par->vyres)
688 set_screen_start(xoffset, var->yoffset, p);
693 static int controlfb_blank(int blank_mode, struct fb_info *info)
695 struct fb_info_control __maybe_unused *p =
696 container_of(info, struct fb_info_control, info);
699 ctrl = in_le32(CNTRL_REG(p, ctrl));
701 switch (blank_mode) {
702 case FB_BLANK_VSYNC_SUSPEND:
705 case FB_BLANK_HSYNC_SUSPEND:
708 case FB_BLANK_POWERDOWN:
711 case FB_BLANK_NORMAL:
721 out_le32(CNTRL_REG(p,ctrl), ctrl);
727 * Private mmap since we want to have a different caching on the framebuffer
729 * Note there's no locking in here; it's done in fb_mmap() in fbmem.c.
731 static int controlfb_mmap(struct fb_info *info,
732 struct vm_area_struct *vma)
734 unsigned long mmio_pgoff;
738 start = info->fix.smem_start;
739 len = info->fix.smem_len;
740 mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
741 if (vma->vm_pgoff >= mmio_pgoff) {
742 if (info->var.accel_flags)
744 vma->vm_pgoff -= mmio_pgoff;
745 start = info->fix.mmio_start;
746 len = info->fix.mmio_len;
747 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
750 vma->vm_page_prot = pgprot_cached_wthru(vma->vm_page_prot);
753 return vm_iomap_memory(vma, start, len);
756 static const struct fb_ops controlfb_ops = {
757 .owner = THIS_MODULE,
758 .fb_check_var = controlfb_check_var,
759 .fb_set_par = controlfb_set_par,
760 .fb_setcolreg = controlfb_setcolreg,
761 .fb_pan_display = controlfb_pan_display,
762 .fb_blank = controlfb_blank,
763 .fb_mmap = controlfb_mmap,
764 .fb_fillrect = cfb_fillrect,
765 .fb_copyarea = cfb_copyarea,
766 .fb_imageblit = cfb_imageblit,
770 * Set misc info vars for this driver
772 static void __init control_init_info(struct fb_info *info, struct fb_info_control *p)
776 info->fbops = &controlfb_ops;
777 info->pseudo_palette = p->pseudo_palette;
778 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
779 info->screen_base = p->frame_buffer + CTRLFB_OFF;
781 fb_alloc_cmap(&info->cmap, 256, 0);
783 /* Fill fix common fields */
784 strcpy(info->fix.id, "control");
785 info->fix.mmio_start = p->control_regs_phys;
786 info->fix.mmio_len = sizeof(struct control_regs);
787 info->fix.type = FB_TYPE_PACKED_PIXELS;
788 info->fix.smem_start = p->frame_buffer_phys + CTRLFB_OFF;
789 info->fix.smem_len = p->total_vram - CTRLFB_OFF;
790 info->fix.ywrapstep = 0;
791 info->fix.type_aux = 0;
792 info->fix.accel = FB_ACCEL_NONE;
796 * Parse user specified options (`video=controlfb:')
798 static void __init control_setup(char *options)
802 if (!options || !*options)
805 while ((this_opt = strsep(&options, ",")) != NULL) {
806 if (!strncmp(this_opt, "vmode:", 6)) {
807 int vmode = simple_strtoul(this_opt+6, NULL, 0);
808 if (vmode > 0 && vmode <= VMODE_MAX &&
809 control_mac_modes[vmode - 1].m[1] >= 0)
810 default_vmode = vmode;
811 } else if (!strncmp(this_opt, "cmode:", 6)) {
812 int depth = simple_strtoul(this_opt+6, NULL, 0);
817 default_cmode = depth;
820 default_cmode = CMODE_8;
824 default_cmode = CMODE_16;
828 default_cmode = CMODE_32;
836 * finish off the driver initialization and register
838 static int __init init_control(struct fb_info_control *p)
840 int full, sense, vmode, cmode, vyres;
841 struct fb_var_screeninfo var;
844 printk(KERN_INFO "controlfb: ");
846 full = p->total_vram == 0x400000;
848 /* Try to pick a video mode out of NVRAM if we have one. */
849 cmode = default_cmode;
850 if (IS_REACHABLE(CONFIG_NVRAM) && cmode == CMODE_NVRAM)
851 cmode = nvram_read_byte(NV_CMODE);
852 if (cmode < CMODE_8 || cmode > CMODE_32)
855 vmode = default_vmode;
856 if (IS_REACHABLE(CONFIG_NVRAM) && vmode == VMODE_NVRAM)
857 vmode = nvram_read_byte(NV_VMODE);
858 if (vmode < 1 || vmode > VMODE_MAX ||
859 control_mac_modes[vmode - 1].m[full] < cmode) {
860 sense = read_control_sense(p);
861 printk(KERN_CONT "Monitor sense value = 0x%x, ", sense);
862 vmode = mac_map_monitor_sense(sense);
863 if (control_mac_modes[vmode - 1].m[full] < 0)
864 vmode = VMODE_640_480_60;
865 cmode = min(cmode, control_mac_modes[vmode - 1].m[full]);
868 /* Initialize info structure */
869 control_init_info(&p->info, p);
871 /* Setup default var */
872 if (mac_vmode_to_var(vmode, cmode, &var) < 0) {
873 /* This shouldn't happen! */
874 printk("mac_vmode_to_var(%d, %d,) failed\n", vmode, cmode);
876 vmode = VMODE_640_480_60;
878 if (mac_vmode_to_var(vmode, cmode, &var) < 0) {
879 printk(KERN_ERR "controlfb: mac_vmode_to_var() failed\n");
882 printk(KERN_INFO "controlfb: ");
884 printk("using video mode %d and color mode %d.\n", vmode, cmode);
886 vyres = (p->total_vram - CTRLFB_OFF) / (var.xres << cmode);
887 if (vyres > var.yres)
888 var.yres_virtual = vyres;
890 /* Apply default var */
891 var.activate = FB_ACTIVATE_NOW;
892 rc = fb_set_var(&p->info, &var);
893 if (rc && (vmode != VMODE_640_480_60 || cmode != CMODE_8))
896 /* Register with fbdev layer */
897 if (register_framebuffer(&p->info) < 0)
900 fb_info(&p->info, "control display adapter\n");
905 static void control_cleanup(void)
907 struct fb_info_control *p = control_fb;
913 iounmap(p->cmap_regs);
915 iounmap(p->control_regs);
916 if (p->frame_buffer) {
917 if (p->control_use_bank2)
918 p->frame_buffer -= 0x600000;
919 iounmap(p->frame_buffer);
921 if (p->cmap_regs_phys)
922 release_mem_region(p->cmap_regs_phys, 0x1000);
923 if (p->control_regs_phys)
924 release_mem_region(p->control_regs_phys, p->control_regs_size);
926 release_mem_region(p->fb_orig_base, p->fb_orig_size);
931 * find "control" and initialize
933 static int __init control_of_init(struct device_node *dp)
935 struct fb_info_control *p;
936 struct resource fb_res, reg_res;
939 printk(KERN_ERR "controlfb: only one control is supported\n");
943 if (of_pci_address_to_resource(dp, 2, &fb_res) ||
944 of_pci_address_to_resource(dp, 1, ®_res)) {
945 printk(KERN_ERR "can't get 2 addresses for control\n");
948 p = kzalloc(sizeof(*p), GFP_KERNEL);
951 control_fb = p; /* save it for cleanups */
953 /* Map in frame buffer and registers */
954 p->fb_orig_base = fb_res.start;
955 p->fb_orig_size = resource_size(&fb_res);
956 /* use the big-endian aperture (??) */
957 p->frame_buffer_phys = fb_res.start + 0x800000;
958 p->control_regs_phys = reg_res.start;
959 p->control_regs_size = resource_size(®_res);
961 if (!p->fb_orig_base ||
962 !request_mem_region(p->fb_orig_base,p->fb_orig_size,"controlfb")) {
966 /* map at most 8MB for the frame buffer */
967 p->frame_buffer = ioremap_wt(p->frame_buffer_phys, 0x800000);
969 if (!p->control_regs_phys ||
970 !request_mem_region(p->control_regs_phys, p->control_regs_size,
972 p->control_regs_phys = 0;
975 p->control_regs = ioremap(p->control_regs_phys, p->control_regs_size);
977 p->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
978 if (!request_mem_region(p->cmap_regs_phys, 0x1000, "controlfb cmap")) {
979 p->cmap_regs_phys = 0;
982 p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000);
984 if (!p->cmap_regs || !p->control_regs || !p->frame_buffer)
991 if (init_control(p) < 0)
1001 static int __init control_init(void)
1003 struct device_node *dp;
1004 char *option = NULL;
1007 if (fb_get_options("controlfb", &option))
1009 control_setup(option);
1011 dp = of_find_node_by_name(NULL, "control");
1012 if (dp && !control_of_init(dp))
1019 device_initcall(control_init);