1c35d236eSmrg/* 2c35d236eSmrg * Copyright 1998 by Alan Hourihane, Wigan, England. 3c35d236eSmrg * 4c35d236eSmrg * Permission to use, copy, modify, distribute, and sell this software and its 5c35d236eSmrg * documentation for any purpose is hereby granted without fee, provided that 6c35d236eSmrg * the above copyright notice appear in all copies and that both that 7c35d236eSmrg * copyright notice and this permission notice appear in supporting 8c35d236eSmrg * documentation, and that the name of Alan Hourihane not be used in 9c35d236eSmrg * advertising or publicity pertaining to distribution of the software without 10c35d236eSmrg * specific, written prior permission. Alan Hourihane makes no representations 11c35d236eSmrg * about the suitability of this software for any purpose. It is provided 12c35d236eSmrg * "as is" without express or implied warranty. 13c35d236eSmrg * 14c35d236eSmrg * ALAN HOURIHANE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15c35d236eSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16c35d236eSmrg * EVENT SHALL ALAN HOURIHANE BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17c35d236eSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18c35d236eSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19c35d236eSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20c35d236eSmrg * PERFORMANCE OF THIS SOFTWARE. 21c35d236eSmrg * 22c35d236eSmrg * Authors: Alan Hourihane, <alanh@fairlite.demon.co.uk> 23c35d236eSmrg * 24c35d236eSmrg * Permedia2OutIndReg() and Permedia2InIndReg() are used to access 25c35d236eSmrg * the indirect Permedia2 RAMDAC registers only. 26c35d236eSmrg */ 27c35d236eSmrg 28c35d236eSmrg#ifdef HAVE_CONFIG_H 29c35d236eSmrg#include "config.h" 30c35d236eSmrg#endif 31c35d236eSmrg 32c35d236eSmrg#include "xf86.h" 33c35d236eSmrg#include "xf86_OSproc.h" 34c35d236eSmrg 35c35d236eSmrg#include "xf86Pci.h" 36c35d236eSmrg 37c35d236eSmrg#include "glint_regs.h" 38c35d236eSmrg#include "glint.h" 39c35d236eSmrg 40c35d236eSmrgvoid 41c35d236eSmrgPermedia2OutIndReg(ScrnInfoPtr pScrn, 42c35d236eSmrg CARD32 reg, unsigned char mask, unsigned char data) 43c35d236eSmrg{ 44c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 45c35d236eSmrg unsigned char tmp = 0x00; 46c35d236eSmrg 47c35d236eSmrg GLINT_SLOW_WRITE_REG (reg, PM2DACIndexReg); 48c35d236eSmrg 49c35d236eSmrg if (mask != 0x00) 50c35d236eSmrg tmp = GLINT_READ_REG (PM2DACIndexData) & mask; 51c35d236eSmrg 52c35d236eSmrg GLINT_SLOW_WRITE_REG (tmp | data, PM2DACIndexData); 53c35d236eSmrg} 54c35d236eSmrg 55c35d236eSmrgunsigned char 56c35d236eSmrgPermedia2InIndReg (ScrnInfoPtr pScrn, CARD32 reg) 57c35d236eSmrg{ 58c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 59c35d236eSmrg unsigned char ret; 60c35d236eSmrg 61c35d236eSmrg GLINT_SLOW_WRITE_REG (reg, PM2DACIndexReg); 62c35d236eSmrg GLINTDACDelay(5); 63c35d236eSmrg ret = GLINT_READ_REG (PM2DACIndexData); 64c35d236eSmrg 65c35d236eSmrg return (ret); 66c35d236eSmrg} 67c35d236eSmrg 68c35d236eSmrgvoid 69c35d236eSmrgPermedia2WriteAddress (ScrnInfoPtr pScrn, CARD32 index) 70c35d236eSmrg{ 71c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 72c35d236eSmrg 73c35d236eSmrg GLINT_SLOW_WRITE_REG(index, PM2DACWriteAddress); 74c35d236eSmrg} 75c35d236eSmrg 76c35d236eSmrgvoid 77c35d236eSmrgPermedia2WriteData (ScrnInfoPtr pScrn, unsigned char data) 78c35d236eSmrg{ 79c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 80c35d236eSmrg 81c35d236eSmrg GLINT_SLOW_WRITE_REG(data, PM2DACData); 82c35d236eSmrg} 83c35d236eSmrg 84c35d236eSmrgvoid 85c35d236eSmrgPermedia2ReadAddress (ScrnInfoPtr pScrn, CARD32 index) 86c35d236eSmrg{ 87c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 88c35d236eSmrg 89c35d236eSmrg GLINT_SLOW_WRITE_REG(0xFF, PM2DACReadMask); 90c35d236eSmrg GLINT_SLOW_WRITE_REG(index, PM2DACReadAddress); 91c35d236eSmrg} 92c35d236eSmrg 93c35d236eSmrgunsigned char 94c35d236eSmrgPermedia2ReadData (ScrnInfoPtr pScrn) 95c35d236eSmrg{ 96c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 97c35d236eSmrg GLINTDACDelay(5); 98c35d236eSmrg return(GLINT_READ_REG(PM2DACData)); 99c35d236eSmrg} 100c35d236eSmrg 101c35d236eSmrgvoid Permedia2LoadPalette( 102c35d236eSmrg ScrnInfoPtr pScrn, 103c35d236eSmrg int numColors, 104c35d236eSmrg int *indices, 105c35d236eSmrg LOCO *colors, 106c35d236eSmrg VisualPtr pVisual 107c35d236eSmrg){ 108c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 109c35d236eSmrg int i, index, shift = 0, j, repeat = 1; 110c35d236eSmrg 111c35d236eSmrg if (pScrn->depth == 15) { 112c35d236eSmrg repeat = 8; 113c35d236eSmrg shift = 3; 114c35d236eSmrg } 115c35d236eSmrg 116c35d236eSmrg for(i = 0; i < numColors; i++) { 117c35d236eSmrg index = indices[i]; 118c35d236eSmrg for (j = 0; j < repeat; j++) { 119c35d236eSmrg Permedia2WriteAddress(pScrn, (index << shift)+j); 120c35d236eSmrg Permedia2WriteData(pScrn, colors[index].red); 121c35d236eSmrg Permedia2WriteData(pScrn, colors[index].green); 122c35d236eSmrg Permedia2WriteData(pScrn, colors[index].blue); 123c35d236eSmrg } 124c35d236eSmrg /* for video i/o */ 125c35d236eSmrg GLINT_SLOW_WRITE_REG(index, TexelLUTIndex); 126c35d236eSmrg GLINT_SLOW_WRITE_REG((colors[index].red & 0xFF) | 127c35d236eSmrg ((colors[index].green & 0xFF) << 8) | 128c35d236eSmrg ((colors[index].blue & 0xFF) << 16), 129c35d236eSmrg TexelLUTData); 130c35d236eSmrg } 131c35d236eSmrg} 132c35d236eSmrg 133c35d236eSmrg/* special one for 565 mode */ 134c35d236eSmrgvoid Permedia2LoadPalette16( 135c35d236eSmrg ScrnInfoPtr pScrn, 136c35d236eSmrg int numColors, 137c35d236eSmrg int *indices, 138c35d236eSmrg LOCO *colors, 139c35d236eSmrg VisualPtr pVisual 140c35d236eSmrg){ 141c35d236eSmrg GLINTPtr pGlint = GLINTPTR(pScrn); 142c35d236eSmrg int i, index, j; 143c35d236eSmrg 144c35d236eSmrg for(i = 0; i < numColors; i++) { 145c35d236eSmrg index = indices[i]; 146c35d236eSmrg for (j = 0; j < 4; j++) { 147c35d236eSmrg Permedia2WriteAddress(pScrn, (index << 2)+j); 148c35d236eSmrg Permedia2WriteData(pScrn, colors[index >> 1].red); 149c35d236eSmrg Permedia2WriteData(pScrn, colors[index].green); 150c35d236eSmrg Permedia2WriteData(pScrn, colors[index >> 1].blue); 151c35d236eSmrg } 152c35d236eSmrg GLINT_SLOW_WRITE_REG(index, TexelLUTIndex); 153c35d236eSmrg GLINT_SLOW_WRITE_REG((colors[index].red & 0xFF) | 154c35d236eSmrg ((colors[index].green & 0xFF) << 8) | 155c35d236eSmrg ((colors[index].blue & 0xFF) << 16), 156c35d236eSmrg TexelLUTData); 157c35d236eSmrg 158c35d236eSmrg if(index <= 31) { 159c35d236eSmrg for (j = 0; j < 4; j++) { 160c35d236eSmrg Permedia2WriteAddress(pScrn, (index << 3)+j); 161c35d236eSmrg Permedia2WriteData(pScrn, colors[index].red); 162c35d236eSmrg Permedia2WriteData(pScrn, colors[(index << 1) + 1].green); 163c35d236eSmrg Permedia2WriteData(pScrn, colors[index].blue); 164c35d236eSmrg } 165c35d236eSmrg } 166c35d236eSmrg } 167c35d236eSmrg} 168