1 /* $NetBSD: vga_ofbus.c,v 1.8 2005/12/11 12:19:05 christos 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.8 2005/12/11 12:19:05 christos 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 int vga_ofbus_match (struct device *, struct cfdata *, void *); 60 void vga_ofbus_attach (struct device *, struct device *, void *); 61 62 CFATTACH_DECL(vga_ofbus, sizeof(struct vga_ofbus_softc), 63 vga_ofbus_match, vga_ofbus_attach, NULL, NULL); 64 65 static const char *compat_strings[] = { "pnpPNP,900", 0 }; 66 67 int 68 vga_ofbus_match(struct device *parent, struct cfdata *match, void *aux) 69 { 70 struct ofbus_attach_args *oba = aux; 71 72 if (of_compatible(oba->oba_phandle, compat_strings) == -1) 73 return (0); 74 75 if (!vga_is_console(&isa_io_bs_tag, WSDISPLAY_TYPE_ISAVGA) && 76 !vga_common_probe(&isa_io_bs_tag, &isa_mem_bs_tag)) 77 return (0); 78 79 return (2); /* more than generic pcdisplay */ 80 } 81 82 void 83 vga_ofbus_attach(struct device *parent, struct device *self, void *aux) 84 { 85 struct vga_ofbus_softc *osc = (void *) self; 86 struct vga_softc *sc = &osc->sc_vga; 87 struct ofbus_attach_args *oba = aux; 88 89 printf("\n"); 90 osc->sc_phandle = oba->oba_phandle; 91 92 vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag, 93 WSDISPLAY_TYPE_ISAVGA, 0, NULL); 94 } 95 96 int 97 vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt) 98 { 99 int chosen_phandle; 100 int stdout_ihandle, stdout_phandle; 101 char buf[128]; 102 103 stdout_phandle = 0; 104 105 /* 106 * Find out whether the firmware's chosen stdout is 107 * a display. If so, use the existing ihandle so the firmware 108 * doesn't become Unhappy. If not, just open it. 109 */ 110 if ((chosen_phandle = OF_finddevice("/chosen")) == -1 || 111 OF_getprop(chosen_phandle, "stdout", &stdout_ihandle, 112 sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) { 113 return ENXIO; 114 } 115 stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle); 116 if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 || 117 OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) { 118 return ENXIO; 119 } 120 121 if (strcmp(buf, "display") != 0) { 122 /* The display is not stdout device. */ 123 return ENXIO; 124 } 125 126 if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) { 127 printf("vga_ofbus_match: text-mode3 method invocation on VGA " 128 "screen device failed\n"); 129 } 130 131 return (vga_cnattach(iot, memt, WSDISPLAY_TYPE_ISAVGA, 1)); 132 } 133