modedb.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*
  2. * linux/drivers/video/modedb.c -- Standard video mode database management
  3. *
  4. * Copyright (C) 1999 Geert Uytterhoeven
  5. *
  6. * 2001 - Documented with DocBook
  7. * - Brad Douglas <brad@neruo.com>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file COPYING in the main directory of this archive for
  11. * more details.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/slab.h>
  15. #include <linux/fb.h>
  16. #include <linux/kernel.h>
  17. #undef DEBUG
  18. #define name_matches(v, s, l) \
  19. ((v).name && !strncmp((s), (v).name, (l)) && strlen((v).name) == (l))
  20. #define res_matches(v, x, y) \
  21. ((v).xres == (x) && (v).yres == (y))
  22. #ifdef DEBUG
  23. #define DPRINTK(fmt, args...) printk("modedb %s: " fmt, __func__ , ## args)
  24. #else
  25. #define DPRINTK(fmt, args...)
  26. #endif
  27. /*
  28. * Standard video mode definitions (taken from XFree86)
  29. */
  30. static const struct fb_videomode modedb[] = {
  31. /* 640x400 @ 70 Hz, 31.5 kHz hsync */
  32. { NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, 0,
  33. FB_VMODE_NONINTERLACED },
  34. /* 640x480 @ 60 Hz, 31.5 kHz hsync */
  35. { NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2, 0,
  36. FB_VMODE_NONINTERLACED },
  37. /* 800x600 @ 56 Hz, 35.15 kHz hsync */
  38. { NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2, 0,
  39. FB_VMODE_NONINTERLACED },
  40. /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
  41. { NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, 0,
  42. FB_VMODE_INTERLACED },
  43. /* 640x400 @ 85 Hz, 37.86 kHz hsync */
  44. { NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
  45. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
  46. /* 640x480 @ 72 Hz, 36.5 kHz hsync */
  47. { NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, 0,
  48. FB_VMODE_NONINTERLACED },
  49. /* 640x480 @ 75 Hz, 37.50 kHz hsync */
  50. { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0,
  51. FB_VMODE_NONINTERLACED },
  52. /* 800x600 @ 60 Hz, 37.8 kHz hsync */
  53. { NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
  54. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  55. FB_VMODE_NONINTERLACED },
  56. /* 640x480 @ 85 Hz, 43.27 kHz hsync */
  57. { NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, 0,
  58. FB_VMODE_NONINTERLACED },
  59. /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
  60. { NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, 0,
  61. FB_VMODE_INTERLACED },
  62. /* 800x600 @ 72 Hz, 48.0 kHz hsync */
  63. { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
  64. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  65. FB_VMODE_NONINTERLACED },
  66. /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
  67. { NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, 0,
  68. FB_VMODE_NONINTERLACED },
  69. /* 640x480 @ 100 Hz, 53.01 kHz hsync */
  70. { NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6, 0,
  71. FB_VMODE_NONINTERLACED },
  72. /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
  73. { NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, 0,
  74. FB_VMODE_NONINTERLACED },
  75. /* 800x600 @ 85 Hz, 55.84 kHz hsync */
  76. { NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, 0,
  77. FB_VMODE_NONINTERLACED },
  78. /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
  79. { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0,
  80. FB_VMODE_NONINTERLACED },
  81. /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
  82. { NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12, 0,
  83. FB_VMODE_INTERLACED },
  84. /* 800x600 @ 100 Hz, 64.02 kHz hsync */
  85. { NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, 0,
  86. FB_VMODE_NONINTERLACED },
  87. /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
  88. { NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, 0,
  89. FB_VMODE_NONINTERLACED },
  90. /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
  91. { NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, 0,
  92. FB_VMODE_NONINTERLACED },
  93. /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
  94. { NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, 0,
  95. FB_VMODE_NONINTERLACED },
  96. /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
  97. { NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, 0,
  98. FB_VMODE_NONINTERLACED },
  99. /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
  100. { NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
  101. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  102. FB_VMODE_NONINTERLACED },
  103. /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
  104. { NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
  105. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  106. FB_VMODE_NONINTERLACED },
  107. /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
  108. { NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, 0,
  109. FB_VMODE_NONINTERLACED },
  110. /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
  111. { NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, 0,
  112. FB_VMODE_NONINTERLACED },
  113. /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
  114. { NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, 0,
  115. FB_VMODE_NONINTERLACED },
  116. /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
  117. { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
  118. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  119. FB_VMODE_NONINTERLACED },
  120. /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
  121. { NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, 0,
  122. FB_VMODE_NONINTERLACED },
  123. /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
  124. { NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, 0,
  125. FB_VMODE_NONINTERLACED },
  126. /* 1024x768 @ 100Hz, 80.21 kHz hsync */
  127. { NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, 0,
  128. FB_VMODE_NONINTERLACED },
  129. /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
  130. { NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, 0,
  131. FB_VMODE_NONINTERLACED },
  132. /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
  133. { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, 0,
  134. FB_VMODE_NONINTERLACED },
  135. /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
  136. { NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, 0,
  137. FB_VMODE_NONINTERLACED },
  138. /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
  139. { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
  140. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  141. FB_VMODE_NONINTERLACED },
  142. /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
  143. { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
  144. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  145. FB_VMODE_NONINTERLACED },
  146. /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
  147. { NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
  148. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  149. FB_VMODE_NONINTERLACED },
  150. /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
  151. { NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
  152. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  153. FB_VMODE_NONINTERLACED },
  154. /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
  155. { NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, 0,
  156. FB_VMODE_NONINTERLACED },
  157. /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
  158. { NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
  159. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  160. FB_VMODE_NONINTERLACED },
  161. /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
  162. { NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
  163. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  164. FB_VMODE_NONINTERLACED },
  165. /* 512x384 @ 78 Hz, 31.50 kHz hsync */
  166. { NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0,
  167. FB_VMODE_NONINTERLACED },
  168. /* 512x384 @ 85 Hz, 34.38 kHz hsync */
  169. { NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, 0,
  170. FB_VMODE_NONINTERLACED },
  171. /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
  172. { NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0,
  173. FB_VMODE_DOUBLE },
  174. /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
  175. { NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, 0,
  176. FB_VMODE_DOUBLE },
  177. /* 320x240 @ 72 Hz, 36.5 kHz hsync */
  178. { NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0,
  179. FB_VMODE_DOUBLE },
  180. /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
  181. { NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, 0,
  182. FB_VMODE_DOUBLE },
  183. /* 400x300 @ 60 Hz, 37.8 kHz hsync */
  184. { NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, 0,
  185. FB_VMODE_DOUBLE },
  186. /* 400x300 @ 72 Hz, 48.0 kHz hsync */
  187. { NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3, 0,
  188. FB_VMODE_DOUBLE },
  189. /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
  190. { NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, 0,
  191. FB_VMODE_DOUBLE },
  192. /* 480x300 @ 60 Hz, 37.8 kHz hsync */
  193. { NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, 0,
  194. FB_VMODE_DOUBLE },
  195. /* 480x300 @ 63 Hz, 39.6 kHz hsync */
  196. { NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, 0,
  197. FB_VMODE_DOUBLE },
  198. /* 480x300 @ 72 Hz, 48.0 kHz hsync */
  199. { NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, 0,
  200. FB_VMODE_DOUBLE },
  201. /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
  202. { NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
  203. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  204. FB_VMODE_NONINTERLACED },
  205. /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
  206. { NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
  207. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  208. FB_VMODE_NONINTERLACED },
  209. /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
  210. { NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5, 0,
  211. FB_VMODE_NONINTERLACED },
  212. /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
  213. { NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3, 0,
  214. FB_VMODE_NONINTERLACED },
  215. /* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
  216. { NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5, 0,
  217. FB_VMODE_INTERLACED },
  218. /* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
  219. { NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5, 0,
  220. FB_VMODE_INTERLACED },
  221. /* 864x480 @ 60 Hz, 35.15 kHz hsync */
  222. { NULL, 60, 864, 480, 27777, 1, 1, 1, 1, 0, 0,
  223. 0, FB_VMODE_NONINTERLACED },
  224. };
  225. #ifdef CONFIG_FB_MODE_HELPERS
  226. const struct fb_videomode cea_modes[64] = {
  227. /* #1: 640x480p@59.94/60Hz */
  228. [1] = {
  229. NULL, 60, 640, 480, 39722, 48, 16, 33, 10, 96, 2, 0,
  230. FB_VMODE_NONINTERLACED, 0,
  231. },
  232. /* #3: 720x480p@59.94/60Hz */
  233. [3] = {
  234. NULL, 60, 720, 480, 37037, 60, 16, 30, 9, 62, 6, 0,
  235. FB_VMODE_NONINTERLACED, 0,
  236. },
  237. /* #5: 1920x1080i@59.94/60Hz */
  238. [5] = {
  239. NULL, 60, 1920, 1080, 13763, 148, 88, 15, 2, 44, 5,
  240. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  241. FB_VMODE_INTERLACED, 0,
  242. },
  243. /* #7: 720(1440)x480iH@59.94/60Hz */
  244. [7] = {
  245. NULL, 60, 1440, 480, 18554/*37108*/, 114, 38, 15, 4, 124, 3, 0,
  246. FB_VMODE_INTERLACED, 0,
  247. },
  248. /* #9: 720(1440)x240pH@59.94/60Hz */
  249. [9] = {
  250. NULL, 60, 1440, 240, 18554, 114, 38, 16, 4, 124, 3, 0,
  251. FB_VMODE_NONINTERLACED, 0,
  252. },
  253. /* #18: 720x576pH@50Hz */
  254. [18] = {
  255. NULL, 50, 720, 576, 37037, 68, 12, 39, 5, 64, 5, 0,
  256. FB_VMODE_NONINTERLACED, 0,
  257. },
  258. /* #19: 1280x720p@50Hz */
  259. [19] = {
  260. NULL, 50, 1280, 720, 13468, 220, 440, 20, 5, 40, 5,
  261. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  262. FB_VMODE_NONINTERLACED, 0,
  263. },
  264. /* #20: 1920x1080i@50Hz */
  265. [20] = {
  266. NULL, 50, 1920, 1080, 13480, 148, 528, 15, 5, 528, 5,
  267. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  268. FB_VMODE_INTERLACED, 0,
  269. },
  270. /* #32: 1920x1080p@23.98/24Hz */
  271. [32] = {
  272. NULL, 24, 1920, 1080, 13468, 148, 638, 36, 4, 44, 5,
  273. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  274. FB_VMODE_NONINTERLACED, 0,
  275. },
  276. /* #35: (2880)x480p4x@59.94/60Hz */
  277. [35] = {
  278. NULL, 60, 2880, 480, 9250, 240, 64, 30, 9, 248, 6, 0,
  279. FB_VMODE_NONINTERLACED, 0,
  280. },
  281. };
  282. const struct fb_videomode vesa_modes[] = {
  283. /* 0 640x350-85 VESA */
  284. { NULL, 85, 640, 350, 31746, 96, 32, 60, 32, 64, 3,
  285. FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA},
  286. /* 1 640x400-85 VESA */
  287. { NULL, 85, 640, 400, 31746, 96, 32, 41, 01, 64, 3,
  288. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  289. /* 2 720x400-85 VESA */
  290. { NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
  291. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  292. /* 3 640x480-60 VESA */
  293. { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
  294. 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  295. /* 4 640x480-72 VESA */
  296. { NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
  297. 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  298. /* 5 640x480-75 VESA */
  299. { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
  300. 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  301. /* 6 640x480-85 VESA */
  302. { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
  303. 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  304. /* 7 800x600-56 VESA */
  305. { NULL, 56, 800, 600, 27777, 128, 24, 22, 01, 72, 2,
  306. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  307. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  308. /* 8 800x600-60 VESA */
  309. { NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
  310. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  311. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  312. /* 9 800x600-72 VESA */
  313. { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
  314. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  315. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  316. /* 10 800x600-75 VESA */
  317. { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
  318. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  319. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  320. /* 11 800x600-85 VESA */
  321. { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
  322. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  323. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  324. /* 12 1024x768i-43 VESA */
  325. { NULL, 43, 1024, 768, 22271, 56, 8, 41, 0, 176, 8,
  326. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  327. FB_VMODE_INTERLACED, FB_MODE_IS_VESA },
  328. /* 13 1024x768-60 VESA */
  329. { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
  330. 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  331. /* 14 1024x768-70 VESA */
  332. { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
  333. 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  334. /* 15 1024x768-75 VESA */
  335. { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
  336. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  337. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  338. /* 16 1024x768-85 VESA */
  339. { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
  340. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  341. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  342. /* 17 1152x864-75 VESA */
  343. { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
  344. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  345. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  346. /* 18 1280x960-60 VESA */
  347. { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
  348. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  349. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  350. /* 19 1280x960-85 VESA */
  351. { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
  352. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  353. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  354. /* 20 1280x1024-60 VESA */
  355. { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
  356. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  357. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  358. /* 21 1280x1024-75 VESA */
  359. { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
  360. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  361. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  362. /* 22 1280x1024-85 VESA */
  363. { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
  364. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  365. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  366. /* 23 1600x1200-60 VESA */
  367. { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
  368. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  369. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  370. /* 24 1600x1200-65 VESA */
  371. { NULL, 65, 1600, 1200, 5698, 304, 64, 46, 1, 192, 3,
  372. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  373. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  374. /* 25 1600x1200-70 VESA */
  375. { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
  376. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  377. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  378. /* 26 1600x1200-75 VESA */
  379. { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
  380. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  381. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  382. /* 27 1600x1200-85 VESA */
  383. { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
  384. FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
  385. FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  386. /* 28 1792x1344-60 VESA */
  387. { NULL, 60, 1792, 1344, 4882, 328, 128, 46, 1, 200, 3,
  388. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  389. /* 29 1792x1344-75 VESA */
  390. { NULL, 75, 1792, 1344, 3831, 352, 96, 69, 1, 216, 3,
  391. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  392. /* 30 1856x1392-60 VESA */
  393. { NULL, 60, 1856, 1392, 4580, 352, 96, 43, 1, 224, 3,
  394. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  395. /* 31 1856x1392-75 VESA */
  396. { NULL, 75, 1856, 1392, 3472, 352, 128, 104, 1, 224, 3,
  397. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  398. /* 32 1920x1440-60 VESA */
  399. { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 200, 3,
  400. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  401. /* 33 1920x1440-75 VESA */
  402. { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
  403. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  404. /* 34 1920x1200-60 RB VESA */
  405. { NULL, 60, 1920, 1200, 6493, 80, 48, 26, 3, 32, 6,
  406. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  407. /* 35 1920x1200-60 VESA */
  408. { NULL, 60, 1920, 1200, 5174, 336, 136, 36, 3, 200, 6,
  409. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  410. /* 36 1920x1200-75 VESA */
  411. { NULL, 75, 1920, 1200, 4077, 344, 136, 46, 3, 208, 6,
  412. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  413. /* 37 1920x1200-85 VESA */
  414. { NULL, 85, 1920, 1200, 3555, 352, 144, 53, 3, 208, 6,
  415. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  416. /* 38 2560x1600-60 RB VESA */
  417. { NULL, 60, 2560, 1600, 3724, 80, 48, 37, 3, 32, 6,
  418. FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  419. /* 39 2560x1600-60 VESA */
  420. { NULL, 60, 2560, 1600, 2869, 472, 192, 49, 3, 280, 6,
  421. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  422. /* 40 2560x1600-75 VESA */
  423. { NULL, 75, 2560, 1600, 2256, 488, 208, 63, 3, 280, 6,
  424. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  425. /* 41 2560x1600-85 VESA */
  426. { NULL, 85, 2560, 1600, 1979, 488, 208, 73, 3, 280, 6,
  427. FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  428. /* 42 2560x1600-120 RB VESA */
  429. { NULL, 120, 2560, 1600, 1809, 80, 48, 85, 3, 32, 6,
  430. FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
  431. };
  432. EXPORT_SYMBOL(vesa_modes);
  433. const struct dmt_videomode dmt_modes[DMT_SIZE] = {
  434. { 0x01, 0x0000, 0x000000, &vesa_modes[0] },
  435. { 0x02, 0x3119, 0x000000, &vesa_modes[1] },
  436. { 0x03, 0x0000, 0x000000, &vesa_modes[2] },
  437. { 0x04, 0x3140, 0x000000, &vesa_modes[3] },
  438. { 0x05, 0x314c, 0x000000, &vesa_modes[4] },
  439. { 0x06, 0x314f, 0x000000, &vesa_modes[5] },
  440. { 0x07, 0x3159, 0x000000, &vesa_modes[6] },
  441. { 0x08, 0x0000, 0x000000, &vesa_modes[7] },
  442. { 0x09, 0x4540, 0x000000, &vesa_modes[8] },
  443. { 0x0a, 0x454c, 0x000000, &vesa_modes[9] },
  444. { 0x0b, 0x454f, 0x000000, &vesa_modes[10] },
  445. { 0x0c, 0x4559, 0x000000, &vesa_modes[11] },
  446. { 0x0d, 0x0000, 0x000000, NULL },
  447. { 0x0e, 0x0000, 0x000000, NULL },
  448. { 0x0f, 0x0000, 0x000000, &vesa_modes[12] },
  449. { 0x10, 0x6140, 0x000000, &vesa_modes[13] },
  450. { 0x11, 0x614a, 0x000000, &vesa_modes[14] },
  451. { 0x12, 0x614f, 0x000000, &vesa_modes[15] },
  452. { 0x13, 0x6159, 0x000000, &vesa_modes[16] },
  453. { 0x14, 0x0000, 0x000000, NULL },
  454. { 0x15, 0x714f, 0x000000, &vesa_modes[17] },
  455. { 0x16, 0x0000, 0x7f1c21, NULL },
  456. { 0x17, 0x0000, 0x7f1c28, NULL },
  457. { 0x18, 0x0000, 0x7f1c44, NULL },
  458. { 0x19, 0x0000, 0x7f1c62, NULL },
  459. { 0x1a, 0x0000, 0x000000, NULL },
  460. { 0x1b, 0x0000, 0x8f1821, NULL },
  461. { 0x1c, 0x8100, 0x8f1828, NULL },
  462. { 0x1d, 0x810f, 0x8f1844, NULL },
  463. { 0x1e, 0x8119, 0x8f1862, NULL },
  464. { 0x1f, 0x0000, 0x000000, NULL },
  465. { 0x20, 0x8140, 0x000000, &vesa_modes[18] },
  466. { 0x21, 0x8159, 0x000000, &vesa_modes[19] },
  467. { 0x22, 0x0000, 0x000000, NULL },
  468. { 0x23, 0x8180, 0x000000, &vesa_modes[20] },
  469. { 0x24, 0x818f, 0x000000, &vesa_modes[21] },
  470. { 0x25, 0x8199, 0x000000, &vesa_modes[22] },
  471. { 0x26, 0x0000, 0x000000, NULL },
  472. { 0x27, 0x0000, 0x000000, NULL },
  473. { 0x28, 0x0000, 0x000000, NULL },
  474. { 0x29, 0x0000, 0x0c2021, NULL },
  475. { 0x2a, 0x9040, 0x0c2028, NULL },
  476. { 0x2b, 0x904f, 0x0c2044, NULL },
  477. { 0x2c, 0x9059, 0x0c2062, NULL },
  478. { 0x2d, 0x0000, 0x000000, NULL },
  479. { 0x2e, 0x9500, 0xc11821, NULL },
  480. { 0x2f, 0x9500, 0xc11828, NULL },
  481. { 0x30, 0x950f, 0xc11844, NULL },
  482. { 0x31, 0x9519, 0xc11868, NULL },
  483. { 0x32, 0x0000, 0x000000, NULL },
  484. { 0x33, 0xa940, 0x000000, &vesa_modes[23] },
  485. { 0x34, 0xa945, 0x000000, &vesa_modes[24] },
  486. { 0x35, 0xa94a, 0x000000, &vesa_modes[25] },
  487. { 0x36, 0xa94f, 0x000000, &vesa_modes[26] },
  488. { 0x37, 0xa959, 0x000000, &vesa_modes[27] },
  489. { 0x38, 0x0000, 0x000000, NULL },
  490. { 0x39, 0x0000, 0x0c2821, NULL },
  491. { 0x3a, 0xb300, 0x0c2828, NULL },
  492. { 0x3b, 0xb30f, 0x0c2844, NULL },
  493. { 0x3c, 0xb319, 0x0c2868, NULL },
  494. { 0x3d, 0x0000, 0x000000, NULL },
  495. { 0x3e, 0xc140, 0x000000, &vesa_modes[28] },
  496. { 0x3f, 0xc14f, 0x000000, &vesa_modes[29] },
  497. { 0x40, 0x0000, 0x000000, NULL},
  498. { 0x41, 0xc940, 0x000000, &vesa_modes[30] },
  499. { 0x42, 0xc94f, 0x000000, &vesa_modes[31] },
  500. { 0x43, 0x0000, 0x000000, NULL },
  501. { 0x44, 0x0000, 0x572821, &vesa_modes[34] },
  502. { 0x45, 0xd100, 0x572828, &vesa_modes[35] },
  503. { 0x46, 0xd10f, 0x572844, &vesa_modes[36] },
  504. { 0x47, 0xd119, 0x572862, &vesa_modes[37] },
  505. { 0x48, 0x0000, 0x000000, NULL },
  506. { 0x49, 0xd140, 0x000000, &vesa_modes[32] },
  507. { 0x4a, 0xd14f, 0x000000, &vesa_modes[33] },
  508. { 0x4b, 0x0000, 0x000000, NULL },
  509. { 0x4c, 0x0000, 0x1f3821, &vesa_modes[38] },
  510. { 0x4d, 0x0000, 0x1f3828, &vesa_modes[39] },
  511. { 0x4e, 0x0000, 0x1f3844, &vesa_modes[40] },
  512. { 0x4f, 0x0000, 0x1f3862, &vesa_modes[41] },
  513. { 0x50, 0x0000, 0x000000, &vesa_modes[42] },
  514. };
  515. EXPORT_SYMBOL(dmt_modes);
  516. #endif /* CONFIG_FB_MODE_HELPERS */
  517. /**
  518. * fb_try_mode - test a video mode
  519. * @var: frame buffer user defined part of display
  520. * @info: frame buffer info structure
  521. * @mode: frame buffer video mode structure
  522. * @bpp: color depth in bits per pixel
  523. *
  524. * Tries a video mode to test it's validity for device @info.
  525. *
  526. * Returns 1 on success.
  527. *
  528. */
  529. static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
  530. const struct fb_videomode *mode, unsigned int bpp)
  531. {
  532. int err = 0;
  533. DPRINTK("Trying mode %s %dx%d-%d@%d\n",
  534. mode->name ? mode->name : "noname",
  535. mode->xres, mode->yres, bpp, mode->refresh);
  536. var->xres = mode->xres;
  537. var->yres = mode->yres;
  538. var->xres_virtual = mode->xres;
  539. var->yres_virtual = mode->yres;
  540. var->xoffset = 0;
  541. var->yoffset = 0;
  542. var->bits_per_pixel = bpp;
  543. var->activate |= FB_ACTIVATE_TEST;
  544. var->pixclock = mode->pixclock;
  545. var->left_margin = mode->left_margin;
  546. var->right_margin = mode->right_margin;
  547. var->upper_margin = mode->upper_margin;
  548. var->lower_margin = mode->lower_margin;
  549. var->hsync_len = mode->hsync_len;
  550. var->vsync_len = mode->vsync_len;
  551. var->sync = mode->sync;
  552. var->vmode = mode->vmode;
  553. if (info->fbops->fb_check_var)
  554. err = info->fbops->fb_check_var(var, info);
  555. var->activate &= ~FB_ACTIVATE_TEST;
  556. return err;
  557. }
  558. /**
  559. * fb_find_mode - finds a valid video mode
  560. * @var: frame buffer user defined part of display
  561. * @info: frame buffer info structure
  562. * @mode_option: string video mode to find
  563. * @db: video mode database
  564. * @dbsize: size of @db
  565. * @default_mode: default video mode to fall back to
  566. * @default_bpp: default color depth in bits per pixel
  567. *
  568. * Finds a suitable video mode, starting with the specified mode
  569. * in @mode_option with fallback to @default_mode. If
  570. * @default_mode fails, all modes in the video mode database will
  571. * be tried.
  572. *
  573. * Valid mode specifiers for @mode_option:
  574. *
  575. * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
  576. * <name>[-<bpp>][@<refresh>]
  577. *
  578. * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
  579. * <name> a string.
  580. *
  581. * If 'M' is present after yres (and before refresh/bpp if present),
  582. * the function will compute the timings using VESA(tm) Coordinated
  583. * Video Timings (CVT). If 'R' is present after 'M', will compute with
  584. * reduced blanking (for flatpanels). If 'i' is present, compute
  585. * interlaced mode. If 'm' is present, add margins equal to 1.8%
  586. * of xres rounded down to 8 pixels, and 1.8% of yres. The char
  587. * 'i' and 'm' must be after 'M' and 'R'. Example:
  588. *
  589. * 1024x768MR-8@60m - Reduced blank with margins at 60Hz.
  590. *
  591. * NOTE: The passed struct @var is _not_ cleared! This allows you
  592. * to supply values for e.g. the grayscale and accel_flags fields.
  593. *
  594. * Returns zero for failure, 1 if using specified @mode_option,
  595. * 2 if using specified @mode_option with an ignored refresh rate,
  596. * 3 if default mode is used, 4 if fall back to any valid mode.
  597. *
  598. */
  599. int fb_find_mode(struct fb_var_screeninfo *var,
  600. struct fb_info *info, const char *mode_option,
  601. const struct fb_videomode *db, unsigned int dbsize,
  602. const struct fb_videomode *default_mode,
  603. unsigned int default_bpp)
  604. {
  605. int i;
  606. /* Set up defaults */
  607. if (!db) {
  608. db = modedb;
  609. dbsize = ARRAY_SIZE(modedb);
  610. }
  611. if (!default_mode)
  612. default_mode = &db[0];
  613. if (!default_bpp)
  614. default_bpp = 8;
  615. /* Did the user specify a video mode? */
  616. if (!mode_option)
  617. mode_option = fb_mode_option;
  618. if (mode_option) {
  619. const char *name = mode_option;
  620. unsigned int namelen = strlen(name);
  621. int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
  622. unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
  623. int yres_specified = 0, cvt = 0, rb = 0, interlace = 0;
  624. int margins = 0;
  625. u32 best, diff, tdiff;
  626. for (i = namelen-1; i >= 0; i--) {
  627. switch (name[i]) {
  628. case '@':
  629. namelen = i;
  630. if (!refresh_specified && !bpp_specified &&
  631. !yres_specified) {
  632. refresh = simple_strtol(&name[i+1], NULL,
  633. 10);
  634. refresh_specified = 1;
  635. if (cvt || rb)
  636. cvt = 0;
  637. } else
  638. goto done;
  639. break;
  640. case '-':
  641. namelen = i;
  642. if (!bpp_specified && !yres_specified) {
  643. bpp = simple_strtol(&name[i+1], NULL,
  644. 10);
  645. bpp_specified = 1;
  646. if (cvt || rb)
  647. cvt = 0;
  648. } else
  649. goto done;
  650. break;
  651. case 'x':
  652. if (!yres_specified) {
  653. yres = simple_strtol(&name[i+1], NULL,
  654. 10);
  655. yres_specified = 1;
  656. } else
  657. goto done;
  658. break;
  659. case '0' ... '9':
  660. break;
  661. case 'M':
  662. if (!yres_specified)
  663. cvt = 1;
  664. break;
  665. case 'R':
  666. if (!cvt)
  667. rb = 1;
  668. break;
  669. case 'm':
  670. if (!cvt)
  671. margins = 1;
  672. break;
  673. case 'i':
  674. if (!cvt)
  675. interlace = 1;
  676. break;
  677. default:
  678. goto done;
  679. }
  680. }
  681. if (i < 0 && yres_specified) {
  682. xres = simple_strtol(name, NULL, 10);
  683. res_specified = 1;
  684. }
  685. done:
  686. if (cvt) {
  687. struct fb_videomode cvt_mode;
  688. int ret;
  689. DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
  690. (refresh) ? refresh : 60,
  691. (rb) ? " reduced blanking" : "",
  692. (margins) ? " with margins" : "",
  693. (interlace) ? " interlaced" : "");
  694. memset(&cvt_mode, 0, sizeof(cvt_mode));
  695. cvt_mode.xres = xres;
  696. cvt_mode.yres = yres;
  697. cvt_mode.refresh = (refresh) ? refresh : 60;
  698. if (interlace)
  699. cvt_mode.vmode |= FB_VMODE_INTERLACED;
  700. else
  701. cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
  702. ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
  703. if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
  704. DPRINTK("modedb CVT: CVT mode ok\n");
  705. return 1;
  706. }
  707. DPRINTK("CVT mode invalid, getting mode from database\n");
  708. }
  709. DPRINTK("Trying specified video mode%s %ix%i\n",
  710. refresh_specified ? "" : " (ignoring refresh rate)",
  711. xres, yres);
  712. if (!refresh_specified) {
  713. /*
  714. * If the caller has provided a custom mode database and
  715. * a valid monspecs structure, we look for the mode with
  716. * the highest refresh rate. Otherwise we play it safe
  717. * it and try to find a mode with a refresh rate closest
  718. * to the standard 60 Hz.
  719. */
  720. if (db != modedb &&
  721. info->monspecs.vfmin && info->monspecs.vfmax &&
  722. info->monspecs.hfmin && info->monspecs.hfmax &&
  723. info->monspecs.dclkmax) {
  724. refresh = 1000;
  725. } else {
  726. refresh = 60;
  727. }
  728. }
  729. diff = -1;
  730. best = -1;
  731. for (i = 0; i < dbsize; i++) {
  732. if ((name_matches(db[i], name, namelen) ||
  733. (res_specified && res_matches(db[i], xres, yres))) &&
  734. !fb_try_mode(var, info, &db[i], bpp)) {
  735. if (refresh_specified && db[i].refresh == refresh)
  736. return 1;
  737. if (abs(db[i].refresh - refresh) < diff) {
  738. diff = abs(db[i].refresh - refresh);
  739. best = i;
  740. }
  741. }
  742. }
  743. if (best != -1) {
  744. fb_try_mode(var, info, &db[best], bpp);
  745. return (refresh_specified) ? 2 : 1;
  746. }
  747. diff = 2 * (xres + yres);
  748. best = -1;
  749. DPRINTK("Trying best-fit modes\n");
  750. for (i = 0; i < dbsize; i++) {
  751. DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
  752. if (!fb_try_mode(var, info, &db[i], bpp)) {
  753. tdiff = abs(db[i].xres - xres) +
  754. abs(db[i].yres - yres);
  755. /*
  756. * Penalize modes with resolutions smaller
  757. * than requested.
  758. */
  759. if (xres > db[i].xres || yres > db[i].yres)
  760. tdiff += xres + yres;
  761. if (diff > tdiff) {
  762. diff = tdiff;
  763. best = i;
  764. }
  765. }
  766. }
  767. if (best != -1) {
  768. fb_try_mode(var, info, &db[best], bpp);
  769. return 5;
  770. }
  771. }
  772. DPRINTK("Trying default video mode\n");
  773. if (!fb_try_mode(var, info, default_mode, default_bpp))
  774. return 3;
  775. DPRINTK("Trying all modes\n");
  776. for (i = 0; i < dbsize; i++)
  777. if (!fb_try_mode(var, info, &db[i], default_bpp))
  778. return 4;
  779. DPRINTK("No valid mode found\n");
  780. return 0;
  781. }
  782. /**
  783. * fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
  784. * @mode: pointer to struct fb_videomode
  785. * @var: pointer to struct fb_var_screeninfo
  786. */
  787. void fb_var_to_videomode(struct fb_videomode *mode,
  788. const struct fb_var_screeninfo *var)
  789. {
  790. u32 pixclock, hfreq, htotal, vtotal;
  791. mode->name = NULL;
  792. mode->xres = var->xres;
  793. mode->yres = var->yres;
  794. mode->pixclock = var->pixclock;
  795. mode->hsync_len = var->hsync_len;
  796. mode->vsync_len = var->vsync_len;
  797. mode->left_margin = var->left_margin;
  798. mode->right_margin = var->right_margin;
  799. mode->upper_margin = var->upper_margin;
  800. mode->lower_margin = var->lower_margin;
  801. mode->sync = var->sync;
  802. mode->vmode = var->vmode & FB_VMODE_MASK;
  803. mode->flag = FB_MODE_IS_FROM_VAR;
  804. mode->refresh = 0;
  805. if (!var->pixclock)
  806. return;
  807. pixclock = PICOS2KHZ(var->pixclock) * 1000;
  808. htotal = var->xres + var->right_margin + var->hsync_len +
  809. var->left_margin;
  810. vtotal = var->yres + var->lower_margin + var->vsync_len +
  811. var->upper_margin;
  812. if (var->vmode & FB_VMODE_INTERLACED)
  813. vtotal /= 2;
  814. if (var->vmode & FB_VMODE_DOUBLE)
  815. vtotal *= 2;
  816. hfreq = pixclock/htotal;
  817. mode->refresh = hfreq/vtotal;
  818. }
  819. /**
  820. * fb_videomode_to_var - convert fb_videomode to fb_var_screeninfo
  821. * @var: pointer to struct fb_var_screeninfo
  822. * @mode: pointer to struct fb_videomode
  823. */
  824. void fb_videomode_to_var(struct fb_var_screeninfo *var,
  825. const struct fb_videomode *mode)
  826. {
  827. var->xres = mode->xres;
  828. var->yres = mode->yres;
  829. var->xres_virtual = mode->xres;
  830. var->yres_virtual = mode->yres;
  831. var->xoffset = 0;
  832. var->yoffset = 0;
  833. var->pixclock = mode->pixclock;
  834. var->left_margin = mode->left_margin;
  835. var->right_margin = mode->right_margin;
  836. var->upper_margin = mode->upper_margin;
  837. var->lower_margin = mode->lower_margin;
  838. var->hsync_len = mode->hsync_len;
  839. var->vsync_len = mode->vsync_len;
  840. var->sync = mode->sync;
  841. var->vmode = mode->vmode & FB_VMODE_MASK;
  842. }
  843. /**
  844. * fb_mode_is_equal - compare 2 videomodes
  845. * @mode1: first videomode
  846. * @mode2: second videomode
  847. *
  848. * RETURNS:
  849. * 1 if equal, 0 if not
  850. */
  851. int fb_mode_is_equal(const struct fb_videomode *mode1,
  852. const struct fb_videomode *mode2)
  853. {
  854. return (mode1->xres == mode2->xres &&
  855. mode1->yres == mode2->yres &&
  856. mode1->pixclock == mode2->pixclock &&
  857. mode1->hsync_len == mode2->hsync_len &&
  858. mode1->vsync_len == mode2->vsync_len &&
  859. mode1->left_margin == mode2->left_margin &&
  860. mode1->right_margin == mode2->right_margin &&
  861. mode1->upper_margin == mode2->upper_margin &&
  862. mode1->lower_margin == mode2->lower_margin &&
  863. mode1->sync == mode2->sync &&
  864. mode1->vmode == mode2->vmode);
  865. }
  866. /**
  867. * fb_find_best_mode - find best matching videomode
  868. * @var: pointer to struct fb_var_screeninfo
  869. * @head: pointer to struct list_head of modelist
  870. *
  871. * RETURNS:
  872. * struct fb_videomode, NULL if none found
  873. *
  874. * IMPORTANT:
  875. * This function assumes that all modelist entries in
  876. * info->modelist are valid.
  877. *
  878. * NOTES:
  879. * Finds best matching videomode which has an equal or greater dimension than
  880. * var->xres and var->yres. If more than 1 videomode is found, will return
  881. * the videomode with the highest refresh rate
  882. */
  883. const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
  884. struct list_head *head)
  885. {
  886. struct list_head *pos;
  887. struct fb_modelist *modelist;
  888. struct fb_videomode *mode, *best = NULL;
  889. u32 diff = -1;
  890. list_for_each(pos, head) {
  891. u32 d;
  892. modelist = list_entry(pos, struct fb_modelist, list);
  893. mode = &modelist->mode;
  894. if (mode->xres >= var->xres && mode->yres >= var->yres) {
  895. d = (mode->xres - var->xres) +
  896. (mode->yres - var->yres);
  897. if (diff > d) {
  898. diff = d;
  899. best = mode;
  900. } else if (diff == d && best &&
  901. mode->refresh > best->refresh)
  902. best = mode;
  903. }
  904. }
  905. return best;
  906. }
  907. /**
  908. * fb_find_nearest_mode - find closest videomode
  909. *
  910. * @mode: pointer to struct fb_videomode
  911. * @head: pointer to modelist
  912. *
  913. * Finds best matching videomode, smaller or greater in dimension.
  914. * If more than 1 videomode is found, will return the videomode with
  915. * the closest refresh rate.
  916. */
  917. const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
  918. struct list_head *head)
  919. {
  920. struct list_head *pos;
  921. struct fb_modelist *modelist;
  922. struct fb_videomode *cmode, *best = NULL;
  923. u32 diff = -1, diff_refresh = -1;
  924. list_for_each(pos, head) {
  925. u32 d;
  926. modelist = list_entry(pos, struct fb_modelist, list);
  927. cmode = &modelist->mode;
  928. d = abs(cmode->xres - mode->xres) +
  929. abs(cmode->yres - mode->yres);
  930. if (diff > d) {
  931. diff = d;
  932. diff_refresh = abs(cmode->refresh - mode->refresh);
  933. best = cmode;
  934. } else if (diff == d) {
  935. d = abs(cmode->refresh - mode->refresh);
  936. if (diff_refresh > d) {
  937. diff_refresh = d;
  938. best = cmode;
  939. }
  940. }
  941. }
  942. return best;
  943. }
  944. /**
  945. * fb_match_mode - find a videomode which exactly matches the timings in var
  946. * @var: pointer to struct fb_var_screeninfo
  947. * @head: pointer to struct list_head of modelist
  948. *
  949. * RETURNS:
  950. * struct fb_videomode, NULL if none found
  951. */
  952. const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
  953. struct list_head *head)
  954. {
  955. struct list_head *pos;
  956. struct fb_modelist *modelist;
  957. struct fb_videomode *m, mode;
  958. fb_var_to_videomode(&mode, var);
  959. list_for_each(pos, head) {
  960. modelist = list_entry(pos, struct fb_modelist, list);
  961. m = &modelist->mode;
  962. if (fb_mode_is_equal(m, &mode))
  963. return m;
  964. }
  965. return NULL;
  966. }
  967. /**
  968. * fb_add_videomode - adds videomode entry to modelist
  969. * @mode: videomode to add
  970. * @head: struct list_head of modelist
  971. *
  972. * NOTES:
  973. * Will only add unmatched mode entries
  974. */
  975. int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
  976. {
  977. struct list_head *pos;
  978. struct fb_modelist *modelist;
  979. struct fb_videomode *m;
  980. int found = 0;
  981. list_for_each(pos, head) {
  982. modelist = list_entry(pos, struct fb_modelist, list);
  983. m = &modelist->mode;
  984. if (fb_mode_is_equal(m, mode)) {
  985. found = 1;
  986. break;
  987. }
  988. }
  989. if (!found) {
  990. modelist = kmalloc(sizeof(struct fb_modelist),
  991. GFP_KERNEL);
  992. if (!modelist)
  993. return -ENOMEM;
  994. modelist->mode = *mode;
  995. list_add(&modelist->list, head);
  996. }
  997. return 0;
  998. }
  999. /**
  1000. * fb_delete_videomode - removed videomode entry from modelist
  1001. * @mode: videomode to remove
  1002. * @head: struct list_head of modelist
  1003. *
  1004. * NOTES:
  1005. * Will remove all matching mode entries
  1006. */
  1007. void fb_delete_videomode(const struct fb_videomode *mode,
  1008. struct list_head *head)
  1009. {
  1010. struct list_head *pos, *n;
  1011. struct fb_modelist *modelist;
  1012. struct fb_videomode *m;
  1013. list_for_each_safe(pos, n, head) {
  1014. modelist = list_entry(pos, struct fb_modelist, list);
  1015. m = &modelist->mode;
  1016. if (fb_mode_is_equal(m, mode)) {
  1017. list_del(pos);
  1018. kfree(pos);
  1019. }
  1020. }
  1021. }
  1022. /**
  1023. * fb_destroy_modelist - destroy modelist
  1024. * @head: struct list_head of modelist
  1025. */
  1026. void fb_destroy_modelist(struct list_head *head)
  1027. {
  1028. struct list_head *pos, *n;
  1029. list_for_each_safe(pos, n, head) {
  1030. list_del(pos);
  1031. kfree(pos);
  1032. }
  1033. }
  1034. EXPORT_SYMBOL_GPL(fb_destroy_modelist);
  1035. /**
  1036. * fb_videomode_to_modelist - convert mode array to mode list
  1037. * @modedb: array of struct fb_videomode
  1038. * @num: number of entries in array
  1039. * @head: struct list_head of modelist
  1040. */
  1041. void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
  1042. struct list_head *head)
  1043. {
  1044. int i;
  1045. INIT_LIST_HEAD(head);
  1046. for (i = 0; i < num; i++) {
  1047. if (fb_add_videomode(&modedb[i], head))
  1048. return;
  1049. }
  1050. }
  1051. const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
  1052. struct list_head *head)
  1053. {
  1054. struct list_head *pos;
  1055. struct fb_modelist *modelist;
  1056. const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
  1057. int first = 0;
  1058. if (!head->prev || !head->next || list_empty(head))
  1059. goto finished;
  1060. /* get the first detailed mode and the very first mode */
  1061. list_for_each(pos, head) {
  1062. modelist = list_entry(pos, struct fb_modelist, list);
  1063. m = &modelist->mode;
  1064. if (!first) {
  1065. m1 = m;
  1066. first = 1;
  1067. }
  1068. if (m->flag & FB_MODE_IS_FIRST) {
  1069. md = m;
  1070. break;
  1071. }
  1072. }
  1073. /* first detailed timing is preferred */
  1074. if (specs->misc & FB_MISC_1ST_DETAIL) {
  1075. best = md;
  1076. goto finished;
  1077. }
  1078. /* find best mode based on display width and height */
  1079. if (specs->max_x && specs->max_y) {
  1080. struct fb_var_screeninfo var;
  1081. memset(&var, 0, sizeof(struct fb_var_screeninfo));
  1082. var.xres = (specs->max_x * 7200)/254;
  1083. var.yres = (specs->max_y * 7200)/254;
  1084. m = fb_find_best_mode(&var, head);
  1085. if (m) {
  1086. best = m;
  1087. goto finished;
  1088. }
  1089. }
  1090. /* use first detailed mode */
  1091. if (md) {
  1092. best = md;
  1093. goto finished;
  1094. }
  1095. /* last resort, use the very first mode */
  1096. best = m1;
  1097. finished:
  1098. return best;
  1099. }
  1100. EXPORT_SYMBOL(fb_find_best_display);
  1101. EXPORT_SYMBOL(fb_videomode_to_var);
  1102. EXPORT_SYMBOL(fb_var_to_videomode);
  1103. EXPORT_SYMBOL(fb_mode_is_equal);
  1104. EXPORT_SYMBOL(fb_add_videomode);
  1105. EXPORT_SYMBOL(fb_match_mode);
  1106. EXPORT_SYMBOL(fb_find_best_mode);
  1107. EXPORT_SYMBOL(fb_find_nearest_mode);
  1108. EXPORT_SYMBOL(fb_videomode_to_modelist);
  1109. EXPORT_SYMBOL(fb_find_mode);
  1110. EXPORT_SYMBOL(fb_find_mode_cvt);