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