xref: /netbsd-src/sys/dev/sun/pfour_subr.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: pfour_subr.c,v 1.6 2008/04/28 20:23:58 martin 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Support routines for pfour framebuffers.
34  */
35 
36 
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: pfour_subr.c,v 1.6 2008/04/28 20:23:58 martin Exp $");
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 
44 #include <dev/sun/pfourreg.h>
45 #include <dev/sun/fbio.h>
46 #include <dev/sun/fbvar.h>
47 
48 void
49 fb_setsize_pfour(fb)
50 	struct fbdevice *fb;
51 {
52 #if defined(SUN4)
53 	volatile u_int32_t pfour;
54 	int width, height;
55 
56 	/*
57 	 * Some pfour framebuffers, e.g. the
58 	 * cgsix, don't encode resolution the
59 	 * same, so the driver handles that.
60 	 * The driver can let us know that it
61 	 * needs to do this by not mapping in
62 	 * the pfour register by the time this
63 	 * routine is called.
64 	 */
65 	if (fb->fb_pfour == NULL)
66 		return;
67 
68 	pfour = *fb->fb_pfour;
69 
70 	/*
71 	 * Use the pfour register to determine
72 	 * the size.  Note that the cgsix and
73 	 * cgeight don't use this size encoding.
74 	 * In this case, we have to settle
75 	 * for the defaults we were provided
76 	 * with.
77 	 */
78 	if ((PFOUR_ID(pfour) == PFOUR_ID_COLOR24) ||
79 	    (PFOUR_ID(pfour) == PFOUR_ID_FASTCOLOR))
80 		return;
81 
82 	switch (PFOUR_SIZE(pfour)) {
83 	case PFOUR_SIZE_1152X900:
84 		width = 1152;
85 		height = 900;
86 		break;
87 
88 	case PFOUR_SIZE_1024X1024:
89 		width = 1024;
90 		height = 1024;
91 		break;
92 
93 	case PFOUR_SIZE_1280X1024:
94 		width = 1280;
95 		height = 1024;
96 		break;
97 
98 	case PFOUR_SIZE_1600X1280:
99 		width = 1600;
100 		height = 1280;
101 		break;
102 
103 	case PFOUR_SIZE_1440X1440:
104 		width = 1440;
105 		height = 1440;
106 		break;
107 
108 	case PFOUR_SIZE_640X480:
109 		width = 640;
110 		height = 480;
111 		break;
112 
113 	default:
114 
115 		/*
116 		 * Use the defaults already filled in by the generic fb code.
117 		 */
118 
119 		return;
120 	}
121 
122 	fb->fb_type.fb_width = width;
123 	fb->fb_type.fb_height = height;
124 #endif /* SUN4 */
125 }
126 
127 
128 /*
129  * Probe for a pfour framebuffer.  Return values:
130  *
131  *	PFOUR_NOTPFOUR: framebuffer is not a pfour framebuffer
132  *	otherwise returns pfour ID
133  */
134 int
135 fb_pfour_id(va)
136 	volatile void *va;
137 {
138 #if defined(SUN4)
139 	volatile u_int32_t val, save, *pfour = va;
140 
141 	/* Read the pfour register. */
142 	save = *pfour;
143 
144 	/*
145 	 * Try to modify the type code.  If it changes, put the
146 	 * original value back, and notify the caller that it's
147 	 * not a pfour framebuffer.
148 	 */
149 	val = save & ~PFOUR_REG_RESET;
150 	*pfour = (val ^ PFOUR_FBTYPE_MASK);
151 	if ((*pfour ^ val) & PFOUR_FBTYPE_MASK) {
152 		*pfour = save;
153 		return (PFOUR_NOTPFOUR);
154 	}
155 
156 	return (PFOUR_ID(val));
157 #else
158 	return (PFOUR_NOTPFOUR);
159 #endif /* SUN4 */
160 }
161 
162 /*
163  * Return the status of the video enable.
164  */
165 int
166 fb_pfour_get_video(fb)
167 	struct fbdevice *fb;
168 {
169 
170 	return ((*fb->fb_pfour & PFOUR_REG_VIDEO) != 0);
171 }
172 
173 /*
174  * Enable or disable the framebuffer.
175  */
176 void
177 fb_pfour_set_video(fb, enable)
178 	struct fbdevice *fb;
179 	int enable;
180 {
181 	volatile u_int32_t pfour;
182 
183 	pfour = *fb->fb_pfour & ~(PFOUR_REG_INTCLR|PFOUR_REG_VIDEO);
184 	*fb->fb_pfour = pfour | (enable ? PFOUR_REG_VIDEO : 0);
185 }
186