IBMramdac.c revision 1fb744b4
1/*
2 * Copyright 1998 by Alan Hourihane, Wigan, England.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Alan Hourihane not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  Alan Hourihane makes no representations
11 * about the suitability of this software for any purpose.  It is provided
12 * "as is" without express or implied warranty.
13 *
14 * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Authors:  Alan Hourihane, <alanh@fairlite.demon.co.uk>
23 *
24 * glintOutIBMRGBIndReg() and glintInIBMRGBIndReg() are used to access
25 * the indirect IBM RAMDAC registers only.
26 */
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include "xf86.h"
33#include "xf86_OSproc.h"
34
35#include "xf86Pci.h"
36
37#include "IBM.h"
38#include "glint_regs.h"
39#include "glint.h"
40
41#define IBMRGB_WRITE_ADDR           0x4000
42#define IBMRGB_RAMDAC_DATA          0x4008
43#define IBMRGB_PIXEL_MASK           0x4010
44#define IBMRGB_READ_ADDR            0x4018
45#define IBMRGB_INDEX_LOW            0x4020
46#define IBMRGB_INDEX_HIGH           0x4028
47#define IBMRGB_INDEX_DATA           0x4030
48#define IBMRGB_INDEX_CONTROL        0x4038
49
50void
51glintOutIBMRGBIndReg(ScrnInfoPtr pScrn,
52		     CARD32 reg, unsigned char mask, unsigned char data)
53{
54  GLINTPtr pGlint = GLINTPTR(pScrn);
55  unsigned char tmp = 0x00;
56
57  GLINT_SLOW_WRITE_REG((reg>>8) & 0xff, IBMRGB_INDEX_HIGH);
58  GLINT_SLOW_WRITE_REG (reg & 0xFF, IBMRGB_INDEX_LOW);
59
60  if (mask != 0x00)
61    tmp = GLINT_READ_REG (IBMRGB_INDEX_DATA) & mask;
62
63  GLINT_SLOW_WRITE_REG (tmp | data, IBMRGB_INDEX_DATA);
64}
65
66unsigned char
67glintInIBMRGBIndReg (ScrnInfoPtr pScrn, CARD32 reg)
68{
69  GLINTPtr pGlint = GLINTPTR(pScrn);
70  unsigned char ret;
71
72  GLINT_SLOW_WRITE_REG(reg & 0xFF, IBMRGB_INDEX_LOW);
73  GLINT_SLOW_WRITE_REG((reg>>8) & 0xff, IBMRGB_INDEX_HIGH);
74  ret = GLINT_READ_REG(IBMRGB_INDEX_DATA);
75  return (ret);
76}
77
78void
79glintIBMWriteAddress (ScrnInfoPtr pScrn, CARD32 index)
80{
81    GLINTPtr pGlint = GLINTPTR(pScrn);
82
83    GLINT_SLOW_WRITE_REG(index, IBMRGB_WRITE_ADDR);
84}
85
86void
87glintIBMWriteData (ScrnInfoPtr pScrn, unsigned char data)
88{
89    GLINTPtr pGlint = GLINTPTR(pScrn);
90
91    GLINT_SLOW_WRITE_REG(data, IBMRGB_RAMDAC_DATA);
92}
93
94void
95glintIBMReadAddress (ScrnInfoPtr pScrn, CARD32 index)
96{
97    GLINTPtr pGlint = GLINTPTR(pScrn);
98
99    GLINT_SLOW_WRITE_REG(0xFF, IBMRGB_PIXEL_MASK);
100    GLINT_SLOW_WRITE_REG(index, IBMRGB_READ_ADDR);
101}
102
103unsigned char
104glintIBMReadData (ScrnInfoPtr pScrn)
105{
106    GLINTPtr pGlint = GLINTPTR(pScrn);
107
108    return(GLINT_READ_REG(IBMRGB_RAMDAC_DATA));
109}
110
111Bool
112glintIBMHWCursorInit(ScreenPtr pScreen)
113{
114    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
115    GLINTPtr pGlint = GLINTPTR(pScrn);
116    xf86CursorInfoPtr infoPtr;
117
118    infoPtr = xf86CreateCursorInfoRec();
119    if(!infoPtr) return FALSE;
120
121    pGlint->CursorInfoRec = infoPtr;
122
123    (*pGlint->RamDac->HWCursorInit)(infoPtr);
124
125    return(xf86InitCursor(pScreen, infoPtr));
126}
127