Tizen 2.1 base
[adaptation/xorg/driver/xserver-xorg-video-emulfb.git] / src / crtcconfig / fbdev_mode.c
1 /**************************************************************************
2
3 xserver-xorg-video-emulfb
4
5 Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
6
7 Contact: SooChan Lim <sc1.lim@samsung.com>
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sub license, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
16
17 The above copyright notice and this permission notice (including the
18 next paragraph) shall be included in all copies or substantial portions
19 of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
24 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
25 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
29 **************************************************************************/
30
31
32 #include "fbdev.h"
33
34 #include <linux/fb.h>
35 #include "fbdev_hw.h"
36 #include "fbdev_mode.h"
37
38 typedef struct _FBDevDisplayModeRec
39 {
40         char            name[32];               /* identifier for the mode */
41
42         /* These are the values that the user sees/provides */
43         int                             Clock;          /* pixel clock freq (kHz) */
44         int                             HDisplay;       /* horizontal timing */
45         int                             HSyncStart;
46         int                             HSyncEnd;
47         int                             HTotal;
48         int                             HSkew;
49         int                             VDisplay;       /* vertical timing */
50         int                             VSyncStart;
51         int                             VSyncEnd;
52         int                             VTotal;
53         int                             VScan;
54         int                             Flags;
55
56 } FBDevDisplayModeRec, *FBDevDisplayModePtr;
57
58 /* [soolim: 20100206][TODO] : it has to be recalculated when it comes to change the target framebuffer
59   *                                                                                              The display mode data has to be changed whenever the target is changed
60   *                                                                                              Always check it out.
61   */
62 const FBDevDisplayModeRec fbdevDisplayModes[] =
63 {
64         /* CGA          ( 320 x 200 )   */
65         {"320x200", 38, 320, 336, 338, 354, 0, 200, 203, 205, 233, 0, 0,},
66         /* QVGA         ( 320 x 240 )   */
67         {"320x240", 38, 320, 336, 338, 354, 0, 240, 243, 245, 273, 0, 0,},
68         /* XX   ( 240 x 400 )   */
69         {"240x400", 38, 240, 256, 258, 274, 0, 400, 428, 430, 433, 0, 0,},
70         /* HVGA                 (320 x 480 )    */
71         {"320x480", 38, 320, 336, 338, 354, 0, 480, 483, 485, 513, 0, 0,},
72         /* WVGA         ( 480 x 720 )   */
73         {"480x720", 38, 480, 496, 498, 514, 0, 720, 723, 725, 753, 0, 0},
74         /* WVGA         ( 480 x 800 )   */
75         {"480x800", 38, 480, 496, 498, 514, 0, 800, 803, 805, 833, 0, 0},
76         /* VGA          ( 640 x 480 )   */
77         {"640x480", 19, 640, 840, 880, 959, 0, 480, 491, 501, 511, 0, 0,},
78         /* NTSC                 ( 720 x 480 )   */
79         {"720x480", 19, 720, 920, 960, 1039, 0, 480, 491, 501, 511, 0, 0,},
80         /* PAL          ( 768 x 576 )   */
81         {"768x576", 19, 768, 968, 1008, 1087, 0, 576, 587, 597, 607, 0, 0,},
82         /* WVGA         ( 800 x 480 )   */
83         {"800x480", 19, 800, 1000, 1040, 1119, 0, 480, 491, 501, 511, 0, 0},
84         /* WVGA         ( 854 x 480 )   */
85         {"854x480", 19, 854, 1054, 1094, 1173, 0, 480, 491, 501, 511, 0, 0,},
86         /* WSVGA        ( 600 x 1024 ) */
87         {"600x1024", 19, 600, 611, 621, 631, 0, 1024, 1224, 1264, 1343, 0, 0},
88         /* WSVGA        ( 1024 x 600 ) */
89         {"1024x600", 19, 1024, 1224, 1264, 1343, 0, 600, 611, 621, 631, 0, 0},
90 #if 0
91         /* XGA          ( 1024 x 768 ) */
92         {"1024x768", 19, 1024, 1224, 1264, 1343, 600, 611, 621, 631, 0,},
93 #endif
94 };
95
96
97 #define NUM_DISPLAY_MODES (sizeof(fbdevDisplayModes)/sizeof(fbdevDisplayModes[0]))
98
99 const int fbdevNumDisplayModes = NUM_DISPLAY_MODES;
100
101
102 DisplayModePtr
103 FBDevGetSupportModes(DisplayModePtr builtin_mode)
104 {
105         DisplayModePtr pMode = NULL;
106         DisplayModePtr prev_pMode = NULL;
107         DisplayModePtr ret_pMode = NULL;
108         int i;
109         int clock = 0;
110         if(builtin_mode)
111                 clock = builtin_mode->Clock;
112         else
113                 clock = 0;
114
115         for(i=0; i< fbdevNumDisplayModes; i++)
116         {
117                 pMode = calloc(1, sizeof(DisplayModeRec));
118                 pMode->next = NULL;
119                 pMode->prev = NULL;
120                 pMode->name = calloc(1, sizeof(char)*32);
121                 sprintf(pMode->name,"%s", fbdevDisplayModes[i].name);
122                 pMode->status = MODE_OK;
123                 pMode->type = M_T_DRIVER | M_T_PREFERRED;
124
125                 pMode->Clock = clock;
126                 pMode->HDisplay = fbdevDisplayModes[i].HDisplay;
127                 pMode->HSyncStart = fbdevDisplayModes[i].HSyncStart;
128                 pMode->HSyncEnd = fbdevDisplayModes[i].HSyncEnd;
129                 pMode->HTotal = fbdevDisplayModes[i].HTotal;
130                 pMode->HSkew = fbdevDisplayModes[i].HSkew;
131                 pMode->VDisplay = fbdevDisplayModes[i].VDisplay;
132                 pMode->VSyncStart = fbdevDisplayModes[i].VSyncStart;
133                 pMode->VSyncEnd = fbdevDisplayModes[i].VSyncEnd;
134                 pMode->VTotal = fbdevDisplayModes[i].VTotal;
135                 pMode->VScan = fbdevDisplayModes[i].VScan;
136                 pMode->Flags = fbdevDisplayModes[i].Flags;
137
138                 if(prev_pMode)
139                 {
140                         pMode->prev = prev_pMode;
141                         prev_pMode->next = pMode;
142                         prev_pMode = prev_pMode->next;
143                 }
144                 else
145                 {
146                         prev_pMode = pMode;
147                         ret_pMode = pMode;
148                 }
149
150                 pMode = NULL;
151         }
152
153         return ret_pMode;
154 }
155
156 #define OPTION_PREFERRED_MODE 0
157
158 char *
159 FBDevCheckPreferredMode(ScrnInfoPtr pScrn, xf86OutputPtr output)
160 {
161         char *preferred_mode = NULL;
162
163         /* Check for a configured preference for a particular mode */
164         preferred_mode = xf86GetOptValString (output->options,
165                                               OPTION_PREFERRED_MODE);
166         if (preferred_mode)
167                 return preferred_mode;
168
169         if (pScrn->display->modes && *pScrn->display->modes)
170                 preferred_mode = *pScrn->display->modes;
171
172         return preferred_mode;
173 }