modedb.c 31 KB

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