blob: 473562191586f2101d169d8fb765b7b21ef4d2e4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
14#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/fb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#undef DEBUG
18
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))
23
24#ifdef DEBUG
Harvey Harrison5ae12172008-04-28 02:15:47 -070025#define DPRINTK(fmt, args...) printk("modedb %s: " fmt, __func__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#else
27#define DPRINTK(fmt, args...)
28#endif
29
Geert Uytterhoeven9a054fb2007-10-16 01:29:51 -070030const char *fb_mode_option;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32 /*
33 * Standard video mode definitions (taken from XFree86)
34 */
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static const struct fb_videomode modedb[] = {
37 {
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 */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -070075 NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 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 */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700123 NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 0, FB_VMODE_NONINTERLACED
125 }, {
126 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700127 NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 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 }, {
Olaf Heringb0c87972006-03-27 01:17:38 -0800182 /* 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 }, {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 /* 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
Antonino Daplasdb6778d2005-08-08 14:22:43 +0800249 }, {
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
Michael Hanselmann1dfcdfa2005-11-08 21:39:06 -0800254 }, {
255 /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700256 NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
Michael Hanselmann1dfcdfa2005-11-08 21:39:06 -0800257 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
Dennis Munsief71689e2006-06-26 00:26:39 -0700258 }, {
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
Alex545c4422008-01-17 15:21:18 -0800262 }, {
263 /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
264 NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
265 0, FB_VMODE_NONINTERLACED
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 },
267};
268
269#ifdef CONFIG_FB_MODE_HELPERS
270const struct fb_videomode vesa_modes[] = {
271 /* 0 640x350-85 VESA */
272 { NULL, 85, 640, 350, 31746, 96, 32, 60, 32, 64, 3,
273 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA},
274 /* 1 640x400-85 VESA */
275 { NULL, 85, 640, 400, 31746, 96, 32, 41, 01, 64, 3,
276 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
277 /* 2 720x400-85 VESA */
278 { NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
279 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
280 /* 3 640x480-60 VESA */
281 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
282 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
283 /* 4 640x480-72 VESA */
284 { NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
285 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
286 /* 5 640x480-75 VESA */
287 { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
288 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
289 /* 6 640x480-85 VESA */
290 { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
291 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
292 /* 7 800x600-56 VESA */
293 { NULL, 56, 800, 600, 27777, 128, 24, 22, 01, 72, 2,
294 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
295 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
296 /* 8 800x600-60 VESA */
297 { NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
298 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
299 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
300 /* 9 800x600-72 VESA */
301 { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
302 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
303 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
304 /* 10 800x600-75 VESA */
305 { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
306 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
307 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
308 /* 11 800x600-85 VESA */
309 { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
310 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
311 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
312 /* 12 1024x768i-43 VESA */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700313 { NULL, 43, 1024, 768, 22271, 56, 8, 41, 0, 176, 8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
315 FB_VMODE_INTERLACED, FB_MODE_IS_VESA },
316 /* 13 1024x768-60 VESA */
317 { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
318 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
319 /* 14 1024x768-70 VESA */
320 { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
321 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
322 /* 15 1024x768-75 VESA */
323 { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
324 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
325 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
326 /* 16 1024x768-85 VESA */
327 { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
328 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
329 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
330 /* 17 1152x864-75 VESA */
331 { NULL, 75, 1153, 864, 9259, 256, 64, 32, 1, 128, 3,
332 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
333 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
334 /* 18 1280x960-60 VESA */
335 { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
336 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
337 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
338 /* 19 1280x960-85 VESA */
339 { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
340 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
341 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
342 /* 20 1280x1024-60 VESA */
343 { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
344 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
345 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
346 /* 21 1280x1024-75 VESA */
347 { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
348 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
349 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
350 /* 22 1280x1024-85 VESA */
351 { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
352 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
353 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
354 /* 23 1600x1200-60 VESA */
355 { NULL, 60, 1600, 1200, 6172, 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 /* 24 1600x1200-65 VESA */
359 { NULL, 65, 1600, 1200, 5698, 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 /* 25 1600x1200-70 VESA */
363 { NULL, 70, 1600, 1200, 5291, 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 /* 26 1600x1200-75 VESA */
367 { NULL, 75, 1600, 1200, 4938, 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 /* 27 1600x1200-85 VESA */
371 { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
372 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
373 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
374 /* 28 1792x1344-60 VESA */
375 { NULL, 60, 1792, 1344, 4882, 328, 128, 46, 1, 200, 3,
376 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
377 /* 29 1792x1344-75 VESA */
378 { NULL, 75, 1792, 1344, 3831, 352, 96, 69, 1, 216, 3,
379 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
380 /* 30 1856x1392-60 VESA */
381 { NULL, 60, 1856, 1392, 4580, 352, 96, 43, 1, 224, 3,
382 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
383 /* 31 1856x1392-75 VESA */
384 { NULL, 75, 1856, 1392, 3472, 352, 128, 104, 1, 224, 3,
385 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
386 /* 32 1920x1440-60 VESA */
387 { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 200, 3,
388 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
389 /* 33 1920x1440-75 VESA */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700390 { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
392};
393EXPORT_SYMBOL(vesa_modes);
394#endif /* CONFIG_FB_MODE_HELPERS */
395
396static int my_atoi(const char *name)
397{
398 int val = 0;
399
400 for (;; name++) {
401 switch (*name) {
Robert P. J. Day88b229c2007-05-08 00:38:27 -0700402 case '0' ... '9':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 val = 10*val+(*name-'0');
404 break;
405 default:
406 return val;
407 }
408 }
409}
410
411/**
412 * fb_try_mode - test a video mode
413 * @var: frame buffer user defined part of display
414 * @info: frame buffer info structure
415 * @mode: frame buffer video mode structure
416 * @bpp: color depth in bits per pixel
417 *
418 * Tries a video mode to test it's validity for device @info.
419 *
420 * Returns 1 on success.
421 *
422 */
423
424static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
425 const struct fb_videomode *mode, unsigned int bpp)
426{
427 int err = 0;
428
429 DPRINTK("Trying mode %s %dx%d-%d@%d\n", mode->name ? mode->name : "noname",
430 mode->xres, mode->yres, bpp, mode->refresh);
431 var->xres = mode->xres;
432 var->yres = mode->yres;
433 var->xres_virtual = mode->xres;
434 var->yres_virtual = mode->yres;
435 var->xoffset = 0;
436 var->yoffset = 0;
437 var->bits_per_pixel = bpp;
438 var->activate |= FB_ACTIVATE_TEST;
439 var->pixclock = mode->pixclock;
440 var->left_margin = mode->left_margin;
441 var->right_margin = mode->right_margin;
442 var->upper_margin = mode->upper_margin;
443 var->lower_margin = mode->lower_margin;
444 var->hsync_len = mode->hsync_len;
445 var->vsync_len = mode->vsync_len;
446 var->sync = mode->sync;
447 var->vmode = mode->vmode;
448 if (info->fbops->fb_check_var)
449 err = info->fbops->fb_check_var(var, info);
450 var->activate &= ~FB_ACTIVATE_TEST;
451 return err;
452}
453
454/**
455 * fb_find_mode - finds a valid video mode
456 * @var: frame buffer user defined part of display
457 * @info: frame buffer info structure
458 * @mode_option: string video mode to find
459 * @db: video mode database
460 * @dbsize: size of @db
461 * @default_mode: default video mode to fall back to
462 * @default_bpp: default color depth in bits per pixel
463 *
464 * Finds a suitable video mode, starting with the specified mode
465 * in @mode_option with fallback to @default_mode. If
466 * @default_mode fails, all modes in the video mode database will
467 * be tried.
468 *
469 * Valid mode specifiers for @mode_option:
470 *
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700471 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 * <name>[-<bpp>][@<refresh>]
473 *
474 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
475 * <name> a string.
476 *
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700477 * If 'M' is present after yres (and before refresh/bpp if present),
478 * the function will compute the timings using VESA(tm) Coordinated
479 * Video Timings (CVT). If 'R' is present after 'M', will compute with
480 * reduced blanking (for flatpanels). If 'i' is present, compute
481 * interlaced mode. If 'm' is present, add margins equal to 1.8%
482 * of xres rounded down to 8 pixels, and 1.8% of yres. The char
483 * 'i' and 'm' must be after 'M' and 'R'. Example:
484 *
485 * 1024x768MR-8@60m - Reduced blank with margins at 60Hz.
486 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 * NOTE: The passed struct @var is _not_ cleared! This allows you
488 * to supply values for e.g. the grayscale and accel_flags fields.
489 *
490 * Returns zero for failure, 1 if using specified @mode_option,
491 * 2 if using specified @mode_option with an ignored refresh rate,
492 * 3 if default mode is used, 4 if fall back to any valid mode.
493 *
494 */
495
496int fb_find_mode(struct fb_var_screeninfo *var,
497 struct fb_info *info, const char *mode_option,
498 const struct fb_videomode *db, unsigned int dbsize,
499 const struct fb_videomode *default_mode,
500 unsigned int default_bpp)
501{
502 int i;
503
504 /* Set up defaults */
505 if (!db) {
506 db = modedb;
Tobias Klauserd1ae4182006-03-27 01:17:39 -0800507 dbsize = ARRAY_SIZE(modedb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
Jordan Crousec25623f2006-12-08 02:40:21 -0800509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 if (!default_mode)
Jordan Crousec25623f2006-12-08 02:40:21 -0800511 default_mode = &db[0];
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (!default_bpp)
514 default_bpp = 8;
515
516 /* Did the user specify a video mode? */
Geert Uytterhoevenc40eea92007-10-18 03:04:36 -0700517 if (!mode_option)
518 mode_option = fb_mode_option;
519 if (mode_option) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 const char *name = mode_option;
521 unsigned int namelen = strlen(name);
522 int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
523 unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700524 int yres_specified = 0, cvt = 0, rb = 0, interlace = 0, margins = 0;
Michal Januszewski6b745b62008-04-28 02:14:48 -0700525 u32 best, diff, tdiff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527 for (i = namelen-1; i >= 0; i--) {
528 switch (name[i]) {
529 case '@':
530 namelen = i;
531 if (!refresh_specified && !bpp_specified &&
532 !yres_specified) {
533 refresh = my_atoi(&name[i+1]);
534 refresh_specified = 1;
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700535 if (cvt || rb)
536 cvt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 } else
538 goto done;
539 break;
540 case '-':
541 namelen = i;
542 if (!bpp_specified && !yres_specified) {
543 bpp = my_atoi(&name[i+1]);
544 bpp_specified = 1;
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700545 if (cvt || rb)
546 cvt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 } else
548 goto done;
549 break;
550 case 'x':
551 if (!yres_specified) {
552 yres = my_atoi(&name[i+1]);
553 yres_specified = 1;
554 } else
555 goto done;
556 break;
Robert P. J. Day88b229c2007-05-08 00:38:27 -0700557 case '0' ... '9':
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 break;
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700559 case 'M':
560 if (!yres_specified)
561 cvt = 1;
562 break;
563 case 'R':
564 if (!cvt)
565 rb = 1;
566 break;
567 case 'm':
568 if (!cvt)
569 margins = 1;
570 break;
571 case 'i':
572 if (!cvt)
573 interlace = 1;
574 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 default:
576 goto done;
577 }
578 }
579 if (i < 0 && yres_specified) {
580 xres = my_atoi(name);
581 res_specified = 1;
582 }
583done:
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700584 if (cvt) {
585 struct fb_videomode cvt_mode;
586 int ret;
587
588 DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
589 (refresh) ? refresh : 60, (rb) ? " reduced blanking" :
590 "", (margins) ? " with margins" : "", (interlace) ?
591 " interlaced" : "");
592
593 cvt_mode.xres = xres;
594 cvt_mode.yres = yres;
595 cvt_mode.refresh = (refresh) ? refresh : 60;
596
597 if (interlace)
598 cvt_mode.vmode |= FB_VMODE_INTERLACED;
599 else
600 cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
601
602 ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
603
604 if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
605 DPRINTK("modedb CVT: CVT mode ok\n");
606 return 1;
607 }
608
609 DPRINTK("CVT mode invalid, getting mode from database\n");
610 }
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 DPRINTK("Trying specified video mode%s %ix%i\n",
613 refresh_specified ? "" : " (ignoring refresh rate)", xres, yres);
614
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700615 if (!refresh_specified) {
616 /*
617 * If the caller has provided a custom mode database and a
618 * valid monspecs structure, we look for the mode with the
619 * highest refresh rate. Otherwise we play it safe it and
620 * try to find a mode with a refresh rate closest to the
621 * standard 60 Hz.
622 */
623 if (db != modedb &&
624 info->monspecs.vfmin && info->monspecs.vfmax &&
625 info->monspecs.hfmin && info->monspecs.hfmax &&
626 info->monspecs.dclkmax) {
627 refresh = 1000;
628 } else {
629 refresh = 60;
630 }
631 }
632
633 diff = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 best = -1;
635 for (i = 0; i < dbsize; i++) {
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700636 if ((name_matches(db[i], name, namelen) ||
637 (res_specified && res_matches(db[i], xres, yres))) &&
638 !fb_try_mode(var, info, &db[i], bpp)) {
639 if (refresh_specified && db[i].refresh == refresh) {
640 return 1;
641 } else {
642 if (abs(db[i].refresh - refresh) < diff) {
643 diff = abs(db[i].refresh - refresh);
644 best = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 }
646 }
647 }
648 }
649 if (best != -1) {
650 fb_try_mode(var, info, &db[best], bpp);
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700651 return (refresh_specified) ? 2 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Michal Januszewski6b745b62008-04-28 02:14:48 -0700654 diff = 2 * (xres + yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 best = -1;
656 DPRINTK("Trying best-fit modes\n");
657 for (i = 0; i < dbsize; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
659 if (!fb_try_mode(var, info, &db[i], bpp)) {
Michal Januszewski6b745b62008-04-28 02:14:48 -0700660 tdiff = abs(db[i].xres - xres) +
661 abs(db[i].yres - yres);
662
663 /*
664 * Penalize modes with resolutions smaller
665 * than requested.
666 */
667 if (xres > db[i].xres || yres > db[i].yres)
668 tdiff += xres + yres;
669
670 if (diff > tdiff) {
671 diff = tdiff;
672 best = i;
673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
676 if (best != -1) {
677 fb_try_mode(var, info, &db[best], bpp);
678 return 5;
679 }
680 }
681
682 DPRINTK("Trying default video mode\n");
683 if (!fb_try_mode(var, info, default_mode, default_bpp))
684 return 3;
685
686 DPRINTK("Trying all modes\n");
687 for (i = 0; i < dbsize; i++)
688 if (!fb_try_mode(var, info, &db[i], default_bpp))
689 return 4;
690
691 DPRINTK("No valid mode found\n");
692 return 0;
693}
694
695/**
696 * fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
697 * @mode: pointer to struct fb_videomode
698 * @var: pointer to struct fb_var_screeninfo
699 */
700void fb_var_to_videomode(struct fb_videomode *mode,
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800701 const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
703 u32 pixclock, hfreq, htotal, vtotal;
704
705 mode->name = NULL;
706 mode->xres = var->xres;
707 mode->yres = var->yres;
708 mode->pixclock = var->pixclock;
709 mode->hsync_len = var->hsync_len;
710 mode->vsync_len = var->vsync_len;
711 mode->left_margin = var->left_margin;
712 mode->right_margin = var->right_margin;
713 mode->upper_margin = var->upper_margin;
714 mode->lower_margin = var->lower_margin;
715 mode->sync = var->sync;
716 mode->vmode = var->vmode & FB_VMODE_MASK;
717 mode->flag = FB_MODE_IS_FROM_VAR;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800718 mode->refresh = 0;
719
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (!var->pixclock)
721 return;
722
723 pixclock = PICOS2KHZ(var->pixclock) * 1000;
724
725 htotal = var->xres + var->right_margin + var->hsync_len +
726 var->left_margin;
727 vtotal = var->yres + var->lower_margin + var->vsync_len +
728 var->upper_margin;
729
730 if (var->vmode & FB_VMODE_INTERLACED)
731 vtotal /= 2;
732 if (var->vmode & FB_VMODE_DOUBLE)
733 vtotal *= 2;
734
735 hfreq = pixclock/htotal;
736 mode->refresh = hfreq/vtotal;
737}
738
739/**
740 * fb_videomode_to_var - convert fb_videomode to fb_var_screeninfo
741 * @var: pointer to struct fb_var_screeninfo
742 * @mode: pointer to struct fb_videomode
743 */
744void fb_videomode_to_var(struct fb_var_screeninfo *var,
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800745 const struct fb_videomode *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
747 var->xres = mode->xres;
748 var->yres = mode->yres;
Geert Uytterhoevendcfe2662007-02-12 00:55:21 -0800749 var->xres_virtual = mode->xres;
750 var->yres_virtual = mode->yres;
751 var->xoffset = 0;
752 var->yoffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 var->pixclock = mode->pixclock;
754 var->left_margin = mode->left_margin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 var->right_margin = mode->right_margin;
756 var->upper_margin = mode->upper_margin;
757 var->lower_margin = mode->lower_margin;
Geert Uytterhoevendcfe2662007-02-12 00:55:21 -0800758 var->hsync_len = mode->hsync_len;
759 var->vsync_len = mode->vsync_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 var->sync = mode->sync;
761 var->vmode = mode->vmode & FB_VMODE_MASK;
762}
763
764/**
765 * fb_mode_is_equal - compare 2 videomodes
766 * @mode1: first videomode
767 * @mode2: second videomode
768 *
769 * RETURNS:
770 * 1 if equal, 0 if not
771 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800772int fb_mode_is_equal(const struct fb_videomode *mode1,
773 const struct fb_videomode *mode2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
775 return (mode1->xres == mode2->xres &&
776 mode1->yres == mode2->yres &&
777 mode1->pixclock == mode2->pixclock &&
778 mode1->hsync_len == mode2->hsync_len &&
779 mode1->vsync_len == mode2->vsync_len &&
780 mode1->left_margin == mode2->left_margin &&
781 mode1->right_margin == mode2->right_margin &&
782 mode1->upper_margin == mode2->upper_margin &&
783 mode1->lower_margin == mode2->lower_margin &&
784 mode1->sync == mode2->sync &&
785 mode1->vmode == mode2->vmode);
786}
787
788/**
789 * fb_find_best_mode - find best matching videomode
790 * @var: pointer to struct fb_var_screeninfo
791 * @head: pointer to struct list_head of modelist
792 *
793 * RETURNS:
794 * struct fb_videomode, NULL if none found
795 *
796 * IMPORTANT:
797 * This function assumes that all modelist entries in
798 * info->modelist are valid.
799 *
800 * NOTES:
801 * Finds best matching videomode which has an equal or greater dimension than
802 * var->xres and var->yres. If more than 1 videomode is found, will return
803 * the videomode with the highest refresh rate
804 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800805const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
806 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 struct list_head *pos;
809 struct fb_modelist *modelist;
810 struct fb_videomode *mode, *best = NULL;
811 u32 diff = -1;
812
813 list_for_each(pos, head) {
814 u32 d;
815
816 modelist = list_entry(pos, struct fb_modelist, list);
817 mode = &modelist->mode;
818
819 if (mode->xres >= var->xres && mode->yres >= var->yres) {
820 d = (mode->xres - var->xres) +
821 (mode->yres - var->yres);
822 if (diff > d) {
823 diff = d;
824 best = mode;
Antonino A. Daplas17cc62812006-06-26 00:26:44 -0700825 } else if (diff == d && best &&
826 mode->refresh > best->refresh)
827 best = mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829 }
830 return best;
831}
832
833/**
Michal Januszewski8fb65672005-11-07 01:00:47 -0800834 * fb_find_nearest_mode - find closest videomode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 *
Michal Januszewski8fb65672005-11-07 01:00:47 -0800836 * @mode: pointer to struct fb_videomode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 * @head: pointer to modelist
838 *
839 * Finds best matching videomode, smaller or greater in dimension.
840 * If more than 1 videomode is found, will return the videomode with
Michal Januszewski8fb65672005-11-07 01:00:47 -0800841 * the closest refresh rate.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800843const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
844 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
846 struct list_head *pos;
847 struct fb_modelist *modelist;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800848 struct fb_videomode *cmode, *best = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 u32 diff = -1, diff_refresh = -1;
850
851 list_for_each(pos, head) {
852 u32 d;
853
854 modelist = list_entry(pos, struct fb_modelist, list);
Michal Januszewski8fb65672005-11-07 01:00:47 -0800855 cmode = &modelist->mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Michal Januszewski8fb65672005-11-07 01:00:47 -0800857 d = abs(cmode->xres - mode->xres) +
858 abs(cmode->yres - mode->yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 if (diff > d) {
860 diff = d;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800861 best = cmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 } else if (diff == d) {
Michal Januszewski8fb65672005-11-07 01:00:47 -0800863 d = abs(cmode->refresh - mode->refresh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 if (diff_refresh > d) {
865 diff_refresh = d;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800866 best = cmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868 }
869 }
870
871 return best;
872}
873
874/**
875 * fb_match_mode - find a videomode which exactly matches the timings in var
876 * @var: pointer to struct fb_var_screeninfo
877 * @head: pointer to struct list_head of modelist
878 *
879 * RETURNS:
880 * struct fb_videomode, NULL if none found
881 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800882const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
883 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884{
885 struct list_head *pos;
886 struct fb_modelist *modelist;
887 struct fb_videomode *m, mode;
888
889 fb_var_to_videomode(&mode, var);
890 list_for_each(pos, head) {
891 modelist = list_entry(pos, struct fb_modelist, list);
892 m = &modelist->mode;
893 if (fb_mode_is_equal(m, &mode))
894 return m;
895 }
896 return NULL;
897}
898
899/**
900 * fb_add_videomode: adds videomode entry to modelist
901 * @mode: videomode to add
902 * @head: struct list_head of modelist
903 *
904 * NOTES:
905 * Will only add unmatched mode entries
906 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800907int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
909 struct list_head *pos;
910 struct fb_modelist *modelist;
911 struct fb_videomode *m;
912 int found = 0;
913
914 list_for_each(pos, head) {
915 modelist = list_entry(pos, struct fb_modelist, list);
916 m = &modelist->mode;
917 if (fb_mode_is_equal(m, mode)) {
918 found = 1;
919 break;
920 }
921 }
922 if (!found) {
923 modelist = kmalloc(sizeof(struct fb_modelist),
924 GFP_KERNEL);
925
926 if (!modelist)
927 return -ENOMEM;
928 modelist->mode = *mode;
929 list_add(&modelist->list, head);
930 }
931 return 0;
932}
933
934/**
935 * fb_delete_videomode: removed videomode entry from modelist
936 * @mode: videomode to remove
937 * @head: struct list_head of modelist
938 *
939 * NOTES:
940 * Will remove all matching mode entries
941 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800942void fb_delete_videomode(const struct fb_videomode *mode,
943 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944{
945 struct list_head *pos, *n;
946 struct fb_modelist *modelist;
947 struct fb_videomode *m;
948
949 list_for_each_safe(pos, n, head) {
950 modelist = list_entry(pos, struct fb_modelist, list);
951 m = &modelist->mode;
952 if (fb_mode_is_equal(m, mode)) {
953 list_del(pos);
954 kfree(pos);
955 }
956 }
957}
958
959/**
960 * fb_destroy_modelist: destroy modelist
961 * @head: struct list_head of modelist
962 */
963void fb_destroy_modelist(struct list_head *head)
964{
965 struct list_head *pos, *n;
966
967 list_for_each_safe(pos, n, head) {
968 list_del(pos);
969 kfree(pos);
970 }
971}
Michal Januszewski9953d232007-10-16 01:28:23 -0700972EXPORT_SYMBOL_GPL(fb_destroy_modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974/**
975 * fb_videomode_to_modelist: convert mode array to mode list
976 * @modedb: array of struct fb_videomode
977 * @num: number of entries in array
978 * @head: struct list_head of modelist
979 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800980void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 struct list_head *head)
982{
983 int i;
984
985 INIT_LIST_HEAD(head);
986
987 for (i = 0; i < num; i++) {
988 if (fb_add_videomode(&modedb[i], head))
989 return;
990 }
991}
992
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800993const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
994 struct list_head *head)
Antonino A. Daplas003cfc02005-11-07 01:00:54 -0800995{
996 struct list_head *pos;
997 struct fb_modelist *modelist;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800998 const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
Antonino A. Daplas003cfc02005-11-07 01:00:54 -0800999 int first = 0;
1000
1001 if (!head->prev || !head->next || list_empty(head))
1002 goto finished;
1003
1004 /* get the first detailed mode and the very first mode */
1005 list_for_each(pos, head) {
1006 modelist = list_entry(pos, struct fb_modelist, list);
1007 m = &modelist->mode;
1008
1009 if (!first) {
1010 m1 = m;
1011 first = 1;
1012 }
1013
1014 if (m->flag & FB_MODE_IS_FIRST) {
1015 md = m;
1016 break;
1017 }
1018 }
1019
1020 /* first detailed timing is preferred */
1021 if (specs->misc & FB_MISC_1ST_DETAIL) {
1022 best = md;
1023 goto finished;
1024 }
1025
1026 /* find best mode based on display width and height */
1027 if (specs->max_x && specs->max_y) {
1028 struct fb_var_screeninfo var;
1029
1030 memset(&var, 0, sizeof(struct fb_var_screeninfo));
1031 var.xres = (specs->max_x * 7200)/254;
1032 var.yres = (specs->max_y * 7200)/254;
1033 m = fb_find_best_mode(&var, head);
1034 if (m) {
1035 best = m;
1036 goto finished;
1037 }
1038 }
1039
1040 /* use first detailed mode */
1041 if (md) {
1042 best = md;
1043 goto finished;
1044 }
1045
1046 /* last resort, use the very first mode */
1047 best = m1;
1048finished:
1049 return best;
1050}
1051EXPORT_SYMBOL(fb_find_best_display);
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053EXPORT_SYMBOL(fb_videomode_to_var);
1054EXPORT_SYMBOL(fb_var_to_videomode);
1055EXPORT_SYMBOL(fb_mode_is_equal);
1056EXPORT_SYMBOL(fb_add_videomode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057EXPORT_SYMBOL(fb_match_mode);
1058EXPORT_SYMBOL(fb_find_best_mode);
1059EXPORT_SYMBOL(fb_find_nearest_mode);
1060EXPORT_SYMBOL(fb_videomode_to_modelist);
1061EXPORT_SYMBOL(fb_find_mode);