Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
472 giacomo 1
/*
2
 *  linux/drivers/video/modedb.c -- Standard video mode database management
3
 *
4
 *      Copyright (C) 1999 Geert Uytterhoeven
5
 *
6
 *      2001 - Documented with DocBook
7
 *      - Brad Douglas <brad@neruo.com>
8
 *
9
 *  This file is subject to the terms and conditions of the GNU General Public
10
 *  License. See the file COPYING in the main directory of this archive for
11
 *  more details.
12
 */
13
 
14
#include <linuxcomp.h>
15
 
16
#include <linux/module.h>
17
#include <linux/tty.h>
18
#include <linux/fb.h>
19
#include <linux/sched.h>
20
 
21
#undef DEBUG
22
 
23
#define name_matches(v, s, l) \
24
    ((v).name && !strncmp((s), (v).name, (l)) && strlen((v).name) == (l))
25
#define res_matches(v, x, y) \
26
    ((v).xres == (x) && (v).yres == (y))
27
 
28
#ifdef DEBUG
29
#define DPRINTK(fmt, args...)   printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
30
#else
31
#define DPRINTK(fmt, args...)
32
#endif
33
 
34
 
35
const char *global_mode_option = NULL;
36
 
37
 
38
    /*
39
     *  Standard video mode definitions (taken from XFree86)
40
     */
41
 
42
#define DEFAULT_MODEDB_INDEX    0
43
 
44
static const struct fb_videomode modedb[] __initdata = {
45
    {
46
        /* 640x400 @ 70 Hz, 31.5 kHz hsync */
47
        NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
48
        0, FB_VMODE_NONINTERLACED
49
    }, {
50
        /* 640x480 @ 60 Hz, 31.5 kHz hsync */
51
        NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
52
        0, FB_VMODE_NONINTERLACED
53
    }, {
54
        /* 800x600 @ 56 Hz, 35.15 kHz hsync */
55
        NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
56
        0, FB_VMODE_NONINTERLACED
57
    }, {
58
        /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
59
        NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
60
        0, FB_VMODE_INTERLACED
61
    }, {
62
        /* 640x400 @ 85 Hz, 37.86 kHz hsync */
63
        NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
64
        FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
65
    }, {
66
        /* 640x480 @ 72 Hz, 36.5 kHz hsync */
67
        NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
68
        0, FB_VMODE_NONINTERLACED
69
    }, {
70
        /* 640x480 @ 75 Hz, 37.50 kHz hsync */
71
        NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
72
        0, FB_VMODE_NONINTERLACED
73
    }, {
74
        /* 800x600 @ 60 Hz, 37.8 kHz hsync */
75
        NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
76
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
77
    }, {
78
        /* 640x480 @ 85 Hz, 43.27 kHz hsync */
79
        NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
80
        0, FB_VMODE_NONINTERLACED
81
    }, {
82
        /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
83
        NULL, 69, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
84
        0, FB_VMODE_INTERLACED
85
    }, {
86
        /* 800x600 @ 72 Hz, 48.0 kHz hsync */
87
        NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
88
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
89
    }, {
90
        /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
91
        NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
92
        0, FB_VMODE_NONINTERLACED
93
    }, {
94
        /* 640x480 @ 100 Hz, 53.01 kHz hsync */
95
        NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
96
        0, FB_VMODE_NONINTERLACED
97
    }, {
98
        /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
99
        NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
100
        0, FB_VMODE_NONINTERLACED
101
    }, {
102
        /* 800x600 @ 85 Hz, 55.84 kHz hsync */
103
        NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
104
        0, FB_VMODE_NONINTERLACED
105
    }, {
106
        /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
107
        NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
108
        0, FB_VMODE_NONINTERLACED
109
    }, {
110
        /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
111
        NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
112
        0, FB_VMODE_INTERLACED
113
    }, {
114
        /* 800x600 @ 100 Hz, 64.02 kHz hsync */
115
        NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
116
        0, FB_VMODE_NONINTERLACED
117
    }, {
118
        /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
119
        NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
120
        0, FB_VMODE_NONINTERLACED
121
    }, {
122
        /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
123
        NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
124
        0, FB_VMODE_NONINTERLACED
125
    }, {
126
        /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
127
        NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
128
        0, FB_VMODE_NONINTERLACED
129
    }, {
130
        /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
131
        NULL, 68, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
132
        0, FB_VMODE_NONINTERLACED      
133
    }, {
134
        /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
135
        "LCD_XGA_75", 75, 1400, 1050, 9271, 120, 56, 13, 0, 112, 3,
136
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
137
    }, {
138
        /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
139
        "LCD_XGA_60", 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
140
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
141
    }, {
142
        /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
143
        NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
144
        0, FB_VMODE_NONINTERLACED
145
    }, {
146
        /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
147
        NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
148
        0, FB_VMODE_NONINTERLACED
149
    }, {
150
        /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
151
        NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
152
        0, FB_VMODE_NONINTERLACED
153
    }, {
154
        /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
155
        NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
156
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
157
    }, {
158
        /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
159
        NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
160
        0, FB_VMODE_NONINTERLACED
161
    }, {
162
        /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
163
        NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
164
        0, FB_VMODE_NONINTERLACED
165
    }, {
166
        /* 1024x768 @ 100Hz, 80.21 kHz hsync */
167
        NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
168
        0, FB_VMODE_NONINTERLACED
169
    }, {
170
        /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
171
        NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
172
        0, FB_VMODE_NONINTERLACED
173
    }, {
174
        /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
175
        NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
176
        0, FB_VMODE_NONINTERLACED
177
    }, {
178
        /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
179
        NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
180
        0, FB_VMODE_NONINTERLACED
181
    }, {
182
        /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
183
        NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
184
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
185
    }, {
186
        /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
187
        NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
188
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
189
    }, {
190
        /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
191
        NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
192
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
193
    }, {
194
        /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
195
        NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
196
        0, FB_VMODE_NONINTERLACED
197
    }, {
198
        /* 1800x1440 @ 64Hz, 96.15 kHz hsync  */
199
        NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
200
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
201
    }, {
202
        /* 1800x1440 @ 70Hz, 104.52 kHz hsync  */
203
        NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
204
        FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
205
    }, {
206
        /* 512x384 @ 78 Hz, 31.50 kHz hsync */
207
        NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
208
        0, FB_VMODE_NONINTERLACED
209
    }, {
210
        /* 512x384 @ 85 Hz, 34.38 kHz hsync */
211
        NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
212
        0, FB_VMODE_NONINTERLACED
213
    }, {
214
        /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
215
        NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
216
        0, FB_VMODE_DOUBLE
217
    }, {
218
        /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
219
        NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
220
        0, FB_VMODE_DOUBLE
221
    }, {
222
        /* 320x240 @ 72 Hz, 36.5 kHz hsync */
223
        NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
224
        0, FB_VMODE_DOUBLE
225
    }, {
226
        /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
227
        NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
228
        0, FB_VMODE_DOUBLE
229
    }, {
230
        /* 400x300 @ 60 Hz, 37.8 kHz hsync */
231
        NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
232
        0, FB_VMODE_DOUBLE
233
    }, {
234
        /* 400x300 @ 72 Hz, 48.0 kHz hsync */
235
        NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
236
        0, FB_VMODE_DOUBLE
237
    }, {
238
        /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
239
        NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
240
        0, FB_VMODE_DOUBLE
241
    }, {
242
        /* 480x300 @ 60 Hz, 37.8 kHz hsync */
243
        NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
244
        0, FB_VMODE_DOUBLE
245
    }, {
246
        /* 480x300 @ 63 Hz, 39.6 kHz hsync */
247
        NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
248
        0, FB_VMODE_DOUBLE
249
    }, {
250
        /* 480x300 @ 72 Hz, 48.0 kHz hsync */
251
        NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
252
        0, FB_VMODE_DOUBLE
253
    },
254
};
255
 
256
const struct fb_videomode vesa_modes[] = {
257
        /* 0 640x350-85 VESA */
258
        { NULL, 85, 640, 350, 31746,  96, 32, 60, 32, 64, 3,
259
          FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED },
260
        /* 1 640x400-85 VESA */
261
        { NULL, 85, 640, 400, 31746,  96, 32, 41, 01, 64, 3,
262
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
263
        /* 2 720x400-85 VESA */
264
        { NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
265
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
266
        /* 3 640x480-60 VESA */
267
        { NULL, 60, 640, 480, 39682,  48, 16, 33, 10, 96, 2,
268
          0, FB_VMODE_NONINTERLACED },
269
        /* 4 640x480-72 VESA */
270
        { NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
271
          0, FB_VMODE_NONINTERLACED },
272
        /* 5 640x480-75 VESA */
273
        { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
274
          0, FB_VMODE_NONINTERLACED },
275
        /* 6 640x480-85 VESA */
276
        { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
277
          0, FB_VMODE_NONINTERLACED },
278
        /* 7 800x600-56 VESA */
279
        { NULL, 56, 800, 600, 27777, 128, 24, 22, 01, 72, 2,
280
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
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, FB_VMODE_NONINTERLACED },
284
        /* 9 800x600-72 VESA */
285
        { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
286
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
287
        /* 10 800x600-75 VESA */
288
        { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
289
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
290
        /* 11 800x600-85 VESA */
291
        { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
292
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
293
        /* 12 1024x768i-43 VESA */
294
        { NULL, 53, 1024, 768, 22271, 56, 8, 41, 0, 176, 8,
295
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_INTERLACED },
296
        /* 13 1024x768-60 VESA */
297
        { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
298
          0, FB_VMODE_NONINTERLACED },
299
        /* 14 1024x768-70 VESA */
300
        { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
301
          0, FB_VMODE_NONINTERLACED },
302
        /* 15 1024x768-75 VESA */
303
        { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
304
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
305
        /* 16 1024x768-85 VESA */
306
        { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
307
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
308
        /* 17 1152x864-75 VESA */
309
        { NULL, 75, 1153, 864, 9259, 256, 64, 32, 1, 128, 3,
310
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
311
        /* 18 1280x960-60 VESA */
312
        { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
313
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
314
        /* 19 1280x960-85 VESA */
315
        { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
316
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
317
        /* 20 1280x1024-60 VESA */
318
        { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
319
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
320
        /* 21 1280x1024-75 VESA */
321
        { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
322
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
323
        /* 22 1280x1024-85 VESA */
324
        { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
325
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
326
        /* 23 1600x1200-60 VESA */
327
        { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
328
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
329
        /* 24 1600x1200-65 VESA */
330
        { NULL, 65, 1600, 1200, 5698, 304,  64, 46, 1, 192, 3,
331
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
332
        /* 25 1600x1200-70 VESA */
333
        { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
334
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
335
        /* 26 1600x1200-75 VESA */
336
        { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
337
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
338
        /* 27 1600x1200-85 VESA */
339
        { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
340
          FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
341
        /* 28 1792x1344-60 VESA */
342
        { NULL, 60, 1792, 1344, 4882, 328, 128, 46, 1, 200, 3,
343
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
344
        /* 29 1792x1344-75 VESA */
345
        { NULL, 75, 1792, 1344, 3831, 352, 96, 69, 1, 216, 3,
346
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
347
        /* 30 1856x1392-60 VESA */
348
        { NULL, 60, 1856, 1392, 4580, 352, 96, 43, 1, 224, 3,
349
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
350
        /* 31 1856x1392-75 VESA */
351
        { NULL, 75, 1856, 1392, 3472, 352, 128, 104, 1, 224, 3,
352
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
353
        /* 32 1920x1440-60 VESA */
354
        { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 200, 3,
355
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
356
        /* 33 1920x1440-75 VESA */
357
        { NULL, 60, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
358
          FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
359
};
360
 
361
static int __init my_atoi(const char *name)
362
{
363
    int val = 0;
364
 
365
    for (;; name++) {
366
        switch (*name) {
367
            case '0'...'9':
368
                val = 10*val+(*name-'0');
369
                break;
370
            default:
371
                return val;
372
        }
373
    }
374
}
375
 
376
/**
377
 *      __fb_try_mode - test a video mode
378
 *      @var: frame buffer user defined part of display
379
 *      @info: frame buffer info structure
380
 *      @mode: frame buffer video mode structure
381
 *      @bpp: color depth in bits per pixel
382
 *
383
 *      Tries a video mode to test it's validity for device @info.
384
 *
385
 *      Returns 1 on success.
386
 *
387
 */
388
 
389
int __fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
390
                  const struct fb_videomode *mode, unsigned int bpp)
391
{
392
    int err = 1;
393
 
394
    DPRINTK("Trying mode %s %dx%d-%d@%d\n", mode->name ? mode->name : "noname",
395
            mode->xres, mode->yres, bpp, mode->refresh);
396
    var->xres = mode->xres;
397
    var->yres = mode->yres;
398
    var->xres_virtual = mode->xres;
399
    var->yres_virtual = mode->yres;
400
    var->xoffset = 0;
401
    var->yoffset = 0;
402
    var->bits_per_pixel = bpp;
403
    var->activate |= FB_ACTIVATE_TEST;
404
    var->pixclock = mode->pixclock;
405
    var->left_margin = mode->left_margin;
406
    var->right_margin = mode->right_margin;
407
    var->upper_margin = mode->upper_margin;
408
    var->lower_margin = mode->lower_margin;
409
    var->hsync_len = mode->hsync_len;
410
    var->vsync_len = mode->vsync_len;
411
    var->sync = mode->sync;
412
    var->vmode = mode->vmode;
413
    if (info->fbops->fb_check_var)
414
        err = info->fbops->fb_check_var(var, info);
415
    var->activate &= ~FB_ACTIVATE_TEST;
416
    return !err;
417
}
418
 
419
 
420
/**
421
 *      fb_find_mode - finds a valid video mode
422
 *      @var: frame buffer user defined part of display
423
 *      @info: frame buffer info structure
424
 *      @mode_option: string video mode to find
425
 *      @db: video mode database
426
 *      @dbsize: size of @db
427
 *      @default_mode: default video mode to fall back to
428
 *      @default_bpp: default color depth in bits per pixel
429
 *
430
 *      Finds a suitable video mode, starting with the specified mode
431
 *      in @mode_option with fallback to @default_mode.  If
432
 *      @default_mode fails, all modes in the video mode database will
433
 *      be tried.
434
 *
435
 *      Valid mode specifiers for @mode_option:
436
 *
437
 *      <xres>x<yres>[-<bpp>][@<refresh>] or
438
 *      <name>[-<bpp>][@<refresh>]
439
 *
440
 *      with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
441
 *      <name> a string.
442
 *
443
 *      NOTE: The passed struct @var is _not_ cleared!  This allows you
444
 *      to supply values for e.g. the grayscale and accel_flags fields.
445
 *
446
 *      Returns zero for failure, 1 if using specified @mode_option,
447
 *      2 if using specified @mode_option with an ignored refresh rate,
448
 *      3 if default mode is used, 4 if fall back to any valid mode.
449
 *
450
 */
451
 
452
int __init fb_find_mode(struct fb_var_screeninfo *var,
453
                        struct fb_info *info, const char *mode_option,
454
                        const struct fb_videomode *db, unsigned int dbsize,
455
                        const struct fb_videomode *default_mode,
456
                        unsigned int default_bpp)
457
{
458
    int i, j;
459
 
460
    /* Set up defaults */
461
    if (!db) {
462
        db = modedb;
463
        dbsize = sizeof(modedb)/sizeof(*modedb);
464
    }
465
    if (!default_mode)
466
        default_mode = &modedb[DEFAULT_MODEDB_INDEX];
467
    if (!default_bpp)
468
        default_bpp = 8;
469
 
470
    /* Did the user specify a video mode? */
471
    if (mode_option || (mode_option = global_mode_option)) {
472
        const char *name = mode_option;
473
        unsigned int namelen = strlen(name);
474
        int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
475
        unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
476
        int yres_specified = 0;
477
 
478
        for (i = namelen-1; i >= 0; i--) {
479
            switch (name[i]) {
480
                case '@':
481
                    namelen = i;
482
                    if (!refresh_specified && !bpp_specified &&
483
                        !yres_specified) {
484
                        refresh = my_atoi(&name[i+1]);
485
                        refresh_specified = 1;
486
                    } else
487
                        goto done;
488
                    break;
489
                case '-':
490
                    namelen = i;
491
                    if (!bpp_specified && !yres_specified) {
492
                        bpp = my_atoi(&name[i+1]);
493
                        bpp_specified = 1;
494
                    } else
495
                        goto done;
496
                    break;
497
                case 'x':
498
                    if (!yres_specified) {
499
                        yres = my_atoi(&name[i+1]);
500
                        yres_specified = 1;
501
                    } else
502
                        goto done;
503
                    break;
504
                case '0'...'9':
505
                    break;
506
                default:
507
                    goto done;
508
            }
509
        }
510
        if (i < 0 && yres_specified) {
511
            xres = my_atoi(name);
512
            res_specified = 1;
513
        }
514
done:
515
        for (i = refresh_specified; i >= 0; i--) {
516
            DPRINTK("Trying specified video mode%s\n",
517
                    i ? "" : " (ignoring refresh rate)");
518
            for (j = 0; j < dbsize; j++)
519
                if ((name_matches(db[j], name, namelen) ||
520
                     (res_specified && res_matches(db[j], xres, yres))) &&
521
                    (!i || db[j].refresh == refresh) &&
522
                    __fb_try_mode(var, info, &db[j], bpp))
523
                    return 2-i;
524
        }
525
    }
526
 
527
    DPRINTK("Trying default video mode\n");
528
    if (__fb_try_mode(var, info, default_mode, default_bpp))
529
        return 3;
530
 
531
    DPRINTK("Trying all modes\n");
532
    for (i = 0; i < dbsize; i++)
533
        if (__fb_try_mode(var, info, &db[i], default_bpp))
534
            return 4;
535
 
536
    DPRINTK("No valid mode found\n");
537
    return 0;
538
}
539
 
540
EXPORT_SYMBOL(__fb_try_mode);
541
EXPORT_SYMBOL(vesa_modes);