1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/nsc_gx2_cursor.c,v 1.5tsi Exp $ */
2/*
3 * $Workfile: nsc_gx2_cursor.c $
4 * $Revision: 1.1.1.1 $
5 * $Author: mrg $
6 *
7 * File Contents: Xfree cursor implementation routines
8 *                for geode HWcursor init.setting cursor color,image etc
9 *                are done here.
10 * Project:       Geode Xfree Frame buffer device driver.
11 *
12 */
13
14/*
15 * NSC_LIC_ALTERNATIVE_PREAMBLE
16 *
17 * Revision 1.0
18 *
19 * National Semiconductor Alternative GPL-BSD License
20 *
21 * National Semiconductor Corporation licenses this software
22 * ("Software"):
23 *
24 * National Xfree frame buffer driver
25 *
26 * under one of the two following licenses, depending on how the
27 * Software is received by the Licensee.
28 *
29 * If this Software is received as part of the Linux Framebuffer or
30 * other GPL licensed software, then the GPL license designated
31 * NSC_LIC_GPL applies to this Software; in all other circumstances
32 * then the BSD-style license designated NSC_LIC_BSD shall apply.
33 *
34 * END_NSC_LIC_ALTERNATIVE_PREAMBLE */
35
36/* NSC_LIC_BSD
37 *
38 * National Semiconductor Corporation Open Source License for
39 *
40 * National Xfree frame buffer driver
41 *
42 * (BSD License with Export Notice)
43 *
44 * Copyright (c) 1999-2001
45 * National Semiconductor Corporation.
46 * All rights reserved.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 *
52 *   * Redistributions of source code must retain the above copyright
53 *     notice, this list of conditions and the following disclaimer.
54 *
55 *   * Redistributions in binary form must reproduce the above
56 *     copyright notice, this list of conditions and the following
57 *     disclaimer in the documentation and/or other materials provided
58 *     with the distribution.
59 *
60 *   * Neither the name of the National Semiconductor Corporation nor
61 *     the names of its contributors may be used to endorse or promote
62 *     products derived from this software without specific prior
63 *     written permission.
64 *
65 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
66 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
67 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
68 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
69 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
70 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
72 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
73 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
74 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
75 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
76 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
77 * OF SUCH DAMAGE.
78 *
79 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
80 * YOUR JURISDICTION. It is licensee's responsibility to comply with
81 * any export regulations applicable in licensee's jurisdiction. Under
82 * CURRENT (2001) U.S. export regulations this software
83 * is eligible for export from the U.S. and can be downloaded by or
84 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
85 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
86 * Syria, Sudan, Afghanistan and any other country to which the U.S.
87 * has embargoed goods and services.
88 *
89 * END_NSC_LIC_BSD */
90
91/* NSC_LIC_GPL
92 *
93 * National Semiconductor Corporation Gnu General Public License for
94 *
95 * National Xfree frame buffer driver
96 *
97 * (GPL License with Export Notice)
98 *
99 * Copyright (c) 1999-2001
100 * National Semiconductor Corporation.
101 * All rights reserved.
102 *
103 * Redistribution and use in source and binary forms, with or without
104 * modification, are permitted under the terms of the GNU General
105 * Public License as published by the Free Software Foundation; either
106 * version 2 of the License, or (at your option) any later version
107 *
108 * In addition to the terms of the GNU General Public License, neither
109 * the name of the National Semiconductor Corporation nor the names of
110 * its contributors may be used to endorse or promote products derived
111 * from this software without specific prior written permission.
112 *
113 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
114 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
115 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
116 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
117 * NATIONAL SEMICONDUCTOR CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY
118 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
119 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
120 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
121 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
122 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE,
123 * INTELLECTUAL PROPERTY INFRINGEMENT, OR OTHERWISE) ARISING IN ANY WAY
124 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
125 * OF SUCH DAMAGE. See the GNU General Public License for more details.
126 *
127 * EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
128 * YOUR JURISDICTION. It is licensee's responsibility to comply with
129 * any export regulations applicable in licensee's jurisdiction. Under
130 * CURRENT (2001) U.S. export regulations this software
131 * is eligible for export from the U.S. and can be downloaded by or
132 * otherwise exported or reexported worldwide EXCEPT to U.S. embargoed
133 * destinations which include Cuba, Iraq, Libya, North Korea, Iran,
134 * Syria, Sudan, Afghanistan and any other country to which the U.S.
135 * has embargoed goods and services.
136 *
137 * You should have received a copy of the GNU General Public License
138 * along with this file; if not, write to the Free Software Foundation,
139 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
140 *
141 * END_NSC_LIC_GPL */
142
143#ifdef HAVE_CONFIG_H
144#include "config.h"
145#endif
146
147#include "xf86.h"
148#include "xf86_OSproc.h"
149#include "xf86Pci.h"
150#include "xf86PciInfo.h"
151#include "nsc.h"
152
153/* Forward declarations of the functions */
154Bool GX2HWCursorInit(ScreenPtr pScreen);
155static void GX2SetCursorColors(ScrnInfoPtr pScreenInfo, int bg, int fg);
156static void GX2SetCursorPosition(ScrnInfoPtr pScreenInfo, int x, int y);
157void GX2LoadCursorImage(ScrnInfoPtr pScreenInfo, unsigned char *src);
158void GX2HideCursor(ScrnInfoPtr pScreenInfo);
159void GX2ShowCursor(ScrnInfoPtr pScreenInfo);
160static Bool GX2UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs);
161extern void GX2SetVideoPosition(int x, int y, int width, int height,
162				short src_w, short src_h, short drw_w,
163				short drw_h, int id, int offset,
164				ScrnInfoPtr pScrn);
165
166/*----------------------------------------------------------------------------
167 * GX2HWCursorInit.
168 *
169 * Description	:This function sets the cursor information by probing the
170 * hardware.
171 *
172 * Parameters.
173 *     pScreen	:Screeen pointer structure.
174 *
175 * Returns		:TRUE on success and FALSE on Failure
176 *
177 * Comments		:Geode supports the hardware_cursor,no need to enable SW
178 *                    cursor.
179*----------------------------------------------------------------------------
180*/
181Bool
182GX2HWCursorInit(ScreenPtr pScreen)
183{
184   ScrnInfoPtr pScreenInfo = xf86Screens[pScreen->myNum];
185   GeodePtr pGeode = GEODEPTR(pScreenInfo);
186   xf86CursorInfoPtr infoPtr;
187
188   infoPtr = xf86CreateCursorInfoRec();
189   if (!infoPtr)
190      return FALSE;
191   /* the geode structure is intiallized with the cursor infoRec */
192   pGeode->CursorInfo = infoPtr;
193   infoPtr->MaxWidth = 32;
194   infoPtr->MaxHeight = 32;
195   /* seeting up the cursor flags */
196   infoPtr->Flags = HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
197	 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
198	 HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED;
199   /* cursor info ptr is intiallized with the values obtained from
200    * * durnago calls
201    */
202   infoPtr->SetCursorColors = GX2SetCursorColors;
203   infoPtr->SetCursorPosition = GX2SetCursorPosition;
204   infoPtr->LoadCursorImage = GX2LoadCursorImage;
205   infoPtr->HideCursor = GX2HideCursor;
206   infoPtr->ShowCursor = GX2ShowCursor;
207   infoPtr->UseHWCursor = GX2UseHWCursor;
208   return (xf86InitCursor(pScreen, infoPtr));
209}
210
211/*----------------------------------------------------------------------------
212 * GX2SetCursorColors.
213 *
214 * Description	:This function sets the cursor foreground and background
215 *                    colors
216 * Parameters:
217 *    pScreen:	Screeen pointer structure.
218 *    	   bg:	Specifies the color value of cursor background color.
219 *    	   fg:	Specifies the color value of cursor foreground color.
220 *    Returns:	none.
221 *
222 *   Comments:	The integer color value passed by this function is
223 *              converted into  * RGB  value by the gfx_set_color routines.
224 *----------------------------------------------------------------------------
225 */
226static void
227GX2SetCursorColors(ScrnInfoPtr pScreenInfo, int bg, int fg)
228{
229   GFX(set_cursor_colors(bg, fg));
230}
231
232/*----------------------------------------------------------------------------
233 * GX2SetCursorPosition.
234 *
235 * Description	:This function sets the cursor co -ordinates and enable the
236 *               cursor.
237 *
238 * Parameters:
239 *    pScreen: Screeen pointer structure.
240 *    	    x: Specifies the x-cordinates of the cursor.
241 *    	    y: Specifies the y co-ordinate of the cursor.
242 *    Returns: none.
243 *
244 *----------------------------------------------------------------------------
245 */
246static void
247GX2SetCursorPosition(ScrnInfoPtr pScreenInfo, int x, int y)
248{
249   unsigned long offset;
250   static int panOffset = 0;
251   GeodePtr pGeode = GEODEPTR(pScreenInfo);
252
253   unsigned short xhot = 0, yhot = 0;
254
255   if (x < 0) {
256      xhot = (unsigned short)(-x);
257      x = 0;
258   }
259   if (y < 0) {
260      yhot = (unsigned short)(-y);
261      y = 0;
262   }
263
264   GFX(set_cursor_position(pGeode->CursorStartOffset, x, y, xhot, yhot));
265   GFX(set_cursor_enable(1));
266
267   if ((pGeode->OverlayON) && (pGeode->Panel)) {
268#if defined(STB_X)
269      Gal_get_display_offset(&offset);
270#else
271      offset = gfx_get_display_offset();
272#endif
273      if (offset != panOffset) {
274	 GX2SetVideoPosition(pGeode->video_x, pGeode->video_y,
275			     pGeode->video_w, pGeode->video_h,
276			     pGeode->video_srcw, pGeode->video_srch,
277			     pGeode->video_dstw, pGeode->video_dsth,
278			     pGeode->video_id, pGeode->video_offset,
279			     pGeode->video_scrnptr);
280	 panOffset = offset;
281      }
282   }
283}
284
285/*----------------------------------------------------------------------------
286 * GX2LoadCursorImage
287 *
288 * Description	:This function loads the 32x32 cursor pattern.The shape
289 *               and color is set by AND and XOR masking of arrays of 32
290 *               DWORD.
291 * Parameters:
292 *    pScreen: Screeen pointer structure.
293 *    src    : Specifies cursor data.
294 * Returns   : none
295 *
296 *----------------------------------------------------------------------------
297*/
298void
299GX2LoadCursorImage(ScrnInfoPtr pScreenInfo, unsigned char *src)
300{
301   int i;
302   unsigned long shape;
303   unsigned long mask;
304   unsigned long andMask[32] = { 0, };
305   unsigned long xorMask[32] = { 0, };
306   GeodePtr pGeode = GEODEPTR(pScreenInfo);
307
308   for (i = 0; i < 32; i++) {
309      if (src) {
310	 shape = ((unsigned long)src[i * 4] << 24) |
311	       ((unsigned long)src[i * 4 + 1] << 16) |
312	       ((unsigned long)src[i * 4 + 2] << 8) |
313	       ((unsigned long)src[i * 4 + 3] << 0);
314	 mask = ((unsigned long)src[i * 4 + 128] << 24) |
315	       ((unsigned long)src[i * 4 + 1 + 128] << 16) |
316	       ((unsigned long)src[i * 4 + 2 + 128] << 8) |
317	       ((unsigned long)src[i * 4 + 3 + 128] << 0);
318      } else {
319	 mask = 0x0;
320	 shape = 0xFFFFFFFF;
321      }
322
323      andMask[i] = ~(mask);
324      xorMask[i] = shape & mask;
325   }
326
327   GFX(set_cursor_shape32(pGeode->CursorStartOffset, andMask, xorMask));
328}
329
330/*----------------------------------------------------------------------------
331 * GX2HideCursor.
332 *
333 * Description	:This function will disable the cursor.
334 *
335 * Parameters:
336 *    pScreen: Handles to the Screeen pointer structure.
337 *
338 *    Returns: none.
339 *
340 *   Comments:	gfx_set_cursor enable function is hardcoded to disable
341 *		the cursor.
342 *----------------------------------------------------------------------------
343 */
344void
345GX2HideCursor(ScrnInfoPtr pScreenInfo)
346{
347   GFX(set_cursor_enable(0));
348}
349
350/*----------------------------------------------------------------------------
351 * GX2ShowCursor
352 *
353 * Description	:This function will enable  the cursor.
354 *
355 * Parameters:
356 *	pScreen		:Handles to the Screeen pointer structure.
357 *
358 * Returns      :none
359 *
360 * Comments		:gfx_set_cursor enable function is hardcoded to enable the
361 * 											cursor
362 *----------------------------------------------------------------------------
363*/
364void
365GX2ShowCursor(ScrnInfoPtr pScreenInfo)
366{
367   GFX(set_cursor_enable(1));
368}
369
370/*----------------------------------------------------------------------------
371 * GX2UseHwCursor.
372 *
373 * Description	:This function will sets the hardware cursor flag in
374 *                 pscreen  structure.
375 *
376 * Parameters.
377 *	pScreen		:Handles to the Screeen pointer structure.
378 *
379 * Returns		:none
380 *
381 * Comments		:none
382 *
383 *----------------------------------------------------------------------------
384*/
385static Bool
386GX2UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs)
387{
388   ScrnInfoPtr pScreenInfo = XF86SCRNINFO(pScreen);
389
390   if (pScreenInfo->currentMode->Flags & V_DBLSCAN)
391      return FALSE;
392   return TRUE;
393}
394
395/* End of File */
396