📄 r128.c
字号:
static void R128SavePLLRegisters(R128SavePtr save){ save->ppll_ref_div = INPLL(R128_PPLL_REF_DIV); save->ppll_div_3 = INPLL(R128_PPLL_DIV_3); save->htotal_cntl = INPLL(R128_HTOTAL_CNTL);}/* Read DDA registers. */static void R128SaveDDARegisters(R128SavePtr save){ save->dda_config = INREG(R128_DDA_CONFIG); save->dda_on_off = INREG(R128_DDA_ON_OFF); save->vga_dda_config = INREG(R128_VGA_DDA_CONFIG); save->vga_dda_on_off = INREG(R128_VGA_DDA_ON_OFF);}/* Read palette data. */static void R128SavePalette(R128SavePtr save){ int i; /* Select palette 0 (main CRTC) if using FP-enabled chip */// if (info->HasPanelRegs) PAL_SELECT(0); INPAL_START(0); for (i = 0; i < 256; i++) save->palette[i] = INPAL_NEXT(); save->palette_valid = 1;}/* Save state that defines current video mode. */static void R128SaveMode(R128SavePtr save){ R128SaveCommonRegisters(save); R128SaveCrtcRegisters(save);// if (R128PTR(pScrn)->HasPanelRegs)// R128SaveFPRegisters(save); R128SavePLLRegisters(save); R128SaveDDARegisters(save); R128SavePalette(save); save->dp_datatype = INREG(R128_DP_DATATYPE); save->gen_reset_cntl = INREG(R128_GEN_RESET_CNTL); save->clock_cntl_index = INREG(R128_CLOCK_CNTL_INDEX); save->amcgpio_en_reg = INREG(R128_AMCGPIO_EN_REG); save->amcgpio_mask = INREG(R128_AMCGPIO_MASK);}static void R128InitCommonRegisters(R128SavePtr save){ save->ovr_clr = 0; save->ovr_wid_left_right = 0; save->ovr_wid_top_bottom = 0; save->ov0_scale_cntl = 0; save->mpp_tb_config = 0; save->mpp_gp_config = 0; save->subpic_cntl = 0; save->viph_control = 0; save->i2c_cntl_1 = 0; save->gen_int_cntl = 0; save->cap0_trig_cntl = 0; save->cap1_trig_cntl = 0; save->mem_vga_wp_sel = 0; save->mem_vga_rp_sel = 0; save->bus_cntl = BusCntl; /* * If bursts are enabled, turn on discards and aborts */ if (save->bus_cntl & (R128_BUS_WRT_BURST|R128_BUS_READ_BURST)) save->bus_cntl |= R128_BUS_RD_DISCARD_EN | R128_BUS_RD_ABORT_EN;}/* Define CRTC registers for requested video mode. */static Bool R128InitCrtcRegisters(R128SavePtr save, ModeTiming *mode, ModeInfo *info){ int format; int hsync_start; int hsync_wid; int hsync_fudge; int vsync_wid; int bytpp; int hsync_fudge_default[] = { 0x00, 0x12, 0x09, 0x09, 0x06, 0x05 }; int hsync_fudge_fp[] = { 0x12, 0x11, 0x09, 0x09, 0x05, 0x05 }; int hsync_fudge_fp_crt[] = { 0x12, 0x10, 0x08, 0x08, 0x04, 0x04 }; int dac6bits; dac6bits=0; switch (info->bitsPerPixel) { case 4: format = 1; bytpp = 0; dac6bits = 1; break; case 8: format = 2; bytpp = 1; dac6bits = 1; break; case 16: if(info->greenWeight==5) format = 3; else format = 4; bytpp = 2; break; case 24: format = 5; bytpp = 3; break; /* RGB */ case 32: format = 6; bytpp = 4; break; /* xRGB */ default: return 0; } if (HasPanelRegs) if (CRTOnly) hsync_fudge = hsync_fudge_fp_crt[format-1]; else hsync_fudge = hsync_fudge_fp[format-1]; else hsync_fudge = hsync_fudge_default[format-1]; save->crtc_gen_cntl = (R128_CRTC_EXT_DISP_EN | R128_CRTC_EN | (format << 8) | ((mode->flags & DOUBLESCAN) ? R128_CRTC_DBL_SCAN_EN : 0) | ((mode->flags & INTERLACED) ? R128_CRTC_INTERLACE_EN : 0)); save->crtc_ext_cntl = R128_VGA_ATI_LINEAR | R128_XCRT_CNT_EN | R128_VGA_MEM_PS_EN; save->dac_cntl = (R128_DAC_MASK_ALL | R128_DAC_VGA_ADR_EN | (dac6bits ? 0 : R128_DAC_8BIT_EN)); save->crtc_h_total_disp = ((((mode->CrtcHTotal / 8) - 1) & 0xffff) | (((mode->CrtcHDisplay / 8) - 1) << 16)); hsync_wid = (mode->CrtcHSyncEnd - mode->CrtcHSyncStart) / 8; if (!hsync_wid) hsync_wid = 1; if (hsync_wid > 0x3f) hsync_wid = 0x3f; hsync_start = mode->CrtcHSyncStart - 8 + hsync_fudge; save->crtc_h_sync_strt_wid = ((hsync_start & 0xfff) | (hsync_wid << 16) | ((mode->flags & NHSYNC) ? R128_CRTC_H_SYNC_POL : 0));#if 1 /* This works for double scan mode. */ save->crtc_v_total_disp = (((mode->CrtcVTotal - 1) & 0xffff) | ((mode->CrtcVDisplay - 1) << 16));#else /* This is what cce/nbmode.c example code does -- is this correct? */ save->crtc_v_total_disp = (((mode->CrtcVTotal - 1) & 0xffff) | ((mode->CrtcVDisplay * ((mode->Flags & DOUBLESCAN) ? 2 : 1) - 1) << 16));#endif vsync_wid = mode->CrtcVSyncEnd - mode->CrtcVSyncStart; if (!vsync_wid) vsync_wid = 1; if (vsync_wid > 0x1f) vsync_wid = 0x1f; save->crtc_v_sync_strt_wid = (((mode->CrtcVSyncStart - 1) & 0xfff) | (vsync_wid << 16) | ((mode->flags & NVSYNC) ? R128_CRTC_V_SYNC_POL : 0)); save->crtc_offset = 0; save->crtc_offset_cntl = 0; save->crtc_pitch = info->width / 8; save->config_cntl |= R128_CFG_VGA_RAM_EN;#if 0 /* Change the endianness of the aperture */ switch (info->bitsPerPixel) { case 15: case 16: save->config_cntl |= APER_0_BIG_ENDIAN_16BPP_SWAP; break; case 32: save->config_cntl |= APER_0_BIG_ENDIAN_32BPP_SWAP; break; default: break; }#endif return 1;}/* Define CRTC registers for requested video mode. */static void R128InitFPRegisters(R128SavePtr orig, R128SavePtr save, ModeTiming *mode, ModeInfo *info){#if 0 int xres = mode->CrtcHDisplay; int yres = mode->CrtcVDisplay; float Hratio, Vratio; if (CRTOnly) { save->crtc_ext_cntl |= R128_CRTC_CRT_ON; save->crtc2_gen_cntl = 0; save->fp_gen_cntl = orig->fp_gen_cntl; save->fp_gen_cntl &= ~(R128_FP_FPON | R128_FP_CRTC_USE_SHADOW_VEND | R128_FP_CRTC_HORZ_DIV2_EN | R128_FP_CRTC_HOR_CRT_DIV2_DIS | R128_FP_USE_SHADOW_EN); save->fp_gen_cntl |= (R128_FP_SEL_CRTC2 | R128_FP_CRTC_DONT_SHADOW_VPAR); save->fp_panel_cntl = orig->fp_panel_cntl & ~R128_FP_DIGON; save->lvds_gen_cntl = orig->lvds_gen_cntl & ~(R128_LVDS_ON | R128_LVDS_BLON); return; } if (xres > info->PanelXRes) xres = info->PanelXRes; if (yres > info->PanelYRes) yres = info->PanelYRes; Hratio = (float)xres/(float)info->PanelXRes; Vratio = (float)yres/(float)info->PanelYRes; save->fp_horz_stretch = (((((int)(Hratio * R128_HORZ_STRETCH_RATIO_MAX + 0.5)) & R128_HORZ_STRETCH_RATIO_MASK) << R128_HORZ_STRETCH_RATIO_SHIFT) | (orig->fp_horz_stretch & (R128_HORZ_PANEL_SIZE | R128_HORZ_FP_LOOP_STRETCH | R128_HORZ_STRETCH_RESERVED))); save->fp_horz_stretch &= ~R128_HORZ_AUTO_RATIO_FIX_EN; if (Hratio == 1.0) save->fp_horz_stretch &= ~(R128_HORZ_STRETCH_BLEND | R128_HORZ_STRETCH_ENABLE); else save->fp_horz_stretch |= (R128_HORZ_STRETCH_BLEND | R128_HORZ_STRETCH_ENABLE); save->fp_vert_stretch = (((((int)(Vratio * R128_VERT_STRETCH_RATIO_MAX + 0.5)) & R128_VERT_STRETCH_RATIO_MASK) << R128_VERT_STRETCH_RATIO_SHIFT) | (orig->fp_vert_stretch & (R128_VERT_PANEL_SIZE | R128_VERT_STRETCH_RESERVED))); save->fp_vert_stretch &= ~R128_VERT_AUTO_RATIO_EN; if (Vratio == 1.0) save->fp_vert_stretch &= ~(R128_VERT_STRETCH_ENABLE | R128_VERT_STRETCH_BLEND); else save->fp_vert_stretch |= (R128_VERT_STRETCH_ENABLE | R128_VERT_STRETCH_BLEND); save->fp_gen_cntl = (orig->fp_gen_cntl & ~(R128_FP_SEL_CRTC2 | R128_FP_CRTC_USE_SHADOW_VEND | R128_FP_CRTC_HORZ_DIV2_EN | R128_FP_CRTC_HOR_CRT_DIV2_DIS | R128_FP_USE_SHADOW_EN)); if (orig->fp_gen_cntl & R128_FP_DETECT_SENSE) { save->fp_gen_cntl |= (R128_FP_CRTC_DONT_SHADOW_VPAR | R128_FP_TDMS_EN); } save->fp_panel_cntl = orig->fp_panel_cntl; save->lvds_gen_cntl = orig->lvds_gen_cntl; save->tmds_crc = orig->tmds_crc; /* Disable CRT output by disabling CRT output and setting the CRT DAC to use CRTC2, which we set to 0's. In the future, we will want to use the dual CRTC capabilities of the R128 to allow both the flat panel and external CRT to either simultaneously display the same image or display two different images. */ save->crtc_ext_cntl &= ~R128_CRTC_CRT_ON; save->dac_cntl |= R128_DAC_CRT_SEL_CRTC2; save->crtc2_gen_cntl = 0; /* WARNING: Be careful about turning on the flat panel */#if 1 save->lvds_gen_cntl |= (R128_LVDS_ON | R128_LVDS_BLON);#else save->fp_panel_cntl |= (R128_FP_DIGON | R128_FP_BLON); save->fp_gen_cntl |= (R128_FP_FPON);#endif save->fp_crtc_h_total_disp = save->crtc_h_total_disp; save->fp_crtc_v_total_disp = save->crtc_v_total_disp; save->fp_h_sync_strt_wid = save->crtc_h_sync_strt_wid; save->fp_v_sync_strt_wid = save->crtc_v_sync_strt_wid;#endif}/* Define PLL registers for requested video mode. */static void R128InitPLLRegisters(R128SavePtr save, R128PLLPtr pll, double dot_clock){ unsigned long freq = dot_clock * 100; struct { int divider; int bitvalue; } *post_div, post_divs[] = { /* From RAGE 128 VR/RAGE 128 GL Register Reference Manual (Technical Reference Manual P/N RRG-G04100-C Rev. 0.04), page 3-17 (PLL_DIV_[3:0]). */ { 1, 0 }, /* VCLK_SRC */ { 2, 1 }, /* VCLK_SRC/2 */ { 4, 2 }, /* VCLK_SRC/4 */ { 8, 3 }, /* VCLK_SRC/8 */ { 3, 4 }, /* VCLK_SRC/3 */ /* bitvalue = 5 is reserved */ { 6, 6 }, /* VCLK_SRC/6 */ { 12, 7 }, /* VCLK_SRC/12 */ { 0, 0 } }; if (freq > pll->max_pll_freq) freq = pll->max_pll_freq; if (freq * 12 < pll->min_pll_freq) freq = pll->min_pll_freq / 12; for (post_div = &post_divs[0]; post_div->divider; ++post_div) { save->pll_output_freq = post_div->divider * freq; if (save->pll_output_freq >= pll->min_pll_freq && save->pll_output_freq <= pll->max_pll_freq) break; } save->dot_clock_freq = freq; save->feedback_div = R128Div(pll->reference_div * save->pll_output_freq, pll->reference_freq); save->post_div = post_div->divider; save->ppll_ref_div = pll->reference_div; save->ppll_div_3 = (save->feedback_div | (post_div->bitvalue << 16)); save->htotal_cntl = 0;}/* Define DDA registers for requested video mode. */static Bool R128InitDDARegisters(R128SavePtr save, R128PLLPtr pll, ModeInfo *info){ int DisplayFifoWidth = 128; int DisplayFifoDepth = 32; int XclkFreq; int VclkFreq; int XclksPerTransfer; int XclksPerTransferPrecise; int UseablePrecision; int Roff; int Ron; XclkFreq = pll->xclk; VclkFreq = R128Div(pll->reference_freq * save->feedback_div, pll->reference_div * save->post_div); XclksPerTransfer = R128Div(XclkFreq * DisplayFifoWidth, VclkFreq * (info->bytesPerPixel * 8)); UseablePrecision = R128MinBits(XclksPerTransfer) + 1; XclksPerTransferPrecise = R128Div((XclkFreq * DisplayFifoWidth) << (11 - UseablePrecision), VclkFreq * (info->bytesPerPixel * 8)); Roff = XclksPerTransferPrecise * (DisplayFifoDepth - 4); Ron = (4 * ram[r128_ramtype].MB + 3 * (((ram[r128_ramtype].Trcd - 2)>0)?(ram[r128_ramtype].Trcd - 2):0) + 2 * ram[r128_ramtype].Trp + ram[r128_ramtype].Twr + ram[r128_ramtype].CL + ram[r128_ramtype].Tr2w + XclksPerTransfer) << (11 - UseablePrecision); if (Ron + ram[r128_ramtype].Rloop >= Roff) { return 0; } save->dda_config = (XclksPerTransferPrecise | (UseablePrecision << 16) | (ram[r128_ramtype].Rloop << 20)); save->dda_on_off = (Ron << 16) | Roff; return 1;}/* Define initial palette for requested video mode. This doesn't do anything for XFree86 4.0. */static void R128InitPalette(R128SavePtr save){ int i; save->palette_valid = 1; for(i=0;i<256;i++) save->palette[i]=i | (i<<8) | (i<<16);}/* Define registers for a requested video mode. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -