modedb.c 31 KB

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