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_PPC_PMAC
52 #include <asm/btext.h>
56 #include "controlfb.h"
58 #if !defined(CONFIG_PPC_PMAC) || !defined(CONFIG_PPC32)
59 #define invalid_vram_cache(addr)
65 #define out_8(addr, val)
66 #define in_le32(addr) 0
67 #define out_le32(addr, val)
68 #define pgprot_cached_wthru(prot) (prot)
70 static void invalid_vram_cache(void __force *addr)
81 struct fb_par_control {
87 struct control_regvals regvals;
92 #define DIRTY(z) ((x)->z != (y)->z)
93 #define DIRTY_CMAP(z) (memcmp(&((x)->z), &((y)->z), sizeof((y)->z)))
94 static inline int PAR_EQUAL(struct fb_par_control *x, struct fb_par_control *y)
99 for (i = 0; i < 3; i++)
100 results &= !DIRTY(regvals.clock_params[i]);
103 for (i = 0; i < 16; i++)
104 results &= !DIRTY(regvals.regs[i]);
107 return (!DIRTY(cmode) && !DIRTY(xres) && !DIRTY(yres)
108 && !DIRTY(vxres) && !DIRTY(vyres));
110 static inline int VAR_MATCH(struct fb_var_screeninfo *x, struct fb_var_screeninfo *y)
112 return (!DIRTY(bits_per_pixel) && !DIRTY(xres)
113 && !DIRTY(yres) && !DIRTY(xres_virtual)
114 && !DIRTY(yres_virtual)
115 && !DIRTY_CMAP(red) && !DIRTY_CMAP(green) && !DIRTY_CMAP(blue));
118 struct fb_info_control {
120 struct fb_par_control par;
121 u32 pseudo_palette[16];
123 struct cmap_regs __iomem *cmap_regs;
124 unsigned long cmap_regs_phys;
126 struct control_regs __iomem *control_regs;
127 unsigned long control_regs_phys;
128 unsigned long control_regs_size;
130 __u8 __iomem *frame_buffer;
131 unsigned long frame_buffer_phys;
132 unsigned long fb_orig_base;
133 unsigned long fb_orig_size;
135 int control_use_bank2;
136 unsigned long total_vram;
137 unsigned char vram_attr;
140 /* control register access macro */
141 #define CNTRL_REG(INFO,REG) (&(((INFO)->control_regs->REG).r))
144 /************************** Internal variables *******************************/
146 static struct fb_info_control *control_fb;
148 static int default_vmode __initdata = VMODE_NVRAM;
149 static int default_cmode __initdata = CMODE_NVRAM;
152 static int controlfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
153 u_int transp, struct fb_info *info)
155 struct fb_info_control *p =
156 container_of(info, struct fb_info_control, info);
166 out_8(&p->cmap_regs->addr, regno); /* tell clut what addr to fill */
167 out_8(&p->cmap_regs->lut, r); /* send one color channel at */
168 out_8(&p->cmap_regs->lut, g); /* a time... */
169 out_8(&p->cmap_regs->lut, b);
173 switch (p->par.cmode) {
175 p->pseudo_palette[regno] =
176 (regno << 10) | (regno << 5) | regno;
179 i = (regno << 8) | regno;
180 p->pseudo_palette[regno] = (i << 16) | i;
189 /******************** End of controlfb_ops implementation ******************/
193 static void set_control_clock(unsigned char *params)
195 #ifdef CONFIG_ADB_CUDA
196 struct adb_request req;
199 for (i = 0; i < 3; ++i) {
200 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC,
201 0x50, i + 1, params[i]);
202 while (!req.complete)
209 * Set screen start address according to var offset values
211 static inline void set_screen_start(int xoffset, int yoffset,
212 struct fb_info_control *p)
214 struct fb_par_control *par = &p->par;
216 par->xoffset = xoffset;
217 par->yoffset = yoffset;
218 out_le32(CNTRL_REG(p,start_addr),
219 par->yoffset * par->pitch + (par->xoffset << par->cmode));
222 #define RADACAL_WRITE(a,d) \
223 out_8(&p->cmap_regs->addr, (a)); \
224 out_8(&p->cmap_regs->dat, (d))
226 /* Now how about actually saying, Make it so! */
227 /* Some things in here probably don't need to be done each time. */
228 static void control_set_hardware(struct fb_info_control *p, struct fb_par_control *par)
230 struct control_regvals *r;
231 volatile struct preg __iomem *rp;
234 if (PAR_EQUAL(&p->par, par)) {
236 * check if only xoffset or yoffset differs.
237 * this prevents flickers in typical VT switch case.
239 if (p->par.xoffset != par->xoffset ||
240 p->par.yoffset != par->yoffset)
241 set_screen_start(par->xoffset, par->yoffset, p);
247 cmode = p->par.cmode;
250 /* Turn off display */
251 out_le32(CNTRL_REG(p,ctrl), 0x400 | par->ctrl);
253 set_control_clock(r->clock_params);
255 RADACAL_WRITE(0x20, r->radacal_ctrl);
256 RADACAL_WRITE(0x21, p->control_use_bank2 ? 0 : 1);
257 RADACAL_WRITE(0x10, 0);
258 RADACAL_WRITE(0x11, 0);
260 rp = &p->control_regs->vswin;
261 for (i = 0; i < 16; ++i, ++rp)
262 out_le32(&rp->r, r->regs[i]);
264 out_le32(CNTRL_REG(p,pitch), par->pitch);
265 out_le32(CNTRL_REG(p,mode), r->mode);
266 out_le32(CNTRL_REG(p,vram_attr), p->vram_attr);
267 out_le32(CNTRL_REG(p,start_addr), par->yoffset * par->pitch
268 + (par->xoffset << cmode));
269 out_le32(CNTRL_REG(p,rfrcnt), 0x1e5);
270 out_le32(CNTRL_REG(p,intr_ena), 0);
272 /* Turn on display */
273 out_le32(CNTRL_REG(p,ctrl), par->ctrl);
275 #ifdef CONFIG_BOOTX_TEXT
276 btext_update_display(p->frame_buffer_phys + CTRLFB_OFF,
277 p->par.xres, p->par.yres,
278 (cmode == CMODE_32? 32: cmode == CMODE_16? 16: 8),
280 #endif /* CONFIG_BOOTX_TEXT */
283 /* Work out which banks of VRAM we have installed. */
284 /* danj: I guess the card just ignores writes to nonexistant VRAM... */
286 static void __init find_vram_size(struct fb_info_control *p)
291 * Set VRAM in 2MB (bank 1) mode
292 * VRAM Bank 2 will be accessible through offset 0x600000 if present
293 * and VRAM Bank 1 will not respond at that offset even if present
295 out_le32(CNTRL_REG(p,vram_attr), 0x31);
297 out_8(&p->frame_buffer[0x600000], 0xb3);
298 out_8(&p->frame_buffer[0x600001], 0x71);
299 invalid_vram_cache(&p->frame_buffer[0x600000]);
301 bank2 = (in_8(&p->frame_buffer[0x600000]) == 0xb3)
302 && (in_8(&p->frame_buffer[0x600001]) == 0x71);
305 * Set VRAM in 2MB (bank 2) mode
306 * VRAM Bank 1 will be accessible through offset 0x000000 if present
307 * and VRAM Bank 2 will not respond at that offset even if present
309 out_le32(CNTRL_REG(p,vram_attr), 0x39);
311 out_8(&p->frame_buffer[0], 0x5a);
312 out_8(&p->frame_buffer[1], 0xc7);
313 invalid_vram_cache(&p->frame_buffer[0]);
315 bank1 = (in_8(&p->frame_buffer[0]) == 0x5a)
316 && (in_8(&p->frame_buffer[1]) == 0xc7);
323 p->control_use_bank2 = 1;
325 p->frame_buffer += 0x600000;
326 p->frame_buffer_phys += 0x600000;
340 p->total_vram = (bank1 + bank2) * 0x200000;
342 printk(KERN_INFO "controlfb: VRAM Total = %dMB "
343 "(%dMB @ bank 1, %dMB @ bank 2)\n",
344 (bank1 + bank2) << 1, bank1 << 1, bank2 << 1);
348 * Get the monitor sense value.
349 * Note that this can be called before calibrate_delay,
350 * so we can't use udelay.
352 static int read_control_sense(struct fb_info_control *p)
356 out_le32(CNTRL_REG(p,mon_sense), 7); /* drive all lines high */
358 out_le32(CNTRL_REG(p,mon_sense), 077); /* turn off drivers */
360 sense = (in_le32(CNTRL_REG(p,mon_sense)) & 0x1c0) << 2;
362 /* drive each sense line low in turn and collect the other 2 */
363 out_le32(CNTRL_REG(p,mon_sense), 033); /* drive A low */
365 sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0xc0) >> 2;
366 out_le32(CNTRL_REG(p,mon_sense), 055); /* drive B low */
368 sense |= ((in_le32(CNTRL_REG(p,mon_sense)) & 0x100) >> 5)
369 | ((in_le32(CNTRL_REG(p,mon_sense)) & 0x40) >> 4);
370 out_le32(CNTRL_REG(p,mon_sense), 066); /* drive C low */
372 sense |= (in_le32(CNTRL_REG(p,mon_sense)) & 0x180) >> 7;
374 out_le32(CNTRL_REG(p,mon_sense), 077); /* turn off drivers */
379 /********************** Various translation functions **********************/
381 #define CONTROL_PIXCLOCK_BASE 256016
382 #define CONTROL_PIXCLOCK_MIN 5000 /* ~ 200 MHz dot clock */
385 * calculate the clock paramaters to be sent to CUDA according to given
386 * pixclock in pico second.
388 static int calc_clock_params(unsigned long clk, unsigned char *param)
390 unsigned long p0, p1, p2, k, l, m, n, min;
392 if (clk > (CONTROL_PIXCLOCK_BASE << 3))
395 p2 = ((clk << 4) < CONTROL_PIXCLOCK_BASE)? 3: 2;
399 for (k = 1, min = l; k < 32; k++) {
402 m = CONTROL_PIXCLOCK_BASE * k;
405 if (n && (n < 128) && rem < min) {
423 * This routine takes a user-supplied var, and picks the best vmode/cmode
427 static int control_var_to_par(struct fb_var_screeninfo *var,
428 struct fb_par_control *par, const struct fb_info *fb_info)
430 int cmode, piped_diff, hstep;
431 unsigned hperiod, hssync, hsblank, hesync, heblank, piped, heq, hlfln,
432 hserr, vperiod, vssync, vesync, veblank, vsblank, vswin, vewin;
433 unsigned long pixclock;
434 struct fb_info_control *p =
435 container_of(fb_info, struct fb_info_control, info);
436 struct control_regvals *r = &par->regvals;
438 switch (var->bits_per_pixel) {
440 par->cmode = CMODE_8;
441 if (p->total_vram > 0x200000) {
443 r->radacal_ctrl = 0x20;
447 r->radacal_ctrl = 0x10;
453 par->cmode = CMODE_16;
454 if (p->total_vram > 0x200000) {
456 r->radacal_ctrl = 0x24;
460 r->radacal_ctrl = 0x14;
465 par->cmode = CMODE_32;
466 if (p->total_vram > 0x200000) {
468 r->radacal_ctrl = 0x28;
471 r->radacal_ctrl = 0x18;
480 * adjust xres and vxres so that the corresponding memory widths are
483 hstep = 31 >> par->cmode;
484 par->xres = (var->xres + hstep) & ~hstep;
485 par->vxres = (var->xres_virtual + hstep) & ~hstep;
486 par->xoffset = (var->xoffset + hstep) & ~hstep;
487 if (par->vxres < par->xres)
488 par->vxres = par->xres;
489 par->pitch = par->vxres << par->cmode;
491 par->yres = var->yres;
492 par->vyres = var->yres_virtual;
493 par->yoffset = var->yoffset;
494 if (par->vyres < par->yres)
495 par->vyres = par->yres;
497 par->sync = var->sync;
499 if (par->pitch * par->vyres + CTRLFB_OFF > p->total_vram)
502 if (par->xoffset + par->xres > par->vxres)
503 par->xoffset = par->vxres - par->xres;
504 if (par->yoffset + par->yres > par->vyres)
505 par->yoffset = par->vyres - par->yres;
507 pixclock = (var->pixclock < CONTROL_PIXCLOCK_MIN)? CONTROL_PIXCLOCK_MIN:
509 if (calc_clock_params(pixclock, r->clock_params))
512 hperiod = ((var->left_margin + par->xres + var->right_margin
513 + var->hsync_len) >> 1) - 2;
514 hssync = hperiod + 1;
515 hsblank = hssync - (var->right_margin >> 1);
516 hesync = (var->hsync_len >> 1) - 1;
517 heblank = (var->left_margin >> 1) + hesync;
518 piped = heblank - piped_diff;
519 heq = var->hsync_len >> 2;
520 hlfln = (hperiod+2) >> 1;
521 hserr = hssync-hesync;
522 vperiod = (var->vsync_len + var->lower_margin + par->yres
523 + var->upper_margin) << 1;
524 vssync = vperiod - 2;
525 vesync = (var->vsync_len << 1) - vperiod + vssync;
526 veblank = (var->upper_margin << 1) + vesync;
527 vsblank = vssync - (var->lower_margin << 1);
528 vswin = (vsblank+vssync) >> 1;
529 vewin = (vesync+veblank) >> 1;
532 r->regs[1] = vsblank;
533 r->regs[2] = veblank;
537 r->regs[6] = vperiod;
539 r->regs[8] = hperiod;
540 r->regs[9] = hsblank;
541 r->regs[10] = heblank;
542 r->regs[11] = hesync;
543 r->regs[12] = hssync;
548 if (par->xres >= 1280 && par->cmode >= CMODE_16)
553 if (mac_var_to_vmode(var, &par->vmode, &cmode))
561 * Convert hardware data in par to an fb_var_screeninfo
564 static void control_par_to_var(struct fb_par_control *par, struct fb_var_screeninfo *var)
566 struct control_regints *rv;
568 rv = (struct control_regints *) par->regvals.regs;
570 memset(var, 0, sizeof(*var));
571 var->xres = par->xres;
572 var->yres = par->yres;
573 var->xres_virtual = par->vxres;
574 var->yres_virtual = par->vyres;
575 var->xoffset = par->xoffset;
576 var->yoffset = par->yoffset;
581 var->bits_per_pixel = 8;
583 var->green.length = 8;
584 var->blue.length = 8;
586 case CMODE_16: /* RGB 555 */
587 var->bits_per_pixel = 16;
588 var->red.offset = 10;
590 var->green.offset = 5;
591 var->green.length = 5;
592 var->blue.length = 5;
594 case CMODE_32: /* RGB 888 */
595 var->bits_per_pixel = 32;
596 var->red.offset = 16;
598 var->green.offset = 8;
599 var->green.length = 8;
600 var->blue.length = 8;
601 var->transp.offset = 24;
602 var->transp.length = 8;
607 var->vmode = FB_VMODE_NONINTERLACED;
609 var->left_margin = (rv->heblank - rv->hesync) << 1;
610 var->right_margin = (rv->hssync - rv->hsblank) << 1;
611 var->hsync_len = (rv->hperiod + 2 - rv->hssync + rv->hesync) << 1;
613 var->upper_margin = (rv->veblank - rv->vesync) >> 1;
614 var->lower_margin = (rv->vssync - rv->vsblank) >> 1;
615 var->vsync_len = (rv->vperiod - rv->vssync + rv->vesync) >> 1;
617 var->sync = par->sync;
620 * 10^12 * clock_params[0] / (3906400 * clock_params[1]
621 * * 2^clock_params[2])
622 * (10^12 * clock_params[0] / (3906400 * clock_params[1]))
625 /* (255990.17 * clock_params[0] / clock_params[1]) >> clock_params[2] */
626 var->pixclock = CONTROL_PIXCLOCK_BASE * par->regvals.clock_params[0];
627 var->pixclock /= par->regvals.clock_params[1];
628 var->pixclock >>= par->regvals.clock_params[2];
631 /******************** The functions for controlfb_ops ********************/
634 * Checks a var structure
636 static int controlfb_check_var (struct fb_var_screeninfo *var, struct fb_info *info)
638 struct fb_par_control par;
641 err = control_var_to_par(var, &par, info);
644 control_par_to_var(&par, var);
650 * Applies current var to display
652 static int controlfb_set_par (struct fb_info *info)
654 struct fb_info_control *p =
655 container_of(info, struct fb_info_control, info);
656 struct fb_par_control par;
659 if((err = control_var_to_par(&info->var, &par, info))) {
660 printk (KERN_ERR "controlfb_set_par: error calling"
661 " control_var_to_par: %d.\n", err);
665 control_set_hardware(p, &par);
667 info->fix.visual = (p->par.cmode == CMODE_8) ?
668 FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR;
669 info->fix.line_length = p->par.pitch;
670 info->fix.xpanstep = 32 >> p->par.cmode;
671 info->fix.ypanstep = 1;
676 static int controlfb_pan_display(struct fb_var_screeninfo *var,
677 struct fb_info *info)
679 unsigned int xoffset, hstep;
680 struct fb_info_control *p =
681 container_of(info, struct fb_info_control, info);
682 struct fb_par_control *par = &p->par;
685 * make sure start addr will be 32-byte aligned
687 hstep = 0x1f >> par->cmode;
688 xoffset = (var->xoffset + hstep) & ~hstep;
690 if (xoffset+par->xres > par->vxres ||
691 var->yoffset+par->yres > par->vyres)
694 set_screen_start(xoffset, var->yoffset, p);
699 static int controlfb_blank(int blank_mode, struct fb_info *info)
701 struct fb_info_control __maybe_unused *p =
702 container_of(info, struct fb_info_control, info);
705 ctrl = in_le32(CNTRL_REG(p, ctrl));
707 switch (blank_mode) {
708 case FB_BLANK_VSYNC_SUSPEND:
711 case FB_BLANK_HSYNC_SUSPEND:
714 case FB_BLANK_POWERDOWN:
717 case FB_BLANK_NORMAL:
727 out_le32(CNTRL_REG(p,ctrl), ctrl);
733 * Private mmap since we want to have a different caching on the framebuffer
735 * Note there's no locking in here; it's done in fb_mmap() in fbmem.c.
737 static int controlfb_mmap(struct fb_info *info,
738 struct vm_area_struct *vma)
740 unsigned long mmio_pgoff;
744 start = info->fix.smem_start;
745 len = info->fix.smem_len;
746 mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
747 if (vma->vm_pgoff >= mmio_pgoff) {
748 if (info->var.accel_flags)
750 vma->vm_pgoff -= mmio_pgoff;
751 start = info->fix.mmio_start;
752 len = info->fix.mmio_len;
753 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
756 vma->vm_page_prot = pgprot_cached_wthru(vma->vm_page_prot);
759 return vm_iomap_memory(vma, start, len);
762 static const struct fb_ops controlfb_ops = {
763 .owner = THIS_MODULE,
764 .fb_check_var = controlfb_check_var,
765 .fb_set_par = controlfb_set_par,
766 .fb_setcolreg = controlfb_setcolreg,
767 .fb_pan_display = controlfb_pan_display,
768 .fb_blank = controlfb_blank,
769 .fb_mmap = controlfb_mmap,
770 .fb_fillrect = cfb_fillrect,
771 .fb_copyarea = cfb_copyarea,
772 .fb_imageblit = cfb_imageblit,
776 * Set misc info vars for this driver
778 static void __init control_init_info(struct fb_info *info, struct fb_info_control *p)
782 info->fbops = &controlfb_ops;
783 info->pseudo_palette = p->pseudo_palette;
784 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
785 info->screen_base = p->frame_buffer + CTRLFB_OFF;
787 fb_alloc_cmap(&info->cmap, 256, 0);
789 /* Fill fix common fields */
790 strcpy(info->fix.id, "control");
791 info->fix.mmio_start = p->control_regs_phys;
792 info->fix.mmio_len = sizeof(struct control_regs);
793 info->fix.type = FB_TYPE_PACKED_PIXELS;
794 info->fix.smem_start = p->frame_buffer_phys + CTRLFB_OFF;
795 info->fix.smem_len = p->total_vram - CTRLFB_OFF;
796 info->fix.ywrapstep = 0;
797 info->fix.type_aux = 0;
798 info->fix.accel = FB_ACCEL_NONE;
802 * Parse user specified options (`video=controlfb:')
804 static void __init control_setup(char *options)
808 if (!options || !*options)
811 while ((this_opt = strsep(&options, ",")) != NULL) {
812 if (!strncmp(this_opt, "vmode:", 6)) {
813 int vmode = simple_strtoul(this_opt+6, NULL, 0);
814 if (vmode > 0 && vmode <= VMODE_MAX &&
815 control_mac_modes[vmode - 1].m[1] >= 0)
816 default_vmode = vmode;
817 } else if (!strncmp(this_opt, "cmode:", 6)) {
818 int depth = simple_strtoul(this_opt+6, NULL, 0);
823 default_cmode = depth;
826 default_cmode = CMODE_8;
830 default_cmode = CMODE_16;
834 default_cmode = CMODE_32;
842 * finish off the driver initialization and register
844 static int __init init_control(struct fb_info_control *p)
846 int full, sense, vmode, cmode, vyres;
847 struct fb_var_screeninfo var;
850 printk(KERN_INFO "controlfb: ");
852 full = p->total_vram == 0x400000;
854 /* Try to pick a video mode out of NVRAM if we have one. */
855 cmode = default_cmode;
856 if (IS_REACHABLE(CONFIG_NVRAM) && cmode == CMODE_NVRAM)
857 cmode = nvram_read_byte(NV_CMODE);
858 if (cmode < CMODE_8 || cmode > CMODE_32)
861 vmode = default_vmode;
862 if (IS_REACHABLE(CONFIG_NVRAM) && vmode == VMODE_NVRAM)
863 vmode = nvram_read_byte(NV_VMODE);
864 if (vmode < 1 || vmode > VMODE_MAX ||
865 control_mac_modes[vmode - 1].m[full] < cmode) {
866 sense = read_control_sense(p);
867 printk(KERN_CONT "Monitor sense value = 0x%x, ", sense);
868 vmode = mac_map_monitor_sense(sense);
869 if (control_mac_modes[vmode - 1].m[full] < 0)
870 vmode = VMODE_640_480_60;
871 cmode = min(cmode, control_mac_modes[vmode - 1].m[full]);
874 /* Initialize info structure */
875 control_init_info(&p->info, p);
877 /* Setup default var */
878 if (mac_vmode_to_var(vmode, cmode, &var) < 0) {
879 /* This shouldn't happen! */
880 printk("mac_vmode_to_var(%d, %d,) failed\n", vmode, cmode);
882 vmode = VMODE_640_480_60;
884 if (mac_vmode_to_var(vmode, cmode, &var) < 0) {
885 printk(KERN_ERR "controlfb: mac_vmode_to_var() failed\n");
888 printk(KERN_INFO "controlfb: ");
890 printk("using video mode %d and color mode %d.\n", vmode, cmode);
892 vyres = (p->total_vram - CTRLFB_OFF) / (var.xres << cmode);
893 if (vyres > var.yres)
894 var.yres_virtual = vyres;
896 /* Apply default var */
897 var.activate = FB_ACTIVATE_NOW;
898 rc = fb_set_var(&p->info, &var);
899 if (rc && (vmode != VMODE_640_480_60 || cmode != CMODE_8))
902 /* Register with fbdev layer */
903 if (register_framebuffer(&p->info) < 0)
906 fb_info(&p->info, "control display adapter\n");
911 static void control_cleanup(void)
913 struct fb_info_control *p = control_fb;
919 iounmap(p->cmap_regs);
921 iounmap(p->control_regs);
922 if (p->frame_buffer) {
923 if (p->control_use_bank2)
924 p->frame_buffer -= 0x600000;
925 iounmap(p->frame_buffer);
927 if (p->cmap_regs_phys)
928 release_mem_region(p->cmap_regs_phys, 0x1000);
929 if (p->control_regs_phys)
930 release_mem_region(p->control_regs_phys, p->control_regs_size);
932 release_mem_region(p->fb_orig_base, p->fb_orig_size);
937 * find "control" and initialize
939 static int __init control_of_init(struct device_node *dp)
941 struct fb_info_control *p;
942 struct resource fb_res, reg_res;
945 printk(KERN_ERR "controlfb: only one control is supported\n");
949 if (of_pci_address_to_resource(dp, 2, &fb_res) ||
950 of_pci_address_to_resource(dp, 1, ®_res)) {
951 printk(KERN_ERR "can't get 2 addresses for control\n");
954 p = kzalloc(sizeof(*p), GFP_KERNEL);
957 control_fb = p; /* save it for cleanups */
959 /* Map in frame buffer and registers */
960 p->fb_orig_base = fb_res.start;
961 p->fb_orig_size = resource_size(&fb_res);
962 /* use the big-endian aperture (??) */
963 p->frame_buffer_phys = fb_res.start + 0x800000;
964 p->control_regs_phys = reg_res.start;
965 p->control_regs_size = resource_size(®_res);
967 if (!p->fb_orig_base ||
968 !request_mem_region(p->fb_orig_base,p->fb_orig_size,"controlfb")) {
972 /* map at most 8MB for the frame buffer */
973 p->frame_buffer = ioremap_wt(p->frame_buffer_phys, 0x800000);
975 if (!p->control_regs_phys ||
976 !request_mem_region(p->control_regs_phys, p->control_regs_size,
978 p->control_regs_phys = 0;
981 p->control_regs = ioremap(p->control_regs_phys, p->control_regs_size);
983 p->cmap_regs_phys = 0xf301b000; /* XXX not in prom? */
984 if (!request_mem_region(p->cmap_regs_phys, 0x1000, "controlfb cmap")) {
985 p->cmap_regs_phys = 0;
988 p->cmap_regs = ioremap(p->cmap_regs_phys, 0x1000);
990 if (!p->cmap_regs || !p->control_regs || !p->frame_buffer)
997 if (init_control(p) < 0)
1007 static int __init control_init(void)
1009 struct device_node *dp;
1010 char *option = NULL;
1013 if (fb_get_options("controlfb", &option))
1015 control_setup(option);
1017 dp = of_find_node_by_name(NULL, "control");
1018 if (dp && !control_of_init(dp))
1025 device_initcall(control_init);