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