Driver
Jean-Paul Smets <[email protected]> Thu, 22 May 2003 14:35:53 +0200
| Newsgroups | gmane.comp.hardware.openbrick.general |
|---|---|
| Organization | Nexedi |
| Message-ID | <[email protected]> |
Here is the latest cyber2000 driver for Linux kernel. Russell King was kind enough to send it to me. I could get accelerated fb driver with this one (and use XFree fb driver). I followed the steps explained in the directfb list. Again, I will try to write some doc asap. By changing a bit this driver, I think it is possible to control PAL/NTSC output. JPS. -- Jean-Paul Smets-Solanes Nexedi CEO Tel. +33(0)6 62 05 76 14 Fax. +33(0)1 53 01 09 29 About www.nexedi.com Nexedi is a consulting and development services company helping small and medium organisations to choose open source / free software and fulfill their IT application needs. Nexedi is the founder of the ERP5 project, a Free / Open Source ERP software based on innovative technologies (www.erp5.org). About www.storever.com Storever provides a reliable source for OpenBrick, WiFi infrastructure, notebooks and servers preconfigured with the GNU/Linux operating system
cyber2000fb.c
(text/x-csrc, 48.3 KB)
/* * linux/drivers/video/cyber2000fb.c * * Copyright (C) 1998-2002 Russell King * * MIPS and 50xx clock support * Copyright (C) 2001 Bradley D. LaRonde <[email protected]> * * 32 bit support, text color and panning fixes for modes != 8 bit * Copyright (C) 2002 Denis Oliver Kropp <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Integraphics CyberPro 2000, 2010 and 5000 frame buffer device * * Based on cyberfb.c. * * Note that we now use the new fbcon fix, var and cmap scheme. We do * still have to check which console is the currently displayed one * however, especially for the colourmap stuff. * * We also use the new hotplug PCI subsystem. I'm not sure if there * are any such cards, but I'm erring on the side of caution. We don't * want to go pop just because someone does have one. * * Note that this doesn't work fully in the case of multiple CyberPro * cards with grabbers. We currently can only attach to the first * CyberPro card found. * * When we're in truecolour mode, we power down the LUT RAM as a power * saving feature. Also, when we enter any of the powersaving modes * (except soft blanking) we power down the RAMDACs. This saves about * 1W, which is roughly 8% of the power consumption of a NetWinder * (which, incidentally, is about the same saving as a 2.5in hard disk * entering standby mode.) */ #include <linux/config.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/string.h> #include <linux/mm.h> #include <linux/tty.h> #include <linux/slab.h> #include <linux/delay.h> #include <linux/fb.h> #include <linux/pci.h> #include <linux/init.h> #include <asm/io.h> #include <asm/irq.h> #include <asm/pgtable.h> #include <asm/system.h> #include <asm/uaccess.h> #include <video/fbcon.h> #include <video/fbcon-cfb8.h> #include <video/fbcon-cfb16.h> #include <video/fbcon-cfb24.h> #include <video/fbcon-cfb32.h> #include "cyber2000fb.h" struct cfb_info { struct fb_info fb; struct display_switch *dispsw; struct display *display; struct pci_dev *dev; unsigned char *region; unsigned char *regs; u_int id; int func_use_count; u_long ref_ps; /* * Clock divisors */ u_int divisors[4]; struct { u8 red, green, blue; } palette[NR_PALETTE]; u_char mem_ctl0; u_char mem_ctl1; u_char mem_ctl2; u_char mclk_mult; u_char mclk_div; /* * RAMDAC control register is both of these or'ed together */ u_char ramdac_ctrl; u_char ramdac_powerdown; }; static char default_font_storage[40]; static char *default_font = "Acorn8x8"; MODULE_PARM(default_font, "s"); MODULE_PARM_DESC(default_font, "Default font name"); /* * Our access methods. */ #define cyber2000fb_writel(val,reg,cfb) writel(val, (cfb)->regs + (reg)) #define cyber2000fb_writew(val,reg,cfb) writew(val, (cfb)->regs + (reg)) #define cyber2000fb_writeb(val,reg,cfb) writeb(val, (cfb)->regs + (reg)) #define cyber2000fb_readb(reg,cfb) readb((cfb)->regs + (reg)) static inline void cyber2000_crtcw(unsigned int reg, unsigned int val, struct cfb_info *cfb) { cyber2000fb_writew((reg & 255) | val << 8, 0x3d4, cfb); } static inline void cyber2000_grphw(unsigned int reg, unsigned int val, struct cfb_info *cfb) { cyber2000fb_writew((reg & 255) | val << 8, 0x3ce, cfb); } static inline unsigned int cyber2000_grphr(unsigned int reg, struct cfb_info *cfb) { cyber2000fb_writeb(reg, 0x3ce, cfb); return cyber2000fb_readb(0x3cf, cfb); } static inline void cyber2000_attrw(unsigned int reg, unsigned int val, struct cfb_info *cfb) { cyber2000fb_readb(0x3da, cfb); cyber2000fb_writeb(reg, 0x3c0, cfb); cyber2000fb_readb(0x3c1, cfb); cyber2000fb_writeb(val, 0x3c0, cfb); } static inline void cyber2000_seqw(unsigned int reg, unsigned int val, struct cfb_info *cfb) { cyber2000fb_writew((reg & 255) | val << 8, 0x3c4, cfb); } /* -------------------- Hardware specific routines ------------------------- */ /* * Hardware Cyber2000 Acceleration */ static void cyber2000_accel_wait(struct cfb_info *cfb) { int count = 100000; while (cyber2000fb_readb(CO_REG_CONTROL, cfb) & CO_CTRL_BUSY) { if (!count--) { debug_printf("accel_wait timed out\n"); cyber2000fb_writeb(0, CO_REG_CONTROL, cfb); return; } udelay(1); } } static void cyber2000_accel_setup(struct display *display) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; cfb->dispsw->setup(display); } static void cyber2000_accel_bmove(struct display *display, int sy, int sx, int dy, int dx, int height, int width) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; struct fb_var_screeninfo *var = &display->var; u_long src, dst; u_int fh, fw, cmd = CO_CMD_L_PATTERN_FGCOL; fw = fontwidth(display); sx *= fw; dx *= fw; width *= fw; width -= 1; if (sx < dx) { sx += width; dx += width; cmd |= CO_CMD_L_INC_LEFT; } fh = fontheight(display); sy *= fh; dy *= fh; height *= fh; height -= 1; if (sy < dy) { sy += height; dy += height; cmd |= CO_CMD_L_INC_UP; } src = sx + sy * var->xres_virtual; dst = dx + dy * var->xres_virtual; cyber2000_accel_wait(cfb); cyber2000fb_writeb(0x00, CO_REG_CONTROL, cfb); cyber2000fb_writew(width, CO_REG_PIXWIDTH, cfb); cyber2000fb_writew(height, CO_REG_PIXHEIGHT, cfb); if (var->bits_per_pixel == 24) { cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb); dst *= 3; src *= 3; } cyber2000fb_writel(src, CO_REG_SRC1_PTR, cfb); cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb); cyber2000fb_writeb(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb); cyber2000fb_writew(cmd, CO_REG_CMD_L, cfb); cyber2000fb_writew(CO_CMD_H_FGSRCMAP|CO_CMD_H_BLITTER, CO_REG_CMD_H, cfb); } static void cyber2000_accel_clear(struct vc_data *conp, struct display *display, int sy, int sx, int height, int width) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; struct fb_var_screeninfo *var = &display->var; u_long dst; u_int fw, fh; u32 bgx = attr_bgcol_ec(display, conp); fw = fontwidth(display); fh = fontheight(display); dst = sx * fw + sy * var->xres_virtual * fh; width = width * fw - 1; height = height * fh - 1; cyber2000_accel_wait(cfb); cyber2000fb_writeb(0x00, CO_REG_CONTROL, cfb); cyber2000fb_writew(width, CO_REG_PIXWIDTH, cfb); cyber2000fb_writew(height, CO_REG_PIXHEIGHT, cfb); if (var->bits_per_pixel == 24) { cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb); dst *= 3; } if (var->bits_per_pixel == 16) bgx = ((u16 *)display->dispsw_data)[bgx]; else if (var->bits_per_pixel >= 24) bgx = ((u32 *)display->dispsw_data)[bgx]; cyber2000fb_writel(bgx, CO_REG_FGCOLOUR, cfb); cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb); cyber2000fb_writeb(CO_FG_MIX_SRC, CO_REG_FGMIX, cfb); cyber2000fb_writew(CO_CMD_L_PATTERN_FGCOL, CO_REG_CMD_L, cfb); cyber2000fb_writew(CO_CMD_H_BLITTER, CO_REG_CMD_H, cfb); } static void cyber2000_accel_putc(struct vc_data *conp, struct display *display, int c, int yy, int xx) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; cyber2000_accel_wait(cfb); cfb->dispsw->putc(conp, display, c, yy, xx); } static void cyber2000_accel_putcs(struct vc_data *conp, struct display *display, const unsigned short *s, int count, int yy, int xx) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; cyber2000_accel_wait(cfb); cfb->dispsw->putcs(conp, display, s, count, yy, xx); } static void cyber2000_accel_revc(struct display *display, int xx, int yy) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; cyber2000_accel_wait(cfb); cfb->dispsw->revc(display, xx, yy); } static void cyber2000_accel_clear_margins(struct vc_data *conp, struct display *display, int bottom_only) { struct cfb_info *cfb = (struct cfb_info *)display->fb_info; cfb->dispsw->clear_margins(conp, display, bottom_only); } static struct display_switch fbcon_cyber_accel = { .setup = cyber2000_accel_setup, .bmove = cyber2000_accel_bmove, .clear = cyber2000_accel_clear, .putc = cyber2000_accel_putc, .putcs = cyber2000_accel_putcs, .revc = cyber2000_accel_revc, .clear_margins = cyber2000_accel_clear_margins, .fontwidthmask = FONTWIDTH(8)|FONTWIDTH(16) }; static inline u32 convert_bitfield(u_int val, struct fb_bitfield *bf) { u_int mask = (1 << bf->length) - 1; return (val >> (16 - bf->length) & mask) << bf->offset; } /* * Set a single color register. Return != 0 for invalid regno. */ static int cyber2000fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, u_int transp, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; struct fb_var_screeninfo *var = &cfb->display->var; u32 pseudo_val; int ret = 1; switch (cfb->fb.fix.visual) { default: return 1; #ifdef FBCON_HAS_CFB8 /* * Pseudocolour: * 8 8 * pixel --/--+--/--> red lut --> red dac * | 8 * +--/--> green lut --> green dac * | 8 * +--/--> blue lut --> blue dac */ case FB_VISUAL_PSEUDOCOLOR: if (regno >= NR_PALETTE) return 1; red >>= 8; green >>= 8; blue >>= 8; cfb->palette[regno].red = red; cfb->palette[regno].green = green; cfb->palette[regno].blue = blue; cyber2000fb_writeb(regno, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); return 0; #endif /* * Direct colour: * n rl * pixel --/--+--/--> red lut --> red dac * | gl * +--/--> green lut --> green dac * | bl * +--/--> blue lut --> blue dac * n = bpp, rl = red length, gl = green length, bl = blue length */ case FB_VISUAL_DIRECTCOLOR: red >>= 8; green >>= 8; blue >>= 8; if (var->green.length == 6 && regno < 64) { cfb->palette[regno << 2].green = green; /* * The 6 bits of the green component are applied * to the high 6 bits of the LUT. */ cyber2000fb_writeb(regno << 2, 0x3c8, cfb); cyber2000fb_writeb(cfb->palette[regno >> 1].red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(cfb->palette[regno >> 1].blue, 0x3c9, cfb); green = cfb->palette[regno << 3].green; ret = 0; } if (var->green.length >= 5 && regno < 32) { cfb->palette[regno << 3].red = red; cfb->palette[regno << 3].green = green; cfb->palette[regno << 3].blue = blue; /* * The 5 bits of each colour component are * applied to the high 5 bits of the LUT. */ cyber2000fb_writeb(regno << 3, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); ret = 0; } if (var->green.length == 4 && regno < 16) { cfb->palette[regno << 4].red = red; cfb->palette[regno << 4].green = green; cfb->palette[regno << 4].blue = blue; /* * The 5 bits of each colour component are * applied to the high 5 bits of the LUT. */ cyber2000fb_writeb(regno << 4, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); ret = 0; } /* * Since this is only used for the first 16 colours, we * don't have to care about overflowing for regno >= 32 */ pseudo_val = regno << var->red.offset | regno << var->green.offset | regno << var->blue.offset; break; /* * True colour: * n rl * pixel --/--+--/--> red dac * | gl * +--/--> green dac * | bl * +--/--> blue dac * n = bpp, rl = red length, gl = green length, bl = blue length */ case FB_VISUAL_TRUECOLOR: pseudo_val = convert_bitfield(transp ^ 0xffff, &var->transp); pseudo_val |= convert_bitfield(red, &var->red); pseudo_val |= convert_bitfield(green, &var->green); pseudo_val |= convert_bitfield(blue, &var->blue); break; } /* * Now set our pseudo palette for the CFB16/24/32 drivers. */ if (regno < 16) { if (var->bits_per_pixel == 16) ((u16 *)cfb->fb.pseudo_palette)[regno] = pseudo_val; else ((u32 *)cfb->fb.pseudo_palette)[regno] = pseudo_val; ret = 0; } return ret; } struct par_info { /* * Hardware */ u_char clock_mult; u_char clock_div; u_char extseqmisc; u_char co_pixfmt; u_char crtc_ofl; u_char crtc[19]; u_int width; u_int pitch; u_int fetch; /* * Other */ u_char ramdac; }; static const u_char crtc_idx[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18 }; static void cyber2000fb_write_ramdac_ctrl(struct cfb_info *cfb) { unsigned int i; unsigned int val = cfb->ramdac_ctrl | cfb->ramdac_powerdown; cyber2000fb_writeb(0x56, 0x3ce, cfb); i = cyber2000fb_readb(0x3cf, cfb); cyber2000fb_writeb(i | 4, 0x3cf, cfb); cyber2000fb_writeb(val, 0x3c6, cfb); cyber2000fb_writeb(i, 0x3cf, cfb); } static void cyber2000fb_set_timing(struct cfb_info *cfb, struct par_info *hw) { u_int i; /* * Blank palette */ for (i = 0; i < NR_PALETTE; i++) { cyber2000fb_writeb(i, 0x3c8, cfb); cyber2000fb_writeb(0, 0x3c9, cfb); cyber2000fb_writeb(0, 0x3c9, cfb); cyber2000fb_writeb(0, 0x3c9, cfb); } cyber2000fb_writeb(0xef, 0x3c2, cfb); cyber2000_crtcw(0x11, 0x0b, cfb); cyber2000_attrw(0x11, 0x00, cfb); cyber2000_seqw(0x00, 0x01, cfb); cyber2000_seqw(0x01, 0x01, cfb); cyber2000_seqw(0x02, 0x0f, cfb); cyber2000_seqw(0x03, 0x00, cfb); cyber2000_seqw(0x04, 0x0e, cfb); cyber2000_seqw(0x00, 0x03, cfb); for (i = 0; i < sizeof(crtc_idx); i++) cyber2000_crtcw(crtc_idx[i], hw->crtc[i], cfb); for (i = 0x0a; i < 0x10; i++) cyber2000_crtcw(i, 0, cfb); cyber2000_grphw(EXT_CRT_VRTOFL, hw->crtc_ofl, cfb); cyber2000_grphw(0x00, 0x00, cfb); cyber2000_grphw(0x01, 0x00, cfb); cyber2000_grphw(0x02, 0x00, cfb); cyber2000_grphw(0x03, 0x00, cfb); cyber2000_grphw(0x04, 0x00, cfb); cyber2000_grphw(0x05, 0x60, cfb); cyber2000_grphw(0x06, 0x05, cfb); cyber2000_grphw(0x07, 0x0f, cfb); cyber2000_grphw(0x08, 0xff, cfb); /* Attribute controller registers */ for (i = 0; i < 16; i++) cyber2000_attrw(i, i, cfb); cyber2000_attrw(0x10, 0x01, cfb); cyber2000_attrw(0x11, 0x00, cfb); cyber2000_attrw(0x12, 0x0f, cfb); cyber2000_attrw(0x13, 0x00, cfb); cyber2000_attrw(0x14, 0x00, cfb); /* PLL registers */ cyber2000_grphw(EXT_DCLK_MULT, hw->clock_mult, cfb); cyber2000_grphw(EXT_DCLK_DIV, hw->clock_div, cfb); cyber2000_grphw(EXT_MCLK_MULT, cfb->mclk_mult, cfb); cyber2000_grphw(EXT_MCLK_DIV, cfb->mclk_div, cfb); cyber2000_grphw(0x90, 0x01, cfb); cyber2000_grphw(0xb9, 0x80, cfb); cyber2000_grphw(0xb9, 0x00, cfb); cfb->ramdac_ctrl = hw->ramdac; cyber2000fb_write_ramdac_ctrl(cfb); cyber2000fb_writeb(0x20, 0x3c0, cfb); cyber2000fb_writeb(0xff, 0x3c6, cfb); cyber2000_grphw(0x14, hw->fetch, cfb); cyber2000_grphw(0x15, ((hw->fetch >> 8) & 0x03) | ((hw->pitch >> 4) & 0x30), cfb); cyber2000_grphw(EXT_SEQ_MISC, hw->extseqmisc, cfb); // cyber2000_grphw(EXT_BIU_MISC, EXT_BIU_MISC_LIN_ENABLE | // EXT_BIU_MISC_COP_ENABLE | // EXT_BIU_MISC_COP_BFC, cfb); /* * Set up accelerator registers */ cyber2000fb_writew(hw->width, CO_REG_SRC_WIDTH, cfb); cyber2000fb_writew(hw->width, CO_REG_DEST_WIDTH, cfb); cyber2000fb_writeb(hw->co_pixfmt, CO_REG_PIXFMT, cfb); } static inline int cyber2000fb_update_start(struct cfb_info *cfb, struct fb_var_screeninfo *var) { u_int base = var->yoffset * var->xres_virtual + var->xoffset; base *= var->bits_per_pixel; /* * Convert to bytes and shift two extra bits because DAC * can only start on 4 byte aligned data. */ base >>= 5; if (base >= 1 << 20) return -EINVAL; cyber2000_grphw(0x10, base >> 16 | 0x10, cfb); cyber2000_crtcw(0x0c, base >> 8, cfb); cyber2000_crtcw(0x0d, base, cfb); return 0; } /* * Set the Colormap */ static int cyber2000fb_set_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; struct display *display = fb_display + con; struct fb_cmap *dcmap = &display->cmap; int err = 0; /* no colormap allocated? */ if (!dcmap->len) err = fb_alloc_cmap(dcmap, 256, 0); /* * we should be able to remove this test once fbcon has been * "improved" --rmk */ if (!err && display == cfb->display) { err = fb_set_cmap(cmap, kspc, cyber2000fb_setcolreg, &cfb->fb); dcmap = &cfb->fb.cmap; } if (!err) fb_copy_cmap(cmap, dcmap, kspc ? 0 : 1); return err; } static int cyber2000fb_decode_crtc(struct par_info *hw, struct cfb_info *cfb, struct fb_var_screeninfo *var) { u_int Htotal, Hblankend, Hsyncend; u_int Vtotal, Vdispend, Vblankstart, Vblankend, Vsyncstart, Vsyncend; #define BIT(v,b1,m,b2) (((v >> b1) & m) << b2) hw->crtc[13] = hw->pitch; hw->crtc[17] = 0xe3; hw->crtc[14] = 0; hw->crtc[8] = 0; Htotal = var->xres + var->right_margin + var->hsync_len + var->left_margin; if (Htotal > 2080) return -EINVAL; hw->crtc[0] = (Htotal >> 3) - 5; hw->crtc[1] = (var->xres >> 3) - 1; hw->crtc[2] = var->xres >> 3; hw->crtc[4] = (var->xres + var->right_margin) >> 3; Hblankend = (Htotal - 4*8) >> 3; hw->crtc[3] = BIT(Hblankend, 0, 0x1f, 0) | BIT(1, 0, 0x01, 7); Hsyncend = (var->xres + var->right_margin + var->hsync_len) >> 3; hw->crtc[5] = BIT(Hsyncend, 0, 0x1f, 0) | BIT(Hblankend, 5, 0x01, 7); Vdispend = var->yres - 1; Vsyncstart = var->yres + var->lower_margin; Vsyncend = var->yres + var->lower_margin + var->vsync_len; Vtotal = var->yres + var->lower_margin + var->vsync_len + var->upper_margin - 2; if (Vtotal > 2047) return -EINVAL; Vblankstart = var->yres + 6; Vblankend = Vtotal - 10; hw->crtc[6] = Vtotal; hw->crtc[7] = BIT(Vtotal, 8, 0x01, 0) | BIT(Vdispend, 8, 0x01, 1) | BIT(Vsyncstart, 8, 0x01, 2) | BIT(Vblankstart,8, 0x01, 3) | BIT(1, 0, 0x01, 4) | BIT(Vtotal, 9, 0x01, 5) | BIT(Vdispend, 9, 0x01, 6) | BIT(Vsyncstart, 9, 0x01, 7); hw->crtc[9] = BIT(0, 0, 0x1f, 0) | BIT(Vblankstart,9, 0x01, 5) | BIT(1, 0, 0x01, 6); hw->crtc[10] = Vsyncstart; hw->crtc[11] = BIT(Vsyncend, 0, 0x0f, 0) | BIT(1, 0, 0x01, 7); hw->crtc[12] = Vdispend; hw->crtc[15] = Vblankstart; hw->crtc[16] = Vblankend; hw->crtc[18] = 0xff; /* * overflow - graphics reg 0x11 * 0=VTOTAL:10 1=VDEND:10 2=VRSTART:10 3=VBSTART:10 * 4=LINECOMP:10 5-IVIDEO 6=FIXCNT */ hw->crtc_ofl = BIT(Vtotal, 10, 0x01, 0) | BIT(Vdispend, 10, 0x01, 1) | BIT(Vsyncstart, 10, 0x01, 2) | BIT(Vblankstart,10, 0x01, 3) | EXT_CRT_VRTOFL_LINECOMP10; /* woody: set the interlaced bit... */ /* FIXME: what about doublescan? */ if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) hw->crtc_ofl |= EXT_CRT_VRTOFL_INTERLACE; return 0; } /* * The following was discovered by a good monitor, bit twiddling, theorising * and but mostly luck. Strangely, it looks like everyone elses' PLL! * * Clock registers: * fclock = fpll / div2 * fpll = fref * mult / div1 * where: * fref = 14.318MHz (69842ps) * mult = reg0xb0.7:0 * div1 = (reg0xb1.5:0 + 1) * div2 = 2^(reg0xb1.7:6) * fpll should be between 115 and 260 MHz * (8696ps and 3846ps) */ static int cyber2000fb_decode_clock(struct par_info *hw, struct cfb_info *cfb, struct fb_var_screeninfo *var) { u_long pll_ps = var->pixclock; const u_long ref_ps = cfb->ref_ps; u_int div2, t_div1, best_div1, best_mult; int best_diff; int vco; /* * Step 1: * find div2 such that 115MHz < fpll < 260MHz * and 0 <= div2 < 4 */ for (div2 = 0; div2 < 4; div2++) { u_long new_pll; new_pll = pll_ps / cfb->divisors[div2]; if (8696 > new_pll && new_pll > 3846) { pll_ps = new_pll; break; } } if (div2 == 4) return -EINVAL; /* * Step 2: * Given pll_ps and ref_ps, find: * pll_ps * 0.995 < pll_ps_calc < pll_ps * 1.005 * where { 1 < best_div1 < 32, 1 < best_mult < 256 } * pll_ps_calc = best_div1 / (ref_ps * best_mult) */ best_diff = 0x7fffffff; best_mult = 32; best_div1 = 255; for (t_div1 = 32; t_div1 > 1; t_div1 -= 1) { u_int rr, t_mult, t_pll_ps; int diff; /* * Find the multiplier for this divisor */ rr = ref_ps * t_div1; t_mult = (rr + pll_ps / 2) / pll_ps; /* * Is the multiplier within the correct range? */ if (t_mult > 256 || t_mult < 2) continue; /* * Calculate the actual clock period from this multiplier * and divisor, and estimate the error. */ t_pll_ps = (rr + t_mult / 2) / t_mult; diff = pll_ps - t_pll_ps; if (diff < 0) diff = -diff; if (diff < best_diff) { best_diff = diff; best_mult = t_mult; best_div1 = t_div1; } /* * If we hit an exact value, there is no point in continuing. */ if (diff == 0) break; } /* * Step 3: * combine values */ hw->clock_mult = best_mult - 1; hw->clock_div = div2 << 6 | (best_div1 - 1); vco = ref_ps * best_div1 / best_mult; if ((ref_ps == 40690) && (vco < 5556)) /* Set VFSEL when VCO > 180MHz (5.556 ps). */ hw->clock_div |= EXT_DCLK_DIV_VFSEL; return 0; } /* * Decode the info required for the hardware. * This involves the PLL parameters for the dot clock, * CRTC registers, and accelerator settings. */ static int cyber2000fb_decode_var(struct fb_var_screeninfo *var, struct cfb_info *cfb, struct par_info *hw) { unsigned int mem; int err; hw->width = var->xres_virtual; hw->ramdac = RAMDAC_VREFEN | RAMDAC_DAC8BIT; var->transp.msb_right = 0; var->red.msb_right = 0; var->green.msb_right = 0; var->blue.msb_right = 0; switch (var->bits_per_pixel) { #ifdef FBCON_HAS_CFB8 case 8: /* PSEUDOCOLOUR, 256 */ hw->co_pixfmt = CO_PIXFMT_8BPP; hw->pitch = hw->width >> 3; hw->extseqmisc = EXT_SEQ_MISC_8; var->transp.offset = 0; var->transp.length = 0; var->red.offset = 0; var->red.length = 8; var->green.offset = 0; var->green.length = 8; var->blue.offset = 0; var->blue.length = 8; break; #endif #ifdef FBCON_HAS_CFB16 case 16:/* DIRECTCOLOUR, 64k or 32k */ hw->co_pixfmt = CO_PIXFMT_16BPP; hw->pitch = hw->width >> 2; switch (var->green.length) { case 6: /* RGB565, 64k */ hw->extseqmisc = EXT_SEQ_MISC_16_RGB565; var->transp.offset = 0; var->transp.length = 0; var->red.offset = 11; var->red.length = 5; var->green.offset = 5; var->green.length = 6; var->blue.offset = 0; var->blue.length = 5; break; default: case 5: /* RGB555, 32k */ hw->extseqmisc = EXT_SEQ_MISC_16_RGB555; var->transp.offset = 0; var->transp.length = 0; var->red.offset = 10; var->red.length = 5; var->green.offset = 5; var->green.length = 5; var->blue.offset = 0; var->blue.length = 5; break; case 4: /* RGB444, 4k + transparency? */ hw->extseqmisc = EXT_SEQ_MISC_16_RGB444; var->transp.offset = 12; var->transp.length = 4; var->red.offset = 8; var->red.length = 4; var->green.offset = 4; var->green.length = 4; var->blue.offset = 0; var->blue.length = 4; break; } break; #endif #ifdef FBCON_HAS_CFB24 case 24:/* TRUECOLOUR, 16m */ hw->co_pixfmt = CO_PIXFMT_24BPP; hw->width *= 3; hw->pitch = hw->width >> 3; hw->ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN); hw->extseqmisc = EXT_SEQ_MISC_24_RGB888; var->transp.offset = 0; var->transp.length = 0; var->red.offset = 16; var->red.length = 8; var->green.offset = 8; var->green.length = 8; var->blue.offset = 0; var->blue.length = 8; break; #endif #ifdef FBCON_HAS_CFB32 case 32:/* TRUECOLOUR, 16m */ hw->co_pixfmt = CO_PIXFMT_32BPP; hw->pitch = hw->width >> 1; hw->ramdac |= (RAMDAC_BYPASS | RAMDAC_RAMPWRDN); hw->extseqmisc = EXT_SEQ_MISC_32; var->transp.offset = 24; var->transp.length = 8; var->red.offset = 16; var->red.length = 8; var->green.offset = 8; var->green.length = 8; var->blue.offset = 0; var->blue.length = 8; break; #endif default: return -EINVAL; } mem = var->xres_virtual * var->yres_virtual * (var->bits_per_pixel / 8); if (mem > cfb->fb.fix.smem_len) var->yres_virtual = cfb->fb.fix.smem_len * 8 / (var->bits_per_pixel * var->xres_virtual); if (var->yres > var->yres_virtual) var->yres = var->yres_virtual; if (var->xres > var->xres_virtual) var->xres = var->xres_virtual; err = cyber2000fb_decode_clock(hw, cfb, var); if (err) return err; err = cyber2000fb_decode_crtc(hw, cfb, var); if (err) return err; hw->width -= 1; hw->fetch = hw->pitch; if (!(cfb->mem_ctl2 & MEM_CTL2_64BIT)) hw->fetch <<= 1; hw->fetch += 1; return 0; } /* * Set the User Defined Part of the Display */ static int cyber2000fb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; struct display *display; struct par_info hw; int err, chgvar; /* * CONUPDATE and SMOOTH_XPAN are equal. However, * SMOOTH_XPAN is only used internally by fbcon. */ if (var->vmode & FB_VMODE_CONUPDATE) { var->vmode |= FB_VMODE_YWRAP; var->xoffset = cfb->display->var.xoffset; var->yoffset = cfb->display->var.yoffset; } err = cyber2000fb_decode_var(var, cfb, &hw); if (err) return err; if (var->activate & FB_ACTIVATE_TEST) return 0; if ((var->activate & FB_ACTIVATE_MASK) != FB_ACTIVATE_NOW) return -EINVAL; if (con < 0) { display = cfb->fb.disp; } else { display = fb_display + con; } chgvar = cfb->fb.var.xres != var->xres || cfb->fb.var.yres != var->yres || cfb->fb.var.xres_virtual != var->xres_virtual || cfb->fb.var.yres_virtual != var->yres_virtual || cfb->fb.var.bits_per_pixel != var->bits_per_pixel; if (memcmp(&cfb->fb.var.red, &var->red, sizeof(var->red)) || memcmp(&cfb->fb.var.green, &var->green, sizeof(var->green)) || memcmp(&cfb->fb.var.blue, &var->blue, sizeof(var->blue))) chgvar = 1; if (con < 0) chgvar = 0; /* * If we are setting all the virtual consoles, also set the * defaults used to create new consoles. */ err = var->activate; var->activate = FB_ACTIVATE_NOW; if (err & FB_ACTIVATE_ALL) cfb->fb.disp->var = *var; cfb->fb.var = *var; cfb->fb.fix.line_length = var->xres_virtual * var->bits_per_pixel / 8; switch (var->bits_per_pixel) { #ifdef FBCON_HAS_CFB8 case 8: /* PSEUDOCOLOUR, 256 */ cfb->dispsw = &fbcon_cfb8; display->dispsw_data = NULL; break; #endif #ifdef FBCON_HAS_CFB16 case 16:/* DIRECTCOLOUR */ cfb->dispsw = &fbcon_cfb16; display->dispsw_data = cfb->fb.pseudo_palette; break; #endif #ifdef FBCON_HAS_CFB24 case 24:/* TRUECOLOUR, 16m */ cfb->dispsw = &fbcon_cfb24; display->dispsw_data = cfb->fb.pseudo_palette; break; #endif #ifdef FBCON_HAS_CFB32 case 32:/* TRUECOLOUR, 16m */ cfb->dispsw = &fbcon_cfb32; display->dispsw_data = cfb->fb.pseudo_palette; break; #endif default:/* in theory this should never happen */ printk(KERN_WARNING "%s: no support for %dbpp\n", cfb->fb.fix.id, var->bits_per_pixel); cfb->dispsw = &fbcon_dummy; break; } /* * 8bpp displays are always pseudo colour. * 16bpp and above are direct colour or true colour, depending * on whether the RAMDAC palettes are bypassed. (Direct colour * has palettes, true colour does not.) */ if (var->bits_per_pixel == 8) cfb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR; else if (hw.ramdac & RAMDAC_BYPASS) cfb->fb.fix.visual = FB_VISUAL_TRUECOLOR; else cfb->fb.fix.visual = FB_VISUAL_DIRECTCOLOR; if (var->accel_flags & FB_ACCELF_TEXT && cfb->dispsw != &fbcon_dummy) display->dispsw = &fbcon_cyber_accel; else display->dispsw = cfb->dispsw; display->screen_base = cfb->fb.screen_base; display->line_length = cfb->fb.fix.line_length; display->next_line = cfb->fb.fix.line_length; display->visual = cfb->fb.fix.visual; display->type = cfb->fb.fix.type; display->type_aux = cfb->fb.fix.type_aux; display->ypanstep = cfb->fb.fix.ypanstep; display->ywrapstep = cfb->fb.fix.ywrapstep; display->can_soft_blank = 1; display->inverse = 0; display->var = *var; cyber2000fb_set_timing(cfb, &hw); cyber2000fb_update_start(cfb, var); fb_set_cmap(&cfb->fb.cmap, 1, cyber2000fb_setcolreg, &cfb->fb); if (chgvar && cfb->fb.changevar) cfb->fb.changevar(con); return 0; } /* * Pan or Wrap the Display */ static int cyber2000fb_pan_display(struct fb_var_screeninfo *var, int con, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; u_int y_bottom; y_bottom = var->yoffset; if (!(var->vmode & FB_VMODE_YWRAP)) y_bottom += var->yres; if (var->xoffset > (var->xres_virtual - var->xres)) return -EINVAL; if (y_bottom > cfb->display->var.yres_virtual) return -EINVAL; if (cyber2000fb_update_start(cfb, var)) return -EINVAL; cfb->display->var.xoffset = var->xoffset; cfb->display->var.yoffset = var->yoffset; if (var->vmode & FB_VMODE_YWRAP) { cfb->display->var.vmode |= FB_VMODE_YWRAP; } else { cfb->display->var.vmode &= ~FB_VMODE_YWRAP; } return 0; } /* * Update the `var' structure (called by fbcon.c) * * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'. * Since it's called by a kernel driver, no range checking is done. */ static int cyber2000fb_updatevar(int con, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; return cyber2000fb_update_start(cfb, &fb_display[con].var); } static int cyber2000fb_switch(int con, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; struct display *display = cfb->display; struct fb_cmap *cmap; if (display) { /* * Save the old colormap and video mode. */ if (display->cmap.len) fb_copy_cmap(&cfb->fb.cmap, &display->cmap, 0); } cfb->display = display = fb_display + con; /* * Install the new colormap and change the video mode. By default, * fbcon sets all the colormaps and video modes to the default * values at bootup. * * Really, we want to set the colourmap size depending on the * depth of the new video mode. For now, we leave it at its * default 256 entry. */ if (display->cmap.len) cmap = &display->cmap; else cmap = fb_default_cmap(1 << display->var.bits_per_pixel); fb_copy_cmap(cmap, &cfb->fb.cmap, 0); display->var.activate = FB_ACTIVATE_NOW; cyber2000fb_set_var(&display->var, con, &cfb->fb); return 0; } /* * (Un)Blank the display. * * Blank the screen if blank_mode != 0, else unblank. If * blank == NULL then the caller blanks by setting the CLUT * (Color Look Up Table) to all black. Return 0 if blanking * succeeded, != 0 if un-/blanking failed due to e.g. a * video mode which doesn't support it. Implements VESA * suspend and powerdown modes on hardware that supports * disabling hsync/vsync: * blank_mode == 2: suspend vsync * blank_mode == 3: suspend hsync * blank_mode == 4: powerdown * * wms...Enable VESA DMPS compatible powerdown mode * run "setterm -powersave powerdown" to take advantage */ static void cyber2000fb_blank(int blank, struct fb_info *info) { struct cfb_info *cfb = (struct cfb_info *)info; unsigned int sync = 0; int i; switch (blank) { case 4: /* powerdown - both sync lines down */ sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_0; break; case 3: /* hsync off */ sync = EXT_SYNC_CTL_VS_NORMAL | EXT_SYNC_CTL_HS_0; break; case 2: /* vsync off */ sync = EXT_SYNC_CTL_VS_0 | EXT_SYNC_CTL_HS_NORMAL; break; case 1: /* soft blank */ default: /* unblank */ break; } cyber2000_grphw(EXT_SYNC_CTL, sync, cfb); if (blank <= 1) { /* turn on ramdacs */ cfb->ramdac_powerdown &= ~(RAMDAC_DACPWRDN | RAMDAC_BYPASS | RAMDAC_RAMPWRDN); cyber2000fb_write_ramdac_ctrl(cfb); } /* * Soft blank/unblank the display. */ if (blank) { /* soft blank */ for (i = 0; i < NR_PALETTE; i++) { cyber2000fb_writeb(i, 0x3c8, cfb); cyber2000fb_writeb(0, 0x3c9, cfb); cyber2000fb_writeb(0, 0x3c9, cfb); cyber2000fb_writeb(0, 0x3c9, cfb); } } else { /* unblank */ for (i = 0; i < NR_PALETTE; i++) { cyber2000fb_writeb(i, 0x3c8, cfb); cyber2000fb_writeb(cfb->palette[i].red, 0x3c9, cfb); cyber2000fb_writeb(cfb->palette[i].green, 0x3c9, cfb); cyber2000fb_writeb(cfb->palette[i].blue, 0x3c9, cfb); } } if (blank >= 2) { /* turn off ramdacs */ cfb->ramdac_powerdown |= RAMDAC_DACPWRDN | RAMDAC_BYPASS | RAMDAC_RAMPWRDN; cyber2000fb_write_ramdac_ctrl(cfb); } } /* * Get the currently displayed virtual consoles colormap. */ static int gen_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info) { fb_copy_cmap(&info->cmap, cmap, kspc ? 0 : 2); return 0; } /* * Get the currently displayed virtual consoles fixed part of the display. */ static int gen_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *info) { *fix = info->fix; return 0; } /* * Get the current user defined part of the display. */ static int gen_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *info) { *var = info->var; return 0; } static struct fb_ops cyber2000fb_ops = { .owner = THIS_MODULE, .fb_set_var = cyber2000fb_set_var, .fb_set_cmap = cyber2000fb_set_cmap, .fb_pan_display = cyber2000fb_pan_display, .fb_get_fix = gen_get_fix, .fb_get_var = gen_get_var, .fb_get_cmap = gen_get_cmap, }; /* * This is the only "static" reference to the internal data structures * of this driver. It is here solely at the moment to support the other * CyberPro modules external to this driver. */ static struct cfb_info *int_cfb_info; /* * Enable access to the extended registers */ void cyber2000fb_enable_extregs(struct cfb_info *cfb) { cfb->func_use_count += 1; if (cfb->func_use_count == 1) { int old; old = cyber2000_grphr(EXT_FUNC_CTL, cfb); old |= EXT_FUNC_CTL_EXTREGENBL; cyber2000_grphw(EXT_FUNC_CTL, old, cfb); } } /* * Disable access to the extended registers */ void cyber2000fb_disable_extregs(struct cfb_info *cfb) { if (cfb->func_use_count == 1) { int old; old = cyber2000_grphr(EXT_FUNC_CTL, cfb); old &= ~EXT_FUNC_CTL_EXTREGENBL; cyber2000_grphw(EXT_FUNC_CTL, old, cfb); } if (cfb->func_use_count == 0) printk(KERN_ERR "disable_extregs: count = 0\n"); else cfb->func_use_count -= 1; } void cyber2000fb_get_fb_var(struct cfb_info *cfb, struct fb_var_screeninfo *var) { memcpy(var, &cfb->display->var, sizeof(struct fb_var_screeninfo)); } /* * Attach a capture/tv driver to the core CyberX0X0 driver. */ int cyber2000fb_attach(struct cyberpro_info *info, int idx) { if (int_cfb_info != NULL) { info->dev = int_cfb_info->dev; info->regs = int_cfb_info->regs; info->fb = int_cfb_info->fb.screen_base; info->fb_size = int_cfb_info->fb.fix.smem_len; info->enable_extregs = cyber2000fb_enable_extregs; info->disable_extregs = cyber2000fb_disable_extregs; info->info = int_cfb_info; strncpy(info->dev_name, int_cfb_info->fb.fix.id, sizeof(info->dev_name)); MOD_INC_USE_COUNT; } return int_cfb_info != NULL; } /* * Detach a capture/tv driver from the core CyberX0X0 driver. */ void cyber2000fb_detach(int idx) { MOD_DEC_USE_COUNT; } EXPORT_SYMBOL(cyber2000fb_attach); EXPORT_SYMBOL(cyber2000fb_detach); EXPORT_SYMBOL(cyber2000fb_enable_extregs); EXPORT_SYMBOL(cyber2000fb_disable_extregs); EXPORT_SYMBOL(cyber2000fb_get_fb_var); /* * These parameters give * 640x480, hsync 31.5kHz, vsync 60Hz */ static struct fb_videomode __devinitdata cyber2000fb_default_mode = { .refresh = 60, .xres = 640, .yres = 480, .pixclock = 39722, .left_margin = 56, .right_margin = 16, .upper_margin = 34, .lower_margin = 9, .hsync_len = 88, .vsync_len = 2, .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, .vmode = FB_VMODE_NONINTERLACED }; /* static register programming for all chips */ static char igs_regs[] __devinitdata = { EXT_CRT_IRQ, 0, EXT_CRT_TEST, 0, EXT_SYNC_CTL, 0, EXT_SEG_WRITE_PTR, 0, EXT_SEG_READ_PTR, 0, EXT_BIU_MISC, EXT_BIU_MISC_LIN_ENABLE | EXT_BIU_MISC_COP_ENABLE | EXT_BIU_MISC_COP_BFC, EXT_FUNC_CTL, 0, CURS_H_START, 0, CURS_H_START + 1, 0, CURS_H_PRESET, 0, CURS_V_START, 0, CURS_V_START + 1, 0, CURS_V_PRESET, 0, CURS_CTL, 0, EXT_ATTRIB_CTL, EXT_ATTRIB_CTL_EXT, EXT_OVERSCAN_RED, 0, EXT_OVERSCAN_GREEN, 0, EXT_OVERSCAN_BLUE, 0, }; /* specific register setting for the 2000 series */ static char igs_2000_regs[] __devinitdata = { /* some of these are questionable when we have a BIOS */ EXT_MEM_CTL0, EXT_MEM_CTL0_7CLK | EXT_MEM_CTL0_RAS_1 | EXT_MEM_CTL0_MULTCAS, EXT_HIDDEN_CTL1, 0x30, EXT_FIFO_CTL, 0x0b, EXT_FIFO_CTL + 1, 0x17, 0x76, 0x00, EXT_HIDDEN_CTL4, 0xc8 }; /* * Initialise the CyberPro hardware. */ static void cyberpro_init_hw(struct cfb_info *cfb) { int i; for (i = 0; i < sizeof(igs_regs); i += 2) cyber2000_grphw(igs_regs[i], igs_regs[i+1], cfb); if (cfb->id == ID_CYBERPRO_5000) { /* * On the CyberPro5XXXX, ensure that we're using the correct * PLL (5XXX's may be programmed to use an additional set of * PLLs.) */ unsigned char val; cyber2000fb_writeb(0xba, 0x3ce, cfb); val = cyber2000fb_readb(0x3cf, cfb) & 0x80; cyber2000fb_writeb(val, 0x3cf, cfb); cyber2000fb_ops.fb_pan_display = NULL; /* FIXME: panning broken */ } else { /* * Other supported chips (2000 series) appear to need * these registers programming */ for (i = 0; i < sizeof(igs_2000_regs); i += 2) cyber2000_grphw(igs_2000_regs[i], igs_2000_regs[i+1], cfb); } } static struct cfb_info * __devinit cyberpro_alloc_fb_info(unsigned int id, char *name) { struct cfb_info *cfb; cfb = kmalloc(sizeof(struct cfb_info) + sizeof(struct display) + sizeof(u32) * 16, GFP_KERNEL); if (!cfb) return NULL; memset(cfb, 0, sizeof(struct cfb_info) + sizeof(struct display)); cfb->id = id; if (id == ID_CYBERPRO_5000) cfb->ref_ps = 40690; // 24.576 MHz else cfb->ref_ps = 69842; // 14.31818 MHz (69841?) cfb->divisors[0] = 1; cfb->divisors[1] = 2; cfb->divisors[2] = 4; if (id == ID_CYBERPRO_2000) cfb->divisors[3] = 8; else cfb->divisors[3] = 6; strcpy(cfb->fb.fix.id, name); cfb->fb.fix.type = FB_TYPE_PACKED_PIXELS; cfb->fb.fix.type_aux = 0; cfb->fb.fix.xpanstep = 0; cfb->fb.fix.ypanstep = 1; cfb->fb.fix.ywrapstep = 0; switch (id) { case ID_IGA_1682: cfb->fb.fix.accel = 0; break; case ID_CYBERPRO_2000: cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2000; break; case ID_CYBERPRO_2010: cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2010; break; case ID_CYBERPRO_5000: cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER5000; break; } cfb->fb.var.nonstd = 0; cfb->fb.var.activate = FB_ACTIVATE_NOW; cfb->fb.var.height = -1; cfb->fb.var.width = -1; cfb->fb.var.accel_flags = FB_ACCELF_TEXT; strcpy(cfb->fb.modename, cfb->fb.fix.id); strcpy(cfb->fb.fontname, default_font); cfb->fb.fbops = &cyber2000fb_ops; cfb->fb.changevar = NULL; cfb->fb.switch_con = cyber2000fb_switch; cfb->fb.updatevar = cyber2000fb_updatevar; cfb->fb.blank = cyber2000fb_blank; cfb->fb.flags = FBINFO_FLAG_DEFAULT; cfb->fb.disp = (struct display *)(cfb + 1); cfb->fb.pseudo_palette = (void *)(cfb->fb.disp + 1); fb_alloc_cmap(&cfb->fb.cmap, NR_PALETTE, 0); return cfb; } static void __devinit cyberpro_free_fb_info(struct cfb_info *cfb) { if (cfb) { /* * Free the colourmap */ fb_alloc_cmap(&cfb->fb.cmap, 0, 0); kfree(cfb); } } /* * Parse Cyber2000fb options. Usage: * video=cyber2000:font:fontname */ int cyber2000fb_setup(char *options) { char *opt; if (!options || !*options) return 0; while ((opt = strsep(&options, ",")) != NULL) { if (!*opt) continue; if (strncmp(opt, "font:", 5) == 0) { strncpy(default_font_storage, opt + 5, sizeof(default_font_storage)); default_font = default_font_storage; continue; } printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt); } return 0; } /* * The CyberPro chips can be placed on many different bus types. * This probe function is common to all bus types. The bus-specific * probe function is expected to have: * - enabled access to the linear memory region * - memory mapped access to the registers * - initialised mem_ctl1 and mem_ctl2 appropriately. */ static int __devinit cyberpro_common_probe(struct cfb_info *cfb) { u_long smem_size; u_int h_sync, v_sync; int err; cyberpro_init_hw(cfb); /* * Get the video RAM size and width from the VGA register. * This should have been already initialised by the BIOS, * but if it's garbage, claim default 1MB VRAM (woody) */ cfb->mem_ctl0 = cyber2000_grphr(EXT_MEM_CTL0, cfb); cfb->mem_ctl1 = cyber2000_grphr(EXT_MEM_CTL1, cfb); cfb->mem_ctl2 = cyber2000_grphr(EXT_MEM_CTL2, cfb); /* * Determine the size of the memory. */ switch (cfb->mem_ctl2 & MEM_CTL2_SIZE_MASK) { case MEM_CTL2_SIZE_4MB: smem_size = 0x00400000; break; case MEM_CTL2_SIZE_2MB: smem_size = 0x00200000; break; case MEM_CTL2_SIZE_1MB: smem_size = 0x00100000; break; default: smem_size = 0x00100000; break; } cfb->fb.fix.smem_len = smem_size; cfb->fb.fix.mmio_len = MMIO_SIZE; cfb->fb.screen_base = cfb->region; err = -EINVAL; if (!fb_find_mode(&cfb->fb.var, &cfb->fb, NULL, NULL, 0, &cyber2000fb_default_mode, 8)) { printk("%s: no valid mode found\n", cfb->fb.fix.id); goto failed; } cfb->fb.var.yres_virtual = cfb->fb.fix.smem_len * 8 / (cfb->fb.var.bits_per_pixel * cfb->fb.var.xres_virtual); if (cfb->fb.var.yres_virtual < cfb->fb.var.yres) cfb->fb.var.yres_virtual = cfb->fb.var.yres; cyber2000fb_set_var(&cfb->fb.var, -1, &cfb->fb); /* * Calculate the hsync and vsync frequencies. Note that * we split the 1e12 constant up so that we can preserve * the precision and fit the results into 32-bit registers. * (1953125000 * 512 = 1e12) */ h_sync = 1953125000 / cfb->fb.var.pixclock; h_sync = h_sync * 512 / (cfb->fb.var.xres + cfb->fb.var.left_margin + cfb->fb.var.right_margin + cfb->fb.var.hsync_len); v_sync = h_sync / (cfb->fb.var.yres + cfb->fb.var.upper_margin + cfb->fb.var.lower_margin + cfb->fb.var.vsync_len); printk(KERN_INFO "%s: %dKiB VRAM, using %dx%d, %d.%03dkHz, %dHz\n", cfb->fb.fix.id, cfb->fb.fix.smem_len >> 10, cfb->fb.var.xres, cfb->fb.var.yres, h_sync / 1000, h_sync % 1000, v_sync); err = register_framebuffer(&cfb->fb); failed: return err; } static void cyberpro_common_resume(struct cfb_info *cfb) { cyberpro_init_hw(cfb); /* * Reprogram the MEM_CTL0, 1 and 2 registers */ cyber2000_grphw(EXT_MEM_CTL0, cfb->mem_ctl0, cfb); cyber2000_grphw(EXT_MEM_CTL1, cfb->mem_ctl1, cfb); cyber2000_grphw(EXT_MEM_CTL2, cfb->mem_ctl2, cfb); /* * Restore the old video mode and the palette. * We also need to tell fbcon to redraw the console. */ cfb->fb.var.activate = FB_ACTIVATE_NOW; cyber2000fb_set_var(&cfb->fb.var, -1, &cfb->fb); } /* * PCI specific support. */ /* * We need to wake up the CyberPro, and make sure its in linear memory * mode. Unfortunately, this is specific to the platform and card that * we are running on. * * On x86 and ARM, should we be initialising the CyberPro first via the * IO registers, and then the MMIO registers to catch all cases? Can we * end up in the situation where the chip is in MMIO mode, but not awake * on an x86 system? */ static int cyberpro_pci_enable_mmio(struct cfb_info *cfb) { unsigned char val; #if defined(__sparc_v9__) #error "You loose, consult DaveM." #elif defined(__sparc__) /* * SPARC does not have an "outb" instruction, so we generate * I/O cycles storing into a reserved memory space at * physical address 0x3000000 */ unsigned char *iop; iop = ioremap(0x3000000, 0x5000); if (iop == NULL) { prom_printf("iga5000: cannot map I/O\n"); return -ENOMEM; } writeb(0x18, iop + 0x46e8); writeb(0x01, iop + 0x102); writeb(0x08, iop + 0x46e8); writeb(EXT_BIU_MISC, iop + 0x3ce); writeb(EXT_BIU_MISC_LIN_ENABLE, iop + 0x3cf); iounmap((void *)iop); #elif defined(CONFIG_ARCH_SHARK) /* * Shark probably needs to do it this way rather than use the * IO method below. Since the CyberPro on the Shark isn't a * PCI device, we probably want to move this to a bus-specific * probe function. Do we even need to do this? */ cyber2000fb_writeb(0x18, 0x46e8, cfb); cyber2000fb_writeb(0x01, 0x102, cfb); cyber2000fb_writeb(0x08, 0x46e8, cfb); cyber2000fb_writeb(EXT_BIU_MISC, 0x3ce, cfb); cyber2000fb_writeb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf, cfb); #else /* * Most other machine types are "normal", so * we use the standard IO-based wakeup. */ outb(0x18, 0x46e8); outb(0x01, 0x102); outb(0x08, 0x46e8); outb(EXT_BIU_MISC, 0x3ce); outb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf); #endif /* * Allow the CyberPro to accept PCI burst accesses */ val = cyber2000_grphr(EXT_BUS_CTL, cfb); if (!(val & EXT_BUS_CTL_PCIBURST_WRITE)) { printk(KERN_INFO "%s: enabling PCI bursts\n", cfb->fb.fix.id); val |= EXT_BUS_CTL_PCIBURST_WRITE; if (cfb->id == ID_CYBERPRO_5000) val |= EXT_BUS_CTL_PCIBURST_READ; cyber2000_grphw(EXT_BUS_CTL, val, cfb); } return 0; } static int __devinit cyberpro_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { struct cfb_info *cfb; char name[16]; int err; sprintf(name, "CyberPro%4X", id->device); err = pci_enable_device(dev); if (err) return err; err = pci_request_regions(dev, name); if (err) return err; err = -ENOMEM; cfb = cyberpro_alloc_fb_info(id->driver_data, name); if (!cfb) goto failed_release; cfb->dev = dev; cfb->region = ioremap(pci_resource_start(dev, 0), pci_resource_len(dev, 0)); if (!cfb->region) goto failed_ioremap; cfb->regs = cfb->region + MMIO_OFFSET; cfb->fb.fix.mmio_start = pci_resource_start(dev, 0) + MMIO_OFFSET; cfb->fb.fix.smem_start = pci_resource_start(dev, 0); /* * Bring up the hardware. This is expected to enable access * to the linear memory region, and allow access to the memory * mapped registers. Also, mem_ctl1 and mem_ctl2 must be * initialised. */ err = cyberpro_pci_enable_mmio(cfb); if (err) goto failed; #if defined(CONFIG_ARCH_SHARK) || defined(CONFIG_ARCH_NETWINDER) /* * MCLK on the NetWinder and the Shark is fixed at 75MHz */ cfb->mclk_mult = 0xdb; cfb->mclk_div = 0x54; #else /* * Use MCLK from BIOS. FIXME: what about hotplug? */ cfb->mclk_mult = cyber2000_grphr(EXT_MCLK_MULT, cfb); cfb->mclk_div = cyber2000_grphr(EXT_MCLK_DIV, cfb); #endif err = cyberpro_common_probe(cfb); if (err) goto failed; /* * Our driver data */ pci_set_drvdata(dev, cfb); if (int_cfb_info == NULL) int_cfb_info = cfb; return 0; failed: iounmap(cfb->region); failed_ioremap: cyberpro_free_fb_info(cfb); failed_release: pci_release_regions(dev); return err; } static void __devexit cyberpro_pci_remove(struct pci_dev *dev) { struct cfb_info *cfb = pci_get_drvdata(dev); if (cfb) { /* * If unregister_framebuffer fails, then * we will be leaving hooks that could cause * oopsen laying around. */ if (unregister_framebuffer(&cfb->fb)) printk(KERN_WARNING "%s: danger Will Robinson, " "danger danger! Oopsen imminent!\n", cfb->fb.fix.id); iounmap(cfb->region); cyberpro_free_fb_info(cfb); /* * Ensure that the driver data is no longer * valid. */ pci_set_drvdata(dev, NULL); if (cfb == int_cfb_info) int_cfb_info = NULL; pci_release_regions(dev); } } static int cyberpro_pci_suspend(struct pci_dev *dev, u32 state) { return 0; } /* * Re-initialise the CyberPro hardware */ static int cyberpro_pci_resume(struct pci_dev *dev) { struct cfb_info *cfb = pci_get_drvdata(dev); if (cfb) { cyberpro_pci_enable_mmio(cfb); cyberpro_common_resume(cfb); } return 0; } static struct pci_device_id cyberpro_pci_table[] __devinitdata = { // Not yet // { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682, // PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_IGA_1682 }, { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2000 }, { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2010 }, { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_5000 }, { 0, } }; MODULE_DEVICE_TABLE(pci,cyberpro_pci_table); #ifndef __devexit_p #define __devexit_p(x) (x) #endif static struct pci_driver cyberpro_driver = { .name = "CyberPro", .probe = cyberpro_pci_probe, .remove = __devexit_p(cyberpro_pci_remove), .suspend = cyberpro_pci_suspend, .resume = cyberpro_pci_resume, .id_table = cyberpro_pci_table }; /* * I don't think we can use the "module_init" stuff here because * the fbcon stuff may not be initialised yet. Hence the #ifdef * around module_init. */ int __init cyber2000fb_init(void) { return pci_module_init(&cyberpro_driver); } static void __exit cyberpro_exit(void) { pci_unregister_driver(&cyberpro_driver); } #ifdef MODULE module_init(cyber2000fb_init); #endif module_exit(cyberpro_exit); MODULE_AUTHOR("Russell King"); MODULE_DESCRIPTION("CyberPro 2000, 2010 and 5000 framebuffer driver"); MODULE_LICENSE("GPL");
cyber2000fb.h
(text/x-chdr, 15.6 KB)
/*
* linux/drivers/video/cyber2000fb.h
*
* Copyright (C) 1998-2000 Russell King
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Integraphics Cyber2000 frame buffer device
*/
#include <linux/config.h>
/*
* Internal CyberPro sizes and offsets.
*/
#define MMIO_OFFSET 0x00800000
#define MMIO_SIZE 0x000c0000
#define NR_PALETTE 256
#if defined(DEBUG) && defined(CONFIG_DEBUG_LL)
static void debug_printf(char *fmt, ...)
{
extern void printascii(const char *);
char buffer[128];
va_list ap;
va_start(ap, fmt);
vsprintf(buffer, fmt, ap);
va_end(ap);
printascii(buffer);
}
#else
#define debug_printf(x...) do { } while (0)
#endif
#define RAMDAC_RAMPWRDN 0x01
#define RAMDAC_DAC8BIT 0x02
#define RAMDAC_VREFEN 0x04
#define RAMDAC_BYPASS 0x10
#define RAMDAC_DACPWRDN 0x40
#define EXT_CRT_VRTOFL 0x11
#define EXT_CRT_VRTOFL_LINECOMP10 0x10
#define EXT_CRT_VRTOFL_INTERLACE 0x20
#define EXT_CRT_IRQ 0x12
#define EXT_CRT_IRQ_ENABLE 0x01
#define EXT_CRT_IRQ_ACT_HIGH 0x04
#define EXT_CRT_TEST 0x13
#define EXT_SYNC_CTL 0x16
#define EXT_SYNC_CTL_HS_NORMAL 0x00
#define EXT_SYNC_CTL_HS_0 0x01
#define EXT_SYNC_CTL_HS_1 0x02
#define EXT_SYNC_CTL_HS_HSVS 0x03
#define EXT_SYNC_CTL_VS_NORMAL 0x00
#define EXT_SYNC_CTL_VS_0 0x04
#define EXT_SYNC_CTL_VS_1 0x08
#define EXT_SYNC_CTL_VS_COMP 0x0c
#define EXT_BUS_CTL 0x30
#define EXT_BUS_CTL_LIN_1MB 0x00
#define EXT_BUS_CTL_LIN_2MB 0x01
#define EXT_BUS_CTL_LIN_4MB 0x02
#define EXT_BUS_CTL_ZEROWAIT 0x04
#define EXT_BUS_CTL_PCIBURST_WRITE 0x20
#define EXT_BUS_CTL_PCIBURST_READ 0x80 /* CyberPro 5000 only */
#define EXT_SEG_WRITE_PTR 0x31
#define EXT_SEG_READ_PTR 0x32
#define EXT_BIU_MISC 0x33
#define EXT_BIU_MISC_LIN_ENABLE 0x01
#define EXT_BIU_MISC_COP_ENABLE 0x04
#define EXT_BIU_MISC_COP_BFC 0x08
#define EXT_FUNC_CTL 0x3c
#define EXT_FUNC_CTL_EXTREGENBL 0x80 /* enable access to 0xbcxxx */
#define PCI_BM_CTL 0x3e
#define PCI_BM_CTL_ENABLE 0x01 /* enable bus-master */
#define PCI_BM_CTL_BURST 0x02 /* enable burst */
#define PCI_BM_CTL_BACK2BACK 0x04 /* enable back to back */
#define PCI_BM_CTL_DUMMY 0x08 /* insert dummy cycle */
#define X_V2_VID_MEM_START 0x40
#define X_V2_VID_SRC_WIDTH 0x43
#define X_V2_X_START 0x45
#define X_V2_X_END 0x47
#define X_V2_Y_START 0x49
#define X_V2_Y_END 0x4b
#define X_V2_VID_SRC_WIN_WIDTH 0x4d
#define Y_V2_DDA_X_INC 0x43
#define Y_V2_DDA_Y_INC 0x47
#define Y_V2_VID_FIFO_CTL 0x49
#define Y_V2_VID_FMT 0x4b
#define Y_V2_VID_DISP_CTL1 0x4c
#define Y_V2_VID_FIFO_CTL1 0x4d
#define J_X2_VID_MEM_START 0x40
#define J_X2_VID_SRC_WIDTH 0x43
#define J_X2_X_START 0x47
#define J_X2_X_END 0x49
#define J_X2_Y_START 0x4b
#define J_X2_Y_END 0x4d
#define J_X2_VID_SRC_WIN_WIDTH 0x4f
#define K_X2_DDA_X_INIT 0x40
#define K_X2_DDA_X_INC 0x42
#define K_X2_DDA_Y_INIT 0x44
#define K_X2_DDA_Y_INC 0x46
#define K_X2_VID_FMT 0x48
#define K_X2_VID_DISP_CTL1 0x49
#define K_CAP_X2_CTL1 0x49
#define CURS_H_START 0x50
#define CURS_H_PRESET 0x52
#define CURS_V_START 0x53
#define CURS_V_PRESET 0x55
#define CURS_CTL 0x56
#define EXT_ATTRIB_CTL 0x57
#define EXT_ATTRIB_CTL_EXT 0x01
#define EXT_OVERSCAN_RED 0x58
#define EXT_OVERSCAN_GREEN 0x59
#define EXT_OVERSCAN_BLUE 0x5a
#define CAP_X_START 0x60
#define CAP_X_END 0x62
#define CAP_Y_START 0x64
#define CAP_Y_END 0x66
#define CAP_DDA_X_INIT 0x68
#define CAP_DDA_X_INC 0x6a
#define CAP_DDA_Y_INIT 0x6c
#define CAP_DDA_Y_INC 0x6e
#define EXT_MEM_CTL0 0x70
#define EXT_MEM_CTL0_7CLK 0x01
#define EXT_MEM_CTL0_RAS_1 0x02
#define EXT_MEM_CTL0_RAS2CAS_1 0x04
#define EXT_MEM_CTL0_MULTCAS 0x08
#define EXT_MEM_CTL0_ASYM 0x10
#define EXT_MEM_CTL0_CAS1ON 0x20
#define EXT_MEM_CTL0_FIFOFLUSH 0x40
#define EXT_MEM_CTL0_SEQRESET 0x80
#define EXT_MEM_CTL1 0x71
#define EXT_MEM_CTL1_PAR 0x00
#define EXT_MEM_CTL1_SERPAR 0x01
#define EXT_MEM_CTL1_SER 0x03
#define EXT_MEM_CTL1_SYNC 0x04
#define EXT_MEM_CTL1_VRAM 0x08
#define EXT_MEM_CTL1_4K_REFRESH 0x10
#define EXT_MEM_CTL1_256Kx4 0x00
#define EXT_MEM_CTL1_512Kx8 0x40
#define EXT_MEM_CTL1_1Mx16 0x60
#define EXT_MEM_CTL2 0x72
#define MEM_CTL2_SIZE_1MB 0x00
#define MEM_CTL2_SIZE_2MB 0x01
#define MEM_CTL2_SIZE_4MB 0x02
#define MEM_CTL2_SIZE_MASK 0x03
#define MEM_CTL2_64BIT 0x04
#define EXT_HIDDEN_CTL1 0x73
#define EXT_FIFO_CTL 0x74
#define EXT_SEQ_MISC 0x77
#define EXT_SEQ_MISC_8 0x01
#define EXT_SEQ_MISC_16_RGB565 0x02
#define EXT_SEQ_MISC_32 0x03
#define EXT_SEQ_MISC_24_RGB888 0x04
#define EXT_SEQ_MISC_16_RGB555 0x06
#define EXT_SEQ_MISC_8_RGB332 0x09
#define EXT_SEQ_MISC_16_RGB444 0x0a
#define EXT_HIDDEN_CTL4 0x7a
#define CURS_MEM_START 0x7e /* bits 23..12 */
#define CAP_PIP_X_START 0x80
#define CAP_PIP_X_END 0x82
#define CAP_PIP_Y_START 0x84
#define CAP_PIP_Y_END 0x86
#define EXT_CAP_CTL1 0x88
#define EXT_CAP_CTL2 0x89
#define EXT_CAP_CTL2_ODDFRAMEIRQ 0x01
#define EXT_CAP_CTL2_ANYFRAMEIRQ 0x02
#define BM_CTRL0 0x9c
#define BM_CTRL1 0x9d
#define EXT_CAP_MODE1 0xa4
#define EXT_CAP_MODE1_8BIT 0x01 /* enable 8bit capture mode */
#define EXT_CAP_MODE1_CCIR656 0x02 /* CCIR656 mode */
#define EXT_CAP_MODE1_IGNOREVGT 0x04 /* ignore VGT */
#define EXT_CAP_MODE1_ALTFIFO 0x10 /* use alternate FIFO for capture */
#define EXT_CAP_MODE1_SWAPUV 0x20 /* swap UV bytes */
#define EXT_CAP_MODE1_MIRRORY 0x40 /* mirror vertically */
#define EXT_CAP_MODE1_MIRRORX 0x80 /* mirror horizontally */
#define EXT_CAP_MODE2 0xa5
#define EXT_CAP_MODE2_CCIRINVOE 0x01
#define EXT_CAP_MODE2_CCIRINVVGT 0x02
#define EXT_CAP_MODE2_CCIRINVHGT 0x04
#define EXT_CAP_MODE2_CCIRINVDG 0x08
#define EXT_CAP_MODE2_DATEND 0x10
#define EXT_CAP_MODE2_CCIRDGH 0x20
#define EXT_CAP_MODE2_FIXSONY 0x40
#define EXT_CAP_MODE2_SYNCFREEZE 0x80
#define EXT_TV_CTL 0xae
#define EXT_DCLK_MULT 0xb0
#define EXT_DCLK_DIV 0xb1
#define EXT_DCLK_DIV_VFSEL 0x20
#define EXT_MCLK_MULT 0xb2
#define EXT_MCLK_DIV 0xb3
#define EXT_LATCH1 0xb5
#define EXT_LATCH1_VAFC_EN 0x01 /* enable VAFC */
#define EXT_FEATURE 0xb7
#define EXT_FEATURE_BUS_MASK 0x07 /* host bus mask */
#define EXT_FEATURE_BUS_PCI 0x00
#define EXT_FEATURE_BUS_VL_STD 0x04
#define EXT_FEATURE_BUS_VL_LINEAR 0x05
#define EXT_FEATURE_1682 0x20 /* IGS 1682 compatibility */
#define EXT_LATCH2 0xb6
#define EXT_LATCH2_I2C_CLKEN 0x10
#define EXT_LATCH2_I2C_CLK 0x20
#define EXT_LATCH2_I2C_DATEN 0x40
#define EXT_LATCH2_I2C_DAT 0x80
#define EXT_XT_CTL 0xbe
#define EXT_XT_CAP16 0x04
#define EXT_XT_LINEARFB 0x08
#define EXT_XT_PAL 0x10
#define EXT_MEM_START 0xc0 /* ext start address 21 bits */
#define HOR_PHASE_SHIFT 0xc2 /* high 3 bits */
#define EXT_SRC_WIDTH 0xc3 /* ext offset phase 10 bits */
#define EXT_SRC_HEIGHT 0xc4 /* high 6 bits */
#define EXT_X_START 0xc5 /* ext->screen, 16 bits */
#define EXT_X_END 0xc7 /* ext->screen, 16 bits */
#define EXT_Y_START 0xc9 /* ext->screen, 16 bits */
#define EXT_Y_END 0xcb /* ext->screen, 16 bits */
#define EXT_SRC_WIN_WIDTH 0xcd /* 8 bits */
#define EXT_COLOUR_COMPARE 0xce /* 24 bits */
#define EXT_DDA_X_INIT 0xd1 /* ext->screen 16 bits */
#define EXT_DDA_X_INC 0xd3 /* ext->screen 16 bits */
#define EXT_DDA_Y_INIT 0xd5 /* ext->screen 16 bits */
#define EXT_DDA_Y_INC 0xd7 /* ext->screen 16 bits */
#define EXT_VID_FIFO_CTL 0xd9
#define EXT_VID_FMT 0xdb
#define EXT_VID_FMT_YUV422 0x00 /* formats - does this cause conversion? */
#define EXT_VID_FMT_RGB555 0x01
#define EXT_VID_FMT_RGB565 0x02
#define EXT_VID_FMT_RGB888_24 0x03
#define EXT_VID_FMT_RGB888_32 0x04
#define EXT_VID_FMT_RGB8 0x05
#define EXT_VID_FMT_RGB4444 0x06
#define EXT_VID_FMT_RGB8T 0x07
#define EXT_VID_FMT_DUP_PIX_ZOON 0x08 /* duplicate pixel zoom */
#define EXT_VID_FMT_MOD_3RD_PIX 0x20 /* modify 3rd duplicated pixel */
#define EXT_VID_FMT_DBL_H_PIX 0x40 /* double horiz pixels */
#define EXT_VID_FMT_YUV128 0x80 /* YUV data offset by 128 */
#define EXT_VID_DISP_CTL1 0xdc
#define EXT_VID_DISP_CTL1_INTRAM 0x01 /* video pixels go to internal RAM */
#define EXT_VID_DISP_CTL1_IGNORE_CCOMP 0x02 /* ignore colour compare registers */
#define EXT_VID_DISP_CTL1_NOCLIP 0x04 /* do not clip to 16235,16240 */
#define EXT_VID_DISP_CTL1_UV_AVG 0x08 /* U/V data is averaged */
#define EXT_VID_DISP_CTL1_Y128 0x10 /* Y data offset by 128 (if YUV128 set) */
#define EXT_VID_DISP_CTL1_VINTERPOL_OFF 0x20 /* disable vertical interpolation */
#define EXT_VID_DISP_CTL1_FULL_WIN 0x40 /* video out window full */
#define EXT_VID_DISP_CTL1_ENABLE_WINDOW 0x80 /* enable video window */
#define EXT_VID_FIFO_CTL1 0xdd
#define EXT_VID_FIFO_CTL1_OE_HIGH 0x02
#define EXT_VID_FIFO_CTL1_INTERLEAVE 0x04 /* enable interleaved memory read */
#define EXT_ROM_UCB4GH 0xe5
#define EXT_ROM_UCB4GH_FREEZE 0x02 /* capture frozen */
#define EXT_ROM_UCB4GH_ODDFRAME 0x04 /* 1 = odd frame captured */
#define EXT_ROM_UCB4GH_1HL 0x08 /* first horizonal line after VGT falling edge */
#define EXT_ROM_UCB4GH_ODD 0x10 /* odd frame indicator */
#define EXT_ROM_UCB4GH_INTSTAT 0x20 /* video interrupt */
#define VFAC_CTL1 0xe8
#define VFAC_CTL1_CAPTURE 0x01 /* capture enable (only when VSYNC high)*/
#define VFAC_CTL1_VFAC_ENABLE 0x02 /* vfac enable */
#define VFAC_CTL1_FREEZE_CAPTURE 0x04 /* freeze capture */
#define VFAC_CTL1_FREEZE_CAPTURE_SYNC 0x08 /* sync freeze capture */
#define VFAC_CTL1_VALIDFRAME_SRC 0x10 /* select valid frame source */
#define VFAC_CTL1_PHILIPS 0x40 /* select Philips mode */
#define VFAC_CTL1_MODVINTERPOLCLK 0x80 /* modify vertical interpolation clocl */
#define VFAC_CTL2 0xe9
#define VFAC_CTL2_INVERT_VIDDATAVALID 0x01 /* invert video data valid */
#define VFAC_CTL2_INVERT_GRAPHREADY 0x02 /* invert graphic ready output sig */
#define VFAC_CTL2_INVERT_DATACLK 0x04 /* invert data clock signal */
#define VFAC_CTL2_INVERT_HSYNC 0x08 /* invert hsync input */
#define VFAC_CTL2_INVERT_VSYNC 0x10 /* invert vsync input */
#define VFAC_CTL2_INVERT_FRAME 0x20 /* invert frame odd/even input */
#define VFAC_CTL2_INVERT_BLANK 0x40 /* invert blank output */
#define VFAC_CTL2_INVERT_OVSYNC 0x80 /* invert other vsync input */
#define VFAC_CTL3 0xea
#define VFAC_CTL3_CAP_LARGE_FIFO 0x01 /* large capture fifo */
#define VFAC_CTL3_CAP_INTERLACE 0x02 /* capture odd and even fields */
#define VFAC_CTL3_CAP_HOLD_4NS 0x00 /* hold capture data for 4ns */
#define VFAC_CTL3_CAP_HOLD_2NS 0x04 /* hold capture data for 2ns */
#define VFAC_CTL3_CAP_HOLD_6NS 0x08 /* hold capture data for 6ns */
#define VFAC_CTL3_CAP_HOLD_0NS 0x0c /* hold capture data for 0ns */
#define VFAC_CTL3_CHROMAKEY 0x20 /* capture data will be chromakeyed */
#define VFAC_CTL3_CAP_IRQ 0x40 /* enable capture interrupt */
#define CAP_MEM_START 0xeb /* 18 bits */
#define CAP_MAP_WIDTH 0xed /* high 6 bits */
#define CAP_PITCH 0xee /* 8 bits */
#define CAP_CTL_MISC 0xef
#define CAP_CTL_MISC_HDIV 0x01
#define CAP_CTL_MISC_HDIV4 0x02
#define CAP_CTL_MISC_ODDEVEN 0x04
#define CAP_CTL_MISC_HSYNCDIV2 0x08
#define CAP_CTL_MISC_SYNCTZHIGH 0x10
#define CAP_CTL_MISC_SYNCTZOR 0x20
#define CAP_CTL_MISC_DISPUSED 0x80
#define REG_BANK 0xfa
#define REG_BANK_X 0x00
#define REG_BANK_Y 0x01
#define REG_BANK_W 0x02
#define REG_BANK_T 0x03
#define REG_BANK_J 0x04
#define REG_BANK_K 0x05
/*
* Bus-master
*/
#define BM_VID_ADDR_LOW 0xbc040
#define BM_VID_ADDR_HIGH 0xbc044
#define BM_ADDRESS_LOW 0xbc080
#define BM_ADDRESS_HIGH 0xbc084
#define BM_LENGTH 0xbc088
#define BM_CONTROL 0xbc08c
#define BM_CONTROL_ENABLE 0x01 /* enable transfer */
#define BM_CONTROL_IRQEN 0x02 /* enable IRQ at end of transfer */
#define BM_CONTROL_INIT 0x04 /* initialise status & count */
#define BM_COUNT 0xbc090 /* read-only */
/*
* TV registers
*/
#define TV_VBLANK_EVEN_START 0xbe43c
#define TV_VBLANK_EVEN_END 0xbe440
#define TV_VBLANK_ODD_START 0xbe444
#define TV_VBLANK_ODD_END 0xbe448
#define TV_SYNC_YGAIN 0xbe44c
#define TV_UV_GAIN 0xbe450
#define TV_PED_UVDET 0xbe454
#define TV_UV_BURST_AMP 0xbe458
#define TV_HSYNC_START 0xbe45c
#define TV_HSYNC_END 0xbe460
#define TV_Y_DELAY1 0xbe464
#define TV_Y_DELAY2 0xbe468
#define TV_UV_DELAY1 0xbe46c
#define TV_BURST_START 0xbe470
#define TV_BURST_END 0xbe474
#define TV_HBLANK_START 0xbe478
#define TV_HBLANK_END 0xbe47c
#define TV_PED_EVEN_START 0xbe480
#define TV_PED_EVEN_END 0xbe484
#define TV_PED_ODD_START 0xbe488
#define TV_PED_ODD_END 0xbe48c
#define TV_VSYNC_EVEN_START 0xbe490
#define TV_VSYNC_EVEN_END 0xbe494
#define TV_VSYNC_ODD_START 0xbe498
#define TV_VSYNC_ODD_END 0xbe49c
#define TV_SCFL 0xbe4a0
#define TV_SCFH 0xbe4a4
#define TV_SCP 0xbe4a8
#define TV_DELAYBYPASS 0xbe4b4
#define TV_EQL_END 0xbe4bc
#define TV_SERR_START 0xbe4c0
#define TV_SERR_END 0xbe4c4
#define TV_CTL 0xbe4dc /* reflects a previous register- MVFCLR, MVPCLR etc P241*/
#define TV_VSYNC_VGA_HS 0xbe4e8
#define TV_FLICK_XMIN 0xbe514
#define TV_FLICK_XMAX 0xbe518
#define TV_FLICK_YMIN 0xbe51c
#define TV_FLICK_YMAX 0xbe520
/*
* Graphics Co-processor
*/
#define CO_REG_CONTROL 0xbf011
#define CO_CTRL_BUSY 0x80
#define CO_CTRL_CMDFULL 0x04
#define CO_CTRL_FIFOEMPTY 0x02
#define CO_CTRL_READY 0x01
#define CO_REG_SRC_WIDTH 0xbf018
#define CO_REG_PIXFMT 0xbf01c
#define CO_PIXFMT_32BPP 0x03
#define CO_PIXFMT_24BPP 0x02
#define CO_PIXFMT_16BPP 0x01
#define CO_PIXFMT_8BPP 0x00
#define CO_REG_FGMIX 0xbf048
#define CO_FG_MIX_ZERO 0x00
#define CO_FG_MIX_SRC_AND_DST 0x01
#define CO_FG_MIX_SRC_AND_NDST 0x02
#define CO_FG_MIX_SRC 0x03
#define CO_FG_MIX_NSRC_AND_DST 0x04
#define CO_FG_MIX_DST 0x05
#define CO_FG_MIX_SRC_XOR_DST 0x06
#define CO_FG_MIX_SRC_OR_DST 0x07
#define CO_FG_MIX_NSRC_AND_NDST 0x08
#define CO_FG_MIX_SRC_XOR_NDST 0x09
#define CO_FG_MIX_NDST 0x0a
#define CO_FG_MIX_SRC_OR_NDST 0x0b
#define CO_FG_MIX_NSRC 0x0c
#define CO_FG_MIX_NSRC_OR_DST 0x0d
#define CO_FG_MIX_NSRC_OR_NDST 0x0e
#define CO_FG_MIX_ONES 0x0f
#define CO_REG_FGCOLOUR 0xbf058
#define CO_REG_BGCOLOUR 0xbf05c
#define CO_REG_PIXWIDTH 0xbf060
#define CO_REG_PIXHEIGHT 0xbf062
#define CO_REG_X_PHASE 0xbf078
#define CO_REG_CMD_L 0xbf07c
#define CO_CMD_L_PATTERN_FGCOL 0x8000
#define CO_CMD_L_INC_LEFT 0x0004
#define CO_CMD_L_INC_UP 0x0002
#define CO_REG_CMD_H 0xbf07e
#define CO_CMD_H_BGSRCMAP 0x8000 /* otherwise bg colour */
#define CO_CMD_H_FGSRCMAP 0x2000 /* otherwise fg colour */
#define CO_CMD_H_BLITTER 0x0800
#define CO_REG_SRC1_PTR 0xbf170
#define CO_REG_SRC2_PTR 0xbf174
#define CO_REG_DEST_PTR 0xbf178
#define CO_REG_DEST_WIDTH 0xbf218
/*
* Private structure
*/
struct cfb_info;
struct cyberpro_info {
struct pci_dev *dev;
unsigned char *regs;
char *fb;
char dev_name[32];
unsigned int fb_size;
unsigned int chip_id;
/*
* The following is a pointer to be passed into the
* functions below. The modules outside the main
* cyber2000fb.c driver have no knowledge as to what
* is within this structure.
*/
struct cfb_info *info;
/*
* Use these to enable the BM or TV registers. In an SMP
* environment, these two function pointers should only be
* called from the module_init() or module_exit()
* functions.
*/
void (*enable_extregs)(struct cfb_info *);
void (*disable_extregs)(struct cfb_info *);
};
#define ID_IGA_1682 0
#define ID_CYBERPRO_2000 1
#define ID_CYBERPRO_2010 2
#define ID_CYBERPRO_5000 3
struct fb_var_screeninfo;
/*
* Note! Writing to the Cyber20x0 registers from an interrupt
* routine is definitely a bad idea atm.
*/
int cyber2000fb_attach(struct cyberpro_info *info, int idx);
void cyber2000fb_detach(int idx);
void cyber2000fb_enable_extregs(struct cfb_info *cfb);
void cyber2000fb_disable_extregs(struct cfb_info *cfb);
void cyber2000fb_get_fb_var(struct cfb_info *cfb, struct fb_var_screeninfo *var);