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