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> 31898e129cSchristos#include <sys/ioctl.h> 3298bb403aSmacallan#include <dev/sun/fbio.h> 3398bb403aSmacallan#include <dev/wscons/wsconsio.h> 3498bb403aSmacallan 3598bb403aSmacallan#include "ag10e.h" 3698bb403aSmacallan 3798bb403aSmacallanstatic void AG10ELoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src); 3898bb403aSmacallanstatic void AG10EShowCursor(ScrnInfoPtr pScrn); 3998bb403aSmacallanstatic void AG10EHideCursor(ScrnInfoPtr pScrn); 4098bb403aSmacallanstatic void AG10ESetCursorPosition(ScrnInfoPtr pScrn, int x, int y); 4198bb403aSmacallanstatic void AG10ESetCursorColors(ScrnInfoPtr pScrn, int bg, int fg); 4298bb403aSmacallan 4398bb403aSmacallanstatic void 4498bb403aSmacallanAG10ELoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src) 4598bb403aSmacallan{ 4698bb403aSmacallan AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 4798bb403aSmacallan 4898bb403aSmacallan pAG10E->Cursor.set = FB_CUR_SETSHAPE; 4998bb403aSmacallan pAG10E->Cursor.image = src; 5098bb403aSmacallan pAG10E->Cursor.mask = src + 0x200; 5198bb403aSmacallan 5298bb403aSmacallan if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 5398bb403aSmacallan xf86Msg(X_ERROR, "FB_CUR_SETSHAPE failed\n"); 5498bb403aSmacallan} 5598bb403aSmacallan 5698bb403aSmacallanvoid 5798bb403aSmacallanAG10EShowCursor(ScrnInfoPtr pScrn) 5898bb403aSmacallan{ 5998bb403aSmacallan AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 6098bb403aSmacallan 6198bb403aSmacallan if (pAG10E->Cursor.enable == 0) { 6298bb403aSmacallan pAG10E->Cursor.enable = 1; 6398bb403aSmacallan pAG10E->Cursor.set = FB_CUR_SETCUR; 6498bb403aSmacallan if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 6598bb403aSmacallan xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n"); 6698bb403aSmacallan } 6798bb403aSmacallan} 6898bb403aSmacallan 6998bb403aSmacallanvoid 7098bb403aSmacallanAG10EHideCursor(ScrnInfoPtr pScrn) 7198bb403aSmacallan{ 7298bb403aSmacallan AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 7398bb403aSmacallan 7498bb403aSmacallan if (pAG10E->Cursor.enable == 1) { 7598bb403aSmacallan pAG10E->Cursor.enable = 0; 7698bb403aSmacallan pAG10E->Cursor.set = FB_CUR_SETCUR; 7798bb403aSmacallan if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 7898bb403aSmacallan xf86Msg(X_ERROR, "FB_CUR_SETCUR failed\n"); 7998bb403aSmacallan } 8098bb403aSmacallan} 8198bb403aSmacallan 8298bb403aSmacallanstatic void 8398bb403aSmacallanAG10ESetCursorPosition(ScrnInfoPtr pScrn, int x, int y) 8498bb403aSmacallan{ 8598bb403aSmacallan AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 8698bb403aSmacallan 8798bb403aSmacallan pAG10E->Cursor.pos.x = x; 8898bb403aSmacallan pAG10E->Cursor.pos.y = y; 8998bb403aSmacallan pAG10E->Cursor.set = FB_CUR_SETPOS; 9098bb403aSmacallan if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 9198bb403aSmacallan xf86Msg(X_ERROR, "FB_CUR_SETPOS failed\n"); 9298bb403aSmacallan} 9398bb403aSmacallan 9498bb403aSmacallanstatic void 9598bb403aSmacallanAG10ESetCursorColors(ScrnInfoPtr pScrn, int bg, int fg) 9698bb403aSmacallan{ 9798bb403aSmacallan AG10EPtr pAG10E = GET_AG10E_FROM_SCRN(pScrn); 9898bb403aSmacallan 9998bb403aSmacallan pAG10E->Cursor.set = FB_CUR_SETCMAP; 10098bb403aSmacallan pAG10E->Cursor.cmap.index = 0; 10198bb403aSmacallan pAG10E->Cursor.cmap.count = 2; 10298bb403aSmacallan pAG10E->Cursor.cmap.red[0] = (bg & 0xff0000) >> 16; 10398bb403aSmacallan pAG10E->Cursor.cmap.green[0] = (bg & 0xff00) >> 8; 10498bb403aSmacallan pAG10E->Cursor.cmap.blue[0] = bg & 0xff; 10598bb403aSmacallan pAG10E->Cursor.cmap.red[1] = (fg & 0xff0000) >> 16; 10698bb403aSmacallan pAG10E->Cursor.cmap.green[1] = (fg & 0xff00) >> 8; 10798bb403aSmacallan pAG10E->Cursor.cmap.blue[1] = fg & 0xff; 10898bb403aSmacallan if (ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor) == -1) 10998bb403aSmacallan xf86Msg(X_ERROR, "FB_CUR_SETCMAP failed\n"); 11098bb403aSmacallan} 11198bb403aSmacallan 11298bb403aSmacallanBool 11398bb403aSmacallanAG10EHWCursorInit(ScreenPtr pScreen) 11498bb403aSmacallan{ 11598bb403aSmacallan ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; 11698bb403aSmacallan AG10EPtr pAG10E; 11798bb403aSmacallan xf86CursorInfoPtr infoPtr; 11898bb403aSmacallan 11998bb403aSmacallan pAG10E = GET_AG10E_FROM_SCRN(pScrn); 12098bb403aSmacallan 12198bb403aSmacallan pAG10E->Cursor.mask = NULL; 12298bb403aSmacallan pAG10E->Cursor.image = NULL; 12398bb403aSmacallan if (ioctl(pAG10E->psdp->fd, FBIOGCURSOR, &pAG10E->Cursor) == -1) { 12498bb403aSmacallan xf86Msg(X_ERROR, "Hardware cursor isn't available\n"); 12598bb403aSmacallan return FALSE; 12698bb403aSmacallan } 12798bb403aSmacallan 12898bb403aSmacallan infoPtr = xf86CreateCursorInfoRec(); 12998bb403aSmacallan if(!infoPtr) return FALSE; 13098bb403aSmacallan 13198bb403aSmacallan pAG10E->CursorInfoRec = infoPtr; 13298bb403aSmacallan 13398bb403aSmacallan infoPtr->MaxWidth = 64; 13498bb403aSmacallan infoPtr->MaxHeight = 64; 13598bb403aSmacallan 13698bb403aSmacallan pAG10E->Cursor.hot.x = 0; 13798bb403aSmacallan pAG10E->Cursor.hot.y = 0; 13898bb403aSmacallan pAG10E->Cursor.set = FB_CUR_SETHOT; 13998bb403aSmacallan ioctl(pAG10E->psdp->fd, FBIOSCURSOR, &pAG10E->Cursor); 14098bb403aSmacallan 14198bb403aSmacallan pAG10E->Cursor.cmap.red = pAG10E->pal; 14298bb403aSmacallan pAG10E->Cursor.cmap.green = pAG10E->pal + 3; 14398bb403aSmacallan pAG10E->Cursor.cmap.blue = pAG10E->pal + 6; 14498bb403aSmacallan 14598bb403aSmacallan infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK | 14698bb403aSmacallan HARDWARE_CURSOR_TRUECOLOR_AT_8BPP; 14798bb403aSmacallan 14898bb403aSmacallan infoPtr->SetCursorColors = AG10ESetCursorColors; 14998bb403aSmacallan infoPtr->SetCursorPosition = AG10ESetCursorPosition; 15098bb403aSmacallan infoPtr->LoadCursorImage = AG10ELoadCursorImage; 15198bb403aSmacallan infoPtr->HideCursor = AG10EHideCursor; 15298bb403aSmacallan infoPtr->ShowCursor = AG10EShowCursor; 15398bb403aSmacallan infoPtr->UseHWCursor = NULL; 15498bb403aSmacallan 15598bb403aSmacallan return xf86InitCursor(pScreen, infoPtr); 15698bb403aSmacallan} 157