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