1 1.32 thorpej /* $NetBSD: ess_ofisa.c,v 1.32 2021/01/27 03:10:21 thorpej Exp $ */ 2 1.1 augustss 3 1.1 augustss /*- 4 1.1 augustss * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 1.1 augustss * All rights reserved. 6 1.1 augustss * 7 1.1 augustss * This code is derived from software contributed to The NetBSD Foundation 8 1.1 augustss * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 1.1 augustss * NASA Ames Research Center. 10 1.1 augustss * 11 1.1 augustss * Redistribution and use in source and binary forms, with or without 12 1.1 augustss * modification, are permitted provided that the following conditions 13 1.1 augustss * are met: 14 1.1 augustss * 1. Redistributions of source code must retain the above copyright 15 1.1 augustss * notice, this list of conditions and the following disclaimer. 16 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright 17 1.1 augustss * notice, this list of conditions and the following disclaimer in the 18 1.1 augustss * documentation and/or other materials provided with the distribution. 19 1.1 augustss * 20 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 1.1 augustss * POSSIBILITY OF SUCH DAMAGE. 31 1.1 augustss */ 32 1.7 lukem 33 1.7 lukem #include <sys/cdefs.h> 34 1.32 thorpej __KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.32 2021/01/27 03:10:21 thorpej Exp $"); 35 1.1 augustss 36 1.1 augustss #include <sys/param.h> 37 1.1 augustss #include <sys/systm.h> 38 1.1 augustss #include <sys/device.h> 39 1.1 augustss 40 1.18 ad #include <sys/bus.h> 41 1.18 ad #include <sys/intr.h> 42 1.1 augustss 43 1.1 augustss #include <sys/audioio.h> 44 1.28 isaki #include <dev/audio/audio_if.h> 45 1.1 augustss 46 1.1 augustss #include <dev/ofw/openfirm.h> 47 1.1 augustss #include <dev/isa/isavar.h> 48 1.1 augustss #include <dev/ofisa/ofisavar.h> 49 1.1 augustss 50 1.1 augustss #include <dev/isa/essreg.h> 51 1.1 augustss #include <dev/isa/essvar.h> 52 1.1 augustss 53 1.24 cegger int ess_ofisa_match(device_t, cfdata_t, void *); 54 1.24 cegger void ess_ofisa_attach(device_t, device_t, void *); 55 1.1 augustss 56 1.25 tsutsui CFATTACH_DECL_NEW(ess_ofisa, sizeof(struct ess_softc), 57 1.11 thorpej ess_ofisa_match, ess_ofisa_attach, NULL, NULL); 58 1.1 augustss 59 1.29 thorpej static const struct device_compatible_entry compat_data[] = { 60 1.29 thorpej { .compat = "ESST,es1887-codec" }, /* ESS 1887 */ 61 1.29 thorpej { .compat = "ESST,es1888-codec" }, /* ESS 1888 */ 62 1.29 thorpej { .compat = "ESST,es888-codec" }, /* ESS 888 */ 63 1.31 thorpej DEVICE_COMPAT_EOL 64 1.29 thorpej }; 65 1.29 thorpej 66 1.1 augustss int 67 1.24 cegger ess_ofisa_match(device_t parent, cfdata_t cf, void *aux) 68 1.1 augustss { 69 1.1 augustss struct ofisa_attach_args *aa = aux; 70 1.1 augustss 71 1.29 thorpej /* beat generic SB */ 72 1.32 thorpej return of_compatible_match(aa->oba.oba_phandle, compat_data) ? 10 : 0; 73 1.1 augustss } 74 1.1 augustss 75 1.1 augustss void 76 1.24 cegger ess_ofisa_attach(device_t parent, device_t self, void *aux) 77 1.1 augustss { 78 1.17 thorpej struct ess_softc *sc = device_private(self); 79 1.1 augustss struct ofisa_attach_args *aa = aux; 80 1.1 augustss struct ofisa_reg_desc reg; 81 1.1 augustss struct ofisa_intr_desc intr[2]; 82 1.1 augustss struct ofisa_dma_desc dma[2]; 83 1.1 augustss int n, ndrq; 84 1.1 augustss 85 1.25 tsutsui sc->sc_dev = self; 86 1.25 tsutsui 87 1.1 augustss /* 88 1.1 augustss * We're living on an OFW. We have to ask the OFW what our 89 1.1 augustss * registers and interrupts properties look like. 90 1.1 augustss * 91 1.1 augustss * We expect: 92 1.1 augustss * 93 1.3 augustss * 1 i/o register region 94 1.3 augustss * 1 or 2 interrupts 95 1.12 wiz * 2 DMA channels 96 1.1 augustss */ 97 1.1 augustss 98 1.1 augustss n = ofisa_reg_get(aa->oba.oba_phandle, ®, 1); 99 1.1 augustss if (n != 1) { 100 1.25 tsutsui aprint_error(": error getting register data\n"); 101 1.1 augustss return; 102 1.1 augustss } 103 1.1 augustss if (reg.type != OFISA_REG_TYPE_IO) { 104 1.25 tsutsui aprint_error(": register type not i/o\n"); 105 1.1 augustss return; 106 1.1 augustss } 107 1.1 augustss if (reg.len != ESS_NPORT) { 108 1.25 tsutsui aprint_error(": weird register size (%lu, expected %d)\n", 109 1.1 augustss (unsigned long)reg.len, ESS_NPORT); 110 1.1 augustss return; 111 1.1 augustss } 112 1.1 augustss 113 1.1 augustss n = ofisa_intr_get(aa->oba.oba_phandle, intr, 2); 114 1.3 augustss if (n == 1) { 115 1.5 mycroft sc->sc_audio1.irq = intr[0].irq; 116 1.5 mycroft sc->sc_audio1.ist = intr[0].share; 117 1.5 mycroft sc->sc_audio2.irq = intr[0].irq; 118 1.5 mycroft sc->sc_audio2.ist = intr[0].share; 119 1.3 augustss } else if (n == 2) { 120 1.5 mycroft sc->sc_audio1.irq = intr[0].irq; 121 1.5 mycroft sc->sc_audio1.ist = intr[0].share; 122 1.5 mycroft sc->sc_audio2.irq = intr[1].irq; 123 1.5 mycroft sc->sc_audio2.ist = intr[1].share; 124 1.3 augustss } else { 125 1.25 tsutsui aprint_error(": error getting interrupt data\n"); 126 1.1 augustss return; 127 1.1 augustss } 128 1.1 augustss 129 1.1 augustss ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2); 130 1.1 augustss if (ndrq != 2) { 131 1.25 tsutsui aprint_error(": error getting DMA data\n"); 132 1.1 augustss return; 133 1.1 augustss } 134 1.5 mycroft sc->sc_audio1.drq = dma[0].drq; 135 1.5 mycroft sc->sc_audio2.drq = dma[1].drq; 136 1.1 augustss 137 1.1 augustss sc->sc_ic = aa->ic; 138 1.1 augustss 139 1.1 augustss sc->sc_iot = aa->iot; 140 1.1 augustss sc->sc_iobase = reg.addr; 141 1.1 augustss if (bus_space_map(sc->sc_iot, sc->sc_iobase, reg.len, 0, 142 1.1 augustss &sc->sc_ioh)) { 143 1.25 tsutsui aprint_error(": unable to map register space\n"); 144 1.1 augustss return; 145 1.1 augustss } 146 1.1 augustss 147 1.15 perry /* 148 1.6 nathanw * The Shark firmware doesn't program the ESS ISA address registers. 149 1.6 nathanw * Do that here instead of inside essmatch() since we want to defer 150 1.6 nathanw * to the firmware on other platforms. 151 1.6 nathanw */ 152 1.6 nathanw if (ess_config_addr(sc)) 153 1.6 nathanw return; 154 1.1 augustss if (essmatch(sc) == 0) { 155 1.25 tsutsui aprint_error(": essmatch failed\n"); 156 1.1 augustss return; 157 1.1 augustss } 158 1.1 augustss 159 1.27 christos ofisa_print_model(self, aa->oba.oba_phandle); 160 1.1 augustss 161 1.13 drochner essattach(sc, 0); 162 1.1 augustss } 163