xref: /netbsd/sys/dev/pci/tga_conf.c (revision 6550d01e)
1 /* $NetBSD: tga_conf.c,v 1.7 2009/03/14 15:36:19 dsl Exp $ */
2 
3 /*
4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
9  * Permission to use, copy, modify and distribute this software and
10  * its documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29 
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: tga_conf.c,v 1.7 2009/03/14 15:36:19 dsl Exp $");
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 
37 #include <dev/pci/pcivar.h>
38 #include <dev/pci/tgareg.h>
39 #include <dev/pci/tgavar.h>
40 
41 #include <dev/ic/bt485var.h>
42 #include <dev/ic/bt463var.h>
43 #include <dev/ic/ibm561var.h>
44 
45 #undef KB
46 #define KB		* 1024
47 #undef MB
48 #define	MB		* 1024 * 1024
49 
50 static const struct tga_conf tga_configs[TGA_TYPE_UNKNOWN] = {
51 	/* TGA_TYPE_T8_01 */
52 	{
53 		"T8-01",
54 		bt485_funcs,
55 		8,
56 		4 MB,
57 		2 KB,
58 		1,	{  2 MB,     0 },	{ 1 MB,    0 },
59 		0,	{     0,     0 },	{    0,    0 },
60 	},
61 	/* TGA_TYPE_T8_02 */
62 	{
63 		"T8-02",
64 		bt485_funcs,
65 		8,
66 		4 MB,
67 		4 KB,
68 		1,	{  2 MB,     0 },	{ 2 MB,    0 },
69 		0,	{     0,     0 },	{    0,    0 },
70 	},
71 	/* TGA_TYPE_T8_22 */
72 	{
73 		"T8-22",
74 		bt485_funcs,
75 		8,
76 		8 MB,
77 		4 KB,
78 		1,	{  4 MB,     0 },	{ 2 MB,    0 },
79 		1,	{  6 MB,     0 },	{ 2 MB,    0 },
80 	},
81 	/* TGA_TYPE_T8_44 */
82 	{
83 		"T8-44",
84 		bt485_funcs,
85 		8,
86 		16 MB,
87 		4 KB,
88 		2,	{  8 MB, 12 MB },	{ 2 MB, 2 MB },
89 		2,	{ 10 MB, 14 MB },	{ 2 MB, 2 MB },
90 	},
91 	/* TGA_TYPE_T32_04 */
92 	{
93 		"T32-04",
94 		bt463_funcs,
95 		32,
96 		16 MB,
97 		8 KB,
98 		1,	{  8 MB,     0 },	{ 4 MB,    0 },
99 		0,	{     0,     0 },	{    0,    0 },
100 	},
101 	/* TGA_TYPE_T32_08 */
102 	{
103 		"T32-08",
104 		bt463_funcs,
105 		32,
106 		16 MB,
107 		16 KB,
108 		1,	{  8 MB,    0 },	{ 8 MB,    0 },
109 		0,	{     0,    0 },	{    0,    0 },
110 	},
111 	/* TGA_TYPE_T32_88 */
112 	{
113 		"T32-88",
114 		bt463_funcs,
115 		32,
116 		32 MB,
117 		16 KB,
118 		1,	{ 16 MB,    0 },	{ 8 MB,    0 },
119 		1,	{ 24 MB,    0 },	{ 8 MB,    0 },
120 	},
121 	/* TGA_TYPE_POWERSTORM_4D20 */
122 	/* XXX: These numbers may be incorrect */
123 	{
124 		"PS4d20",
125 		ibm561_funcs,
126 		32,
127 		32 MB,
128 		16 KB,
129 		1,	{ 16 MB,    0 },	{ 8 MB,    0 },
130 		1,	{ 24 MB,    0 },	{ 8 MB,    0 },
131 	}
132 };
133 
134 #undef KB
135 #undef MB
136 
137 int
138 tga_identify(struct tga_devconfig *dc)
139 {
140 	int type;
141 	int gder;
142 	int grev;
143 	int deep, addrmask, wide;
144 	int tga2;
145 
146 	gder = TGARREG(dc, TGA_REG_GDER);
147 	grev = TGARREG(dc, TGA_REG_GREV);
148 
149 	deep = (gder & 0x1) != 0; /* XXX */
150 	addrmask = (gder >> 2) & 0x7; /* XXX */
151 	wide = (gder & 0x200) == 0; /* XXX */
152 	tga2 = (grev & 0x20) != 0;
153 
154 	type = TGA_TYPE_UNKNOWN;
155 
156 	if (!deep) {
157 		/* 8bpp frame buffer */
158 
159 		if (addrmask == 0x0) {
160 			/* 4MB core map; T8-01 or T8-02 */
161 
162 			if (!wide)
163 				type = TGA_TYPE_T8_01;
164 			else
165 				type = TGA_TYPE_T8_02;
166 		} else if (addrmask == 0x1) {
167 			/* 8MB core map; T8-22 */
168 
169 			if (wide)			/* sanity */
170 				type = TGA_TYPE_T8_22;
171 		} else if (addrmask == 0x3) {
172 			/* 16MB core map; T8-44 */
173 
174 			if (wide)			/* sanity */
175 				type = TGA_TYPE_T8_44;
176 		}
177 	} else {
178 		/* 32bpp frame buffer */
179 		if (addrmask == 0x00 && tga2 && wide) {
180 			/* My PowerStorm 4d20 shows up this way? */
181 			type = TGA_TYPE_POWERSTORM_4D20;
182 		}
183 
184 		if (addrmask == 0x3) {
185 			/* 16MB core map; T32-04 or T32-08 */
186 
187 			if (!wide)
188 				type = TGA_TYPE_T32_04;
189 			else
190 				type = TGA_TYPE_T32_08;
191 		} else if (addrmask == 0x7) {
192 			/* 32MB core map; T32-88 */
193 
194 			if (wide && !tga2)			/* sanity */
195 				type = TGA_TYPE_T32_88;
196 		}
197 	}
198 
199 	return (type);
200 }
201 
202 const struct tga_conf *
203 tga_getconf(int type)
204 {
205 
206 	if (type >= 0 && type < TGA_TYPE_UNKNOWN)
207 		return &tga_configs[type];
208 
209 	return (NULL);
210 }
211