This source file includes following definitions.
- bt485_funcs
- bt485_register
- bt485_cninit
- bt485_init
- bt485_set_cmap
- bt485_get_cmap
- bt485_set_cursor
- bt485_get_cursor
- bt485_set_curpos
- bt485_get_curpos
- bt485_get_curmax
- bt485_wr_i
- bt485_rd_i
- bt485_update
- bt485_update_curpos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 #include <sys/buf.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41
42 #include <uvm/uvm_extern.h>
43
44 #include <dev/pci/pcivar.h>
45 #include <dev/ic/bt485reg.h>
46 #include <dev/ic/bt485var.h>
47 #include <dev/ic/ramdac.h>
48
49 #include <dev/wscons/wsconsio.h>
50 #include <dev/wscons/wsdisplayvar.h>
51 #include <dev/rasops/rasops.h>
52
53
54
55
56 void bt485_init(struct ramdac_cookie *);
57 int bt485_set_cmap(struct ramdac_cookie *,
58 struct wsdisplay_cmap *);
59 int bt485_get_cmap(struct ramdac_cookie *,
60 struct wsdisplay_cmap *);
61 int bt485_set_cursor(struct ramdac_cookie *,
62 struct wsdisplay_cursor *);
63 int bt485_get_cursor(struct ramdac_cookie *,
64 struct wsdisplay_cursor *);
65 int bt485_set_curpos(struct ramdac_cookie *,
66 struct wsdisplay_curpos *);
67 int bt485_get_curpos(struct ramdac_cookie *,
68 struct wsdisplay_curpos *);
69 int bt485_get_curmax(struct ramdac_cookie *,
70 struct wsdisplay_curpos *);
71
72
73 struct ramdac_funcs bt485_funcsstruct = {
74 "Bt485",
75 bt485_register,
76 bt485_init,
77 bt485_set_cmap,
78 bt485_get_cmap,
79 bt485_set_cursor,
80 bt485_get_cursor,
81 bt485_set_curpos,
82 bt485_get_curpos,
83 bt485_get_curmax,
84 NULL,
85 NULL,
86 NULL,
87 NULL,
88 };
89
90
91
92
93 struct bt485data {
94 void *cookie;
95
96
97
98
99 int (*ramdac_sched_update)(void *, void (*)(void *));
100 void (*ramdac_wr)(void *, u_int, u_int8_t);
101 u_int8_t (*ramdac_rd)(void *, u_int);
102
103 int changed;
104 int curenb;
105 struct wsdisplay_curpos curpos;
106 struct wsdisplay_curpos curhot;
107 char curcmap_r[2];
108 char curcmap_g[2];
109 char curcmap_b[2];
110 struct wsdisplay_curpos cursize;
111 char curimage[512];
112 char curmask[512];
113 char cmap_r[256];
114 char cmap_g[256];
115 char cmap_b[256];
116 };
117
118 #define DATA_ENB_CHANGED 0x01
119 #define DATA_CURCMAP_CHANGED 0x02
120 #define DATA_CURSHAPE_CHANGED 0x04
121 #define DATA_CMAP_CHANGED 0x08
122 #define DATA_ALL_CHANGED 0x0f
123
124 #define CURSOR_MAX_SIZE 64
125
126
127
128
129 inline void bt485_wr_i(struct bt485data *, u_int8_t, u_int8_t);
130 inline u_int8_t bt485_rd_i(struct bt485data *, u_int8_t);
131 void bt485_update(void *);
132 void bt485_update_curpos(struct bt485data *);
133
134
135
136
137
138
139
140 struct ramdac_funcs *
141 bt485_funcs(void)
142 {
143 return &bt485_funcsstruct;
144 }
145
146 struct ramdac_cookie *
147 bt485_register(v, sched_update, wr, rd)
148 void *v;
149 int (*sched_update)(void *, void (*)(void *));
150 void (*wr)(void *, u_int, u_int8_t);
151 u_int8_t (*rd)(void *, u_int);
152 {
153 struct bt485data *data;
154
155
156
157
158
159
160 data = malloc(sizeof *data, M_DEVBUF, M_WAITOK);
161
162 data->cookie = v;
163 data->ramdac_sched_update = sched_update;
164 data->ramdac_wr = wr;
165 data->ramdac_rd = rd;
166 return (struct ramdac_cookie *)data;
167 }
168
169
170
171
172
173
174 void
175 bt485_cninit(v, sched_update, wr, rd)
176 void *v;
177 int (*sched_update)(void *, void (*)(void *));
178 void (*wr)(void *, u_int, u_int8_t);
179 u_int8_t (*rd)(void *, u_int);
180 {
181 struct bt485data tmp, *data = &tmp;
182 data->cookie = v;
183 data->ramdac_sched_update = sched_update;
184 data->ramdac_wr = wr;
185 data->ramdac_rd = rd;
186 bt485_init((struct ramdac_cookie *)data);
187 }
188
189 void
190 bt485_init(rc)
191 struct ramdac_cookie *rc;
192 {
193 u_int8_t regval;
194 struct bt485data *data = (struct bt485data *)rc;
195 int i;
196
197
198
199
200
201
202
203
204
205
206 regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_0);
207 regval |= 0x80;
208
209
210
211
212 regval |= 0x02;
213 data->ramdac_wr(data->cookie, BT485_REG_COMMAND_0, regval);
214
215
216 data->ramdac_wr(data->cookie, BT485_REG_COMMAND_1, 0x40);
217
218
219 regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_2);
220 regval &= ~0x03;
221 regval |= 0x24;
222 data->ramdac_wr(data->cookie, BT485_REG_COMMAND_2, regval);
223
224
225 regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
226 regval |= 0x04;
227 regval |= 0x08;
228 bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
229
230
231 data->ramdac_wr(data->cookie, BT485_REG_PIXMASK, 0xff);
232
233
234
235
236
237 data->changed = DATA_ALL_CHANGED;
238
239 data->curenb = 0;
240 data->curpos.x = data->curpos.y = 0;
241 data->curhot.x = data->curhot.y = 0;
242
243
244 data->curcmap_r[0] = data->curcmap_g[0] = data->curcmap_b[0] = 0;
245 data->curcmap_r[1] = data->curcmap_g[1] = data->curcmap_b[1] = 0xff;
246
247
248 data->cursize.x = data->cursize.y = 64;
249 for (i = 0; i < 512; i++)
250 data->curimage[i] = data->curmask[i] = 0xff;
251
252
253 data->cmap_r[0] = data->cmap_g[0] = data->cmap_b[0] = 0;
254 for (i = 0; i < 256; i++) {
255 data->cmap_r[i] = rasops_cmap[3*i + 0];
256 data->cmap_g[i] = rasops_cmap[3*i + 1];
257 data->cmap_b[i] = rasops_cmap[3*i + 2];
258 }
259
260 bt485_update((void *)data);
261 }
262
263 int
264 bt485_set_cmap(rc, cmapp)
265 struct ramdac_cookie *rc;
266 struct wsdisplay_cmap *cmapp;
267 {
268 struct bt485data *data = (struct bt485data *)rc;
269 u_int count, index;
270 int s, error;
271
272 #ifdef DIAGNOSTIC
273 if (rc == NULL)
274 panic("bt485_set_cmap: rc");
275 if (cmapp == NULL)
276 panic("bt485_set_cmap: cmapp");
277 #endif
278 index = cmapp->index;
279 count = cmapp->count;
280
281 if (index >= 256 || count > 256 - index)
282 return (EINVAL);
283
284 s = spltty();
285
286 if ((error = copyin(cmapp->red, &data->cmap_r[index], count)) != 0) {
287 splx(s);
288 return (error);
289 }
290 if ((error = copyin(cmapp->green, &data->cmap_g[index], count)) != 0) {
291 splx(s);
292 return (error);
293 }
294 if ((error = copyin(cmapp->blue, &data->cmap_b[index], count)) != 0) {
295 splx(s);
296 return (error);
297 }
298
299 data->changed |= DATA_CMAP_CHANGED;
300
301 data->ramdac_sched_update(data->cookie, bt485_update);
302 #ifdef __alpha__
303 alpha_mb();
304 #endif
305 splx(s);
306
307 return (0);
308 }
309
310 int
311 bt485_get_cmap(rc, cmapp)
312 struct ramdac_cookie *rc;
313 struct wsdisplay_cmap *cmapp;
314 {
315 struct bt485data *data = (struct bt485data *)rc;
316 u_int count, index;
317 int error;
318
319 if (cmapp->index >= 256 || cmapp->count > 256 - cmapp->index)
320 return (EINVAL);
321
322 count = cmapp->count;
323 index = cmapp->index;
324
325 error = copyout(&data->cmap_r[index], cmapp->red, count);
326 if (error)
327 return (error);
328 error = copyout(&data->cmap_g[index], cmapp->green, count);
329 if (error)
330 return (error);
331 error = copyout(&data->cmap_b[index], cmapp->blue, count);
332 return (error);
333 }
334
335 int
336 bt485_set_cursor(rc, cursorp)
337 struct ramdac_cookie *rc;
338 struct wsdisplay_cursor *cursorp;
339 {
340 struct bt485data *data = (struct bt485data *)rc;
341 u_int count, index;
342 int error;
343 int v, s;
344
345 v = cursorp->which;
346
347
348
349
350
351 if (v & WSDISPLAY_CURSOR_DOCMAP) {
352 index = cursorp->cmap.index;
353 count = cursorp->cmap.count;
354 if (index >= 2 || count > 2 - index)
355 return (EINVAL);
356 }
357 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
358 if ((u_int)cursorp->size.x > CURSOR_MAX_SIZE ||
359 (u_int)cursorp->size.y > CURSOR_MAX_SIZE)
360 return (EINVAL);
361 }
362
363 if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOCUR)) {
364 if (v & WSDISPLAY_CURSOR_DOPOS)
365 data->curpos = cursorp->pos;
366 if (v & WSDISPLAY_CURSOR_DOCUR)
367 data->curhot = cursorp->hot;
368 bt485_update_curpos(data);
369 }
370
371 s = spltty();
372
373
374 if (v & WSDISPLAY_CURSOR_DOCUR) {
375 data->curenb = cursorp->enable;
376 data->changed |= DATA_ENB_CHANGED;
377 }
378 if (v & WSDISPLAY_CURSOR_DOCMAP) {
379 index = cursorp->cmap.index;
380 count = cursorp->cmap.count;
381 if ((error = copyin(cursorp->cmap.red,
382 &data->curcmap_r[index], count)) != 0) {
383 splx(s);
384 return (error);
385 }
386 if ((error = copyin(cursorp->cmap.green,
387 &data->curcmap_g[index], count)) != 0) {
388 splx(s);
389 return (error);
390 }
391 if ((error = copyin(cursorp->cmap.blue,
392 &data->curcmap_b[index], count)) != 0) {
393 splx(s);
394 return (error);
395 }
396 data->changed |= DATA_CURCMAP_CHANGED;
397 }
398 if (v & WSDISPLAY_CURSOR_DOSHAPE) {
399 data->cursize = cursorp->size;
400 count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
401 bzero(data->curimage, sizeof data->curimage);
402 bzero(data->curmask, sizeof data->curmask);
403 if ((error = copyin(cursorp->image, data->curimage,
404 count)) != 0) {
405 splx(s);
406 return (error);
407 }
408 if ((error = copyin(cursorp->mask, data->curmask,
409 count)) != 0) {
410 splx(s);
411 return (error);
412 }
413 data->changed |= DATA_CURSHAPE_CHANGED;
414 }
415
416 if (data->changed)
417 data->ramdac_sched_update(data->cookie, bt485_update);
418 splx(s);
419
420 return (0);
421 }
422
423 int
424 bt485_get_cursor(rc, cursorp)
425 struct ramdac_cookie *rc;
426 struct wsdisplay_cursor *cursorp;
427 {
428 struct bt485data *data = (struct bt485data *)rc;
429 int error, count;
430
431
432 cursorp->which = WSDISPLAY_CURSOR_DOALL;
433
434 cursorp->enable = data->curenb;
435 cursorp->pos = data->curpos;
436 cursorp->hot = data->curhot;
437
438 cursorp->cmap.index = 0;
439 cursorp->cmap.count = 2;
440 if (cursorp->cmap.red != NULL) {
441 error = copyout(data->curcmap_r, cursorp->cmap.red, 2);
442 if (error)
443 return (error);
444 }
445 if (cursorp->cmap.green != NULL) {
446 error = copyout(data->curcmap_g, cursorp->cmap.green, 2);
447 if (error)
448 return (error);
449 }
450 if (cursorp->cmap.blue != NULL) {
451 error = copyout(data->curcmap_b, cursorp->cmap.blue, 2);
452 if (error)
453 return (error);
454 }
455
456 cursorp->size = data->cursize;
457 if (cursorp->image != NULL) {
458 count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
459 error = copyout(data->curimage, cursorp->image, count);
460 if (error)
461 return (error);
462 error = copyout(data->curmask, cursorp->mask, count);
463 if (error)
464 return (error);
465 }
466
467 return (0);
468 }
469
470 int
471 bt485_set_curpos(rc, curposp)
472 struct ramdac_cookie *rc;
473 struct wsdisplay_curpos *curposp;
474 {
475 struct bt485data *data = (struct bt485data *)rc;
476
477 data->curpos = *curposp;
478 bt485_update_curpos(data);
479
480 return (0);
481 }
482
483 int
484 bt485_get_curpos(rc, curposp)
485 struct ramdac_cookie *rc;
486 struct wsdisplay_curpos *curposp;
487 {
488 struct bt485data *data = (struct bt485data *)rc;
489
490 *curposp = data->curpos;
491 return (0);
492 }
493
494 int
495 bt485_get_curmax(rc, curposp)
496 struct ramdac_cookie *rc;
497 struct wsdisplay_curpos *curposp;
498 {
499
500 curposp->x = curposp->y = CURSOR_MAX_SIZE;
501 return (0);
502 }
503
504
505
506
507
508
509
510 inline void
511 bt485_wr_i(data, ireg, val)
512 struct bt485data *data;
513 u_int8_t ireg;
514 u_int8_t val;
515 {
516 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, ireg);
517 data->ramdac_wr(data->cookie, BT485_REG_EXTENDED, val);
518 }
519
520 inline u_int8_t
521 bt485_rd_i(data, ireg)
522 struct bt485data *data;
523 u_int8_t ireg;
524 {
525 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, ireg);
526 return (data->ramdac_rd(data->cookie, BT485_REG_EXTENDED));
527 }
528
529 void
530 bt485_update(vp)
531 void *vp;
532 {
533 struct bt485data *data = vp;
534 u_int8_t regval;
535 int count, i, v;
536
537 v = data->changed;
538 data->changed = 0;
539
540 if (v & DATA_ENB_CHANGED) {
541 regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_2);
542 if (data->curenb)
543 regval |= 0x01;
544 else
545 regval &= ~0x03;
546 data->ramdac_wr(data->cookie, BT485_REG_COMMAND_2, regval);
547 }
548
549 if (v & DATA_CURCMAP_CHANGED) {
550
551
552 data->ramdac_wr(data->cookie, BT485_REG_COC_WRADDR, 0x01);
553
554
555 for (i = 0; i < 2; i++) {
556 data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
557 data->curcmap_r[i]);
558 data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
559 data->curcmap_g[i]);
560 data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
561 data->curcmap_b[i]);
562 }
563 }
564
565 if (v & DATA_CURSHAPE_CHANGED) {
566 count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
567
568
569
570
571
572
573
574 regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
575 regval &= ~0x03;
576 bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
577 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0);
578 for (i = 0; i < count; i++)
579 data->ramdac_wr(data->cookie, BT485_REG_CURSOR_RAM,
580 data->curimage[i]);
581
582
583
584
585
586
587
588 regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
589 regval &= ~0x03; regval |= 0x02;
590 bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
591 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0);
592 for (i = 0; i < count; i++)
593 data->ramdac_wr(data->cookie, BT485_REG_CURSOR_RAM,
594 data->curmask[i]);
595
596
597 regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
598 regval &= ~0x03;
599 bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
600 }
601
602 if (v & DATA_CMAP_CHANGED) {
603
604
605 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0x00);
606
607
608 for (i = 0; i < 256; i++) {
609 data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
610 data->cmap_r[i]);
611 data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
612 data->cmap_g[i]);
613 data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
614 data->cmap_b[i]);
615 }
616 }
617 }
618
619 void
620 bt485_update_curpos(data)
621 struct bt485data *data;
622 {
623 void *cookie = data->cookie;
624 int s, x, y;
625
626 s = spltty();
627
628 x = data->curpos.x + CURSOR_MAX_SIZE - data->curhot.x;
629 y = data->curpos.y + CURSOR_MAX_SIZE - data->curhot.y;
630 data->ramdac_wr(cookie, BT485_REG_CURSOR_X_LOW, x & 0xff);
631 data->ramdac_wr(cookie, BT485_REG_CURSOR_X_HIGH, (x >> 8) & 0x0f);
632 data->ramdac_wr(cookie, BT485_REG_CURSOR_Y_LOW, y & 0xff);
633 data->ramdac_wr(cookie, BT485_REG_CURSOR_Y_HIGH, (y >> 8) & 0x0f);
634
635 splx(s);
636 }