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