1 /* $NetBSD: vga_common.c,v 1.10 2008/04/08 12:07:27 cegger Exp $ */
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: vga_common.c,v 1.10 2008/04/08 12:07:27 cegger Exp $");
33 #include <sys/param.h>
34 #include <sys/device.h>
37 #include <dev/ic/mc6845reg.h>
38 #include <dev/ic/pcdisplayvar.h>
39 #include <dev/ic/vgareg.h>
40 #include <dev/ic/vgavar.h>
43 * The following functions implement back-end configuration grabbing
47 vga_common_probe(bus_space_tag_t iot
, bus_space_tag_t memt
)
49 bus_space_handle_t ioh_vga
, ioh_6845
, memh
;
52 int gotio_vga
, gotio_6845
, gotmem
, mono
, rv
;
55 gotio_vga
= gotio_6845
= gotmem
= rv
= 0;
57 if (bus_space_map(iot
, 0x3c0, 0x10, 0, &ioh_vga
))
61 /* read "misc output register" */
62 regval
= bus_space_read_1(iot
, ioh_vga
, VGA_MISC_DATAR
);
65 if (bus_space_map(iot
, (mono
? 0x3b0 : 0x3d0), 0x10, 0, &ioh_6845
))
69 if (bus_space_map(memt
, 0xa0000, 0x20000, 0, &memh
))
73 dispoffset
= (mono
? 0x10000 : 0x18000);
75 vgadata
= bus_space_read_2(memt
, memh
, dispoffset
);
76 bus_space_write_2(memt
, memh
, dispoffset
, 0xa55a);
77 if (bus_space_read_2(memt
, memh
, dispoffset
) != 0xa55a)
79 bus_space_write_2(memt
, memh
, dispoffset
, vgadata
);
82 * check if this is really a VGA
83 * (try to write "Color Select" register as XFree86 does)
84 * XXX check before if at least EGA?
87 (void) bus_space_read_1(iot
, ioh_6845
, 10);
88 bus_space_write_1(iot
, ioh_vga
, VGA_ATC_INDEX
,
89 20 | 0x20); /* colselect | enable */
90 regval
= bus_space_read_1(iot
, ioh_vga
, VGA_ATC_DATAR
);
91 /* toggle the implemented bits */
92 bus_space_write_1(iot
, ioh_vga
, VGA_ATC_DATAW
, regval
^ 0x0f);
93 bus_space_write_1(iot
, ioh_vga
, VGA_ATC_INDEX
, 20 | 0x20);
95 if (bus_space_read_1(iot
, ioh_vga
, VGA_ATC_DATAR
) != (regval
^ 0x0f))
97 /* restore contents */
98 bus_space_write_1(iot
, ioh_vga
, VGA_ATC_DATAW
, regval
);
103 bus_space_unmap(iot
, ioh_vga
, 0x10);
105 bus_space_unmap(iot
, ioh_6845
, 0x10);
107 bus_space_unmap(memt
, memh
, 0x20000);