pm2ramdac.c revision c35d236e
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 * Permedia2OutIndReg() and Permedia2InIndReg() are used to access
25 * the indirect Permedia2 RAMDAC registers only.
26 */
27/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/glint/pm2ramdac.c,v 1.10 1999/07/18 03:26:57 dawes Exp $ */
28
29#ifdef HAVE_CONFIG_H
30#include "config.h"
31#endif
32
33#include "xf86.h"
34#include "xf86_OSproc.h"
35
36#include "xf86PciInfo.h"
37#include "xf86Pci.h"
38
39#include "glint_regs.h"
40#include "glint.h"
41
42void
43Permedia2OutIndReg(ScrnInfoPtr pScrn,
44		     CARD32 reg, unsigned char mask, unsigned char data)
45{
46  GLINTPtr pGlint = GLINTPTR(pScrn);
47  unsigned char tmp = 0x00;
48
49  GLINT_SLOW_WRITE_REG (reg, PM2DACIndexReg);
50
51  if (mask != 0x00)
52    tmp = GLINT_READ_REG (PM2DACIndexData) & mask;
53
54  GLINT_SLOW_WRITE_REG (tmp | data, PM2DACIndexData);
55}
56
57unsigned char
58Permedia2InIndReg (ScrnInfoPtr pScrn, CARD32 reg)
59{
60  GLINTPtr pGlint = GLINTPTR(pScrn);
61  unsigned char ret;
62
63  GLINT_SLOW_WRITE_REG (reg, PM2DACIndexReg);
64  GLINTDACDelay(5);
65  ret = GLINT_READ_REG (PM2DACIndexData);
66
67  return (ret);
68}
69
70void
71Permedia2WriteAddress (ScrnInfoPtr pScrn, CARD32 index)
72{
73    GLINTPtr pGlint = GLINTPTR(pScrn);
74
75    GLINT_SLOW_WRITE_REG(index, PM2DACWriteAddress);
76}
77
78void
79Permedia2WriteData (ScrnInfoPtr pScrn, unsigned char data)
80{
81    GLINTPtr pGlint = GLINTPTR(pScrn);
82
83    GLINT_SLOW_WRITE_REG(data, PM2DACData);
84}
85
86void
87Permedia2ReadAddress (ScrnInfoPtr pScrn, CARD32 index)
88{
89    GLINTPtr pGlint = GLINTPTR(pScrn);
90
91    GLINT_SLOW_WRITE_REG(0xFF, PM2DACReadMask);
92    GLINT_SLOW_WRITE_REG(index, PM2DACReadAddress);
93}
94
95unsigned char
96Permedia2ReadData (ScrnInfoPtr pScrn)
97{
98    GLINTPtr pGlint = GLINTPTR(pScrn);
99    GLINTDACDelay(5);
100    return(GLINT_READ_REG(PM2DACData));
101}
102
103void Permedia2LoadPalette(
104    ScrnInfoPtr pScrn,
105    int numColors,
106    int *indices,
107    LOCO *colors,
108    VisualPtr pVisual
109){
110    GLINTPtr pGlint = GLINTPTR(pScrn);
111    int i, index, shift = 0, j, repeat = 1;
112
113    if (pScrn->depth == 15) {
114	repeat = 8;
115	shift = 3;
116    }
117
118    for(i = 0; i < numColors; i++) {
119	index = indices[i];
120	for (j = 0; j < repeat; j++) {
121	    Permedia2WriteAddress(pScrn, (index << shift)+j);
122	    Permedia2WriteData(pScrn, colors[index].red);
123	    Permedia2WriteData(pScrn, colors[index].green);
124	    Permedia2WriteData(pScrn, colors[index].blue);
125	}
126	/* for video i/o */
127        GLINT_SLOW_WRITE_REG(index, TexelLUTIndex);
128	GLINT_SLOW_WRITE_REG((colors[index].red & 0xFF) |
129			     ((colors[index].green & 0xFF) << 8) |
130			     ((colors[index].blue & 0xFF) << 16),
131			     TexelLUTData);
132    }
133}
134
135/* special one for 565 mode */
136void Permedia2LoadPalette16(
137    ScrnInfoPtr pScrn,
138    int numColors,
139    int *indices,
140    LOCO *colors,
141    VisualPtr pVisual
142){
143    GLINTPtr pGlint = GLINTPTR(pScrn);
144    int i, index, j;
145
146    for(i = 0; i < numColors; i++) {
147	index = indices[i];
148	for (j = 0; j < 4; j++) {
149	    Permedia2WriteAddress(pScrn, (index << 2)+j);
150	    Permedia2WriteData(pScrn, colors[index >> 1].red);
151	    Permedia2WriteData(pScrn, colors[index].green);
152	    Permedia2WriteData(pScrn, colors[index >> 1].blue);
153	}
154        GLINT_SLOW_WRITE_REG(index, TexelLUTIndex);
155	GLINT_SLOW_WRITE_REG((colors[index].red & 0xFF) |
156			     ((colors[index].green & 0xFF) << 8) |
157			     ((colors[index].blue & 0xFF) << 16),
158			     TexelLUTData);
159
160	if(index <= 31) {
161	    for (j = 0; j < 4; j++) {
162	    	Permedia2WriteAddress(pScrn, (index << 3)+j);
163	    	Permedia2WriteData(pScrn, colors[index].red);
164	    	Permedia2WriteData(pScrn, colors[(index << 1) + 1].green);
165	    	Permedia2WriteData(pScrn, colors[index].blue);
166	    }
167	}
168    }
169}
170