Home | History | Annotate | Line # | Download | only in acpi
wss_acpi.c revision 1.3
      1 /* $NetBSD: wss_acpi.c,v 1.3 2002/12/28 18:59:52 jmcneill 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.3 2002/12/28 18:59:52 jmcneill 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 void	wss_acpi_config_interrupts(struct device *);
     59 
     60 CFATTACH_DECL(wss_acpi, sizeof(struct wss_softc), wss_acpi_match,
     61     wss_acpi_attach, NULL, NULL);
     62 
     63 /*
     64  * Supported device IDs
     65  */
     66 
     67 static const char * const wss_acpi_ids[] = {
     68 	"CSC0100",	/* NeoMagic 256AV with CS4232 codec */
     69 	NULL
     70 };
     71 
     72 /*
     73  * wss_acpi_match: autoconf(9) match routine
     74  */
     75 int
     76 wss_acpi_match(struct device *parent, struct cfdata *match, void *aux)
     77 {
     78 	struct acpi_attach_args *aa = aux;
     79 	const char *id;
     80 	int i;
     81 
     82 	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
     83 		return 0;
     84 
     85 	for (i = 0; (id = wss_acpi_ids[i]) != NULL; ++i) {
     86 		if (strcmp(aa->aa_node->ad_devinfo.HardwareId, id) == 0)
     87 			return 1;
     88 	}
     89 
     90 	/* No matches found */
     91 	return 0;
     92 }
     93 
     94 /*
     95  * wss_acpi_attach: autoconf(9) attach routine
     96  */
     97 void
     98 wss_acpi_attach(struct device *parent, struct device *self, void *aux)
     99 {
    100 	struct wss_softc *sc = (struct wss_softc *)self;
    101 	struct acpi_attach_args *aa = aux;
    102 	struct acpi_resources res;
    103 	struct acpi_io *dspio, *oplio;
    104 	struct acpi_irq *irq;
    105 	struct acpi_drq *playdrq, *recdrq;
    106 	struct audio_attach_args arg;
    107 	ACPI_STATUS rv;
    108 
    109 	printf(": NeoMagic 256AV audio\n");
    110 
    111 	/* Parse our resources */
    112 	rv = acpi_resource_parse(&sc->sc_ad1848.sc_ad1848.sc_dev,
    113 	    aa->aa_node, &res, &acpi_resource_parse_ops_default);
    114 	if (rv != AE_OK) {
    115 		printf("%s: unable to parse resources\n",
    116 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    117 		return;
    118 	}
    119 
    120 	/* Find and map our i/o registers */
    121 	sc->sc_iot = aa->aa_iot;
    122 	dspio = acpi_res_io(&res, 0);
    123 	oplio = acpi_res_io(&res, 1);
    124 	if (dspio == NULL || oplio == NULL) {
    125 		printf("%s: unable to find i/o registers resource\n",
    126 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    127 		return;
    128 	}
    129 	if (bus_space_map(sc->sc_iot, dspio->ar_base, dspio->ar_length,
    130 	    0, &sc->sc_ioh) != 0) {
    131 		printf("%s: unable to map i/o registers\n",
    132 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    133 		return;
    134 	}
    135 	if (bus_space_map(sc->sc_iot, oplio->ar_base, oplio->ar_length,
    136 	    0, &sc->sc_opl_ioh) != 0) {
    137 		printf("%s: unable to map opl i/o registers\n",
    138 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    139 		return;
    140 	}
    141 
    142 	sc->wss_ic = aa->aa_ic;
    143 
    144 	/* Find our IRQ */
    145 	irq = acpi_res_irq(&res, 0);
    146 	if (irq == NULL) {
    147 		printf("%s: unable to find irq resource\n",
    148 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    149 		/* XXX bus_space_unmap */
    150 		return;
    151 	}
    152 	sc->wss_irq = irq->ar_irq;
    153 
    154 	/* Find our playback and record DRQs */
    155 	playdrq = acpi_res_drq(&res, 0);
    156 	recdrq = acpi_res_drq(&res, 1);
    157 	if (playdrq == NULL || recdrq == NULL) {
    158 		printf("%s: unable to find drq resources\n",
    159 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    160 		/* XXX bus_space_unmap */
    161 		return;
    162 	}
    163 	sc->wss_playdrq = playdrq->ar_drq;
    164 	sc->wss_recdrq = recdrq->ar_drq;
    165 
    166 	sc->sc_ad1848.sc_ad1848.sc_iot = sc->sc_iot;
    167 	bus_space_subregion(sc->sc_iot, sc->sc_ioh, 0, 4,
    168 	    &sc->sc_ad1848.sc_ad1848.sc_ioh);
    169 
    170 	/* Look for the ad1848 */
    171 	if (!ad1848_isa_probe(&sc->sc_ad1848)) {
    172 		printf("%s: ad1848 probe failed\n",
    173 		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    174 		/* XXX cleanup */
    175 		return;
    176 	}
    177 
    178 	printf("%s", sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
    179 	/* Attach our wss device */
    180 	wssattach(sc);
    181 
    182 	arg.type = AUDIODEV_TYPE_OPL;
    183 	arg.hwif = 0;
    184 	arg.hdl = 0;
    185 	config_found(self, &arg, audioprint);
    186 }
    187