1 /*
2    TI Davinci driver - Primary Screen
3 
4    (c) Copyright 2007  Telio AG
5 
6    Written by Denis Oliver Kropp <dok@directfb.org>
7 
8    Code is derived from VMWare driver.
9 
10    (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
11    (c) Copyright 2000-2004  Convergence (integrated media) GmbH
12 
13    All rights reserved.
14 
15    This library is free software; you can redistribute it and/or
16    modify it under the terms of the GNU Lesser General Public
17    License as published by the Free Software Foundation; either
18    version 2 of the License, or (at your option) any later version.
19 
20    This library is distributed in the hope that it will be useful,
21    but WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    Lesser General Public License for more details.
24 
25    You should have received a copy of the GNU Lesser General Public
26    License along with this library; if not, write to the
27    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28    Boston, MA 02111-1307, USA.
29 */
30 
31 //#define DIRECT_ENABLE_DEBUG
32 
33 #include <config.h>
34 
35 #include <asm/types.h>
36 
37 #include <stdio.h>
38 #include <sys/mman.h>
39 
40 #include <directfb.h>
41 
42 #include <core/screens.h>
43 
44 #include <direct/debug.h>
45 #include <direct/messages.h>
46 
47 #include <sys/ioctl.h>
48 
49 #include "davincifb.h"
50 
51 #include "davinci_gfxdriver.h"
52 #include "davinci_screen.h"
53 
54 
55 D_DEBUG_DOMAIN( Davinci_Screen, "Davinci/Screen", "TI Davinci Screen" );
56 
57 /**********************************************************************************************************************/
58 
59 static DFBResult
davinciInitScreen(CoreScreen * screen,CoreGraphicsDevice * device,void * driver_data,void * screen_data,DFBScreenDescription * description)60 davinciInitScreen( CoreScreen           *screen,
61                    CoreGraphicsDevice   *device,
62                    void                 *driver_data,
63                    void                 *screen_data,
64                    DFBScreenDescription *description )
65 {
66      D_DEBUG_AT( Davinci_Screen, "%s()\n", __FUNCTION__ );
67 
68      /* Set the screen capabilities. */
69      description->caps = DSCCAPS_VSYNC;
70 
71      /* Set the screen name. */
72      snprintf( description->name, DFB_SCREEN_DESC_NAME_LENGTH, "TI Davinci Screen" );
73 
74      return DFB_OK;
75 }
76 
77 static DFBResult
davinciGetScreenSize(CoreScreen * screen,void * driver_data,void * screen_data,int * ret_width,int * ret_height)78 davinciGetScreenSize( CoreScreen *screen,
79                       void       *driver_data,
80                       void       *screen_data,
81                       int        *ret_width,
82                       int        *ret_height )
83 {
84      int                  ret;
85      vpbe_fb_videomode_t  mode;
86      DavinciDriverData   *ddrv = driver_data;
87 
88      D_DEBUG_AT( Davinci_Screen, "%s()\n", __FUNCTION__ );
89 
90      D_ASSERT( ret_width != NULL );
91      D_ASSERT( ret_height != NULL );
92 
93      ret = ioctl( ddrv->fb[OSD0].fd, FBIO_GET_TIMING, &mode );
94      if (ret) {
95           D_PERROR( "%s: FBIO_GET_TIMING (fb%d, OSD0) failed!\n", __func__, OSD0 );
96           return DFB_INIT;
97      }
98 
99      *ret_width  = mode.xres;
100      *ret_height = mode.yres;
101 
102      return DFB_OK;
103 }
104 
105 static DFBResult
davinciWaitVSync(CoreScreen * screen,void * driver_data,void * screen_data)106 davinciWaitVSync( CoreScreen *screen,
107                   void       *driver_data,
108                   void       *screen_data )
109 {
110      DavinciDriverData *ddrv = driver_data;
111 
112      D_DEBUG_AT( Davinci_Screen, "%s()\n", __FUNCTION__ );
113 
114      ioctl( ddrv->fb[OSD0].fd, FBIO_WAITFORVSYNC );
115 
116      return DFB_OK;
117 }
118 
119 ScreenFuncs davinciScreenFuncs = {
120      .InitScreen    = davinciInitScreen,
121      .GetScreenSize = davinciGetScreenSize,
122      .WaitVSync     = davinciWaitVSync,
123 };
124 
125