Home | History | Annotate | Line # | Download | only in sun
pfour_subr.c revision 1.1
      1 /*	$NetBSD: pfour_subr.c,v 1.1 2000/08/22 21:18:14 pk 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/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/device.h>
     47 
     48 #include <dev/sun/pfourreg.h>
     49 #include <dev/sun/fbio.h>
     50 #include <dev/sun/fbvar.h>
     51 
     52 void
     53 fb_setsize_pfour(fb)
     54 	struct fbdevice *fb;
     55 {
     56 #if defined(SUN4)
     57 	volatile u_int32_t pfour;
     58 	int width, height;
     59 
     60 	/*
     61 	 * Some pfour framebuffers, e.g. the
     62 	 * cgsix, don't encode resolution the
     63 	 * same, so the driver handles that.
     64 	 * The driver can let us know that it
     65 	 * needs to do this by not mapping in
     66 	 * the pfour register by the time this
     67 	 * routine is called.
     68 	 */
     69 	if (fb->fb_pfour == NULL)
     70 		return;
     71 
     72 	pfour = *fb->fb_pfour;
     73 
     74 	/*
     75 	 * Use the pfour register to determine
     76 	 * the size.  Note that the cgsix and
     77 	 * cgeight don't use this size encoding.
     78 	 * In this case, we have to settle
     79 	 * for the defaults we were provided
     80 	 * with.
     81 	 */
     82 	if ((PFOUR_ID(pfour) == PFOUR_ID_COLOR24) ||
     83 	    (PFOUR_ID(pfour) == PFOUR_ID_FASTCOLOR))
     84 		return;
     85 
     86 	switch (PFOUR_SIZE(pfour)) {
     87 	case PFOUR_SIZE_1152X900:
     88 		width = 1152;
     89 		height = 900;
     90 		break;
     91 
     92 	case PFOUR_SIZE_1024X1024:
     93 		width = 1024;
     94 		height = 1024;
     95 		break;
     96 
     97 	case PFOUR_SIZE_1280X1024:
     98 		width = 1280;
     99 		height = 1024;
    100 		break;
    101 
    102 	case PFOUR_SIZE_1600X1280:
    103 		width = 1600;
    104 		height = 1280;
    105 		break;
    106 
    107 	case PFOUR_SIZE_1440X1440:
    108 		width = 1440;
    109 		height = 1440;
    110 		break;
    111 
    112 	case PFOUR_SIZE_640X480:
    113 		width = 640;
    114 		height = 480;
    115 		break;
    116 
    117 	default:
    118 		/*
    119 		 * XXX: Do nothing, I guess.
    120 		 * Should we print a warning about
    121 		 * an unknown value? --thorpej
    122 		 */
    123 		break;
    124 	}
    125 
    126 	fb->fb_type.fb_width = width;
    127 	fb->fb_type.fb_height = height;
    128 #endif /* SUN4 */
    129 }
    130 
    131 
    132 /*
    133  * Probe for a pfour framebuffer.  Return values:
    134  *
    135  *	PFOUR_NOTPFOUR: framebuffer is not a pfour framebuffer
    136  *	otherwise returns pfour ID
    137  */
    138 int
    139 fb_pfour_id(va)
    140 	volatile void *va;
    141 {
    142 #if defined(SUN4)
    143 	volatile u_int32_t val, save, *pfour = va;
    144 
    145 	/* Read the pfour register. */
    146 	save = *pfour;
    147 
    148 	/*
    149 	 * Try to modify the type code.  If it changes, put the
    150 	 * original value back, and notify the caller that it's
    151 	 * not a pfour framebuffer.
    152 	 */
    153 	val = save & ~PFOUR_REG_RESET;
    154 	*pfour = (val ^ PFOUR_FBTYPE_MASK);
    155 	if ((*pfour ^ val) & PFOUR_FBTYPE_MASK) {
    156 		*pfour = save;
    157 		return (PFOUR_NOTPFOUR);
    158 	}
    159 
    160 	return (PFOUR_ID(val));
    161 #else
    162 	return (PFOUR_NOTPFOUR);
    163 #endif /* SUN4 */
    164 }
    165 
    166 /*
    167  * Return the status of the video enable.
    168  */
    169 int
    170 fb_pfour_get_video(fb)
    171 	struct fbdevice *fb;
    172 {
    173 
    174 	return ((*fb->fb_pfour & PFOUR_REG_VIDEO) != 0);
    175 }
    176 
    177 /*
    178  * Enable or disable the framebuffer.
    179  */
    180 void
    181 fb_pfour_set_video(fb, enable)
    182 	struct fbdevice *fb;
    183 	int enable;
    184 {
    185 	volatile u_int32_t pfour;
    186 
    187 	pfour = *fb->fb_pfour & ~(PFOUR_REG_INTCLR|PFOUR_REG_VIDEO);
    188 	*fb->fb_pfour = pfour | (enable ? PFOUR_REG_VIDEO : 0);
    189 }
    190