ag10e_cursor.c revision 98bb403a
198bb403aSmacallan/*
298bb403aSmacallan * Hardware cursor support for Fujitsu AG-10e
398bb403aSmacallan *
498bb403aSmacallan * Copyright 2007 by Michael Lorenz
598bb403aSmacallan *
698bb403aSmacallan * Permission to use, copy, modify, distribute, and sell this software
798bb403aSmacallan * and its documentation for any purpose is hereby granted without
898bb403aSmacallan * fee, provided that the above copyright notice appear in all copies
998bb403aSmacallan * and that both that copyright notice and this permission notice
1098bb403aSmacallan * appear in supporting documentation, and that the name of Jakub
1198bb403aSmacallan * Jelinek not be used in advertising or publicity pertaining to
1298bb403aSmacallan * distribution of the software without specific, written prior
1398bb403aSmacallan * permission.  Jakub Jelinek makes no representations about the
1498bb403aSmacallan * suitability of this software for any purpose.  It is provided "as
1598bb403aSmacallan * is" without express or implied warranty.
1698bb403aSmacallan *
1798bb403aSmacallan * JAKUB JELINEK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
1898bb403aSmacallan * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
1998bb403aSmacallan * FITNESS, IN NO EVENT SHALL JAKUB JELINEK BE LIABLE FOR ANY
2098bb403aSmacallan * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
2198bb403aSmacallan * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
2298bb403aSmacallan * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
2398bb403aSmacallan * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
2498bb403aSmacallan * SOFTWARE.
2598bb403aSmacallan */
2698bb403aSmacallan/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/suncg6/cg6_cursor.c,v 1.1 2000/06/30 19:30:46 dawes Exp $ */
2798bb403aSmacallan
2898bb403aSmacallan#include <fcntl.h>
2998bb403aSmacallan#include <sys/time.h>
3098bb403aSmacallan#include <sys/types.h>
3198bb403aSmacallan#include <dev/sun/fbio.h>
3298bb403aSmacallan#include <dev/wscons/wsconsio.h>
3398bb403aSmacallan
3498bb403aSmacallan#include "ag10e.h"
3598bb403aSmacallan
3698bb403aSmacallanstatic void AG10ELoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
3798bb403aSmacallanstatic void AG10EShowCursor(ScrnInfoPtr pScrn);
3898bb403aSmacallanstatic void AG10EHideCursor(ScrnInfoPtr pScrn);
3998bb403aSmacallanstatic void AG10ESetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
4098bb403aSmacallanstatic void AG10ESetCursorColors(ScrnInfoPtr pScrn, int bg, int fg);
4198bb403aSmacallan
4298bb403aSmacallanstatic void
4398bb403aSmacallanAG10ELoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src)
4498bb403aSmacallan{
4598bb403aSmacallan    AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn);
4698bb403aSmacallan
4798bb403aSmacallan    pAG10E->Cursor.set = FB_CUR_SETSHAPE;
4898bb403aSmacallan    pAG10E->Cursor.image = src;
4998bb403aSmacallan    pAG10E->Cursor.mask = src + 0x200;
5098bb403aSmacallan
5198bb403aSmacallan    if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1)
5298bb403aSmacallan	xf86Msg(X_ERROR, "FB_CUR_SETSHAPE failed\n");
5398bb403aSmacallan}
5498bb403aSmacallan
5598bb403aSmacallanvoid
5698bb403aSmacallanAG10EShowCursor(ScrnInfoPtr pScrn)
5798bb403aSmacallan{
5898bb403aSmacallan    AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn);
5998bb403aSmacallan
6098bb403aSmacallan    if (pAG10E->Cursor.enable == 0) {
6198bb403aSmacallan    	pAG10E->Cursor.enable = 1;
6298bb403aSmacallan	pAG10E->Cursor.set = FB_CUR_SETCUR;
6398bb403aSmacallan	if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1)
6498bb403aSmacallan	    xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n");
6598bb403aSmacallan    }
6698bb403aSmacallan}
6798bb403aSmacallan
6898bb403aSmacallanvoid
6998bb403aSmacallanAG10EHideCursor(ScrnInfoPtr pScrn)
7098bb403aSmacallan{
7198bb403aSmacallan    AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn);
7298bb403aSmacallan
7398bb403aSmacallan    if (pAG10E->Cursor.enable == 1) {
7498bb403aSmacallan    	pAG10E->Cursor.enable = 0;
7598bb403aSmacallan	pAG10E->Cursor.set = FB_CUR_SETCUR;
7698bb403aSmacallan	if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1)
7798bb403aSmacallan	    xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n");
7898bb403aSmacallan    }
7998bb403aSmacallan}
8098bb403aSmacallan
8198bb403aSmacallanstatic void
8298bb403aSmacallanAG10ESetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
8398bb403aSmacallan{
8498bb403aSmacallan    AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn);
8598bb403aSmacallan
8698bb403aSmacallan    pAG10E->Cursor.pos.x = x;
8798bb403aSmacallan    pAG10E->Cursor.pos.y = y;
8898bb403aSmacallan    pAG10E->Cursor.set = FB_CUR_SETPOS;
8998bb403aSmacallan    if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1)
9098bb403aSmacallan	xf86Msg(X_ERROR, "FB_CUR_SETPOS failed\n");
9198bb403aSmacallan}
9298bb403aSmacallan
9398bb403aSmacallanstatic void
9498bb403aSmacallanAG10ESetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
9598bb403aSmacallan{
9698bb403aSmacallan    AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn);
9798bb403aSmacallan
9898bb403aSmacallan    pAG10E->Cursor.set = FB_CUR_SETCMAP;
9998bb403aSmacallan    pAG10E->Cursor.cmap.index = 0;
10098bb403aSmacallan    pAG10E->Cursor.cmap.count = 2;
10198bb403aSmacallan    pAG10E->Cursor.cmap.red[0] = (bg & 0xff0000) >> 16;
10298bb403aSmacallan    pAG10E->Cursor.cmap.green[0] = (bg & 0xff00) >> 8;
10398bb403aSmacallan    pAG10E->Cursor.cmap.blue[0] = bg & 0xff;
10498bb403aSmacallan    pAG10E->Cursor.cmap.red[1] = (fg & 0xff0000) >> 16;
10598bb403aSmacallan    pAG10E->Cursor.cmap.green[1] = (fg & 0xff00) >> 8;
10698bb403aSmacallan    pAG10E->Cursor.cmap.blue[1] = fg & 0xff;
10798bb403aSmacallan    if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1)
10898bb403aSmacallan	xf86Msg(X_ERROR, "FB_CUR_SETCMAP failed\n");
10998bb403aSmacallan}
11098bb403aSmacallan
11198bb403aSmacallanBool
11298bb403aSmacallanAG10EHWCursorInit(ScreenPtr pScreen)
11398bb403aSmacallan{
11498bb403aSmacallan    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
11598bb403aSmacallan    AG10EPtr pAG10E;
11698bb403aSmacallan    xf86CursorInfoPtr infoPtr;
11798bb403aSmacallan
11898bb403aSmacallan    pAG10E = GET_AG10E_FROM_SCRN(pScrn);
11998bb403aSmacallan
12098bb403aSmacallan    pAG10E->Cursor.mask = NULL;
12198bb403aSmacallan    pAG10E->Cursor.image = NULL;
12298bb403aSmacallan    if (ioctl(pAG10E->psdp->fd, FBIOGCURSOR, &pAG10E->Cursor) == -1) {
12398bb403aSmacallan    	xf86Msg(X_ERROR, "Hardware cursor isn't available\n");
12498bb403aSmacallan	return FALSE;
12598bb403aSmacallan    }
12698bb403aSmacallan
12798bb403aSmacallan    infoPtr = xf86CreateCursorInfoRec();
12898bb403aSmacallan    if(!infoPtr) return FALSE;
12998bb403aSmacallan
13098bb403aSmacallan    pAG10E->CursorInfoRec = infoPtr;
13198bb403aSmacallan
13298bb403aSmacallan    infoPtr->MaxWidth = 64;
13398bb403aSmacallan    infoPtr->MaxHeight = 64;
13498bb403aSmacallan
13598bb403aSmacallan    pAG10E->Cursor.hot.x = 0;
13698bb403aSmacallan    pAG10E->Cursor.hot.y = 0;
13798bb403aSmacallan    pAG10E->Cursor.set = FB_CUR_SETHOT;
13898bb403aSmacallan    ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor);
13998bb403aSmacallan
14098bb403aSmacallan    pAG10E->Cursor.cmap.red = pAG10E->pal;
14198bb403aSmacallan    pAG10E->Cursor.cmap.green = pAG10E->pal + 3;
14298bb403aSmacallan    pAG10E->Cursor.cmap.blue = pAG10E->pal + 6;
14398bb403aSmacallan
14498bb403aSmacallan    infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
14598bb403aSmacallan	HARDWARE_CURSOR_TRUECOLOR_AT_8BPP;
14698bb403aSmacallan
14798bb403aSmacallan    infoPtr->SetCursorColors = AG10ESetCursorColors;
14898bb403aSmacallan    infoPtr->SetCursorPosition = AG10ESetCursorPosition;
14998bb403aSmacallan    infoPtr->LoadCursorImage = AG10ELoadCursorImage;
15098bb403aSmacallan    infoPtr->HideCursor = AG10EHideCursor;
15198bb403aSmacallan    infoPtr->ShowCursor = AG10EShowCursor;
15298bb403aSmacallan    infoPtr->UseHWCursor = NULL;
15398bb403aSmacallan
15498bb403aSmacallan    return xf86InitCursor(pScreen, infoPtr);
15598bb403aSmacallan}
156