📄 radeonfb.c
字号:
v.red.length = v.green.length = v.blue.length = 5; v.transp.offset = v.transp.length = 0; break; case 16: nom = 2; den = 1; disp->line_length = v.xres_virtual * 2; disp->visual = FB_VISUAL_DIRECTCOLOR; v.red.offset = 11; v.green.offset = 5; v.blue.offset = 0; v.red.length = 5; v.green.length = 6; v.blue.length = 5; v.transp.offset = v.transp.length = 0; break; #endif #ifdef FBCON_HAS_CFB24 case 24: nom = 4; den = 1; disp->line_length = v.xres_virtual * 3; disp->visual = FB_VISUAL_DIRECTCOLOR; v.red.offset = 16; v.green.offset = 8; v.blue.offset = 0; v.red.length = v.blue.length = v.green.length = 8; v.transp.offset = v.transp.length = 0; break;#endif#ifdef FBCON_HAS_CFB32 case 32: nom = 4; den = 1; disp->line_length = v.xres_virtual * 4; disp->visual = FB_VISUAL_DIRECTCOLOR; v.red.offset = 16; v.green.offset = 8; v.blue.offset = 0; v.red.length = v.blue.length = v.green.length = 8; v.transp.offset = 24; v.transp.length = 8; break;#endif default: printk ("radeonfb: mode %dx%dx%d rejected, color depth invalid\n", var->xres, var->yres, var->bits_per_pixel); return -EINVAL; } if (radeonfb_do_maximize(rinfo, var, &v, nom, den) < 0) return -EINVAL; if (v.xoffset < 0) v.xoffset = 0; if (v.yoffset < 0) v.yoffset = 0; if (v.xoffset > v.xres_virtual - v.xres) v.xoffset = v.xres_virtual - v.xres - 1; if (v.yoffset > v.yres_virtual - v.yres) v.yoffset = v.yres_virtual - v.yres - 1; v.red.msb_right = v.green.msb_right = v.blue.msb_right = v.transp.offset = v.transp.length = v.transp.msb_right = 0; switch (v.activate & FB_ACTIVATE_MASK) { case FB_ACTIVATE_TEST: return 0; case FB_ACTIVATE_NXTOPEN: case FB_ACTIVATE_NOW: break; default: return -EINVAL; } memcpy (&disp->var, &v, sizeof (v)); if (chgvar) { radeon_set_dispsw(rinfo, disp); if (noaccel) disp->scrollmode = SCROLL_YREDRAW; else disp->scrollmode = 0; if (info && info->changevar) info->changevar(con); } radeon_load_video_mode (rinfo, &v); do_install_cmap(con, info); return 0;}static int radeonfb_get_cmap (struct fb_cmap *cmap, int kspc, int con, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; struct display *disp; disp = (con < 0) ? rinfo->info.disp : &fb_display[con]; if (con == rinfo->currcon) { int rc = fb_get_cmap (cmap, kspc, radeon_getcolreg, info); return rc; } else if (disp->cmap.len) fb_copy_cmap (&disp->cmap, cmap, kspc ? 0 : 2); else fb_copy_cmap (fb_default_cmap (radeon_get_cmap_len (&disp->var)), cmap, kspc ? 0 : 2); return 0;}static int radeonfb_set_cmap (struct fb_cmap *cmap, int kspc, int con, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; struct display *disp; unsigned int cmap_len; disp = (con < 0) ? rinfo->info.disp : &fb_display[con]; cmap_len = radeon_get_cmap_len (&disp->var); if (disp->cmap.len != cmap_len) { int err = fb_alloc_cmap (&disp->cmap, cmap_len, 0); if (err) return err; } if (con == rinfo->currcon) { int rc = fb_set_cmap (cmap, kspc, radeon_setcolreg, info); return rc; } else fb_copy_cmap (cmap, &disp->cmap, kspc ? 0 : 1); return 0;} static int radeonfb_pan_display (struct fb_var_screeninfo *var, int con, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; u32 offset, xoffset, yoffset; xoffset = (var->xoffset + 7) & ~7; yoffset = var->yoffset; if ((xoffset + var->xres > var->xres_virtual) || (yoffset+var->yres > var->yres_virtual)) return -EINVAL; offset = ((yoffset * var->xres + xoffset) * var->bits_per_pixel) >> 6; OUTREG(CRTC_OFFSET, offset); return 0;}static int radeonfb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg, int con, struct fb_info *info){ return -EINVAL;}static int radeonfb_switch (int con, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; struct display *disp; struct fb_cmap *cmap; int switchmode = 0; disp = (con < 0) ? rinfo->info.disp : &fb_display[con]; if (rinfo->currcon >= 0) { cmap = &(rinfo->currcon_display->cmap); if (cmap->len) fb_get_cmap (cmap, 1, radeon_getcolreg, info); } switchmode = (con != rinfo->currcon); rinfo->currcon = con; rinfo->currcon_display = disp; disp->var.activate = FB_ACTIVATE_NOW; if (switchmode) { radeonfb_set_var (&disp->var, con, info); radeon_set_dispsw (rinfo, disp); do_install_cmap(con, info); } /* XXX absurd hack for X to restore console */ { OUTREGP(CRTC_EXT_CNTL, rinfo->hack_crtc_ext_cntl, CRTC_HSYNC_DIS | CRTC_VSYNC_DIS | CRTC_DISPLAY_DIS); OUTREG(CRTC_V_SYNC_STRT_WID, rinfo->hack_crtc_v_sync_strt_wid); } return 0;}static int radeonfb_updatevar (int con, struct fb_info *info){ int rc; rc = (con < 0) ? -EINVAL : radeonfb_pan_display (&fb_display[con].var, con, info); return rc;}static void radeonfb_blank (int blank, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; u32 val = INREG(CRTC_EXT_CNTL); u32 val2 = INREG(LVDS_GEN_CNTL);#ifdef CONFIG_PMAC_BACKLIGHT if (rinfo->dviDisp_type == MT_LCD && _machine == _MACH_Pmac) { set_backlight_enable(!blank); return; }#endif /* reset it */ val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS | CRTC_VSYNC_DIS); val2 &= ~(LVDS_DISPLAY_DIS); switch (blank) { case VESA_NO_BLANKING: break; case VESA_VSYNC_SUSPEND: val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS); break; case VESA_HSYNC_SUSPEND: val |= (CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS); break; case VESA_POWERDOWN: val |= (CRTC_DISPLAY_DIS | CRTC_VSYNC_DIS | CRTC_HSYNC_DIS); val2 |= (LVDS_DISPLAY_DIS); break; } switch (rinfo->dviDisp_type) { case MT_LCD: OUTREG(LVDS_GEN_CNTL, val2); break; case MT_CRT: default: OUTREG(CRTC_EXT_CNTL, val); break; }}static int radeon_get_cmap_len (const struct fb_var_screeninfo *var){ int rc = 256; /* reasonable default */ switch (var_to_depth(var)) { case 15: rc = 32; break; case 16: rc = 64; break; } return rc;}static int radeon_getcolreg (unsigned regno, unsigned *red, unsigned *green, unsigned *blue, unsigned *transp, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; if (regno > 255) return 1; *red = (rinfo->palette[regno].red<<8) | rinfo->palette[regno].red; *green = (rinfo->palette[regno].green<<8) | rinfo->palette[regno].green; *blue = (rinfo->palette[regno].blue<<8) | rinfo->palette[regno].blue; *transp = 0; return 0;} static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green, unsigned blue, unsigned transp, struct fb_info *info){ struct radeonfb_info *rinfo = (struct radeonfb_info *) info; u32 pindex; if (regno > 255) return 1; red >>= 8; green >>= 8; blue >>= 8; rinfo->palette[regno].red = red; rinfo->palette[regno].green = green; rinfo->palette[regno].blue = blue; /* default */ pindex = regno; if (rinfo->bpp == 16) { pindex = regno * 8; if (rinfo->depth == 16 && regno > 63) return 1; if (rinfo->depth == 15 && regno > 31) return 1; /* For 565, the green component is mixed one order below */ if (rinfo->depth == 16) { OUTREG(PALETTE_INDEX, pindex>>1); OUTREG(PALETTE_DATA, (rinfo->palette[regno>>1].red << 16) | (green << 8) | (rinfo->palette[regno>>1].blue)); green = rinfo->palette[regno<<1].green; } } if (rinfo->depth != 16 || regno < 32) { OUTREG(PALETTE_INDEX, pindex); OUTREG(PALETTE_DATA, (red << 16) | (green << 8) | blue); } if (regno < 16) { switch (rinfo->depth) {#ifdef FBCON_HAS_CFB16 case 15: rinfo->con_cmap.cfb16[regno] = (regno << 10) | (regno << 5) | regno; break; case 16: rinfo->con_cmap.cfb16[regno] = (regno << 11) | (regno << 5) | regno; break;#endif#ifdef FBCON_HAS_CFB24 case 24: rinfo->con_cmap.cfb24[regno] = (regno << 16) | (regno << 8) | regno; break;#endif#ifdef FBCON_HAS_CFB32 case 32: { u32 i; i = (regno << 8) | regno; rinfo->con_cmap.cfb32[regno] = (i << 16) | i; break; }#endif } } return 0;}static void radeon_save_state (struct radeonfb_info *rinfo, struct radeon_regs *save){ /* CRTC regs */ save->crtc_gen_cntl = INREG(CRTC_GEN_CNTL); save->crtc_ext_cntl = INREG(CRTC_EXT_CNTL); save->dac_cntl = INREG(DAC_CNTL); save->crtc_h_total_disp = INREG(CRTC_H_TOTAL_DISP); save->crtc_h_sync_strt_wid = INREG(CRTC_H_SYNC_STRT_WID); save->crtc_v_total_disp = INREG(CRTC_V_TOTAL_DISP); save->crtc_v_sync_strt_wid = INREG(CRTC_V_SYNC_STRT_WID); save->crtc_pitch = INREG(CRTC_PITCH);#if defined(__BIG_ENDIAN) save->surface_cntl = INREG(SURFACE_CNTL);#endif /* FP regs */ save->fp_crtc_h_total_disp = INREG(FP_CRTC_H_TOTAL_DISP); save->fp_crtc_v_total_disp = INREG(FP_CRTC_V_TOTAL_DISP); save->fp_gen_cntl = INREG(FP_GEN_CNTL); save->fp_h_sync_strt_wid = INREG(FP_H_SYNC_STRT_WID); save->fp_horz_stretch = INREG(FP_HORZ_STRETCH); save->fp_v_sync_strt_wid = INREG(FP_V_SYNC_STRT_WID); save->fp_vert_stretch = INREG(FP_VERT_STRETCH); save->lvds_gen_cntl = INREG(LVDS_GEN_CNTL); save->lvds_pll_cntl = INREG(LVDS_PLL_CNTL); save->tmds_crc = INREG(TMDS_CRC); save->tmds_transmitter_cntl = INREG(TMDS_TRANSMITTER_CNTL);}static void radeon_load_video_mode (struct radeonfb_info *rinfo, struct fb_var_screeninfo *mode){ struct radeon_regs newmode; int hTotal, vTotal, hSyncStart, hSyncEnd, hSyncPol, vSyncStart, vSyncEnd, vSyncPol, cSync; u8 hsync_adj_tab[] = {0, 0x12, 9, 9, 6, 5}; u8 hsync_fudge_fp[] = {2, 2, 0, 0, 5, 5}; u32 dotClock = 1000000000 / mode->pixclock, sync, h_sync_pol, v_sync_pol; int freq = dotClock / 10; /* x 100 */ int xclk_freq, vclk_freq, xclk_per_trans, xclk_per_trans_precise; int useable_precision, roff, ron; int min_bits, format = 0; int hsync_start, hsync_fudge, bytpp, hsync_wid, vsync_wid; int primary_mon = PRIMARY_MONITOR(rinfo); int depth = var_to_depth(mode); rinfo->xres = mode->xres; rinfo->yres = mode->yres; rinfo->pixclock = mode->pixclock; hSyncStart = mode->xres + mode->right_margin; hSyncEnd = hSyncStart + mode->hsync_len; hTotal = hSyncEnd + mode->left_margin; vSyncStart = mode->yres + mode->lower_margin; vSyncEnd = vSyncStart + mode->vsync_len; vTotal = vSyncEnd + mode->upper_margin; if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) { if (rinfo->panel_xres < mode->xres) rinfo->xres = mode->xres = rinfo->panel_xres; if (rinfo->panel_yres < mode->yres) rinfo->yres = mode->yres = rinfo->panel_yres; hTotal = mode->xres + rinfo->hblank; hSyncStart = mode->xres + rinfo->hOver_plus; hSyncEnd = hSyncStart + rinfo->hSync_width; vTotal = mode->yres + rinfo->vblank; vSyncStart = mode->yres + rinfo->vOver_plus; vSyncEnd = vSyncStart + rinfo->vSync_width; } sync = mode->sync; h_sync_pol = sync & FB_SYNC_HOR_HIGH_ACT ? 0 : 1; v_sync_pol = sync & FB_SYNC_VERT_HIGH_ACT ? 0 : 1; RTRACE("hStart = %d, hEnd = %d, hTotal = %d\n", hSyncStart, hSyncEnd, hTotal); RTRACE("vStart = %d, vEnd = %d, vTotal = %d\n", vSyncStart, vSyncEnd, vTotal); hsync_wid = (hSyncEnd - hSyncStart) / 8; vsync_wid = vSyncEnd - vSyncStart; if (hsync_wid == 0) hsync_wid = 1; else if (hsync_wid > 0x3f) /* max */ hsync_wid = 0x3f; if (vsync_wid == 0) vsync_wid = 1; else if (vsync_wid > 0x1f) /* max */ vsync_wid = 0x1f;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -