vga_ofbus.c revision 1.13 1 /* $NetBSD: vga_ofbus.c,v 1.13 2008/03/14 22:12:08 cube Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
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.
14 *
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.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: vga_ofbus.c,v 1.13 2008/03/14 22:12:08 cube Exp $");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/device.h>
37 #include <sys/malloc.h>
38
39 #include <dev/isa/isavar.h>
40
41 #include <dev/ic/mc6845reg.h>
42 #include <dev/ic/pcdisplayvar.h>
43 #include <dev/ic/vgareg.h>
44 #include <dev/ic/vgavar.h>
45
46 #include <dev/wscons/wsconsio.h>
47 #include <dev/wscons/wsdisplayvar.h>
48
49 #include <dev/ofw/openfirm.h>
50
51 #include <shark/ofw/vga_ofbusvar.h>
52
53 struct vga_ofbus_softc {
54 struct vga_softc sc_vga;
55
56 int sc_phandle;
57 };
58
59 #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
60 extern int console_ihandle;
61 #endif
62
63 int vga_ofbus_match (device_t, cfdata_t, void *);
64 void vga_ofbus_attach (device_t, device_t, void *);
65
66 CFATTACH_DECL_NEW(vga_ofbus, sizeof(struct vga_ofbus_softc),
67 vga_ofbus_match, vga_ofbus_attach, NULL, NULL);
68
69 static const char *compat_strings[] = { "pnpPNP,900", 0 };
70
71 int
72 vga_ofbus_match(device_t parent, cfdata_t match, void *aux)
73 {
74 struct ofbus_attach_args *oba = aux;
75
76 if (of_compatible(oba->oba_phandle, compat_strings) == -1)
77 return (0);
78
79 if (!vga_is_console(&isa_io_bs_tag, WSDISPLAY_TYPE_ISAVGA) &&
80 !vga_common_probe(&isa_io_bs_tag, &isa_mem_bs_tag))
81 return (0);
82
83 return (2); /* more than generic pcdisplay */
84 }
85
86 void
87 vga_ofbus_attach(device_t parent, device_t self, void *aux)
88 {
89 struct vga_ofbus_softc *osc = device_private(self);
90 struct vga_softc *sc = &osc->sc_vga;
91 struct ofbus_attach_args *oba = aux;
92
93 sc->sc_dev = self;
94 aprint_normal("\n");
95 osc->sc_phandle = oba->oba_phandle;
96
97 vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag,
98 WSDISPLAY_TYPE_ISAVGA, 0, NULL);
99 }
100
101 int
102 vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt)
103 {
104 int chosen_phandle;
105 int stdout_ihandle, stdout_phandle, ret;
106 char buf[128];
107
108 stdout_phandle = 0;
109
110 /*
111 * Find out whether the firmware's chosen stdout is
112 * a display. If so, use the existing ihandle so the firmware
113 * doesn't become Unhappy. If not, just open it.
114 */
115 if ((chosen_phandle = OF_finddevice("/chosen")) == -1 ||
116 OF_getprop(chosen_phandle, "stdout", &stdout_ihandle,
117 sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) {
118 return ENXIO;
119 }
120 stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle);
121 if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 ||
122 OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) {
123 return ENXIO;
124 }
125
126 if (strcmp(buf, "display") != 0) {
127 /* The display is not stdout device. */
128 return ENXIO;
129 }
130
131 if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) {
132 printf("vga_ofbus_match: text-mode3 method invocation on VGA "
133 "screen device failed\n");
134 }
135
136 ret = vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1);
137 #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0)
138 if (ret == 0)
139 console_ihandle = stdout_ihandle;
140 #endif
141
142 return ret;
143 }
144