📄 cyber2000fb.c
字号:
/* * linux/drivers/video/cyber2000fb.c * * Copyright (C) 1998-2000 Russell King * * MIPS and 50xx clock support * Copyright (C) 2001 Bradley D. LaRonde <brad@ltc.com> * * 32 bit support, text color and panning fixes for modes != 8 bit * Copyright (C) 2002 Denis Oliver Kropp <dok@directfb.org> * * 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. * * Intergraphics 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, since * especially for the colourmap stuff. Once fbcon has been fully migrated, * we can kill the last 5 references to cfb->currcon. * * 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. */#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>/* * Define this if you don't want RGB565, but RGB555 for 16bpp displays. *//*#define CFB16_IS_CFB15*/#include "cyber2000fb.h"struct cfb_info { struct fb_info fb; struct display_switch *dispsw; struct pci_dev *dev; unsigned char *region; unsigned char *regs; signed int currcon; 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_ctl1; u_char mem_ctl2; u_char mclk_mult; u_char mclk_div;};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 voidcyber2000_crtcw(unsigned int reg, unsigned int val, struct cfb_info *cfb){ cyber2000fb_writew((reg & 255) | val << 8, 0x3d4, cfb);}static inline voidcyber2000_grphw(unsigned int reg, unsigned int val, struct cfb_info *cfb){ cyber2000fb_writew((reg & 255) | val << 8, 0x3ce, cfb);}static inline unsigned intcyber2000_grphr(unsigned int reg, struct cfb_info *cfb){ cyber2000fb_writeb(reg, 0x3ce, cfb); return cyber2000fb_readb(0x3cf, cfb);}static inline voidcyber2000_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 voidcyber2000_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) & 0x80) { 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 *p){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; cfb->dispsw->setup(p);}static voidcyber2000_accel_bmove(struct display *p, int sy, int sx, int dy, int dx, int height, int width){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; struct fb_var_screeninfo *var = &p->fb_info->var; u_long src, dst; u_int fh, fw; int cmd = CO_CMD_L_PATTERN_FGCOL; fw = fontwidth(p); sx *= fw; dx *= fw; width *= fw; width -= 1; if (sx < dx) { sx += width; dx += width; cmd |= CO_CMD_L_INC_LEFT; } fh = fontheight(p); 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_writeb(0x03, CO_REG_FORE_MIX, cfb); cyber2000fb_writew(width, CO_REG_WIDTH, cfb); if (var->bits_per_pixel != 24) { cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb); cyber2000fb_writel(src, CO_REG_SRC_PTR, cfb); } else { cyber2000fb_writel(dst * 3, CO_REG_DEST_PTR, cfb); cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb); cyber2000fb_writel(src * 3, CO_REG_SRC_PTR, cfb); } cyber2000fb_writew(height, CO_REG_HEIGHT, cfb); cyber2000fb_writew(cmd, CO_REG_CMD_L, cfb); cyber2000fb_writew(0x2800, CO_REG_CMD_H, cfb);}static voidcyber2000_accel_clear(struct vc_data *conp, struct display *p, int sy, int sx, int height, int width){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; struct fb_var_screeninfo *var = &p->fb_info->var; u_long dst; u_int fw, fh; u32 bgx = attr_bgcol_ec(p, conp); fw = fontwidth(p); fh = fontheight(p); 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_writeb(0x03, CO_REG_FORE_MIX, cfb); cyber2000fb_writew(width, CO_REG_WIDTH, cfb); cyber2000fb_writew(height, CO_REG_HEIGHT, cfb); switch (var->bits_per_pixel) { case 15: case 16: bgx = ((u16 *)p->dispsw_data)[bgx]; case 8: cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb); break; case 24: cyber2000fb_writel(dst * 3, CO_REG_DEST_PTR, cfb); cyber2000fb_writeb(dst, CO_REG_X_PHASE, cfb); bgx = ((u32 *)p->dispsw_data)[bgx]; break; case 32: bgx = ((u32 *)p->dispsw_data)[bgx]; cyber2000fb_writel(dst, CO_REG_DEST_PTR, cfb); break; } cyber2000fb_writel(bgx, CO_REG_FOREGROUND, cfb); cyber2000fb_writew(CO_CMD_L_PATTERN_FGCOL, CO_REG_CMD_L, cfb); cyber2000fb_writew(0x0800, CO_REG_CMD_H, cfb);}static voidcyber2000_accel_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; cyber2000_accel_wait(cfb); cfb->dispsw->putc(conp, p, c, yy, xx);}static voidcyber2000_accel_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; cyber2000_accel_wait(cfb); cfb->dispsw->putcs(conp, p, s, count, yy, xx);}static void cyber2000_accel_revc(struct display *p, int xx, int yy){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; cyber2000_accel_wait(cfb); cfb->dispsw->revc(p, xx, yy);}static voidcyber2000_accel_clear_margins(struct vc_data *conp, struct display *p, int bottom_only){ struct cfb_info *cfb = (struct cfb_info *)p->fb_info; cfb->dispsw->clear_margins(conp, p, 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)};/* * Set a single color register. Return != 0 for invalid regno. */static intcyber2000_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; u_int alpha = transp ^ 0xFFFF; if (regno >= NR_PALETTE) return 1; red >>= 8; green >>= 8; blue >>= 8; alpha >>= 8; cfb->palette[regno].red = red; cfb->palette[regno].green = green; cfb->palette[regno].blue = blue; switch (cfb->fb.var.bits_per_pixel) {#ifdef FBCON_HAS_CFB8 case 8: cyber2000fb_writeb(regno, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); break;#endif#ifdef FBCON_HAS_CFB16 case 16:#ifndef CFB16_IS_CFB15 if (regno < 64) { /* write green */ 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); } if (regno < 32) { /* write red,blue */ cyber2000fb_writeb(regno << 3, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(cfb->palette[regno << 1].green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); } if (regno < 16) ((u16 *)cfb->fb.pseudo_palette)[regno] = ((red << 8) & 0xf800) | ((green << 3) & 0x07e0) | ((blue >> 3)); break;#endif case 15: if (regno < 32) { cyber2000fb_writeb(regno << 3, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); } if (regno < 16) ((u16 *)cfb->fb.pseudo_palette)[regno] = ((red << 7) & 0x7c00) | ((green << 2) & 0x03e0) | ((blue >> 3)); break;#endif#ifdef FBCON_HAS_CFB24 case 24: cyber2000fb_writeb(regno, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); if (regno < 16) ((u32 *)cfb->fb.pseudo_palette)[regno] = (red << 16) | (green << 8) | blue; break;#endif#ifdef FBCON_HAS_CFB32 case 32: cyber2000fb_writeb(regno, 0x3c8, cfb); cyber2000fb_writeb(red, 0x3c9, cfb); cyber2000fb_writeb(green, 0x3c9, cfb); cyber2000fb_writeb(blue, 0x3c9, cfb); if (regno < 16) ((u32 *)cfb->fb.pseudo_palette)[regno] = (alpha << 24) | (red << 16) | (green << 8) | blue; break;#endif default: return 1; } return 0;}struct par_info { /* * Hardware */ u_char clock_mult; u_char clock_div; u_char visualid; u_char pixformat; u_char crtc_ofl; u_char crtc[19]; u_int width; u_int pitch; u_int fetch; /* * Other */ u_char palette_ctrl; u_int vmode;};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_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(0x11, 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); /* woody: set the interlaced bit... */ /* FIXME: what about doublescan? */ cyber2000fb_writeb(0x11, 0x3ce, cfb); i = cyber2000fb_readb(0x3cf, cfb); if (hw->vmode == FB_VMODE_INTERLACED) i |= 0x20; else i &= ~0x20; cyber2000fb_writeb(i, 0x3cf, cfb); /* PLL registers */ cyber2000_grphw(DCLK_MULT, hw->clock_mult, cfb); cyber2000_grphw(DCLK_DIV, hw->clock_div, cfb); cyber2000_grphw(MCLK_MULT, cfb->mclk_mult, cfb); cyber2000_grphw(MCLK_DIV, cfb->mclk_div, cfb); cyber2000_grphw(0x90, 0x01, cfb); cyber2000_grphw(0xb9, 0x80, cfb); cyber2000_grphw(0xb9, 0x00, cfb); cyber2000fb_writeb(0x56, 0x3ce, cfb); i = cyber2000fb_readb(0x3cf, cfb); cyber2000fb_writeb(i | 4, 0x3cf, cfb); cyber2000fb_writeb(hw->palette_ctrl, 0x3c6, cfb); cyber2000fb_writeb(i, 0x3cf, 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(0x77, hw->visualid, cfb); /* make sure we stay in linear mode */ cyber2000_grphw(0x33, 0x0d, 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->pixformat, CO_REG_PIX_FORMAT, cfb);}static inline intcyber2000fb_update_start(struct cfb_info *cfb, struct fb_var_screeninfo *var){ u_int base; base = var->yoffset * var->xres_virtual + var->xoffset; /* have to be careful, because bits_per_pixel might be 15 in this version of the driver -- dok@directfb.org 2002/06/13 */ base *= (var->bits_per_pixel + 7) >> 3; base >>= 2; 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 intcyber2000fb_set_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info){ struct cfb_info *cfb = (struct cfb_info *)info; struct fb_cmap *dcmap = &fb_display[con].cmap; int err = 0; /* no colormap allocated? */ if (!dcmap->len) { int size; if (cfb->fb.var.bits_per_pixel == 16) size = 32; else size = 256; err = fb_alloc_cmap(dcmap, size, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -