Home | History | Annotate | Line # | Download | only in dev
com_opb.c revision 1.12
      1 /* $NetBSD: com_opb.c,v 1.12 2004/12/24 14:55:50 shige Exp $ */
      2 
      3 /*
      4  * Copyright 2001 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *      This product includes software developed for the NetBSD Project by
     20  *      Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 /*
     39  * Copyright (c) 1998
     40  *	Matthias Drochner.  All rights reserved.
     41  *
     42  * Redistribution and use in source and binary forms, with or without
     43  * modification, are permitted provided that the following conditions
     44  * are met:
     45  * 1. Redistributions of source code must retain the above copyright
     46  *    notice, this list of conditions and the following disclaimer.
     47  * 2. Redistributions in binary form must reproduce the above copyright
     48  *    notice, this list of conditions and the following disclaimer in the
     49  *    documentation and/or other materials provided with the distribution.
     50  *
     51  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     52  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     53  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     54  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     55  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     56  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     57  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     58  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     59  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     60  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     61  */
     62 
     63 #include <sys/cdefs.h>
     64 __KERNEL_RCSID(0, "$NetBSD: com_opb.c,v 1.12 2004/12/24 14:55:50 shige Exp $");
     65 
     66 #include <sys/param.h>
     67 #include <sys/device.h>
     68 #include <sys/tty.h>
     69 #include <sys/systm.h>
     70 
     71 #include <lib/libkern/libkern.h>
     72 
     73 #include <machine/cpu.h>
     74 
     75 #include <powerpc/ibm4xx/dev/opbvar.h>
     76 #include <powerpc/ibm4xx/dev/comopbvar.h>
     77 
     78 #include "com.h"
     79 #if (NCOM > 0)
     80 #include <dev/ic/comreg.h>
     81 #include <dev/ic/comvar.h>
     82 #endif
     83 
     84 struct com_opb_softc {
     85 	struct com_softc sc_com;
     86 	void *sc_ih;
     87 };
     88 
     89 static int	com_opb_probe(struct device *, struct cfdata *, void *);
     90 static void	com_opb_attach(struct device *, struct device *, void *);
     91 
     92 CFATTACH_DECL(com_opb, sizeof(struct com_opb_softc),
     93     com_opb_probe, com_opb_attach, NULL, NULL);
     94 
     95 int
     96 com_opb_probe(struct device *parent, struct cfdata *cf, void *aux)
     97 {
     98 	struct opb_attach_args *oaa = aux;
     99 
    100 	/* match only com devices */
    101 	if (strcmp(oaa->opb_name, cf->cf_name) != 0)
    102 		return 0;
    103 
    104 	return (1);
    105 }
    106 
    107 void
    108 com_opb_attach(struct device *parent, struct device *self, void *aux)
    109 {
    110 	struct com_opb_softc *msc = (void *)self;
    111 	struct com_softc *sc = &msc->sc_com;
    112 	struct opb_attach_args *oaa = aux;
    113 
    114 	sc->sc_iot = oaa->opb_bt;
    115 	sc->sc_iobase = oaa->opb_addr;
    116 
    117 	/* XXX console check */
    118 
    119 	bus_space_map(sc->sc_iot, oaa->opb_addr, COM_NPORTS, 0,
    120 	    &sc->sc_ioh);
    121 
    122 	if (prop_get(dev_propdb, &sc->sc_dev, "frequency",
    123 		     &sc->sc_frequency, sizeof(sc->sc_frequency), NULL) == -1) {
    124 		printf(": unable to get frequency property\n");
    125 		return;
    126 	}
    127 
    128 	com_attach_subr(sc);
    129 
    130 	intr_establish(oaa->opb_irq, IST_LEVEL, IPL_SERIAL, comintr, sc);
    131 }
    132 
    133 /*
    134  * com_opb_cnattach:
    135  * Initialize the system console.
    136  */
    137 void
    138 com_opb_cnattach(int com_freq, int conaddr, int conspeed, int conmode)
    139 {
    140 	static int attached = 0;
    141 #if (NCOM > 0)
    142 	bus_space_tag_t tag;
    143 #endif
    144 
    145 	if (attached)
    146 		return;
    147 	attached = 1;
    148 
    149 #if (NCOM > 0)
    150 	/* We *know* the com-console attaches to opb */
    151 	tag = opb_get_bus_space_tag();
    152 
    153 	if (comcnattach(tag,
    154 		conaddr, conspeed, com_freq, COM_TYPE_NORMAL, conmode))
    155 		panic("can't init serial console @%x", conaddr);
    156 	else
    157 		return;
    158 #endif
    159 	panic("console device missing -- serial console not in kernel");
    160 	/* Of course, this is moot if there is no console... */
    161 }
    162 
    163 /*
    164  * com_opb_device_register:
    165  */
    166 void
    167 com_opb_device_register(struct device *dev, int frequency)
    168 {
    169 	int com_freq = frequency;
    170 
    171 	/* Set the frequency of the on-chip UART. */
    172 	if (prop_set(dev_propdb, dev, "frequency",
    173 		&com_freq, sizeof(com_freq), PROP_INT, 0) != 0)
    174 		printf("WARNING: unable to set frequency "
    175 			"property for %s\n", dev->dv_xname);
    176 	return;
    177 }
    178