1 /* $OpenBSD: bt_subr.c,v 1.9 2003/06/02 23:27:53 millert Exp $ */
2 /* $NetBSD: bt_subr.c,v 1.5 1996/03/14 19:44:32 christos Exp $ */
3
4 /*
5 * Copyright (c) 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This software was developed by the Computer Systems Engineering group
9 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10 * contributed to Berkeley.
11 *
12 * All advertising materials mentioning features or use of this software
13 * must display the following acknowledgement:
14 * This product includes software developed by the University of
15 * California, Lawrence Berkeley Laboratory.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 * SUCH DAMAGE.
40 *
41 * @(#)bt_subr.c 8.2 (Berkeley) 1/21/94
42 */
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/buf.h>
47 #include <sys/errno.h>
48
49 #include <uvm/uvm_extern.h>
50
51 #include <dev/wscons/wsconsio.h>
52
53 #include <sparc/dev/btreg.h>
54 #include <sparc/dev/btvar.h>
55
56 /*
57 * Common code for dealing with Brooktree video DACs.
58 */
59
60 int
bt_getcmap(bcm,rcm)61 bt_getcmap(bcm, rcm)
62 union bt_cmap *bcm;
63 struct wsdisplay_cmap *rcm;
64 {
65 u_int index = rcm->index, count = rcm->count, i;
66 int error;
67
68 if (index >= 256 || count > 256 - index)
69 return (EINVAL);
70 for (i = 0; i < count; i++) {
71 if ((error = copyout(&bcm->cm_map[index + i][0],
72 &rcm->red[i], 1)) != 0)
73 return (error);
74 if ((error = copyout(&bcm->cm_map[index + i][1],
75 &rcm->green[i], 1)) != 0)
76 return (error);
77 if ((error = copyout(&bcm->cm_map[index + i][2],
78 &rcm->blue[i], 1)) != 0)
79 return (error);
80 }
81 return (0);
82 }
83
84 int
bt_putcmap(bcm,rcm)85 bt_putcmap(bcm, rcm)
86 union bt_cmap *bcm;
87 struct wsdisplay_cmap *rcm;
88 {
89 u_int index = rcm->index, count = rcm->count, i;
90 int error;
91
92 if (index >= 256 || count > 256 - index)
93 return (EINVAL);
94 for (i = 0; i < count; i++) {
95 if ((error = copyin(&rcm->red[i],
96 &bcm->cm_map[index + i][0], 1)) != 0)
97 return (error);
98 if ((error = copyin(&rcm->green[i],
99 &bcm->cm_map[index + i][1], 1)) != 0)
100 return (error);
101 if ((error = copyin(&rcm->blue[i],
102 &bcm->cm_map[index + i][2], 1)) != 0)
103 return (error);
104 }
105 return (0);
106 }
107
108 void
bt_loadcmap(cm,bt,start,ncolors,cgsix)109 bt_loadcmap(cm, bt, start, ncolors, cgsix)
110 union bt_cmap *cm;
111 volatile struct bt_regs *bt;
112 u_int start, ncolors;
113 int cgsix;
114 {
115 u_int *ip, i;
116 int count;
117
118 ip = &cm->cm_chip[BT_D4M3(start)]; /* start/4 * 3 */
119 count = BT_D4M3(start + ncolors - 1) - BT_D4M3(start) + 3;
120
121 if (cgsix) {
122 /* hardware that makes one want to pound boards with hammers */
123 bt->bt_addr = BT_D4M4(start) << 24;
124 while (--count >= 0) {
125 i = *ip++;
126 bt->bt_cmap = i;
127 bt->bt_cmap = i << 8;
128 bt->bt_cmap = i << 16;
129 bt->bt_cmap = i << 24;
130 }
131 } else {
132 bt->bt_addr = BT_D4M4(start);
133 while (--count >= 0)
134 bt->bt_cmap = *ip++;
135 }
136 }
137
138 void
bt_setcolor(cm,bt,index,r,g,b,cgsix)139 bt_setcolor(cm, bt, index, r, g, b, cgsix)
140 union bt_cmap *cm;
141 volatile struct bt_regs *bt;
142 u_int index;
143 u_int8_t r, g, b;
144 int cgsix;
145 {
146
147 cm->cm_map[index][0] = r;
148 cm->cm_map[index][1] = g;
149 cm->cm_map[index][2] = b;
150 bt_loadcmap(cm, bt, index, 1, cgsix);
151 }
152