⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aty128fb.c

📁 S3C44B0X下的LCD (framebuffer)驱动资料与相关代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $Id: aty128fb.c,v 1.1.1.1.36.1 1999/12/11 09:03:05 Exp $ *  linux/drivers/video/aty128fb.c -- Frame buffer device for ATI Rage128 * *  Copyright (C) 1999-2000, Brad Douglas <brad@neruo.com> *  Copyright (C) 1999, Anthony Tong <atong@uiuc.edu> * *                Ani Joshi / Jeff Garzik *                      - Code cleanup * *                Michel D鋘zer <michdaen@iiic.ethz.ch> *                      - 15/16 bit cleanup *                      - fix panning *                       *                Benjamin Herrenschmidt *                      - pmac-specific PM stuff * *                Andreas Hundt <andi@convergence.de> *                      - FB_ACTIVATE fixes * *  Based off of Geert's atyfb.c and vfb.c. * *  TODO: *		- monitor sensing (DDC) *              - virtual display *		- other platform support (only ppc/x86 supported) *		- hardware cursor support *		- ioctl()'s * *    Please cc: your patches to brad@neruo.com. *//* * A special note of gratitude to ATI's devrel for providing documentation, * example code and hardware. Thanks Nitya.	-atong and brad */#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/vmalloc.h>#include <linux/delay.h>#include <linux/interrupt.h>#include <asm/uaccess.h>#include <linux/fb.h>#include <linux/init.h>#include <linux/selection.h>#include <linux/console.h>#include <linux/pci.h>#include <linux/ioport.h>#include <asm/io.h>#ifdef CONFIG_PPC#include <asm/prom.h>#include <asm/pci-bridge.h>#include <video/macmodes.h>#ifdef CONFIG_NVRAM#include <linux/nvram.h>#endif#endif#ifdef CONFIG_ADB_PMU#include <linux/adb.h>#include <linux/pmu.h>#endif#ifdef CONFIG_PMAC_BACKLIGHT#include <asm/backlight.h>#endif#ifdef CONFIG_FB_COMPAT_XPMAC#include <asm/vc_ioctl.h>#endif#ifdef CONFIG_BOOTX_TEXT#include <asm/btext.h>#endif /* CONFIG_BOOTX_TEXT */#include <video/fbcon.h>#include <video/fbcon-cfb8.h>#include <video/fbcon-cfb16.h>#include <video/fbcon-cfb24.h>#include <video/fbcon-cfb32.h>#ifdef CONFIG_MTRR#include <asm/mtrr.h>#endif#include "aty128.h"/* Debug flag */#undef DEBUG#ifdef DEBUG#define DBG(fmt, args...)		printk(KERN_DEBUG "aty128fb: %s " fmt, __FUNCTION__, ##args);#else#define DBG(fmt, args...)#endif#ifndef CONFIG_PPC/* default mode */static struct fb_var_screeninfo default_var __initdata = {    /* 640x480, 60 Hz, Non-Interlaced (25.175 MHz dotclock) */    640, 480, 640, 480, 0, 0, 8, 0,    {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},    0, 0, -1, -1, 0, 39722, 48, 16, 33, 10, 96, 2,    0, FB_VMODE_NONINTERLACED};#else /* CONFIG_PPC *//* default to 1024x768 at 75Hz on PPC - this will work * on the iMac, the usual 640x480 @ 60Hz doesn't. */static struct fb_var_screeninfo default_var = {    /* 1024x768, 75 Hz, Non-Interlaced (78.75 MHz dotclock) */    1024, 768, 1024, 768, 0, 0, 8, 0,    {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},    0, 0, -1, -1, 0, 12699, 160, 32, 28, 1, 96, 3,    FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED};#endif /* CONFIG_PPC *//* default modedb mode *//* 640x480, 60 Hz, Non-Interlaced (25.172 MHz dotclock) */static struct fb_videomode defaultmode __initdata = {	refresh:	60,	xres:		640,	yres:		480,	pixclock:	39722,	left_margin:	48,	right_margin:	16,	upper_margin:	33,	lower_margin:	10,	hsync_len:	96,	vsync_len:	2,	sync:		0,	vmode:		FB_VMODE_NONINTERLACED};/* struct to hold chip description information */struct aty128_chip_info {    const char *name;    unsigned short device;    int chip_gen;};/* Chip generations */enum {	rage_128,	rage_128_pro,	rage_M3};/* supported Rage128 chipsets */static struct aty128_chip_info aty128_pci_probe_list[] __initdata ={    {"Rage128 RE (PCI)", PCI_DEVICE_ID_ATI_RAGE128_RE, rage_128},    {"Rage128 RF (AGP)", PCI_DEVICE_ID_ATI_RAGE128_RF, rage_128},    {"Rage128 RK (PCI)", PCI_DEVICE_ID_ATI_RAGE128_RK, rage_128},    {"Rage128 RL (AGP)", PCI_DEVICE_ID_ATI_RAGE128_RL, rage_128},    {"Rage128 Pro PF (AGP)", PCI_DEVICE_ID_ATI_RAGE128_PF, rage_128_pro},    {"Rage128 Pro PR (PCI)", PCI_DEVICE_ID_ATI_RAGE128_PR, rage_128_pro},    {"Rage128 Pro TR (AGP)", PCI_DEVICE_ID_ATI_RAGE128_U3, rage_128_pro},    {"Rage128 Pro TF (AGP)", PCI_DEVICE_ID_ATI_RAGE128_U1, rage_128_pro},    {"Rage Mobility M3 (PCI)", PCI_DEVICE_ID_ATI_RAGE128_LE, rage_M3},    {"Rage Mobility M3 (AGP)", PCI_DEVICE_ID_ATI_RAGE128_LF, rage_M3},    {NULL, 0, rage_128} };/* packed BIOS settings */#ifndef CONFIG_PPCtypedef struct {	u8 clock_chip_type;	u8 struct_size;	u8 accelerator_entry;	u8 VGA_entry;	u16 VGA_table_offset;	u16 POST_table_offset;	u16 XCLK;	u16 MCLK;	u8 num_PLL_blocks;	u8 size_PLL_blocks;	u16 PCLK_ref_freq;	u16 PCLK_ref_divider;	u32 PCLK_min_freq;	u32 PCLK_max_freq;	u16 MCLK_ref_freq;	u16 MCLK_ref_divider;	u32 MCLK_min_freq;	u32 MCLK_max_freq;	u16 XCLK_ref_freq;	u16 XCLK_ref_divider;	u32 XCLK_min_freq;	u32 XCLK_max_freq;} __attribute__ ((packed)) PLL_BLOCK;#endif /* !CONFIG_PPC *//* onboard memory information */struct aty128_meminfo {    u8 ML;    u8 MB;    u8 Trcd;    u8 Trp;    u8 Twr;    u8 CL;    u8 Tr2w;    u8 LoopLatency;    u8 DspOn;    u8 Rloop;    const char *name;};/* various memory configurations */static const struct aty128_meminfo sdr_128   =    { 4, 4, 3, 3, 1, 3, 1, 16, 30, 16, "128-bit SDR SGRAM (1:1)" };static const struct aty128_meminfo sdr_64    =    { 4, 8, 3, 3, 1, 3, 1, 17, 46, 17, "64-bit SDR SGRAM (1:1)" };static const struct aty128_meminfo sdr_sgram =    { 4, 4, 1, 2, 1, 2, 1, 16, 24, 16, "64-bit SDR SGRAM (2:1)" };static const struct aty128_meminfo ddr_sgram =    { 4, 4, 3, 3, 2, 3, 1, 16, 31, 16, "64-bit DDR SGRAM" };static const char *aty128fb_name = "ATY Rage128";static char fontname[40] __initdata = { 0 };static int  noaccel __initdata = 0;static char *font __initdata = NULL;static char *mode __initdata = NULL;static int  nomtrr __initdata = 0;static char *mode_option __initdata = NULL;#ifdef CONFIG_PPCstatic int default_vmode __initdata = VMODE_1024_768_60;static int default_cmode __initdata = CMODE_8;#endif#ifdef CONFIG_PMAC_PBOOKstatic int default_crt_on __initdata = 0;static int default_lcd_on __initdata = 1;#endif#ifdef CONFIG_MTRRstatic int mtrr = 1;#endif/* PLL constants */struct aty128_constants {    u32 dotclock;    u32 ppll_min;    u32 ppll_max;    u32 ref_divider;    u32 xclk;    u32 fifo_width;    u32 fifo_depth;};struct aty128_crtc {    u32 gen_cntl;    u32 ext_cntl;    u32 h_total, h_sync_strt_wid;    u32 v_total, v_sync_strt_wid;    u32 pitch;    u32 offset, offset_cntl;    u32 xoffset, yoffset;    u32 vxres, vyres;    u32 depth, bpp;};struct aty128_pll {    u32 post_divider;    u32 feedback_divider;    u32 vclk;};struct aty128_ddafifo {    u32 dda_config;    u32 dda_on_off;};/* register values for a specific mode */struct aty128fb_par {    struct aty128_crtc crtc;    struct aty128_pll pll;    struct aty128_ddafifo fifo_reg;    u32 accel_flags;};struct fb_info_aty128 {    struct fb_info fb_info;    struct fb_info_aty128 *next;    struct aty128_constants constants;  /* PLL and others      */    unsigned long regbase_phys;         /* physical mmio       */    void *regbase;                      /* remapped mmio       */    unsigned long frame_buffer_phys;    /* physical fb memory  */    void *frame_buffer;                 /* remaped framebuffer */    u32 vram_size;                      /* onboard video ram   */    int chip_gen;    const struct aty128_meminfo *mem;   /* onboard mem info    */    struct aty128fb_par default_par, current_par;    struct display disp;    struct { u8 red, green, blue, pad; } palette[256];    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;#ifdef CONFIG_PCI    struct pci_dev *pdev;#endif#ifdef CONFIG_MTRR    struct { int vram; int vram_valid; } mtrr;#endif    int currcon;    int blitter_may_be_busy;    int fifo_slots;                 /* free slots in FIFO (64 max) */#ifdef CONFIG_PMAC_PBOOK    unsigned char *save_framebuffer;    int	pm_reg;    int crt_on, lcd_on;    u32 save_lcd_gen_cntl;#endif};static struct fb_info_aty128 *board_list = NULL;#ifdef CONFIG_PMAC_PBOOK  int aty128_sleep_notify(struct pmu_sleep_notifier *self, int when);  static struct pmu_sleep_notifier aty128_sleep_notifier = {  	aty128_sleep_notify, SLEEP_LEVEL_VIDEO,  };#endif#define round_div(n, d) ((n+(d/2))/d)    /*     *  Interface used by the world     */int aty128fb_setup(char *options);static int aty128fb_get_fix(struct fb_fix_screeninfo *fix, int con,		       struct fb_info *info);static int aty128fb_get_var(struct fb_var_screeninfo *var, int con,		       struct fb_info *info);static int aty128fb_set_var(struct fb_var_screeninfo *var, int con,		       struct fb_info *info);static int aty128fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,			struct fb_info *info);static int aty128fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,			struct fb_info *info);static int aty128fb_pan_display(struct fb_var_screeninfo *var, int con,			   struct fb_info *fb);static int aty128fb_ioctl(struct inode *inode, struct file *file, u_int cmd,		       u_long arg, int con, struct fb_info *info);static int aty128fb_rasterimg(struct fb_info *info, int start);    /*     *  Interface to the low level console driver     */int aty128fb_init(void);static int aty128fbcon_switch(int con, struct fb_info *fb);static void aty128fbcon_blank(int blank, struct fb_info *fb);    /*     *  Internal routines     */static void aty128_encode_fix(struct fb_fix_screeninfo *fix,				struct aty128fb_par *par,				const struct fb_info_aty128 *info);static void aty128_set_dispsw(struct display *disp,			struct fb_info_aty128 *info, int bpp, int accel);static int aty128_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,				u_int *transp, struct fb_info *info);static int aty128_setcolreg(u_int regno, u_int red, u_int green, u_int blue,				u_int transp, struct fb_info *info);static void do_install_cmap(int con, struct fb_info *info);static int aty128_encode_var(struct fb_var_screeninfo *var,                             const struct aty128fb_par *par,                             const struct fb_info_aty128 *info);static int aty128_decode_var(struct fb_var_screeninfo *var,                             struct aty128fb_par *par,                             const struct fb_info_aty128 *info);static int aty128_pci_register(struct pci_dev *pdev,                               const struct aty128_chip_info *aci);static struct fb_info_aty128 *aty128_board_list_add(struct fb_info_aty128				*board_list, struct fb_info_aty128 *new_node);#if !defined(CONFIG_PPC) && !defined(__sparc__)static void __init aty128_get_pllinfo(struct fb_info_aty128 *info,			char *bios_seg);static char __init *aty128find_ROM(struct fb_info_aty128 *info);#endifstatic void aty128_timings(struct fb_info_aty128 *info);static void aty128_init_engine(const struct aty128fb_par *par, 				struct fb_info_aty128 *info);static void aty128_reset_engine(const struct fb_info_aty128 *info);static void aty128_flush_pixel_cache(const struct fb_info_aty128 *info);static void do_wait_for_fifo(u16 entries, struct fb_info_aty128 *info);static void wait_for_fifo(u16 entries, struct fb_info_aty128 *info);static void wait_for_idle(struct fb_info_aty128 *info);static u32 depth_to_dst(u32 depth);#ifdef FBCON_HAS_CFB8static struct display_switch fbcon_aty128_8;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_aty128_16;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_aty128_24;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_aty128_32;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);#endifstatic struct fb_ops aty128fb_ops = {	owner:		THIS_MODULE,	fb_get_fix:	aty128fb_get_fix,	fb_get_var:	aty128fb_get_var,	fb_set_var:	aty128fb_set_var,	fb_get_cmap:	aty128fb_get_cmap,	fb_set_cmap:	aty128fb_set_cmap,	fb_pan_display:	aty128fb_pan_display,	fb_ioctl:	aty128fb_ioctl,	fb_rasterimg:	aty128fb_rasterimg,};#ifdef CONFIG_PMAC_BACKLIGHTstatic int aty128_set_backlight_enable(int on, int level, void* data);static int aty128_set_backlight_level(int level, void* data);static struct backlight_controller aty128_backlight_controller = {	aty128_set_backlight_enable,	aty128_set_backlight_level};#endif /* CONFIG_PMAC_BACKLIGHT */    /*     * Functions to read from/write to the mmio registers     *	- endian conversions may possibly be avoided by     *    using the other register aperture. TODO.     */static inline u32_aty_ld_le32(volatile unsigned int regindex,                               const struct fb_info_aty128 *info){    u32 val;#if defined(__powerpc__)    asm("lwbrx %0,%1,%2;eieio" : "=r"(val) : "b"(regindex), "r"(info->regbase));#else    val = readl (info->regbase + regindex);#endif    return val;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -