bt485.c revision 1.17 1 1.17 riastrad /* $NetBSD: bt485.c,v 1.17 2013/06/24 03:57:36 riastradh Exp $ */
2 1.1 elric
3 1.1 elric /*
4 1.1 elric * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 elric * All rights reserved.
6 1.1 elric *
7 1.1 elric * Author: Chris G. Demetriou
8 1.1 elric *
9 1.1 elric * Permission to use, copy, modify and distribute this software and
10 1.1 elric * its documentation is hereby granted, provided that both the copyright
11 1.1 elric * notice and this permission notice appear in all copies of the
12 1.1 elric * software, derivative works or modified versions, and any portions
13 1.1 elric * thereof, and that both notices appear in supporting documentation.
14 1.1 elric *
15 1.1 elric * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 elric * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 elric * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 elric *
19 1.1 elric * Carnegie Mellon requests users of this software to return to
20 1.1 elric *
21 1.1 elric * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 elric * School of Computer Science
23 1.1 elric * Carnegie Mellon University
24 1.1 elric * Pittsburgh PA 15213-3890
25 1.1 elric *
26 1.1 elric * any improvements or extensions that they make and grant Carnegie the
27 1.1 elric * rights to redistribute these changes.
28 1.1 elric */
29 1.1 elric
30 1.1 elric /* This code was derived from and originally located in sys/dev/pci/
31 1.12 perry * NetBSD: tga_bt485.c,v 1.4 1999/03/24 05:51:21 mrg Exp
32 1.1 elric */
33 1.7 lukem
34 1.7 lukem #include <sys/cdefs.h>
35 1.17 riastrad __KERNEL_RCSID(0, "$NetBSD: bt485.c,v 1.17 2013/06/24 03:57:36 riastradh Exp $");
36 1.1 elric
37 1.1 elric #include <sys/param.h>
38 1.1 elric #include <sys/systm.h>
39 1.1 elric #include <sys/device.h>
40 1.1 elric #include <sys/buf.h>
41 1.1 elric #include <sys/kernel.h>
42 1.1 elric #include <sys/malloc.h>
43 1.3 mrg
44 1.1 elric #include <dev/pci/pcivar.h>
45 1.1 elric #include <dev/ic/bt485reg.h>
46 1.1 elric #include <dev/ic/bt485var.h>
47 1.1 elric #include <dev/ic/ramdac.h>
48 1.1 elric
49 1.1 elric #include <dev/wscons/wsconsio.h>
50 1.1 elric
51 1.1 elric /*
52 1.1 elric * Functions exported via the RAMDAC configuration table.
53 1.1 elric */
54 1.11 perry void bt485_init(struct ramdac_cookie *);
55 1.11 perry int bt485_set_cmap(struct ramdac_cookie *, struct wsdisplay_cmap *);
56 1.11 perry int bt485_get_cmap(struct ramdac_cookie *, struct wsdisplay_cmap *);
57 1.11 perry int bt485_set_cursor(struct ramdac_cookie *, struct wsdisplay_cursor *);
58 1.11 perry int bt485_get_cursor(struct ramdac_cookie *, struct wsdisplay_cursor *);
59 1.11 perry int bt485_set_curpos(struct ramdac_cookie *, struct wsdisplay_curpos *);
60 1.11 perry int bt485_get_curpos(struct ramdac_cookie *, struct wsdisplay_curpos *);
61 1.11 perry int bt485_get_curmax(struct ramdac_cookie *, struct wsdisplay_curpos *);
62 1.1 elric
63 1.1 elric /* XXX const */
64 1.1 elric struct ramdac_funcs bt485_funcsstruct = {
65 1.1 elric "Bt485",
66 1.2 nathanw bt485_register,
67 1.1 elric bt485_init,
68 1.1 elric bt485_set_cmap,
69 1.1 elric bt485_get_cmap,
70 1.1 elric bt485_set_cursor,
71 1.1 elric bt485_get_cursor,
72 1.1 elric bt485_set_curpos,
73 1.1 elric bt485_get_curpos,
74 1.1 elric bt485_get_curmax,
75 1.1 elric NULL, /* check_curcmap; not needed */
76 1.1 elric NULL, /* set_curcmap; not needed */
77 1.1 elric NULL, /* get_curcmap; not needed */
78 1.8 elric NULL, /* no dot clock to set */
79 1.1 elric };
80 1.1 elric
81 1.1 elric /*
82 1.1 elric * Private data.
83 1.1 elric */
84 1.1 elric struct bt485data {
85 1.1 elric void *cookie; /* This is what is passed
86 1.1 elric * around, and is probably
87 1.1 elric * struct tga_devconfig *
88 1.1 elric */
89 1.12 perry
90 1.11 perry int (*ramdac_sched_update)(void *, void (*)(void *));
91 1.11 perry void (*ramdac_wr)(void *, u_int, u_int8_t);
92 1.11 perry u_int8_t (*ramdac_rd)(void *, u_int);
93 1.1 elric
94 1.1 elric int changed; /* what changed; see below */
95 1.1 elric int curenb; /* cursor enabled */
96 1.1 elric struct wsdisplay_curpos curpos; /* current cursor position */
97 1.1 elric struct wsdisplay_curpos curhot; /* cursor hotspot */
98 1.1 elric char curcmap_r[2]; /* cursor colormap */
99 1.1 elric char curcmap_g[2];
100 1.1 elric char curcmap_b[2];
101 1.1 elric struct wsdisplay_curpos cursize; /* current cursor size */
102 1.1 elric char curimage[512]; /* cursor image data */
103 1.1 elric char curmask[512]; /* cursor mask data */
104 1.1 elric char cmap_r[256]; /* colormap */
105 1.1 elric char cmap_g[256];
106 1.1 elric char cmap_b[256];
107 1.1 elric };
108 1.1 elric
109 1.1 elric #define DATA_ENB_CHANGED 0x01 /* cursor enable changed */
110 1.1 elric #define DATA_CURCMAP_CHANGED 0x02 /* cursor colormap changed */
111 1.1 elric #define DATA_CURSHAPE_CHANGED 0x04 /* cursor size, image, mask changed */
112 1.1 elric #define DATA_CMAP_CHANGED 0x08 /* colormap changed */
113 1.1 elric #define DATA_ALL_CHANGED 0x0f
114 1.1 elric
115 1.1 elric #define CURSOR_MAX_SIZE 64
116 1.1 elric
117 1.1 elric /*
118 1.1 elric * Internal functions.
119 1.1 elric */
120 1.17 riastrad
121 1.11 perry void bt485_update(void *);
122 1.11 perry void bt485_update_curpos(struct bt485data *);
123 1.1 elric
124 1.17 riastrad static inline void
125 1.17 riastrad bt485_wr_i(struct bt485data *data, u_int8_t ireg, u_int8_t val)
126 1.17 riastrad {
127 1.17 riastrad data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, ireg);
128 1.17 riastrad data->ramdac_wr(data->cookie, BT485_REG_EXTENDED, val);
129 1.17 riastrad }
130 1.17 riastrad
131 1.17 riastrad static inline u_int8_t
132 1.17 riastrad bt485_rd_i(struct bt485data *data, u_int8_t ireg)
133 1.17 riastrad {
134 1.17 riastrad data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, ireg);
135 1.17 riastrad return (data->ramdac_rd(data->cookie, BT485_REG_EXTENDED));
136 1.17 riastrad }
137 1.17 riastrad
138 1.1 elric /*****************************************************************************/
139 1.1 elric
140 1.1 elric /*
141 1.1 elric * Functions exported via the RAMDAC configuration table.
142 1.1 elric */
143 1.1 elric
144 1.1 elric struct ramdac_funcs *
145 1.1 elric bt485_funcs(void)
146 1.1 elric {
147 1.1 elric return &bt485_funcsstruct;
148 1.1 elric }
149 1.1 elric
150 1.1 elric struct ramdac_cookie *
151 1.16 matt bt485_register(
152 1.16 matt void *v,
153 1.16 matt int (*sched_update)(void *, void (*)(void *)),
154 1.16 matt void (*wr)(void *, u_int, u_int8_t),
155 1.16 matt u_int8_t (*rd)(void *, u_int))
156 1.1 elric {
157 1.1 elric struct bt485data *data;
158 1.1 elric /*
159 1.1 elric * XXX -- comment out of date. rcd.
160 1.1 elric * If we should allocate a new private info struct, do so.
161 1.1 elric * Otherwise, use the one we have (if it's there), or
162 1.1 elric * use the temporary one on the stack.
163 1.1 elric */
164 1.1 elric data = malloc(sizeof *data, M_DEVBUF, M_WAITOK);
165 1.1 elric /* XXX -- if !data */
166 1.1 elric data->cookie = v;
167 1.1 elric data->ramdac_sched_update = sched_update;
168 1.1 elric data->ramdac_wr = wr;
169 1.1 elric data->ramdac_rd = rd;
170 1.1 elric return (struct ramdac_cookie *)data;
171 1.1 elric }
172 1.1 elric
173 1.1 elric /*
174 1.1 elric * This function exists solely to provide a means to init
175 1.1 elric * the RAMDAC without first registering. It is useful for
176 1.1 elric * initializing the console early on.
177 1.1 elric */
178 1.1 elric void
179 1.16 matt bt485_cninit(
180 1.16 matt void *v,
181 1.16 matt int (*sched_update)(void *, void (*)(void *)),
182 1.16 matt void (*wr)(void *, u_int, u_int8_t),
183 1.16 matt u_int8_t (*rd)(void *, u_int))
184 1.1 elric {
185 1.1 elric struct bt485data tmp, *data = &tmp;
186 1.1 elric data->cookie = v;
187 1.1 elric data->ramdac_sched_update = sched_update;
188 1.1 elric data->ramdac_wr = wr;
189 1.1 elric data->ramdac_rd = rd;
190 1.1 elric bt485_init((struct ramdac_cookie *)data);
191 1.1 elric }
192 1.1 elric
193 1.1 elric void
194 1.14 dsl bt485_init(struct ramdac_cookie *rc)
195 1.1 elric {
196 1.1 elric u_int8_t regval;
197 1.1 elric struct bt485data *data = (struct bt485data *)rc;
198 1.1 elric int i;
199 1.1 elric
200 1.1 elric /*
201 1.1 elric * Init the BT485 for normal operation.
202 1.1 elric */
203 1.1 elric
204 1.1 elric /*
205 1.1 elric * Allow indirect register access. (Actually, this is
206 1.1 elric * already enabled. In fact, if it is _disabled_, for
207 1.1 elric * some reason the monitor appears to lose sync!!! (?!?!)
208 1.1 elric */
209 1.1 elric regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_0);
210 1.1 elric regval |= 0x80;
211 1.1 elric /*
212 1.1 elric * Set the RAMDAC to 8 bit resolution, rather than 6 bit
213 1.1 elric * resolution.
214 1.1 elric */
215 1.1 elric regval |= 0x02;
216 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COMMAND_0, regval);
217 1.1 elric
218 1.1 elric /* Set the RAMDAC to 8BPP (no interestion options). */
219 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COMMAND_1, 0x40);
220 1.1 elric
221 1.1 elric /* Disable the cursor (for now) */
222 1.1 elric regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_2);
223 1.1 elric regval &= ~0x03;
224 1.1 elric regval |= 0x24;
225 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COMMAND_2, regval);
226 1.1 elric
227 1.1 elric /* Use a 64x64x2 cursor */
228 1.1 elric regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
229 1.1 elric regval |= 0x04;
230 1.1 elric regval |= 0x08;
231 1.1 elric bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
232 1.1 elric
233 1.1 elric /* Set the Pixel Mask to something useful */
234 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PIXMASK, 0xff);
235 1.1 elric
236 1.1 elric /*
237 1.6 wiz * Initialize the RAMDAC info struct to hold all of our
238 1.1 elric * data, and fill it in.
239 1.1 elric */
240 1.1 elric data->changed = DATA_ALL_CHANGED;
241 1.1 elric
242 1.1 elric data->curenb = 0; /* cursor disabled */
243 1.1 elric data->curpos.x = data->curpos.y = 0; /* right now at 0,0 */
244 1.1 elric data->curhot.x = data->curhot.y = 0; /* hot spot at 0,0 */
245 1.1 elric
246 1.1 elric /* initial cursor colormap: 0 is black, 1 is white */
247 1.1 elric data->curcmap_r[0] = data->curcmap_g[0] = data->curcmap_b[0] = 0;
248 1.1 elric data->curcmap_r[1] = data->curcmap_g[1] = data->curcmap_b[1] = 0xff;
249 1.1 elric
250 1.1 elric /* initial cursor data: 64x64 block of white. */
251 1.1 elric data->cursize.x = data->cursize.y = 64;
252 1.1 elric for (i = 0; i < 512; i++)
253 1.1 elric data->curimage[i] = data->curmask[i] = 0xff;
254 1.1 elric
255 1.1 elric /* Initial colormap: 0 is black, everything else is white */
256 1.1 elric data->cmap_r[0] = data->cmap_g[0] = data->cmap_b[0] = 0;
257 1.1 elric for (i = 1; i < 256; i++)
258 1.1 elric data->cmap_r[i] = data->cmap_g[i] = data->cmap_b[i] = 255;
259 1.1 elric
260 1.1 elric bt485_update((void *)data);
261 1.1 elric }
262 1.1 elric
263 1.1 elric int
264 1.14 dsl bt485_set_cmap(struct ramdac_cookie *rc, struct wsdisplay_cmap *cmapp)
265 1.1 elric {
266 1.1 elric struct bt485data *data = (struct bt485data *)rc;
267 1.5 jdolecek u_int count, index;
268 1.10 chs uint8_t r[256], g[256], b[256];
269 1.10 chs int s, error;
270 1.1 elric
271 1.9 itojun if (cmapp->index >= 256 || cmapp->count > 256 - cmapp->index)
272 1.1 elric return (EINVAL);
273 1.1 elric
274 1.1 elric index = cmapp->index;
275 1.1 elric count = cmapp->count;
276 1.10 chs error = copyin(cmapp->red, &r[index], count);
277 1.10 chs if (error)
278 1.10 chs return error;
279 1.10 chs error = copyin(cmapp->green, &g[index], count);
280 1.10 chs if (error)
281 1.10 chs return error;
282 1.10 chs error = copyin(cmapp->blue, &b[index], count);
283 1.10 chs if (error)
284 1.10 chs return error;
285 1.10 chs s = spltty();
286 1.10 chs memcpy(&data->cmap_r[index], &r[index], count);
287 1.10 chs memcpy(&data->cmap_g[index], &g[index], count);
288 1.10 chs memcpy(&data->cmap_b[index], &b[index], count);
289 1.1 elric data->changed |= DATA_CMAP_CHANGED;
290 1.1 elric data->ramdac_sched_update(data->cookie, bt485_update);
291 1.1 elric splx(s);
292 1.1 elric return (0);
293 1.1 elric }
294 1.1 elric
295 1.1 elric int
296 1.14 dsl bt485_get_cmap(struct ramdac_cookie *rc, struct wsdisplay_cmap *cmapp)
297 1.1 elric {
298 1.1 elric struct bt485data *data = (struct bt485data *)rc;
299 1.9 itojun u_int count, index;
300 1.9 itojun int error;
301 1.1 elric
302 1.9 itojun if (cmapp->index >= 256 || cmapp->count > 256 - cmapp->index )
303 1.1 elric return (EINVAL);
304 1.1 elric
305 1.1 elric count = cmapp->count;
306 1.1 elric index = cmapp->index;
307 1.1 elric error = copyout(&data->cmap_r[index], cmapp->red, count);
308 1.1 elric if (error)
309 1.1 elric return (error);
310 1.1 elric error = copyout(&data->cmap_g[index], cmapp->green, count);
311 1.1 elric if (error)
312 1.1 elric return (error);
313 1.1 elric error = copyout(&data->cmap_b[index], cmapp->blue, count);
314 1.1 elric return (error);
315 1.1 elric }
316 1.1 elric
317 1.1 elric int
318 1.14 dsl bt485_set_cursor(struct ramdac_cookie *rc, struct wsdisplay_cursor *cursorp)
319 1.1 elric {
320 1.1 elric struct bt485data *data = (struct bt485data *)rc;
321 1.10 chs u_int count = 0, icount = 0, index = 0, v;
322 1.10 chs char r[2], g[2], b[2], image[512], mask[512];
323 1.10 chs int s, error;
324 1.1 elric
325 1.1 elric v = cursorp->which;
326 1.1 elric
327 1.1 elric /*
328 1.10 chs * For DOCMAP and DOSHAPE, copy in the new data
329 1.1 elric * before we do anything that we can't recover from.
330 1.1 elric */
331 1.1 elric if (v & WSDISPLAY_CURSOR_DOCMAP) {
332 1.5 jdolecek if (cursorp->cmap.index > 2 ||
333 1.5 jdolecek (cursorp->cmap.index + cursorp->cmap.count) > 2)
334 1.1 elric return (EINVAL);
335 1.1 elric count = cursorp->cmap.count;
336 1.10 chs index = cursorp->cmap.index;
337 1.10 chs error = copyin(cursorp->cmap.red, &r[index], count);
338 1.10 chs if (error)
339 1.10 chs return error;
340 1.10 chs error = copyin(cursorp->cmap.green, &g[index], count);
341 1.10 chs if (error)
342 1.10 chs return error;
343 1.10 chs error = copyin(cursorp->cmap.blue, &b[index], count);
344 1.10 chs if (error)
345 1.10 chs return error;
346 1.1 elric }
347 1.1 elric if (v & WSDISPLAY_CURSOR_DOSHAPE) {
348 1.5 jdolecek if (cursorp->size.x > CURSOR_MAX_SIZE ||
349 1.5 jdolecek cursorp->size.y > CURSOR_MAX_SIZE)
350 1.1 elric return (EINVAL);
351 1.10 chs icount = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
352 1.10 chs error = copyin(cursorp->image, image, icount);
353 1.10 chs if (error)
354 1.10 chs return error;
355 1.10 chs error = copyin(cursorp->mask, mask, icount);
356 1.10 chs if (error)
357 1.10 chs return error;
358 1.1 elric }
359 1.1 elric
360 1.1 elric if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOCUR)) {
361 1.1 elric if (v & WSDISPLAY_CURSOR_DOPOS)
362 1.1 elric data->curpos = cursorp->pos;
363 1.1 elric if (v & WSDISPLAY_CURSOR_DOCUR)
364 1.1 elric data->curhot = cursorp->hot;
365 1.1 elric bt485_update_curpos(data);
366 1.1 elric }
367 1.1 elric
368 1.1 elric s = spltty();
369 1.1 elric
370 1.10 chs /* Data is all available; perform the requested operations. */
371 1.1 elric if (v & WSDISPLAY_CURSOR_DOCUR) {
372 1.1 elric data->curenb = cursorp->enable;
373 1.1 elric data->changed |= DATA_ENB_CHANGED;
374 1.1 elric }
375 1.1 elric if (v & WSDISPLAY_CURSOR_DOCMAP) {
376 1.10 chs memcpy(&data->curcmap_r[index], &r[index], count);
377 1.10 chs memcpy(&data->curcmap_g[index], &g[index], count);
378 1.10 chs memcpy(&data->curcmap_b[index], &b[index], count);
379 1.1 elric data->changed |= DATA_CURCMAP_CHANGED;
380 1.1 elric }
381 1.1 elric if (v & WSDISPLAY_CURSOR_DOSHAPE) {
382 1.1 elric data->cursize = cursorp->size;
383 1.1 elric count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
384 1.4 thorpej memset(data->curimage, 0, sizeof data->curimage);
385 1.4 thorpej memset(data->curmask, 0, sizeof data->curmask);
386 1.10 chs memcpy(data->curimage, image, icount);
387 1.10 chs memcpy(data->curmask, mask, icount);
388 1.1 elric data->changed |= DATA_CURSHAPE_CHANGED;
389 1.1 elric }
390 1.1 elric
391 1.1 elric if (data->changed)
392 1.1 elric data->ramdac_sched_update(data->cookie, bt485_update);
393 1.1 elric splx(s);
394 1.1 elric
395 1.1 elric return (0);
396 1.1 elric }
397 1.1 elric
398 1.1 elric int
399 1.14 dsl bt485_get_cursor(struct ramdac_cookie *rc, struct wsdisplay_cursor *cursorp)
400 1.1 elric {
401 1.1 elric struct bt485data *data = (struct bt485data *)rc;
402 1.1 elric int error, count;
403 1.1 elric
404 1.1 elric /* we return everything they want */
405 1.1 elric cursorp->which = WSDISPLAY_CURSOR_DOALL;
406 1.1 elric
407 1.1 elric cursorp->enable = data->curenb; /* DOCUR */
408 1.1 elric cursorp->pos = data->curpos; /* DOPOS */
409 1.1 elric cursorp->hot = data->curhot; /* DOHOT */
410 1.1 elric
411 1.1 elric cursorp->cmap.index = 0; /* DOCMAP */
412 1.1 elric cursorp->cmap.count = 2;
413 1.1 elric if (cursorp->cmap.red != NULL) {
414 1.1 elric error = copyout(data->curcmap_r, cursorp->cmap.red, 2);
415 1.1 elric if (error)
416 1.1 elric return (error);
417 1.1 elric }
418 1.1 elric if (cursorp->cmap.green != NULL) {
419 1.1 elric error = copyout(data->curcmap_g, cursorp->cmap.green, 2);
420 1.1 elric if (error)
421 1.1 elric return (error);
422 1.1 elric }
423 1.1 elric if (cursorp->cmap.blue != NULL) {
424 1.1 elric error = copyout(data->curcmap_b, cursorp->cmap.blue, 2);
425 1.1 elric if (error)
426 1.1 elric return (error);
427 1.1 elric }
428 1.1 elric
429 1.1 elric cursorp->size = data->cursize; /* DOSHAPE */
430 1.1 elric if (cursorp->image != NULL) {
431 1.1 elric count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
432 1.1 elric error = copyout(data->curimage, cursorp->image, count);
433 1.1 elric if (error)
434 1.1 elric return (error);
435 1.1 elric error = copyout(data->curmask, cursorp->mask, count);
436 1.1 elric if (error)
437 1.1 elric return (error);
438 1.1 elric }
439 1.1 elric
440 1.1 elric return (0);
441 1.1 elric }
442 1.1 elric
443 1.1 elric int
444 1.14 dsl bt485_set_curpos(struct ramdac_cookie *rc, struct wsdisplay_curpos *curposp)
445 1.1 elric {
446 1.1 elric struct bt485data *data = (struct bt485data *)rc;
447 1.1 elric
448 1.1 elric data->curpos = *curposp;
449 1.1 elric bt485_update_curpos(data);
450 1.1 elric
451 1.1 elric return (0);
452 1.1 elric }
453 1.1 elric
454 1.1 elric int
455 1.14 dsl bt485_get_curpos(struct ramdac_cookie *rc, struct wsdisplay_curpos *curposp)
456 1.1 elric {
457 1.1 elric struct bt485data *data = (struct bt485data *)rc;
458 1.1 elric
459 1.1 elric *curposp = data->curpos;
460 1.1 elric return (0);
461 1.1 elric }
462 1.1 elric
463 1.1 elric int
464 1.14 dsl bt485_get_curmax(struct ramdac_cookie *rc, struct wsdisplay_curpos *curposp)
465 1.1 elric {
466 1.1 elric
467 1.1 elric curposp->x = curposp->y = CURSOR_MAX_SIZE;
468 1.1 elric return (0);
469 1.1 elric }
470 1.1 elric
471 1.1 elric /*****************************************************************************/
472 1.1 elric
473 1.1 elric /*
474 1.1 elric * Internal functions.
475 1.1 elric */
476 1.1 elric
477 1.1 elric void
478 1.14 dsl bt485_update(void *vp)
479 1.1 elric {
480 1.1 elric struct bt485data *data = vp;
481 1.1 elric u_int8_t regval;
482 1.1 elric int count, i, v;
483 1.1 elric
484 1.1 elric v = data->changed;
485 1.1 elric data->changed = 0;
486 1.1 elric
487 1.1 elric if (v & DATA_ENB_CHANGED) {
488 1.1 elric regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_2);
489 1.1 elric if (data->curenb)
490 1.1 elric regval |= 0x01;
491 1.1 elric else
492 1.1 elric regval &= ~0x03;
493 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COMMAND_2, regval);
494 1.1 elric }
495 1.1 elric
496 1.1 elric if (v & DATA_CURCMAP_CHANGED) {
497 1.1 elric /* addr[9:0] assumed to be 0 */
498 1.1 elric /* set addr[7:0] to 1 */
499 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COC_WRADDR, 0x01);
500 1.1 elric
501 1.1 elric /* spit out the cursor data */
502 1.1 elric for (i = 0; i < 2; i++) {
503 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
504 1.1 elric data->curcmap_r[i]);
505 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
506 1.1 elric data->curcmap_g[i]);
507 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
508 1.1 elric data->curcmap_b[i]);
509 1.1 elric }
510 1.1 elric }
511 1.1 elric
512 1.1 elric if (v & DATA_CURSHAPE_CHANGED) {
513 1.1 elric count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
514 1.1 elric
515 1.1 elric /*
516 1.1 elric * Write the cursor image data:
517 1.1 elric * set addr[9:8] to 0,
518 1.1 elric * set addr[7:0] to 0,
519 1.1 elric * spit it all out.
520 1.1 elric */
521 1.1 elric regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
522 1.1 elric regval &= ~0x03;
523 1.1 elric bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
524 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0);
525 1.1 elric for (i = 0; i < count; i++)
526 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_CURSOR_RAM,
527 1.1 elric data->curimage[i]);
528 1.12 perry
529 1.1 elric /*
530 1.1 elric * Write the cursor mask data:
531 1.1 elric * set addr[9:8] to 2,
532 1.1 elric * set addr[7:0] to 0,
533 1.1 elric * spit it all out.
534 1.1 elric */
535 1.1 elric regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
536 1.1 elric regval &= ~0x03; regval |= 0x02;
537 1.1 elric bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
538 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0);
539 1.1 elric for (i = 0; i < count; i++)
540 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_CURSOR_RAM,
541 1.1 elric data->curmask[i]);
542 1.1 elric
543 1.1 elric /* set addr[9:0] back to 0 */
544 1.1 elric regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
545 1.1 elric regval &= ~0x03;
546 1.1 elric bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
547 1.1 elric }
548 1.1 elric
549 1.1 elric if (v & DATA_CMAP_CHANGED) {
550 1.1 elric /* addr[9:0] assumed to be 0 */
551 1.1 elric /* set addr[7:0] to 0 */
552 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0x00);
553 1.1 elric
554 1.1 elric /* spit out the cursor data */
555 1.1 elric for (i = 0; i < 256; i++) {
556 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
557 1.1 elric data->cmap_r[i]);
558 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
559 1.1 elric data->cmap_g[i]);
560 1.1 elric data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
561 1.1 elric data->cmap_b[i]);
562 1.1 elric }
563 1.1 elric }
564 1.1 elric }
565 1.1 elric
566 1.1 elric void
567 1.14 dsl bt485_update_curpos(struct bt485data *data)
568 1.1 elric {
569 1.1 elric void *cookie = data->cookie;
570 1.1 elric int s, x, y;
571 1.1 elric
572 1.1 elric s = spltty();
573 1.1 elric
574 1.1 elric x = data->curpos.x + CURSOR_MAX_SIZE - data->curhot.x;
575 1.1 elric y = data->curpos.y + CURSOR_MAX_SIZE - data->curhot.y;
576 1.1 elric data->ramdac_wr(cookie, BT485_REG_CURSOR_X_LOW, x & 0xff);
577 1.1 elric data->ramdac_wr(cookie, BT485_REG_CURSOR_X_HIGH, (x >> 8) & 0x0f);
578 1.1 elric data->ramdac_wr(cookie, BT485_REG_CURSOR_Y_LOW, y & 0xff);
579 1.1 elric data->ramdac_wr(cookie, BT485_REG_CURSOR_Y_HIGH, (y >> 8) & 0x0f);
580 1.1 elric
581 1.1 elric splx(s);
582 1.1 elric }
583