Home | History | Annotate | Line # | Download | only in ioplanar
      1 /*	$NetBSD: com_iop.c,v 1.5 2018/12/08 17:46:12 thorpej 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: com_iop.c,v 1.5 2018/12/08 17:46:12 thorpej Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/device.h>
     37 #include <sys/ioctl.h>
     38 #include <sys/tty.h>
     39 #include <sys/bus.h>
     40 
     41 #include <machine/intr.h>
     42 
     43 #include <dev/ic/comreg.h>
     44 #include <dev/ic/comvar.h>
     45 
     46 #include <dev/mca/mcavar.h>
     47 #include <dev/mca/mcadevs.h>
     48 
     49 #include <rs6000/ioplanar/ioplanarvar.h>
     50 
     51 struct com_iop_softc {
     52 	struct	com_softc sc_com;	/* real com softc */
     53 	void *sc_ih;
     54 };
     55 
     56 int com_iop_probe(device_t, cfdata_t , void *);
     57 void com_iop_attach(device_t, device_t, void *);
     58 
     59 CFATTACH_DECL_NEW(com_iop, sizeof(struct com_iop_softc),
     60     com_iop_probe, com_iop_attach, NULL, NULL);
     61 
     62 #define COM_RAINBOW_FREQ	8000000
     63 
     64 /*
     65  * This probe is very unorthodox.  Basically, we have no way to actually
     66  * probe the device, so instead, we check that the specific device should
     67  * exist on the ioplanar, and just return true.
     68  */
     69 
     70 int
     71 com_iop_probe(device_t parent, cfdata_t match, void *aux)
     72 {
     73 	struct ioplanar_dev_attach_args *idaa = aux;
     74 
     75 	if (idaa->idaa_devid == MCA_PRODUCT_IBM_SIO_RAINBOW &&
     76 	    (idaa->idaa_device == IOP_COM0 || idaa->idaa_device == IOP_COM1))
     77 		return 1;
     78 
     79 	return 0;
     80 }
     81 
     82 void
     83 com_iop_attach(device_t parent, device_t self, void *aux)
     84 {
     85 	struct com_iop_softc *isc = device_private(self);
     86 	struct com_softc *sc = &isc->sc_com;
     87 	int iobase, irq;
     88 	struct ioplanar_dev_attach_args *idaa = aux;
     89 	bus_space_handle_t ioh;
     90 
     91 	sc->sc_dev = self;
     92 
     93 	switch (idaa->idaa_devid) {
     94 	case MCA_PRODUCT_IBM_SIO_RAINBOW:
     95 		switch (idaa->idaa_device) {
     96 		case IOP_COM0:
     97 			iobase = 0x30;
     98 			irq = 2; /* ??? */
     99 			sc->sc_frequency = COM_RAINBOW_FREQ;
    100 			break;
    101 		case IOP_COM1:
    102 			iobase = 0x38;
    103 			irq = 2; /* ??? */
    104 			sc->sc_frequency = COM_RAINBOW_FREQ;
    105 			break;
    106 		default:
    107 			return;
    108 		}
    109 		break;
    110 	default:
    111 		return;
    112 	}
    113 	if (!com_is_console(idaa->idaa_iot, iobase, &ioh) &&
    114 	    bus_space_map(idaa->idaa_iot, iobase, COM_NPORTS, 0, &ioh)) {
    115 		aprint_error(": can't map i/o space\n");
    116 		return;
    117 	}
    118 
    119 	com_init_regs(&sc->sc_regs, idaa->idaa_iot, ioh, iobase);
    120 
    121 	aprint_normal("i/o %#x-%#x irq %d", iobase, iobase + COM_NPORTS - 1,
    122 	    irq);
    123 
    124 	com_attach_subr(sc);
    125 
    126 	isc->sc_ih = mca_intr_establish(idaa->idaa_mc, irq, IPL_SERIAL,
    127 	    comintr, sc);
    128 
    129 	if (isc->sc_ih == NULL) {
    130 		aprint_error_dev(self,
    131 		    "couldn't establish interrupt handler\n");
    132 		return;
    133 	}
    134 }
    135