Home | History | Annotate | Line # | Download | only in sbus
cs4231_sbus.c revision 1.11
      1 /*	$NetBSD: cs4231_sbus.c,v 1.11 1999/06/05 14:29:11 mrg 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/autoconf.h>
     49 #include <machine/cpu.h>
     50 
     51 #include <sys/audioio.h>
     52 #include <dev/audio_if.h>
     53 
     54 #include <dev/ic/ad1848reg.h>
     55 #include <dev/ic/cs4231reg.h>
     56 #include <dev/ic/ad1848var.h>
     57 #include <dev/ic/cs4231var.h>
     58 
     59 #define AUDIO_ROM_NAME		"SUNW,CS4231"
     60 #define CS4231_REG_SIZE		16
     61 
     62 /* autoconfiguration driver */
     63 void	cs4231_attach_sbus __P((struct device *, struct device *, void *));
     64 int	cs4231_match_sbus __P((struct device *, struct cfdata *, void *));
     65 
     66 struct cfattach audiocs_sbus_ca = {
     67 	sizeof(struct cs4231_softc), cs4231_match_sbus, cs4231_attach_sbus
     68 };
     69 
     70 /* autoconfig routines */
     71 
     72 int
     73 cs4231_match_sbus(parent, cf, aux)
     74 	struct device *parent;
     75 	struct cfdata *cf;
     76 	void *aux;
     77 {
     78 	struct sbus_attach_args *sa = aux;
     79 
     80 	return (strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0);
     81 }
     82 
     83 /*
     84  * Audio chip found.
     85  */
     86 void
     87 cs4231_attach_sbus(parent, self, aux)
     88 	struct device *parent, *self;
     89 	void *aux;
     90 {
     91 	struct cs4231_softc *sc = (struct cs4231_softc *)self;
     92 	struct sbus_attach_args *sa = aux;
     93 	bus_space_handle_t bh;
     94 
     95 	sc->sc_bustag = sa->sa_bustag;
     96 	sc->sc_dmatag = sa->sa_dmatag;
     97 
     98 	sc->sc_ad1848.parent = sc;
     99 	sc->sc_ad1848.sc_iot = sc->sc_bustag;
    100 	sc->sc_ad1848.sc_readreg = cs4231_read;
    101 	sc->sc_ad1848.sc_writereg = cs4231_write;
    102 
    103 	/*
    104 	 * Map my registers in, if they aren't already in virtual
    105 	 * address space.
    106 	 */
    107 	if (sa->sa_npromvaddrs) {
    108 		bh = (bus_space_handle_t)sa->sa_promvaddrs[0];
    109 	} else {
    110 		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    111 				 sa->sa_offset,
    112 				 sa->sa_size,
    113 				 BUS_SPACE_MAP_LINEAR,
    114 				 0, &bh) != 0) {
    115 			printf("%s @ sbus: cannot map registers\n",
    116 				self->dv_xname);
    117 			return;
    118 		}
    119 	}
    120 
    121 	sc->sc_ad1848.sc_ioh = bh;
    122 	sc->sc_dmareg = (struct apc_dma *)(bh + CS4231_REG_SIZE);
    123 
    124 	cs4231_init(sc);
    125 
    126 	/* Put ad1848 driver in `MODE 2' mode */
    127 	sc->sc_ad1848.mode = 2;
    128 	ad1848_attach(&sc->sc_ad1848);
    129 
    130 	printf("\n");
    131 
    132 	sbus_establish(&sc->sc_sd, &sc->sc_ad1848.sc_dev);
    133 
    134 	/* Establish interrupt channel */
    135 	bus_intr_establish(sa->sa_bustag,
    136 			   sa->sa_pri, 0,
    137 			   cs4231_intr, sc);
    138 
    139 	evcnt_attach(&sc->sc_ad1848.sc_dev, "intr", &sc->sc_intrcnt);
    140 	audio_attach_mi(&audiocs_hw_if, sc, &sc->sc_ad1848.sc_dev);
    141 }
    142 #endif
    143