xref: /openbmc/linux/drivers/video/fbdev/core/modedb.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
119757fc8STomi Valkeinen /*
219757fc8STomi Valkeinen  *  linux/drivers/video/modedb.c -- Standard video mode database management
319757fc8STomi Valkeinen  *
419757fc8STomi Valkeinen  *	Copyright (C) 1999 Geert Uytterhoeven
519757fc8STomi Valkeinen  *
619757fc8STomi Valkeinen  *	2001 - Documented with DocBook
719757fc8STomi Valkeinen  *	- Brad Douglas <brad@neruo.com>
819757fc8STomi Valkeinen  *
919757fc8STomi Valkeinen  *  This file is subject to the terms and conditions of the GNU General Public
1019757fc8STomi Valkeinen  *  License. See the file COPYING in the main directory of this archive for
1119757fc8STomi Valkeinen  *  more details.
1219757fc8STomi Valkeinen  */
1319757fc8STomi Valkeinen 
1419757fc8STomi Valkeinen #include <linux/module.h>
1519757fc8STomi Valkeinen #include <linux/slab.h>
1619757fc8STomi Valkeinen #include <linux/fb.h>
1719757fc8STomi Valkeinen #include <linux/kernel.h>
1819757fc8STomi Valkeinen 
1919757fc8STomi Valkeinen #undef DEBUG
2019757fc8STomi Valkeinen 
2119757fc8STomi Valkeinen #define name_matches(v, s, l) \
2219757fc8STomi Valkeinen     ((v).name && !strncmp((s), (v).name, (l)) && strlen((v).name) == (l))
2319757fc8STomi Valkeinen #define res_matches(v, x, y) \
2419757fc8STomi Valkeinen     ((v).xres == (x) && (v).yres == (y))
2519757fc8STomi Valkeinen 
2619757fc8STomi Valkeinen #ifdef DEBUG
2719757fc8STomi Valkeinen #define DPRINTK(fmt, args...)	printk("modedb %s: " fmt, __func__ , ## args)
2819757fc8STomi Valkeinen #else
2919757fc8STomi Valkeinen #define DPRINTK(fmt, args...)
3019757fc8STomi Valkeinen #endif
3119757fc8STomi Valkeinen 
3219757fc8STomi Valkeinen /*
3319757fc8STomi Valkeinen  *  Standard video mode definitions (taken from XFree86)
3419757fc8STomi Valkeinen  */
3519757fc8STomi Valkeinen 
3619757fc8STomi Valkeinen static const struct fb_videomode modedb[] = {
3719757fc8STomi Valkeinen 
3819757fc8STomi Valkeinen 	/* 640x400 @ 70 Hz, 31.5 kHz hsync */
3919757fc8STomi Valkeinen 	{ NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2, 0,
4019757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
4119757fc8STomi Valkeinen 
4219757fc8STomi Valkeinen 	/* 640x480 @ 60 Hz, 31.5 kHz hsync */
4319757fc8STomi Valkeinen 	{ NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,	0,
4419757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
4519757fc8STomi Valkeinen 
4619757fc8STomi Valkeinen 	/* 800x600 @ 56 Hz, 35.15 kHz hsync */
4719757fc8STomi Valkeinen 	{ NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,	0,
4819757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
4919757fc8STomi Valkeinen 
5019757fc8STomi Valkeinen 	/* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
5119757fc8STomi Valkeinen 	{ NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8, 0,
5219757fc8STomi Valkeinen 		FB_VMODE_INTERLACED },
5319757fc8STomi Valkeinen 
5419757fc8STomi Valkeinen 	/* 640x400 @ 85 Hz, 37.86 kHz hsync */
5519757fc8STomi Valkeinen 	{ NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
5619757fc8STomi Valkeinen 		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED },
5719757fc8STomi Valkeinen 
5819757fc8STomi Valkeinen 	/* 640x480 @ 72 Hz, 36.5 kHz hsync */
5919757fc8STomi Valkeinen 	{ NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3, 0,
6019757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
6119757fc8STomi Valkeinen 
6219757fc8STomi Valkeinen 	/* 640x480 @ 75 Hz, 37.50 kHz hsync */
6319757fc8STomi Valkeinen 	{ NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,	0,
6419757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
6519757fc8STomi Valkeinen 
6619757fc8STomi Valkeinen 	/* 800x600 @ 60 Hz, 37.8 kHz hsync */
6719757fc8STomi Valkeinen 	{ NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
6819757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
6919757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
7019757fc8STomi Valkeinen 
7119757fc8STomi Valkeinen 	/* 640x480 @ 85 Hz, 43.27 kHz hsync */
7219757fc8STomi Valkeinen 	{ NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3, 0,
7319757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
7419757fc8STomi Valkeinen 
7519757fc8STomi Valkeinen 	/* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
7619757fc8STomi Valkeinen 	{ NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10, 0,
7719757fc8STomi Valkeinen 		FB_VMODE_INTERLACED },
7819757fc8STomi Valkeinen 	/* 800x600 @ 72 Hz, 48.0 kHz hsync */
7919757fc8STomi Valkeinen 	{ NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
8019757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
8119757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
8219757fc8STomi Valkeinen 
8319757fc8STomi Valkeinen 	/* 1024x768 @ 60 Hz, 48.4 kHz hsync */
8419757fc8STomi Valkeinen 	{ NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6, 0,
8519757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
8619757fc8STomi Valkeinen 
8719757fc8STomi Valkeinen 	/* 640x480 @ 100 Hz, 53.01 kHz hsync */
8819757fc8STomi Valkeinen 	{ NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,	0,
8919757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
9019757fc8STomi Valkeinen 
9119757fc8STomi Valkeinen 	/* 1152x864 @ 60 Hz, 53.5 kHz hsync */
9219757fc8STomi Valkeinen 	{ NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8, 0,
9319757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
9419757fc8STomi Valkeinen 
9519757fc8STomi Valkeinen 	/* 800x600 @ 85 Hz, 55.84 kHz hsync */
9619757fc8STomi Valkeinen 	{ NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5, 0,
9719757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
9819757fc8STomi Valkeinen 
9919757fc8STomi Valkeinen 	/* 1024x768 @ 70 Hz, 56.5 kHz hsync */
10019757fc8STomi Valkeinen 	{ NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0,
10119757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
10219757fc8STomi Valkeinen 
10319757fc8STomi Valkeinen 	/* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
10419757fc8STomi Valkeinen 	{ NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,	0,
10519757fc8STomi Valkeinen 		FB_VMODE_INTERLACED },
10619757fc8STomi Valkeinen 
10719757fc8STomi Valkeinen 	/* 800x600 @ 100 Hz, 64.02 kHz hsync */
10819757fc8STomi Valkeinen 	{ NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6, 0,
10919757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
11019757fc8STomi Valkeinen 
11119757fc8STomi Valkeinen 	/* 1024x768 @ 76 Hz, 62.5 kHz hsync */
11219757fc8STomi Valkeinen 	{ NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3, 0,
11319757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
11419757fc8STomi Valkeinen 
11519757fc8STomi Valkeinen 	/* 1152x864 @ 70 Hz, 62.4 kHz hsync */
11619757fc8STomi Valkeinen 	{ NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10, 0,
11719757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
11819757fc8STomi Valkeinen 
11919757fc8STomi Valkeinen 	/* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
12019757fc8STomi Valkeinen 	{ NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3, 0,
12119757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
12219757fc8STomi Valkeinen 
12319757fc8STomi Valkeinen 	/* 1400x1050 @ 60Hz, 63.9 kHz hsync */
12419757fc8STomi Valkeinen 	{ NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3, 0,
12519757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
12619757fc8STomi Valkeinen 
12719757fc8STomi Valkeinen 	/* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
12819757fc8STomi Valkeinen 	{ NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
12919757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
13019757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
13119757fc8STomi Valkeinen 
13219757fc8STomi Valkeinen 	/* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
13319757fc8STomi Valkeinen 	{ NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
13419757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
13519757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
13619757fc8STomi Valkeinen 
13719757fc8STomi Valkeinen 	/* 1024x768 @ 85 Hz, 70.24 kHz hsync */
13819757fc8STomi Valkeinen 	{ NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6, 0,
13919757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
14019757fc8STomi Valkeinen 
14119757fc8STomi Valkeinen 	/* 1152x864 @ 78 Hz, 70.8 kHz hsync */
14219757fc8STomi Valkeinen 	{ NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12, 0,
14319757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
14419757fc8STomi Valkeinen 
14519757fc8STomi Valkeinen 	/* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
14619757fc8STomi Valkeinen 	{ NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8, 0,
14719757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
14819757fc8STomi Valkeinen 
14919757fc8STomi Valkeinen 	/* 1600x1200 @ 60Hz, 75.00 kHz hsync */
15019757fc8STomi Valkeinen 	{ NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
15119757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
15219757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
15319757fc8STomi Valkeinen 
15419757fc8STomi Valkeinen 	/* 1152x864 @ 84 Hz, 76.0 kHz hsync */
15519757fc8STomi Valkeinen 	{ NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12, 0,
15619757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
15719757fc8STomi Valkeinen 
15819757fc8STomi Valkeinen 	/* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
15919757fc8STomi Valkeinen 	{ NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3, 0,
16019757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
16119757fc8STomi Valkeinen 
16219757fc8STomi Valkeinen 	/* 1024x768 @ 100Hz, 80.21 kHz hsync */
16319757fc8STomi Valkeinen 	{ NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10, 0,
16419757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
16519757fc8STomi Valkeinen 
16619757fc8STomi Valkeinen 	/* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
16719757fc8STomi Valkeinen 	{ NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3, 0,
16819757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
16919757fc8STomi Valkeinen 
17019757fc8STomi Valkeinen 	/* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
17119757fc8STomi Valkeinen 	{ NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3, 0,
17219757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
17319757fc8STomi Valkeinen 
17419757fc8STomi Valkeinen 	/* 1152x864 @ 100 Hz, 89.62 kHz hsync */
17519757fc8STomi Valkeinen 	{ NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19, 0,
17619757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
17719757fc8STomi Valkeinen 
17819757fc8STomi Valkeinen 	/* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
17919757fc8STomi Valkeinen 	{ NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
18019757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
18119757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
18219757fc8STomi Valkeinen 
18319757fc8STomi Valkeinen 	/* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
18419757fc8STomi Valkeinen 	{ NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
18519757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
18619757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
18719757fc8STomi Valkeinen 
18819757fc8STomi Valkeinen 	/* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
18919757fc8STomi Valkeinen 	{ NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
19019757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
19119757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
19219757fc8STomi Valkeinen 
19319757fc8STomi Valkeinen 	/* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
19419757fc8STomi Valkeinen 	{ NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
19519757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
19619757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
19719757fc8STomi Valkeinen 
19819757fc8STomi Valkeinen 	/* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
19919757fc8STomi Valkeinen 	{ NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15, 0,
20019757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
20119757fc8STomi Valkeinen 
20219757fc8STomi Valkeinen 	/* 1800x1440 @ 64Hz, 96.15 kHz hsync  */
20319757fc8STomi Valkeinen 	{ NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
20419757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
20519757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
20619757fc8STomi Valkeinen 
20719757fc8STomi Valkeinen 	/* 1800x1440 @ 70Hz, 104.52 kHz hsync  */
20819757fc8STomi Valkeinen 	{ NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
20919757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
21019757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
21119757fc8STomi Valkeinen 
21219757fc8STomi Valkeinen 	/* 512x384 @ 78 Hz, 31.50 kHz hsync */
21319757fc8STomi Valkeinen 	{ NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0,
21419757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
21519757fc8STomi Valkeinen 
21619757fc8STomi Valkeinen 	/* 512x384 @ 85 Hz, 34.38 kHz hsync */
21719757fc8STomi Valkeinen 	{ NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3, 0,
21819757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
21919757fc8STomi Valkeinen 
22019757fc8STomi Valkeinen 	/* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
22119757fc8STomi Valkeinen 	{ NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0,
22219757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
22319757fc8STomi Valkeinen 
22419757fc8STomi Valkeinen 	/* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
22519757fc8STomi Valkeinen 	{ NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1, 0,
22619757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
22719757fc8STomi Valkeinen 
22819757fc8STomi Valkeinen 	/* 320x240 @ 72 Hz, 36.5 kHz hsync */
22919757fc8STomi Valkeinen 	{ NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0,
23019757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
23119757fc8STomi Valkeinen 
23219757fc8STomi Valkeinen 	/* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
23319757fc8STomi Valkeinen 	{ NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1, 0,
23419757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
23519757fc8STomi Valkeinen 
23619757fc8STomi Valkeinen 	/* 400x300 @ 60 Hz, 37.8 kHz hsync */
23719757fc8STomi Valkeinen 	{ NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2, 0,
23819757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
23919757fc8STomi Valkeinen 
24019757fc8STomi Valkeinen 	/* 400x300 @ 72 Hz, 48.0 kHz hsync */
24119757fc8STomi Valkeinen 	{ NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,	0,
24219757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
24319757fc8STomi Valkeinen 
24419757fc8STomi Valkeinen 	/* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
24519757fc8STomi Valkeinen 	{ NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1, 0,
24619757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
24719757fc8STomi Valkeinen 
24819757fc8STomi Valkeinen 	/* 480x300 @ 60 Hz, 37.8 kHz hsync */
24919757fc8STomi Valkeinen 	{ NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2, 0,
25019757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
25119757fc8STomi Valkeinen 
25219757fc8STomi Valkeinen 	/* 480x300 @ 63 Hz, 39.6 kHz hsync */
25319757fc8STomi Valkeinen 	{ NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2, 0,
25419757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
25519757fc8STomi Valkeinen 
25619757fc8STomi Valkeinen 	/* 480x300 @ 72 Hz, 48.0 kHz hsync */
25719757fc8STomi Valkeinen 	{ NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3, 0,
25819757fc8STomi Valkeinen 		FB_VMODE_DOUBLE },
25919757fc8STomi Valkeinen 
260c8902258SHelge Deller 	/* 1920x1080 @ 60 Hz, 67.3 kHz hsync */
261c8902258SHelge Deller 	{ NULL, 60, 1920, 1080, 6734, 148, 88, 36, 4, 44, 5, 0,
262c8902258SHelge Deller 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
263c8902258SHelge Deller 		FB_VMODE_NONINTERLACED },
264c8902258SHelge Deller 
26519757fc8STomi Valkeinen 	/* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
26619757fc8STomi Valkeinen 	{ NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
26719757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
26819757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
26919757fc8STomi Valkeinen 
27019757fc8STomi Valkeinen 	/* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
27119757fc8STomi Valkeinen 	{ NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
27219757fc8STomi Valkeinen 		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
27319757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
27419757fc8STomi Valkeinen 
27519757fc8STomi Valkeinen 	/* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
27619757fc8STomi Valkeinen 	{ NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5, 0,
27719757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
27819757fc8STomi Valkeinen 
27919757fc8STomi Valkeinen 	/* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
28019757fc8STomi Valkeinen 	{ NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3, 0,
28119757fc8STomi Valkeinen 		FB_VMODE_NONINTERLACED },
28219757fc8STomi Valkeinen 
28319757fc8STomi Valkeinen 	/* 720x576i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
28419757fc8STomi Valkeinen 	{ NULL, 50, 720, 576, 74074, 64, 16, 39, 5, 64, 5, 0,
28519757fc8STomi Valkeinen 		FB_VMODE_INTERLACED },
28619757fc8STomi Valkeinen 
28719757fc8STomi Valkeinen 	/* 800x520i @ 50 Hz, 15.625 kHz hsync (PAL RGB) */
28819757fc8STomi Valkeinen 	{ NULL, 50, 800, 520, 58823, 144, 64, 72, 28, 80, 5, 0,
28919757fc8STomi Valkeinen 		FB_VMODE_INTERLACED },
29019757fc8STomi Valkeinen 
29119757fc8STomi Valkeinen 	/* 864x480 @ 60 Hz, 35.15 kHz hsync */
29219757fc8STomi Valkeinen 	{ NULL, 60, 864, 480, 27777, 1, 1, 1, 1, 0, 0,
29319757fc8STomi Valkeinen 		0, FB_VMODE_NONINTERLACED },
29419757fc8STomi Valkeinen };
29519757fc8STomi Valkeinen 
29619757fc8STomi Valkeinen #ifdef CONFIG_FB_MODE_HELPERS
29719757fc8STomi Valkeinen const struct fb_videomode vesa_modes[] = {
29819757fc8STomi Valkeinen 	/* 0 640x350-85 VESA */
29919757fc8STomi Valkeinen 	{ NULL, 85, 640, 350, 31746,  96, 32, 60, 32, 64, 3,
30019757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA},
30119757fc8STomi Valkeinen 	/* 1 640x400-85 VESA */
30219757fc8STomi Valkeinen 	{ NULL, 85, 640, 400, 31746,  96, 32, 41, 01, 64, 3,
30319757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
30419757fc8STomi Valkeinen 	/* 2 720x400-85 VESA */
30519757fc8STomi Valkeinen 	{ NULL, 85, 721, 400, 28169, 108, 36, 42, 01, 72, 3,
30619757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
30719757fc8STomi Valkeinen 	/* 3 640x480-60 VESA */
30819757fc8STomi Valkeinen 	{ NULL, 60, 640, 480, 39682,  48, 16, 33, 10, 96, 2,
30919757fc8STomi Valkeinen 	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
31019757fc8STomi Valkeinen 	/* 4 640x480-72 VESA */
31119757fc8STomi Valkeinen 	{ NULL, 72, 640, 480, 31746, 128, 24, 29, 9, 40, 2,
31219757fc8STomi Valkeinen 	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
31319757fc8STomi Valkeinen 	/* 5 640x480-75 VESA */
31419757fc8STomi Valkeinen 	{ NULL, 75, 640, 480, 31746, 120, 16, 16, 01, 64, 3,
31519757fc8STomi Valkeinen 	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
31619757fc8STomi Valkeinen 	/* 6 640x480-85 VESA */
31719757fc8STomi Valkeinen 	{ NULL, 85, 640, 480, 27777, 80, 56, 25, 01, 56, 3,
31819757fc8STomi Valkeinen 	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
31919757fc8STomi Valkeinen 	/* 7 800x600-56 VESA */
32019757fc8STomi Valkeinen 	{ NULL, 56, 800, 600, 27777, 128, 24, 22, 01, 72, 2,
32119757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
32219757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
32319757fc8STomi Valkeinen 	/* 8 800x600-60 VESA */
32419757fc8STomi Valkeinen 	{ NULL, 60, 800, 600, 25000, 88, 40, 23, 01, 128, 4,
32519757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
32619757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
32719757fc8STomi Valkeinen 	/* 9 800x600-72 VESA */
32819757fc8STomi Valkeinen 	{ NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
32919757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
33019757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
33119757fc8STomi Valkeinen 	/* 10 800x600-75 VESA */
33219757fc8STomi Valkeinen 	{ NULL, 75, 800, 600, 20202, 160, 16, 21, 01, 80, 3,
33319757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
33419757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
33519757fc8STomi Valkeinen 	/* 11 800x600-85 VESA */
33619757fc8STomi Valkeinen 	{ NULL, 85, 800, 600, 17761, 152, 32, 27, 01, 64, 3,
33719757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
33819757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
33919757fc8STomi Valkeinen         /* 12 1024x768i-43 VESA */
34019757fc8STomi Valkeinen 	{ NULL, 43, 1024, 768, 22271, 56, 8, 41, 0, 176, 8,
34119757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
34219757fc8STomi Valkeinen 	  FB_VMODE_INTERLACED, FB_MODE_IS_VESA },
34319757fc8STomi Valkeinen 	/* 13 1024x768-60 VESA */
34419757fc8STomi Valkeinen 	{ NULL, 60, 1024, 768, 15384, 160, 24, 29, 3, 136, 6,
34519757fc8STomi Valkeinen 	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
34619757fc8STomi Valkeinen 	/* 14 1024x768-70 VESA */
34719757fc8STomi Valkeinen 	{ NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
34819757fc8STomi Valkeinen 	  0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
34919757fc8STomi Valkeinen 	/* 15 1024x768-75 VESA */
35019757fc8STomi Valkeinen 	{ NULL, 75, 1024, 768, 12690, 176, 16, 28, 1, 96, 3,
35119757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
35219757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
35319757fc8STomi Valkeinen 	/* 16 1024x768-85 VESA */
35419757fc8STomi Valkeinen 	{ NULL, 85, 1024, 768, 10582, 208, 48, 36, 1, 96, 3,
35519757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
35619757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
35719757fc8STomi Valkeinen 	/* 17 1152x864-75 VESA */
35819757fc8STomi Valkeinen 	{ NULL, 75, 1152, 864, 9259, 256, 64, 32, 1, 128, 3,
35919757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
36019757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36119757fc8STomi Valkeinen 	/* 18 1280x960-60 VESA */
36219757fc8STomi Valkeinen 	{ NULL, 60, 1280, 960, 9259, 312, 96, 36, 1, 112, 3,
36319757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
36419757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36519757fc8STomi Valkeinen 	/* 19 1280x960-85 VESA */
36619757fc8STomi Valkeinen 	{ NULL, 85, 1280, 960, 6734, 224, 64, 47, 1, 160, 3,
36719757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
36819757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36919757fc8STomi Valkeinen 	/* 20 1280x1024-60 VESA */
37019757fc8STomi Valkeinen 	{ NULL, 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
37119757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
37219757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
37319757fc8STomi Valkeinen 	/* 21 1280x1024-75 VESA */
37419757fc8STomi Valkeinen 	{ NULL, 75, 1280, 1024, 7407, 248, 16, 38, 1, 144, 3,
37519757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
37619757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
37719757fc8STomi Valkeinen 	/* 22 1280x1024-85 VESA */
37819757fc8STomi Valkeinen 	{ NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
37919757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
38019757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38119757fc8STomi Valkeinen 	/* 23 1600x1200-60 VESA */
38219757fc8STomi Valkeinen 	{ NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
38319757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
38419757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38519757fc8STomi Valkeinen 	/* 24 1600x1200-65 VESA */
38619757fc8STomi Valkeinen 	{ NULL, 65, 1600, 1200, 5698, 304,  64, 46, 1, 192, 3,
38719757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
38819757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38919757fc8STomi Valkeinen 	/* 25 1600x1200-70 VESA */
39019757fc8STomi Valkeinen 	{ NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
39119757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
39219757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39319757fc8STomi Valkeinen 	/* 26 1600x1200-75 VESA */
39419757fc8STomi Valkeinen 	{ NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
39519757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
39619757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39719757fc8STomi Valkeinen 	/* 27 1600x1200-85 VESA */
39819757fc8STomi Valkeinen 	{ NULL, 85, 1600, 1200, 4357, 304, 64, 46, 1, 192, 3,
39919757fc8STomi Valkeinen 	  FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
40019757fc8STomi Valkeinen 	  FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
40119757fc8STomi Valkeinen 	/* 28 1792x1344-60 VESA */
40219757fc8STomi Valkeinen 	{ NULL, 60, 1792, 1344, 4882, 328, 128, 46, 1, 200, 3,
40319757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
40419757fc8STomi Valkeinen 	/* 29 1792x1344-75 VESA */
40519757fc8STomi Valkeinen 	{ NULL, 75, 1792, 1344, 3831, 352, 96, 69, 1, 216, 3,
40619757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
40719757fc8STomi Valkeinen 	/* 30 1856x1392-60 VESA */
40819757fc8STomi Valkeinen 	{ NULL, 60, 1856, 1392, 4580, 352, 96, 43, 1, 224, 3,
40919757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
41019757fc8STomi Valkeinen 	/* 31 1856x1392-75 VESA */
41119757fc8STomi Valkeinen 	{ NULL, 75, 1856, 1392, 3472, 352, 128, 104, 1, 224, 3,
41219757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
41319757fc8STomi Valkeinen 	/* 32 1920x1440-60 VESA */
41419757fc8STomi Valkeinen 	{ NULL, 60, 1920, 1440, 4273, 344, 128, 56, 1, 200, 3,
41519757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
41619757fc8STomi Valkeinen 	/* 33 1920x1440-75 VESA */
41719757fc8STomi Valkeinen 	{ NULL, 75, 1920, 1440, 3367, 352, 144, 56, 1, 224, 3,
41819757fc8STomi Valkeinen 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
41937715f55SDavid Ung 	/* 34 1920x1200-60 RB VESA */
42037715f55SDavid Ung 	{ NULL, 60, 1920, 1200, 6493, 80, 48, 26, 3, 32, 6,
42137715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
42237715f55SDavid Ung 	/* 35 1920x1200-60 VESA */
42337715f55SDavid Ung 	{ NULL, 60, 1920, 1200, 5174, 336, 136, 36, 3, 200, 6,
42437715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
42537715f55SDavid Ung 	/* 36 1920x1200-75 VESA */
42637715f55SDavid Ung 	{ NULL, 75, 1920, 1200, 4077, 344, 136, 46, 3, 208, 6,
42737715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
42837715f55SDavid Ung 	/* 37 1920x1200-85 VESA */
42937715f55SDavid Ung 	{ NULL, 85, 1920, 1200, 3555, 352, 144, 53, 3, 208, 6,
43037715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
43137715f55SDavid Ung 	/* 38 2560x1600-60 RB VESA */
43237715f55SDavid Ung 	{ NULL, 60, 2560, 1600, 3724, 80, 48, 37, 3, 32, 6,
43337715f55SDavid Ung 	  FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
43437715f55SDavid Ung 	/* 39 2560x1600-60 VESA */
43537715f55SDavid Ung 	{ NULL, 60, 2560, 1600, 2869, 472, 192, 49, 3, 280, 6,
43637715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
43737715f55SDavid Ung 	/* 40 2560x1600-75 VESA */
43837715f55SDavid Ung 	{ NULL, 75, 2560, 1600, 2256, 488, 208, 63, 3, 280, 6,
43937715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
44037715f55SDavid Ung 	/* 41 2560x1600-85 VESA */
44137715f55SDavid Ung 	{ NULL, 85, 2560, 1600, 1979, 488, 208, 73, 3, 280, 6,
44237715f55SDavid Ung 	  FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
44337715f55SDavid Ung 	/* 42 2560x1600-120 RB VESA */
44437715f55SDavid Ung 	{ NULL, 120, 2560, 1600, 1809, 80, 48, 85, 3, 32, 6,
44537715f55SDavid Ung 	  FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
44619757fc8STomi Valkeinen };
44719757fc8STomi Valkeinen EXPORT_SYMBOL(vesa_modes);
4488f5ee77bSDavid Ung 
4498f5ee77bSDavid Ung const struct dmt_videomode dmt_modes[DMT_SIZE] = {
4508f5ee77bSDavid Ung 	{ 0x01, 0x0000, 0x000000, &vesa_modes[0] },
4518f5ee77bSDavid Ung 	{ 0x02, 0x3119, 0x000000, &vesa_modes[1] },
4528f5ee77bSDavid Ung 	{ 0x03, 0x0000, 0x000000, &vesa_modes[2] },
4538f5ee77bSDavid Ung 	{ 0x04, 0x3140, 0x000000, &vesa_modes[3] },
4548f5ee77bSDavid Ung 	{ 0x05, 0x314c, 0x000000, &vesa_modes[4] },
4558f5ee77bSDavid Ung 	{ 0x06, 0x314f, 0x000000, &vesa_modes[5] },
4568f5ee77bSDavid Ung 	{ 0x07, 0x3159, 0x000000, &vesa_modes[6] },
4578f5ee77bSDavid Ung 	{ 0x08, 0x0000, 0x000000, &vesa_modes[7] },
4588f5ee77bSDavid Ung 	{ 0x09, 0x4540, 0x000000, &vesa_modes[8] },
4598f5ee77bSDavid Ung 	{ 0x0a, 0x454c, 0x000000, &vesa_modes[9] },
4608f5ee77bSDavid Ung 	{ 0x0b, 0x454f, 0x000000, &vesa_modes[10] },
4618f5ee77bSDavid Ung 	{ 0x0c, 0x4559, 0x000000, &vesa_modes[11] },
462ba59bab7SDavid Ung 	{ 0x0d, 0x0000, 0x000000, NULL },
463ba59bab7SDavid Ung 	{ 0x0e, 0x0000, 0x000000, NULL },
4648f5ee77bSDavid Ung 	{ 0x0f, 0x0000, 0x000000, &vesa_modes[12] },
4658f5ee77bSDavid Ung 	{ 0x10, 0x6140, 0x000000, &vesa_modes[13] },
4668f5ee77bSDavid Ung 	{ 0x11, 0x614a, 0x000000, &vesa_modes[14] },
4678f5ee77bSDavid Ung 	{ 0x12, 0x614f, 0x000000, &vesa_modes[15] },
4688f5ee77bSDavid Ung 	{ 0x13, 0x6159, 0x000000, &vesa_modes[16] },
469ba59bab7SDavid Ung 	{ 0x14, 0x0000, 0x000000, NULL },
4708f5ee77bSDavid Ung 	{ 0x15, 0x714f, 0x000000, &vesa_modes[17] },
471ba59bab7SDavid Ung 	{ 0x16, 0x0000, 0x7f1c21, NULL },
472ba59bab7SDavid Ung 	{ 0x17, 0x0000, 0x7f1c28, NULL },
473ba59bab7SDavid Ung 	{ 0x18, 0x0000, 0x7f1c44, NULL },
474ba59bab7SDavid Ung 	{ 0x19, 0x0000, 0x7f1c62, NULL },
475ba59bab7SDavid Ung 	{ 0x1a, 0x0000, 0x000000, NULL },
476ba59bab7SDavid Ung 	{ 0x1b, 0x0000, 0x8f1821, NULL },
477ba59bab7SDavid Ung 	{ 0x1c, 0x8100, 0x8f1828, NULL },
478ba59bab7SDavid Ung 	{ 0x1d, 0x810f, 0x8f1844, NULL },
479ba59bab7SDavid Ung 	{ 0x1e, 0x8119, 0x8f1862, NULL },
480ba59bab7SDavid Ung 	{ 0x1f, 0x0000, 0x000000, NULL },
4818f5ee77bSDavid Ung 	{ 0x20, 0x8140, 0x000000, &vesa_modes[18] },
4828f5ee77bSDavid Ung 	{ 0x21, 0x8159, 0x000000, &vesa_modes[19] },
483ba59bab7SDavid Ung 	{ 0x22, 0x0000, 0x000000, NULL },
4848f5ee77bSDavid Ung 	{ 0x23, 0x8180, 0x000000, &vesa_modes[20] },
4858f5ee77bSDavid Ung 	{ 0x24, 0x818f, 0x000000, &vesa_modes[21] },
4868f5ee77bSDavid Ung 	{ 0x25, 0x8199, 0x000000, &vesa_modes[22] },
487ba59bab7SDavid Ung 	{ 0x26, 0x0000, 0x000000, NULL },
488ba59bab7SDavid Ung 	{ 0x27, 0x0000, 0x000000, NULL },
489ba59bab7SDavid Ung 	{ 0x28, 0x0000, 0x000000, NULL },
490ba59bab7SDavid Ung 	{ 0x29, 0x0000, 0x0c2021, NULL },
491ba59bab7SDavid Ung 	{ 0x2a, 0x9040, 0x0c2028, NULL },
492ba59bab7SDavid Ung 	{ 0x2b, 0x904f, 0x0c2044, NULL },
493ba59bab7SDavid Ung 	{ 0x2c, 0x9059, 0x0c2062, NULL },
494ba59bab7SDavid Ung 	{ 0x2d, 0x0000, 0x000000, NULL },
495ba59bab7SDavid Ung 	{ 0x2e, 0x9500, 0xc11821, NULL },
496ba59bab7SDavid Ung 	{ 0x2f, 0x9500, 0xc11828, NULL },
497ba59bab7SDavid Ung 	{ 0x30, 0x950f, 0xc11844, NULL },
498ba59bab7SDavid Ung 	{ 0x31, 0x9519, 0xc11868, NULL },
499ba59bab7SDavid Ung 	{ 0x32, 0x0000, 0x000000, NULL },
5008f5ee77bSDavid Ung 	{ 0x33, 0xa940, 0x000000, &vesa_modes[23] },
5018f5ee77bSDavid Ung 	{ 0x34, 0xa945, 0x000000, &vesa_modes[24] },
5028f5ee77bSDavid Ung 	{ 0x35, 0xa94a, 0x000000, &vesa_modes[25] },
5038f5ee77bSDavid Ung 	{ 0x36, 0xa94f, 0x000000, &vesa_modes[26] },
5048f5ee77bSDavid Ung 	{ 0x37, 0xa959, 0x000000, &vesa_modes[27] },
505ba59bab7SDavid Ung 	{ 0x38, 0x0000, 0x000000, NULL },
506ba59bab7SDavid Ung 	{ 0x39, 0x0000, 0x0c2821, NULL },
507ba59bab7SDavid Ung 	{ 0x3a, 0xb300, 0x0c2828, NULL },
508ba59bab7SDavid Ung 	{ 0x3b, 0xb30f, 0x0c2844, NULL },
509ba59bab7SDavid Ung 	{ 0x3c, 0xb319, 0x0c2868, NULL },
510ba59bab7SDavid Ung 	{ 0x3d, 0x0000, 0x000000, NULL },
5118f5ee77bSDavid Ung 	{ 0x3e, 0xc140, 0x000000, &vesa_modes[28] },
5128f5ee77bSDavid Ung 	{ 0x3f, 0xc14f, 0x000000, &vesa_modes[29] },
513ba59bab7SDavid Ung 	{ 0x40, 0x0000, 0x000000, NULL},
5148f5ee77bSDavid Ung 	{ 0x41, 0xc940, 0x000000, &vesa_modes[30] },
5158f5ee77bSDavid Ung 	{ 0x42, 0xc94f, 0x000000, &vesa_modes[31] },
516ba59bab7SDavid Ung 	{ 0x43, 0x0000, 0x000000, NULL },
5178f5ee77bSDavid Ung 	{ 0x44, 0x0000, 0x572821, &vesa_modes[34] },
5188f5ee77bSDavid Ung 	{ 0x45, 0xd100, 0x572828, &vesa_modes[35] },
5198f5ee77bSDavid Ung 	{ 0x46, 0xd10f, 0x572844, &vesa_modes[36] },
5208f5ee77bSDavid Ung 	{ 0x47, 0xd119, 0x572862, &vesa_modes[37] },
521ba59bab7SDavid Ung 	{ 0x48, 0x0000, 0x000000, NULL },
5228f5ee77bSDavid Ung 	{ 0x49, 0xd140, 0x000000, &vesa_modes[32] },
5238f5ee77bSDavid Ung 	{ 0x4a, 0xd14f, 0x000000, &vesa_modes[33] },
524ba59bab7SDavid Ung 	{ 0x4b, 0x0000, 0x000000, NULL },
5258f5ee77bSDavid Ung 	{ 0x4c, 0x0000, 0x1f3821, &vesa_modes[38] },
5268f5ee77bSDavid Ung 	{ 0x4d, 0x0000, 0x1f3828, &vesa_modes[39] },
5278f5ee77bSDavid Ung 	{ 0x4e, 0x0000, 0x1f3844, &vesa_modes[40] },
5288f5ee77bSDavid Ung 	{ 0x4f, 0x0000, 0x1f3862, &vesa_modes[41] },
5298f5ee77bSDavid Ung 	{ 0x50, 0x0000, 0x000000, &vesa_modes[42] },
5308f5ee77bSDavid Ung };
5318f5ee77bSDavid Ung EXPORT_SYMBOL(dmt_modes);
53219757fc8STomi Valkeinen #endif /* CONFIG_FB_MODE_HELPERS */
53319757fc8STomi Valkeinen 
53419757fc8STomi Valkeinen /**
53519757fc8STomi Valkeinen  *	fb_try_mode - test a video mode
53619757fc8STomi Valkeinen  *	@var: frame buffer user defined part of display
53719757fc8STomi Valkeinen  *	@info: frame buffer info structure
53819757fc8STomi Valkeinen  *	@mode: frame buffer video mode structure
53919757fc8STomi Valkeinen  *	@bpp: color depth in bits per pixel
54019757fc8STomi Valkeinen  *
54119757fc8STomi Valkeinen  *	Tries a video mode to test it's validity for device @info.
54219757fc8STomi Valkeinen  *
54319757fc8STomi Valkeinen  *	Returns 1 on success.
54419757fc8STomi Valkeinen  *
54519757fc8STomi Valkeinen  */
54619757fc8STomi Valkeinen 
fb_try_mode(struct fb_var_screeninfo * var,struct fb_info * info,const struct fb_videomode * mode,unsigned int bpp)54719757fc8STomi Valkeinen static int fb_try_mode(struct fb_var_screeninfo *var, struct fb_info *info,
54819757fc8STomi Valkeinen 		       const struct fb_videomode *mode, unsigned int bpp)
54919757fc8STomi Valkeinen {
55019757fc8STomi Valkeinen 	int err = 0;
55119757fc8STomi Valkeinen 
55219757fc8STomi Valkeinen 	DPRINTK("Trying mode %s %dx%d-%d@%d\n",
55319757fc8STomi Valkeinen 		mode->name ? mode->name : "noname",
55419757fc8STomi Valkeinen 		mode->xres, mode->yres, bpp, mode->refresh);
55519757fc8STomi Valkeinen 	var->xres = mode->xres;
55619757fc8STomi Valkeinen 	var->yres = mode->yres;
55719757fc8STomi Valkeinen 	var->xres_virtual = mode->xres;
55819757fc8STomi Valkeinen 	var->yres_virtual = mode->yres;
55919757fc8STomi Valkeinen 	var->xoffset = 0;
56019757fc8STomi Valkeinen 	var->yoffset = 0;
56119757fc8STomi Valkeinen 	var->bits_per_pixel = bpp;
56219757fc8STomi Valkeinen 	var->activate |= FB_ACTIVATE_TEST;
56319757fc8STomi Valkeinen 	var->pixclock = mode->pixclock;
56419757fc8STomi Valkeinen 	var->left_margin = mode->left_margin;
56519757fc8STomi Valkeinen 	var->right_margin = mode->right_margin;
56619757fc8STomi Valkeinen 	var->upper_margin = mode->upper_margin;
56719757fc8STomi Valkeinen 	var->lower_margin = mode->lower_margin;
56819757fc8STomi Valkeinen 	var->hsync_len = mode->hsync_len;
56919757fc8STomi Valkeinen 	var->vsync_len = mode->vsync_len;
57019757fc8STomi Valkeinen 	var->sync = mode->sync;
57119757fc8STomi Valkeinen 	var->vmode = mode->vmode;
57219757fc8STomi Valkeinen 	if (info->fbops->fb_check_var)
57319757fc8STomi Valkeinen 		err = info->fbops->fb_check_var(var, info);
57419757fc8STomi Valkeinen 	var->activate &= ~FB_ACTIVATE_TEST;
57519757fc8STomi Valkeinen 	return err;
57619757fc8STomi Valkeinen }
57719757fc8STomi Valkeinen 
57819757fc8STomi Valkeinen /**
57919757fc8STomi Valkeinen  * fb_find_mode - finds a valid video mode
58019757fc8STomi Valkeinen  * @var: frame buffer user defined part of display
58119757fc8STomi Valkeinen  * @info: frame buffer info structure
58219757fc8STomi Valkeinen  * @mode_option: string video mode to find
58319757fc8STomi Valkeinen  * @db: video mode database
58419757fc8STomi Valkeinen  * @dbsize: size of @db
58519757fc8STomi Valkeinen  * @default_mode: default video mode to fall back to
58619757fc8STomi Valkeinen  * @default_bpp: default color depth in bits per pixel
58719757fc8STomi Valkeinen  *
58819757fc8STomi Valkeinen  * Finds a suitable video mode, starting with the specified mode
58919757fc8STomi Valkeinen  * in @mode_option with fallback to @default_mode.  If
59019757fc8STomi Valkeinen  * @default_mode fails, all modes in the video mode database will
59119757fc8STomi Valkeinen  * be tried.
59219757fc8STomi Valkeinen  *
593e32e2fe6SDaniel Vetter  * Valid mode specifiers for @mode_option::
59419757fc8STomi Valkeinen  *
595e32e2fe6SDaniel Vetter  *     <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][p][m]
596e32e2fe6SDaniel Vetter  *
597e32e2fe6SDaniel Vetter  * or ::
598e32e2fe6SDaniel Vetter  *
59919757fc8STomi Valkeinen  *     <name>[-<bpp>][@<refresh>]
60019757fc8STomi Valkeinen  *
60119757fc8STomi Valkeinen  * with <xres>, <yres>, <bpp> and <refresh> decimal numbers and
60219757fc8STomi Valkeinen  * <name> a string.
60319757fc8STomi Valkeinen  *
60419757fc8STomi Valkeinen  * If 'M' is present after yres (and before refresh/bpp if present),
60519757fc8STomi Valkeinen  * the function will compute the timings using VESA(tm) Coordinated
60619757fc8STomi Valkeinen  * Video Timings (CVT).  If 'R' is present after 'M', will compute with
6071ba0a59cSFredrik Noring  * reduced blanking (for flatpanels).  If 'i' or 'p' are present, compute
6081ba0a59cSFredrik Noring  * interlaced or progressive mode.  If 'm' is present, add margins equal
609e32e2fe6SDaniel Vetter  * to 1.8% of xres rounded down to 8 pixels, and 1.8% of yres. The char
610e32e2fe6SDaniel Vetter  * 'i', 'p' and 'm' must be after 'M' and 'R'. Example::
61119757fc8STomi Valkeinen  *
61219757fc8STomi Valkeinen  *     1024x768MR-8@60m - Reduced blank with margins at 60Hz.
61319757fc8STomi Valkeinen  *
61419757fc8STomi Valkeinen  * NOTE: The passed struct @var is _not_ cleared!  This allows you
61519757fc8STomi Valkeinen  * to supply values for e.g. the grayscale and accel_flags fields.
61619757fc8STomi Valkeinen  *
61719757fc8STomi Valkeinen  * Returns zero for failure, 1 if using specified @mode_option,
61819757fc8STomi Valkeinen  * 2 if using specified @mode_option with an ignored refresh rate,
61919757fc8STomi Valkeinen  * 3 if default mode is used, 4 if fall back to any valid mode.
62019757fc8STomi Valkeinen  */
62119757fc8STomi Valkeinen 
fb_find_mode(struct fb_var_screeninfo * var,struct fb_info * info,const char * mode_option,const struct fb_videomode * db,unsigned int dbsize,const struct fb_videomode * default_mode,unsigned int default_bpp)62219757fc8STomi Valkeinen int fb_find_mode(struct fb_var_screeninfo *var,
62319757fc8STomi Valkeinen 		 struct fb_info *info, const char *mode_option,
62419757fc8STomi Valkeinen 		 const struct fb_videomode *db, unsigned int dbsize,
62519757fc8STomi Valkeinen 		 const struct fb_videomode *default_mode,
62619757fc8STomi Valkeinen 		 unsigned int default_bpp)
62719757fc8STomi Valkeinen {
628089d924dSThomas Zimmermann 	char *mode_option_buf = NULL;
62919757fc8STomi Valkeinen 	int i;
63019757fc8STomi Valkeinen 
63119757fc8STomi Valkeinen 	/* Set up defaults */
63219757fc8STomi Valkeinen 	if (!db) {
63319757fc8STomi Valkeinen 		db = modedb;
63419757fc8STomi Valkeinen 		dbsize = ARRAY_SIZE(modedb);
63519757fc8STomi Valkeinen 	}
63619757fc8STomi Valkeinen 
63719757fc8STomi Valkeinen 	if (!default_mode)
63819757fc8STomi Valkeinen 		default_mode = &db[0];
63919757fc8STomi Valkeinen 
64019757fc8STomi Valkeinen 	if (!default_bpp)
64119757fc8STomi Valkeinen 		default_bpp = 8;
64219757fc8STomi Valkeinen 
64319757fc8STomi Valkeinen 	/* Did the user specify a video mode? */
644089d924dSThomas Zimmermann 	if (!mode_option) {
645089d924dSThomas Zimmermann 		fb_get_options(NULL, &mode_option_buf);
646089d924dSThomas Zimmermann 		mode_option = mode_option_buf;
647089d924dSThomas Zimmermann 	}
64819757fc8STomi Valkeinen 	if (mode_option) {
64919757fc8STomi Valkeinen 		const char *name = mode_option;
65019757fc8STomi Valkeinen 		unsigned int namelen = strlen(name);
65119757fc8STomi Valkeinen 		int res_specified = 0, bpp_specified = 0, refresh_specified = 0;
65219757fc8STomi Valkeinen 		unsigned int xres = 0, yres = 0, bpp = default_bpp, refresh = 0;
6531ba0a59cSFredrik Noring 		int yres_specified = 0, cvt = 0, rb = 0;
6541ba0a59cSFredrik Noring 		int interlace_specified = 0, interlace = 0;
65519757fc8STomi Valkeinen 		int margins = 0;
65619757fc8STomi Valkeinen 		u32 best, diff, tdiff;
65719757fc8STomi Valkeinen 
65819757fc8STomi Valkeinen 		for (i = namelen-1; i >= 0; i--) {
65919757fc8STomi Valkeinen 			switch (name[i]) {
66019757fc8STomi Valkeinen 			case '@':
66119757fc8STomi Valkeinen 				namelen = i;
66219757fc8STomi Valkeinen 				if (!refresh_specified && !bpp_specified &&
66319757fc8STomi Valkeinen 				    !yres_specified) {
66419757fc8STomi Valkeinen 					refresh = simple_strtol(&name[i+1], NULL,
66519757fc8STomi Valkeinen 								10);
66619757fc8STomi Valkeinen 					refresh_specified = 1;
66719757fc8STomi Valkeinen 					if (cvt || rb)
66819757fc8STomi Valkeinen 						cvt = 0;
66919757fc8STomi Valkeinen 				} else
67019757fc8STomi Valkeinen 					goto done;
67119757fc8STomi Valkeinen 				break;
67219757fc8STomi Valkeinen 			case '-':
67319757fc8STomi Valkeinen 				namelen = i;
67419757fc8STomi Valkeinen 				if (!bpp_specified && !yres_specified) {
67519757fc8STomi Valkeinen 					bpp = simple_strtol(&name[i+1], NULL,
67619757fc8STomi Valkeinen 							    10);
67719757fc8STomi Valkeinen 					bpp_specified = 1;
67819757fc8STomi Valkeinen 					if (cvt || rb)
67919757fc8STomi Valkeinen 						cvt = 0;
68019757fc8STomi Valkeinen 				} else
68119757fc8STomi Valkeinen 					goto done;
68219757fc8STomi Valkeinen 				break;
68319757fc8STomi Valkeinen 			case 'x':
68419757fc8STomi Valkeinen 				if (!yres_specified) {
68519757fc8STomi Valkeinen 					yres = simple_strtol(&name[i+1], NULL,
68619757fc8STomi Valkeinen 							     10);
68719757fc8STomi Valkeinen 					yres_specified = 1;
68819757fc8STomi Valkeinen 				} else
68919757fc8STomi Valkeinen 					goto done;
69019757fc8STomi Valkeinen 				break;
69119757fc8STomi Valkeinen 			case '0' ... '9':
69219757fc8STomi Valkeinen 				break;
69319757fc8STomi Valkeinen 			case 'M':
69419757fc8STomi Valkeinen 				if (!yres_specified)
69519757fc8STomi Valkeinen 					cvt = 1;
69619757fc8STomi Valkeinen 				break;
69719757fc8STomi Valkeinen 			case 'R':
69819757fc8STomi Valkeinen 				if (!cvt)
69919757fc8STomi Valkeinen 					rb = 1;
70019757fc8STomi Valkeinen 				break;
70119757fc8STomi Valkeinen 			case 'm':
70219757fc8STomi Valkeinen 				if (!cvt)
70319757fc8STomi Valkeinen 					margins = 1;
70419757fc8STomi Valkeinen 				break;
7051ba0a59cSFredrik Noring 			case 'p':
7061ba0a59cSFredrik Noring 				if (!cvt) {
7071ba0a59cSFredrik Noring 					interlace = 0;
7081ba0a59cSFredrik Noring 					interlace_specified = 1;
7091ba0a59cSFredrik Noring 				}
7101ba0a59cSFredrik Noring 				break;
71119757fc8STomi Valkeinen 			case 'i':
7121ba0a59cSFredrik Noring 				if (!cvt) {
71319757fc8STomi Valkeinen 					interlace = 1;
7141ba0a59cSFredrik Noring 					interlace_specified = 1;
7151ba0a59cSFredrik Noring 				}
71619757fc8STomi Valkeinen 				break;
71719757fc8STomi Valkeinen 			default:
71819757fc8STomi Valkeinen 				goto done;
71919757fc8STomi Valkeinen 			}
72019757fc8STomi Valkeinen 		}
72119757fc8STomi Valkeinen 		if (i < 0 && yres_specified) {
72219757fc8STomi Valkeinen 			xres = simple_strtol(name, NULL, 10);
72319757fc8STomi Valkeinen 			res_specified = 1;
72419757fc8STomi Valkeinen 		}
72519757fc8STomi Valkeinen done:
726089d924dSThomas Zimmermann 		kfree(mode_option_buf);
72719757fc8STomi Valkeinen 		if (cvt) {
72819757fc8STomi Valkeinen 			struct fb_videomode cvt_mode;
72919757fc8STomi Valkeinen 			int ret;
73019757fc8STomi Valkeinen 
73119757fc8STomi Valkeinen 			DPRINTK("CVT mode %dx%d@%dHz%s%s%s\n", xres, yres,
73219757fc8STomi Valkeinen 				(refresh) ? refresh : 60,
73319757fc8STomi Valkeinen 				(rb) ? " reduced blanking" : "",
73419757fc8STomi Valkeinen 				(margins) ? " with margins" : "",
73519757fc8STomi Valkeinen 				(interlace) ? " interlaced" : "");
73619757fc8STomi Valkeinen 
73719757fc8STomi Valkeinen 			memset(&cvt_mode, 0, sizeof(cvt_mode));
73819757fc8STomi Valkeinen 			cvt_mode.xres = xres;
73919757fc8STomi Valkeinen 			cvt_mode.yres = yres;
74019757fc8STomi Valkeinen 			cvt_mode.refresh = (refresh) ? refresh : 60;
74119757fc8STomi Valkeinen 
74219757fc8STomi Valkeinen 			if (interlace)
74319757fc8STomi Valkeinen 				cvt_mode.vmode |= FB_VMODE_INTERLACED;
74419757fc8STomi Valkeinen 			else
74519757fc8STomi Valkeinen 				cvt_mode.vmode &= ~FB_VMODE_INTERLACED;
74619757fc8STomi Valkeinen 
74719757fc8STomi Valkeinen 			ret = fb_find_mode_cvt(&cvt_mode, margins, rb);
74819757fc8STomi Valkeinen 
74919757fc8STomi Valkeinen 			if (!ret && !fb_try_mode(var, info, &cvt_mode, bpp)) {
75019757fc8STomi Valkeinen 				DPRINTK("modedb CVT: CVT mode ok\n");
75119757fc8STomi Valkeinen 				return 1;
75219757fc8STomi Valkeinen 			}
75319757fc8STomi Valkeinen 
75419757fc8STomi Valkeinen 			DPRINTK("CVT mode invalid, getting mode from database\n");
75519757fc8STomi Valkeinen 		}
75619757fc8STomi Valkeinen 
75719757fc8STomi Valkeinen 		DPRINTK("Trying specified video mode%s %ix%i\n",
75819757fc8STomi Valkeinen 			refresh_specified ? "" : " (ignoring refresh rate)",
75919757fc8STomi Valkeinen 			xres, yres);
76019757fc8STomi Valkeinen 
76119757fc8STomi Valkeinen 		if (!refresh_specified) {
76219757fc8STomi Valkeinen 			/*
76319757fc8STomi Valkeinen 			 * If the caller has provided a custom mode database and
76419757fc8STomi Valkeinen 			 * a valid monspecs structure, we look for the mode with
76519757fc8STomi Valkeinen 			 * the highest refresh rate.  Otherwise we play it safe
76619757fc8STomi Valkeinen 			 * it and try to find a mode with a refresh rate closest
76719757fc8STomi Valkeinen 			 * to the standard 60 Hz.
76819757fc8STomi Valkeinen 			 */
76919757fc8STomi Valkeinen 			if (db != modedb &&
77019757fc8STomi Valkeinen 			    info->monspecs.vfmin && info->monspecs.vfmax &&
77119757fc8STomi Valkeinen 			    info->monspecs.hfmin && info->monspecs.hfmax &&
77219757fc8STomi Valkeinen 			    info->monspecs.dclkmax) {
77319757fc8STomi Valkeinen 				refresh = 1000;
77419757fc8STomi Valkeinen 			} else {
77519757fc8STomi Valkeinen 				refresh = 60;
77619757fc8STomi Valkeinen 			}
77719757fc8STomi Valkeinen 		}
77819757fc8STomi Valkeinen 
77919757fc8STomi Valkeinen 		diff = -1;
78019757fc8STomi Valkeinen 		best = -1;
78119757fc8STomi Valkeinen 		for (i = 0; i < dbsize; i++) {
78219757fc8STomi Valkeinen 			if ((name_matches(db[i], name, namelen) ||
78319757fc8STomi Valkeinen 			     (res_specified && res_matches(db[i], xres, yres))) &&
78419757fc8STomi Valkeinen 			    !fb_try_mode(var, info, &db[i], bpp)) {
7851ba0a59cSFredrik Noring 				const int db_interlace = (db[i].vmode &
7861ba0a59cSFredrik Noring 					FB_VMODE_INTERLACED ? 1 : 0);
7871ba0a59cSFredrik Noring 				int score = abs(db[i].refresh - refresh);
7881ba0a59cSFredrik Noring 
7891ba0a59cSFredrik Noring 				if (interlace_specified)
7901ba0a59cSFredrik Noring 					score += abs(db_interlace - interlace);
7911ba0a59cSFredrik Noring 
7921ba0a59cSFredrik Noring 				if (!interlace_specified ||
7931ba0a59cSFredrik Noring 				    db_interlace == interlace)
7941ba0a59cSFredrik Noring 					if (refresh_specified &&
7951ba0a59cSFredrik Noring 					    db[i].refresh == refresh)
79619757fc8STomi Valkeinen 						return 1;
79719757fc8STomi Valkeinen 
7981ba0a59cSFredrik Noring 				if (score < diff) {
7991ba0a59cSFredrik Noring 					diff = score;
80019757fc8STomi Valkeinen 					best = i;
80119757fc8STomi Valkeinen 				}
80219757fc8STomi Valkeinen 			}
80319757fc8STomi Valkeinen 		}
80419757fc8STomi Valkeinen 		if (best != -1) {
80519757fc8STomi Valkeinen 			fb_try_mode(var, info, &db[best], bpp);
80619757fc8STomi Valkeinen 			return (refresh_specified) ? 2 : 1;
80719757fc8STomi Valkeinen 		}
80819757fc8STomi Valkeinen 
80919757fc8STomi Valkeinen 		diff = 2 * (xres + yres);
81019757fc8STomi Valkeinen 		best = -1;
81119757fc8STomi Valkeinen 		DPRINTK("Trying best-fit modes\n");
81219757fc8STomi Valkeinen 		for (i = 0; i < dbsize; i++) {
81319757fc8STomi Valkeinen 			DPRINTK("Trying %ix%i\n", db[i].xres, db[i].yres);
81419757fc8STomi Valkeinen 			if (!fb_try_mode(var, info, &db[i], bpp)) {
81519757fc8STomi Valkeinen 				tdiff = abs(db[i].xres - xres) +
81619757fc8STomi Valkeinen 					abs(db[i].yres - yres);
81719757fc8STomi Valkeinen 
81819757fc8STomi Valkeinen 				/*
81919757fc8STomi Valkeinen 				 * Penalize modes with resolutions smaller
82019757fc8STomi Valkeinen 				 * than requested.
82119757fc8STomi Valkeinen 				 */
82219757fc8STomi Valkeinen 				if (xres > db[i].xres || yres > db[i].yres)
82319757fc8STomi Valkeinen 					tdiff += xres + yres;
82419757fc8STomi Valkeinen 
82519757fc8STomi Valkeinen 				if (diff > tdiff) {
82619757fc8STomi Valkeinen 					diff = tdiff;
82719757fc8STomi Valkeinen 					best = i;
82819757fc8STomi Valkeinen 				}
82919757fc8STomi Valkeinen 			}
83019757fc8STomi Valkeinen 		}
83119757fc8STomi Valkeinen 		if (best != -1) {
83219757fc8STomi Valkeinen 			fb_try_mode(var, info, &db[best], bpp);
83319757fc8STomi Valkeinen 			return 5;
83419757fc8STomi Valkeinen 		}
83519757fc8STomi Valkeinen 	}
83619757fc8STomi Valkeinen 
83719757fc8STomi Valkeinen 	DPRINTK("Trying default video mode\n");
83819757fc8STomi Valkeinen 	if (!fb_try_mode(var, info, default_mode, default_bpp))
83919757fc8STomi Valkeinen 		return 3;
84019757fc8STomi Valkeinen 
84119757fc8STomi Valkeinen 	DPRINTK("Trying all modes\n");
84219757fc8STomi Valkeinen 	for (i = 0; i < dbsize; i++)
84319757fc8STomi Valkeinen 		if (!fb_try_mode(var, info, &db[i], default_bpp))
84419757fc8STomi Valkeinen 			return 4;
84519757fc8STomi Valkeinen 
84619757fc8STomi Valkeinen 	DPRINTK("No valid mode found\n");
84719757fc8STomi Valkeinen 	return 0;
84819757fc8STomi Valkeinen }
84919757fc8STomi Valkeinen 
85019757fc8STomi Valkeinen /**
85119757fc8STomi Valkeinen  * fb_var_to_videomode - convert fb_var_screeninfo to fb_videomode
85219757fc8STomi Valkeinen  * @mode: pointer to struct fb_videomode
85319757fc8STomi Valkeinen  * @var: pointer to struct fb_var_screeninfo
85419757fc8STomi Valkeinen  */
fb_var_to_videomode(struct fb_videomode * mode,const struct fb_var_screeninfo * var)85519757fc8STomi Valkeinen void fb_var_to_videomode(struct fb_videomode *mode,
85619757fc8STomi Valkeinen 			 const struct fb_var_screeninfo *var)
85719757fc8STomi Valkeinen {
85819757fc8STomi Valkeinen 	u32 pixclock, hfreq, htotal, vtotal;
85919757fc8STomi Valkeinen 
86019757fc8STomi Valkeinen 	mode->name = NULL;
86119757fc8STomi Valkeinen 	mode->xres = var->xres;
86219757fc8STomi Valkeinen 	mode->yres = var->yres;
86319757fc8STomi Valkeinen 	mode->pixclock = var->pixclock;
86419757fc8STomi Valkeinen 	mode->hsync_len = var->hsync_len;
86519757fc8STomi Valkeinen 	mode->vsync_len = var->vsync_len;
86619757fc8STomi Valkeinen 	mode->left_margin = var->left_margin;
86719757fc8STomi Valkeinen 	mode->right_margin = var->right_margin;
86819757fc8STomi Valkeinen 	mode->upper_margin = var->upper_margin;
86919757fc8STomi Valkeinen 	mode->lower_margin = var->lower_margin;
87019757fc8STomi Valkeinen 	mode->sync = var->sync;
87119757fc8STomi Valkeinen 	mode->vmode = var->vmode & FB_VMODE_MASK;
87219757fc8STomi Valkeinen 	mode->flag = FB_MODE_IS_FROM_VAR;
87319757fc8STomi Valkeinen 	mode->refresh = 0;
87419757fc8STomi Valkeinen 
87519757fc8STomi Valkeinen 	if (!var->pixclock)
87619757fc8STomi Valkeinen 		return;
87719757fc8STomi Valkeinen 
87819757fc8STomi Valkeinen 	pixclock = PICOS2KHZ(var->pixclock) * 1000;
87919757fc8STomi Valkeinen 
88019757fc8STomi Valkeinen 	htotal = var->xres + var->right_margin + var->hsync_len +
88119757fc8STomi Valkeinen 		var->left_margin;
88219757fc8STomi Valkeinen 	vtotal = var->yres + var->lower_margin + var->vsync_len +
88319757fc8STomi Valkeinen 		var->upper_margin;
88419757fc8STomi Valkeinen 
88519757fc8STomi Valkeinen 	if (var->vmode & FB_VMODE_INTERLACED)
88619757fc8STomi Valkeinen 		vtotal /= 2;
88719757fc8STomi Valkeinen 	if (var->vmode & FB_VMODE_DOUBLE)
88819757fc8STomi Valkeinen 		vtotal *= 2;
88919757fc8STomi Valkeinen 
890cf84807fSShile Zhang 	if (!htotal || !vtotal)
891cf84807fSShile Zhang 		return;
892cf84807fSShile Zhang 
89319757fc8STomi Valkeinen 	hfreq = pixclock/htotal;
89419757fc8STomi Valkeinen 	mode->refresh = hfreq/vtotal;
89519757fc8STomi Valkeinen }
89619757fc8STomi Valkeinen 
89719757fc8STomi Valkeinen /**
89819757fc8STomi Valkeinen  * fb_videomode_to_var - convert fb_videomode to fb_var_screeninfo
89919757fc8STomi Valkeinen  * @var: pointer to struct fb_var_screeninfo
90019757fc8STomi Valkeinen  * @mode: pointer to struct fb_videomode
90119757fc8STomi Valkeinen  */
fb_videomode_to_var(struct fb_var_screeninfo * var,const struct fb_videomode * mode)90219757fc8STomi Valkeinen void fb_videomode_to_var(struct fb_var_screeninfo *var,
90319757fc8STomi Valkeinen 			 const struct fb_videomode *mode)
90419757fc8STomi Valkeinen {
90519757fc8STomi Valkeinen 	var->xres = mode->xres;
90619757fc8STomi Valkeinen 	var->yres = mode->yres;
90719757fc8STomi Valkeinen 	var->xres_virtual = mode->xres;
90819757fc8STomi Valkeinen 	var->yres_virtual = mode->yres;
90919757fc8STomi Valkeinen 	var->xoffset = 0;
91019757fc8STomi Valkeinen 	var->yoffset = 0;
91119757fc8STomi Valkeinen 	var->pixclock = mode->pixclock;
91219757fc8STomi Valkeinen 	var->left_margin = mode->left_margin;
91319757fc8STomi Valkeinen 	var->right_margin = mode->right_margin;
91419757fc8STomi Valkeinen 	var->upper_margin = mode->upper_margin;
91519757fc8STomi Valkeinen 	var->lower_margin = mode->lower_margin;
91619757fc8STomi Valkeinen 	var->hsync_len = mode->hsync_len;
91719757fc8STomi Valkeinen 	var->vsync_len = mode->vsync_len;
91819757fc8STomi Valkeinen 	var->sync = mode->sync;
91919757fc8STomi Valkeinen 	var->vmode = mode->vmode & FB_VMODE_MASK;
92019757fc8STomi Valkeinen }
92119757fc8STomi Valkeinen 
92219757fc8STomi Valkeinen /**
92319757fc8STomi Valkeinen  * fb_mode_is_equal - compare 2 videomodes
92419757fc8STomi Valkeinen  * @mode1: first videomode
92519757fc8STomi Valkeinen  * @mode2: second videomode
92619757fc8STomi Valkeinen  *
92719757fc8STomi Valkeinen  * RETURNS:
92819757fc8STomi Valkeinen  * 1 if equal, 0 if not
92919757fc8STomi Valkeinen  */
fb_mode_is_equal(const struct fb_videomode * mode1,const struct fb_videomode * mode2)93019757fc8STomi Valkeinen int fb_mode_is_equal(const struct fb_videomode *mode1,
93119757fc8STomi Valkeinen 		     const struct fb_videomode *mode2)
93219757fc8STomi Valkeinen {
93319757fc8STomi Valkeinen 	return (mode1->xres         == mode2->xres &&
93419757fc8STomi Valkeinen 		mode1->yres         == mode2->yres &&
93519757fc8STomi Valkeinen 		mode1->pixclock     == mode2->pixclock &&
93619757fc8STomi Valkeinen 		mode1->hsync_len    == mode2->hsync_len &&
93719757fc8STomi Valkeinen 		mode1->vsync_len    == mode2->vsync_len &&
93819757fc8STomi Valkeinen 		mode1->left_margin  == mode2->left_margin &&
93919757fc8STomi Valkeinen 		mode1->right_margin == mode2->right_margin &&
94019757fc8STomi Valkeinen 		mode1->upper_margin == mode2->upper_margin &&
94119757fc8STomi Valkeinen 		mode1->lower_margin == mode2->lower_margin &&
94219757fc8STomi Valkeinen 		mode1->sync         == mode2->sync &&
94319757fc8STomi Valkeinen 		mode1->vmode        == mode2->vmode);
94419757fc8STomi Valkeinen }
94519757fc8STomi Valkeinen 
94619757fc8STomi Valkeinen /**
94719757fc8STomi Valkeinen  * fb_find_best_mode - find best matching videomode
94819757fc8STomi Valkeinen  * @var: pointer to struct fb_var_screeninfo
94919757fc8STomi Valkeinen  * @head: pointer to struct list_head of modelist
95019757fc8STomi Valkeinen  *
95119757fc8STomi Valkeinen  * RETURNS:
95219757fc8STomi Valkeinen  * struct fb_videomode, NULL if none found
95319757fc8STomi Valkeinen  *
95419757fc8STomi Valkeinen  * IMPORTANT:
95519757fc8STomi Valkeinen  * This function assumes that all modelist entries in
95619757fc8STomi Valkeinen  * info->modelist are valid.
95719757fc8STomi Valkeinen  *
95819757fc8STomi Valkeinen  * NOTES:
95919757fc8STomi Valkeinen  * Finds best matching videomode which has an equal or greater dimension than
96019757fc8STomi Valkeinen  * var->xres and var->yres.  If more than 1 videomode is found, will return
96119757fc8STomi Valkeinen  * the videomode with the highest refresh rate
96219757fc8STomi Valkeinen  */
fb_find_best_mode(const struct fb_var_screeninfo * var,struct list_head * head)96319757fc8STomi Valkeinen const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
96419757fc8STomi Valkeinen 					     struct list_head *head)
96519757fc8STomi Valkeinen {
96619757fc8STomi Valkeinen 	struct fb_modelist *modelist;
96719757fc8STomi Valkeinen 	struct fb_videomode *mode, *best = NULL;
96819757fc8STomi Valkeinen 	u32 diff = -1;
96919757fc8STomi Valkeinen 
970*1520081aSJinjie Ruan 	list_for_each_entry(modelist, head, list) {
97119757fc8STomi Valkeinen 		u32 d;
97219757fc8STomi Valkeinen 		mode = &modelist->mode;
97319757fc8STomi Valkeinen 
97419757fc8STomi Valkeinen 		if (mode->xres >= var->xres && mode->yres >= var->yres) {
97519757fc8STomi Valkeinen 			d = (mode->xres - var->xres) +
97619757fc8STomi Valkeinen 				(mode->yres - var->yres);
97719757fc8STomi Valkeinen 			if (diff > d) {
97819757fc8STomi Valkeinen 				diff = d;
97919757fc8STomi Valkeinen 				best = mode;
98019757fc8STomi Valkeinen 			} else if (diff == d && best &&
98119757fc8STomi Valkeinen 				   mode->refresh > best->refresh)
98219757fc8STomi Valkeinen 				best = mode;
98319757fc8STomi Valkeinen 		}
98419757fc8STomi Valkeinen 	}
98519757fc8STomi Valkeinen 	return best;
98619757fc8STomi Valkeinen }
98719757fc8STomi Valkeinen 
98819757fc8STomi Valkeinen /**
98919757fc8STomi Valkeinen  * fb_find_nearest_mode - find closest videomode
99019757fc8STomi Valkeinen  *
99119757fc8STomi Valkeinen  * @mode: pointer to struct fb_videomode
99219757fc8STomi Valkeinen  * @head: pointer to modelist
99319757fc8STomi Valkeinen  *
99419757fc8STomi Valkeinen  * Finds best matching videomode, smaller or greater in dimension.
99519757fc8STomi Valkeinen  * If more than 1 videomode is found, will return the videomode with
99619757fc8STomi Valkeinen  * the closest refresh rate.
99719757fc8STomi Valkeinen  */
fb_find_nearest_mode(const struct fb_videomode * mode,struct list_head * head)99819757fc8STomi Valkeinen const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
99919757fc8STomi Valkeinen 					        struct list_head *head)
100019757fc8STomi Valkeinen {
100119757fc8STomi Valkeinen 	struct fb_modelist *modelist;
100219757fc8STomi Valkeinen 	struct fb_videomode *cmode, *best = NULL;
100319757fc8STomi Valkeinen 	u32 diff = -1, diff_refresh = -1;
100419757fc8STomi Valkeinen 
1005*1520081aSJinjie Ruan 	list_for_each_entry(modelist, head, list) {
100619757fc8STomi Valkeinen 		u32 d;
100719757fc8STomi Valkeinen 		cmode = &modelist->mode;
100819757fc8STomi Valkeinen 
100919757fc8STomi Valkeinen 		d = abs(cmode->xres - mode->xres) +
101019757fc8STomi Valkeinen 			abs(cmode->yres - mode->yres);
101119757fc8STomi Valkeinen 		if (diff > d) {
101219757fc8STomi Valkeinen 			diff = d;
101319757fc8STomi Valkeinen 			diff_refresh = abs(cmode->refresh - mode->refresh);
101419757fc8STomi Valkeinen 			best = cmode;
101519757fc8STomi Valkeinen 		} else if (diff == d) {
101619757fc8STomi Valkeinen 			d = abs(cmode->refresh - mode->refresh);
101719757fc8STomi Valkeinen 			if (diff_refresh > d) {
101819757fc8STomi Valkeinen 				diff_refresh = d;
101919757fc8STomi Valkeinen 				best = cmode;
102019757fc8STomi Valkeinen 			}
102119757fc8STomi Valkeinen 		}
102219757fc8STomi Valkeinen 	}
102319757fc8STomi Valkeinen 
102419757fc8STomi Valkeinen 	return best;
102519757fc8STomi Valkeinen }
102619757fc8STomi Valkeinen 
102719757fc8STomi Valkeinen /**
102819757fc8STomi Valkeinen  * fb_match_mode - find a videomode which exactly matches the timings in var
102919757fc8STomi Valkeinen  * @var: pointer to struct fb_var_screeninfo
103019757fc8STomi Valkeinen  * @head: pointer to struct list_head of modelist
103119757fc8STomi Valkeinen  *
103219757fc8STomi Valkeinen  * RETURNS:
103319757fc8STomi Valkeinen  * struct fb_videomode, NULL if none found
103419757fc8STomi Valkeinen  */
fb_match_mode(const struct fb_var_screeninfo * var,struct list_head * head)103519757fc8STomi Valkeinen const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
103619757fc8STomi Valkeinen 					 struct list_head *head)
103719757fc8STomi Valkeinen {
103819757fc8STomi Valkeinen 	struct fb_modelist *modelist;
103919757fc8STomi Valkeinen 	struct fb_videomode *m, mode;
104019757fc8STomi Valkeinen 
104119757fc8STomi Valkeinen 	fb_var_to_videomode(&mode, var);
1042*1520081aSJinjie Ruan 	list_for_each_entry(modelist, head, list) {
104319757fc8STomi Valkeinen 		m = &modelist->mode;
104419757fc8STomi Valkeinen 		if (fb_mode_is_equal(m, &mode))
104519757fc8STomi Valkeinen 			return m;
104619757fc8STomi Valkeinen 	}
104719757fc8STomi Valkeinen 	return NULL;
104819757fc8STomi Valkeinen }
104919757fc8STomi Valkeinen 
105019757fc8STomi Valkeinen /**
105119757fc8STomi Valkeinen  * fb_add_videomode - adds videomode entry to modelist
105219757fc8STomi Valkeinen  * @mode: videomode to add
105319757fc8STomi Valkeinen  * @head: struct list_head of modelist
105419757fc8STomi Valkeinen  *
105519757fc8STomi Valkeinen  * NOTES:
105619757fc8STomi Valkeinen  * Will only add unmatched mode entries
105719757fc8STomi Valkeinen  */
fb_add_videomode(const struct fb_videomode * mode,struct list_head * head)105819757fc8STomi Valkeinen int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
105919757fc8STomi Valkeinen {
106019757fc8STomi Valkeinen 	struct fb_modelist *modelist;
106119757fc8STomi Valkeinen 	struct fb_videomode *m;
106219757fc8STomi Valkeinen 	int found = 0;
106319757fc8STomi Valkeinen 
1064*1520081aSJinjie Ruan 	list_for_each_entry(modelist, head, list) {
106519757fc8STomi Valkeinen 		m = &modelist->mode;
106619757fc8STomi Valkeinen 		if (fb_mode_is_equal(m, mode)) {
106719757fc8STomi Valkeinen 			found = 1;
106819757fc8STomi Valkeinen 			break;
106919757fc8STomi Valkeinen 		}
107019757fc8STomi Valkeinen 	}
107119757fc8STomi Valkeinen 	if (!found) {
107219757fc8STomi Valkeinen 		modelist = kmalloc(sizeof(struct fb_modelist),
107319757fc8STomi Valkeinen 						  GFP_KERNEL);
107419757fc8STomi Valkeinen 
107519757fc8STomi Valkeinen 		if (!modelist)
107619757fc8STomi Valkeinen 			return -ENOMEM;
107719757fc8STomi Valkeinen 		modelist->mode = *mode;
107819757fc8STomi Valkeinen 		list_add(&modelist->list, head);
107919757fc8STomi Valkeinen 	}
108019757fc8STomi Valkeinen 	return 0;
108119757fc8STomi Valkeinen }
108219757fc8STomi Valkeinen 
108319757fc8STomi Valkeinen /**
108419757fc8STomi Valkeinen  * fb_delete_videomode - removed videomode entry from modelist
108519757fc8STomi Valkeinen  * @mode: videomode to remove
108619757fc8STomi Valkeinen  * @head: struct list_head of modelist
108719757fc8STomi Valkeinen  *
108819757fc8STomi Valkeinen  * NOTES:
108919757fc8STomi Valkeinen  * Will remove all matching mode entries
109019757fc8STomi Valkeinen  */
fb_delete_videomode(const struct fb_videomode * mode,struct list_head * head)109119757fc8STomi Valkeinen void fb_delete_videomode(const struct fb_videomode *mode,
109219757fc8STomi Valkeinen 			 struct list_head *head)
109319757fc8STomi Valkeinen {
109419757fc8STomi Valkeinen 	struct list_head *pos, *n;
109519757fc8STomi Valkeinen 	struct fb_modelist *modelist;
109619757fc8STomi Valkeinen 	struct fb_videomode *m;
109719757fc8STomi Valkeinen 
109819757fc8STomi Valkeinen 	list_for_each_safe(pos, n, head) {
109919757fc8STomi Valkeinen 		modelist = list_entry(pos, struct fb_modelist, list);
110019757fc8STomi Valkeinen 		m = &modelist->mode;
110119757fc8STomi Valkeinen 		if (fb_mode_is_equal(m, mode)) {
110219757fc8STomi Valkeinen 			list_del(pos);
110319757fc8STomi Valkeinen 			kfree(pos);
110419757fc8STomi Valkeinen 		}
110519757fc8STomi Valkeinen 	}
110619757fc8STomi Valkeinen }
110719757fc8STomi Valkeinen 
110819757fc8STomi Valkeinen /**
110919757fc8STomi Valkeinen  * fb_destroy_modelist - destroy modelist
111019757fc8STomi Valkeinen  * @head: struct list_head of modelist
111119757fc8STomi Valkeinen  */
fb_destroy_modelist(struct list_head * head)111219757fc8STomi Valkeinen void fb_destroy_modelist(struct list_head *head)
111319757fc8STomi Valkeinen {
111419757fc8STomi Valkeinen 	struct list_head *pos, *n;
111519757fc8STomi Valkeinen 
111619757fc8STomi Valkeinen 	list_for_each_safe(pos, n, head) {
111719757fc8STomi Valkeinen 		list_del(pos);
111819757fc8STomi Valkeinen 		kfree(pos);
111919757fc8STomi Valkeinen 	}
112019757fc8STomi Valkeinen }
112119757fc8STomi Valkeinen EXPORT_SYMBOL_GPL(fb_destroy_modelist);
112219757fc8STomi Valkeinen 
112319757fc8STomi Valkeinen /**
112419757fc8STomi Valkeinen  * fb_videomode_to_modelist - convert mode array to mode list
112519757fc8STomi Valkeinen  * @modedb: array of struct fb_videomode
112619757fc8STomi Valkeinen  * @num: number of entries in array
112719757fc8STomi Valkeinen  * @head: struct list_head of modelist
112819757fc8STomi Valkeinen  */
fb_videomode_to_modelist(const struct fb_videomode * modedb,int num,struct list_head * head)112919757fc8STomi Valkeinen void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
113019757fc8STomi Valkeinen 			      struct list_head *head)
113119757fc8STomi Valkeinen {
113219757fc8STomi Valkeinen 	int i;
113319757fc8STomi Valkeinen 
113419757fc8STomi Valkeinen 	INIT_LIST_HEAD(head);
113519757fc8STomi Valkeinen 
113619757fc8STomi Valkeinen 	for (i = 0; i < num; i++) {
113719757fc8STomi Valkeinen 		if (fb_add_videomode(&modedb[i], head))
113819757fc8STomi Valkeinen 			return;
113919757fc8STomi Valkeinen 	}
114019757fc8STomi Valkeinen }
114119757fc8STomi Valkeinen 
fb_find_best_display(const struct fb_monspecs * specs,struct list_head * head)114219757fc8STomi Valkeinen const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
114319757fc8STomi Valkeinen 					        struct list_head *head)
114419757fc8STomi Valkeinen {
114519757fc8STomi Valkeinen 	struct fb_modelist *modelist;
114619757fc8STomi Valkeinen 	const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
114719757fc8STomi Valkeinen 	int first = 0;
114819757fc8STomi Valkeinen 
114919757fc8STomi Valkeinen 	if (!head->prev || !head->next || list_empty(head))
115019757fc8STomi Valkeinen 		goto finished;
115119757fc8STomi Valkeinen 
115219757fc8STomi Valkeinen 	/* get the first detailed mode and the very first mode */
1153*1520081aSJinjie Ruan 	list_for_each_entry(modelist, head, list) {
115419757fc8STomi Valkeinen 		m = &modelist->mode;
115519757fc8STomi Valkeinen 
115619757fc8STomi Valkeinen 		if (!first) {
115719757fc8STomi Valkeinen 			m1 = m;
115819757fc8STomi Valkeinen 			first = 1;
115919757fc8STomi Valkeinen 		}
116019757fc8STomi Valkeinen 
116119757fc8STomi Valkeinen 		if (m->flag & FB_MODE_IS_FIRST) {
116219757fc8STomi Valkeinen  			md = m;
116319757fc8STomi Valkeinen 			break;
116419757fc8STomi Valkeinen 		}
116519757fc8STomi Valkeinen 	}
116619757fc8STomi Valkeinen 
116719757fc8STomi Valkeinen 	/* first detailed timing is preferred */
116819757fc8STomi Valkeinen 	if (specs->misc & FB_MISC_1ST_DETAIL) {
116919757fc8STomi Valkeinen 		best = md;
117019757fc8STomi Valkeinen 		goto finished;
117119757fc8STomi Valkeinen 	}
117219757fc8STomi Valkeinen 
117319757fc8STomi Valkeinen 	/* find best mode based on display width and height */
117419757fc8STomi Valkeinen 	if (specs->max_x && specs->max_y) {
117519757fc8STomi Valkeinen 		struct fb_var_screeninfo var;
117619757fc8STomi Valkeinen 
117719757fc8STomi Valkeinen 		memset(&var, 0, sizeof(struct fb_var_screeninfo));
117819757fc8STomi Valkeinen 		var.xres = (specs->max_x * 7200)/254;
117919757fc8STomi Valkeinen 		var.yres = (specs->max_y * 7200)/254;
118019757fc8STomi Valkeinen 		m = fb_find_best_mode(&var, head);
118119757fc8STomi Valkeinen 		if (m) {
118219757fc8STomi Valkeinen 			best = m;
118319757fc8STomi Valkeinen 			goto finished;
118419757fc8STomi Valkeinen 		}
118519757fc8STomi Valkeinen 	}
118619757fc8STomi Valkeinen 
118719757fc8STomi Valkeinen 	/* use first detailed mode */
118819757fc8STomi Valkeinen 	if (md) {
118919757fc8STomi Valkeinen 		best = md;
119019757fc8STomi Valkeinen 		goto finished;
119119757fc8STomi Valkeinen 	}
119219757fc8STomi Valkeinen 
119319757fc8STomi Valkeinen 	/* last resort, use the very first mode */
119419757fc8STomi Valkeinen 	best = m1;
119519757fc8STomi Valkeinen finished:
119619757fc8STomi Valkeinen 	return best;
119719757fc8STomi Valkeinen }
119819757fc8STomi Valkeinen EXPORT_SYMBOL(fb_find_best_display);
119919757fc8STomi Valkeinen 
120019757fc8STomi Valkeinen EXPORT_SYMBOL(fb_videomode_to_var);
120119757fc8STomi Valkeinen EXPORT_SYMBOL(fb_var_to_videomode);
120219757fc8STomi Valkeinen EXPORT_SYMBOL(fb_mode_is_equal);
120319757fc8STomi Valkeinen EXPORT_SYMBOL(fb_add_videomode);
120419757fc8STomi Valkeinen EXPORT_SYMBOL(fb_match_mode);
120519757fc8STomi Valkeinen EXPORT_SYMBOL(fb_find_best_mode);
120619757fc8STomi Valkeinen EXPORT_SYMBOL(fb_find_nearest_mode);
120719757fc8STomi Valkeinen EXPORT_SYMBOL(fb_videomode_to_modelist);
120819757fc8STomi Valkeinen EXPORT_SYMBOL(fb_find_mode);
120919757fc8STomi Valkeinen EXPORT_SYMBOL(fb_find_mode_cvt);
1210