xref: /netbsd-src/sys/arch/sun3/dev/fb.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: fb.c,v 1.3 1995/04/10 05:45:56 mycroft Exp $ */
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. All advertising materials mentioning features or use of this software
25  *    must display the following acknowledgement:
26  *	This product includes software developed by the University of
27  *	California, Berkeley and its contributors.
28  * 4. Neither the name of the University nor the names of its contributors
29  *    may be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  *	@(#)fb.c	8.1 (Berkeley) 6/11/93
45  */
46 
47 /*
48  * /dev/fb (indirect frame buffer driver).
49  */
50 
51 #include <sys/param.h>
52 #include <sys/conf.h>
53 #include <sys/device.h>
54 #include <sys/ioctl.h>
55 #include <sys/proc.h>
56 
57 #include <machine/fbio.h>
58 
59 #include "fbvar.h"
60 
61 static struct fbdevice *devfb;
62 static int fbpriority;
63 
64 /*
65  * This is called by the real driver (i.e. bw2, cg3, ...)
66  * to declare itself as a potential default frame buffer.
67  */
68 void
69 fb_attach(fb, newpri)
70 	struct fbdevice *fb;
71 	int newpri;
72 {
73 	if (fbpriority < newpri) {
74 		fbpriority = newpri;
75 		devfb = fb;
76 	}
77 }
78 
79 int
80 fbopen(dev, flags, mode, p)
81 	dev_t dev;
82 	int flags, mode;
83 	struct proc *p;
84 {
85 
86 	if (devfb == NULL)
87 		return (ENXIO);
88 	return ((*devfb->fb_driver->fbd_open)(dev, flags, mode, p));
89 }
90 
91 int
92 fbclose(dev, flags, mode, p)
93 	dev_t dev;
94 	int flags, mode;
95 	struct proc *p;
96 {
97 
98 	return ((*devfb->fb_driver->fbd_close)(dev, flags, mode, p));
99 }
100 
101 int
102 fbioctl(dev, cmd, data, flags, p)
103 	dev_t dev;
104 	u_long cmd;
105 	caddr_t data;
106 	int flags;
107 	struct proc *p;
108 {
109 	return (fbioctlfb(devfb, cmd, data));
110 }
111 
112 int
113 fbmmap(dev, off, prot)
114 	dev_t dev;
115 	int off, prot;
116 {
117 	return ((*devfb->fb_driver->fbd_mmap)(dev, off, prot));
118 }
119 
120 void
121 fb_unblank()
122 {
123 	int on = 1;
124 
125 	if (devfb) {
126 		(void) fbioctlfb(devfb, FBIOSVIDEO, (caddr_t)&on);
127 	}
128 }
129 
130 /*
131  * Common fb ioctl function
132  */
133 int
134 fbioctlfb(fb, cmd, data)
135 	struct fbdevice *fb;
136 	u_long cmd;
137 	caddr_t data;
138 {
139 	struct fbdriver *fbd = fb->fb_driver;
140 	int error;
141 
142 	switch (cmd) {
143 
144 	case FBIOGTYPE:
145 		*(struct fbtype *)data = fb->fb_fbtype;
146 		error = 0;
147 		break;
148 
149 	case FBIOGATTR:
150 		error = (*fbd->fbd_gattr)(fb, (struct fbgattr *)data);
151 		break;
152 
153 	case FBIOGVIDEO:
154 		error = (*fbd->fbd_gvideo)(fb, (int *)data);
155 		break;
156 
157 	case FBIOSVIDEO:
158 		error = (*fbd->fbd_svideo)(fb, (int *)data);
159 		break;
160 
161 	case FBIOGETCMAP:
162 		error = (*fbd->fbd_getcmap)(fb, (struct fbcmap *)data);
163 		break;
164 
165 	case FBIOPUTCMAP:
166 		error = (*fbd->fbd_putcmap)(fb, (struct fbcmap *)data);
167 		break;
168 
169 	default:
170 		error = ENOTTY;
171 	}
172 	return (error);
173 }
174