Home | History | Annotate | Line # | Download | only in dev
com_ebus.c revision 1.1
      1 /*	$NetBSD: com_ebus.c,v 1.1 2000/09/21 22:25:08 eeh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1999, 2000 Matthew R. Green
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  * SUCH DAMAGE.
     29  */
     30 
     31 /*
     32  * NS Super I/O PC87332VLJ "com" to ebus attachment
     33  */
     34 
     35 #include <sys/types.h>
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/device.h>
     39 #include <sys/tty.h>
     40 #include <sys/conf.h>
     41 
     42 #include <machine/bus.h>
     43 #include <machine/autoconf.h>
     44 #include <machine/openfirm.h>
     45 
     46 #include <sparc64/dev/ebusreg.h>
     47 #include <sparc64/dev/ebusvar.h>
     48 
     49 #include <dev/cons.h>
     50 #include <dev/ic/comvar.h>
     51 #include <dev/sun/kbd_ms_ttyvar.h>
     52 
     53 #include "kbd.h"
     54 #include "ms.h"
     55 
     56 cdev_decl(com); /* XXX this belongs elsewhere */
     57 
     58 int	com_ebus_match __P((struct device *, struct cfdata *, void *));
     59 void	com_ebus_attach __P((struct device *, struct device *, void *));
     60 int	com_ebus_isconsole __P((int node));
     61 
     62 struct cfattach com_ebus_ca = {
     63 	sizeof(struct com_softc), com_ebus_match, com_ebus_attach
     64 };
     65 
     66 static char *com_names[] = {
     67 	"su",
     68 	"su_pnp",
     69 	NULL
     70 };
     71 
     72 int
     73 com_ebus_match(parent, match, aux)
     74 	struct device *parent;
     75 	struct cfdata *match;
     76 	void *aux;
     77 {
     78 	struct ebus_attach_args *ea = aux;
     79 	int i;
     80 
     81 	for (i=0; com_names[i]; i++)
     82 		if (strcmp(ea->ea_name, com_names[i]) == 0)
     83 			return (1);
     84 
     85 	return (0);
     86 }
     87 
     88 int
     89 com_ebus_isconsole(node)
     90 	int node;
     91 {
     92 	u_int chosen;
     93 
     94 	/*
     95 	 * We'll just to the OBP grovelling down here since that's
     96 	 * the only type of firmware we support.
     97 	 */
     98 	chosen = OF_finddevice("/chosen");
     99 
    100 	if (node == OF_instance_to_package(OF_stdin())) {
    101 		return (1);
    102 	}
    103 
    104 	if (node == OF_instance_to_package(OF_stdout())) {
    105 		return (1);
    106 	}
    107 
    108 	return (0);
    109 }
    110 
    111 #define BAUD_BASE       (1846200)
    112 
    113 void
    114 com_ebus_attach(parent, self, aux)
    115 	struct device *parent, *self;
    116 	void *aux;
    117 {
    118 	struct com_softc *sc = (void *)self;
    119 	struct ebus_attach_args *ea = aux;
    120 	struct kbd_ms_tty_attach_args kma;
    121 	struct consdev *old_cn = cn_tab;
    122 #if (NKBD > 0) || (NMS > 0)
    123 	int maj;
    124 #endif
    125 	int i;
    126 
    127 	sc->sc_iot = ea->ea_bustag;
    128 	sc->sc_iobase = EBUS_PADDR_FROM_REG(&ea->ea_regs[0]);
    129 	/*
    130 	 * Addresses that shoud be supplied by the prom:
    131 	 *	- normal com registers
    132 	 *	- ns873xx configuration registers
    133 	 *	- DMA space
    134 	 * The `com' driver does not use DMA accesses, so we can
    135 	 * ignore that for now.  We should enable the com port in
    136 	 * the ns873xx registers here. XXX
    137 	 *
    138 	 * Use the prom address if there.
    139 	 */
    140 	if (ea->ea_nvaddrs)
    141 		sc->sc_ioh = (bus_space_handle_t)ea->ea_vaddrs[0];
    142 	else if (ebus_bus_map(sc->sc_iot, 0,
    143 			      EBUS_PADDR_FROM_REG(&ea->ea_regs[0]),
    144 			      ea->ea_regs[0].size,
    145 			      BUS_SPACE_MAP_LINEAR,
    146 			      0, &sc->sc_ioh) != 0) {
    147 		printf(": can't map register space\n");
    148                 return;
    149 	}
    150 	sc->sc_hwflags = 0;
    151 	sc->sc_frequency = BAUD_BASE;
    152 
    153 	for (i = 0; i < ea->ea_nintrs; i++)
    154 		bus_intr_establish(ea->ea_bustag, ea->ea_intrs[i], 0,
    155 		    IPL_SERIAL, comintr, sc);
    156 	printf("\n");
    157 
    158 	com_attach_subr(sc);
    159 
    160 printf("com_ebus: orig cn_tab %p\n", cn_tab);
    161 	kma.kmta_consdev = NULL;
    162 	if (com_ebus_isconsole(ea->ea_node)) {
    163 		extern struct consdev comcons;
    164 
    165 		/* Record some info to attach console. */
    166 		kma.kmta_baud = 9600;
    167 		kma.kmta_cflag = (CREAD | CS8 | HUPCL);
    168 		kma.kmta_consdev = &comcons;
    169 printf("com_ebus: reverted cn_tab %p\n", cn_tab);
    170 	}
    171 
    172 #if (NKBD > 0) || (NMS > 0)
    173 	kma.kmta_tp = sc->sc_tty;
    174 /* If we figure out we're the console we should point this to our consdev */
    175 
    176 	/* locate the major number */
    177 	for (maj = 0; maj < nchrdev; maj++)
    178 		if (cdevsw[maj].d_open == comopen)
    179 			break;
    180 
    181 	kma.kmta_dev = makedev(maj, sc->sc_dev.dv_unit);
    182 
    183 /* Attach 'em if we got 'em. */
    184 #if (NKBD > 0)
    185 	kma.kmta_name = "keyboard";
    186 	if (getproplen(ea->ea_node, kma.kmta_name) == 0) {
    187 		config_found(self, (void *)&kma, NULL);
    188 	}
    189 #endif
    190 #if (NMS > 0)
    191 	kma.kmta_name = "mouse";
    192 	if (getproplen(ea->ea_node, kma.kmta_name) == 0) {
    193 		config_found(self, (void *)&kma, NULL);
    194 	}
    195 #endif
    196 #endif
    197 	if (kma.kmta_consdev) {
    198 		/* Attach com as the console. */
    199 printf("com_ebus: comcnattach at %d baud\n", kma.kmta_baud);
    200 		if (comcnattach(sc->sc_iot, sc->sc_iobase, kma.kmta_baud,
    201 			sc->sc_frequency, kma.kmta_cflag)) {
    202 			printf("Error: comcnattach failed\n");
    203 		}
    204 printf("com_ebus: setting cn_tab %p to %p\n", cn_tab, kma.kmta_consdev);
    205 		/*
    206 		 * If we're the keyboard then we need the original
    207 		 * cn_tab w/prom I/O, which sunkbd copied into kma.
    208 		 * Otherwise we want conscom which we copied into
    209 		 * kma.kmta_consdev.
    210 		 */
    211 		cn_tab = kma.kmta_consdev;
    212 	}
    213 }
    214 
    215