Home | History | Annotate | Line # | Download | only in acpi
wss_acpi.c revision 1.9
      1 /* $NetBSD: wss_acpi.c,v 1.9 2003/11/03 18:07:10 mycroft Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. The name of the author may not be used to endorse or promote products
     13  *    derived from this software without specific prior written permission.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     20  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     22  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     23  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: wss_acpi.c,v 1.9 2003/11/03 18:07:10 mycroft Exp $");
     30 
     31 #include <sys/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/errno.h>
     34 #include <sys/ioctl.h>
     35 #include <sys/syslog.h>
     36 #include <sys/device.h>
     37 #include <sys/proc.h>
     38 
     39 #include <machine/bus.h>
     40 
     41 #include <sys/audioio.h>
     42 #include <dev/audio_if.h>
     43 
     44 #include <dev/isa/isavar.h>
     45 #include <dev/isa/isadmavar.h>
     46 
     47 #include <dev/acpi/acpica.h>
     48 #include <dev/acpi/acpireg.h>
     49 #include <dev/acpi/acpivar.h>
     50 
     51 #include <dev/isa/ad1848var.h>
     52 #include <dev/isa/wssreg.h>
     53 #include <dev/isa/wssvar.h>
     54 
     55 int	wss_acpi_match(struct device *, struct cfdata *, void *);
     56 void	wss_acpi_attach(struct device *, struct device *, void *);
     57 
     58 CFATTACH_DECL(wss_acpi, sizeof(struct wss_softc), wss_acpi_match,
     59     wss_acpi_attach, NULL, NULL);
     60 
     61 /*
     62  * Supported device IDs
     63  */
     64 
     65 struct wss_acpi_hint {
     66 	char idstr[8];
     67 	int io_region_idx_ad1848;	/* which region index is the DAC?  */
     68 	int io_region_idx_opl;		/* which region index is the OPL?  */
     69 	int offset_ad1848;		/* offset from start of DAC region */
     70 };
     71 
     72 struct wss_acpi_hint wss_acpi_hints[] = {
     73 	{ "NMX2210", 1, 2, WSS_CODEC },
     74 	{ "CSC0000", 0, 1, 0 },		/* Dell Latitude CPi */
     75 	{ "CSC0100", 0, 1, 0 },		/* CS4610 with CS4236 codec */
     76 	{ { 0 }, 0, 0, 0 }
     77 };
     78 
     79 int wss_acpi_hints_index (const char *);
     80 
     81 int
     82 wss_acpi_hints_index(idstr)
     83 	const char *idstr;
     84 {
     85 	int idx = 0;
     86 
     87 	while (wss_acpi_hints[idx].idstr[0] != 0) {
     88 		if (!strcmp(wss_acpi_hints[idx].idstr, idstr))
     89 			return idx;
     90 		++idx;
     91 	}
     92 
     93 	return -1;
     94 }
     95 
     96 /*
     97  * wss_acpi_match: autoconf(9) match routine
     98  */
     99 int
    100 wss_acpi_match(struct device *parent, struct cfdata *match, void *aux)
    101 {
    102 	struct acpi_attach_args *aa = aux;
    103 
    104 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE ||
    105 	    wss_acpi_hints_index(aa->aa_node->ad_devinfo->HardwareId.Value) == -1)
    106 		return (0);
    107 
    108 	return (1);
    109 }
    110 
    111 /*
    112  * wss_acpi_attach: autoconf(9) attach routine
    113  */
    114 void
    115 wss_acpi_attach(struct device *parent, struct device *self, void *aux)
    116 {
    117 	struct wss_softc *sc = (struct wss_softc *)self;
    118 	struct acpi_attach_args *aa = aux;
    119 	struct acpi_resources res;
    120 	struct acpi_io *dspio, *oplio;
    121 	struct acpi_irq *irq;
    122 	struct acpi_drq *playdrq, *recdrq;
    123 	struct audio_attach_args arg;
    124 	ACPI_STATUS rv;
    125 	struct wss_acpi_hint *wah;
    126 
    127 	printf(": NeoMagic 256AV audio\n");
    128 
    129 	wah = &wss_acpi_hints[
    130 	    wss_acpi_hints_index(aa->aa_node->ad_devinfo->HardwareId.Value)];
    131 
    132 	/* Parse our resources */
    133 	rv = acpi_resource_parse(&sc->sc_ad1848.sc_ad1848.sc_dev,
    134 	    aa->aa_node, &res, &acpi_resource_parse_ops_default);
    135 	if (ACPI_FAILURE(rv))
    136 		return;
    137 
    138 	/* Find and map our i/o registers */
    139 	sc->sc_iot = aa->aa_iot;
    140 	dspio = acpi_res_io(&res, wah->io_region_idx_ad1848);
    141 	oplio = acpi_res_io(&res, wah->io_region_idx_opl);
    142 	if (dspio == NULL || oplio == NULL) {
    143 		printf("%s: unable to find i/o registers resource\n",
    144 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    145 		return;
    146 	}
    147 	if (bus_space_map(sc->sc_iot, dspio->ar_base, dspio->ar_length,
    148 	    0, &sc->sc_ioh) != 0) {
    149 		printf("%s: unable to map i/o registers\n",
    150 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    151 		return;
    152 	}
    153 	if (bus_space_map(sc->sc_iot, oplio->ar_base, oplio->ar_length,
    154 	    0, &sc->sc_opl_ioh) != 0) {
    155 		printf("%s: unable to map opl i/o registers\n",
    156 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    157 		return;
    158 	}
    159 
    160 	sc->wss_ic = aa->aa_ic;
    161 
    162 	/* Find our IRQ */
    163 	irq = acpi_res_irq(&res, 0);
    164 	if (irq == NULL) {
    165 		printf("%s: unable to find irq resource\n",
    166 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    167 		/* XXX bus_space_unmap */
    168 		return;
    169 	}
    170 	sc->wss_irq = irq->ar_irq;
    171 
    172 	/* Find our playback and record DRQs */
    173 	playdrq = acpi_res_drq(&res, 0);
    174 	recdrq = acpi_res_drq(&res, 1);
    175 	if (playdrq == NULL || recdrq == NULL) {
    176 		printf("%s: unable to find drq resources\n",
    177 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    178 		/* XXX bus_space_unmap */
    179 		return;
    180 	}
    181 	sc->wss_playdrq = playdrq->ar_drq;
    182 	sc->wss_recdrq = recdrq->ar_drq;
    183 
    184 	sc->sc_ad1848.sc_ad1848.sc_iot = sc->sc_iot;
    185 	bus_space_subregion(sc->sc_iot, sc->sc_ioh, wah->offset_ad1848, 4,
    186 	    &sc->sc_ad1848.sc_ad1848.sc_ioh);
    187 
    188 	/* Look for the ad1848 */
    189 	if (!ad1848_isa_probe(&sc->sc_ad1848)) {
    190 		printf("%s: ad1848 probe failed\n",
    191 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    192 		/* XXX cleanup */
    193 		return;
    194 	}
    195 
    196 	printf("%s", sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    197 	/* Attach our wss device */
    198 	wssattach(sc);
    199 
    200 	arg.type = AUDIODEV_TYPE_OPL;
    201 	arg.hwif = 0;
    202 	arg.hdl = 0;
    203 	config_found(self, &arg, audioprint);
    204 }
    205