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
14 #include <linux/module.h>
15 #include <linux/tty.h>
17 #include <linux/sched.h>
21 #define name_matches(v, s, l) \
22 ((v).name && !strncmp((s), (v).name, (l)) && strlen((v).name) == (l))
23 #define res_matches(v, x, y) \
24 ((v).xres == (x) && (v).yres == (y))
27 #define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
29 #define DPRINTK(fmt, args...)
33 const char *global_mode_option
= NULL
;
37 * Standard video mode definitions (taken from XFree86)
40 #define DEFAULT_MODEDB_INDEX 0
42 static const __init
struct fb_videomode modedb
[] = {
44 /* 640x400 @ 70 Hz, 31.5 kHz hsync */
45 NULL
, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
46 0, FB_VMODE_NONINTERLACED
48 /* 640x480 @ 60 Hz, 31.5 kHz hsync */
49 NULL
, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
50 0, FB_VMODE_NONINTERLACED
52 /* 800x600 @ 56 Hz, 35.15 kHz hsync */
53 NULL
, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
54 0, FB_VMODE_NONINTERLACED
56 /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
57 NULL
, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
58 0, FB_VMODE_INTERLACED
60 /* 640x400 @ 85 Hz, 37.86 kHz hsync */
61 NULL
, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
62 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
64 /* 640x480 @ 72 Hz, 36.5 kHz hsync */
65 NULL
, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
66 0, FB_VMODE_NONINTERLACED
68 /* 640x480 @ 75 Hz, 37.50 kHz hsync */
69 NULL
, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
70 0, FB_VMODE_NONINTERLACED
72 /* 800x600 @ 60 Hz, 37.8 kHz hsync */
73 NULL
, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
74 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
76 /* 640x480 @ 85 Hz, 43.27 kHz hsync */
77 NULL
, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
78 0, FB_VMODE_NONINTERLACED
80 /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
81 NULL
, 69, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
82 0, FB_VMODE_INTERLACED
84 /* 800x600 @ 72 Hz, 48.0 kHz hsync */
85 NULL
, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
86 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
88 /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
89 NULL
, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
90 0, FB_VMODE_NONINTERLACED
92 /* 640x480 @ 100 Hz, 53.01 kHz hsync */
93 NULL
, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
94 0, FB_VMODE_NONINTERLACED
96 /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
97 NULL
, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
98 0, FB_VMODE_NONINTERLACED
100 /* 800x600 @ 85 Hz, 55.84 kHz hsync */
101 NULL
, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
102 0, FB_VMODE_NONINTERLACED
104 /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
105 NULL
, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
106 0, FB_VMODE_NONINTERLACED
108 /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
109 NULL
, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
110 0, FB_VMODE_INTERLACED
112 /* 800x600 @ 100 Hz, 64.02 kHz hsync */
113 NULL
, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
114 0, FB_VMODE_NONINTERLACED
116 /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
117 NULL
, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
118 0, FB_VMODE_NONINTERLACED
120 /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
121 NULL
, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
122 0, FB_VMODE_NONINTERLACED
124 /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
125 NULL
, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
126 0, FB_VMODE_NONINTERLACED
128 /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
129 NULL
, 68, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
130 0, FB_VMODE_NONINTERLACED
132 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
133 NULL
, 75, 1400, 1050, 9271, 120, 56, 13, 0, 112, 3,
134 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
136 /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
137 NULL
, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
138 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
140 /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
141 NULL
, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
142 0, FB_VMODE_NONINTERLACED
144 /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
145 NULL
, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
146 0, FB_VMODE_NONINTERLACED
148 /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
149 NULL
, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
150 0, FB_VMODE_NONINTERLACED
152 /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
153 NULL
, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
154 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
156 /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
157 NULL
, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
158 0, FB_VMODE_NONINTERLACED
160 /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
161 NULL
, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
162 0, FB_VMODE_NONINTERLACED
164 /* 1024x768 @ 100Hz, 80.21 kHz hsync */
165 NULL
, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
166 0, FB_VMODE_NONINTERLACED
168 /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
169 NULL
, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
170 0, FB_VMODE_NONINTERLACED
172 /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
173 NULL
, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
174 0, FB_VMODE_NONINTERLACED
176 /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
177 NULL
, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
178 0, FB_VMODE_NONINTERLACED
180 /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
181 NULL
, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
182 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
184 /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
185 NULL
, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
186 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
188 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
189 NULL
, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
190 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
192 /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
193 NULL
, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
194 0, FB_VMODE_NONINTERLACED
196 /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
197 NULL
, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
198 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
200 /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
201 NULL
, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
202 FB_SYNC_HOR_HIGH_ACT
|FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
204 /* 512x384 @ 78 Hz, 31.50 kHz hsync */
205 NULL
, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
206 0, FB_VMODE_NONINTERLACED
208 /* 512x384 @ 85 Hz, 34.38 kHz hsync */
209 NULL
, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
210 0, FB_VMODE_NONINTERLACED
212 /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
213 NULL
, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
216 /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
217 NULL
, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
220 /* 320x240 @ 72 Hz, 36.5 kHz hsync */
221 NULL
, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
224 /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
225 NULL
, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
228 /* 400x300 @ 60 Hz, 37.8 kHz hsync */
229 NULL
, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
232 /* 400x300 @ 72 Hz, 48.0 kHz hsync */
233 NULL
, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
236 /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
237 NULL
, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
240 /* 480x300 @ 60 Hz, 37.8 kHz hsync */
241 NULL
, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
244 /* 480x300 @ 63 Hz, 39.6 kHz hsync */
245 NULL
, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
248 /* 480x300 @ 72 Hz, 48.0 kHz hsync */
249 NULL
, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
254 #ifdef CONFIG_FB_MODE_HELPERS
255 const struct fb_videomode vesa_modes
[] = {
256 /* 0 640x350-85 VESA */
257 { NULL
, 85, 640, 350, 31746, 96, 32, 60, 32, 64, 3,
258 FB_SYNC_HOR_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
259 /* 1 640x400-85 VESA */
260 { NULL
, 85, 640, 400, 31746, 96, 32, 41, 01, 64, 3,
261 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
262 /* 2 720x400-85 VESA */
263 { NULL
, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
264 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
265 /* 3 640x480-60 VESA */
266 { NULL
, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
267 0, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
268 /* 4 640x480-72 VESA */
269 { NULL
, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
270 0, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
271 /* 5 640x480-75 VESA */
272 { NULL
, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
273 0, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
274 /* 6 640x480-85 VESA */
275 { NULL
, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
276 0, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
277 /* 7 800x600-56 VESA */
278 { NULL
, 56, 800, 600, 27777, 128, 24, 22, 01, 72, 2,
279 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
280 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
281 /* 8 800x600-60 VESA */
282 { NULL
, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
283 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
284 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
285 /* 9 800x600-72 VESA */
286 { NULL
, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
287 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
288 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
289 /* 10 800x600-75 VESA */
290 { NULL
, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
291 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
292 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
293 /* 11 800x600-85 VESA */
294 { NULL
, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
295 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
296 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
297 /* 12 1024x768i-43 VESA */
298 { NULL
, 53, 1024, 768, 22271, 56, 8, 41, 0, 176, 8,
299 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
300 FB_VMODE_INTERLACED
, FB_MODE_IS_VESA
},
301 /* 13 1024x768-60 VESA */
302 { NULL
, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
303 0, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
304 /* 14 1024x768-70 VESA */
305 { NULL
, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
306 0, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
307 /* 15 1024x768-75 VESA */
308 { NULL
, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
309 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
310 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
311 /* 16 1024x768-85 VESA */
312 { NULL
, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
313 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
314 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
315 /* 17 1152x864-75 VESA */
316 { NULL
, 75, 1153, 864, 9259, 256, 64, 32, 1, 128, 3,
317 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
318 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
319 /* 18 1280x960-60 VESA */
320 { NULL
, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
321 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
322 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
323 /* 19 1280x960-85 VESA */
324 { NULL
, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
325 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
326 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
327 /* 20 1280x1024-60 VESA */
328 { NULL
, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
329 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
330 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
331 /* 21 1280x1024-75 VESA */
332 { NULL
, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
333 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
334 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
335 /* 22 1280x1024-85 VESA */
336 { NULL
, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
337 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
338 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
339 /* 23 1600x1200-60 VESA */
340 { NULL
, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
341 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
342 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
343 /* 24 1600x1200-65 VESA */
344 { NULL
, 65, 1600, 1200, 5698, 304, 64, 46, 1, 192, 3,
345 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
346 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
347 /* 25 1600x1200-70 VESA */
348 { NULL
, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
349 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
350 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
351 /* 26 1600x1200-75 VESA */
352 { NULL
, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
353 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
354 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
355 /* 27 1600x1200-85 VESA */
356 { NULL
, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
357 FB_SYNC_HOR_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
358 FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
359 /* 28 1792x1344-60 VESA */
360 { NULL
, 60, 1792, 1344, 4882, 328, 128, 46, 1, 200, 3,
361 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
362 /* 29 1792x1344-75 VESA */
363 { NULL
, 75, 1792, 1344, 3831, 352, 96, 69, 1, 216, 3,
364 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
365 /* 30 1856x1392-60 VESA */
366 { NULL
, 60, 1856, 1392, 4580, 352, 96, 43, 1, 224, 3,
367 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
368 /* 31 1856x1392-75 VESA */
369 { NULL
, 75, 1856, 1392, 3472, 352, 128, 104, 1, 224, 3,
370 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
371 /* 32 1920x1440-60 VESA */
372 { NULL
, 60, 1920, 1440, 4273, 344, 128, 56, 1, 200, 3,
373 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
374 /* 33 1920x1440-75 VESA */
375 { NULL
, 60, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
376 FB_SYNC_VERT_HIGH_ACT
, FB_VMODE_NONINTERLACED
, FB_MODE_IS_VESA
},
378 EXPORT_SYMBOL(vesa_modes
);
379 #endif /* CONFIG_FB_MODE_HELPERS */
381 static int my_atoi(const char *name
)
388 val
= 10*val
+(*name
-'0');
397 * fb_try_mode - test a video mode
398 * @var: frame buffer user defined part of display
399 * @info: frame buffer info structure
400 * @mode: frame buffer video mode structure
401 * @bpp: color depth in bits per pixel
403 * Tries a video mode to test it's validity for device @info.
405 * Returns 1 on success.
409 int fb_try_mode(struct fb_var_screeninfo
*var
, struct fb_info
*info
,
410 const struct fb_videomode
*mode
, unsigned int bpp
)
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
;
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
;
440 * fb_find_mode - finds a valid video mode
441 * @var: frame buffer user defined part of display
442 * @info: frame buffer info structure
443 * @mode_option: string video mode to find
444 * @db: video mode database
445 * @dbsize: size of @db
446 * @default_mode: default video mode to fall back to
447 * @default_bpp: default color depth in bits per pixel
449 * Finds a suitable video mode, starting with the specified mode
450 * in @mode_option with fallback to @default_mode. If
451 * @default_mode fails, all modes in the video mode database will
454 * Valid mode specifiers for @mode_option:
456 * <xres>x<yres>[-<bpp>][@<refresh>] or
457 * <name>[-<bpp>][@<refresh>]
459 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
462 * NOTE: The passed struct @var is _not_ cleared! This allows you
463 * to supply values for e.g. the grayscale and accel_flags fields.
465 * Returns zero for failure, 1 if using specified @mode_option,
466 * 2 if using specified @mode_option with an ignored refresh rate,
467 * 3 if default mode is used, 4 if fall back to any valid mode.
471 int fb_find_mode(struct fb_var_screeninfo
*var
,
472 struct fb_info
*info
, const char *mode_option
,
473 const struct fb_videomode
*db
, unsigned int dbsize
,
474 const struct fb_videomode
*default_mode
,
475 unsigned int default_bpp
)
479 /* Set up defaults */
482 dbsize
= sizeof(modedb
)/sizeof(*modedb
);
485 default_mode
= &modedb
[DEFAULT_MODEDB_INDEX
];
489 /* Did the user specify a video mode? */
490 if (mode_option
|| (mode_option
= global_mode_option
)) {
491 const char *name
= mode_option
;
492 unsigned int namelen
= strlen(name
);
493 int res_specified
= 0, bpp_specified
= 0, refresh_specified
= 0;
494 unsigned int xres
= 0, yres
= 0, bpp
= default_bpp
, refresh
= 0;
495 int yres_specified
= 0;
496 u32 best
= -1, diff
= -1;
498 for (i
= namelen
-1; i
>= 0; i
--) {
502 if (!refresh_specified
&& !bpp_specified
&&
504 refresh
= my_atoi(&name
[i
+1]);
505 refresh_specified
= 1;
511 if (!bpp_specified
&& !yres_specified
) {
512 bpp
= my_atoi(&name
[i
+1]);
518 if (!yres_specified
) {
519 yres
= my_atoi(&name
[i
+1]);
530 if (i
< 0 && yres_specified
) {
531 xres
= my_atoi(name
);
535 for (i
= refresh_specified
; i
>= 0; i
--) {
536 DPRINTK("Trying specified video mode%s %ix%i\n",
537 i
? "" : " (ignoring refresh rate)", xres
, yres
);
538 for (j
= 0; j
< dbsize
; j
++)
539 if ((name_matches(db
[j
], name
, namelen
) ||
540 (res_specified
&& res_matches(db
[j
], xres
, yres
))) &&
541 (!i
|| db
[j
].refresh
== refresh
) &&
542 !fb_try_mode(var
, info
, &db
[j
], bpp
))
545 DPRINTK("Trying best-fit modes\n");
546 for (i
= 0; i
< dbsize
; i
++) {
547 if (xres
<= db
[i
].xres
&& yres
<= db
[i
].yres
) {
548 DPRINTK("Trying %ix%i\n", db
[i
].xres
, db
[i
].yres
);
549 if (!fb_try_mode(var
, info
, &db
[i
], bpp
)) {
550 if (diff
> (db
[i
].xres
- xres
) + (db
[i
].yres
- yres
)) {
551 diff
= (db
[i
].xres
- xres
) + (db
[i
].yres
- yres
);
558 fb_try_mode(var
, info
, &db
[best
], bpp
);
563 DPRINTK("Trying default video mode\n");
564 if (!fb_try_mode(var
, info
, default_mode
, default_bpp
))
567 DPRINTK("Trying all modes\n");
568 for (i
= 0; i
< dbsize
; i
++)
569 if (!fb_try_mode(var
, info
, &db
[i
], default_bpp
))
572 DPRINTK("No valid mode found\n");
577 * fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
578 * @mode: pointer to struct fb_videomode
579 * @var: pointer to struct fb_var_screeninfo
581 void fb_var_to_videomode(struct fb_videomode
*mode
,
582 struct fb_var_screeninfo
*var
)
584 u32 pixclock
, hfreq
, htotal
, vtotal
;
587 mode
->xres
= var
->xres
;
588 mode
->yres
= var
->yres
;
589 mode
->pixclock
= var
->pixclock
;
590 mode
->hsync_len
= var
->hsync_len
;
591 mode
->vsync_len
= var
->vsync_len
;
592 mode
->left_margin
= var
->left_margin
;
593 mode
->right_margin
= var
->right_margin
;
594 mode
->upper_margin
= var
->upper_margin
;
595 mode
->lower_margin
= var
->lower_margin
;
596 mode
->sync
= var
->sync
;
597 mode
->vmode
= var
->vmode
& FB_VMODE_MASK
;
598 mode
->flag
= FB_MODE_IS_FROM_VAR
;
602 pixclock
= PICOS2KHZ(var
->pixclock
) * 1000;
604 htotal
= var
->xres
+ var
->right_margin
+ var
->hsync_len
+
606 vtotal
= var
->yres
+ var
->lower_margin
+ var
->vsync_len
+
609 if (var
->vmode
& FB_VMODE_INTERLACED
)
611 if (var
->vmode
& FB_VMODE_DOUBLE
)
614 hfreq
= pixclock
/htotal
;
615 mode
->refresh
= hfreq
/vtotal
;
619 * fb_videomode_to_var - convert fb_videomode to fb_var_screeninfo
620 * @var: pointer to struct fb_var_screeninfo
621 * @mode: pointer to struct fb_videomode
623 void fb_videomode_to_var(struct fb_var_screeninfo
*var
,
624 struct fb_videomode
*mode
)
626 var
->xres
= mode
->xres
;
627 var
->yres
= mode
->yres
;
628 var
->pixclock
= mode
->pixclock
;
629 var
->left_margin
= mode
->left_margin
;
630 var
->hsync_len
= mode
->hsync_len
;
631 var
->vsync_len
= mode
->vsync_len
;
632 var
->right_margin
= mode
->right_margin
;
633 var
->upper_margin
= mode
->upper_margin
;
634 var
->lower_margin
= mode
->lower_margin
;
635 var
->sync
= mode
->sync
;
636 var
->vmode
= mode
->vmode
& FB_VMODE_MASK
;
640 * fb_mode_is_equal - compare 2 videomodes
641 * @mode1: first videomode
642 * @mode2: second videomode
645 * 1 if equal, 0 if not
647 int fb_mode_is_equal(struct fb_videomode
*mode1
,
648 struct fb_videomode
*mode2
)
650 return (mode1
->xres
== mode2
->xres
&&
651 mode1
->yres
== mode2
->yres
&&
652 mode1
->pixclock
== mode2
->pixclock
&&
653 mode1
->hsync_len
== mode2
->hsync_len
&&
654 mode1
->vsync_len
== mode2
->vsync_len
&&
655 mode1
->left_margin
== mode2
->left_margin
&&
656 mode1
->right_margin
== mode2
->right_margin
&&
657 mode1
->upper_margin
== mode2
->upper_margin
&&
658 mode1
->lower_margin
== mode2
->lower_margin
&&
659 mode1
->sync
== mode2
->sync
&&
660 mode1
->vmode
== mode2
->vmode
);
664 * fb_find_best_mode - find best matching videomode
665 * @var: pointer to struct fb_var_screeninfo
666 * @head: pointer to struct list_head of modelist
669 * struct fb_videomode, NULL if none found
672 * This function assumes that all modelist entries in
673 * info->modelist are valid.
676 * Finds best matching videomode which has an equal or greater dimension than
677 * var->xres and var->yres. If more than 1 videomode is found, will return
678 * the videomode with the highest refresh rate
680 struct fb_videomode
*fb_find_best_mode(struct fb_var_screeninfo
*var
,
681 struct list_head
*head
)
683 struct list_head
*pos
;
684 struct fb_modelist
*modelist
;
685 struct fb_videomode
*mode
, *best
= NULL
;
688 list_for_each(pos
, head
) {
691 modelist
= list_entry(pos
, struct fb_modelist
, list
);
692 mode
= &modelist
->mode
;
694 if (mode
->xres
>= var
->xres
&& mode
->yres
>= var
->yres
) {
695 d
= (mode
->xres
- var
->xres
) +
696 (mode
->yres
- var
->yres
);
700 } else if (diff
== d
&& mode
->refresh
> best
->refresh
)
708 * fb_match_mode - find a videomode which exactly matches the timings in var
709 * @var: pointer to struct fb_var_screeninfo
710 * @head: pointer to struct list_head of modelist
713 * struct fb_videomode, NULL if none found
715 struct fb_videomode
*fb_match_mode(struct fb_var_screeninfo
*var
,
716 struct list_head
*head
)
718 struct list_head
*pos
;
719 struct fb_modelist
*modelist
;
720 struct fb_videomode
*m
, mode
;
722 fb_var_to_videomode(&mode
, var
);
723 list_for_each(pos
, head
) {
724 modelist
= list_entry(pos
, struct fb_modelist
, list
);
726 if (fb_mode_is_equal(m
, &mode
))
733 * fb_add_videomode: adds videomode entry to modelist
734 * @mode: videomode to add
735 * @head: struct list_head of modelist
738 * Will only add unmatched mode entries
740 int fb_add_videomode(struct fb_videomode
*mode
, struct list_head
*head
)
742 struct list_head
*pos
;
743 struct fb_modelist
*modelist
;
744 struct fb_videomode
*m
;
747 list_for_each(pos
, head
) {
748 modelist
= list_entry(pos
, struct fb_modelist
, list
);
750 if (fb_mode_is_equal(m
, mode
)) {
756 modelist
= kmalloc(sizeof(struct fb_modelist
),
761 modelist
->mode
= *mode
;
762 list_add(&modelist
->list
, head
);
768 * fb_delete_videomode: removed videomode entry from modelist
769 * @mode: videomode to remove
770 * @head: struct list_head of modelist
773 * Will remove all matching mode entries
775 void fb_delete_videomode(struct fb_videomode
*mode
, struct list_head
*head
)
777 struct list_head
*pos
, *n
;
778 struct fb_modelist
*modelist
;
779 struct fb_videomode
*m
;
781 list_for_each_safe(pos
, n
, head
) {
782 modelist
= list_entry(pos
, struct fb_modelist
, list
);
784 if (fb_mode_is_equal(m
, mode
)) {
792 * fb_destroy_modelist: destroy modelist
793 * @head: struct list_head of modelist
795 void fb_destroy_modelist(struct list_head
*head
)
797 struct list_head
*pos
, *n
;
799 list_for_each_safe(pos
, n
, head
) {
806 * fb_videomode_to_modelist: convert mode array to mode list
807 * @modedb: array of struct fb_videomode
808 * @num: number of entries in array
809 * @head: struct list_head of modelist
811 void fb_videomode_to_modelist(struct fb_videomode
*modedb
, int num
,
812 struct list_head
*head
)
816 INIT_LIST_HEAD(head
);
818 for (i
= 0; i
< num
; i
++) {
819 if (fb_add_videomode(&modedb
[i
], head
))
824 EXPORT_SYMBOL(fb_videomode_to_var
);
825 EXPORT_SYMBOL(fb_var_to_videomode
);
826 EXPORT_SYMBOL(fb_mode_is_equal
);
827 EXPORT_SYMBOL(fb_add_videomode
);
828 EXPORT_SYMBOL(fb_delete_videomode
);
829 EXPORT_SYMBOL(fb_destroy_modelist
);
830 EXPORT_SYMBOL(fb_match_mode
);
831 EXPORT_SYMBOL(fb_find_best_mode
);
832 EXPORT_SYMBOL(fb_videomode_to_modelist
);
833 EXPORT_SYMBOL(fb_find_mode
);