fbmon.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. /*
  2. * linux/drivers/video/fbmon.c
  3. *
  4. * Copyright (C) 2002 James Simmons <jsimmons@users.sf.net>
  5. *
  6. * Credits:
  7. *
  8. * The EDID Parser is a conglomeration from the following sources:
  9. *
  10. * 1. SciTech SNAP Graphics Architecture
  11. * Copyright (C) 1991-2002 SciTech Software, Inc. All rights reserved.
  12. *
  13. * 2. XFree86 4.3.0, interpret_edid.c
  14. * Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE>
  15. *
  16. * 3. John Fremlin <vii@users.sourceforge.net> and
  17. * Ani Joshi <ajoshi@unixbox.com>
  18. *
  19. * Generalized Timing Formula is derived from:
  20. *
  21. * GTF Spreadsheet by Andy Morrish (1/5/97)
  22. * available at http://www.vesa.org
  23. *
  24. * This file is subject to the terms and conditions of the GNU General Public
  25. * License. See the file COPYING in the main directory of this archive
  26. * for more details.
  27. *
  28. */
  29. #include <linux/tty.h>
  30. #include <linux/fb.h>
  31. #include <linux/module.h>
  32. #include <video/edid.h>
  33. #ifdef CONFIG_PPC_OF
  34. #include <linux/pci.h>
  35. #include <asm/prom.h>
  36. #include <asm/pci-bridge.h>
  37. #endif
  38. #include "edid.h"
  39. /*
  40. * EDID parser
  41. */
  42. #undef DEBUG /* define this for verbose EDID parsing output */
  43. #ifdef DEBUG
  44. #define DPRINTK(fmt, args...) printk(fmt,## args)
  45. #else
  46. #define DPRINTK(fmt, args...)
  47. #endif
  48. #define FBMON_FIX_HEADER 1
  49. #define FBMON_FIX_INPUT 2
  50. #ifdef CONFIG_FB_MODE_HELPERS
  51. struct broken_edid {
  52. u8 manufacturer[4];
  53. u32 model;
  54. u32 fix;
  55. };
  56. static struct broken_edid brokendb[] = {
  57. /* DEC FR-PCXAV-YZ */
  58. {
  59. .manufacturer = "DEC",
  60. .model = 0x073a,
  61. .fix = FBMON_FIX_HEADER,
  62. },
  63. /* ViewSonic PF775a */
  64. {
  65. .manufacturer = "VSC",
  66. .model = 0x5a44,
  67. .fix = FBMON_FIX_INPUT,
  68. },
  69. };
  70. static const unsigned char edid_v1_header[] = { 0x00, 0xff, 0xff, 0xff,
  71. 0xff, 0xff, 0xff, 0x00
  72. };
  73. static void copy_string(unsigned char *c, unsigned char *s)
  74. {
  75. int i;
  76. c = c + 5;
  77. for (i = 0; (i < 13 && *c != 0x0A); i++)
  78. *(s++) = *(c++);
  79. *s = 0;
  80. while (i-- && (*--s == 0x20)) *s = 0;
  81. }
  82. static int check_edid(unsigned char *edid)
  83. {
  84. unsigned char *block = edid + ID_MANUFACTURER_NAME, manufacturer[4];
  85. unsigned char *b;
  86. u32 model;
  87. int i, fix = 0, ret = 0;
  88. manufacturer[0] = ((block[0] & 0x7c) >> 2) + '@';
  89. manufacturer[1] = ((block[0] & 0x03) << 3) +
  90. ((block[1] & 0xe0) >> 5) + '@';
  91. manufacturer[2] = (block[1] & 0x1f) + '@';
  92. manufacturer[3] = 0;
  93. model = block[2] + (block[3] << 8);
  94. for (i = 0; i < ARRAY_SIZE(brokendb); i++) {
  95. if (!strncmp(manufacturer, brokendb[i].manufacturer, 4) &&
  96. brokendb[i].model == model) {
  97. printk("fbmon: The EDID Block of "
  98. "Manufacturer: %s Model: 0x%x is known to "
  99. "be broken,\n", manufacturer, model);
  100. fix = brokendb[i].fix;
  101. break;
  102. }
  103. }
  104. switch (fix) {
  105. case FBMON_FIX_HEADER:
  106. for (i = 0; i < 8; i++) {
  107. if (edid[i] != edid_v1_header[i])
  108. ret = fix;
  109. }
  110. break;
  111. case FBMON_FIX_INPUT:
  112. b = edid + EDID_STRUCT_DISPLAY;
  113. /* Only if display is GTF capable will
  114. the input type be reset to analog */
  115. if (b[4] & 0x01 && b[0] & 0x80)
  116. ret = fix;
  117. break;
  118. }
  119. return ret;
  120. }
  121. static void fix_edid(unsigned char *edid, int fix)
  122. {
  123. unsigned char *b;
  124. switch (fix) {
  125. case FBMON_FIX_HEADER:
  126. printk("fbmon: trying a header reconstruct\n");
  127. memcpy(edid, edid_v1_header, 8);
  128. break;
  129. case FBMON_FIX_INPUT:
  130. printk("fbmon: trying to fix input type\n");
  131. b = edid + EDID_STRUCT_DISPLAY;
  132. b[0] &= ~0x80;
  133. edid[127] += 0x80;
  134. }
  135. }
  136. static int edid_checksum(unsigned char *edid)
  137. {
  138. unsigned char i, csum = 0, all_null = 0;
  139. int err = 0, fix = check_edid(edid);
  140. if (fix)
  141. fix_edid(edid, fix);
  142. for (i = 0; i < EDID_LENGTH; i++) {
  143. csum += edid[i];
  144. all_null |= edid[i];
  145. }
  146. if (csum == 0x00 && all_null) {
  147. /* checksum passed, everything's good */
  148. err = 1;
  149. }
  150. return err;
  151. }
  152. static int edid_check_header(unsigned char *edid)
  153. {
  154. int i, err = 1, fix = check_edid(edid);
  155. if (fix)
  156. fix_edid(edid, fix);
  157. for (i = 0; i < 8; i++) {
  158. if (edid[i] != edid_v1_header[i])
  159. err = 0;
  160. }
  161. return err;
  162. }
  163. static void parse_vendor_block(unsigned char *block, struct fb_monspecs *specs)
  164. {
  165. specs->manufacturer[0] = ((block[0] & 0x7c) >> 2) + '@';
  166. specs->manufacturer[1] = ((block[0] & 0x03) << 3) +
  167. ((block[1] & 0xe0) >> 5) + '@';
  168. specs->manufacturer[2] = (block[1] & 0x1f) + '@';
  169. specs->manufacturer[3] = 0;
  170. specs->model = block[2] + (block[3] << 8);
  171. specs->serial = block[4] + (block[5] << 8) +
  172. (block[6] << 16) + (block[7] << 24);
  173. specs->year = block[9] + 1990;
  174. specs->week = block[8];
  175. DPRINTK(" Manufacturer: %s\n", specs->manufacturer);
  176. DPRINTK(" Model: %x\n", specs->model);
  177. DPRINTK(" Serial#: %u\n", specs->serial);
  178. DPRINTK(" Year: %u Week %u\n", specs->year, specs->week);
  179. }
  180. static void get_dpms_capabilities(unsigned char flags,
  181. struct fb_monspecs *specs)
  182. {
  183. specs->dpms = 0;
  184. if (flags & DPMS_ACTIVE_OFF)
  185. specs->dpms |= FB_DPMS_ACTIVE_OFF;
  186. if (flags & DPMS_SUSPEND)
  187. specs->dpms |= FB_DPMS_SUSPEND;
  188. if (flags & DPMS_STANDBY)
  189. specs->dpms |= FB_DPMS_STANDBY;
  190. DPRINTK(" DPMS: Active %s, Suspend %s, Standby %s\n",
  191. (flags & DPMS_ACTIVE_OFF) ? "yes" : "no",
  192. (flags & DPMS_SUSPEND) ? "yes" : "no",
  193. (flags & DPMS_STANDBY) ? "yes" : "no");
  194. }
  195. static void get_chroma(unsigned char *block, struct fb_monspecs *specs)
  196. {
  197. int tmp;
  198. DPRINTK(" Chroma\n");
  199. /* Chromaticity data */
  200. tmp = ((block[5] & (3 << 6)) >> 6) | (block[0x7] << 2);
  201. tmp *= 1000;
  202. tmp += 512;
  203. specs->chroma.redx = tmp/1024;
  204. DPRINTK(" RedX: 0.%03d ", specs->chroma.redx);
  205. tmp = ((block[5] & (3 << 4)) >> 4) | (block[0x8] << 2);
  206. tmp *= 1000;
  207. tmp += 512;
  208. specs->chroma.redy = tmp/1024;
  209. DPRINTK("RedY: 0.%03d\n", specs->chroma.redy);
  210. tmp = ((block[5] & (3 << 2)) >> 2) | (block[0x9] << 2);
  211. tmp *= 1000;
  212. tmp += 512;
  213. specs->chroma.greenx = tmp/1024;
  214. DPRINTK(" GreenX: 0.%03d ", specs->chroma.greenx);
  215. tmp = (block[5] & 3) | (block[0xa] << 2);
  216. tmp *= 1000;
  217. tmp += 512;
  218. specs->chroma.greeny = tmp/1024;
  219. DPRINTK("GreenY: 0.%03d\n", specs->chroma.greeny);
  220. tmp = ((block[6] & (3 << 6)) >> 6) | (block[0xb] << 2);
  221. tmp *= 1000;
  222. tmp += 512;
  223. specs->chroma.bluex = tmp/1024;
  224. DPRINTK(" BlueX: 0.%03d ", specs->chroma.bluex);
  225. tmp = ((block[6] & (3 << 4)) >> 4) | (block[0xc] << 2);
  226. tmp *= 1000;
  227. tmp += 512;
  228. specs->chroma.bluey = tmp/1024;
  229. DPRINTK("BlueY: 0.%03d\n", specs->chroma.bluey);
  230. tmp = ((block[6] & (3 << 2)) >> 2) | (block[0xd] << 2);
  231. tmp *= 1000;
  232. tmp += 512;
  233. specs->chroma.whitex = tmp/1024;
  234. DPRINTK(" WhiteX: 0.%03d ", specs->chroma.whitex);
  235. tmp = (block[6] & 3) | (block[0xe] << 2);
  236. tmp *= 1000;
  237. tmp += 512;
  238. specs->chroma.whitey = tmp/1024;
  239. DPRINTK("WhiteY: 0.%03d\n", specs->chroma.whitey);
  240. }
  241. static int edid_is_serial_block(unsigned char *block)
  242. {
  243. if ((block[0] == 0x00) && (block[1] == 0x00) &&
  244. (block[2] == 0x00) && (block[3] == 0xff) &&
  245. (block[4] == 0x00))
  246. return 1;
  247. else
  248. return 0;
  249. }
  250. static int edid_is_ascii_block(unsigned char *block)
  251. {
  252. if ((block[0] == 0x00) && (block[1] == 0x00) &&
  253. (block[2] == 0x00) && (block[3] == 0xfe) &&
  254. (block[4] == 0x00))
  255. return 1;
  256. else
  257. return 0;
  258. }
  259. static int edid_is_limits_block(unsigned char *block)
  260. {
  261. if ((block[0] == 0x00) && (block[1] == 0x00) &&
  262. (block[2] == 0x00) && (block[3] == 0xfd) &&
  263. (block[4] == 0x00))
  264. return 1;
  265. else
  266. return 0;
  267. }
  268. static int edid_is_monitor_block(unsigned char *block)
  269. {
  270. if ((block[0] == 0x00) && (block[1] == 0x00) &&
  271. (block[2] == 0x00) && (block[3] == 0xfc) &&
  272. (block[4] == 0x00))
  273. return 1;
  274. else
  275. return 0;
  276. }
  277. static void calc_mode_timings(int xres, int yres, int refresh, struct fb_videomode *mode)
  278. {
  279. struct fb_var_screeninfo var;
  280. struct fb_info info;
  281. var.xres = xres;
  282. var.yres = yres;
  283. fb_get_mode(FB_VSYNCTIMINGS | FB_IGNOREMON,
  284. refresh, &var, &info);
  285. mode->xres = xres;
  286. mode->yres = yres;
  287. mode->pixclock = var.pixclock;
  288. mode->refresh = refresh;
  289. mode->left_margin = var.left_margin;
  290. mode->right_margin = var.right_margin;
  291. mode->upper_margin = var.upper_margin;
  292. mode->lower_margin = var.lower_margin;
  293. mode->hsync_len = var.hsync_len;
  294. mode->vsync_len = var.vsync_len;
  295. mode->vmode = 0;
  296. mode->sync = 0;
  297. }
  298. static int get_est_timing(unsigned char *block, struct fb_videomode *mode)
  299. {
  300. int num = 0;
  301. unsigned char c;
  302. c = block[0];
  303. if (c&0x80) {
  304. calc_mode_timings(720, 400, 70, &mode[num]);
  305. mode[num++].flag = FB_MODE_IS_CALCULATED;
  306. DPRINTK(" 720x400@70Hz\n");
  307. }
  308. if (c&0x40) {
  309. calc_mode_timings(720, 400, 88, &mode[num]);
  310. mode[num++].flag = FB_MODE_IS_CALCULATED;
  311. DPRINTK(" 720x400@88Hz\n");
  312. }
  313. if (c&0x20) {
  314. mode[num++] = vesa_modes[3];
  315. DPRINTK(" 640x480@60Hz\n");
  316. }
  317. if (c&0x10) {
  318. calc_mode_timings(640, 480, 67, &mode[num]);
  319. mode[num++].flag = FB_MODE_IS_CALCULATED;
  320. DPRINTK(" 640x480@67Hz\n");
  321. }
  322. if (c&0x08) {
  323. mode[num++] = vesa_modes[4];
  324. DPRINTK(" 640x480@72Hz\n");
  325. }
  326. if (c&0x04) {
  327. mode[num++] = vesa_modes[5];
  328. DPRINTK(" 640x480@75Hz\n");
  329. }
  330. if (c&0x02) {
  331. mode[num++] = vesa_modes[7];
  332. DPRINTK(" 800x600@56Hz\n");
  333. }
  334. if (c&0x01) {
  335. mode[num++] = vesa_modes[8];
  336. DPRINTK(" 800x600@60Hz\n");
  337. }
  338. c = block[1];
  339. if (c&0x80) {
  340. mode[num++] = vesa_modes[9];
  341. DPRINTK(" 800x600@72Hz\n");
  342. }
  343. if (c&0x40) {
  344. mode[num++] = vesa_modes[10];
  345. DPRINTK(" 800x600@75Hz\n");
  346. }
  347. if (c&0x20) {
  348. calc_mode_timings(832, 624, 75, &mode[num]);
  349. mode[num++].flag = FB_MODE_IS_CALCULATED;
  350. DPRINTK(" 832x624@75Hz\n");
  351. }
  352. if (c&0x10) {
  353. mode[num++] = vesa_modes[12];
  354. DPRINTK(" 1024x768@87Hz Interlaced\n");
  355. }
  356. if (c&0x08) {
  357. mode[num++] = vesa_modes[13];
  358. DPRINTK(" 1024x768@60Hz\n");
  359. }
  360. if (c&0x04) {
  361. mode[num++] = vesa_modes[14];
  362. DPRINTK(" 1024x768@70Hz\n");
  363. }
  364. if (c&0x02) {
  365. mode[num++] = vesa_modes[15];
  366. DPRINTK(" 1024x768@75Hz\n");
  367. }
  368. if (c&0x01) {
  369. mode[num++] = vesa_modes[21];
  370. DPRINTK(" 1280x1024@75Hz\n");
  371. }
  372. c = block[2];
  373. if (c&0x80) {
  374. mode[num++] = vesa_modes[17];
  375. DPRINTK(" 1152x870@75Hz\n");
  376. }
  377. DPRINTK(" Manufacturer's mask: %x\n",c&0x7F);
  378. return num;
  379. }
  380. static int get_std_timing(unsigned char *block, struct fb_videomode *mode)
  381. {
  382. int xres, yres = 0, refresh, ratio, i;
  383. xres = (block[0] + 31) * 8;
  384. if (xres <= 256)
  385. return 0;
  386. ratio = (block[1] & 0xc0) >> 6;
  387. switch (ratio) {
  388. case 0:
  389. yres = xres;
  390. break;
  391. case 1:
  392. yres = (xres * 3)/4;
  393. break;
  394. case 2:
  395. yres = (xres * 4)/5;
  396. break;
  397. case 3:
  398. yres = (xres * 9)/16;
  399. break;
  400. }
  401. refresh = (block[1] & 0x3f) + 60;
  402. DPRINTK(" %dx%d@%dHz\n", xres, yres, refresh);
  403. for (i = 0; i < VESA_MODEDB_SIZE; i++) {
  404. if (vesa_modes[i].xres == xres &&
  405. vesa_modes[i].yres == yres &&
  406. vesa_modes[i].refresh == refresh) {
  407. *mode = vesa_modes[i];
  408. mode->flag |= FB_MODE_IS_STANDARD;
  409. return 1;
  410. }
  411. }
  412. calc_mode_timings(xres, yres, refresh, mode);
  413. return 1;
  414. }
  415. static int get_dst_timing(unsigned char *block,
  416. struct fb_videomode *mode)
  417. {
  418. int j, num = 0;
  419. for (j = 0; j < 6; j++, block+= STD_TIMING_DESCRIPTION_SIZE)
  420. num += get_std_timing(block, &mode[num]);
  421. return num;
  422. }
  423. static void get_detailed_timing(unsigned char *block,
  424. struct fb_videomode *mode)
  425. {
  426. mode->xres = H_ACTIVE;
  427. mode->yres = V_ACTIVE;
  428. mode->pixclock = PIXEL_CLOCK;
  429. mode->pixclock /= 1000;
  430. mode->pixclock = KHZ2PICOS(mode->pixclock);
  431. mode->right_margin = H_SYNC_OFFSET;
  432. mode->left_margin = (H_ACTIVE + H_BLANKING) -
  433. (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
  434. mode->upper_margin = V_BLANKING - V_SYNC_OFFSET -
  435. V_SYNC_WIDTH;
  436. mode->lower_margin = V_SYNC_OFFSET;
  437. mode->hsync_len = H_SYNC_WIDTH;
  438. mode->vsync_len = V_SYNC_WIDTH;
  439. if (HSYNC_POSITIVE)
  440. mode->sync |= FB_SYNC_HOR_HIGH_ACT;
  441. if (VSYNC_POSITIVE)
  442. mode->sync |= FB_SYNC_VERT_HIGH_ACT;
  443. mode->refresh = PIXEL_CLOCK/((H_ACTIVE + H_BLANKING) *
  444. (V_ACTIVE + V_BLANKING));
  445. mode->vmode = 0;
  446. mode->flag = FB_MODE_IS_DETAILED;
  447. DPRINTK(" %d MHz ", PIXEL_CLOCK/1000000);
  448. DPRINTK("%d %d %d %d ", H_ACTIVE, H_ACTIVE + H_SYNC_OFFSET,
  449. H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH, H_ACTIVE + H_BLANKING);
  450. DPRINTK("%d %d %d %d ", V_ACTIVE, V_ACTIVE + V_SYNC_OFFSET,
  451. V_ACTIVE + V_SYNC_OFFSET + V_SYNC_WIDTH, V_ACTIVE + V_BLANKING);
  452. DPRINTK("%sHSync %sVSync\n\n", (HSYNC_POSITIVE) ? "+" : "-",
  453. (VSYNC_POSITIVE) ? "+" : "-");
  454. }
  455. /**
  456. * fb_create_modedb - create video mode database
  457. * @edid: EDID data
  458. * @dbsize: database size
  459. *
  460. * RETURNS: struct fb_videomode, @dbsize contains length of database
  461. *
  462. * DESCRIPTION:
  463. * This function builds a mode database using the contents of the EDID
  464. * data
  465. */
  466. static struct fb_videomode *fb_create_modedb(unsigned char *edid, int *dbsize)
  467. {
  468. struct fb_videomode *mode, *m;
  469. unsigned char *block;
  470. int num = 0, i;
  471. mode = kmalloc(50 * sizeof(struct fb_videomode), GFP_KERNEL);
  472. if (mode == NULL)
  473. return NULL;
  474. memset(mode, 0, 50 * sizeof(struct fb_videomode));
  475. if (edid == NULL || !edid_checksum(edid) ||
  476. !edid_check_header(edid)) {
  477. kfree(mode);
  478. return NULL;
  479. }
  480. *dbsize = 0;
  481. DPRINTK(" Supported VESA Modes\n");
  482. block = edid + ESTABLISHED_TIMING_1;
  483. num += get_est_timing(block, &mode[num]);
  484. DPRINTK(" Standard Timings\n");
  485. block = edid + STD_TIMING_DESCRIPTIONS_START;
  486. for (i = 0; i < STD_TIMING; i++, block += STD_TIMING_DESCRIPTION_SIZE)
  487. num += get_std_timing(block, &mode[num]);
  488. DPRINTK(" Detailed Timings\n");
  489. block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
  490. for (i = 0; i < 4; i++, block+= DETAILED_TIMING_DESCRIPTION_SIZE) {
  491. int first = 1;
  492. if (block[0] == 0x00 && block[1] == 0x00) {
  493. if (block[3] == 0xfa) {
  494. num += get_dst_timing(block + 5, &mode[num]);
  495. }
  496. } else {
  497. get_detailed_timing(block, &mode[num]);
  498. if (first) {
  499. mode[num].flag |= FB_MODE_IS_FIRST;
  500. first = 0;
  501. }
  502. num++;
  503. }
  504. }
  505. /* Yikes, EDID data is totally useless */
  506. if (!num) {
  507. kfree(mode);
  508. return NULL;
  509. }
  510. *dbsize = num;
  511. m = kmalloc(num * sizeof(struct fb_videomode), GFP_KERNEL);
  512. if (!m)
  513. return mode;
  514. memmove(m, mode, num * sizeof(struct fb_videomode));
  515. kfree(mode);
  516. return m;
  517. }
  518. /**
  519. * fb_destroy_modedb - destroys mode database
  520. * @modedb: mode database to destroy
  521. *
  522. * DESCRIPTION:
  523. * Destroy mode database created by fb_create_modedb
  524. */
  525. void fb_destroy_modedb(struct fb_videomode *modedb)
  526. {
  527. kfree(modedb);
  528. }
  529. static int fb_get_monitor_limits(unsigned char *edid, struct fb_monspecs *specs)
  530. {
  531. int i, retval = 1;
  532. unsigned char *block;
  533. block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
  534. DPRINTK(" Monitor Operating Limits: ");
  535. for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) {
  536. if (edid_is_limits_block(block)) {
  537. specs->hfmin = H_MIN_RATE * 1000;
  538. specs->hfmax = H_MAX_RATE * 1000;
  539. specs->vfmin = V_MIN_RATE;
  540. specs->vfmax = V_MAX_RATE;
  541. specs->dclkmax = MAX_PIXEL_CLOCK * 1000000;
  542. specs->gtf = (GTF_SUPPORT) ? 1 : 0;
  543. retval = 0;
  544. DPRINTK("From EDID\n");
  545. break;
  546. }
  547. }
  548. /* estimate monitor limits based on modes supported */
  549. if (retval) {
  550. struct fb_videomode *modes;
  551. int num_modes, i, hz, hscan, pixclock;
  552. modes = fb_create_modedb(edid, &num_modes);
  553. if (!modes) {
  554. DPRINTK("None Available\n");
  555. return 1;
  556. }
  557. retval = 0;
  558. for (i = 0; i < num_modes; i++) {
  559. hz = modes[i].refresh;
  560. pixclock = PICOS2KHZ(modes[i].pixclock) * 1000;
  561. hscan = (modes[i].yres * 105 * hz + 5000)/100;
  562. if (specs->dclkmax == 0 || specs->dclkmax < pixclock)
  563. specs->dclkmax = pixclock;
  564. if (specs->dclkmin == 0 || specs->dclkmin > pixclock)
  565. specs->dclkmin = pixclock;
  566. if (specs->hfmax == 0 || specs->hfmax < hscan)
  567. specs->hfmax = hscan;
  568. if (specs->hfmin == 0 || specs->hfmin > hscan)
  569. specs->hfmin = hscan;
  570. if (specs->vfmax == 0 || specs->vfmax < hz)
  571. specs->vfmax = hz;
  572. if (specs->vfmin == 0 || specs->vfmin > hz)
  573. specs->vfmin = hz;
  574. }
  575. DPRINTK("Extrapolated\n");
  576. fb_destroy_modedb(modes);
  577. }
  578. DPRINTK(" H: %d-%dKHz V: %d-%dHz DCLK: %dMHz\n",
  579. specs->hfmin/1000, specs->hfmax/1000, specs->vfmin,
  580. specs->vfmax, specs->dclkmax/1000000);
  581. return retval;
  582. }
  583. static void get_monspecs(unsigned char *edid, struct fb_monspecs *specs)
  584. {
  585. unsigned char c, *block;
  586. block = edid + EDID_STRUCT_DISPLAY;
  587. fb_get_monitor_limits(edid, specs);
  588. c = block[0] & 0x80;
  589. specs->input = 0;
  590. if (c) {
  591. specs->input |= FB_DISP_DDI;
  592. DPRINTK(" Digital Display Input");
  593. } else {
  594. DPRINTK(" Analog Display Input: Input Voltage - ");
  595. switch ((block[0] & 0x60) >> 5) {
  596. case 0:
  597. DPRINTK("0.700V/0.300V");
  598. specs->input |= FB_DISP_ANA_700_300;
  599. break;
  600. case 1:
  601. DPRINTK("0.714V/0.286V");
  602. specs->input |= FB_DISP_ANA_714_286;
  603. break;
  604. case 2:
  605. DPRINTK("1.000V/0.400V");
  606. specs->input |= FB_DISP_ANA_1000_400;
  607. break;
  608. case 3:
  609. DPRINTK("0.700V/0.000V");
  610. specs->input |= FB_DISP_ANA_700_000;
  611. break;
  612. }
  613. }
  614. DPRINTK("\n Sync: ");
  615. c = block[0] & 0x10;
  616. if (c)
  617. DPRINTK(" Configurable signal level\n");
  618. c = block[0] & 0x0f;
  619. specs->signal = 0;
  620. if (c & 0x10) {
  621. DPRINTK("Blank to Blank ");
  622. specs->signal |= FB_SIGNAL_BLANK_BLANK;
  623. }
  624. if (c & 0x08) {
  625. DPRINTK("Separate ");
  626. specs->signal |= FB_SIGNAL_SEPARATE;
  627. }
  628. if (c & 0x04) {
  629. DPRINTK("Composite ");
  630. specs->signal |= FB_SIGNAL_COMPOSITE;
  631. }
  632. if (c & 0x02) {
  633. DPRINTK("Sync on Green ");
  634. specs->signal |= FB_SIGNAL_SYNC_ON_GREEN;
  635. }
  636. if (c & 0x01) {
  637. DPRINTK("Serration on ");
  638. specs->signal |= FB_SIGNAL_SERRATION_ON;
  639. }
  640. DPRINTK("\n");
  641. specs->max_x = block[1];
  642. specs->max_y = block[2];
  643. DPRINTK(" Max H-size in cm: ");
  644. if (specs->max_x)
  645. DPRINTK("%d\n", specs->max_x);
  646. else
  647. DPRINTK("variable\n");
  648. DPRINTK(" Max V-size in cm: ");
  649. if (specs->max_y)
  650. DPRINTK("%d\n", specs->max_y);
  651. else
  652. DPRINTK("variable\n");
  653. c = block[3];
  654. specs->gamma = c+100;
  655. DPRINTK(" Gamma: ");
  656. DPRINTK("%d.%d\n", specs->gamma/100, specs->gamma % 100);
  657. get_dpms_capabilities(block[4], specs);
  658. switch ((block[4] & 0x18) >> 3) {
  659. case 0:
  660. DPRINTK(" Monochrome/Grayscale\n");
  661. specs->input |= FB_DISP_MONO;
  662. break;
  663. case 1:
  664. DPRINTK(" RGB Color Display\n");
  665. specs->input |= FB_DISP_RGB;
  666. break;
  667. case 2:
  668. DPRINTK(" Non-RGB Multicolor Display\n");
  669. specs->input |= FB_DISP_MULTI;
  670. break;
  671. default:
  672. DPRINTK(" Unknown\n");
  673. specs->input |= FB_DISP_UNKNOWN;
  674. break;
  675. }
  676. get_chroma(block, specs);
  677. specs->misc = 0;
  678. c = block[4] & 0x7;
  679. if (c & 0x04) {
  680. DPRINTK(" Default color format is primary\n");
  681. specs->misc |= FB_MISC_PRIM_COLOR;
  682. }
  683. if (c & 0x02) {
  684. DPRINTK(" First DETAILED Timing is preferred\n");
  685. specs->misc |= FB_MISC_1ST_DETAIL;
  686. }
  687. if (c & 0x01) {
  688. printk(" Display is GTF capable\n");
  689. specs->gtf = 1;
  690. }
  691. }
  692. static int edid_is_timing_block(unsigned char *block)
  693. {
  694. if ((block[0] != 0x00) || (block[1] != 0x00) ||
  695. (block[2] != 0x00) || (block[4] != 0x00))
  696. return 1;
  697. else
  698. return 0;
  699. }
  700. int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
  701. {
  702. int i;
  703. unsigned char *block;
  704. if (edid == NULL || var == NULL)
  705. return 1;
  706. if (!(edid_checksum(edid)))
  707. return 1;
  708. if (!(edid_check_header(edid)))
  709. return 1;
  710. block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
  711. for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) {
  712. if (edid_is_timing_block(block)) {
  713. var->xres = var->xres_virtual = H_ACTIVE;
  714. var->yres = var->yres_virtual = V_ACTIVE;
  715. var->height = var->width = -1;
  716. var->right_margin = H_SYNC_OFFSET;
  717. var->left_margin = (H_ACTIVE + H_BLANKING) -
  718. (H_ACTIVE + H_SYNC_OFFSET + H_SYNC_WIDTH);
  719. var->upper_margin = V_BLANKING - V_SYNC_OFFSET -
  720. V_SYNC_WIDTH;
  721. var->lower_margin = V_SYNC_OFFSET;
  722. var->hsync_len = H_SYNC_WIDTH;
  723. var->vsync_len = V_SYNC_WIDTH;
  724. var->pixclock = PIXEL_CLOCK;
  725. var->pixclock /= 1000;
  726. var->pixclock = KHZ2PICOS(var->pixclock);
  727. if (HSYNC_POSITIVE)
  728. var->sync |= FB_SYNC_HOR_HIGH_ACT;
  729. if (VSYNC_POSITIVE)
  730. var->sync |= FB_SYNC_VERT_HIGH_ACT;
  731. return 0;
  732. }
  733. }
  734. return 1;
  735. }
  736. void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
  737. {
  738. unsigned char *block;
  739. int i;
  740. if (edid == NULL)
  741. return;
  742. if (!(edid_checksum(edid)))
  743. return;
  744. if (!(edid_check_header(edid)))
  745. return;
  746. memset(specs, 0, sizeof(struct fb_monspecs));
  747. specs->version = edid[EDID_STRUCT_VERSION];
  748. specs->revision = edid[EDID_STRUCT_REVISION];
  749. DPRINTK("========================================\n");
  750. DPRINTK("Display Information (EDID)\n");
  751. DPRINTK("========================================\n");
  752. DPRINTK(" EDID Version %d.%d\n", (int) specs->version,
  753. (int) specs->revision);
  754. parse_vendor_block(edid + ID_MANUFACTURER_NAME, specs);
  755. block = edid + DETAILED_TIMING_DESCRIPTIONS_START;
  756. for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) {
  757. if (edid_is_serial_block(block)) {
  758. copy_string(block, specs->serial_no);
  759. DPRINTK(" Serial Number: %s\n", specs->serial_no);
  760. } else if (edid_is_ascii_block(block)) {
  761. copy_string(block, specs->ascii);
  762. DPRINTK(" ASCII Block: %s\n", specs->ascii);
  763. } else if (edid_is_monitor_block(block)) {
  764. copy_string(block, specs->monitor);
  765. DPRINTK(" Monitor Name: %s\n", specs->monitor);
  766. }
  767. }
  768. DPRINTK(" Display Characteristics:\n");
  769. get_monspecs(edid, specs);
  770. specs->modedb = fb_create_modedb(edid, &specs->modedb_len);
  771. DPRINTK("========================================\n");
  772. }
  773. /*
  774. * VESA Generalized Timing Formula (GTF)
  775. */
  776. #define FLYBACK 550
  777. #define V_FRONTPORCH 1
  778. #define H_OFFSET 40
  779. #define H_SCALEFACTOR 20
  780. #define H_BLANKSCALE 128
  781. #define H_GRADIENT 600
  782. #define C_VAL 30
  783. #define M_VAL 300
  784. struct __fb_timings {
  785. u32 dclk;
  786. u32 hfreq;
  787. u32 vfreq;
  788. u32 hactive;
  789. u32 vactive;
  790. u32 hblank;
  791. u32 vblank;
  792. u32 htotal;
  793. u32 vtotal;
  794. };
  795. /**
  796. * fb_get_vblank - get vertical blank time
  797. * @hfreq: horizontal freq
  798. *
  799. * DESCRIPTION:
  800. * vblank = right_margin + vsync_len + left_margin
  801. *
  802. * given: right_margin = 1 (V_FRONTPORCH)
  803. * vsync_len = 3
  804. * flyback = 550
  805. *
  806. * flyback * hfreq
  807. * left_margin = --------------- - vsync_len
  808. * 1000000
  809. */
  810. static u32 fb_get_vblank(u32 hfreq)
  811. {
  812. u32 vblank;
  813. vblank = (hfreq * FLYBACK)/1000;
  814. vblank = (vblank + 500)/1000;
  815. return (vblank + V_FRONTPORCH);
  816. }
  817. /**
  818. * fb_get_hblank_by_freq - get horizontal blank time given hfreq
  819. * @hfreq: horizontal freq
  820. * @xres: horizontal resolution in pixels
  821. *
  822. * DESCRIPTION:
  823. *
  824. * xres * duty_cycle
  825. * hblank = ------------------
  826. * 100 - duty_cycle
  827. *
  828. * duty cycle = percent of htotal assigned to inactive display
  829. * duty cycle = C - (M/Hfreq)
  830. *
  831. * where: C = ((offset - scale factor) * blank_scale)
  832. * -------------------------------------- + scale factor
  833. * 256
  834. * M = blank_scale * gradient
  835. *
  836. */
  837. static u32 fb_get_hblank_by_hfreq(u32 hfreq, u32 xres)
  838. {
  839. u32 c_val, m_val, duty_cycle, hblank;
  840. c_val = (((H_OFFSET - H_SCALEFACTOR) * H_BLANKSCALE)/256 +
  841. H_SCALEFACTOR) * 1000;
  842. m_val = (H_BLANKSCALE * H_GRADIENT)/256;
  843. m_val = (m_val * 1000000)/hfreq;
  844. duty_cycle = c_val - m_val;
  845. hblank = (xres * duty_cycle)/(100000 - duty_cycle);
  846. return (hblank);
  847. }
  848. /**
  849. * fb_get_hblank_by_dclk - get horizontal blank time given pixelclock
  850. * @dclk: pixelclock in Hz
  851. * @xres: horizontal resolution in pixels
  852. *
  853. * DESCRIPTION:
  854. *
  855. * xres * duty_cycle
  856. * hblank = ------------------
  857. * 100 - duty_cycle
  858. *
  859. * duty cycle = percent of htotal assigned to inactive display
  860. * duty cycle = C - (M * h_period)
  861. *
  862. * where: h_period = SQRT(100 - C + (0.4 * xres * M)/dclk) + C - 100
  863. * -----------------------------------------------
  864. * 2 * M
  865. * M = 300;
  866. * C = 30;
  867. */
  868. static u32 fb_get_hblank_by_dclk(u32 dclk, u32 xres)
  869. {
  870. u32 duty_cycle, h_period, hblank;
  871. dclk /= 1000;
  872. h_period = 100 - C_VAL;
  873. h_period *= h_period;
  874. h_period += (M_VAL * xres * 2 * 1000)/(5 * dclk);
  875. h_period *=10000;
  876. h_period = int_sqrt(h_period);
  877. h_period -= (100 - C_VAL) * 100;
  878. h_period *= 1000;
  879. h_period /= 2 * M_VAL;
  880. duty_cycle = C_VAL * 1000 - (M_VAL * h_period)/100;
  881. hblank = (xres * duty_cycle)/(100000 - duty_cycle) + 8;
  882. hblank &= ~15;
  883. return (hblank);
  884. }
  885. /**
  886. * fb_get_hfreq - estimate hsync
  887. * @vfreq: vertical refresh rate
  888. * @yres: vertical resolution
  889. *
  890. * DESCRIPTION:
  891. *
  892. * (yres + front_port) * vfreq * 1000000
  893. * hfreq = -------------------------------------
  894. * (1000000 - (vfreq * FLYBACK)
  895. *
  896. */
  897. static u32 fb_get_hfreq(u32 vfreq, u32 yres)
  898. {
  899. u32 divisor, hfreq;
  900. divisor = (1000000 - (vfreq * FLYBACK))/1000;
  901. hfreq = (yres + V_FRONTPORCH) * vfreq * 1000;
  902. return (hfreq/divisor);
  903. }
  904. static void fb_timings_vfreq(struct __fb_timings *timings)
  905. {
  906. timings->hfreq = fb_get_hfreq(timings->vfreq, timings->vactive);
  907. timings->vblank = fb_get_vblank(timings->hfreq);
  908. timings->vtotal = timings->vactive + timings->vblank;
  909. timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq,
  910. timings->hactive);
  911. timings->htotal = timings->hactive + timings->hblank;
  912. timings->dclk = timings->htotal * timings->hfreq;
  913. }
  914. static void fb_timings_hfreq(struct __fb_timings *timings)
  915. {
  916. timings->vblank = fb_get_vblank(timings->hfreq);
  917. timings->vtotal = timings->vactive + timings->vblank;
  918. timings->vfreq = timings->hfreq/timings->vtotal;
  919. timings->hblank = fb_get_hblank_by_hfreq(timings->hfreq,
  920. timings->hactive);
  921. timings->htotal = timings->hactive + timings->hblank;
  922. timings->dclk = timings->htotal * timings->hfreq;
  923. }
  924. static void fb_timings_dclk(struct __fb_timings *timings)
  925. {
  926. timings->hblank = fb_get_hblank_by_dclk(timings->dclk,
  927. timings->hactive);
  928. timings->htotal = timings->hactive + timings->hblank;
  929. timings->hfreq = timings->dclk/timings->htotal;
  930. timings->vblank = fb_get_vblank(timings->hfreq);
  931. timings->vtotal = timings->vactive + timings->vblank;
  932. timings->vfreq = timings->hfreq/timings->vtotal;
  933. }
  934. /*
  935. * fb_get_mode - calculates video mode using VESA GTF
  936. * @flags: if: 0 - maximize vertical refresh rate
  937. * 1 - vrefresh-driven calculation;
  938. * 2 - hscan-driven calculation;
  939. * 3 - pixelclock-driven calculation;
  940. * @val: depending on @flags, ignored, vrefresh, hsync or pixelclock
  941. * @var: pointer to fb_var_screeninfo
  942. * @info: pointer to fb_info
  943. *
  944. * DESCRIPTION:
  945. * Calculates video mode based on monitor specs using VESA GTF.
  946. * The GTF is best for VESA GTF compliant monitors but is
  947. * specifically formulated to work for older monitors as well.
  948. *
  949. * If @flag==0, the function will attempt to maximize the
  950. * refresh rate. Otherwise, it will calculate timings based on
  951. * the flag and accompanying value.
  952. *
  953. * If FB_IGNOREMON bit is set in @flags, monitor specs will be
  954. * ignored and @var will be filled with the calculated timings.
  955. *
  956. * All calculations are based on the VESA GTF Spreadsheet
  957. * available at VESA's public ftp (http://www.vesa.org).
  958. *
  959. * NOTES:
  960. * The timings generated by the GTF will be different from VESA
  961. * DMT. It might be a good idea to keep a table of standard
  962. * VESA modes as well. The GTF may also not work for some displays,
  963. * such as, and especially, analog TV.
  964. *
  965. * REQUIRES:
  966. * A valid info->monspecs, otherwise 'safe numbers' will be used.
  967. */
  968. int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_info *info)
  969. {
  970. struct __fb_timings timings;
  971. u32 interlace = 1, dscan = 1;
  972. u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax;
  973. /*
  974. * If monspecs are invalid, use values that are enough
  975. * for 640x480@60
  976. */
  977. if (!info->monspecs.hfmax || !info->monspecs.vfmax ||
  978. !info->monspecs.dclkmax ||
  979. info->monspecs.hfmax < info->monspecs.hfmin ||
  980. info->monspecs.vfmax < info->monspecs.vfmin ||
  981. info->monspecs.dclkmax < info->monspecs.dclkmin) {
  982. hfmin = 29000; hfmax = 30000;
  983. vfmin = 60; vfmax = 60;
  984. dclkmin = 0; dclkmax = 25000000;
  985. } else {
  986. hfmin = info->monspecs.hfmin;
  987. hfmax = info->monspecs.hfmax;
  988. vfmin = info->monspecs.vfmin;
  989. vfmax = info->monspecs.vfmax;
  990. dclkmin = info->monspecs.dclkmin;
  991. dclkmax = info->monspecs.dclkmax;
  992. }
  993. memset(&timings, 0, sizeof(struct __fb_timings));
  994. timings.hactive = var->xres;
  995. timings.vactive = var->yres;
  996. if (var->vmode & FB_VMODE_INTERLACED) {
  997. timings.vactive /= 2;
  998. interlace = 2;
  999. }
  1000. if (var->vmode & FB_VMODE_DOUBLE) {
  1001. timings.vactive *= 2;
  1002. dscan = 2;
  1003. }
  1004. switch (flags & ~FB_IGNOREMON) {
  1005. case FB_MAXTIMINGS: /* maximize refresh rate */
  1006. timings.hfreq = hfmax;
  1007. fb_timings_hfreq(&timings);
  1008. if (timings.vfreq > vfmax) {
  1009. timings.vfreq = vfmax;
  1010. fb_timings_vfreq(&timings);
  1011. }
  1012. if (timings.dclk > dclkmax) {
  1013. timings.dclk = dclkmax;
  1014. fb_timings_dclk(&timings);
  1015. }
  1016. break;
  1017. case FB_VSYNCTIMINGS: /* vrefresh driven */
  1018. timings.vfreq = val;
  1019. fb_timings_vfreq(&timings);
  1020. break;
  1021. case FB_HSYNCTIMINGS: /* hsync driven */
  1022. timings.hfreq = val;
  1023. fb_timings_hfreq(&timings);
  1024. break;
  1025. case FB_DCLKTIMINGS: /* pixelclock driven */
  1026. timings.dclk = PICOS2KHZ(val) * 1000;
  1027. fb_timings_dclk(&timings);
  1028. break;
  1029. default:
  1030. return -EINVAL;
  1031. }
  1032. if (!(flags & FB_IGNOREMON) &&
  1033. (timings.vfreq < vfmin || timings.vfreq > vfmax ||
  1034. timings.hfreq < hfmin || timings.hfreq > hfmax ||
  1035. timings.dclk < dclkmin || timings.dclk > dclkmax))
  1036. return -EINVAL;
  1037. var->pixclock = KHZ2PICOS(timings.dclk/1000);
  1038. var->hsync_len = (timings.htotal * 8)/100;
  1039. var->right_margin = (timings.hblank/2) - var->hsync_len;
  1040. var->left_margin = timings.hblank - var->right_margin - var->hsync_len;
  1041. var->vsync_len = (3 * interlace)/dscan;
  1042. var->lower_margin = (1 * interlace)/dscan;
  1043. var->upper_margin = (timings.vblank * interlace)/dscan -
  1044. (var->vsync_len + var->lower_margin);
  1045. return 0;
  1046. }
  1047. #else
  1048. int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
  1049. {
  1050. return 1;
  1051. }
  1052. void fb_edid_to_monspecs(unsigned char *edid, struct fb_monspecs *specs)
  1053. {
  1054. specs = NULL;
  1055. }
  1056. void fb_destroy_modedb(struct fb_videomode *modedb)
  1057. {
  1058. }
  1059. int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var,
  1060. struct fb_info *info)
  1061. {
  1062. return -EINVAL;
  1063. }
  1064. #endif /* CONFIG_FB_MODE_HELPERS */
  1065. /*
  1066. * fb_validate_mode - validates var against monitor capabilities
  1067. * @var: pointer to fb_var_screeninfo
  1068. * @info: pointer to fb_info
  1069. *
  1070. * DESCRIPTION:
  1071. * Validates video mode against monitor capabilities specified in
  1072. * info->monspecs.
  1073. *
  1074. * REQUIRES:
  1075. * A valid info->monspecs.
  1076. */
  1077. int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info)
  1078. {
  1079. u32 hfreq, vfreq, htotal, vtotal, pixclock;
  1080. u32 hfmin, hfmax, vfmin, vfmax, dclkmin, dclkmax;
  1081. /*
  1082. * If monspecs are invalid, use values that are enough
  1083. * for 640x480@60
  1084. */
  1085. if (!info->monspecs.hfmax || !info->monspecs.vfmax ||
  1086. !info->monspecs.dclkmax ||
  1087. info->monspecs.hfmax < info->monspecs.hfmin ||
  1088. info->monspecs.vfmax < info->monspecs.vfmin ||
  1089. info->monspecs.dclkmax < info->monspecs.dclkmin) {
  1090. hfmin = 29000; hfmax = 30000;
  1091. vfmin = 60; vfmax = 60;
  1092. dclkmin = 0; dclkmax = 25000000;
  1093. } else {
  1094. hfmin = info->monspecs.hfmin;
  1095. hfmax = info->monspecs.hfmax;
  1096. vfmin = info->monspecs.vfmin;
  1097. vfmax = info->monspecs.vfmax;
  1098. dclkmin = info->monspecs.dclkmin;
  1099. dclkmax = info->monspecs.dclkmax;
  1100. }
  1101. if (!var->pixclock)
  1102. return -EINVAL;
  1103. pixclock = PICOS2KHZ(var->pixclock) * 1000;
  1104. htotal = var->xres + var->right_margin + var->hsync_len +
  1105. var->left_margin;
  1106. vtotal = var->yres + var->lower_margin + var->vsync_len +
  1107. var->upper_margin;
  1108. if (var->vmode & FB_VMODE_INTERLACED)
  1109. vtotal /= 2;
  1110. if (var->vmode & FB_VMODE_DOUBLE)
  1111. vtotal *= 2;
  1112. hfreq = pixclock/htotal;
  1113. hfreq = (hfreq + 500) / 1000 * 1000;
  1114. vfreq = hfreq/vtotal;
  1115. return (vfreq < vfmin || vfreq > vfmax ||
  1116. hfreq < hfmin || hfreq > hfmax ||
  1117. pixclock < dclkmin || pixclock > dclkmax) ?
  1118. -EINVAL : 0;
  1119. }
  1120. #if defined(__i386__)
  1121. #include <linux/pci.h>
  1122. /*
  1123. * We need to ensure that the EDID block is only returned for
  1124. * the primary graphics adapter.
  1125. */
  1126. const unsigned char *fb_firmware_edid(struct device *device)
  1127. {
  1128. struct pci_dev *dev = NULL;
  1129. struct resource *res = NULL;
  1130. unsigned char *edid = NULL;
  1131. if (device)
  1132. dev = to_pci_dev(device);
  1133. if (dev)
  1134. res = &dev->resource[PCI_ROM_RESOURCE];
  1135. if (res && res->flags & IORESOURCE_ROM_SHADOW)
  1136. edid = edid_info.dummy;
  1137. return edid;
  1138. }
  1139. #else
  1140. const unsigned char *fb_firmware_edid(struct device *device)
  1141. {
  1142. return NULL;
  1143. }
  1144. #endif /* _i386_ */
  1145. EXPORT_SYMBOL(fb_parse_edid);
  1146. EXPORT_SYMBOL(fb_edid_to_monspecs);
  1147. EXPORT_SYMBOL(fb_firmware_edid);
  1148. EXPORT_SYMBOL(fb_get_mode);
  1149. EXPORT_SYMBOL(fb_validate_mode);
  1150. EXPORT_SYMBOL(fb_destroy_modedb);