atyfb.c
来自「Linux内核源代码 为压缩文件 是<<Linux内核>>」· C语言 代码 · 共 2,436 行 · 第 1/5 页
C
2,436 行
/* $Id: atyfb.c,v 1.147 2000/08/29 07:01:56 davem Exp $ * linux/drivers/video/atyfb.c -- Frame buffer device for ATI Mach64 * * Copyright (C) 1997-1998 Geert Uytterhoeven * Copyright (C) 1998 Bernd Harries * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) * * This driver is partly based on the PowerMac console driver: * * Copyright (C) 1996 Paul Mackerras * * and on the PowerMac ATI/mach64 display driver: * * Copyright (C) 1997 Michael AK Tesch * * with work by Jon Howell * Harry AC Eaton * Anthony Tong <atong@uiuc.edu> * * 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. * * Many thanks to Nitya from ATI devrel for support and patience ! *//****************************************************************************** TODO: - cursor support on all cards and all ramdacs. - cursor parameters controlable via ioctl()s. - guess PLL and MCLK based on the original PLL register values initialized by the BIOS or Open Firmware (if they are initialized). (Anyone to help with this?)******************************************************************************/#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/malloc.h>#include <linux/vmalloc.h>#include <linux/delay.h>#include <linux/interrupt.h>#include <linux/fb.h>#include <linux/selection.h>#include <linux/console.h>#include <linux/init.h>#include <linux/pci.h>#include <linux/kd.h>#include <linux/vt_kern.h>#ifdef CONFIG_FB_COMPAT_XPMAC#include <asm/vc_ioctl.h>#endif#include <asm/io.h>#ifdef __powerpc__#include <linux/adb.h>#include <asm/prom.h>#include <asm/pci-bridge.h>#include <video/macmodes.h>#endif#ifdef CONFIG_ADB_PMU#include <linux/pmu.h>#endif#ifdef CONFIG_NVRAM#include <linux/nvram.h>#endif#ifdef CONFIG_PMAC_BACKLIGHT#include <asm/backlight.h>#endif#ifdef __sparc__#include <asm/pbm.h>#include <asm/fbio.h>#endif#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 "aty.h"/* * Debug flags. */#undef DEBUG/* Definitions for the ICS 2595 == ATI 18818_1 Clockchip */#define REF_FREQ_2595 1432 /* 14.33 MHz (exact 14.31818) */#define REF_DIV_2595 46 /* really 43 on ICS 2595 !!! */ /* ohne Prescaler */#define MAX_FREQ_2595 15938 /* 159.38 MHz (really 170.486) */#define MIN_FREQ_2595 8000 /* 80.00 MHz ( 85.565) */ /* mit Prescaler 2, 4, 8 */#define ABS_MIN_FREQ_2595 1000 /* 10.00 MHz (really 10.697) */#define N_ADJ_2595 257#define STOP_BITS_2595 0x1800#define MIN_N_408 2#define MIN_N_1703 6#define MIN_M 2#define MAX_M 30#define MIN_N 35#define MAX_N 255-8/* Make sure n * PAGE_SIZE is protected at end of Aperture for GUI-regs *//* - must be large enough to catch all GUI-Regs *//* - must be aligned to a PAGE boundary */#define GUI_RESERVE (1 * PAGE_SIZE)/* FIXME: remove the FAIL definition */#define FAIL(x) do { printk(x "\n"); return -EINVAL; } while (0) /* * Elements of the Hardware specific atyfb_par structure */struct crtc { u32 vxres; u32 vyres; u32 xoffset; u32 yoffset; u32 bpp; u32 h_tot_disp; u32 h_sync_strt_wid; u32 v_tot_disp; u32 v_sync_strt_wid; u32 off_pitch; u32 gen_cntl; u32 dp_pix_width; /* acceleration */ u32 dp_chain_mask; /* acceleration */};struct pll_gx { u8 m; u8 n;};struct pll_18818{ u32 program_bits; u32 locationAddr; u32 period_in_ps; u32 post_divider;};struct pll_ct { u8 pll_ref_div; u8 pll_gen_cntl; u8 mclk_fb_div; u8 pll_vclk_cntl; u8 vclk_post_div; u8 vclk_fb_div; u8 pll_ext_cntl; u32 dsp_config; /* Mach64 GTB DSP */ u32 dsp_on_off; /* Mach64 GTB DSP */ u8 mclk_post_div_real; u8 vclk_post_div_real;}; /* * The Hardware parameters for each card */struct atyfb_par { struct crtc crtc; union { struct pll_gx gx; struct pll_ct ct; struct pll_18818 ics2595; } pll; u32 accel_flags;};struct aty_cmap_regs { u8 windex; u8 lut; u8 mask; u8 rindex; u8 cntl;};struct pci_mmap_map { unsigned long voff; unsigned long poff; unsigned long size; unsigned long prot_flag; unsigned long prot_mask;};#define DEFAULT_CURSOR_BLINK_RATE (20)#define CURSOR_DRAW_DELAY (2)struct aty_cursor { int enable; int on; int vbl_cnt; int blink_rate; u32 offset; struct { u16 x, y; } pos, hot, size; u32 color[2]; u8 bits[8][64]; u8 mask[8][64]; u8 *ram; struct timer_list *timer;};struct fb_info_aty { struct fb_info fb_info; struct fb_info_aty *next; unsigned long ati_regbase_phys; unsigned long ati_regbase; unsigned long frame_buffer_phys; unsigned long frame_buffer; unsigned long clk_wr_offset; struct pci_mmap_map *mmap_map; struct aty_cursor *cursor; struct aty_cmap_regs *aty_cmap_regs; struct { u8 red, green, blue, pad; } palette[256]; struct atyfb_par default_par; struct atyfb_par current_par; u32 total_vram; u32 ref_clk_per; u32 pll_per; u32 mclk_per; u16 chip_type;#define Gx info->chip_type u8 chip_rev;#define Rev info->chip_rev u8 bus_type; u8 ram_type; u8 dac_type; u8 dac_subtype; u8 clk_type; u8 mem_refresh_rate; struct display disp; struct display_switch dispsw; union {#ifdef FBCON_HAS_CFB16 u16 cfb16[16];#endif#ifdef FBCON_HAS_CFB24 u32 cfb24[16];#endif#ifdef FBCON_HAS_CFB32 u32 cfb32[16];#endif } fbcon_cmap; u8 blitter_may_be_busy;#ifdef __sparc__ u8 mmaped; int open; int vtconsole; int consolecnt;#endif#ifdef CONFIG_PMAC_PBOOK unsigned char *save_framebuffer; unsigned long save_pll[64];#endif};#ifdef CONFIG_PMAC_PBOOK int aty_sleep_notify(struct pmu_sleep_notifier *self, int when); static struct pmu_sleep_notifier aty_sleep_notifier = { aty_sleep_notify, SLEEP_LEVEL_VIDEO, }; static struct fb_info_aty* first_display = NULL;#endif#ifdef CONFIG_PMAC_BACKLIGHTstatic int aty_set_backlight_enable(int on, int level, void* data);static int aty_set_backlight_level(int level, void* data);static struct backlight_controller aty_backlight_controller = { aty_set_backlight_enable, aty_set_backlight_level};#endif /* CONFIG_PMAC_BACKLIGHT */ /* * Frame buffer device API */static int atyfb_open(struct fb_info *info, int user);static int atyfb_release(struct fb_info *info, int user);static int atyfb_get_fix(struct fb_fix_screeninfo *fix, int con, struct fb_info *fb);static int atyfb_get_var(struct fb_var_screeninfo *var, int con, struct fb_info *fb);static int atyfb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *fb);static int atyfb_pan_display(struct fb_var_screeninfo *var, int con, struct fb_info *fb);static int atyfb_get_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info);static int atyfb_set_cmap(struct fb_cmap *cmap, int kspc, int con, struct fb_info *info);static int atyfb_ioctl(struct inode *inode, struct file *file, u_int cmd, u_long arg, int con, struct fb_info *info);#ifdef __sparc__static int atyfb_mmap(struct fb_info *info, struct file *file, struct vm_area_struct *vma);#endifstatic int atyfb_rasterimg(struct fb_info *info, int start); /* * Interface to the low level console driver */static int atyfbcon_switch(int con, struct fb_info *fb);static int atyfbcon_updatevar(int con, struct fb_info *fb);static void atyfbcon_blank(int blank, struct fb_info *fb); /* * Text console acceleration */static void fbcon_aty_bmove(struct display *p, int sy, int sx, int dy, int dx, int height, int width);static void fbcon_aty_clear(struct vc_data *conp, struct display *p, int sy, int sx, int height, int width);#ifdef FBCON_HAS_CFB8static struct display_switch fbcon_aty8;static void fbcon_aty8_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx);static void fbcon_aty8_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx);#endif#ifdef FBCON_HAS_CFB16static struct display_switch fbcon_aty16;static void fbcon_aty16_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx);static void fbcon_aty16_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx);#endif#ifdef FBCON_HAS_CFB24static struct display_switch fbcon_aty24;static void fbcon_aty24_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx);static void fbcon_aty24_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx);#endif#ifdef FBCON_HAS_CFB32static struct display_switch fbcon_aty32;static void fbcon_aty32_putc(struct vc_data *conp, struct display *p, int c, int yy, int xx);static void fbcon_aty32_putcs(struct vc_data *conp, struct display *p, const unsigned short *s, int count, int yy, int xx);#endif /* * Internal routines */static int aty_init(struct fb_info_aty *info, const char *name);static struct aty_cursor *aty_init_cursor(struct fb_info_aty *fb);#ifdef CONFIG_ATARIstatic int store_video_par(char *videopar, unsigned char m64_num);static char *strtoke(char *s, const char *ct);#endifstatic void reset_engine(const struct fb_info_aty *info);static void init_engine(const struct atyfb_par *par, struct fb_info_aty *info);static void aty_st_514(int offset, u8 val, const struct fb_info_aty *info);static void aty_st_pll(int offset, u8 val, const struct fb_info_aty *info);static u8 aty_ld_pll(int offset, const struct fb_info_aty *info);static void aty_set_crtc(const struct fb_info_aty *info, const struct crtc *crtc);static int aty_var_to_crtc(const struct fb_info_aty *info, const struct fb_var_screeninfo *var, struct crtc *crtc);static void aty_set_dac_514(const struct fb_info_aty *info, u32 bpp);static int aty_crtc_to_var(const struct crtc *crtc, struct fb_var_screeninfo *var);static void aty_set_pll_gx(const struct fb_info_aty *info, const struct pll_gx *pll);static int aty_set_dac_ATI68860_B(const struct fb_info_aty *info, u32 bpp, u32 AccelMode);static int aty_set_dac_ATT21C498(const struct fb_info_aty *info, const struct pll_18818 *pll, u32 bpp);void aty_dac_waste4(const struct fb_info_aty *info);static int aty_var_to_pll_18818(u32 period_in_ps, struct pll_18818 *pll);static u32 aty_pll_18818_to_var(const struct pll_18818 *pll);static void aty_set_pll18818(const struct fb_info_aty *info, const struct pll_18818 *pll);static void aty_StrobeClock(const struct fb_info_aty *info);static void aty_ICS2595_put1bit(u8 data, const struct fb_info_aty *info);static int aty_var_to_pll_408(u32 period_in_ps, struct pll_18818 *pll);static u32 aty_pll_408_to_var(const struct pll_18818 *pll);static void aty_set_pll_408(const struct fb_info_aty *info, const struct pll_18818 *pll);static int aty_var_to_pll_1703(u32 period_in_ps, struct pll_18818 *pll);static u32 aty_pll_1703_to_var(const struct pll_18818 *pll);static void aty_set_pll_1703(const struct fb_info_aty *info, const struct pll_18818 *pll);static int aty_var_to_pll_8398(u32 period_in_ps, struct pll_18818 *pll);static u32 aty_pll_8398_to_var(const struct pll_18818 *pll);static void aty_set_pll_8398(const struct fb_info_aty *info, const struct pll_18818 *pll);static int aty_var_to_pll_514(u32 vclk_per, struct pll_gx *pll);static u32 aty_pll_gx_to_var(const struct pll_gx *pll, const struct fb_info_aty *info);static void aty_set_pll_ct(const struct fb_info_aty *info, const struct pll_ct *pll);static int aty_valid_pll_ct(const struct fb_info_aty *info, u32 vclk_per, struct pll_ct *pll);static int aty_dsp_gt(const struct fb_info_aty *info, u8 bpp, struct pll_ct *pll);static void aty_calc_pll_ct(const struct fb_info_aty *info, struct pll_ct *pll);static int aty_var_to_pll_ct(const struct fb_info_aty *info, u32 vclk_per, u8 bpp, struct pll_ct *pll);static u32 aty_pll_ct_to_var(const struct pll_ct *pll, const struct fb_info_aty *info);static void atyfb_set_par(const struct atyfb_par *par, struct fb_info_aty *info);static int atyfb_decode_var(const struct fb_var_screeninfo *var, struct atyfb_par *par, const struct fb_info_aty *info);static int atyfb_encode_var(struct fb_var_screeninfo *var, const struct atyfb_par *par, const struct fb_info_aty *info);static void set_off_pitch(struct atyfb_par *par, const struct fb_info_aty *info);static int encode_fix(struct fb_fix_screeninfo *fix, const struct atyfb_par *par, const struct fb_info_aty *info);static void atyfb_set_dispsw(struct display *disp, struct fb_info_aty *info, int bpp, int accel);static int atyfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue, u_int *transp, struct fb_info *fb);static int atyfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue, u_int transp, struct fb_info *fb);static void do_install_cmap(int con, struct fb_info *info);#ifdef CONFIG_PPCstatic int read_aty_sense(const struct fb_info_aty *info);#endif /* * Interface used by the world */int atyfb_init(void);#ifndef MODULEint atyfb_setup(char*);#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?