static DisplayModePtr fbdev_lcd_output_get_modes(xf86OutputPtr output) { MaliPtr fPtr = MALIPTR(output->scrn); DisplayModePtr mode_ptr; unsigned int hactive_s = fPtr->fb_lcd_var.xres; unsigned int vactive_s = fPtr->fb_lcd_var.yres; mode_ptr = xnfcalloc(1, sizeof(DisplayModeRec)); mode_ptr->HDisplay = hactive_s; mode_ptr->HSyncStart = hactive_s + 20; mode_ptr->HSyncEnd = hactive_s + 40; mode_ptr->HTotal = hactive_s + 80; mode_ptr->VDisplay = vactive_s; mode_ptr->VSyncStart = vactive_s + 20; mode_ptr->VSyncEnd = vactive_s + 40; mode_ptr->VTotal = vactive_s + 80; mode_ptr->VRefresh = 60.0; mode_ptr->Clock = (int) (mode_ptr->VRefresh * mode_ptr->VTotal * mode_ptr->HTotal / 1000.0); mode_ptr->type = M_T_DRIVER; xf86SetModeDefaultName(mode_ptr); mode_ptr->next = NULL; mode_ptr->prev = NULL; return mode_ptr; }
static DisplayModePtr screen_create_mode (ScrnInfoPtr pScrn, int width, int height, int type) { DisplayModePtr mode; mode = xnfcalloc (1, sizeof (DisplayModeRec)); mode->status = MODE_OK; mode->type = type; mode->HDisplay = width; mode->HSyncStart = (width * 105 / 100 + 7) & ~7; mode->HSyncEnd = (width * 115 / 100 + 7) & ~7; mode->HTotal = (width * 130 / 100 + 7) & ~7; mode->VDisplay = height; mode->VSyncStart = height + 1; mode->VSyncEnd = height + 4; mode->VTotal = height * 1035 / 1000; mode->Clock = mode->HTotal * mode->VTotal * 60 / 1000; mode->Flags = V_NHSYNC | V_PVSYNC; xf86SetModeDefaultName (mode); xf86SetModeCrtc (mode, pScrn->adjustFlags); /* needed? xf86-video-modesetting does this */ return mode; }
static Bool crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, int x, int y) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); modesettingPtr ms = modesettingPTR(crtc->scrn); xf86OutputPtr output = NULL; struct crtc_private *crtcp = crtc->driver_private; drmModeCrtcPtr drm_crtc = crtcp->drm_crtc; drmModeModeInfo drm_mode; int i, ret; unsigned int connector_id; for (i = 0; i < config->num_output; output = NULL, i++) { output = config->output[i]; if (output->crtc == crtc) break; } if (!output) return FALSE; connector_id = xorg_output_get_id(output); drm_mode.clock = mode->Clock; drm_mode.hdisplay = mode->HDisplay; drm_mode.hsync_start = mode->HSyncStart; drm_mode.hsync_end = mode->HSyncEnd; drm_mode.htotal = mode->HTotal; drm_mode.vdisplay = mode->VDisplay; drm_mode.vsync_start = mode->VSyncStart; drm_mode.vsync_end = mode->VSyncEnd; drm_mode.vtotal = mode->VTotal; drm_mode.flags = mode->Flags; drm_mode.hskew = mode->HSkew; drm_mode.vscan = mode->VScan; drm_mode.vrefresh = mode->VRefresh; if (!mode->name) xf86SetModeDefaultName(mode); strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN - 1); drm_mode.name[DRM_DISPLAY_MODE_LEN - 1] = '\0'; ret = drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, ms->fb_id, x, y, &connector_id, 1, &drm_mode); if (ret) return FALSE; crtc->x = x; crtc->y = y; crtc->mode = *mode; crtc->rotation = rotation; return TRUE; }
static DisplayModePtr output_get_modes(xf86OutputPtr output) { drmModeConnectorPtr drm_connector = output->driver_private; drmModeModeInfoPtr drm_mode = NULL; DisplayModePtr modes = NULL, mode = NULL; int i; for (i = 0; i < drm_connector->count_modes; i++) { drm_mode = &drm_connector->modes[i]; if (drm_mode) { mode = xcalloc(1, sizeof(DisplayModeRec)); if (!mode) continue; mode->Clock = drm_mode->clock; mode->HDisplay = drm_mode->hdisplay; mode->HSyncStart = drm_mode->hsync_start; mode->HSyncEnd = drm_mode->hsync_end; mode->HTotal = drm_mode->htotal; mode->VDisplay = drm_mode->vdisplay; mode->VSyncStart = drm_mode->vsync_start; mode->VSyncEnd = drm_mode->vsync_end; mode->VTotal = drm_mode->vtotal; mode->Flags = drm_mode->flags; mode->HSkew = drm_mode->hskew; mode->VScan = drm_mode->vscan; mode->VRefresh = xf86ModeVRefresh(mode); mode->Private = (void *)drm_mode; mode->type = 0; if (drm_mode->type & DRM_MODE_TYPE_PREFERRED) mode->type |= M_T_PREFERRED; if (drm_mode->type & DRM_MODE_TYPE_DRIVER) mode->type |= M_T_DRIVER; xf86SetModeDefaultName(mode); modes = xf86ModesAdd(modes, mode); xf86PrintModeline(0, mode); } } return modes; }
static DisplayModePtr ReadLVDSNativeMode(G80Ptr pNv, const int off) { DisplayModePtr mode = xnfcalloc(1, sizeof(DisplayModeRec)); const CARD32 size = pNv->reg[(0x00610B4C+off)/4]; const int width = size & 0x3fff; const int height = (size >> 16) & 0x3fff; mode->HDisplay = mode->CrtcHDisplay = width; mode->VDisplay = mode->CrtcVDisplay = height; mode->Clock = pNv->reg[(0x610AD4+off)/4] & 0x3fffff; mode->CrtcHBlankStart = pNv->reg[(0x610AFC+off)/4]; mode->CrtcHSyncEnd = pNv->reg[(0x610B04+off)/4]; mode->CrtcHBlankEnd = pNv->reg[(0x610AE8+off)/4]; mode->CrtcHTotal = pNv->reg[(0x610AF4+off)/4]; mode->next = mode->prev = NULL; mode->status = MODE_OK; mode->type = M_T_DRIVER | M_T_PREFERRED; xf86SetModeDefaultName(mode); return mode; }
static DisplayModePtr output_get_modes(xf86OutputPtr output) { struct output_private *priv = output->driver_private; drmModeConnectorPtr drm_connector = priv->drm_connector; drmModeModeInfoPtr drm_mode = NULL; drmModePropertyPtr props = NULL; xf86MonPtr ddc_mon = NULL; DisplayModePtr modes = NULL, mode = NULL; int i; for (i = 0; i < drm_connector->count_props; i++) { props = drmModeGetProperty(priv->fd, drm_connector->props[i]); if (!props) continue; if (!(props->flags & DRM_MODE_PROP_BLOB)) goto out_free; if (!strcmp(props->name, "EDID")) { if (priv->edid_blob) drmModeFreePropertyBlob(priv->edid_blob); priv->edid_blob = drmModeGetPropertyBlob(priv->fd, drm_connector->prop_values[i]); } out_free: drmModeFreeProperty(props); } if (priv->edid_blob) { ddc_mon = xf86InterpretEDID(output->scrn->scrnIndex, priv->edid_blob->data); if (ddc_mon && priv->edid_blob->length > 128) ddc_mon->flags |= MONITOR_EDID_COMPLETE_RAWDATA; } xf86OutputSetEDID(output, ddc_mon); for (i = 0; i < drm_connector->count_modes; i++) { drm_mode = &drm_connector->modes[i]; if (drm_mode) { mode = calloc(1, sizeof(DisplayModeRec)); if (!mode) continue; mode->Clock = drm_mode->clock; mode->HDisplay = drm_mode->hdisplay; mode->HSyncStart = drm_mode->hsync_start; mode->HSyncEnd = drm_mode->hsync_end; mode->HTotal = drm_mode->htotal; mode->VDisplay = drm_mode->vdisplay; mode->VSyncStart = drm_mode->vsync_start; mode->VSyncEnd = drm_mode->vsync_end; mode->VTotal = drm_mode->vtotal; mode->Flags = drm_mode->flags; mode->HSkew = drm_mode->hskew; mode->VScan = drm_mode->vscan; mode->VRefresh = xf86ModeVRefresh(mode); mode->Private = (void *)drm_mode; mode->type = 0; if (drm_mode->type & DRM_MODE_TYPE_PREFERRED) mode->type |= M_T_PREFERRED; if (drm_mode->type & DRM_MODE_TYPE_DRIVER) mode->type |= M_T_DRIVER; xf86SetModeDefaultName(mode); modes = xf86ModesAdd(modes, mode); xf86PrintModeline(0, mode); } } return modes; }
static Bool crtc_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode, Rotation rotation, int x, int y) { xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(crtc->scrn); modesettingPtr ms = modesettingPTR(crtc->scrn); ScreenPtr pScreen = crtc->scrn->pScreen; xf86OutputPtr output = NULL; struct crtc_private *crtcp = crtc->driver_private; drmModeCrtcPtr drm_crtc = crtcp->drm_crtc; drmModeModeInfo drm_mode; int i, ret; unsigned int connector_id; PixmapPtr pixmap; for (i = 0; i < config->num_output; output = NULL, i++) { output = config->output[i]; if (output->crtc == crtc) break; } if (!output) { LogMessage(X_ERROR, "No output for this crtc.\n"); return FALSE; } connector_id = xorg_output_get_id(output); drm_mode.clock = mode->Clock; drm_mode.hdisplay = mode->HDisplay; drm_mode.hsync_start = mode->HSyncStart; drm_mode.hsync_end = mode->HSyncEnd; drm_mode.htotal = mode->HTotal; drm_mode.vdisplay = mode->VDisplay; drm_mode.vsync_start = mode->VSyncStart; drm_mode.vsync_end = mode->VSyncEnd; drm_mode.vtotal = mode->VTotal; drm_mode.flags = mode->Flags; drm_mode.hskew = mode->HSkew; drm_mode.vscan = mode->VScan; drm_mode.vrefresh = mode->VRefresh; if (!mode->name) xf86SetModeDefaultName(mode); strncpy(drm_mode.name, mode->name, DRM_DISPLAY_MODE_LEN - 1); drm_mode.name[DRM_DISPLAY_MODE_LEN - 1] = '\0'; /* * Check if we need to scanout from something else than the root * pixmap. In that case, xf86CrtcRotate will take care of allocating * new opaque scanout buffer data "crtc->rotatedData". * However, it will not wrap * that data into pixmaps until the first rotated damage composite. * In out case, the buffer data is actually already a pixmap. */ if (!xf86CrtcRotate(crtc)) return FALSE; if (crtc->transform_in_use && crtc->rotatedData) { x = 0; y = 0; pixmap = (PixmapPtr) crtc->rotatedData; } else pixmap = pScreen->GetScreenPixmap(pScreen); if (crtcp->entry.pixmap != pixmap) { if (crtcp->entry.pixmap) vmwgfx_scanout_unref(&crtcp->entry); crtcp->entry.pixmap = pixmap; crtcp->scanout_id = vmwgfx_scanout_ref(&crtcp->entry); if (crtcp->scanout_id == -1) { LogMessage(X_ERROR, "Failed to convert pixmap to scanout.\n"); return FALSE; } } ret = drmModeSetCrtc(ms->fd, drm_crtc->crtc_id, crtcp->scanout_id, x, y, &connector_id, 1, &drm_mode); if (ret) return FALSE; vmwgfx_scanout_refresh(pixmap); /* Only set gamma when needed, to avoid unneeded delays. */ #if defined(XF86_CRTC_VERSION) && XF86_CRTC_VERSION >= 3 if (!crtc->active && crtc->version >= 3) crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green, crtc->gamma_blue, crtc->gamma_size); crtc->active = TRUE; #endif return TRUE; }
DisplayModePtr xf86GTFMode(int h_pixels, int v_lines, float freq, int interlaced, int margins) { DisplayModeRec *mode = xnfcalloc(1, sizeof(DisplayModeRec)); float h_pixels_rnd; float v_lines_rnd; float v_field_rate_rqd; float top_margin; float bottom_margin; float interlace; float h_period_est; float vsync_plus_bp; float v_back_porch; float total_v_lines; float v_field_rate_est; float h_period; float v_field_rate; float v_frame_rate; float left_margin; float right_margin; float total_active_pixels; float ideal_duty_cycle; float h_blank; float total_pixels; float pixel_freq; float h_freq; float h_sync; float h_front_porch; float v_odd_front_porch_lines; /* 1. In order to give correct results, the number of horizontal * pixels requested is first processed to ensure that it is divisible * by the character size, by rounding it to the nearest character * cell boundary: * * [H PIXELS RND] = ((ROUND([H PIXELS]/[CELL GRAN RND],0))*[CELLGRAN RND]) */ h_pixels_rnd = rint((float) h_pixels / CELL_GRAN) * CELL_GRAN; /* 2. If interlace is requested, the number of vertical lines assumed * by the calculation must be halved, as the computation calculates * the number of vertical lines per field. In either case, the * number of lines is rounded to the nearest integer. * * [V LINES RND] = IF([INT RQD?]="y", ROUND([V LINES]/2,0), * ROUND([V LINES],0)) */ v_lines_rnd = interlaced ? rint((float) v_lines) / 2.0 : rint((float) v_lines); /* 3. Find the frame rate required: * * [V FIELD RATE RQD] = IF([INT RQD?]="y", [I/P FREQ RQD]*2, * [I/P FREQ RQD]) */ v_field_rate_rqd = interlaced ? (freq * 2.0) : (freq); /* 4. Find number of lines in Top margin: * * [TOP MARGIN (LINES)] = IF([MARGINS RQD?]="Y", * ROUND(([MARGIN%]/100*[V LINES RND]),0), * 0) */ top_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); /* 5. Find number of lines in Bottom margin: * * [BOT MARGIN (LINES)] = IF([MARGINS RQD?]="Y", * ROUND(([MARGIN%]/100*[V LINES RND]),0), * 0) */ bottom_margin = margins ? rint(MARGIN_PERCENT / 100.0 * v_lines_rnd) : (0.0); /* 6. If interlace is required, then set variable [INTERLACE]=0.5: * * [INTERLACE]=(IF([INT RQD?]="y",0.5,0)) */ interlace = interlaced ? 0.5 : 0.0; /* 7. Estimate the Horizontal period * * [H PERIOD EST] = ((1/[V FIELD RATE RQD]) - [MIN VSYNC+BP]/1000000) / * ([V LINES RND] + (2*[TOP MARGIN (LINES)]) + * [MIN PORCH RND]+[INTERLACE]) * 1000000 */ h_period_est = (((1.0 / v_field_rate_rqd) - (MIN_VSYNC_PLUS_BP / 1000000.0)) / (v_lines_rnd + (2 * top_margin) + MIN_PORCH + interlace) * 1000000.0); /* 8. Find the number of lines in V sync + back porch: * * [V SYNC+BP] = ROUND(([MIN VSYNC+BP]/[H PERIOD EST]),0) */ vsync_plus_bp = rint(MIN_VSYNC_PLUS_BP / h_period_est); /* 9. Find the number of lines in V back porch alone: * * [V BACK PORCH] = [V SYNC+BP] - [V SYNC RND] * * XXX is "[V SYNC RND]" a typo? should be [V SYNC RQD]? */ v_back_porch = vsync_plus_bp - V_SYNC_RQD; (void) v_back_porch; /* 10. Find the total number of lines in Vertical field period: * * [TOTAL V LINES] = [V LINES RND] + [TOP MARGIN (LINES)] + * [BOT MARGIN (LINES)] + [V SYNC+BP] + [INTERLACE] + * [MIN PORCH RND] */ total_v_lines = v_lines_rnd + top_margin + bottom_margin + vsync_plus_bp + interlace + MIN_PORCH; /* 11. Estimate the Vertical field frequency: * * [V FIELD RATE EST] = 1 / [H PERIOD EST] / [TOTAL V LINES] * 1000000 */ v_field_rate_est = 1.0 / h_period_est / total_v_lines * 1000000.0; /* 12. Find the actual horizontal period: * * [H PERIOD] = [H PERIOD EST] / ([V FIELD RATE RQD] / [V FIELD RATE EST]) */ h_period = h_period_est / (v_field_rate_rqd / v_field_rate_est); /* 13. Find the actual Vertical field frequency: * * [V FIELD RATE] = 1 / [H PERIOD] / [TOTAL V LINES] * 1000000 */ v_field_rate = 1.0 / h_period / total_v_lines * 1000000.0; /* 14. Find the Vertical frame frequency: * * [V FRAME RATE] = (IF([INT RQD?]="y", [V FIELD RATE]/2, [V FIELD RATE])) */ v_frame_rate = interlaced ? v_field_rate / 2.0 : v_field_rate; (void) v_frame_rate; /* 15. Find number of pixels in left margin: * * [LEFT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / * [CELL GRAN RND]),0)) * [CELL GRAN RND], * 0)) */ left_margin = margins ? rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : 0.0; /* 16. Find number of pixels in right margin: * * [RIGHT MARGIN (PIXELS)] = (IF( [MARGINS RQD?]="Y", * (ROUND( ([H PIXELS RND] * [MARGIN%] / 100 / * [CELL GRAN RND]),0)) * [CELL GRAN RND], * 0)) */ right_margin = margins ? rint(h_pixels_rnd * MARGIN_PERCENT / 100.0 / CELL_GRAN) * CELL_GRAN : 0.0; /* 17. Find total number of active pixels in image and left and right * margins: * * [TOTAL ACTIVE PIXELS] = [H PIXELS RND] + [LEFT MARGIN (PIXELS)] + * [RIGHT MARGIN (PIXELS)] */ total_active_pixels = h_pixels_rnd + left_margin + right_margin; /* 18. Find the ideal blanking duty cycle from the blanking duty cycle * equation: * * [IDEAL DUTY CYCLE] = [C'] - ([M']*[H PERIOD]/1000) */ ideal_duty_cycle = C_PRIME - (M_PRIME * h_period / 1000.0); /* 19. Find the number of pixels in the blanking time to the nearest * double character cell: * * [H BLANK (PIXELS)] = (ROUND(([TOTAL ACTIVE PIXELS] * * [IDEAL DUTY CYCLE] / * (100-[IDEAL DUTY CYCLE]) / * (2*[CELL GRAN RND])), 0)) * * (2*[CELL GRAN RND]) */ h_blank = rint(total_active_pixels * ideal_duty_cycle / (100.0 - ideal_duty_cycle) / (2.0 * CELL_GRAN)) * (2.0 * CELL_GRAN); /* 20. Find total number of pixels: * * [TOTAL PIXELS] = [TOTAL ACTIVE PIXELS] + [H BLANK (PIXELS)] */ total_pixels = total_active_pixels + h_blank; /* 21. Find pixel clock frequency: * * [PIXEL FREQ] = [TOTAL PIXELS] / [H PERIOD] */ pixel_freq = total_pixels / h_period; /* 22. Find horizontal frequency: * * [H FREQ] = 1000 / [H PERIOD] */ h_freq = 1000.0 / h_period; /* Stage 1 computations are now complete; I should really pass the results to another function and do the Stage 2 computations, but I only need a few more values so I'll just append the computations here for now */ /* 17. Find the number of pixels in the horizontal sync period: * * [H SYNC (PIXELS)] =(ROUND(([H SYNC%] / 100 * [TOTAL PIXELS] / * [CELL GRAN RND]),0))*[CELL GRAN RND] */ h_sync = rint(H_SYNC_PERCENT / 100.0 * total_pixels / CELL_GRAN) * CELL_GRAN; /* 18. Find the number of pixels in the horizontal front porch period: * * [H FRONT PORCH (PIXELS)] = ([H BLANK (PIXELS)]/2)-[H SYNC (PIXELS)] */ h_front_porch = (h_blank / 2.0) - h_sync; /* 36. Find the number of lines in the odd front porch period: * * [V ODD FRONT PORCH(LINES)]=([MIN PORCH RND]+[INTERLACE]) */ v_odd_front_porch_lines = MIN_PORCH + interlace; /* finally, pack the results in the mode struct */ mode->HDisplay = (int) (h_pixels_rnd); mode->HSyncStart = (int) (h_pixels_rnd + h_front_porch); mode->HSyncEnd = (int) (h_pixels_rnd + h_front_porch + h_sync); mode->HTotal = (int) (total_pixels); mode->VDisplay = (int) (v_lines_rnd); mode->VSyncStart = (int) (v_lines_rnd + v_odd_front_porch_lines); mode->VSyncEnd = (int) (v_lines_rnd + v_odd_front_porch_lines + V_SYNC_RQD); mode->VTotal = (int) (total_v_lines); mode->Clock = (int) (pixel_freq * 1000.0); mode->HSync = h_freq; mode->VRefresh = freq; xf86SetModeDefaultName(mode); mode->Flags = V_NHSYNC | V_PVSYNC; if (interlaced) { mode->VTotal *= 2; mode->Flags |= V_INTERLACE; } return mode; }