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