Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-video-emulfb.git] / src / crtcconfig / fbdev_crtcconfig.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 "fbdevhw.h"
33 #include "fbdev_crtcconfig.h"
34 #include "fbdev_crtc_priv.h"
35 #include "fbdev_output_priv.h"
36
37 #include "xf86Crtc.h"
38
39 #define MIN_CRTC_DPY_WIDTH 320
40 #define MAX_CRTC_DPY_WIDTH 1024
41 #define MIN_CRTC_DPY_HEIGHT 200
42 #define MAX_CRTC_DPY_HEIGHT 1024
43
44 #define NUM_CRTCS 1
45
46 /**
47   * Requests that the driver resize the screen.
48   *
49   * The driver is responsible for updating scrn->virtualX and scrn->virtualY.
50   * If the requested size cannot be set, the driver should leave those values
51   * alone and return FALSE.
52   *
53   * A naive driver that cannot reallocate the screen may simply change
54   * virtual[XY].  A more advanced driver will want to also change the
55   * devPrivate.ptr and devKind of the screen pixmap, update any offscreen
56   * pixmaps it may have moved, and change pScrn->displayWidth.
57   */
58 static Bool fbdev_crtc_config_resize (ScrnInfoPtr scrn, int width, int height)
59 {
60
61         scrn->virtualX = width;
62         scrn->virtualY = height;
63
64         return TRUE;
65 }
66
67
68 /* crtc_config_func */
69 static const xf86CrtcConfigFuncsRec fbdev_crtc_config_funcs =
70 {
71         .resize = fbdev_crtc_config_resize,
72 };
73
74
75 /*
76  * Initialize the CrtcConfig.
77  * And initialize the mode setting throught create the avaliable crtcs and outputs
78  * then Initialize the Configuration of Crtc
79  */
80 Bool FBDevCrtcConfigInit(ScrnInfoPtr pScrn)
81 {
82         int min_width, max_width, min_height, max_height;
83         xf86CrtcConfigPtr crtc_config;
84         int i, o, c;
85         FBDevPtr pFBDev = FBDEVPTR(pScrn);
86         /* TODO: check this routines later whether it is right setting */
87         {
88
89                 fbdevHWUseBuildinMode(pScrn);   /* sets pScrn->modes */
90                 pScrn->modes = xf86DuplicateMode(pScrn->modes); /* well done, fbdevhw. */
91                 pScrn->modes->name = NULL;      /* fbdevhw string can't be freed */
92                 pScrn->modes->type = M_T_DRIVER | M_T_PREFERRED;
93                 pScrn->currentMode = pScrn->modes;
94                 pFBDev->builtin = xf86DuplicateMode(pScrn->modes);
95
96         }
97
98         /* allocate an xf86CrtcConfig */
99         xf86CrtcConfigInit(pScrn, &fbdev_crtc_config_funcs);
100         crtc_config = XF86_CRTC_CONFIG_PTR (pScrn);
101
102         min_width = pScrn->modes->HDisplay;
103         max_width = pScrn->modes->HDisplay;
104         min_height = pScrn->modes->VDisplay;
105         max_height =  pScrn->modes->VDisplay;
106
107         xf86CrtcSetSizeRange(pScrn, min_width, min_height, max_width, max_height);
108
109         /* set up the crtcs */
110         for( i = 0; i < NUM_CRTCS; i++)
111                 FBDevCrtcInit(pScrn, i);
112
113         /* set up the outputs */
114         LcdOutputInit(pScrn);
115
116         /* [TODO]: set the crtc to the output in some manner ???? */
117         for (o = 0; o < crtc_config->num_output; o++)
118         {
119                 xf86OutputPtr output = crtc_config->output[o];
120                 int crtc_mask;
121
122                 crtc_mask = 0;
123                 for (c = 0; c < crtc_config->num_crtc; c++)
124                 {
125                         crtc_mask |= (1 << c);
126                 }
127                 output->possible_crtcs = crtc_mask;
128                 output->possible_clones = FALSE;
129         }
130
131         /* initialize the configuration */
132         if(!xf86InitialConfiguration(pScrn, TRUE))
133         {
134                 return FALSE;
135         }
136
137         return TRUE;
138
139 }