modedb.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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[65] = {
  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][p][m]
  576. *
  577. * or ::
  578. *
  579. * <name>[-<bpp>][@<refresh>]
  580. *
  581. * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
  582. * <name> a string.
  583. *
  584. * If 'M' is present after yres (and before refresh/bpp if present),
  585. * the function will compute the timings using VESA(tm) Coordinated
  586. * Video Timings (CVT). If 'R' is present after 'M', will compute with
  587. * reduced blanking (for flatpanels). If 'i' or 'p' are present, compute
  588. * interlaced or progressive mode. If 'm' is present, add margins equal
  589. * to 1.8% of xres rounded down to 8 pixels, and 1.8% of yres. The char
  590. * 'i', 'p' and 'm' must be after 'M' and 'R'. Example::
  591. *
  592. * 1024x768MR-8@60m - Reduced blank with margins at 60Hz.
  593. *
  594. * NOTE: The passed struct @var is _not_ cleared! This allows you
  595. * to supply values for e.g. the grayscale and accel_flags fields.
  596. *
  597. * Returns zero for failure, 1 if using specified @mode_option,
  598. * 2 if using specified @mode_option with an ignored refresh rate,
  599. * 3 if default mode is used, 4 if fall back to any valid mode.
  600. */
  601. int fb_find_mode(struct fb_var_screeninfo *var,
  602. struct fb_info *info, const char *mode_option,
  603. const struct fb_videomode *db, unsigned int dbsize,
  604. const struct fb_videomode *default_mode,
  605. unsigned int default_bpp)
  606. {
  607. int i;
  608. /* Set up defaults */
  609. if (!db) {
  610. db = modedb;
  611. dbsize = ARRAY_SIZE(modedb);
  612. }
  613. if (!default_mode)
  614. default_mode = &db[0];
  615. if (!default_bpp)
  616. default_bpp = 8;
  617. /* Did the user specify a video mode? */
  618. if (!mode_option)
  619. mode_option = fb_mode_option;
  620. if (mode_option) {
  621. const char *name = mode_option;
  622. unsigned int namelen = strlen(name);
  623. int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
  624. unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
  625. int yres_specified = 0, cvt = 0, rb = 0;
  626. int interlace_specified = 0, interlace = 0;
  627. int margins = 0;
  628. u32 best, diff, tdiff;
  629. for (i = namelen-1; i >= 0; i--) {
  630. switch (name[i]) {
  631. case '@':
  632. namelen = i;
  633. if (!refresh_specified && !bpp_specified &&
  634. !yres_specified) {
  635. refresh = simple_strtol(&name[i+1], NULL,
  636. 10);
  637. refresh_specified = 1;
  638. if (cvt || rb)
  639. cvt = 0;
  640. } else
  641. goto done;
  642. break;
  643. case '-':
  644. namelen = i;
  645. if (!bpp_specified && !yres_specified) {
  646. bpp = simple_strtol(&name[i+1], NULL,
  647. 10);
  648. bpp_specified = 1;
  649. if (cvt || rb)
  650. cvt = 0;
  651. } else
  652. goto done;
  653. break;
  654. case 'x':
  655. if (!yres_specified) {
  656. yres = simple_strtol(&name[i+1], NULL,
  657. 10);
  658. yres_specified = 1;
  659. } else
  660. goto done;
  661. break;
  662. case '0' ... '9':
  663. break;
  664. case 'M':
  665. if (!yres_specified)
  666. cvt = 1;
  667. break;
  668. case 'R':
  669. if (!cvt)
  670. rb = 1;
  671. break;
  672. case 'm':
  673. if (!cvt)
  674. margins = 1;
  675. break;
  676. case 'p':
  677. if (!cvt) {
  678. interlace = 0;
  679. interlace_specified = 1;
  680. }
  681. break;
  682. case 'i':
  683. if (!cvt) {
  684. interlace = 1;
  685. interlace_specified = 1;
  686. }
  687. break;
  688. default:
  689. goto done;
  690. }
  691. }
  692. if (i < 0 && yres_specified) {
  693. xres = simple_strtol(name, NULL, 10);
  694. res_specified = 1;
  695. }
  696. done:
  697. if (cvt) {
  698. struct fb_videomode cvt_mode;
  699. int ret;
  700. DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
  701. (refresh) ? refresh : 60,
  702. (rb) ? " reduced blanking" : "",
  703. (margins) ? " with margins" : "",
  704. (interlace) ? " interlaced" : "");
  705. memset(&cvt_mode, 0, sizeof(cvt_mode));
  706. cvt_mode.xres = xres;
  707. cvt_mode.yres = yres;
  708. cvt_mode.refresh = (refresh) ? refresh : 60;
  709. if (interlace)
  710. cvt_mode.vmode |= FB_VMODE_INTERLACED;
  711. else
  712. cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
  713. ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
  714. if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
  715. DPRINTK("modedb CVT: CVT mode ok\n");
  716. return 1;
  717. }
  718. DPRINTK("CVT mode invalid, getting mode from database\n");
  719. }
  720. DPRINTK("Trying specified video mode%s %ix%i\n",
  721. refresh_specified ? "" : " (ignoring refresh rate)",
  722. xres, yres);
  723. if (!refresh_specified) {
  724. /*
  725. * If the caller has provided a custom mode database and
  726. * a valid monspecs structure, we look for the mode with
  727. * the highest refresh rate. Otherwise we play it safe
  728. * it and try to find a mode with a refresh rate closest
  729. * to the standard 60 Hz.
  730. */
  731. if (db != modedb &&
  732. info->monspecs.vfmin && info->monspecs.vfmax &&
  733. info->monspecs.hfmin && info->monspecs.hfmax &&
  734. info->monspecs.dclkmax) {
  735. refresh = 1000;
  736. } else {
  737. refresh = 60;
  738. }
  739. }
  740. diff = -1;
  741. best = -1;
  742. for (i = 0; i < dbsize; i++) {
  743. if ((name_matches(db[i], name, namelen) ||
  744. (res_specified && res_matches(db[i], xres, yres))) &&
  745. !fb_try_mode(var, info, &db[i], bpp)) {
  746. const int db_interlace = (db[i].vmode &
  747. FB_VMODE_INTERLACED ? 1 : 0);
  748. int score = abs(db[i].refresh - refresh);
  749. if (interlace_specified)
  750. score += abs(db_interlace - interlace);
  751. if (!interlace_specified ||
  752. db_interlace == interlace)
  753. if (refresh_specified &&
  754. db[i].refresh == refresh)
  755. return 1;
  756. if (score < diff) {
  757. diff = score;
  758. best = i;
  759. }
  760. }
  761. }
  762. if (best != -1) {
  763. fb_try_mode(var, info, &db[best], bpp);
  764. return (refresh_specified) ? 2 : 1;
  765. }
  766. diff = 2 * (xres + yres);
  767. best = -1;
  768. DPRINTK("Trying best-fit modes\n");
  769. for (i = 0; i < dbsize; i++) {
  770. DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
  771. if (!fb_try_mode(var, info, &db[i], bpp)) {
  772. tdiff = abs(db[i].xres - xres) +
  773. abs(db[i].yres - yres);
  774. /*
  775. * Penalize modes with resolutions smaller
  776. * than requested.
  777. */
  778. if (xres > db[i].xres || yres > db[i].yres)
  779. tdiff += xres + yres;
  780. if (diff > tdiff) {
  781. diff = tdiff;
  782. best = i;
  783. }
  784. }
  785. }
  786. if (best != -1) {
  787. fb_try_mode(var, info, &db[best], bpp);
  788. return 5;
  789. }
  790. }
  791. DPRINTK("Trying default video mode\n");
  792. if (!fb_try_mode(var, info, default_mode, default_bpp))
  793. return 3;
  794. DPRINTK("Trying all modes\n");
  795. for (i = 0; i < dbsize; i++)
  796. if (!fb_try_mode(var, info, &db[i], default_bpp))
  797. return 4;
  798. DPRINTK("No valid mode found\n");
  799. return 0;
  800. }
  801. /**
  802. * fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
  803. * @mode: pointer to struct fb_videomode
  804. * @var: pointer to struct fb_var_screeninfo
  805. */
  806. void fb_var_to_videomode(struct fb_videomode *mode,
  807. const struct fb_var_screeninfo *var)
  808. {
  809. u32 pixclock, hfreq, htotal, vtotal;
  810. mode->name = NULL;
  811. mode->xres = var->xres;
  812. mode->yres = var->yres;
  813. mode->pixclock = var->pixclock;
  814. mode->hsync_len = var->hsync_len;
  815. mode->vsync_len = var->vsync_len;
  816. mode->left_margin = var->left_margin;
  817. mode->right_margin = var->right_margin;
  818. mode->upper_margin = var->upper_margin;
  819. mode->lower_margin = var->lower_margin;
  820. mode->sync = var->sync;
  821. mode->vmode = var->vmode & FB_VMODE_MASK;
  822. mode->flag = FB_MODE_IS_FROM_VAR;
  823. mode->refresh = 0;
  824. if (!var->pixclock)
  825. return;
  826. pixclock = PICOS2KHZ(var->pixclock) * 1000;
  827. htotal = var->xres + var->right_margin + var->hsync_len +
  828. var->left_margin;
  829. vtotal = var->yres + var->lower_margin + var->vsync_len +
  830. var->upper_margin;
  831. if (var->vmode & FB_VMODE_INTERLACED)
  832. vtotal /= 2;
  833. if (var->vmode & FB_VMODE_DOUBLE)
  834. vtotal *= 2;
  835. hfreq = pixclock/htotal;
  836. mode->refresh = hfreq/vtotal;
  837. }
  838. /**
  839. * fb_videomode_to_var - convert fb_videomode to fb_var_screeninfo
  840. * @var: pointer to struct fb_var_screeninfo
  841. * @mode: pointer to struct fb_videomode
  842. */
  843. void fb_videomode_to_var(struct fb_var_screeninfo *var,
  844. const struct fb_videomode *mode)
  845. {
  846. var->xres = mode->xres;
  847. var->yres = mode->yres;
  848. var->xres_virtual = mode->xres;
  849. var->yres_virtual = mode->yres;
  850. var->xoffset = 0;
  851. var->yoffset = 0;
  852. var->pixclock = mode->pixclock;
  853. var->left_margin = mode->left_margin;
  854. var->right_margin = mode->right_margin;
  855. var->upper_margin = mode->upper_margin;
  856. var->lower_margin = mode->lower_margin;
  857. var->hsync_len = mode->hsync_len;
  858. var->vsync_len = mode->vsync_len;
  859. var->sync = mode->sync;
  860. var->vmode = mode->vmode & FB_VMODE_MASK;
  861. }
  862. /**
  863. * fb_mode_is_equal - compare 2 videomodes
  864. * @mode1: first videomode
  865. * @mode2: second videomode
  866. *
  867. * RETURNS:
  868. * 1 if equal, 0 if not
  869. */
  870. int fb_mode_is_equal(const struct fb_videomode *mode1,
  871. const struct fb_videomode *mode2)
  872. {
  873. return (mode1->xres == mode2->xres &&
  874. mode1->yres == mode2->yres &&
  875. mode1->pixclock == mode2->pixclock &&
  876. mode1->hsync_len == mode2->hsync_len &&
  877. mode1->vsync_len == mode2->vsync_len &&
  878. mode1->left_margin == mode2->left_margin &&
  879. mode1->right_margin == mode2->right_margin &&
  880. mode1->upper_margin == mode2->upper_margin &&
  881. mode1->lower_margin == mode2->lower_margin &&
  882. mode1->sync == mode2->sync &&
  883. mode1->vmode == mode2->vmode);
  884. }
  885. /**
  886. * fb_find_best_mode - find best matching videomode
  887. * @var: pointer to struct fb_var_screeninfo
  888. * @head: pointer to struct list_head of modelist
  889. *
  890. * RETURNS:
  891. * struct fb_videomode, NULL if none found
  892. *
  893. * IMPORTANT:
  894. * This function assumes that all modelist entries in
  895. * info->modelist are valid.
  896. *
  897. * NOTES:
  898. * Finds best matching videomode which has an equal or greater dimension than
  899. * var->xres and var->yres. If more than 1 videomode is found, will return
  900. * the videomode with the highest refresh rate
  901. */
  902. const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
  903. struct list_head *head)
  904. {
  905. struct list_head *pos;
  906. struct fb_modelist *modelist;
  907. struct fb_videomode *mode, *best = NULL;
  908. u32 diff = -1;
  909. list_for_each(pos, head) {
  910. u32 d;
  911. modelist = list_entry(pos, struct fb_modelist, list);
  912. mode = &modelist->mode;
  913. if (mode->xres >= var->xres && mode->yres >= var->yres) {
  914. d = (mode->xres - var->xres) +
  915. (mode->yres - var->yres);
  916. if (diff > d) {
  917. diff = d;
  918. best = mode;
  919. } else if (diff == d && best &&
  920. mode->refresh > best->refresh)
  921. best = mode;
  922. }
  923. }
  924. return best;
  925. }
  926. /**
  927. * fb_find_nearest_mode - find closest videomode
  928. *
  929. * @mode: pointer to struct fb_videomode
  930. * @head: pointer to modelist
  931. *
  932. * Finds best matching videomode, smaller or greater in dimension.
  933. * If more than 1 videomode is found, will return the videomode with
  934. * the closest refresh rate.
  935. */
  936. const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
  937. struct list_head *head)
  938. {
  939. struct list_head *pos;
  940. struct fb_modelist *modelist;
  941. struct fb_videomode *cmode, *best = NULL;
  942. u32 diff = -1, diff_refresh = -1;
  943. list_for_each(pos, head) {
  944. u32 d;
  945. modelist = list_entry(pos, struct fb_modelist, list);
  946. cmode = &modelist->mode;
  947. d = abs(cmode->xres - mode->xres) +
  948. abs(cmode->yres - mode->yres);
  949. if (diff > d) {
  950. diff = d;
  951. diff_refresh = abs(cmode->refresh - mode->refresh);
  952. best = cmode;
  953. } else if (diff == d) {
  954. d = abs(cmode->refresh - mode->refresh);
  955. if (diff_refresh > d) {
  956. diff_refresh = d;
  957. best = cmode;
  958. }
  959. }
  960. }
  961. return best;
  962. }
  963. /**
  964. * fb_match_mode - find a videomode which exactly matches the timings in var
  965. * @var: pointer to struct fb_var_screeninfo
  966. * @head: pointer to struct list_head of modelist
  967. *
  968. * RETURNS:
  969. * struct fb_videomode, NULL if none found
  970. */
  971. const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
  972. struct list_head *head)
  973. {
  974. struct list_head *pos;
  975. struct fb_modelist *modelist;
  976. struct fb_videomode *m, mode;
  977. fb_var_to_videomode(&mode, var);
  978. list_for_each(pos, head) {
  979. modelist = list_entry(pos, struct fb_modelist, list);
  980. m = &modelist->mode;
  981. if (fb_mode_is_equal(m, &mode))
  982. return m;
  983. }
  984. return NULL;
  985. }
  986. /**
  987. * fb_add_videomode - adds videomode entry to modelist
  988. * @mode: videomode to add
  989. * @head: struct list_head of modelist
  990. *
  991. * NOTES:
  992. * Will only add unmatched mode entries
  993. */
  994. int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
  995. {
  996. struct list_head *pos;
  997. struct fb_modelist *modelist;
  998. struct fb_videomode *m;
  999. int found = 0;
  1000. list_for_each(pos, head) {
  1001. modelist = list_entry(pos, struct fb_modelist, list);
  1002. m = &modelist->mode;
  1003. if (fb_mode_is_equal(m, mode)) {
  1004. found = 1;
  1005. break;
  1006. }
  1007. }
  1008. if (!found) {
  1009. modelist = kmalloc(sizeof(struct fb_modelist),
  1010. GFP_KERNEL);
  1011. if (!modelist)
  1012. return -ENOMEM;
  1013. modelist->mode = *mode;
  1014. list_add(&modelist->list, head);
  1015. }
  1016. return 0;
  1017. }
  1018. /**
  1019. * fb_delete_videomode - removed videomode entry from modelist
  1020. * @mode: videomode to remove
  1021. * @head: struct list_head of modelist
  1022. *
  1023. * NOTES:
  1024. * Will remove all matching mode entries
  1025. */
  1026. void fb_delete_videomode(const struct fb_videomode *mode,
  1027. struct list_head *head)
  1028. {
  1029. struct list_head *pos, *n;
  1030. struct fb_modelist *modelist;
  1031. struct fb_videomode *m;
  1032. list_for_each_safe(pos, n, head) {
  1033. modelist = list_entry(pos, struct fb_modelist, list);
  1034. m = &modelist->mode;
  1035. if (fb_mode_is_equal(m, mode)) {
  1036. list_del(pos);
  1037. kfree(pos);
  1038. }
  1039. }
  1040. }
  1041. /**
  1042. * fb_destroy_modelist - destroy modelist
  1043. * @head: struct list_head of modelist
  1044. */
  1045. void fb_destroy_modelist(struct list_head *head)
  1046. {
  1047. struct list_head *pos, *n;
  1048. list_for_each_safe(pos, n, head) {
  1049. list_del(pos);
  1050. kfree(pos);
  1051. }
  1052. }
  1053. EXPORT_SYMBOL_GPL(fb_destroy_modelist);
  1054. /**
  1055. * fb_videomode_to_modelist - convert mode array to mode list
  1056. * @modedb: array of struct fb_videomode
  1057. * @num: number of entries in array
  1058. * @head: struct list_head of modelist
  1059. */
  1060. void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
  1061. struct list_head *head)
  1062. {
  1063. int i;
  1064. INIT_LIST_HEAD(head);
  1065. for (i = 0; i < num; i++) {
  1066. if (fb_add_videomode(&modedb[i], head))
  1067. return;
  1068. }
  1069. }
  1070. const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
  1071. struct list_head *head)
  1072. {
  1073. struct list_head *pos;
  1074. struct fb_modelist *modelist;
  1075. const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
  1076. int first = 0;
  1077. if (!head->prev || !head->next || list_empty(head))
  1078. goto finished;
  1079. /* get the first detailed mode and the very first mode */
  1080. list_for_each(pos, head) {
  1081. modelist = list_entry(pos, struct fb_modelist, list);
  1082. m = &modelist->mode;
  1083. if (!first) {
  1084. m1 = m;
  1085. first = 1;
  1086. }
  1087. if (m->flag & FB_MODE_IS_FIRST) {
  1088. md = m;
  1089. break;
  1090. }
  1091. }
  1092. /* first detailed timing is preferred */
  1093. if (specs->misc & FB_MISC_1ST_DETAIL) {
  1094. best = md;
  1095. goto finished;
  1096. }
  1097. /* find best mode based on display width and height */
  1098. if (specs->max_x && specs->max_y) {
  1099. struct fb_var_screeninfo var;
  1100. memset(&var, 0, sizeof(struct fb_var_screeninfo));
  1101. var.xres = (specs->max_x * 7200)/254;
  1102. var.yres = (specs->max_y * 7200)/254;
  1103. m = fb_find_best_mode(&var, head);
  1104. if (m) {
  1105. best = m;
  1106. goto finished;
  1107. }
  1108. }
  1109. /* use first detailed mode */
  1110. if (md) {
  1111. best = md;
  1112. goto finished;
  1113. }
  1114. /* last resort, use the very first mode */
  1115. best = m1;
  1116. finished:
  1117. return best;
  1118. }
  1119. EXPORT_SYMBOL(fb_find_best_display);
  1120. EXPORT_SYMBOL(fb_videomode_to_var);
  1121. EXPORT_SYMBOL(fb_var_to_videomode);
  1122. EXPORT_SYMBOL(fb_mode_is_equal);
  1123. EXPORT_SYMBOL(fb_add_videomode);
  1124. EXPORT_SYMBOL(fb_match_mode);
  1125. EXPORT_SYMBOL(fb_find_best_mode);
  1126. EXPORT_SYMBOL(fb_find_nearest_mode);
  1127. EXPORT_SYMBOL(fb_videomode_to_modelist);
  1128. EXPORT_SYMBOL(fb_find_mode);
  1129. EXPORT_SYMBOL(fb_find_mode_cvt);