Initialize Tizen 2.3
[adaptation/xorg/driver/xserver-xorg-video-emulfb.git] / src / fbdev.c
1 /*
2  * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
3  *           Michel Dänzer, <michel@tungstengraphics.com>
4  */
5 /**************************************************************************
6
7 xserver-xorg-video-emulfb
8
9 Copyright (C) 1994-2003 The XFree86 Project, Inc.  All Rights Reserved.
10 Copyright 2010 - 2011 Samsung Electronics co., Ltd. All Rights Reserved.
11
12 Contact: SooChan Lim <sc1.lim@samsung.com>
13
14 Permission is hereby granted, free of charge, to any person obtaining a
15 copy of this software and associated documentation files (the
16 "Software"), to deal in the Software without restriction, including
17 without limitation the rights to use, copy, modify, merge, publish,
18 distribute, sub license, and/or sell copies of the Software, and to
19 permit persons to whom the Software is furnished to do so, subject to
20 the following conditions:
21
22 The above copyright notice and this permission notice (including the
23 next paragraph) shall be included in all copies or substantial portions
24 of the Software.
25
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
29 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
30 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
31 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
32 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
34 **************************************************************************/
35
36 #ifdef HAVE_CONFIG_H
37 #include "config.h"
38 #endif
39
40 /* all driver need this */
41 #include "xf86.h"
42 #include "xf86_OSproc.h"
43
44 #include "fb.h"
45 #include "mipointer.h"
46 #include "mibstore.h"
47 #include "micmap.h"
48 #include "colormapst.h"
49 #include "xf86cmap.h"
50 #include "xf86xv.h"
51 #include "xf86Crtc.h"
52
53 #include "fbdev.h"
54 #include "fbdevhw.h"
55 #include "fbdev_hw.h"
56 #include "fbdev_video.h"
57 #include "fbdev_crtcconfig.h"
58 #include "fbdev_dpms.h"
59 #include "fbdev_event_trace.h"
60
61 #include <string.h>
62 #include <sys/ioctl.h>
63 #include <linux/fb.h>
64
65 #if USE_XDBG
66 #include "xdbg.h"
67 #endif
68
69 /* prototypes */
70 static const OptionInfoRec *    FBDevAvailableOptions(int chipid, int busid);
71 static void     FBDevIdentify(int flags);
72 static Bool     FBDevProbe(DriverPtr drv, int flags);
73 static Bool     FBDevPreInit(ScrnInfoPtr pScrn, int flags);
74 static Bool     FBDevScreenInit(ScreenPtr pScreen, int argc, char **argv);
75 static Bool     FBDevEnterVT(ScrnInfoPtr pScrn);
76 static void     FBDevLeaveVT(ScrnInfoPtr pScrn);
77 static Bool     FBDevCloseScreen(ScreenPtr pScreen);
78 static void     FBDevSaveCurrent(ScrnInfoPtr pScrn);
79
80 /* This DriverRec must be defined in the driver for Xserver to load this driver */
81 _X_EXPORT DriverRec FBDEV =
82 {
83         FBDEV_VERSION,
84         FBDEV_DRIVER_NAME,
85         FBDevIdentify,
86         FBDevProbe,
87         FBDevAvailableOptions,
88         NULL,
89         0,
90         NULL,
91 };
92
93 /* Supported "chipsets" */
94 static SymTabRec FBDevChipsets[] =
95 {
96         {-1, NULL }
97 };
98
99 /* Supported options */
100 typedef enum
101 {
102         OPTION_SWCURSOR,
103         OPTION_FBDEV
104 } FBDevOpts;
105
106 static const OptionInfoRec FBDevOptions[] =
107 {
108         { OPTION_SWCURSOR,      "swcursor", OPTV_BOOLEAN,       {0},    FALSE },
109         { OPTION_FBDEV, "fbdev",    OPTV_STRING,        {0},    FALSE },
110         { -1,           NULL,       OPTV_NONE,          {0},    FALSE }
111 };
112
113 /* -------------------------------------------------------------------- */
114
115
116 #ifdef XFree86LOADER
117
118 MODULESETUPPROTO(FBDevSetup);
119
120 static XF86ModuleVersionInfo FBDevVersRec =
121 {
122         "emulfb",
123         MODULEVENDORSTRING,
124         MODINFOSTRING1,
125         MODINFOSTRING2,
126         XORG_VERSION_CURRENT,
127         PACKAGE_VERSION_MAJOR,
128         PACKAGE_VERSION_MINOR,
129         PACKAGE_VERSION_PATCHLEVEL,
130         ABI_CLASS_VIDEODRV,
131         ABI_VIDEODRV_VERSION,
132         NULL,
133         {0,0,0,0}
134 };
135
136 _X_EXPORT XF86ModuleData emulfbModuleData = { &FBDevVersRec, FBDevSetup, NULL };
137
138 pointer
139 FBDevSetup(pointer module, pointer opts, int *errmaj, int *errmin)
140 {
141         static Bool setupDone = FALSE;
142
143         if (!setupDone)
144         {
145                 setupDone = TRUE;
146                 xf86AddDriver(&FBDEV, module, HaveDriverFuncs);
147                 return (pointer)1;
148         }
149         else
150         {
151                 if (errmaj) *errmaj = LDR_ONCEONLY;
152                 return NULL;
153         }
154 }
155
156 #endif /* XFree86LOADER */
157
158 static Bool
159 FBDevGetRec(ScrnInfoPtr pScrn)
160 {
161         if (pScrn->driverPrivate != NULL)
162                 return TRUE;
163
164         pScrn->driverPrivate = xnfcalloc(sizeof(FBDevRec), 1);
165         return TRUE;
166 }
167
168 static void
169 FBDevFreeRec(ScrnInfoPtr pScrn)
170 {
171         if (pScrn->driverPrivate == NULL)
172                 return;
173         free(pScrn->driverPrivate);
174         pScrn->driverPrivate = NULL;
175 }
176
177 /* -------------------------------------------------------------------- */
178
179 static const OptionInfoRec *
180 FBDevAvailableOptions(int chipid, int busid)
181 {
182         return FBDevOptions;
183 }
184
185 static void
186 FBDevIdentify(int flags)
187 {
188         xf86PrintChipsets(FBDEV_NAME, "driver for framebuffer", FBDevChipsets);
189 }
190
191 /*
192  * Probing the device with the device node, this probing depend on the specific hw.
193  * This function just verify whether the display hw is avaliable or not.
194  */
195 static Bool
196 FBDevHWProbe(struct pci_device * pPci, const char *device,char **namep)
197 {
198         return fbdevHWProbe(pPci, (char *)device,namep);
199 }
200
201 /* The purpose of this function is to identify all instances of hardware supported
202  * by the driver. The probe must find the active device sections that match the driver
203  * by calling xf86MatchDevice().
204  */
205 static Bool
206 FBDevProbe(DriverPtr drv, int flags)
207 {
208         int i;
209         ScrnInfoPtr pScrn;
210         GDevPtr *devSections;
211         int numDevSections;
212         const char *dev;
213         int entity;
214         Bool foundScreen = FALSE;
215     const char * drv_name = "fbdev";
216     const char * module_name = "fbdevhw";
217
218         /* For now, just bail out for PROBE_DETECT. */
219         if (flags & PROBE_DETECT)
220                 return FALSE;
221
222         if ((numDevSections = xf86MatchDevice(FBDEV_DRIVER_NAME, &devSections)) <= 0)
223                 return FALSE;
224
225         if (!xf86LoadDrvSubModule (drv, module_name))
226                 return FALSE;
227
228         for (i = 0; i < numDevSections; i++)
229         {
230                 dev = xf86FindOptionValue (devSections[i]->options, drv_name);
231                 if (FBDevHWProbe(NULL,dev,NULL))
232                 {
233                         pScrn = NULL;
234                         entity = xf86ClaimFbSlot(drv, 0, devSections[i], TRUE);
235                         pScrn = xf86ConfigFbEntity(pScrn,0,entity, NULL,NULL,NULL,NULL);
236
237                         if (pScrn)
238                         {
239                                 foundScreen = TRUE;
240
241                                 pScrn->driverVersion = FBDEV_VERSION;
242                                 pScrn->driverName = FBDEV_DRIVER_NAME;
243                                 pScrn->name = FBDEV_NAME;
244                                 pScrn->Probe = FBDevProbe;
245                                 pScrn->PreInit = FBDevPreInit;
246                                 pScrn->ScreenInit = FBDevScreenInit;
247                                 pScrn->SwitchMode = fbdevHWSwitchModeWeak();
248                                 pScrn->AdjustFrame = fbdevHWAdjustFrameWeak();
249                                 pScrn->EnterVT  = FBDevEnterVT;
250                                 pScrn->LeaveVT = FBDevLeaveVT;
251                                 pScrn->ValidMode = fbdevHWValidModeWeak();
252
253                                 xf86DrvMsg(pScrn->scrnIndex, X_INFO
254                                            ,"using %s\n", dev ? dev : "default device");
255                         }
256                 }
257         }
258         free(devSections);
259
260         return foundScreen;
261 }
262
263 /*
264  * Return the default depth and bits per pixel.
265  * Determine the depth and the bpp supported by hw with the hw color format.
266  */
267 static int
268 FBDevGetDefaultDepth(ScrnInfoPtr pScrn, int *bitsPerPixel)
269 {
270         int defaultDepth;
271
272         /* finding out the valid default_depth */
273         defaultDepth = fbdevHWGetDepth(pScrn,bitsPerPixel);
274
275         /* the default depth is not more than 24 */
276         defaultDepth = ((*bitsPerPixel)==32)?24:*bitsPerPixel;
277
278         return defaultDepth;
279 }
280
281 /*
282  * Initialize the device Probing the device with the device node,
283  * this probing depend on the specific hw.
284  * This function just verify whether the display hw is avaliable or not.
285  */
286 static Bool
287 FBDevHWInit(ScrnInfoPtr pScrn, struct pci_device *pPci, const char *device)
288 {
289         /* open device : open the framebuffer device */
290         if (!fbdevHWInit(pScrn, NULL, (char *)device))
291         {
292                 return FALSE;
293         }
294
295         return TRUE;
296 }
297
298 /*
299   * DeInitialize the hw
300   */
301 static void
302 FBDevHWDeInit(ScrnInfoPtr pScrn)
303 {
304         /* close the fd of the fb device ??? */
305
306         return;
307 }
308
309 /*
310  * Check the driver option.
311  * Set the option flags to the driver private
312  */
313 static void
314 FBDevCheckDriverOptions(ScrnInfoPtr pScrn)
315 {
316         FBDevPtr pFBDev = FBDEVPTR(pScrn);
317
318         /* sw cursor */
319         if (xf86ReturnOptValBool(pFBDev->Options, OPTION_SWCURSOR, FALSE))
320                 pFBDev->bSWCursorEnbled = TRUE;
321 }
322
323
324
325 /*
326  * This is called before ScreenInit to probe the screen configuration.
327  * The main tasks to do in this funtion are probing, module loading, option handling,
328  * card mapping, and Crtcs setup.
329  */
330 static Bool
331 FBDevPreInit(ScrnInfoPtr pScrn, int flags)
332 {
333         FBDevPtr pFBDev;
334         int default_depth, fbbpp;
335         const char *path;
336         Gamma defualt_gamma = {0.0, 0.0, 0.0};
337         rgb default_weight = { 0, 0, 0 };
338         int flag24;
339     const char * fb_name = "fbdev";
340
341         if (flags & PROBE_DETECT) return FALSE;
342
343         /* Check the number of entities, and fail if it isn't one. */
344         if (pScrn->numEntities != 1)
345                 return FALSE;
346
347         pScrn->monitor = pScrn->confScreen->monitor;
348
349         /* allocate private */
350         FBDevGetRec(pScrn);
351         pFBDev = FBDEVPTR(pScrn);
352
353         pFBDev->pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
354
355         /* can set the path with fbdev option */
356         path = xf86FindOptionValue(pFBDev->pEnt->device->options, fb_name);
357
358         /* Init HW */
359         if(!FBDevHWInit(pScrn,NULL,path))
360         {
361                 xf86DrvMsg(pScrn->scrnIndex, X_Error
362                            , "fail to initialize hardware\n");
363                 goto bail1;
364         }
365
366         /* finding out the valid default_depth */
367         default_depth = FBDevGetDefaultDepth(pScrn,&fbbpp);
368
369         /* set the depth and the bpp to pScrn */
370         flag24 = Support24bppFb | Support32bppFb;
371         if (!xf86SetDepthBpp(pScrn, default_depth, default_depth, fbbpp, flag24))
372         {
373                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
374                            , "fail to find the depth\n");
375                 goto bail1;
376         }
377         xf86PrintDepthBpp(pScrn); /* just print out the depth and the bpp */
378
379         /* color weight */
380         if (!xf86SetWeight(pScrn, default_weight, default_weight))
381         {
382                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
383                            , "fail to set the color weight of RGB\n");
384                 goto bail1;
385         }
386
387         /* visual init, make a TrueColor, -1 */
388         if (!xf86SetDefaultVisual(pScrn, -1))
389         {
390                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
391                            , "fail to initialize the default visual\n");
392                 goto bail1;
393         }
394
395         /* set gamma */
396         if (!xf86SetGamma(pScrn,defualt_gamma))
397         {
398                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
399                            , "fail to set the gamma\n");
400                 goto bail1;
401         }
402
403         pScrn->progClock = TRUE;
404         pScrn->rgbBits   = 8;
405         pScrn->chipset   = "fbdev";
406         pScrn->videoRam  = fbdevHWGetVidmem(pScrn);
407
408         xf86DrvMsg(pScrn->scrnIndex, X_INFO
409                    , "hardware: %s (video memory: %dkB)\n"
410                    , fbdevHWGetName(pScrn)
411                    , pScrn->videoRam/1024);
412
413         /* Collect all the option flags (fill in pScrn->options) */
414         xf86CollectOptions(pScrn, NULL);
415
416         /*
417           * Process the options based on the information S5POptions.
418           * The results are written to pS5P->Options. If all the options
419           * processing is done within this fuction a local variable "options"
420           * can be used instead of pS5P->Options
421           */
422         if (!(pFBDev->Options = malloc(sizeof(FBDevOptions))))
423                 goto bail1;
424         memcpy(pFBDev->Options, FBDevOptions, sizeof(FBDevOptions));
425         xf86ProcessOptions(pScrn->scrnIndex, pFBDev->pEnt->device->options, pFBDev->Options);
426
427         /* Check with the driver options */
428         FBDevCheckDriverOptions(pScrn);
429
430         /* Set the Crtc,  the default Output, and the current Mode */
431         xf86DrvMsg(pScrn->scrnIndex, X_INFO
432                    , "checking modes against framebuffer device and creating crtc and ouput...\n");
433         if(!FBDevCrtcConfigInit(pScrn))
434         {
435                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
436                            , "Fail to init the CrtcConfig\n");
437                 goto bail1;
438         }
439         FBDevSaveCurrent(pScrn);
440
441         /* TODO::soolim:: re-confirm this condition */
442         if(pScrn->currentMode->HDisplay == pFBDev->var.xres_virtual
443                 && pScrn->currentMode->VDisplay <= pFBDev->var.yres_virtual)
444         {
445                 pScrn->virtualX = pFBDev->var.xres_virtual;
446                 pScrn->virtualY = pFBDev->var.yres_virtual;
447         }
448         else
449         {
450                 pScrn->virtualX = pScrn->currentMode->HDisplay;
451                 pScrn->virtualY = pScrn->currentMode->VDisplay;
452         }
453         pScrn->displayWidth = pScrn->virtualX;
454         xf86PrintModes(pScrn); /* just print the current mode */
455
456         /* Set display resolution */
457         if(pFBDev->var.width && pFBDev->var.height)
458         {
459                 pScrn->monitor->widthmm = pFBDev->var.width;
460                 pScrn->monitor->heightmm = pFBDev->var.height;
461         }
462         xf86SetDpi(pScrn, 0, 0);
463
464         /* Load fb submodule */
465         if (!xf86LoadSubModule(pScrn, "fb"))
466         {
467                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "fail to load fb module\n");
468                 goto bail1;
469         }
470
471         return TRUE;
472
473 bail1:
474         FBDevFreeRec(pScrn);
475         FBDevHWDeInit(pScrn);
476         return FALSE;
477 }
478
479 static void
480 FBDevAdjustFrame(ScrnInfoPtr pScrn, int x, int y)
481 {
482         fbdevHWAdjustFrame(pScrn, x, y);
483 }
484
485
486 /* Save the hw information */
487 static void
488 FBDevSave(ScrnInfoPtr pScrn)
489 {
490         FBDevPtr pFBDev = FBDEVPTR(pScrn);
491
492         FBDevGetVarScreenInfo(fbdevHWGetFD(pScrn), &pFBDev->saved_var);
493 }
494
495 /* Restore the hw information */
496 static void
497 FBDevRestore(ScrnInfoPtr pScrn)
498 {
499         FBDevPtr pFBDev = FBDEVPTR(pScrn);
500
501         FBDevSetVarScreenInfo(fbdevHWGetFD(pScrn), &pFBDev->saved_var);
502 }
503
504 /* Save the current hw information */
505 static void
506 FBDevSaveCurrent(ScrnInfoPtr pScrn)
507 {
508         FBDevPtr pFBDev = FBDEVPTR(pScrn);
509
510         FBDevGetVarScreenInfo(fbdevHWGetFD(pScrn), &pFBDev->var);
511         FBDevGetFixScreenInfo(fbdevHWGetFD(pScrn), &pFBDev->fix);
512 }
513
514 static Bool
515 FBDevModeInit(ScrnInfoPtr pScrn, DisplayModePtr mode)
516 {
517         if (!fbdevHWModeInit(pScrn, mode))
518                 return FALSE;
519
520         return TRUE;
521 }
522
523 /* Get the address of the framebuffer */
524 static unsigned char *
525 FBDevGetFbAddr(ScrnInfoPtr pScrn)
526 {
527         FBDevPtr pFBDev = FBDEVPTR(pScrn);
528         return pFBDev->fbstart;
529 }
530
531 static Bool
532 FBDevScreenInit(ScreenPtr pScreen, int argc, char **argv)
533 {
534         ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
535         FBDevPtr pFBDev = FBDEVPTR(pScrn);
536         VisualPtr visual;
537         int init_picture = 0;
538         unsigned char * pFbAddr;
539         pFBDev->rotate = RR_Rotate_0;
540         Bool rotated = (pFBDev->rotate & (RR_Rotate_90|RR_Rotate_270)) != 0;
541
542         xf86DrvMsg(pScrn->scrnIndex,X_INFO,
543                    "Infomation of Visual is \n\tbitsPerPixel=%d, depth=%d, defaultVisual=%s\n"
544                    "\tmask: %x,%x,%x, offset: %d,%d,%d\n",
545                    pScrn->bitsPerPixel,
546                    pScrn->depth,
547                    xf86GetVisualName(pScrn->defaultVisual),
548                    (unsigned int) pScrn->mask.red,
549                    (unsigned int) pScrn->mask.green,
550                    (unsigned int) pScrn->mask.blue,
551                    (int)pScrn->offset.red,
552                    (int)pScrn->offset.green,
553                    (int)pScrn->offset.blue);
554
555         pFBDev->fbmem = fbdevHWMapVidmem(pScrn); /* mmap memory pointer */
556         if (!pFBDev->fbmem)
557         {
558                 xf86DrvMsg(pScrn->scrnIndex,X_ERROR
559                            ,"mapping of video memory  failed\n");
560                 return FALSE;
561         }
562         pFBDev->fboff = fbdevHWLinearOffset(pScrn);
563
564         /* save fb information */
565         FBDevSave(pScrn);
566
567         /*  set mode and set fb info */
568         DisplayModePtr tmpMode;
569
570         if(rotated)
571                 tmpMode = &pFBDev->builtin_saved;
572         else
573                 tmpMode = pScrn->currentMode;
574
575         if (!FBDevModeInit(pScrn, tmpMode))
576         {
577                 xf86DrvMsg(pScrn->scrnIndex,X_ERROR
578                            ,"mode initialization failed\n");
579                 return FALSE;
580         }
581
582         fbdevHWSaveScreen(pScreen, SCREEN_SAVER_ON);
583         FBDevAdjustFrame(pScrn,0,0);
584
585         FBDevSaveCurrent(pScrn);
586
587         /* mi layer */
588         miClearVisualTypes();
589         if (!miSetVisualTypes(pScrn->depth, TrueColorMask, pScrn->rgbBits, TrueColor))
590         {
591                 xf86DrvMsg(pScrn->scrnIndex,X_ERROR
592                            ,"visual type setup failed for %d bits per pixel [1]\n"
593                            , pScrn->bitsPerPixel);
594                 return FALSE;
595         }
596         if (!miSetPixmapDepths())
597         {
598                 xf86DrvMsg(pScrn->scrnIndex,X_ERROR
599                            ,"pixmap depth setup failed\n");
600                 return FALSE;
601         }
602
603         /* set the starting point of the framebuffer */
604         pFBDev->fbstart = pFBDev->fbmem + pFBDev->fboff;
605
606         /* Get the screen address */
607         pFbAddr = FBDevGetFbAddr(pScrn);
608
609         switch (pScrn->bitsPerPixel)
610         {
611         case 16:
612         case 24:
613         case 32:
614                 if(! fbScreenInit(pScreen, pFbAddr,
615                                   pScrn->virtualX, pScrn->virtualY,
616                                   pScrn->xDpi, pScrn->yDpi,
617                                   pScrn->virtualX, /*Pixel width for framebuffer*/
618                                   pScrn->bitsPerPixel))
619                         return FALSE;
620
621                 init_picture = 1;
622
623                 break;
624         default:
625                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
626                            , "internal error: invalid number of bits per pixel (%d) encountered\n"
627                            , pScrn->bitsPerPixel);
628                 break;
629         }
630
631         if (pScrn->bitsPerPixel > 8)
632         {
633                 /* Fixup RGB ordering */
634                 visual = pScreen->visuals + pScreen->numVisuals;
635                 while (--visual >= pScreen->visuals)
636                 {
637                         if ((visual->class | DynamicClass) == DirectColor)
638                         {
639                                 visual->offsetRed   = pScrn->offset.red;
640                                 visual->offsetGreen = pScrn->offset.green;
641                                 visual->offsetBlue  = pScrn->offset.blue;
642                                 visual->redMask     = pScrn->mask.red;
643                                 visual->greenMask   = pScrn->mask.green;
644                                 visual->blueMask    = pScrn->mask.blue;
645                         }
646                 }
647         }
648
649         /* must be after RGB ordering fixed */
650         if (init_picture && !fbPictureInit(pScreen, NULL, 0))
651                 xf86DrvMsg(pScrn->scrnIndex, X_WARNING
652                            , "Render extension initialisation failed\n");
653
654         /* XVideo Initiailization here */
655 #ifdef XV
656         if (!fbdevVideoInit(pScreen))
657                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
658                            "XVideo extention initialization failed\n");
659 #endif
660
661         xf86SetBlackWhitePixels(pScreen);
662         miInitializeBackingStore(pScreen);
663         xf86SetBackingStore(pScreen);
664
665         /* Check whether the SWCURSOR option is enbled */
666         if(pFBDev->bSWCursorEnbled)
667         {
668                 /* use software cursor */
669                 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
670         }
671         else
672         {
673                 /* use dummy hw_cursro instead of sw_cursor */
674                 miDCInitialize(pScreen, xf86GetPointerScreenFuncs());
675                 xf86DrvMsg(pScrn->scrnIndex, X_INFO
676                            , "Initializing HW Cursor\n");
677
678                 if(!xf86_cursors_init(pScreen, SEC_CURSOR_W, SEC_CURSOR_H,  (HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
679                                       HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
680                                       HARDWARE_CURSOR_INVERT_MASK |
681                                       HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK |
682                                       HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
683                                       HARDWARE_CURSOR_SOURCE_MASK_INTERLEAVE_64 |
684                                       HARDWARE_CURSOR_ARGB)))
685                 {
686                         xf86DrvMsg(pScrn->scrnIndex, X_ERROR
687                                    , "Hardware cursor initialization failed\n");
688                 }
689         }
690
691         /* crtc init */
692         if (!xf86CrtcScreenInit(pScreen))
693                 return FALSE;
694
695         /* set the desire mode : set the mode to xf86crtc here */
696         xf86SetDesiredModes(pScrn);
697
698         /* colormap */
699         if (!miCreateDefColormap(pScreen))
700         {
701                 xf86DrvMsg(pScrn->scrnIndex, X_ERROR
702                            , "internal error: miCreateDefColormap failed \n");
703                 return FALSE;
704         }
705
706         if(!xf86HandleColormaps(pScreen, 256, 8, fbdevHWLoadPaletteWeak(), NULL, CMAP_PALETTED_TRUECOLOR))
707                 return FALSE;
708
709         xf86DPMSInit(pScreen, FBDevDPMSSet(), 0);
710         pScreen->SaveScreen = FBDevSaveScreen();
711         pFBDev->isLcdOff = FALSE;
712
713         /* Wrap the current CloseScreen function */
714         pFBDev->CloseScreen = pScreen->CloseScreen;
715         pScreen->CloseScreen = FBDevCloseScreen;
716
717     /* register the event hook */
718     fbdevTraceInstallHooks ();
719
720 #if USE_XDBG
721     xDbgLogPListInit (pScreen);
722 #endif
723
724         return TRUE;
725 }
726
727
728 static Bool
729 FBDevEnterVT(ScrnInfoPtr pScrn)
730 {
731         xf86DrvMsg(pScrn->scrnIndex, X_INFO
732                    , "EnterVT::Hardware state at EnterVT:\n");
733         return TRUE;
734 }
735
736 static void
737 FBDevLeaveVT(ScrnInfoPtr pScrn)
738 {
739         xf86DrvMsg(pScrn->scrnIndex, X_INFO
740                    , "LeaveVT::Hardware state at LeaveVT:\n");
741 }
742
743 static Bool
744 FBDevCloseScreen(ScreenPtr pScreen)
745 {
746         ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
747         FBDevPtr pFBDev = FBDEVPTR(pScrn);
748
749     fbdevTraceUninstallHooks ();
750
751         FBDevRestore(pScrn);
752
753         fbdevHWUnmapVidmem(pScrn);
754         pScrn->vtSema = FALSE;
755
756         if(!pFBDev->bLockScreen)
757                 FBDevRestore(pScrn);
758         else
759                 ErrorF("Screen closed but LCD was locked\n");
760
761         FBDevHWDeInit(pScrn);
762
763         pScreen->CreateScreenResources = pFBDev->CreateScreenResources;
764         pScreen->CloseScreen = pFBDev->CloseScreen;
765
766         return (*pScreen->CloseScreen)(pScreen);
767 }
768
769
770
771