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