1 /* $NetBSD: arcofi_dio.c,v 1.3 2024/01/16 05:48:28 thorpej Exp $ */ 2 /* $OpenBSD: arcofi_dio.c,v 1.1 2011/12/21 23:12:03 miod Exp $ */ 3 4 /* 5 * Copyright (c) 2011 Miodrag Vallat. 6 * 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #include <sys/param.h> 21 #include <sys/systm.h> 22 #include <sys/conf.h> 23 #include <sys/device.h> 24 #include <sys/bus.h> 25 #include <sys/intr.h> 26 27 #include <sys/audioio.h> 28 #include <dev/audio/audio_if.h> 29 #include <dev/ic/arcofivar.h> 30 31 #include <hp300/dev/dioreg.h> 32 #include <hp300/dev/diovar.h> 33 34 #include <hp300/dev/diodevs.h> 35 36 #define SOFTINT_AUDIO SOFTINT_SERIAL /* XXX */ 37 38 static void arcofi_dio_attach(device_t, device_t, void *); 39 static int arcofi_dio_match(device_t, cfdata_t, void *); 40 41 struct arcofi_dio_softc { 42 struct arcofi_softc sc_arcofi; 43 44 struct bus_space_tag sc_tag; 45 }; 46 47 CFATTACH_DECL_NEW(arcofi_dio, sizeof(struct arcofi_dio_softc), 48 arcofi_dio_match, arcofi_dio_attach, NULL, NULL); 49 50 static int 51 arcofi_dio_match(device_t parent, cfdata_t match, void *aux) 52 { 53 struct dio_attach_args *da = aux; 54 55 if (da->da_id != DIO_DEVICE_ID_AUDIO) 56 return 0; 57 58 return 1; 59 } 60 61 static void 62 arcofi_dio_attach(device_t parent, device_t self, void *aux) 63 { 64 struct arcofi_dio_softc *adsc = device_private(self); 65 struct arcofi_softc *sc = &adsc->sc_arcofi; 66 struct dio_attach_args *da = aux; 67 bus_space_tag_t iot = &adsc->sc_tag; 68 int ipl; 69 70 sc->sc_dev = self; 71 72 /* XXX is it better to use sc->sc_reg[] to handle odd sparse map? */ 73 memcpy(iot, da->da_bst, sizeof(struct bus_space_tag)); 74 dio_set_bus_space_oddbyte(iot); 75 sc->sc_iot = iot; 76 77 if (bus_space_map(iot, da->da_addr, DIOII_SIZEOFF, 0, 78 &sc->sc_ioh) != 0) { 79 aprint_error(": can't map registers\n"); 80 return; 81 } 82 83 ipl = da->da_ipl; 84 dio_intr_establish(arcofi_hwintr, sc, ipl, ISRPRI_AUDIO); 85 86 aprint_normal("\n"); 87 88 arcofi_attach(sc, "dio"); 89 } 90