xref: /netbsd/sys/dev/sun/pfour_subr.c (revision bf9ec67e)
1 /*	$NetBSD: pfour_subr.c,v 1.2 2001/11/13 06:54:32 lukem Exp $ */
2 
3 /*-
4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Support routines for pfour framebuffers.
41  */
42 
43 
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: pfour_subr.c,v 1.2 2001/11/13 06:54:32 lukem Exp $");
46 
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/device.h>
50 
51 #include <dev/sun/pfourreg.h>
52 #include <dev/sun/fbio.h>
53 #include <dev/sun/fbvar.h>
54 
55 void
56 fb_setsize_pfour(fb)
57 	struct fbdevice *fb;
58 {
59 #if defined(SUN4)
60 	volatile u_int32_t pfour;
61 	int width, height;
62 
63 	/*
64 	 * Some pfour framebuffers, e.g. the
65 	 * cgsix, don't encode resolution the
66 	 * same, so the driver handles that.
67 	 * The driver can let us know that it
68 	 * needs to do this by not mapping in
69 	 * the pfour register by the time this
70 	 * routine is called.
71 	 */
72 	if (fb->fb_pfour == NULL)
73 		return;
74 
75 	pfour = *fb->fb_pfour;
76 
77 	/*
78 	 * Use the pfour register to determine
79 	 * the size.  Note that the cgsix and
80 	 * cgeight don't use this size encoding.
81 	 * In this case, we have to settle
82 	 * for the defaults we were provided
83 	 * with.
84 	 */
85 	if ((PFOUR_ID(pfour) == PFOUR_ID_COLOR24) ||
86 	    (PFOUR_ID(pfour) == PFOUR_ID_FASTCOLOR))
87 		return;
88 
89 	switch (PFOUR_SIZE(pfour)) {
90 	case PFOUR_SIZE_1152X900:
91 		width = 1152;
92 		height = 900;
93 		break;
94 
95 	case PFOUR_SIZE_1024X1024:
96 		width = 1024;
97 		height = 1024;
98 		break;
99 
100 	case PFOUR_SIZE_1280X1024:
101 		width = 1280;
102 		height = 1024;
103 		break;
104 
105 	case PFOUR_SIZE_1600X1280:
106 		width = 1600;
107 		height = 1280;
108 		break;
109 
110 	case PFOUR_SIZE_1440X1440:
111 		width = 1440;
112 		height = 1440;
113 		break;
114 
115 	case PFOUR_SIZE_640X480:
116 		width = 640;
117 		height = 480;
118 		break;
119 
120 	default:
121 		/*
122 		 * XXX: Do nothing, I guess.
123 		 * Should we print a warning about
124 		 * an unknown value? --thorpej
125 		 */
126 		break;
127 	}
128 
129 	fb->fb_type.fb_width = width;
130 	fb->fb_type.fb_height = height;
131 #endif /* SUN4 */
132 }
133 
134 
135 /*
136  * Probe for a pfour framebuffer.  Return values:
137  *
138  *	PFOUR_NOTPFOUR: framebuffer is not a pfour framebuffer
139  *	otherwise returns pfour ID
140  */
141 int
142 fb_pfour_id(va)
143 	volatile void *va;
144 {
145 #if defined(SUN4)
146 	volatile u_int32_t val, save, *pfour = va;
147 
148 	/* Read the pfour register. */
149 	save = *pfour;
150 
151 	/*
152 	 * Try to modify the type code.  If it changes, put the
153 	 * original value back, and notify the caller that it's
154 	 * not a pfour framebuffer.
155 	 */
156 	val = save & ~PFOUR_REG_RESET;
157 	*pfour = (val ^ PFOUR_FBTYPE_MASK);
158 	if ((*pfour ^ val) & PFOUR_FBTYPE_MASK) {
159 		*pfour = save;
160 		return (PFOUR_NOTPFOUR);
161 	}
162 
163 	return (PFOUR_ID(val));
164 #else
165 	return (PFOUR_NOTPFOUR);
166 #endif /* SUN4 */
167 }
168 
169 /*
170  * Return the status of the video enable.
171  */
172 int
173 fb_pfour_get_video(fb)
174 	struct fbdevice *fb;
175 {
176 
177 	return ((*fb->fb_pfour & PFOUR_REG_VIDEO) != 0);
178 }
179 
180 /*
181  * Enable or disable the framebuffer.
182  */
183 void
184 fb_pfour_set_video(fb, enable)
185 	struct fbdevice *fb;
186 	int enable;
187 {
188 	volatile u_int32_t pfour;
189 
190 	pfour = *fb->fb_pfour & ~(PFOUR_REG_INTCLR|PFOUR_REG_VIDEO);
191 	*fb->fb_pfour = pfour | (enable ? PFOUR_REG_VIDEO : 0);
192 }
193