Home | History | Annotate | Line # | Download | only in ioplanar
com_iop.c revision 1.1
      1 /*	$NetBSD: com_iop.c,v 1.1 2007/12/17 19:09:38 garbled Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Tim Rightnour
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: com_iop.c,v 1.1 2007/12/17 19:09:38 garbled Exp $");
     41 
     42 #include <sys/param.h>
     43 #include <sys/device.h>
     44 #include <sys/ioctl.h>
     45 #include <sys/tty.h>
     46 
     47 #include <machine/intr.h>
     48 #include <machine/bus.h>
     49 
     50 #include <dev/ic/comreg.h>
     51 #include <dev/ic/comvar.h>
     52 
     53 #include <dev/mca/mcavar.h>
     54 #include <dev/mca/mcadevs.h>
     55 
     56 #include <rs6000/ioplanar/ioplanarvar.h>
     57 
     58 struct com_iop_softc {
     59 	struct	com_softc sc_com;	/* real com softc */
     60 	void *sc_ih;
     61 };
     62 
     63 int com_iop_probe(struct device *, struct cfdata *, void *);
     64 void com_iop_attach(struct device *, struct device *, void *);
     65 
     66 CFATTACH_DECL(com_iop, sizeof(struct com_iop_softc),
     67     com_iop_probe, com_iop_attach, NULL, NULL);
     68 
     69 #define COM_RAINBOW_FREQ	8000000
     70 
     71 /*
     72  * This probe is very unorthodox.  Basically, we have no way to actually
     73  * probe the device, so instead, we check that the specific device should
     74  * exist on the ioplanar, and just return true.
     75  */
     76 
     77 int
     78 com_iop_probe(struct device *parent, struct cfdata *match, void *aux)
     79 {
     80 	struct ioplanar_dev_attach_args *idaa = aux;
     81 
     82 	if (idaa->idaa_devid == MCA_PRODUCT_IBM_SIO_RAINBOW &&
     83 	    (idaa->idaa_device == IOP_COM0 || idaa->idaa_device == IOP_COM1))
     84 		return 1;
     85 
     86 	return 0;
     87 }
     88 
     89 void
     90 com_iop_attach(struct device *parent, struct device *self, void *aux)
     91 {
     92 	struct com_iop_softc *isc = device_private(self);
     93 	struct com_softc *sc = &isc->sc_com;
     94 	int iobase, irq;
     95 	struct ioplanar_dev_attach_args *idaa = aux;
     96 	bus_space_handle_t ioh;
     97 
     98 	switch (idaa->idaa_devid) {
     99 	case MCA_PRODUCT_IBM_SIO_RAINBOW:
    100 		switch (idaa->idaa_device) {
    101 		case IOP_COM0:
    102 			iobase = 0x30;
    103 			irq = 2; /* ??? */
    104 			sc->sc_frequency = COM_RAINBOW_FREQ;
    105 			break;
    106 		case IOP_COM1:
    107 			iobase = 0x38;
    108 			irq = 2; /* ??? */
    109 			sc->sc_frequency = COM_RAINBOW_FREQ;
    110 			break;
    111 		default:
    112 			return;
    113 		}
    114 		break;
    115 	default:
    116 		return;
    117 	}
    118 	if (!com_is_console(idaa->idaa_iot, iobase, &ioh) &&
    119 	    bus_space_map(idaa->idaa_iot, iobase, COM_NPORTS, 0, &ioh)) {
    120 		aprint_error(": can't map i/o space\n");
    121 		return;
    122 	}
    123 
    124 	COM_INIT_REGS(sc->sc_regs, idaa->idaa_iot, ioh, iobase);
    125 
    126 	aprint_normal("i/o %#x-%#x irq %d", iobase, iobase + COM_NPORTS - 1,
    127 	    irq);
    128 
    129 	com_attach_subr(sc);
    130 
    131 	isc->sc_ih = mca_intr_establish(idaa->idaa_mc, irq, IPL_SERIAL,
    132 	    comintr, sc);
    133 
    134 	if (isc->sc_ih == NULL) {
    135 		aprint_error("%s: couldn't establish interrupt handler\n",
    136 		    sc->sc_dev.dv_xname);
    137 		return;
    138 	}
    139 }
    140