blob: a9a907c440d73ee89f2acc8fd20d7aa905230b43 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/fb.h>
Andy Shevchenko2cb96f82009-12-15 16:46:24 -080017#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#undef DEBUG
20
21#define name_matches(v, s, l) \
22 ((v).name && !strncmp((s), (v).name, (l)) && strlen((v).name) == (l))
23#define res_matches(v, x, y) \
24 ((v).xres == (x) && (v).yres == (y))
25
26#ifdef DEBUG
Harvey Harrison5ae12172008-04-28 02:15:47 -070027#define DPRINTK(fmt, args...) printk("modedb %s: " fmt, __func__ , ## args)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#else
29#define DPRINTK(fmt, args...)
30#endif
31
Geert Uytterhoeven9a054fb2007-10-16 01:29:51 -070032const char *fb_mode_option;
Geoff Levand659179b2008-06-05 22:46:44 -070033EXPORT_SYMBOL_GPL(fb_mode_option);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053035/*
36 * Standard video mode definitions (taken from XFree86)
37 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039static const struct fb_videomode modedb[] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 /* 640x400 @ 70 Hz, 31.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053042 { NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, 0,
43 FB_VMODE_NONINTERLACED },
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 /* 640x480 @ 60 Hz, 31.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053046 { NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2, 0,
47 FB_VMODE_NONINTERLACED },
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 /* 800x600 @ 56 Hz, 35.15 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053050 { NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2, 0,
51 FB_VMODE_NONINTERLACED },
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053054 { NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, 0,
55 FB_VMODE_INTERLACED },
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 /* 640x400 @ 85 Hz, 37.86 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053058 { NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
59 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 /* 640x480 @ 72 Hz, 36.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053062 { NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, 0,
63 FB_VMODE_NONINTERLACED },
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 /* 640x480 @ 75 Hz, 37.50 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053066 { NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0,
67 FB_VMODE_NONINTERLACED },
68
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 /* 800x600 @ 60 Hz, 37.8 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053070 { NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
71 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
72 FB_VMODE_NONINTERLACED },
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 /* 640x480 @ 85 Hz, 43.27 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053075 { NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, 0,
76 FB_VMODE_NONINTERLACED },
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053079 { NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, 0,
80 FB_VMODE_INTERLACED },
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 /* 800x600 @ 72 Hz, 48.0 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053082 { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
83 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
84 FB_VMODE_NONINTERLACED },
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053087 { NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, 0,
88 FB_VMODE_NONINTERLACED },
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* 640x480 @ 100 Hz, 53.01 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053091 { NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6, 0,
92 FB_VMODE_NONINTERLACED },
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053095 { NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, 0,
96 FB_VMODE_NONINTERLACED },
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 /* 800x600 @ 85 Hz, 55.84 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +053099 { NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, 0,
100 FB_VMODE_NONINTERLACED },
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530103 { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0,
104 FB_VMODE_NONINTERLACED },
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530107 { NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12, 0,
108 FB_VMODE_INTERLACED },
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 /* 800x600 @ 100 Hz, 64.02 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530111 { NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, 0,
112 FB_VMODE_NONINTERLACED },
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530115 { NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, 0,
116 FB_VMODE_NONINTERLACED },
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530119 { NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, 0,
120 FB_VMODE_NONINTERLACED },
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530123 { NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, 0,
124 FB_VMODE_NONINTERLACED },
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530127 { NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, 0,
128 FB_VMODE_NONINTERLACED },
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530131 { NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
132 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
133 FB_VMODE_NONINTERLACED },
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530136 { NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
137 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
138 FB_VMODE_NONINTERLACED },
139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530141 { NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, 0,
142 FB_VMODE_NONINTERLACED },
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530145 { NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, 0,
146 FB_VMODE_NONINTERLACED },
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530149 { NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, 0,
150 FB_VMODE_NONINTERLACED },
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530153 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
154 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
155 FB_VMODE_NONINTERLACED },
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530158 { NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, 0,
159 FB_VMODE_NONINTERLACED },
160
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530162 { NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, 0,
163 FB_VMODE_NONINTERLACED },
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /* 1024x768 @ 100Hz, 80.21 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530166 { NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, 0,
167 FB_VMODE_NONINTERLACED },
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530170 { NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, 0,
171 FB_VMODE_NONINTERLACED },
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530174 { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, 0,
175 FB_VMODE_NONINTERLACED },
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530178 { NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, 0,
179 FB_VMODE_NONINTERLACED },
180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530182 { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
183 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
184 FB_VMODE_NONINTERLACED },
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530187 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
188 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
189 FB_VMODE_NONINTERLACED },
190
Olaf Heringb0c87972006-03-27 01:17:38 -0800191 /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530192 { NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
193 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
194 FB_VMODE_NONINTERLACED },
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530197 { NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
198 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
199 FB_VMODE_NONINTERLACED },
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530202 { NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, 0,
203 FB_VMODE_NONINTERLACED },
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530206 { NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
207 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
208 FB_VMODE_NONINTERLACED },
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530211 { NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
212 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
213 FB_VMODE_NONINTERLACED },
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /* 512x384 @ 78 Hz, 31.50 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530216 { NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0,
217 FB_VMODE_NONINTERLACED },
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 /* 512x384 @ 85 Hz, 34.38 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530220 { NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, 0,
221 FB_VMODE_NONINTERLACED },
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530224 { NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0,
225 FB_VMODE_DOUBLE },
226
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530228 { NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, 0,
229 FB_VMODE_DOUBLE },
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 /* 320x240 @ 72 Hz, 36.5 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530232 { NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0,
233 FB_VMODE_DOUBLE },
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530236 { NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, 0,
237 FB_VMODE_DOUBLE },
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 /* 400x300 @ 60 Hz, 37.8 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530240 { NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, 0,
241 FB_VMODE_DOUBLE },
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 /* 400x300 @ 72 Hz, 48.0 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530244 { NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3, 0,
245 FB_VMODE_DOUBLE },
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530248 { NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, 0,
249 FB_VMODE_DOUBLE },
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 /* 480x300 @ 60 Hz, 37.8 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530252 { NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, 0,
253 FB_VMODE_DOUBLE },
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 /* 480x300 @ 63 Hz, 39.6 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530256 { NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, 0,
257 FB_VMODE_DOUBLE },
258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /* 480x300 @ 72 Hz, 48.0 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530260 { NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, 0,
261 FB_VMODE_DOUBLE },
262
Antonino Daplasdb6778d2005-08-08 14:22:43 +0800263 /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530264 { NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
265 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
266 FB_VMODE_NONINTERLACED },
267
Michael Hanselmann1dfcdfa2005-11-08 21:39:06 -0800268 /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530269 { NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
270 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
271 FB_VMODE_NONINTERLACED },
272
Dennis Munsief71689e2006-06-26 00:26:39 -0700273 /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530274 { NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5, 0,
275 FB_VMODE_NONINTERLACED },
276
Alex545c4422008-01-17 15:21:18 -0800277 /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530278 { NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3, 0,
279 FB_VMODE_NONINTERLACED },
280
281 /* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
282 { NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5, 0,
283 FB_VMODE_INTERLACED },
284
285 /* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
286 { NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5, 0,
287 FB_VMODE_INTERLACED },
288
Mayuresh Janorkar17ca20c2011-01-06 16:02:42 +0900289 /* 864x480 @ 60 Hz, 35.15 kHz hsync */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530290 { NULL, 60, 864, 480, 27777, 1, 1, 1, 1, 0, 0,
291 0, FB_VMODE_NONINTERLACED },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292};
293
294#ifdef CONFIG_FB_MODE_HELPERS
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100295const struct fb_videomode cea_modes[64] = {
296 /* #1: 640x480p@59.94/60Hz */
297 [1] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530298 NULL, 60, 640, 480, 39722, 48, 16, 33, 10, 96, 2, 0,
299 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100300 },
301 /* #3: 720x480p@59.94/60Hz */
302 [3] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530303 NULL, 60, 720, 480, 37037, 60, 16, 30, 9, 62, 6, 0,
304 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100305 },
306 /* #5: 1920x1080i@59.94/60Hz */
307 [5] = {
Arnd Hannemann20069202010-11-18 09:45:42 +0000308 NULL, 60, 1920, 1080, 13763, 148, 88, 15, 2, 44, 5,
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530309 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
310 FB_VMODE_INTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100311 },
312 /* #7: 720(1440)x480iH@59.94/60Hz */
313 [7] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530314 NULL, 60, 1440, 480, 18554/*37108*/, 114, 38, 15, 4, 124, 3, 0,
315 FB_VMODE_INTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100316 },
317 /* #9: 720(1440)x240pH@59.94/60Hz */
318 [9] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530319 NULL, 60, 1440, 240, 18554, 114, 38, 16, 4, 124, 3, 0,
320 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100321 },
322 /* #18: 720x576pH@50Hz */
323 [18] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530324 NULL, 50, 720, 576, 37037, 68, 12, 39, 5, 64, 5, 0,
325 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100326 },
327 /* #19: 1280x720p@50Hz */
328 [19] = {
Arnd Hannemann20069202010-11-18 09:45:42 +0000329 NULL, 50, 1280, 720, 13468, 220, 440, 20, 5, 40, 5,
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530330 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
331 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100332 },
333 /* #20: 1920x1080i@50Hz */
334 [20] = {
Arnd Hannemann20069202010-11-18 09:45:42 +0000335 NULL, 50, 1920, 1080, 13480, 148, 528, 15, 5, 528, 5,
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530336 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
337 FB_VMODE_INTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100338 },
339 /* #32: 1920x1080p@23.98/24Hz */
340 [32] = {
Arnd Hannemann20069202010-11-18 09:45:42 +0000341 NULL, 24, 1920, 1080, 13468, 148, 638, 36, 4, 44, 5,
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530342 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
343 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100344 },
345 /* #35: (2880)x480p4x@59.94/60Hz */
346 [35] = {
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530347 NULL, 60, 2880, 480, 9250, 240, 64, 30, 9, 248, 6, 0,
348 FB_VMODE_NONINTERLACED, 0,
Guennadi Liakhovetski0ad83f62010-11-11 15:45:04 +0100349 },
350};
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352const struct fb_videomode vesa_modes[] = {
353 /* 0 640x350-85 VESA */
354 { NULL, 85, 640, 350, 31746, 96, 32, 60, 32, 64, 3,
355 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA},
356 /* 1 640x400-85 VESA */
357 { NULL, 85, 640, 400, 31746, 96, 32, 41, 01, 64, 3,
358 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
359 /* 2 720x400-85 VESA */
360 { NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
361 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
362 /* 3 640x480-60 VESA */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530363 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
365 /* 4 640x480-72 VESA */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530366 { NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
368 /* 5 640x480-75 VESA */
369 { NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
370 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
371 /* 6 640x480-85 VESA */
372 { NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
373 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
374 /* 7 800x600-56 VESA */
375 { NULL, 56, 800, 600, 27777, 128, 24, 22, 01, 72, 2,
376 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
377 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
378 /* 8 800x600-60 VESA */
379 { NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
380 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
381 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
382 /* 9 800x600-72 VESA */
383 { NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
384 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
385 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
386 /* 10 800x600-75 VESA */
387 { NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
388 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
389 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
390 /* 11 800x600-85 VESA */
391 { NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
392 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
393 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
394 /* 12 1024x768i-43 VESA */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700395 { NULL, 43, 1024, 768, 22271, 56, 8, 41, 0, 176, 8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
397 FB_VMODE_INTERLACED, FB_MODE_IS_VESA },
398 /* 13 1024x768-60 VESA */
399 { NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
400 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
401 /* 14 1024x768-70 VESA */
402 { NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
403 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
404 /* 15 1024x768-75 VESA */
405 { NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
406 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
407 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
408 /* 16 1024x768-85 VESA */
409 { NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
410 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
411 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
412 /* 17 1152x864-75 VESA */
Jiri Moravec3efbb982009-01-06 14:42:29 -0800413 { NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
415 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
416 /* 18 1280x960-60 VESA */
417 { NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
418 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
419 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
420 /* 19 1280x960-85 VESA */
421 { NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
422 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
423 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
424 /* 20 1280x1024-60 VESA */
425 { NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
426 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
427 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
428 /* 21 1280x1024-75 VESA */
429 { NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
430 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
431 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
432 /* 22 1280x1024-85 VESA */
433 { NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
434 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
435 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
436 /* 23 1600x1200-60 VESA */
437 { NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
438 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
439 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
440 /* 24 1600x1200-65 VESA */
441 { NULL, 65, 1600, 1200, 5698, 304, 64, 46, 1, 192, 3,
442 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
443 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
444 /* 25 1600x1200-70 VESA */
445 { NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
446 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
447 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
448 /* 26 1600x1200-75 VESA */
Mayuresh Janorkarccd8c792011-01-11 19:54:03 +0530449 { NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
451 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
452 /* 27 1600x1200-85 VESA */
453 { NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
454 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
455 FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
456 /* 28 1792x1344-60 VESA */
457 { NULL, 60, 1792, 1344, 4882, 328, 128, 46, 1, 200, 3,
458 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
459 /* 29 1792x1344-75 VESA */
460 { NULL, 75, 1792, 1344, 3831, 352, 96, 69, 1, 216, 3,
461 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
462 /* 30 1856x1392-60 VESA */
463 { NULL, 60, 1856, 1392, 4580, 352, 96, 43, 1, 224, 3,
464 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
465 /* 31 1856x1392-75 VESA */
466 { NULL, 75, 1856, 1392, 3472, 352, 128, 104, 1, 224, 3,
467 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
468 /* 32 1920x1440-60 VESA */
469 { NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 200, 3,
470 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
471 /* 33 1920x1440-75 VESA */
Antonino A. Daplas9d775e172007-10-16 01:28:47 -0700472 { NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
474};
475EXPORT_SYMBOL(vesa_modes);
476#endif /* CONFIG_FB_MODE_HELPERS */
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478/**
479 * fb_try_mode - test a video mode
480 * @var: frame buffer user defined part of display
481 * @info: frame buffer info structure
482 * @mode: frame buffer video mode structure
483 * @bpp: color depth in bits per pixel
484 *
485 * Tries a video mode to test it's validity for device @info.
486 *
487 * Returns 1 on success.
488 *
489 */
490
491static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
492 const struct fb_videomode *mode, unsigned int bpp)
493{
Timur Tabif92d39e2011-09-13 11:05:08 -0500494 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Timur Tabif92d39e2011-09-13 11:05:08 -0500496 DPRINTK("Trying mode %s %dx%d-%d@%d\n",
497 mode->name ? mode->name : "noname",
498 mode->xres, mode->yres, bpp, mode->refresh);
499 var->xres = mode->xres;
500 var->yres = mode->yres;
501 var->xres_virtual = mode->xres;
502 var->yres_virtual = mode->yres;
503 var->xoffset = 0;
504 var->yoffset = 0;
505 var->bits_per_pixel = bpp;
506 var->activate |= FB_ACTIVATE_TEST;
507 var->pixclock = mode->pixclock;
508 var->left_margin = mode->left_margin;
509 var->right_margin = mode->right_margin;
510 var->upper_margin = mode->upper_margin;
511 var->lower_margin = mode->lower_margin;
512 var->hsync_len = mode->hsync_len;
513 var->vsync_len = mode->vsync_len;
514 var->sync = mode->sync;
515 var->vmode = mode->vmode;
516 if (info->fbops->fb_check_var)
517 err = info->fbops->fb_check_var(var, info);
518 var->activate &= ~FB_ACTIVATE_TEST;
519 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520}
521
522/**
Timur Tabif92d39e2011-09-13 11:05:08 -0500523 * fb_find_mode - finds a valid video mode
524 * @var: frame buffer user defined part of display
525 * @info: frame buffer info structure
526 * @mode_option: string video mode to find
527 * @db: video mode database
528 * @dbsize: size of @db
529 * @default_mode: default video mode to fall back to
530 * @default_bpp: default color depth in bits per pixel
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 *
Timur Tabif92d39e2011-09-13 11:05:08 -0500532 * Finds a suitable video mode, starting with the specified mode
533 * in @mode_option with fallback to @default_mode. If
534 * @default_mode fails, all modes in the video mode database will
535 * be tried.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 *
Timur Tabif92d39e2011-09-13 11:05:08 -0500537 * Valid mode specifiers for @mode_option:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 *
Timur Tabif92d39e2011-09-13 11:05:08 -0500539 * <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m] or
540 * <name>[-<bpp>][@<refresh>]
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 *
Timur Tabif92d39e2011-09-13 11:05:08 -0500542 * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
543 * <name> a string.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 *
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700545 * If 'M' is present after yres (and before refresh/bpp if present),
546 * the function will compute the timings using VESA(tm) Coordinated
547 * Video Timings (CVT). If 'R' is present after 'M', will compute with
548 * reduced blanking (for flatpanels). If 'i' is present, compute
549 * interlaced mode. If 'm' is present, add margins equal to 1.8%
550 * of xres rounded down to 8 pixels, and 1.8% of yres. The char
551 * 'i' and 'm' must be after 'M' and 'R'. Example:
552 *
553 * 1024x768MR-8@60m - Reduced blank with margins at 60Hz.
554 *
Timur Tabif92d39e2011-09-13 11:05:08 -0500555 * NOTE: The passed struct @var is _not_ cleared! This allows you
556 * to supply values for e.g. the grayscale and accel_flags fields.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 *
Timur Tabif92d39e2011-09-13 11:05:08 -0500558 * Returns zero for failure, 1 if using specified @mode_option,
559 * 2 if using specified @mode_option with an ignored refresh rate,
560 * 3 if default mode is used, 4 if fall back to any valid mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 *
562 */
563
564int fb_find_mode(struct fb_var_screeninfo *var,
565 struct fb_info *info, const char *mode_option,
566 const struct fb_videomode *db, unsigned int dbsize,
567 const struct fb_videomode *default_mode,
568 unsigned int default_bpp)
569{
Timur Tabif92d39e2011-09-13 11:05:08 -0500570 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Timur Tabif92d39e2011-09-13 11:05:08 -0500572 /* Set up defaults */
573 if (!db) {
574 db = modedb;
575 dbsize = ARRAY_SIZE(modedb);
Antonino A. Daplas96fe6a22005-09-09 13:09:58 -0700576 }
577
Timur Tabif92d39e2011-09-13 11:05:08 -0500578 if (!default_mode)
579 default_mode = &db[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
Timur Tabif92d39e2011-09-13 11:05:08 -0500581 if (!default_bpp)
582 default_bpp = 8;
583
584 /* Did the user specify a video mode? */
585 if (!mode_option)
586 mode_option = fb_mode_option;
587 if (mode_option) {
588 const char *name = mode_option;
589 unsigned int namelen = strlen(name);
590 int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
591 unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
592 int yres_specified = 0, cvt = 0, rb = 0, interlace = 0;
593 int margins = 0;
594 u32 best, diff, tdiff;
595
596 for (i = namelen-1; i >= 0; i--) {
597 switch (name[i]) {
598 case '@':
599 namelen = i;
600 if (!refresh_specified && !bpp_specified &&
601 !yres_specified) {
602 refresh = simple_strtol(&name[i+1], NULL,
603 10);
604 refresh_specified = 1;
605 if (cvt || rb)
606 cvt = 0;
607 } else
608 goto done;
609 break;
610 case '-':
611 namelen = i;
612 if (!bpp_specified && !yres_specified) {
613 bpp = simple_strtol(&name[i+1], NULL,
614 10);
615 bpp_specified = 1;
616 if (cvt || rb)
617 cvt = 0;
618 } else
619 goto done;
620 break;
621 case 'x':
622 if (!yres_specified) {
623 yres = simple_strtol(&name[i+1], NULL,
624 10);
625 yres_specified = 1;
626 } else
627 goto done;
628 break;
629 case '0' ... '9':
630 break;
631 case 'M':
632 if (!yres_specified)
633 cvt = 1;
634 break;
635 case 'R':
636 if (!cvt)
637 rb = 1;
638 break;
639 case 'm':
640 if (!cvt)
641 margins = 1;
642 break;
643 case 'i':
644 if (!cvt)
645 interlace = 1;
646 break;
647 default:
648 goto done;
649 }
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700650 }
Timur Tabif92d39e2011-09-13 11:05:08 -0500651 if (i < 0 && yres_specified) {
652 xres = simple_strtol(name, NULL, 10);
653 res_specified = 1;
654 }
655done:
656 if (cvt) {
657 struct fb_videomode cvt_mode;
658 int ret;
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700659
Timur Tabif92d39e2011-09-13 11:05:08 -0500660 DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
661 (refresh) ? refresh : 60,
662 (rb) ? " reduced blanking" : "",
663 (margins) ? " with margins" : "",
664 (interlace) ? " interlaced" : "");
665
666 memset(&cvt_mode, 0, sizeof(cvt_mode));
667 cvt_mode.xres = xres;
668 cvt_mode.yres = yres;
669 cvt_mode.refresh = (refresh) ? refresh : 60;
670
671 if (interlace)
672 cvt_mode.vmode |= FB_VMODE_INTERLACED;
673 else
674 cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
675
676 ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
677
678 if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
679 DPRINTK("modedb CVT: CVT mode ok\n");
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700680 return 1;
Timur Tabif92d39e2011-09-13 11:05:08 -0500681 }
682
683 DPRINTK("CVT mode invalid, getting mode from database\n");
684 }
685
686 DPRINTK("Trying specified video mode%s %ix%i\n",
687 refresh_specified ? "" : " (ignoring refresh rate)",
688 xres, yres);
689
690 if (!refresh_specified) {
691 /*
692 * If the caller has provided a custom mode database and
693 * a valid monspecs structure, we look for the mode with
694 * the highest refresh rate. Otherwise we play it safe
695 * it and try to find a mode with a refresh rate closest
696 * to the standard 60 Hz.
697 */
698 if (db != modedb &&
699 info->monspecs.vfmin && info->monspecs.vfmax &&
700 info->monspecs.hfmin && info->monspecs.hfmax &&
701 info->monspecs.dclkmax) {
702 refresh = 1000;
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700703 } else {
Timur Tabif92d39e2011-09-13 11:05:08 -0500704 refresh = 60;
705 }
706 }
707
708 diff = -1;
709 best = -1;
710 for (i = 0; i < dbsize; i++) {
711 if ((name_matches(db[i], name, namelen) ||
712 (res_specified && res_matches(db[i], xres, yres))) &&
713 !fb_try_mode(var, info, &db[i], bpp)) {
714 if (refresh_specified && db[i].refresh == refresh)
715 return 1;
716
Michal Januszewski1c5dd172007-10-16 01:29:19 -0700717 if (abs(db[i].refresh - refresh) < diff) {
718 diff = abs(db[i].refresh - refresh);
719 best = i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 }
722 }
Timur Tabif92d39e2011-09-13 11:05:08 -0500723 if (best != -1) {
724 fb_try_mode(var, info, &db[best], bpp);
725 return (refresh_specified) ? 2 : 1;
726 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
Timur Tabif92d39e2011-09-13 11:05:08 -0500728 diff = 2 * (xres + yres);
729 best = -1;
730 DPRINTK("Trying best-fit modes\n");
731 for (i = 0; i < dbsize; i++) {
732 DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
733 if (!fb_try_mode(var, info, &db[i], bpp)) {
734 tdiff = abs(db[i].xres - xres) +
735 abs(db[i].yres - yres);
Michal Januszewski6b745b62008-04-28 02:14:48 -0700736
Timur Tabif92d39e2011-09-13 11:05:08 -0500737 /*
738 * Penalize modes with resolutions smaller
739 * than requested.
740 */
741 if (xres > db[i].xres || yres > db[i].yres)
742 tdiff += xres + yres;
Michal Januszewski6b745b62008-04-28 02:14:48 -0700743
Timur Tabif92d39e2011-09-13 11:05:08 -0500744 if (diff > tdiff) {
745 diff = tdiff;
746 best = i;
747 }
Michal Januszewski6b745b62008-04-28 02:14:48 -0700748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 }
Timur Tabif92d39e2011-09-13 11:05:08 -0500750 if (best != -1) {
751 fb_try_mode(var, info, &db[best], bpp);
752 return 5;
753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
Timur Tabif92d39e2011-09-13 11:05:08 -0500756 DPRINTK("Trying default video mode\n");
757 if (!fb_try_mode(var, info, default_mode, default_bpp))
758 return 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Timur Tabif92d39e2011-09-13 11:05:08 -0500760 DPRINTK("Trying all modes\n");
761 for (i = 0; i < dbsize; i++)
762 if (!fb_try_mode(var, info, &db[i], default_bpp))
763 return 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Timur Tabif92d39e2011-09-13 11:05:08 -0500765 DPRINTK("No valid mode found\n");
766 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767}
768
769/**
770 * fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
771 * @mode: pointer to struct fb_videomode
772 * @var: pointer to struct fb_var_screeninfo
773 */
774void fb_var_to_videomode(struct fb_videomode *mode,
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800775 const struct fb_var_screeninfo *var)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776{
777 u32 pixclock, hfreq, htotal, vtotal;
778
779 mode->name = NULL;
780 mode->xres = var->xres;
781 mode->yres = var->yres;
782 mode->pixclock = var->pixclock;
783 mode->hsync_len = var->hsync_len;
784 mode->vsync_len = var->vsync_len;
785 mode->left_margin = var->left_margin;
786 mode->right_margin = var->right_margin;
787 mode->upper_margin = var->upper_margin;
788 mode->lower_margin = var->lower_margin;
789 mode->sync = var->sync;
790 mode->vmode = var->vmode & FB_VMODE_MASK;
791 mode->flag = FB_MODE_IS_FROM_VAR;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800792 mode->refresh = 0;
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 if (!var->pixclock)
795 return;
796
797 pixclock = PICOS2KHZ(var->pixclock) * 1000;
798
799 htotal = var->xres + var->right_margin + var->hsync_len +
800 var->left_margin;
801 vtotal = var->yres + var->lower_margin + var->vsync_len +
802 var->upper_margin;
803
804 if (var->vmode & FB_VMODE_INTERLACED)
805 vtotal /= 2;
806 if (var->vmode & FB_VMODE_DOUBLE)
807 vtotal *= 2;
808
809 hfreq = pixclock/htotal;
810 mode->refresh = hfreq/vtotal;
811}
812
813/**
814 * fb_videomode_to_var - convert fb_videomode to fb_var_screeninfo
815 * @var: pointer to struct fb_var_screeninfo
816 * @mode: pointer to struct fb_videomode
817 */
818void fb_videomode_to_var(struct fb_var_screeninfo *var,
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800819 const struct fb_videomode *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
821 var->xres = mode->xres;
822 var->yres = mode->yres;
Geert Uytterhoevendcfe2662007-02-12 00:55:21 -0800823 var->xres_virtual = mode->xres;
824 var->yres_virtual = mode->yres;
825 var->xoffset = 0;
826 var->yoffset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 var->pixclock = mode->pixclock;
828 var->left_margin = mode->left_margin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 var->right_margin = mode->right_margin;
830 var->upper_margin = mode->upper_margin;
831 var->lower_margin = mode->lower_margin;
Geert Uytterhoevendcfe2662007-02-12 00:55:21 -0800832 var->hsync_len = mode->hsync_len;
833 var->vsync_len = mode->vsync_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 var->sync = mode->sync;
835 var->vmode = mode->vmode & FB_VMODE_MASK;
836}
837
838/**
839 * fb_mode_is_equal - compare 2 videomodes
840 * @mode1: first videomode
841 * @mode2: second videomode
842 *
843 * RETURNS:
844 * 1 if equal, 0 if not
845 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800846int fb_mode_is_equal(const struct fb_videomode *mode1,
847 const struct fb_videomode *mode2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 return (mode1->xres == mode2->xres &&
850 mode1->yres == mode2->yres &&
851 mode1->pixclock == mode2->pixclock &&
852 mode1->hsync_len == mode2->hsync_len &&
853 mode1->vsync_len == mode2->vsync_len &&
854 mode1->left_margin == mode2->left_margin &&
855 mode1->right_margin == mode2->right_margin &&
856 mode1->upper_margin == mode2->upper_margin &&
857 mode1->lower_margin == mode2->lower_margin &&
858 mode1->sync == mode2->sync &&
859 mode1->vmode == mode2->vmode);
860}
861
862/**
863 * fb_find_best_mode - find best matching videomode
864 * @var: pointer to struct fb_var_screeninfo
865 * @head: pointer to struct list_head of modelist
866 *
867 * RETURNS:
868 * struct fb_videomode, NULL if none found
869 *
870 * IMPORTANT:
871 * This function assumes that all modelist entries in
872 * info->modelist are valid.
873 *
874 * NOTES:
875 * Finds best matching videomode which has an equal or greater dimension than
876 * var->xres and var->yres. If more than 1 videomode is found, will return
877 * the videomode with the highest refresh rate
878 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800879const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
880 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
882 struct list_head *pos;
883 struct fb_modelist *modelist;
884 struct fb_videomode *mode, *best = NULL;
885 u32 diff = -1;
886
887 list_for_each(pos, head) {
888 u32 d;
889
890 modelist = list_entry(pos, struct fb_modelist, list);
891 mode = &modelist->mode;
892
893 if (mode->xres >= var->xres && mode->yres >= var->yres) {
894 d = (mode->xres - var->xres) +
895 (mode->yres - var->yres);
896 if (diff > d) {
897 diff = d;
898 best = mode;
Antonino A. Daplas17cc62812006-06-26 00:26:44 -0700899 } else if (diff == d && best &&
900 mode->refresh > best->refresh)
901 best = mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903 }
904 return best;
905}
906
907/**
Michal Januszewski8fb65672005-11-07 01:00:47 -0800908 * fb_find_nearest_mode - find closest videomode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 *
Michal Januszewski8fb65672005-11-07 01:00:47 -0800910 * @mode: pointer to struct fb_videomode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 * @head: pointer to modelist
912 *
913 * Finds best matching videomode, smaller or greater in dimension.
914 * If more than 1 videomode is found, will return the videomode with
Michal Januszewski8fb65672005-11-07 01:00:47 -0800915 * the closest refresh rate.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800917const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
918 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
920 struct list_head *pos;
921 struct fb_modelist *modelist;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800922 struct fb_videomode *cmode, *best = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 u32 diff = -1, diff_refresh = -1;
924
925 list_for_each(pos, head) {
926 u32 d;
927
928 modelist = list_entry(pos, struct fb_modelist, list);
Michal Januszewski8fb65672005-11-07 01:00:47 -0800929 cmode = &modelist->mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Michal Januszewski8fb65672005-11-07 01:00:47 -0800931 d = abs(cmode->xres - mode->xres) +
932 abs(cmode->yres - mode->yres);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 if (diff > d) {
934 diff = d;
Andrew Kepharte504b842010-12-13 09:46:34 -0600935 diff_refresh = abs(cmode->refresh - mode->refresh);
Michal Januszewski8fb65672005-11-07 01:00:47 -0800936 best = cmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 } else if (diff == d) {
Michal Januszewski8fb65672005-11-07 01:00:47 -0800938 d = abs(cmode->refresh - mode->refresh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 if (diff_refresh > d) {
940 diff_refresh = d;
Michal Januszewski8fb65672005-11-07 01:00:47 -0800941 best = cmode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 }
943 }
944 }
945
946 return best;
947}
948
949/**
950 * fb_match_mode - find a videomode which exactly matches the timings in var
951 * @var: pointer to struct fb_var_screeninfo
952 * @head: pointer to struct list_head of modelist
953 *
954 * RETURNS:
955 * struct fb_videomode, NULL if none found
956 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800957const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
958 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
960 struct list_head *pos;
961 struct fb_modelist *modelist;
962 struct fb_videomode *m, mode;
963
964 fb_var_to_videomode(&mode, var);
965 list_for_each(pos, head) {
966 modelist = list_entry(pos, struct fb_modelist, list);
967 m = &modelist->mode;
968 if (fb_mode_is_equal(m, &mode))
969 return m;
970 }
971 return NULL;
972}
973
974/**
Ben Hutchingsa8b19252010-03-10 15:21:49 -0800975 * fb_add_videomode - adds videomode entry to modelist
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 * @mode: videomode to add
977 * @head: struct list_head of modelist
978 *
979 * NOTES:
980 * Will only add unmatched mode entries
981 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -0800982int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
984 struct list_head *pos;
985 struct fb_modelist *modelist;
986 struct fb_videomode *m;
987 int found = 0;
988
989 list_for_each(pos, head) {
990 modelist = list_entry(pos, struct fb_modelist, list);
991 m = &modelist->mode;
992 if (fb_mode_is_equal(m, mode)) {
993 found = 1;
994 break;
995 }
996 }
997 if (!found) {
998 modelist = kmalloc(sizeof(struct fb_modelist),
999 GFP_KERNEL);
1000
1001 if (!modelist)
1002 return -ENOMEM;
1003 modelist->mode = *mode;
1004 list_add(&modelist->list, head);
1005 }
1006 return 0;
1007}
1008
1009/**
Ben Hutchingsa8b19252010-03-10 15:21:49 -08001010 * fb_delete_videomode - removed videomode entry from modelist
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 * @mode: videomode to remove
1012 * @head: struct list_head of modelist
1013 *
1014 * NOTES:
1015 * Will remove all matching mode entries
1016 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08001017void fb_delete_videomode(const struct fb_videomode *mode,
1018 struct list_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019{
1020 struct list_head *pos, *n;
1021 struct fb_modelist *modelist;
1022 struct fb_videomode *m;
1023
1024 list_for_each_safe(pos, n, head) {
1025 modelist = list_entry(pos, struct fb_modelist, list);
1026 m = &modelist->mode;
1027 if (fb_mode_is_equal(m, mode)) {
1028 list_del(pos);
1029 kfree(pos);
1030 }
1031 }
1032}
1033
1034/**
Ben Hutchingsa8b19252010-03-10 15:21:49 -08001035 * fb_destroy_modelist - destroy modelist
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 * @head: struct list_head of modelist
1037 */
1038void fb_destroy_modelist(struct list_head *head)
1039{
1040 struct list_head *pos, *n;
1041
1042 list_for_each_safe(pos, n, head) {
1043 list_del(pos);
1044 kfree(pos);
1045 }
1046}
Michal Januszewski9953d232007-10-16 01:28:23 -07001047EXPORT_SYMBOL_GPL(fb_destroy_modelist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049/**
Ben Hutchingsa8b19252010-03-10 15:21:49 -08001050 * fb_videomode_to_modelist - convert mode array to mode list
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 * @modedb: array of struct fb_videomode
1052 * @num: number of entries in array
1053 * @head: struct list_head of modelist
1054 */
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08001055void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 struct list_head *head)
1057{
1058 int i;
1059
1060 INIT_LIST_HEAD(head);
1061
1062 for (i = 0; i < num; i++) {
1063 if (fb_add_videomode(&modedb[i], head))
1064 return;
1065 }
1066}
1067
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08001068const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
1069 struct list_head *head)
Antonino A. Daplas003cfc02005-11-07 01:00:54 -08001070{
1071 struct list_head *pos;
1072 struct fb_modelist *modelist;
Geert Uytterhoeven9791d762007-02-12 00:55:19 -08001073 const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
Antonino A. Daplas003cfc02005-11-07 01:00:54 -08001074 int first = 0;
1075
1076 if (!head->prev || !head->next || list_empty(head))
1077 goto finished;
1078
1079 /* get the first detailed mode and the very first mode */
1080 list_for_each(pos, head) {
1081 modelist = list_entry(pos, struct fb_modelist, list);
1082 m = &modelist->mode;
1083
1084 if (!first) {
1085 m1 = m;
1086 first = 1;
1087 }
1088
1089 if (m->flag & FB_MODE_IS_FIRST) {
1090 md = m;
1091 break;
1092 }
1093 }
1094
1095 /* first detailed timing is preferred */
1096 if (specs->misc & FB_MISC_1ST_DETAIL) {
1097 best = md;
1098 goto finished;
1099 }
1100
1101 /* find best mode based on display width and height */
1102 if (specs->max_x && specs->max_y) {
1103 struct fb_var_screeninfo var;
1104
1105 memset(&var, 0, sizeof(struct fb_var_screeninfo));
1106 var.xres = (specs->max_x * 7200)/254;
1107 var.yres = (specs->max_y * 7200)/254;
1108 m = fb_find_best_mode(&var, head);
1109 if (m) {
1110 best = m;
1111 goto finished;
1112 }
1113 }
1114
1115 /* use first detailed mode */
1116 if (md) {
1117 best = md;
1118 goto finished;
1119 }
1120
1121 /* last resort, use the very first mode */
1122 best = m1;
1123finished:
1124 return best;
1125}
1126EXPORT_SYMBOL(fb_find_best_display);
1127
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128EXPORT_SYMBOL(fb_videomode_to_var);
1129EXPORT_SYMBOL(fb_var_to_videomode);
1130EXPORT_SYMBOL(fb_mode_is_equal);
1131EXPORT_SYMBOL(fb_add_videomode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132EXPORT_SYMBOL(fb_match_mode);
1133EXPORT_SYMBOL(fb_find_best_mode);
1134EXPORT_SYMBOL(fb_find_nearest_mode);
1135EXPORT_SYMBOL(fb_videomode_to_modelist);
1136EXPORT_SYMBOL(fb_find_mode);
Tormod Volden1bae8522011-05-28 15:06:11 +00001137EXPORT_SYMBOL(fb_find_mode_cvt);