pfour_subr.c revision 1.3 1 /* $NetBSD: pfour_subr.c,v 1.3 2003/10/28 15:25:27 chs 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.3 2003/10/28 15:25:27 chs 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 /*
123 * Assume the smallest size.
124 */
125
126 width = 640;
127 height = 480;
128 break;
129 }
130
131 fb->fb_type.fb_width = width;
132 fb->fb_type.fb_height = height;
133 #endif /* SUN4 */
134 }
135
136
137 /*
138 * Probe for a pfour framebuffer. Return values:
139 *
140 * PFOUR_NOTPFOUR: framebuffer is not a pfour framebuffer
141 * otherwise returns pfour ID
142 */
143 int
144 fb_pfour_id(va)
145 volatile void *va;
146 {
147 #if defined(SUN4)
148 volatile u_int32_t val, save, *pfour = va;
149
150 /* Read the pfour register. */
151 save = *pfour;
152
153 /*
154 * Try to modify the type code. If it changes, put the
155 * original value back, and notify the caller that it's
156 * not a pfour framebuffer.
157 */
158 val = save & ~PFOUR_REG_RESET;
159 *pfour = (val ^ PFOUR_FBTYPE_MASK);
160 if ((*pfour ^ val) & PFOUR_FBTYPE_MASK) {
161 *pfour = save;
162 return (PFOUR_NOTPFOUR);
163 }
164
165 return (PFOUR_ID(val));
166 #else
167 return (PFOUR_NOTPFOUR);
168 #endif /* SUN4 */
169 }
170
171 /*
172 * Return the status of the video enable.
173 */
174 int
175 fb_pfour_get_video(fb)
176 struct fbdevice *fb;
177 {
178
179 return ((*fb->fb_pfour & PFOUR_REG_VIDEO) != 0);
180 }
181
182 /*
183 * Enable or disable the framebuffer.
184 */
185 void
186 fb_pfour_set_video(fb, enable)
187 struct fbdevice *fb;
188 int enable;
189 {
190 volatile u_int32_t pfour;
191
192 pfour = *fb->fb_pfour & ~(PFOUR_REG_INTCLR|PFOUR_REG_VIDEO);
193 *fb->fb_pfour = pfour | (enable ? PFOUR_REG_VIDEO : 0);
194 }
195