Chameleon

Chameleon Svn Source Tree

Root/branches/zenith432/i386/modules/Resolution/915resolution.c

1/*
2 * resolution.h
3 *
4 *NOTE: I don't beleive this code is production ready / should be in trunk
5 * Atleast, not in it's current state.
6 *
7 * Created by Evan Lojewski on 3/4/10.
8 * Copyright 2009. All rights reserved.
9 *
10 */
11
12#ifndef _RESOLUTION_H_
13#define _RESOLUTION_H_
14
15//#include "libsaio.h"
16//#include "edid.h" //included
17#include "915resolution.h"
18
19
20void patchVideoBios()
21{
22UInt32 x = 0, y = 0, bp = 0;
23
24verbose("Resolution:\n");
25getResolution(&x, &y, &bp);
26
27if (x != 0 && y != 0 && bp != 0)
28{
29vbios_map * map;
30
31map = open_vbios(CT_UNKNOWN);
32if(map)
33{
34unlock_vbios(map);
35
36set_mode(map, x, y, bp, 0, 0);
37
38relock_vbios(map);
39
40close_vbios(map);
41}
42}
43}
44
45
46/* Copied from 915 resolution created by steve tomljenovic
47 *
48 * This code is based on the techniques used in :
49 *
50 * - 855patch. Many thanks to Christian Zietz (czietz gmx net)
51 * for demonstrating how to shadow the VBIOS into system RAM
52 * and then modify it.
53 *
54 * - 1280patch by Andrew Tipton (andrewtipton null li).
55 *
56 * - 855resolution by Alain Poirier
57 *
58 * This source code is into the public domain.
59 */
60
61/**
62 **
63 **/
64
65#define CONFIG_MECH_ONE_ADDR0xCF8
66#define CONFIG_MECH_ONE_DATA0xCFC
67
68int freqs[] = { 60, 75, 85 };
69
70UInt32 get_chipset_id(void)
71{
72outl(CONFIG_MECH_ONE_ADDR, 0x80000000);
73return inl(CONFIG_MECH_ONE_DATA);
74}
75
76chipset_type get_chipset(UInt32 id)
77{
78chipset_type type;
79
80switch (id) {
81case 0x35758086:
82type = CT_830;
83break;
84
85case 0x25608086:
86type = CT_845G;
87break;
88
89case 0x35808086:
90type = CT_855GM;
91break;
92
93case 0x25708086:
94type = CT_865G;
95break;
96
97case 0x25808086:
98type = CT_915G;
99break;
100
101case 0x25908086:
102type = CT_915GM;
103break;
104
105case 0x27708086:
106type = CT_945G;
107break;
108
109case 0x27a08086:
110type = CT_945GM;
111break;
112
113case 0x27ac8086:
114type = CT_945GME;
115break;
116
117case 0x29708086:
118type = CT_946GZ;
119break;
120
121case 0x27748086:
122type = CT_955X;
123break;
124
125case 0x277c8086:
126type = CT_975X;
127break;
128
129case 0x29a08086:
130type = CT_G965;
131break;
132
133case 0x29908086:
134type = CT_Q965;
135break;
136
137case 0x81008086:
138type = CT_500;
139break;
140
141case 0x2e108086:
142case 0X2e908086:
143type = CT_B43;
144break;
145
146case 0x2e208086:
147type = CT_P45;
148break;
149
150case 0x2e308086:
151type = CT_G41;
152break;
153
154case 0x29c08086:
155type = CT_G31;
156break;
157
158case 0x29208086:
159type = CT_G45;
160break;
161
162case 0xA0108086:// mobile
163case 0xA0008086:// desktop
164type = CT_3150;
165break;
166
167case 0x2a008086:
168type = CT_965GM;
169break;
170
171case 0x29e08086:
172type = CT_X48;
173break;
174
175case 0x2a408086:
176type = CT_GM45;
177break;
178
179//
180// Core processors
181// http://pci-ids.ucw.cz/read/PC/8086
182//
183case 0x00408086: // Core Processor DRAM Controller
184case 0x00448086: // Core Processor DRAM Controller
185case 0x00488086: // Core Processor DRAM Controller
186case 0x00698086: // Core Processor DRAM Controller
187
188case 0x01008086: // 2nd Generation Core Processor Family DRAM Controller
189case 0x01048086: // 2nd Generation Core Processor Family DRAM Controller
190case 0x01088086: // Xeon E3-1200 2nd Generation Core Processor Family DRAM Controller
191case 0x010c8086: // Xeon E3-1200 2nd Generation Core Processor Family DRAM Controller
192
193case 0x01508086: // 3rd Generation Core Processor Family DRAM Controller
194case 0x01548086: // 3rd Generation Core Processor Family DRAM Controller
195case 0x01588086: // 3rd Generation Core Processor Family DRAM Controller
196case 0x015c8086: // 3rd Generation Core Processor Family DRAM Controller
197
198case 0x01608086: // 3rd Generation Core Processor Family DRAM Controller
199case 0x01648086: // 3rd Generation Core Processor Family DRAM Controller
200
201case 0x0C008086: // 4rd Generation Core Processor Family DRAM Controller
202case 0x0C048086: // 4rd Generation M-Processor Series
203case 0x0A048086: // 4rd Generation U-Processor Series
204case 0x0D048086: // 4rd Generation H-Processor Series (BGA) with GT3 Graphics
205case 0x16048086: // 5th Generation Core Processor Family DRAM Controller
206verbose(" core proc identified\n");
207type = CT_CORE_PROC;
208break;
209
210default:
211if((id & 0x0000FFFF) == 0x00008086) // Intel chipset
212{
213//printf("Unknown chipset 0x%llX, please email id to meklort@gmail.com", id);
214//getc();
215type = CT_UNKNOWN_INTEL;
216//type = CT_UNKNOWN;
217
218}
219else
220{
221type = CT_UNKNOWN;
222}
223break;
224}
225
226return type;
227}
228
229vbios_resolution_type1 * map_type1_resolution(vbios_map * map, UInt16 res)
230{
231vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res));
232return ptr;
233}
234
235vbios_resolution_type2 * map_type2_resolution(vbios_map * map, UInt16 res)
236{
237vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res));
238return ptr;
239}
240
241vbios_resolution_type3 * map_type3_resolution(vbios_map * map, UInt16 res)
242{
243vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res));
244return ptr;
245}
246
247char detect_bios_type(vbios_map * map, char modeline, int entry_size);
248char detect_bios_type(vbios_map * map, char modeline, int entry_size)
249{
250UInt32 i;
251UInt16 r1, r2;
252
253r1 = r2 = 32000;
254
255for (i=0; i < map->mode_table_size; i++)
256{
257if (map->mode_table[i].resolution <= r1)
258{
259r1 = map->mode_table[i].resolution;
260}
261else
262{
263if (map->mode_table[i].resolution <= r2)
264{
265r2 = map->mode_table[i].resolution;
266}
267}
268
269//printf("r1 = %d r2 = %d\n", r1, r2);
270}
271
272return (r2-r1-6) % entry_size == 0;
273}
274
275void close_vbios(vbios_map * map);
276
277char detect_ati_bios_type(vbios_map * map)
278{
279return map->mode_table_size % sizeof(ATOM_MODE_TIMING) == 0;
280}
281
282
283vbios_map * open_vbios(chipset_type forced_chipset)
284{
285UInt32 z;
286vbios_map * map = malloc(sizeof(vbios_map));
287if (!map)
288{
289return 0;
290}
291for(z=0; z<sizeof(vbios_map); z++) ((char*)map)[z]=0;
292/*
293 * Determine chipset
294 */
295
296if (forced_chipset == CT_UNKNOWN)
297{
298map->chipset_id = get_chipset_id();
299map->chipset = get_chipset(map->chipset_id);
300}
301else if (forced_chipset != CT_UNKNOWN)
302{
303map->chipset = forced_chipset;
304}
305
306
307if (map->chipset == CT_UNKNOWN)
308{
309verbose(" Unknown chipset type: %08x.\n", (unsigned) map->chipset_id);
310//verbose("915resolution only works with Intel 800/900 series graphic chipsets.\n");
311//verbose("Chipset Id: %x\n", map->chipset_id);
312close_vbios(map);
313return 0;
314} else {
315verbose(" Detected chipset/proc id (DRAM controller): %08x\n", (unsigned) map->chipset_id);
316}
317
318
319verbose(" VBios: ");
320/*
321 * Map the video bios to memory
322 */
323map->bios_ptr=(char*)VBIOS_START;
324
325/*
326 * check if we have ATI Radeon
327 */
328map->ati_tables.base = map->bios_ptr;
329map->ati_tables.AtomRomHeader = (ATOM_ROM_HEADER *) (map->bios_ptr + *(unsigned short *) (map->bios_ptr + OFFSET_TO_POINTER_TO_ATOM_ROM_HEADER));
330if (strncmp ((char *) map->ati_tables.AtomRomHeader->uaFirmWareSignature, "ATOM", sizeof("ATOM")) == 0)
331{
332verbose("ATI");
333// ATI Radeon Card
334map->bios = BT_ATI_1;
335
336map->ati_tables.MasterDataTables = (unsigned short *) &((ATOM_MASTER_DATA_TABLE *) (map->bios_ptr + map->ati_tables.AtomRomHeader->usMasterDataTableOffset))->ListOfDataTables;
337unsigned short std_vesa_offset = (unsigned short) ((ATOM_MASTER_LIST_OF_DATA_TABLES *)map->ati_tables.MasterDataTables)->StandardVESA_Timing;
338ATOM_STANDARD_VESA_TIMING * std_vesa = (ATOM_STANDARD_VESA_TIMING *) (map->bios_ptr + std_vesa_offset);
339
340map->ati_mode_table = (char *) &std_vesa->aModeTimings;
341if (map->ati_mode_table == 0)
342{
343printf("Unable to locate the mode table.\n");
344printf("Please run the program 'dump_bios' as root and\n");
345printf("email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
346printf("Chipset: %d\n", map->chipset);
347close_vbios(map);
348return 0;
349}
350map->mode_table_size = std_vesa->sHeader.usStructureSize - sizeof(ATOM_COMMON_TABLE_HEADER);
351
352if (!detect_ati_bios_type(map))
353{
354map->bios = BT_ATI_2;
355}
356
357if (map->bios == BT_ATI_1)
358{
359verbose(", BT_ATI_1\n");
360} else {
361verbose(", BT_ATI_2\n");
362}
363}
364else
365{
366
367/*
368 * check if we have NVIDIA
369 */
370
371int i = 0;
372while (i < 512)
373{ // we don't need to look through the whole bios, just the first 512 bytes
374if ((map->bios_ptr[i] == 'N')
375&& (map->bios_ptr[i+1] == 'V')
376&& (map->bios_ptr[i+2] == 'I')
377&& (map->bios_ptr[i+3] == 'D'))
378{
379verbose("nVidia\n");
380map->bios = BT_NVDA;
381unsigned short nv_data_table_offset = 0;
382unsigned short * nv_data_table;
383NV_VESA_TABLE * std_vesa;
384
385int i = 0;
386
387while (i < 0x300)
388{ //We don't need to look for the table in the whole bios, the 768 first bytes only
389if ((map->bios_ptr[i] == 0x44)
390&& (map->bios_ptr[i+1] == 0x01)
391&& (map->bios_ptr[i+2] == 0x04)
392&& (map->bios_ptr[i+3] == 0x00))
393{
394nv_data_table_offset = (unsigned short) (map->bios_ptr[i+4] | (map->bios_ptr[i+5] << 8));
395break;
396}
397i++;
398}
399
400nv_data_table = (unsigned short *) (map->bios_ptr + (nv_data_table_offset + OFFSET_TO_VESA_TABLE_INDEX));
401std_vesa = (NV_VESA_TABLE *) (map->bios_ptr + *nv_data_table);
402
403map->nv_mode_table = (char *) std_vesa->sModelines;
404if (map->nv_mode_table == 0)
405{
406printf("Unable to locate the mode table.\n");
407printf("Please run the program 'dump_bios' as root and\n");
408printf("email the file 'vbios.dmp' to stomljen@yahoo.com.\n");
409printf("Chipset: %s\n", map->chipset);
410close_vbios(map);
411return 0;
412}
413map->mode_table_size = std_vesa->sHeader.usTable_Size;
414
415break;
416}
417i++;
418}
419}
420
421
422/*
423 * check if we have Intel
424 */
425
426/*if (map->chipset == CT_UNKNOWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {
427 printf( "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n");
428
429 printf("Chipset Id: %x\n", map->chipset_id);
430
431 printf("Please report this problem to stomljen@yahoo.com\n");
432
433 close_vbios(map);
434 return 0;
435 }*/
436
437/*
438 * check for others
439 */
440
441/*
442 * Figure out where the mode table is
443 */
444if ((map->bios != BT_ATI_1) && (map->bios != BT_ATI_2) && (map->bios != BT_NVDA))
445{
446char* p = map->bios_ptr + 16;
447char* limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
448
449verbose("Other");
450while (p < limit && map->mode_table == 0)
451{
452vbios_mode * mode_ptr = (vbios_mode *) p;
453
454if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
455((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30))
456{
457map->mode_table = mode_ptr;
458}
459
460p++;
461}
462
463if (map->mode_table == 0)
464{
465close_vbios(map);
466return 0;
467}
468}
469
470
471/*
472 * Determine size of mode table
473 */
474if ((map->bios != BT_ATI_1) && (map->bios != BT_ATI_2) && (map->bios != BT_NVDA))
475{
476vbios_mode * mode_ptr = map->mode_table;
477
478while (mode_ptr->mode != 0xff)
479{
480map->mode_table_size++;
481mode_ptr++;
482}
483}
484
485/*
486 * Figure out what type of bios we have
487 * order of detection is important
488 */
489if ((map->bios != BT_ATI_1) && (map->bios != BT_ATI_2) && (map->bios != BT_NVDA))
490{
491if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type3)))
492{
493map->bios = BT_3;
494verbose(", BT_3\n");
495}
496else if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type2)))
497{
498map->bios = BT_2;
499verbose(", BT_2\n");
500}
501else if (detect_bios_type(map, FALSE, sizeof(vbios_resolution_type1)))
502{
503map->bios = BT_1;
504verbose(", BT_1\n");
505}
506else {
507verbose(" - unknown\n");
508return 0;
509}
510}
511
512return map;
513}
514
515void close_vbios(vbios_map * map)
516{
517free(map);
518}
519
520void unlock_vbios(vbios_map * map)
521{
522
523map->unlocked = TRUE;
524
525switch (map->chipset) {
526case CT_UNKNOWN:
527break;
528case CT_830:
529case CT_855GM:
530outl(CONFIG_MECH_ONE_ADDR, 0x8000005a);
531map->b1 = inb(CONFIG_MECH_ONE_DATA + 2);
532
533outl(CONFIG_MECH_ONE_ADDR, 0x8000005a);
534outb(CONFIG_MECH_ONE_DATA + 2, 0x33);
535break;
536case CT_845G:
537case CT_865G:
538case CT_915G:
539case CT_915GM:
540case CT_945G:
541case CT_945GM:
542case CT_945GME:
543case CT_946GZ:
544case CT_G965:
545case CT_Q965:
546case CT_965GM:
547case CT_975X:
548case CT_P35:
549case CT_955X:
550case CT_X48:
551case CT_B43:
552case CT_Q45:
553case CT_P45:
554case CT_GM45:
555case CT_G45:
556case CT_G41:
557case CT_G31:
558case CT_500:
559case CT_3150:
560outl(CONFIG_MECH_ONE_ADDR, 0x80000090);
561map->b1 = inb(CONFIG_MECH_ONE_DATA + 1);
562map->b2 = inb(CONFIG_MECH_ONE_DATA + 2);
563outl(CONFIG_MECH_ONE_ADDR, 0x80000090);
564outb(CONFIG_MECH_ONE_DATA + 1, 0x33);
565outb(CONFIG_MECH_ONE_DATA + 2, 0x33);
566break;
567case CT_CORE_PROC: // Core procs - PAM regs are 80h - 86h
568case CT_UNKNOWN_INTEL:// Assume newer intel chipset is the same as before
569outl(CONFIG_MECH_ONE_ADDR, 0x80000080);
570map->b1 = inb(CONFIG_MECH_ONE_DATA + 1);
571map->b2 = inb(CONFIG_MECH_ONE_DATA + 2);
572outl(CONFIG_MECH_ONE_ADDR, 0x80000080);
573outb(CONFIG_MECH_ONE_DATA + 1, 0x33);
574outb(CONFIG_MECH_ONE_DATA + 2, 0x33);
575break;
576default:
577break;
578}
579
580#if DEBUG
581{
582UInt32 t = inl(CONFIG_MECH_ONE_DATA);
583verbose("unlock PAM: (0x%08x)\n", t);
584}
585#endif
586}
587
588void relock_vbios(vbios_map * map)
589{
590
591map->unlocked = FALSE;
592
593switch (map->chipset)
594{
595case CT_UNKNOWN:
596break;
597case CT_830:
598case CT_855GM:
599outl(CONFIG_MECH_ONE_ADDR, 0x8000005a);
600outb(CONFIG_MECH_ONE_DATA + 2, map->b1);
601break;
602case CT_845G:
603case CT_865G:
604case CT_915G:
605case CT_915GM:
606case CT_945G:
607case CT_945GM:
608case CT_945GME:
609case CT_946GZ:
610case CT_G965:
611case CT_955X:
612case CT_G45:
613case CT_Q965:
614case CT_965GM:
615case CT_975X:
616case CT_P35:
617case CT_X48:
618case CT_B43:
619case CT_Q45:
620case CT_P45:
621case CT_GM45:
622case CT_G41:
623case CT_G31:
624case CT_500:
625case CT_3150:
626outl(CONFIG_MECH_ONE_ADDR, 0x80000090);
627outb(CONFIG_MECH_ONE_DATA + 1, map->b1);
628outb(CONFIG_MECH_ONE_DATA + 2, map->b2);
629break;
630case CT_CORE_PROC:
631case CT_UNKNOWN_INTEL:
632outl(CONFIG_MECH_ONE_ADDR, 0x80000080);
633outb(CONFIG_MECH_ONE_DATA + 1, map->b1);
634outb(CONFIG_MECH_ONE_DATA + 2, map->b2);
635default:
636break;
637}
638
639#if DEBUG
640{
641 UInt32 t = inl(CONFIG_MECH_ONE_DATA);
642verbose("relock PAM: (0x%08x)\n", t);
643}
644#endif
645}
646
647
648int getMode(edid_mode *mode)
649{
650char* edidInfo = readEDID();
651
652if(!edidInfo) return 1;
653//Slice
654if(!fb_parse_edid((struct EDID *)edidInfo, mode) || !mode->h_active)
655{
656free( edidInfo );
657return 1;
658}
659/*mode->pixel_clock = (edidInfo[55] << 8) | edidInfo[54];
660mode->h_active = edidInfo[56] | ((edidInfo[58] & 0xF0) << 4);
661mode->h_blanking = ((edidInfo[58] & 0x0F) << 8) | edidInfo[57];
662mode->v_active = edidInfo[59] | ((edidInfo[61] & 0xF0) << 4);
663mode->v_blanking = ((edidInfo[61] & 0x0F) << 8) | edidInfo[60];
664mode->h_sync_offset = ((edidInfo[65] & 0xC0) >> 2) | edidInfo[62];
665mode->h_sync_width = (edidInfo[65] & 0x30) | edidInfo[63];
666mode->v_sync_offset = (edidInfo[65] & 0x0C) | ((edidInfo[64] & 0x0C) >> 2);
667mode->v_sync_width = ((edidInfo[65] & 0x3) << 2) | (edidInfo[64] & 0x03);
668*/
669
670free( edidInfo );
671
672if(!mode->h_active) return 1;
673
674return 0;
675
676}
677
678
679static void gtf_timings(UInt32 x, UInt32 y, UInt32 freq,
680unsigned long *clock,
681UInt16 *hsyncstart, UInt16 *hsyncend, UInt16 *hblank,
682UInt16 *vsyncstart, UInt16 *vsyncend, UInt16 *vblank)
683{
684UInt32 hbl, vbl, vfreq;
685
686vbl = y + (y+1)/(20000.0/(11*freq) - 1) + 1.5;
687vfreq = vbl * freq;
688hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) /
689 + (70.0 + 300000.0 / vfreq) / 16.0 + 0.5);
690
691*vsyncstart = y;
692*vsyncend = y + 3;
693*vblank = vbl - 1;
694*hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;
695*hsyncend = x + hbl / 2 - 1;
696*hblank = x + hbl - 1;
697*clock = (x + hbl) * vfreq / 1000;
698}
699
700void set_mode(vbios_map * map, /*UInt32 mode,*/ UInt32 x, UInt32 y, UInt32 bp, UInt32 htotal, UInt32 vtotal) {
701UInt32 xprev, yprev;
702UInt32 i = 0, j;
703// patch first available mode
704
705//for (i=0; i < map->mode_table_size; i++) {
706//if (map->mode_table[0].mode == mode) {
707verbose(" Patching: ");
708switch(map->bios) {
709case BT_INTEL:
710verbose("BT_INTEL - not supported\n");
711return;
712
713case BT_1:
714{
715verbose("BT_1 patched.\n");
716vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);
717
718if (bp)
719{
720map->mode_table[i].bits_per_pixel = (uint8_t)bp;
721}
722
723res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);
724res->x1 = (x & 0xff);
725
726res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);
727res->y1 = (y & 0xff);
728if (htotal)
729{
730res->x_total = ((htotal-x) & 0xff);
731}
732if (vtotal)
733{
734res->y_total = ((vtotal-y) & 0xff);
735}
736break;
737}
738case BT_2:
739{
740vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);
741
742res->xchars = (uint8_t)(x / 8);
743res->ychars = (uint8_t)(y / 16 - 1);
744xprev = res->modelines[0].x1;
745yprev = res->modelines[0].y1;
746
747for(j=0; j < 3; j++) {
748vbios_modeline_type2 * modeline = &res->modelines[j];
749
750if (modeline->x1 == xprev && modeline->y1 == yprev)
751{
752modeline->x1 = modeline->x2 = (uint16_t)(x-1);
753modeline->y1 = modeline->y2 = (uint16_t)(y-1);
754
755gtf_timings(x, y, freqs[j], &modeline->clock,
756&modeline->hsyncstart, &modeline->hsyncend,
757&modeline->hblank, &modeline->vsyncstart,
758&modeline->vsyncend, &modeline->vblank);
759
760if (htotal)
761{
762modeline->htotal = (uint16_t)htotal;
763}
764else
765{
766modeline->htotal = modeline->hblank;
767}
768if (vtotal)
769{
770modeline->vtotal = (uint16_t)vtotal;
771}
772else
773{
774modeline->vtotal = modeline->vblank;
775}
776}
777}
778verbose("BT_1 patched.\n");
779break;
780}
781case BT_3:
782{
783vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);
784
785xprev = res->modelines[0].x1;
786yprev = res->modelines[0].y1;
787
788for (j=0; j < 3; j++)
789{
790vbios_modeline_type3 * modeline = &res->modelines[j];
791
792if (modeline->x1 == xprev && modeline->y1 == yprev)
793{
794modeline->x1 = modeline->x2 = (uint16_t)(x-1);
795modeline->y1 = modeline->y2 = (uint16_t)(y-1);
796
797gtf_timings(x, y, freqs[j], &modeline->clock,
798&modeline->hsyncstart, &modeline->hsyncend,
799&modeline->hblank, &modeline->vsyncstart,
800&modeline->vsyncend, &modeline->vblank);
801if (htotal)
802{
803modeline->htotal = (uint16_t)htotal;
804}
805else
806{
807modeline->htotal = modeline->hblank;
808}
809if (vtotal)
810{
811modeline->vtotal = (uint16_t)vtotal;
812}
813else
814{
815modeline->vtotal = modeline->vblank;
816}
817modeline->timing_h = (uint16_t)(y-1);
818modeline->timing_v = (uint16_t)(x-1);
819}
820}
821verbose("BT_3 patched.\n");
822break;
823}
824case BT_ATI_1:
825{
826verbose("BT_ATI_1");
827edid_mode mode;
828
829ATOM_MODE_TIMING *mode_timing = (ATOM_MODE_TIMING *) map->ati_mode_table;
830
831//if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force){
832if (!getMode(&mode))
833{
834verbose("\n Edid detailed timing descriptor found: %dx%d\n vbios mode 0 patched!\n", mode.h_active, mode.v_active);
835mode_timing->usCRTC_H_Total = mode.h_active + mode.h_blanking;
836mode_timing->usCRTC_H_Disp = mode.h_active;
837mode_timing->usCRTC_H_SyncStart = mode.h_active + mode.h_sync_offset;
838mode_timing->usCRTC_H_SyncWidth = mode.h_sync_width;
839
840mode_timing->usCRTC_V_Total = mode.v_active + mode.v_blanking;
841mode_timing->usCRTC_V_Disp = mode.v_active;
842mode_timing->usCRTC_V_SyncStart = mode.v_active + mode.v_sync_offset;
843mode_timing->usCRTC_V_SyncWidth = mode.v_sync_width;
844
845mode_timing->usPixelClock = mode.pixel_clock;
846}
847else
848{
849verbose(" Edid not found or invalid - vbios not patched!\n");
850}
851/*else
852{
853vbios_modeline_type2 modeline;
854
855cvt_timings(x, y, freqs[0], &modeline.clock,
856&modeline.hsyncstart, &modeline.hsyncend,
857&modeline.hblank, &modeline.vsyncstart,
858&modeline.vsyncend, &modeline.vblank, 0);
859
860mode_timing->usCRTC_H_Total = x + modeline.hblank;
861mode_timing->usCRTC_H_Disp = x;
862mode_timing->usCRTC_H_SyncStart = modeline.hsyncstart;
863mode_timing->usCRTC_H_SyncWidth = modeline.hsyncend - modeline.hsyncstart;
864
865mode_timing->usCRTC_V_Total = y + modeline.vblank;
866mode_timing->usCRTC_V_Disp = y;
867mode_timing->usCRTC_V_SyncStart = modeline.vsyncstart;
868mode_timing->usCRTC_V_SyncWidth = modeline.vsyncend - modeline.vsyncstart;
869
870mode_timing->usPixelClock = modeline.clock;
871 }*/
872
873break;
874}
875case BT_ATI_2:
876{
877verbose("BT_ATI_2");
878edid_mode mode;
879
880ATOM_DTD_FORMAT *mode_timing = (ATOM_DTD_FORMAT *) map->ati_mode_table;
881
882/*if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force) {*/
883if (!getMode(&mode))
884{
885verbose("\n Edid detailed timing descriptor found: %dx%d\n vbios mode 0 patched!\n", mode.h_active, mode.v_active);
886mode_timing->usHBlanking_Time = mode.h_blanking;
887mode_timing->usHActive = mode.h_active;
888mode_timing->usHSyncOffset = mode.h_sync_offset;
889mode_timing->usHSyncWidth = mode.h_sync_width;
890
891mode_timing->usVBlanking_Time = mode.v_blanking;
892mode_timing->usVActive = mode.v_active;
893mode_timing->usVSyncOffset = mode.v_sync_offset;
894mode_timing->usVSyncWidth = mode.v_sync_width;
895
896mode_timing->usPixClk = mode.pixel_clock;
897}
898else
899{
900verbose(" Edid not found or invalid - vbios not patched!\n");
901}
902/*else
903{
904vbios_modeline_type2 modeline;
905
906cvt_timings(x, y, freqs[0], &modeline.clock,
907&modeline.hsyncstart, &modeline.hsyncend,
908&modeline.hblank, &modeline.vsyncstart,
909&modeline.vsyncend, &modeline.vblank, 0);
910
911mode_timing->usHBlanking_Time = modeline.hblank;
912mode_timing->usHActive = x;
913mode_timing->usHSyncOffset = modeline.hsyncstart - x;
914mode_timing->usHSyncWidth = modeline.hsyncend - modeline.hsyncstart;
915
916mode_timing->usVBlanking_Time = modeline.vblank;
917mode_timing->usVActive = y;
918mode_timing->usVSyncOffset = modeline.vsyncstart - y;
919mode_timing->usVSyncWidth = modeline.hsyncend - modeline.hsyncstart;
920
921mode_timing->usPixClk = modeline.clock;
922}*/
923
924break;
925}
926case BT_NVDA:
927{
928verbose("BT_NVDA");
929edid_mode mode;
930NV_MODELINE *mode_timing = (NV_MODELINE *) map->nv_mode_table;
931
932/*if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force) {*/
933if (!getMode(&mode))
934{
935verbose("\n Edid detailed timing descriptor found: %dx%d\n vbios mode %d patched!\n", mode.h_active, mode.v_active, (int) i);
936mode_timing[i].usH_Total = mode.h_active + mode.h_blanking;
937mode_timing[i].usH_Active = mode.h_active;
938mode_timing[i].usH_SyncStart = mode.h_active + mode.h_sync_offset;
939mode_timing[i].usH_SyncEnd = mode.h_active + mode.h_sync_offset + mode.h_sync_width;
940
941mode_timing[i].usV_Total = mode.v_active + mode.v_blanking;
942mode_timing[i].usV_Active = mode.v_active;
943mode_timing[i].usV_SyncStart = mode.v_active + mode.v_sync_offset;
944mode_timing[i].usV_SyncEnd = mode.v_active + mode.v_sync_offset + mode.v_sync_width;
945
946mode_timing[i].usPixel_Clock = mode.pixel_clock;
947}
948 else
949{
950verbose(" Edid not found or invalid - vbios not patched!\n");
951}
952/*else
953 {
954 vbios_modeline_type2 modeline;
955 cvt_timings(x, y, freqs[0], &modeline.clock,
956 &modeline.hsyncstart, &modeline.hsyncend,
957 &modeline.hblank, &modeline.vsyncstart,
958 &modeline.vsyncend, &modeline.vblank, 0);
959
960 mode_timing[i].usH_Total = x + modeline.hblank - 1;
961 mode_timing[i].usH_Active = x;
962 mode_timing[i].usH_SyncStart = modeline.hsyncstart - 1;
963 mode_timing[i].usH_SyncEnd = modeline.hsyncend - 1;
964
965 mode_timing[i].usV_Total = y + modeline.vblank - 1;
966 mode_timing[i].usV_Active = y;
967 mode_timing[i].usV_SyncStart = modeline.vsyncstart - 1;
968 mode_timing[i].usV_SyncEnd = modeline.vsyncend - 1;
969
970 mode_timing[i].usPixel_Clock = modeline.clock;
971 }*/
972break;
973}
974case BT_UNKNOWN:
975{
976verbose(" Unknown - vbios not patched\n");
977break;
978}
979default:
980break;
981}
982//}
983//}
984}
985
986#endif // _RESOLUTION_H_
987

Archive Download this file

Revision: 2805