1 /* $NetBSD: vga_ofbus.c,v 1.12 2007/10/28 18:01:55 jmmv 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@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.12 2007/10/28 18:01:55 jmmv 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 (struct device *, struct cfdata *, void *); 64 void vga_ofbus_attach (struct device *, struct device *, void *); 65 66 CFATTACH_DECL(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(struct device *parent, struct cfdata *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(struct device *parent, struct device *self, void *aux) 88 { 89 struct vga_ofbus_softc *osc = (void *) self; 90 struct vga_softc *sc = &osc->sc_vga; 91 struct ofbus_attach_args *oba = aux; 92 93 printf("\n"); 94 osc->sc_phandle = oba->oba_phandle; 95 96 vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag, 97 WSDISPLAY_TYPE_ISAVGA, 0, NULL); 98 } 99 100 int 101 vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt) 102 { 103 int chosen_phandle; 104 int stdout_ihandle, stdout_phandle, ret; 105 char buf[128]; 106 107 stdout_phandle = 0; 108 109 /* 110 * Find out whether the firmware's chosen stdout is 111 * a display. If so, use the existing ihandle so the firmware 112 * doesn't become Unhappy. If not, just open it. 113 */ 114 if ((chosen_phandle = OF_finddevice("/chosen")) == -1 || 115 OF_getprop(chosen_phandle, "stdout", &stdout_ihandle, 116 sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) { 117 return ENXIO; 118 } 119 stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle); 120 if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 || 121 OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) { 122 return ENXIO; 123 } 124 125 if (strcmp(buf, "display") != 0) { 126 /* The display is not stdout device. */ 127 return ENXIO; 128 } 129 130 if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) { 131 printf("vga_ofbus_match: text-mode3 method invocation on VGA " 132 "screen device failed\n"); 133 } 134 135 ret = vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1); 136 #if (NIGSFB_OFBUS > 0) || (NVGA_OFBUS > 0) 137 if (ret == 0) 138 console_ihandle = stdout_ihandle; 139 #endif 140 141 return ret; 142 } 143