Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / dev / sun / pfour_subr.c
blob1ad5365f1d7f9939ec8c31716e97a02e3b0a3810
1 /* $NetBSD: pfour_subr.c,v 1.6 2008/04/28 20:23:58 martin Exp $ */
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Paul Kranenburg.
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.
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.
33 * Support routines for pfour framebuffers.
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: pfour_subr.c,v 1.6 2008/04/28 20:23:58 martin Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
44 #include <dev/sun/pfourreg.h>
45 #include <dev/sun/fbio.h>
46 #include <dev/sun/fbvar.h>
48 void
49 fb_setsize_pfour(struct fbdevice *fb)
51 #if defined(SUN4)
52 volatile u_int32_t pfour;
53 int width, height;
56 * Some pfour framebuffers, e.g. the
57 * cgsix, don't encode resolution the
58 * same, so the driver handles that.
59 * The driver can let us know that it
60 * needs to do this by not mapping in
61 * the pfour register by the time this
62 * routine is called.
64 if (fb->fb_pfour == NULL)
65 return;
67 pfour = *fb->fb_pfour;
70 * Use the pfour register to determine
71 * the size. Note that the cgsix and
72 * cgeight don't use this size encoding.
73 * In this case, we have to settle
74 * for the defaults we were provided
75 * with.
77 if ((PFOUR_ID(pfour) == PFOUR_ID_COLOR24) ||
78 (PFOUR_ID(pfour) == PFOUR_ID_FASTCOLOR))
79 return;
81 switch (PFOUR_SIZE(pfour)) {
82 case PFOUR_SIZE_1152X900:
83 width = 1152;
84 height = 900;
85 break;
87 case PFOUR_SIZE_1024X1024:
88 width = 1024;
89 height = 1024;
90 break;
92 case PFOUR_SIZE_1280X1024:
93 width = 1280;
94 height = 1024;
95 break;
97 case PFOUR_SIZE_1600X1280:
98 width = 1600;
99 height = 1280;
100 break;
102 case PFOUR_SIZE_1440X1440:
103 width = 1440;
104 height = 1440;
105 break;
107 case PFOUR_SIZE_640X480:
108 width = 640;
109 height = 480;
110 break;
112 default:
115 * Use the defaults already filled in by the generic fb code.
118 return;
121 fb->fb_type.fb_width = width;
122 fb->fb_type.fb_height = height;
123 #endif /* SUN4 */
128 * Probe for a pfour framebuffer. Return values:
130 * PFOUR_NOTPFOUR: framebuffer is not a pfour framebuffer
131 * otherwise returns pfour ID
134 fb_pfour_id(volatile void *va)
136 #if defined(SUN4)
137 volatile u_int32_t val, save, *pfour = va;
139 /* Read the pfour register. */
140 save = *pfour;
143 * Try to modify the type code. If it changes, put the
144 * original value back, and notify the caller that it's
145 * not a pfour framebuffer.
147 val = save & ~PFOUR_REG_RESET;
148 *pfour = (val ^ PFOUR_FBTYPE_MASK);
149 if ((*pfour ^ val) & PFOUR_FBTYPE_MASK) {
150 *pfour = save;
151 return (PFOUR_NOTPFOUR);
154 return (PFOUR_ID(val));
155 #else
156 return (PFOUR_NOTPFOUR);
157 #endif /* SUN4 */
161 * Return the status of the video enable.
164 fb_pfour_get_video(struct fbdevice *fb)
167 return ((*fb->fb_pfour & PFOUR_REG_VIDEO) != 0);
171 * Enable or disable the framebuffer.
173 void
174 fb_pfour_set_video(struct fbdevice *fb, int enable)
176 volatile u_int32_t pfour;
178 pfour = *fb->fb_pfour & ~(PFOUR_REG_INTCLR|PFOUR_REG_VIDEO);
179 *fb->fb_pfour = pfour | (enable ? PFOUR_REG_VIDEO : 0);