vga_common.c revision 1.4 1 1.4 lukem /* $NetBSD: vga_common.c,v 1.4 2003/07/14 15:47:12 lukem Exp $ */
2 1.1 junyoung
3 1.1 junyoung /*
4 1.1 junyoung * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 1.1 junyoung * All rights reserved.
6 1.1 junyoung *
7 1.1 junyoung * Author: Chris G. Demetriou
8 1.1 junyoung *
9 1.1 junyoung * Permission to use, copy, modify and distribute this software and
10 1.1 junyoung * its documentation is hereby granted, provided that both the copyright
11 1.1 junyoung * notice and this permission notice appear in all copies of the
12 1.1 junyoung * software, derivative works or modified versions, and any portions
13 1.1 junyoung * thereof, and that both notices appear in supporting documentation.
14 1.1 junyoung *
15 1.1 junyoung * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 1.1 junyoung * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 1.1 junyoung * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 1.1 junyoung *
19 1.1 junyoung * Carnegie Mellon requests users of this software to return to
20 1.1 junyoung *
21 1.1 junyoung * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 1.1 junyoung * School of Computer Science
23 1.1 junyoung * Carnegie Mellon University
24 1.1 junyoung * Pittsburgh PA 15213-3890
25 1.1 junyoung *
26 1.1 junyoung * any improvements or extensions that they make and grant Carnegie the
27 1.1 junyoung * rights to redistribute these changes.
28 1.1 junyoung */
29 1.4 lukem
30 1.4 lukem #include <sys/cdefs.h>
31 1.4 lukem __KERNEL_RCSID(0, "$NetBSD: vga_common.c,v 1.4 2003/07/14 15:47:12 lukem Exp $");
32 1.1 junyoung
33 1.1 junyoung #include <sys/param.h>
34 1.1 junyoung #include <sys/device.h>
35 1.1 junyoung #include <machine/bus.h>
36 1.1 junyoung
37 1.1 junyoung #include <dev/ic/mc6845reg.h>
38 1.1 junyoung #include <dev/ic/pcdisplayvar.h>
39 1.1 junyoung #include <dev/ic/vgareg.h>
40 1.1 junyoung #include <dev/ic/vgavar.h>
41 1.1 junyoung
42 1.1 junyoung /*
43 1.1 junyoung * The following functions implement back-end configuration grabbing
44 1.1 junyoung * and attachment.
45 1.1 junyoung */
46 1.1 junyoung int
47 1.1 junyoung vga_common_probe(bus_space_tag_t iot, bus_space_tag_t memt)
48 1.1 junyoung {
49 1.1 junyoung bus_space_handle_t ioh_vga, ioh_6845, memh;
50 1.1 junyoung u_int8_t regval;
51 1.1 junyoung u_int16_t vgadata;
52 1.1 junyoung int gotio_vga, gotio_6845, gotmem, mono, rv;
53 1.1 junyoung int dispoffset;
54 1.1 junyoung
55 1.1 junyoung gotio_vga = gotio_6845 = gotmem = rv = 0;
56 1.1 junyoung
57 1.1 junyoung if (bus_space_map(iot, 0x3c0, 0x10, 0, &ioh_vga))
58 1.1 junyoung goto bad;
59 1.1 junyoung gotio_vga = 1;
60 1.1 junyoung
61 1.1 junyoung /* read "misc output register" */
62 1.3 tsutsui regval = bus_space_read_1(iot, ioh_vga, VGA_MISC_DATAR);
63 1.1 junyoung mono = !(regval & 1);
64 1.1 junyoung
65 1.1 junyoung if (bus_space_map(iot, (mono ? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845))
66 1.1 junyoung goto bad;
67 1.1 junyoung gotio_6845 = 1;
68 1.1 junyoung
69 1.1 junyoung if (bus_space_map(memt, 0xa0000, 0x20000, 0, &memh))
70 1.1 junyoung goto bad;
71 1.1 junyoung gotmem = 1;
72 1.1 junyoung
73 1.1 junyoung dispoffset = (mono ? 0x10000 : 0x18000);
74 1.1 junyoung
75 1.1 junyoung vgadata = bus_space_read_2(memt, memh, dispoffset);
76 1.1 junyoung bus_space_write_2(memt, memh, dispoffset, 0xa55a);
77 1.1 junyoung if (bus_space_read_2(memt, memh, dispoffset) != 0xa55a)
78 1.1 junyoung goto bad;
79 1.1 junyoung bus_space_write_2(memt, memh, dispoffset, vgadata);
80 1.1 junyoung
81 1.1 junyoung /*
82 1.1 junyoung * check if this is really a VGA
83 1.1 junyoung * (try to write "Color Select" register as XFree86 does)
84 1.1 junyoung * XXX check before if at least EGA?
85 1.1 junyoung */
86 1.1 junyoung /* reset state */
87 1.1 junyoung (void) bus_space_read_1(iot, ioh_6845, 10);
88 1.1 junyoung bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX,
89 1.2 tsutsui 20 | 0x20); /* colselect | enable */
90 1.1 junyoung regval = bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR);
91 1.1 junyoung /* toggle the implemented bits */
92 1.1 junyoung bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval ^ 0x0f);
93 1.2 tsutsui bus_space_write_1(iot, ioh_vga, VGA_ATC_INDEX, 20 | 0x20);
94 1.1 junyoung /* read back */
95 1.1 junyoung if (bus_space_read_1(iot, ioh_vga, VGA_ATC_DATAR) != (regval ^ 0x0f))
96 1.1 junyoung goto bad;
97 1.1 junyoung /* restore contents */
98 1.1 junyoung bus_space_write_1(iot, ioh_vga, VGA_ATC_DATAW, regval);
99 1.1 junyoung
100 1.1 junyoung rv = 1;
101 1.1 junyoung bad:
102 1.1 junyoung if (gotio_vga)
103 1.1 junyoung bus_space_unmap(iot, ioh_vga, 0x10);
104 1.1 junyoung if (gotio_6845)
105 1.1 junyoung bus_space_unmap(iot, ioh_6845, 0x10);
106 1.1 junyoung if (gotmem)
107 1.1 junyoung bus_space_unmap(memt, memh, 0x20000);
108 1.1 junyoung
109 1.1 junyoung return (rv);
110 1.1 junyoung }
111