tgafb.c
来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 1,551 行 · 第 1/3 页
C
1,551 行
/* * linux/drivers/video/tgafb.c -- DEC 21030 TGA frame buffer device * * Copyright (C) 1995 Jay Estabrook * Copyright (C) 1997 Geert Uytterhoeven * Copyright (C) 1999,2000 Martin Lucina, Tom Zerucha * Copyright (C) 2002 Richard Henderson * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive for * more details. */#include <linux/module.h>#include <linux/kernel.h>#include <linux/sched.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/init.h>#include <linux/fb.h>#include <linux/pci.h>#include <linux/selection.h>#include <asm/io.h>#include <video/tgafb.h>#include <linux/selection.h>/* * Local functions. */static int tgafb_check_var(struct fb_var_screeninfo *, struct fb_info *);static int tgafb_set_par(struct fb_info *);static void tgafb_set_pll(struct tga_par *, int);static int tgafb_setcolreg(unsigned, unsigned, unsigned, unsigned, unsigned, struct fb_info *);static int tgafb_blank(int, struct fb_info *);static void tgafb_init_fix(struct fb_info *);static void tgafb_imageblit(struct fb_info *, const struct fb_image *);static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *);static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *);static int tgafb_pci_register(struct pci_dev *, const struct pci_device_id *);#ifdef MODULEstatic void tgafb_pci_unregister(struct pci_dev *);#endifstatic const char *mode_option = "640x480@60";/* * Frame buffer operations */static struct fb_ops tgafb_ops = { .owner = THIS_MODULE, .fb_check_var = tgafb_check_var, .fb_set_par = tgafb_set_par, .fb_setcolreg = tgafb_setcolreg, .fb_blank = tgafb_blank, .fb_fillrect = tgafb_fillrect, .fb_copyarea = tgafb_copyarea, .fb_imageblit = tgafb_imageblit, .fb_cursor = soft_cursor,};/* * PCI registration operations */static struct pci_device_id const tgafb_pci_table[] = { { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }};static struct pci_driver tgafb_driver = { .name = "tgafb", .id_table = tgafb_pci_table, .probe = tgafb_pci_register, .remove = __devexit_p(tgafb_pci_unregister),};/** * tgafb_check_var - Optional function. Validates a var passed in. * @var: frame buffer variable screen structure * @info: frame buffer structure that represents a single frame buffer */static inttgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){ struct tga_par *par = (struct tga_par *)info->par; if (par->tga_type == TGA_TYPE_8PLANE) { if (var->bits_per_pixel != 8) return -EINVAL; } else { if (var->bits_per_pixel != 32) return -EINVAL; } if (var->xres_virtual != var->xres || var->yres_virtual != var->yres) return -EINVAL; if (var->nonstd) return -EINVAL; if (1000000000 / var->pixclock > TGA_PLL_MAX_FREQ) return -EINVAL; if ((var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED) return -EINVAL; /* Some of the acceleration routines assume the line width is a multiple of 64 bytes. */ if (var->xres * (par->tga_type == TGA_TYPE_8PLANE ? 1 : 4) % 64) return -EINVAL; return 0;}/** * tgafb_set_par - Optional function. Alters the hardware state. * @info: frame buffer structure that represents a single frame buffer */static inttgafb_set_par(struct fb_info *info){ static unsigned int const deep_presets[4] = { 0x00014000, 0x0001440d, 0xffffffff, 0x0001441d }; static unsigned int const rasterop_presets[4] = { 0x00000003, 0x00000303, 0xffffffff, 0x00000303 }; static unsigned int const mode_presets[4] = { 0x00002000, 0x00002300, 0xffffffff, 0x00002300 }; static unsigned int const base_addr_presets[4] = { 0x00000000, 0x00000001, 0xffffffff, 0x00000001 }; struct tga_par *par = (struct tga_par *) info->par; u32 htimings, vtimings, pll_freq; u8 tga_type; int i, j; /* Encode video timings. */ htimings = (((info->var.xres/4) & TGA_HORIZ_ACT_LSB) | (((info->var.xres/4) & 0x600 << 19) & TGA_HORIZ_ACT_MSB)); vtimings = (info->var.yres & TGA_VERT_ACTIVE); htimings |= ((info->var.right_margin/4) << 9) & TGA_HORIZ_FP; vtimings |= (info->var.lower_margin << 11) & TGA_VERT_FP; htimings |= ((info->var.hsync_len/4) << 14) & TGA_HORIZ_SYNC; vtimings |= (info->var.vsync_len << 16) & TGA_VERT_SYNC; htimings |= ((info->var.left_margin/4) << 21) & TGA_HORIZ_BP; vtimings |= (info->var.upper_margin << 22) & TGA_VERT_BP; if (info->var.sync & FB_SYNC_HOR_HIGH_ACT) htimings |= TGA_HORIZ_POLARITY; if (info->var.sync & FB_SYNC_VERT_HIGH_ACT) vtimings |= TGA_VERT_POLARITY; par->htimings = htimings; par->vtimings = vtimings; par->sync_on_green = !!(info->var.sync & FB_SYNC_ON_GREEN); /* Store other useful values in par. */ par->xres = info->var.xres; par->yres = info->var.yres; par->pll_freq = pll_freq = 1000000000 / info->var.pixclock; par->bits_per_pixel = info->var.bits_per_pixel; tga_type = par->tga_type; /* First, disable video. */ TGA_WRITE_REG(par, TGA_VALID_VIDEO | TGA_VALID_BLANK, TGA_VALID_REG); /* Write the DEEP register. */ while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */ continue; mb(); TGA_WRITE_REG(par, deep_presets[tga_type], TGA_DEEP_REG); while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */ continue; mb(); /* Write some more registers. */ TGA_WRITE_REG(par, rasterop_presets[tga_type], TGA_RASTEROP_REG); TGA_WRITE_REG(par, mode_presets[tga_type], TGA_MODE_REG); TGA_WRITE_REG(par, base_addr_presets[tga_type], TGA_BASE_ADDR_REG); /* Calculate & write the PLL. */ tgafb_set_pll(par, pll_freq); /* Write some more registers. */ TGA_WRITE_REG(par, 0xffffffff, TGA_PLANEMASK_REG); TGA_WRITE_REG(par, 0xffffffff, TGA_PIXELMASK_REG); /* Init video timing regs. */ TGA_WRITE_REG(par, htimings, TGA_HORIZ_REG); TGA_WRITE_REG(par, vtimings, TGA_VERT_REG); /* Initalise RAMDAC. */ if (tga_type == TGA_TYPE_8PLANE) { /* Init BT485 RAMDAC registers. */ BT485_WRITE(par, 0xa2 | (par->sync_on_green ? 0x8 : 0x0), BT485_CMD_0); BT485_WRITE(par, 0x01, BT485_ADDR_PAL_WRITE); BT485_WRITE(par, 0x14, BT485_CMD_3); /* cursor 64x64 */ BT485_WRITE(par, 0x40, BT485_CMD_1); BT485_WRITE(par, 0x20, BT485_CMD_2); /* cursor off, for now */ BT485_WRITE(par, 0xff, BT485_PIXEL_MASK); /* Fill palette registers. */ BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE); TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG); for (i = 0; i < 16; i++) { j = color_table[i]; TGA_WRITE_REG(par, default_red[j]|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); TGA_WRITE_REG(par, default_grn[j]|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); TGA_WRITE_REG(par, default_blu[j]|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); } for (i = 0; i < 240*3; i += 4) { TGA_WRITE_REG(par, 0x55|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x00|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x00|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x00|(BT485_DATA_PAL<<8), TGA_RAMDAC_REG); } } else { /* 24-plane or 24plusZ */ /* Init BT463 registers. */ BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_0, 0x40); BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_1, 0x08); BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_2, (par->sync_on_green ? 0x80 : 0x40)); BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_0, 0xff); BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_1, 0xff); BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_2, 0xff); BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_3, 0x0f); BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_0, 0x00); BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_1, 0x00); BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_2, 0x00); BT463_WRITE(par, BT463_REG_ACC, BT463_BLINK_MASK_3, 0x00); /* Fill the palette. */ BT463_LOAD_ADDR(par, 0x0000); TGA_WRITE_REG(par, BT463_PALETTE<<2, TGA_RAMDAC_REG); for (i = 0; i < 16; i++) { j = color_table[i]; TGA_WRITE_REG(par, default_red[j]|(BT463_PALETTE<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, default_grn[j]|(BT463_PALETTE<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, default_blu[j]|(BT463_PALETTE<<10), TGA_RAMDAC_REG); } for (i = 0; i < 512*3; i += 4) { TGA_WRITE_REG(par, 0x55|(BT463_PALETTE<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x00|(BT463_PALETTE<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x00|(BT463_PALETTE<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x00|(BT463_PALETTE<<10), TGA_RAMDAC_REG); } /* Fill window type table after start of vertical retrace. */ while (!(TGA_READ_REG(par, TGA_INTR_STAT_REG) & 0x01)) continue; TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG); mb(); while (!(TGA_READ_REG(par, TGA_INTR_STAT_REG) & 0x01)) continue; TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG); BT463_LOAD_ADDR(par, BT463_WINDOW_TYPE_BASE); TGA_WRITE_REG(par, BT463_REG_ACC<<2, TGA_RAMDAC_SETUP_REG); for (i = 0; i < 16; i++) { TGA_WRITE_REG(par, 0x00|(BT463_REG_ACC<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x01|(BT463_REG_ACC<<10), TGA_RAMDAC_REG); TGA_WRITE_REG(par, 0x80|(BT463_REG_ACC<<10), TGA_RAMDAC_REG); } } /* Finally, enable video scan (and pray for the monitor... :-) */ TGA_WRITE_REG(par, TGA_VALID_VIDEO, TGA_VALID_REG); return 0;}#define DIFFCHECK(X) \do { \ if (m <= 0x3f) { \ int delta = f - (TGA_PLL_BASE_FREQ * (X)) / (r << shift); \ if (delta < 0) \ delta = -delta; \ if (delta < min_diff) \ min_diff = delta, vm = m, va = a, vr = r; \ } \} while (0)static voidtgafb_set_pll(struct tga_par *par, int f){ int n, shift, base, min_diff, target; int r,a,m,vm = 34, va = 1, vr = 30; for (r = 0 ; r < 12 ; r++) TGA_WRITE_REG(par, !r, TGA_CLOCK_REG); if (f > TGA_PLL_MAX_FREQ) f = TGA_PLL_MAX_FREQ; if (f >= TGA_PLL_MAX_FREQ / 2) shift = 0; else if (f >= TGA_PLL_MAX_FREQ / 4) shift = 1; else shift = 2; TGA_WRITE_REG(par, shift & 1, TGA_CLOCK_REG); TGA_WRITE_REG(par, shift >> 1, TGA_CLOCK_REG); for (r = 0 ; r < 10 ; r++) TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); if (f <= 120000) { TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); } else if (f <= 200000) { TGA_WRITE_REG(par, 1, TGA_CLOCK_REG); TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); } else { TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); TGA_WRITE_REG(par, 1, TGA_CLOCK_REG); } TGA_WRITE_REG(par, 1, TGA_CLOCK_REG); TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); TGA_WRITE_REG(par, 1, TGA_CLOCK_REG); TGA_WRITE_REG(par, 0, TGA_CLOCK_REG); TGA_WRITE_REG(par, 1, TGA_CLOCK_REG); target = (f << shift) / TGA_PLL_BASE_FREQ; min_diff = TGA_PLL_MAX_FREQ; r = 7 / target; if (!r) r = 1; base = target * r; while (base < 449) { for (n = base < 7 ? 7 : base; n < base + target && n < 449; n++) { m = ((n + 3) / 7) - 1; a = 0; DIFFCHECK((m + 1) * 7); m++; DIFFCHECK((m + 1) * 7); m = (n / 6) - 1; if ((a = n % 6)) DIFFCHECK(n); } r++; base += target; } vr--; for (r = 0; r < 8; r++) TGA_WRITE_REG(par, (vm >> r) & 1, TGA_CLOCK_REG); for (r = 0; r < 8 ; r++) TGA_WRITE_REG(par, (va >> r) & 1, TGA_CLOCK_REG); for (r = 0; r < 7 ; r++) TGA_WRITE_REG(par, (vr >> r) & 1, TGA_CLOCK_REG); TGA_WRITE_REG(par, ((vr >> 7) & 1)|2, TGA_CLOCK_REG);}/** * tgafb_setcolreg - Optional function. Sets a color register. * @regno: boolean, 0 copy local, 1 get_user() function * @red: frame buffer colormap structure * @green: The green value which can be up to 16 bits wide * @blue: The blue value which can be up to 16 bits wide. * @transp: If supported the alpha value which can be up to 16 bits wide. * @info: frame buffer info structure */static inttgafb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info){ struct tga_par *par = (struct tga_par *) info->par; if (regno > 255) return 1; red >>= 8; green >>= 8; blue >>= 8; if (par->tga_type == TGA_TYPE_8PLANE) { BT485_WRITE(par, regno, BT485_ADDR_PAL_WRITE); TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG); TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); } else if (regno < 16) { u32 value = (red << 16) | (green << 8) | blue; ((u32 *)info->pseudo_palette)[regno] = value; } return 0;}/** * tgafb_blank - Optional function. Blanks the display. * @blank_mode: the blank mode we want. * @info: frame buffer structure that represents a single frame buffer */static inttgafb_blank(int blank, struct fb_info *info){ struct tga_par *par = (struct tga_par *) info->par; u32 vhcr, vvcr, vvvr; unsigned long flags; local_irq_save(flags); vhcr = TGA_READ_REG(par, TGA_HORIZ_REG); vvcr = TGA_READ_REG(par, TGA_VERT_REG); vvvr = TGA_READ_REG(par, TGA_VALID_REG); vvvr &= ~(TGA_VALID_VIDEO | TGA_VALID_BLANK); switch (blank) { case 0: /* Unblanking */ if (par->vesa_blanked) { TGA_WRITE_REG(par, vhcr & 0xbfffffff, TGA_HORIZ_REG); TGA_WRITE_REG(par, vvcr & 0xbfffffff, TGA_VERT_REG); par->vesa_blanked = 0; } TGA_WRITE_REG(par, vvvr | TGA_VALID_VIDEO, TGA_VALID_REG); break; case 1: /* Normal blanking */ TGA_WRITE_REG(par, vvvr | TGA_VALID_VIDEO | TGA_VALID_BLANK, TGA_VALID_REG); break; case 2: /* VESA blank (vsync off) */ TGA_WRITE_REG(par, vvcr | 0x40000000, TGA_VERT_REG); TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG); par->vesa_blanked = 1; break; case 3: /* VESA blank (hsync off) */ TGA_WRITE_REG(par, vhcr | 0x40000000, TGA_HORIZ_REG); TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG); par->vesa_blanked = 1; break; case 4: /* Poweroff */ TGA_WRITE_REG(par, vhcr | 0x40000000, TGA_HORIZ_REG); TGA_WRITE_REG(par, vvcr | 0x40000000, TGA_VERT_REG); TGA_WRITE_REG(par, vvvr | TGA_VALID_BLANK, TGA_VALID_REG); par->vesa_blanked = 1; break; } local_irq_restore(flags); return 0;}/* * Acceleration. *//** * tgafb_imageblit - REQUIRED function. Can use generic routines if * non acclerated hardware and packed pixel based. * Copies a image from system memory to the screen.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?