Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-video-emulfb.git] / src / crtcconfig / lcd_output.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 #include "fbdev.h"
32 #include "fbdev_output_priv.h"
33 #include "fbdev_mode.h"
34 #include "fbdev_util.h"
35 #include "fbdev_video.h"
36
37 #include <xf86Crtc.h>
38
39 #define STR_XRR_VIDEO_OFFSET_PROPERTY "XRR_PROPERTY_VIDEO_OFFSET"
40
41 static Bool g_video_offset_prop_init = FALSE;
42
43 static Atom xrr_property_video_offset_atom;
44
45 static Bool
46 _lcd_output_prop_video_offset (xf86OutputPtr pOutput, Atom property, RRPropertyValuePtr value)
47 {
48         int x, y;
49         char str[128];
50         char *p;
51
52         if (g_video_offset_prop_init == FALSE)
53         {
54                 xrr_property_video_offset_atom = MakeAtom (STR_XRR_VIDEO_OFFSET_PROPERTY,
55                                                            strlen (STR_XRR_VIDEO_OFFSET_PROPERTY), TRUE);
56                 g_video_offset_prop_init = TRUE;
57         }
58
59         if (xrr_property_video_offset_atom != property)
60                 return FALSE;
61
62         if (!value || !value->data || value->size == 0)
63                 return TRUE;
64
65         if (value->format != 8)
66                 return TRUE;
67
68         snprintf (str, sizeof(str), "%s", (char*)value->data);
69
70         p = strtok (str, ",");
71         return_val_if_fail (p != NULL, FALSE);
72         x = atoi (p);
73
74         p = strtok (NULL, ",");
75         return_val_if_fail (p != NULL, FALSE);
76         y = atoi (p);
77
78         DRVLOG ("%s : offset(%d,%d) \n", __FUNCTION__, x, y);
79
80         fbdevVideoSetOffset (pOutput->scrn, x, y);
81
82         return TRUE;
83 }
84
85
86 /********************************************************************************************/
87 /* Implementation of Output entry points */
88 /********************************************************************************************/
89 static void lcd_output_create_resources(xf86OutputPtr output)
90 {
91 }
92
93 static void lcd_output_dpms(xf86OutputPtr output, int mode)
94 {
95         return;
96 }
97
98 static void lcd_output_save(xf86OutputPtr output)
99 {
100         return;
101 }
102
103 static void lcd_output_restore(xf86OutputPtr output)
104 {
105         return;
106 }
107
108 static int lcd_output_mode_valid(xf86OutputPtr output, DisplayModePtr mode)
109 {
110         FBDevPtr pFBDev = FBDEVPTR(output->scrn);
111
112         if(pFBDev->builtin->HDisplay < mode->HDisplay)
113                 return MODE_HSYNC;
114
115         if(pFBDev->builtin->VDisplay < mode->VDisplay)
116                 return MODE_VSYNC;
117
118         output->scrn->currentMode = mode;
119
120         return MODE_OK;
121
122 }
123
124 static Bool lcd_output_mode_fixup(xf86OutputPtr output, DisplayModePtr mode,
125                                   DisplayModePtr adjusted_mode)
126 {
127         return TRUE;
128 }
129
130 static void lcd_output_prepare(xf86OutputPtr output)
131 {
132         return;
133 }
134
135 static void lcd_output_mode_set(xf86OutputPtr output, DisplayModePtr mode,
136                                 DisplayModePtr adjusted_mode)
137 {
138         ScrnInfoPtr pScrn = output ->scrn;
139         FBDevPtr pFBDev = FBDEVPTR(pScrn);
140
141         /* have to set the physical size of the output */
142         output->mm_width = pFBDev->var.width;
143         output->mm_height = pFBDev->var.height;
144         output->conf_monitor->mon_width = pFBDev->var.width;
145         output ->conf_monitor->mon_height = pFBDev->var.height;
146
147         return;
148 }
149
150 static void lcd_output_commit(xf86OutputPtr output)
151 {
152         return;
153 }
154
155 static xf86OutputStatus lcd_output_detect(xf86OutputPtr output)
156 {
157         return XF86OutputStatusConnected;
158 }
159
160
161
162 /**
163   * Name : lcd_output_get_modes
164   * Input :  xf86OutputPtr
165   * Return : DisplayModePtr
166   * Description : Query the device for the modes it provides.
167                         This function may also update MonInfo, mm_width, and mm_height.
168                         return singly-linked list of modes or NULL if no modes found.
169
170   */
171 static int first_time_rotated = TRUE;
172 static DisplayModePtr lcd_output_get_modes(xf86OutputPtr output)
173 {
174         FBDevPtr pFBDev = FBDEVPTR(output->scrn);
175
176         /* [soolim:20100205] : if there is no mode name in xorg.conf, use the builtin mode */
177         char *preferred_mode;
178         preferred_mode = FBDevCheckPreferredMode(output->scrn, output);
179         if(!preferred_mode)
180         {
181                 int HDisplay, VDisplay;
182
183                 Bool rotated = (pFBDev->rotate & (RR_Rotate_90|RR_Rotate_270)) != 0;
184
185                 if(rotated)
186                 {
187                         if(first_time_rotated)
188                         {
189                                 memcpy(&pFBDev->builtin_saved, pFBDev->builtin, sizeof(*pFBDev->builtin));
190                                 VDisplay = pFBDev->builtin->VDisplay;
191                                 HDisplay = pFBDev->builtin->HDisplay;
192                                 pFBDev->builtin->HDisplay = VDisplay;
193                                 pFBDev->builtin->VDisplay = HDisplay;
194                                 pFBDev->builtin->name = "fake_mode";
195                                 first_time_rotated = FALSE;
196                         }
197                         return xf86DuplicateMode(pFBDev->builtin);
198                 }
199                 else
200                 {
201                         return xf86DuplicateMode(pFBDev->builtin);
202                 }
203         }
204
205         /* [soolim:20100205] : gets the supported modes from framebuffer and makes the list */
206         DisplayModePtr support_modes = NULL;
207
208         if(!pFBDev->support_modes)
209         {
210                 support_modes = FBDevGetSupportModes(pFBDev->builtin);
211                 if(pFBDev->builtin != NULL)
212                 {
213                         if(!pFBDev->builtin->next)
214                         {
215                                 support_modes->prev = pFBDev->builtin;
216                                 pFBDev->builtin->next = support_modes;
217                                 pFBDev->builtin->prev = NULL;
218                         }
219                 }
220                 else
221                 {
222                         pFBDev->builtin = support_modes;
223                 }
224         }
225
226         return support_modes;
227 }
228
229 static Bool lcd_output_set_property(xf86OutputPtr output, Atom property,
230                                     RRPropertyValuePtr value)
231 {
232         if (_lcd_output_prop_video_offset (output, property, value))
233                 return TRUE;
234
235         return TRUE;
236 }
237
238 static Bool lcd_output_get_property(xf86OutputPtr output, Atom property)
239 {
240         return TRUE;
241 }
242
243 static xf86CrtcPtr lcd_output_crtc_get(xf86OutputPtr output)
244 {
245         return 0;
246 }
247
248 static void lcd_output_destroy(xf86OutputPtr output)
249 {
250         return;
251 }
252
253
254 /* output funcs */
255 static const xf86OutputFuncsRec lcd_output_funcs =
256 {
257         .create_resources = lcd_output_create_resources,
258         .destroy = lcd_output_destroy,
259         .dpms = lcd_output_dpms,
260         .save = lcd_output_save,
261         .restore = lcd_output_restore,
262         .mode_valid = lcd_output_mode_valid,
263
264         .mode_fixup = lcd_output_mode_fixup,
265         .prepare = lcd_output_prepare,
266         .mode_set = lcd_output_mode_set,
267         .commit = lcd_output_commit,
268         .detect = lcd_output_detect,
269         .get_modes = lcd_output_get_modes,
270 #ifdef RANDR_12_INTERFACE
271         .set_property = lcd_output_set_property,
272 #endif
273 #ifdef RANDR_13_INTERFACE       /* not a typo */
274         .get_property = lcd_output_get_property,
275 #endif
276 #ifdef RANDR_GET_CRTC_INTERFACE
277         .get_crtc = lcd_output_crtc_get,
278 #endif
279 };
280
281 void LcdOutputInit(ScrnInfoPtr pScrn)
282 {
283         xf86OutputPtr       output;
284         FBDevOutputPrivPtr    lcd_output;
285
286         output = xf86OutputCreate (pScrn, &lcd_output_funcs, "LVDS1");
287         if (!output)
288                 return;
289         lcd_output = xnfcalloc (sizeof (FBDevOutputPriv), 1);
290         if (!lcd_output)
291         {
292                 xf86OutputDestroy (output);
293                 return;
294         }
295
296         output->driver_private = lcd_output;
297         output->interlaceAllowed = FALSE;
298         output->doubleScanAllowed = FALSE;
299
300 }