modedb.c 32 KB

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