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