1 /* $NetBSD: pfour_subr.c,v 1.6 2008/04/28 20:23:58 martin Exp $ */
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
49 fb_setsize_pfour(struct fbdevice
*fb
)
52 volatile u_int32_t pfour
;
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
64 if (fb
->fb_pfour
== NULL
)
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
77 if ((PFOUR_ID(pfour
) == PFOUR_ID_COLOR24
) ||
78 (PFOUR_ID(pfour
) == PFOUR_ID_FASTCOLOR
))
81 switch (PFOUR_SIZE(pfour
)) {
82 case PFOUR_SIZE_1152X900
:
87 case PFOUR_SIZE_1024X1024
:
92 case PFOUR_SIZE_1280X1024
:
97 case PFOUR_SIZE_1600X1280
:
102 case PFOUR_SIZE_1440X1440
:
107 case PFOUR_SIZE_640X480
:
115 * Use the defaults already filled in by the generic fb code.
121 fb
->fb_type
.fb_width
= width
;
122 fb
->fb_type
.fb_height
= height
;
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
)
137 volatile u_int32_t val
, save
, *pfour
= va
;
139 /* Read the pfour register. */
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
) {
151 return (PFOUR_NOTPFOUR
);
154 return (PFOUR_ID(val
));
156 return (PFOUR_NOTPFOUR
);
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.
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);