1 /* $NetBSD: cs4231_sbus.c,v 1.15 2000/07/09 20:57:41 pk Exp $ */ 2 3 /*- 4 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Paul Kranenburg. 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 "audio.h" 40 #if NAUDIO > 0 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/errno.h> 45 #include <sys/device.h> 46 #include <sys/malloc.h> 47 48 #include <machine/bus.h> 49 #include <machine/intr.h> 50 51 #include <dev/sbus/sbusvar.h> 52 53 #include <sys/audioio.h> 54 #include <dev/audio_if.h> 55 56 #include <dev/ic/ad1848reg.h> 57 #include <dev/ic/cs4231reg.h> 58 #include <dev/ic/ad1848var.h> 59 #include <dev/ic/cs4231var.h> 60 61 #define AUDIO_ROM_NAME "SUNW,CS4231" 62 #define CS4231_REG_SIZE 16 63 64 /* autoconfiguration driver */ 65 void cs4231_attach_sbus __P((struct device *, struct device *, void *)); 66 int cs4231_match_sbus __P((struct device *, struct cfdata *, void *)); 67 68 struct cfattach audiocs_sbus_ca = { 69 sizeof(struct cs4231_softc), cs4231_match_sbus, cs4231_attach_sbus 70 }; 71 72 /* autoconfig routines */ 73 74 int 75 cs4231_match_sbus(parent, cf, aux) 76 struct device *parent; 77 struct cfdata *cf; 78 void *aux; 79 { 80 struct sbus_attach_args *sa = aux; 81 82 return (strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0); 83 } 84 85 /* 86 * Audio chip found. 87 */ 88 void 89 cs4231_attach_sbus(parent, self, aux) 90 struct device *parent, *self; 91 void *aux; 92 { 93 struct cs4231_softc *sc = (struct cs4231_softc *)self; 94 struct sbus_attach_args *sa = aux; 95 bus_space_handle_t bh; 96 97 sc->sc_bustag = sa->sa_bustag; 98 sc->sc_dmatag = sa->sa_dmatag; 99 100 sc->sc_ad1848.parent = sc; 101 sc->sc_ad1848.sc_iot = sc->sc_bustag; 102 sc->sc_ad1848.sc_readreg = cs4231_read; 103 sc->sc_ad1848.sc_writereg = cs4231_write; 104 105 /* 106 * Map my registers in, if they aren't already in virtual 107 * address space. 108 */ 109 if (sa->sa_npromvaddrs) { 110 bh = (bus_space_handle_t)sa->sa_promvaddrs[0]; 111 } else { 112 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 113 sa->sa_offset, 114 sa->sa_size, 115 BUS_SPACE_MAP_LINEAR, 116 0, &bh) != 0) { 117 printf("%s @ sbus: cannot map registers\n", 118 self->dv_xname); 119 return; 120 } 121 } 122 123 sc->sc_ad1848.sc_ioh = bh; 124 sc->sc_dmareg = (struct apc_dma *)(u_long)(bh + CS4231_REG_SIZE); 125 126 cs4231_init(sc); 127 128 /* Put ad1848 driver in `MODE 2' mode */ 129 sc->sc_ad1848.mode = 2; 130 ad1848_attach(&sc->sc_ad1848); 131 132 printf("\n"); 133 134 sbus_establish(&sc->sc_sd, &sc->sc_ad1848.sc_dev); 135 136 /* Establish interrupt channel */ 137 if (sa->sa_nintr) 138 bus_intr_establish(sa->sa_bustag, 139 sa->sa_pri, IPL_AUDIO, 0, 140 cs4231_intr, sc); 141 142 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL, 143 sc->sc_ad1848.sc_dev.dv_xname, "intr"); 144 audio_attach_mi(&audiocs_hw_if, sc, &sc->sc_ad1848.sc_dev); 145 } 146 #endif 147