📄 arkfb.c
字号:
/* * linux/drivers/video/arkfb.c -- Frame buffer device driver for ARK 2000PV * with ICS 5342 dac (it is easy to add support for different dacs). * * Copyright (c) 2007 Ondrej Zajicek <santiago@crfreenet.org> * * 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. * * Code is based on s3fb */#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/svga.h>#include <linux/init.h>#include <linux/pci.h>#include <linux/console.h> /* Why should fb driver call console functions? because acquire_console_sem() */#include <video/vga.h>#ifdef CONFIG_MTRR#include <asm/mtrr.h>#endifstruct arkfb_info { int mclk_freq; int mtrr_reg; struct dac_info *dac; struct vgastate state; struct mutex open_lock; unsigned int ref_count; u32 pseudo_palette[16];};/* ------------------------------------------------------------------------- */static const struct svga_fb_format arkfb_formats[] = { { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 8}, { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16}, { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1, FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16}, { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0, FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8}, {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0, FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0, FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 8, 8}, {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0, FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2}, SVGA_FORMAT_END};/* CRT timing register sets */static const struct vga_regset ark_h_total_regs[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END};static const struct vga_regset ark_h_display_regs[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END};static const struct vga_regset ark_h_blank_start_regs[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END};static const struct vga_regset ark_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END};static const struct vga_regset ark_h_sync_start_regs[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END};static const struct vga_regset ark_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};static const struct vga_regset ark_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END};static const struct vga_regset ark_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END};static const struct vga_regset ark_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x40, 5, 5}, VGA_REGSET_END};// const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END};static const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};static const struct vga_regset ark_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x40, 4, 4}, VGA_REGSET_END};static const struct vga_regset ark_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};static const struct vga_regset ark_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END};static const struct vga_regset ark_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END};static const struct vga_regset ark_offset_regs[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END};static const struct svga_timing_regs ark_timing_regs = { ark_h_total_regs, ark_h_display_regs, ark_h_blank_start_regs, ark_h_blank_end_regs, ark_h_sync_start_regs, ark_h_sync_end_regs, ark_v_total_regs, ark_v_display_regs, ark_v_blank_start_regs, ark_v_blank_end_regs, ark_v_sync_start_regs, ark_v_sync_end_regs,};/* ------------------------------------------------------------------------- *//* Module parameters */static char *mode_option __devinitdata = "640x480-8@60";#ifdef CONFIG_MTRRstatic int mtrr = 1;#endifMODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>");MODULE_LICENSE("GPL");MODULE_DESCRIPTION("fbdev driver for ARK 2000PV");module_param(mode_option, charp, 0444);MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)");module_param_named(mode, mode_option, charp, 0444);MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc) (deprecated)");#ifdef CONFIG_MTRRmodule_param(mtrr, int, 0444);MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");#endifstatic int threshold = 4;module_param(threshold, int, 0644);MODULE_PARM_DESC(threshold, "FIFO threshold");/* ------------------------------------------------------------------------- */static void arkfb_settile(struct fb_info *info, struct fb_tilemap *map){ const u8 *font = map->data; u8 __iomem *fb = (u8 __iomem *)info->screen_base; int i, c; if ((map->width != 8) || (map->height != 16) || (map->depth != 1) || (map->length != 256)) { printk(KERN_ERR "fb%d: unsupported font parameters: width %d, " "height %d, depth %d, length %d\n", info->node, map->width, map->height, map->depth, map->length); return; } fb += 2; for (c = 0; c < map->length; c++) { for (i = 0; i < map->height; i++) { fb_writeb(font[i], &fb[i * 4]); fb_writeb(font[i], &fb[i * 4 + (128 * 8)]); } fb += 128; if ((c % 8) == 7) fb += 128*8; font += map->height; }}static struct fb_tile_ops arkfb_tile_ops = { .fb_settile = arkfb_settile, .fb_tilecopy = svga_tilecopy, .fb_tilefill = svga_tilefill, .fb_tileblit = svga_tileblit, .fb_tilecursor = svga_tilecursor, .fb_get_tilemax = svga_get_tilemax,};/* ------------------------------------------------------------------------- *//* image data is MSB-first, fb structure is MSB-first too */static inline u32 expand_color(u32 c){ return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;}/* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */static void arkfb_iplan_imageblit(struct fb_info *info, const struct fb_image *image){ u32 fg = expand_color(image->fg_color); u32 bg = expand_color(image->bg_color); const u8 *src1, *src; u8 __iomem *dst1; u32 __iomem *dst; u32 val; int x, y; src1 = image->data; dst1 = info->screen_base + (image->dy * info->fix.line_length) + ((image->dx / 8) * 4); for (y = 0; y < image->height; y++) { src = src1; dst = (u32 __iomem *) dst1; for (x = 0; x < image->width; x += 8) { val = *(src++) * 0x01010101; val = (val & fg) | (~val & bg); fb_writel(val, dst++); } src1 += image->width / 8; dst1 += info->fix.line_length; }}/* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */static void arkfb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect){ u32 fg = expand_color(rect->color); u8 __iomem *dst1; u32 __iomem *dst; int x, y; dst1 = info->screen_base + (rect->dy * info->fix.line_length) + ((rect->dx / 8) * 4); for (y = 0; y < rect->height; y++) { dst = (u32 __iomem *) dst1; for (x = 0; x < rect->width; x += 8) { fb_writel(fg, dst++); } dst1 += info->fix.line_length; }}/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */static inline u32 expand_pixel(u32 c){ return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) | ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;}/* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */static void arkfb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image){ u32 fg = image->fg_color * 0x11111111; u32 bg = image->bg_color * 0x11111111; const u8 *src1, *src; u8 __iomem *dst1; u32 __iomem *dst; u32 val; int x, y; src1 = image->data; dst1 = info->screen_base + (image->dy * info->fix.line_length) + ((image->dx / 8) * 4); for (y = 0; y < image->height; y++) { src = src1; dst = (u32 __iomem *) dst1; for (x = 0; x < image->width; x += 8) { val = expand_pixel(*(src++)); val = (val & fg) | (~val & bg); fb_writel(val, dst++); } src1 += image->width / 8; dst1 += info->fix.line_length; }}static void arkfb_imageblit(struct fb_info *info, const struct fb_image *image){ if ((info->var.bits_per_pixel == 4) && (image->depth == 1) && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) { if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES) arkfb_iplan_imageblit(info, image); else arkfb_cfb4_imageblit(info, image); } else cfb_imageblit(info, image);}static void arkfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect){ if ((info->var.bits_per_pixel == 4) && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0) && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)) arkfb_iplan_fillrect(info, rect); else cfb_fillrect(info, rect);}/* ------------------------------------------------------------------------- */enum{ DAC_PSEUDO8_8, DAC_RGB1555_8, DAC_RGB0565_8, DAC_RGB0888_8, DAC_RGB8888_8, DAC_PSEUDO8_16, DAC_RGB1555_16, DAC_RGB0565_16, DAC_RGB0888_16, DAC_RGB8888_16, DAC_MAX};struct dac_ops { int (*dac_get_mode)(struct dac_info *info); int (*dac_set_mode)(struct dac_info *info, int mode); int (*dac_get_freq)(struct dac_info *info, int channel); int (*dac_set_freq)(struct dac_info *info, int channel, u32 freq); void (*dac_release)(struct dac_info *info);};typedef void (*dac_read_regs_t)(void *data, u8 *code, int count);typedef void (*dac_write_regs_t)(void *data, u8 *code, int count);struct dac_info{ struct dac_ops *dacops; dac_read_regs_t dac_read_regs; dac_write_regs_t dac_write_regs; void *data;};static inline u8 dac_read_reg(struct dac_info *info, u8 reg){ u8 code[2] = {reg, 0}; info->dac_read_regs(info->data, code, 1); return code[1];}static inline void dac_read_regs(struct dac_info *info, u8 *code, int count){ info->dac_read_regs(info->data, code, count);}static inline void dac_write_reg(struct dac_info *info, u8 reg, u8 val){ u8 code[2] = {reg, val}; info->dac_write_regs(info->data, code, 1);}static inline void dac_write_regs(struct dac_info *info, u8 *code, int count){ info->dac_write_regs(info->data, code, count);}static inline int dac_set_mode(struct dac_info *info, int mode){ return info->dacops->dac_set_mode(info, mode);}static inline int dac_set_freq(struct dac_info *info, int channel, u32 freq){ return info->dacops->dac_set_freq(info, channel, freq);}static inline void dac_release(struct dac_info *info){ info->dacops->dac_release(info);}/* ------------------------------------------------------------------------- *//* ICS5342 DAC */struct ics5342_info{ struct dac_info dac; u8 mode;};#define DAC_PAR(info) ((struct ics5342_info *) info)/* LSB is set to distinguish unused slots */static const u8 ics5342_mode_table[DAC_MAX] = { [DAC_PSEUDO8_8] = 0x01, [DAC_RGB1555_8] = 0x21, [DAC_RGB0565_8] = 0x61, [DAC_RGB0888_8] = 0x41, [DAC_PSEUDO8_16] = 0x11, [DAC_RGB1555_16] = 0x31, [DAC_RGB0565_16] = 0x51, [DAC_RGB0888_16] = 0x91, [DAC_RGB8888_16] = 0x71};static int ics5342_set_mode(struct dac_info *info, int mode){ u8 code; if (mode >= DAC_MAX) return -EINVAL; code = ics5342_mode_table[mode]; if (! code) return -EINVAL; dac_write_reg(info, 6, code & 0xF0); DAC_PAR(info)->mode = mode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -