1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/nsc/nsc_gx1_cursor.c,v 1.5tsi Exp $ */
2/*
3 * $Workfile: nsc_gx1_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 GX1HWCursorInit(ScreenPtr pScreen);
155static void GX1SetCursorColors(ScrnInfoPtr pScreenInfo, int bg, int fg);
156static void GX1SetCursorPosition(ScrnInfoPtr pScreenInfo, int x, int y);
157void GX1LoadCursorImage(ScrnInfoPtr pScreenInfo, unsigned char *src);
158void GX1HideCursor(ScrnInfoPtr pScreenInfo);
159void GX1ShowCursor(ScrnInfoPtr pScreenInfo);
160static Bool GX1UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs);
161extern void GX1SetVideoPosition(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 * GX1HWCursorInit.
167 *
168 * Description	:This function sets the cursor information by probing the
169 * 																hardware.
170 *
171 * Parameters.
172 *     pScreen	:Screeen pointer structure.
173 *
174 * Returns		:TRUE on success and FALSE on Failure
175 *
176 * Comments		:Geode supports the hardware_cursor,no need to enable SW
177 *                    cursor.
178*----------------------------------------------------------------------------
179*/
180Bool
181GX1HWCursorInit(ScreenPtr pScreen)
182{
183   ScrnInfoPtr pScreenInfo = xf86Screens[pScreen->myNum];
184   GeodePtr pGeode = GEODEPTR(pScreenInfo);
185   xf86CursorInfoPtr infoPtr;
186
187   infoPtr = xf86CreateCursorInfoRec();
188   if (!infoPtr)
189      return FALSE;
190   /* the geode structure is intiallized with the cursor infoRec */
191   pGeode->CursorInfo = infoPtr;
192   infoPtr->MaxWidth = 32;
193   infoPtr->MaxHeight = 32;
194   /* seeting up the cursor flags */
195   infoPtr->Flags = HARDWARE_CURSOR_BIT_ORDER_MSBFIRST |
196	 HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
197	 HARDWARE_CURSOR_SOURCE_MASK_NOT_INTERLEAVED;
198   /* cursor info ptr is intiallized with the values obtained from
199    * * durnago calls
200    */
201   infoPtr->SetCursorColors = GX1SetCursorColors;
202   infoPtr->SetCursorPosition = GX1SetCursorPosition;
203   infoPtr->LoadCursorImage = GX1LoadCursorImage;
204   infoPtr->HideCursor = GX1HideCursor;
205   infoPtr->ShowCursor = GX1ShowCursor;
206   infoPtr->UseHWCursor = GX1UseHWCursor;
207   return (xf86InitCursor(pScreen, infoPtr));
208}
209
210/*----------------------------------------------------------------------------
211 * GX1SetCursorColors.
212 *
213 * Description	:This function sets the cursor foreground and background
214 *                    colors
215 * Parameters:
216 *    pScreen:	Screeen pointer structure.
217 *    	   bg:	Specifies the color value of cursor background color.
218 *    	   fg:	Specifies the color value of cursor foreground color.
219 *    Returns:	none.
220 *
221 *   Comments:	The integer color value passed by this function is
222 *              converted into  * RGB  value by the gfx_set_color routines.
223 *----------------------------------------------------------------------------
224 */
225static void
226GX1SetCursorColors(ScrnInfoPtr pScreenInfo, int bg, int fg)
227{
228   GFX(set_cursor_colors(bg, fg));
229}
230
231/*----------------------------------------------------------------------------
232 * GX1SetCursorPosition.
233 *
234 * Description	:This function sets the cursor co -ordinates and enable the
235 *               cursor.
236 *
237 * Parameters:
238 *    pScreen: Screeen pointer structure.
239 *    	    x: Specifies the x-cordinates of the cursor.
240 *    	    y: Specifies the y co-ordinate of the cursor.
241 *    Returns: none.
242 *
243 *----------------------------------------------------------------------------
244 */
245static void
246GX1SetCursorPosition(ScrnInfoPtr pScreenInfo, int x, int y)
247{
248   unsigned long offset;
249   static int panOffset = 0;
250   GeodePtr pGeode = GEODEPTR(pScreenInfo);
251
252   unsigned short xhot = 0, yhot = 0;
253
254   if (x < 0) {
255      xhot = (unsigned short)(-x);
256      x = 0;
257   }
258   if (y < 0) {
259      yhot = (unsigned short)(-y);
260      y = 0;
261   }
262
263   if (pGeode->TV_Overscan_On) {
264      x += pGeode->TVOx;
265      y += pGeode->TVOy;
266   }
267   GFX(set_cursor_position(pGeode->CursorStartOffset, x, y, xhot, yhot));
268   GFX(set_cursor_enable(1));
269
270   if ((pGeode->OverlayON) && (pGeode->Panel)) {
271#if defined(STB_X)
272      Gal_get_display_offset(&offset);
273#else
274      offset = gfx_get_display_offset();
275#endif
276      if (offset != panOffset) {
277	 GX1SetVideoPosition(pGeode->video_x, pGeode->video_y,
278			     pGeode->video_w, pGeode->video_h,
279			     pGeode->video_srcw, pGeode->video_srch,
280			     pGeode->video_dstw, pGeode->video_dsth,
281			     pGeode->video_id, pGeode->video_offset,
282			     pGeode->video_scrnptr);
283	 panOffset = offset;
284      }
285   }
286}
287
288/*----------------------------------------------------------------------------
289 * GX1LoadCursorImage
290 *
291 * Description	:This function loads the 32x32 cursor pattern.The shape
292 *               and color is set by AND and XOR masking of arrays of 32
293 *               DWORD.
294 * Parameters:
295 *    pScreen: Screeen pointer structure.
296 *    src    : Specifies cursor data.
297 * Returns   : none
298 *
299 *----------------------------------------------------------------------------
300*/
301void
302GX1LoadCursorImage(ScrnInfoPtr pScreenInfo, unsigned char *src)
303{
304   int i;
305   unsigned long shape;
306   unsigned long mask;
307   unsigned long andMask[32] = { 0, };
308   unsigned long xorMask[32] = { 0, };
309   GeodePtr pGeode = GEODEPTR(pScreenInfo);
310
311   for (i = 0; i < 32; i++) {
312      if (src) {
313	 shape = ((unsigned long)src[i * 4] << 24) |
314	       ((unsigned long)src[i * 4 + 1] << 16) |
315	       ((unsigned long)src[i * 4 + 2] << 8) |
316	       ((unsigned long)src[i * 4 + 3] << 0);
317	 mask = ((unsigned long)src[i * 4 + 128] << 24) |
318	       ((unsigned long)src[i * 4 + 1 + 128] << 16) |
319	       ((unsigned long)src[i * 4 + 2 + 128] << 8) |
320	       ((unsigned long)src[i * 4 + 3 + 128] << 0);
321      } else {
322	 mask = 0x0;
323	 shape = 0xFFFFFFFF;
324      }
325
326      andMask[i] = ~(mask);
327      xorMask[i] = shape & mask;
328   }
329
330   GFX(set_cursor_shape32(pGeode->CursorStartOffset, andMask, xorMask));
331}
332
333/*----------------------------------------------------------------------------
334 * GX1HideCursor.
335 *
336 * Description	:This function will disable the cursor.
337 *
338 * Parameters:
339 *    pScreen: Handles to the Screeen pointer structure.
340 *
341 *    Returns: none.
342 *
343 *   Comments:	gfx_set_cursor enable function is hardcoded to disable
344 *		the cursor.
345 *----------------------------------------------------------------------------
346 */
347void
348GX1HideCursor(ScrnInfoPtr pScreenInfo)
349{
350   GFX(set_cursor_enable(0));
351}
352
353/*----------------------------------------------------------------------------
354 * GX1ShowCursor
355 *
356 * Description	:This function will enable  the cursor.
357 *
358 * Parameters:
359 *	pScreen		:Handles to the Screeen pointer structure.
360 *
361 * Returns      :none
362 *
363 * Comments		:gfx_set_cursor enable function is hardcoded to enable the
364 * 											cursor
365 *----------------------------------------------------------------------------
366*/
367void
368GX1ShowCursor(ScrnInfoPtr pScreenInfo)
369{
370   GFX(set_cursor_enable(1));
371}
372
373/*----------------------------------------------------------------------------
374 * GX1UseHwCursor.
375 *
376 * Description	:This function will sets the hardware cursor flag in
377 *                 pscreen  structure.
378 *
379 * Parameters.
380 *	pScreen		:Handles to the Screeen pointer structure.
381 *
382 * Returns		:none
383 *
384 * Comments		:none
385 *
386 *----------------------------------------------------------------------------
387*/
388static Bool
389GX1UseHWCursor(ScreenPtr pScreen, CursorPtr pCurs)
390{
391   ScrnInfoPtr pScreenInfo = XF86SCRNINFO(pScreen);
392
393   if (pScreenInfo->currentMode->Flags & V_DBLSCAN)
394      return FALSE;
395   return TRUE;
396}
397
398/* End of File */
399