1 /*
2 * Copyright (C) 2006 Claudio Ciccani <klan@users.sf.net>
3 *
4 * Graphics driver for ATI Radeon cards written by
5 * Claudio Ciccani <klan@users.sf.net>.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23 #include <config.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29
30 #include <directfb.h>
31
32 #include <core/coredefs.h>
33 #include <core/screen.h>
34 #include <core/screens.h>
35 #include <core/layers.h>
36 #include <core/layer_context.h>
37 #include <core/layer_region.h>
38 #include <core/layer_control.h>
39 #include <core/layers_internal.h>
40 #include <core/surface.h>
41 #include <core/system.h>
42
43 #include <misc/conf.h>
44
45 #include "radeon.h"
46 #include "radeon_regs.h"
47 #include "radeon_mmio.h"
48
49
50
51 /*************************** CRTC1 Screen functions **************************/
52
53 static DFBResult
crtc1WaitVSync(CoreScreen * screen,void * driver_data,void * screen_data)54 crtc1WaitVSync( CoreScreen *screen,
55 void *driver_data,
56 void *screen_data )
57 {
58 RadeonDriverData *rdrv = (RadeonDriverData*) driver_data;
59 volatile u8 *mmio = rdrv->mmio_base;
60 int i;
61
62 if (dfb_config->pollvsync_none)
63 return DFB_OK;
64
65 radeon_out32( mmio, GEN_INT_STATUS,
66 (radeon_in32( mmio, GEN_INT_STATUS ) & ~VSYNC_INT) | VSYNC_INT_AK );
67
68 for (i = 0; i < 2000000; i++) {
69 struct timespec t = { 0, 10000 };
70
71 if (radeon_in32( mmio, GEN_INT_STATUS ) & VSYNC_INT)
72 break;
73 nanosleep( &t, NULL );
74 }
75
76 return DFB_OK;
77 }
78
79 ScreenFuncs RadeonCrtc1ScreenFuncs = {
80 .WaitVSync = crtc1WaitVSync
81 };
82
83 ScreenFuncs OldPrimaryScreenFuncs;
84 void *OldPrimaryScreenDriverData;
85
86
87 /*************************** CRTC1 Layer functions **************************/
88
89 #define CRTC1_SUPPORTED_OPTIONS ( DLOP_ALPHACHANNEL )
90
91 static DFBResult
crtc1InitLayer(CoreLayer * layer,void * driver_data,void * layer_data,DFBDisplayLayerDescription * description,DFBDisplayLayerConfig * config,DFBColorAdjustment * adjustment)92 crtc1InitLayer( CoreLayer *layer,
93 void *driver_data,
94 void *layer_data,
95 DFBDisplayLayerDescription *description,
96 DFBDisplayLayerConfig *config,
97 DFBColorAdjustment *adjustment )
98 {
99 DFBResult ret;
100
101 ret = OldPrimaryLayerFuncs.InitLayer( layer,
102 OldPrimaryLayerDriverData,
103 layer_data, description,
104 config, adjustment );
105
106 description->caps |= DLCAPS_ALPHACHANNEL;
107
108 return ret;
109 }
110
111 static DFBResult
crtc1TestRegion(CoreLayer * layer,void * driver_data,void * layer_data,CoreLayerRegionConfig * config,CoreLayerRegionConfigFlags * failed)112 crtc1TestRegion( CoreLayer *layer,
113 void *driver_data,
114 void *layer_data,
115 CoreLayerRegionConfig *config,
116 CoreLayerRegionConfigFlags *failed )
117 {
118 CoreLayerRegionConfig layer_config;
119 CoreLayerRegionConfigFlags fail = 0;
120 DFBResult ret;
121
122 layer_config = *config;
123 layer_config.options &= ~CRTC1_SUPPORTED_OPTIONS;
124
125 ret = OldPrimaryLayerFuncs.TestRegion( layer,
126 OldPrimaryLayerDriverData,
127 layer_data, &layer_config, &fail );
128
129 if (config->options & ~CRTC1_SUPPORTED_OPTIONS)
130 fail |= CLRCF_OPTIONS;
131
132 if (config->options & DLOP_ALPHACHANNEL && config->format != DSPF_ARGB)
133 fail |= CLRCF_OPTIONS;
134
135 if (failed)
136 *failed = fail;
137
138 return fail ? DFB_UNSUPPORTED : DFB_OK;
139 }
140
141 static DFBResult
crtc1SetRegion(CoreLayer * layer,void * driver_data,void * layer_data,void * region_data,CoreLayerRegionConfig * config,CoreLayerRegionConfigFlags updated,CoreSurface * surface,CorePalette * palette,CoreSurfaceBufferLock * lock)142 crtc1SetRegion( CoreLayer *layer,
143 void *driver_data,
144 void *layer_data,
145 void *region_data,
146 CoreLayerRegionConfig *config,
147 CoreLayerRegionConfigFlags updated,
148 CoreSurface *surface,
149 CorePalette *palette,
150 CoreSurfaceBufferLock *lock )
151 {
152
153 if (updated & ~CLRCF_OPTIONS) {
154 return OldPrimaryLayerFuncs.SetRegion( layer,
155 OldPrimaryLayerDriverData,
156 layer_data, region_data,
157 config, updated, surface, palette, lock );
158 }
159
160 return DFB_OK;
161 }
162
163 DisplayLayerFuncs RadeonCrtc1LayerFuncs = {
164 .InitLayer = crtc1InitLayer,
165 .TestRegion = crtc1TestRegion,
166 .SetRegion = crtc1SetRegion
167 };
168
169 DisplayLayerFuncs OldPrimaryLayerFuncs;
170 void *OldPrimaryLayerDriverData;
171
172