ym_acpi.c revision 1.1
11.1Sitohy/* $NetBSD: ym_acpi.c,v 1.1 2006/08/14 09:34:43 itohy Exp $ */ 21.1Sitohy 31.1Sitohy/* 41.1Sitohy * Copyright (c) 2006 Jasper Wallace <jasper@pointless.net> 51.1Sitohy * All rights reserved. 61.1Sitohy * 71.1Sitohy * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca> 81.1Sitohy * All rights reserved. 91.1Sitohy * 101.1Sitohy * Redistribution and use in source and binary forms, with or without 111.1Sitohy * modification, are permitted provided that the following conditions 121.1Sitohy * are met: 131.1Sitohy * 1. Redistributions of source code must retain the above copyright 141.1Sitohy * notice, this list of conditions and the following disclaimer. 151.1Sitohy * 2. The name of the author may not be used to endorse or promote products 161.1Sitohy * derived from this software without specific prior written permission. 171.1Sitohy * 181.1Sitohy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 191.1Sitohy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 201.1Sitohy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 211.1Sitohy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 221.1Sitohy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 231.1Sitohy * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 241.1Sitohy * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 251.1Sitohy * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 261.1Sitohy * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271.1Sitohy * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281.1Sitohy * SUCH DAMAGE. 291.1Sitohy */ 301.1Sitohy 311.1Sitohy#include <sys/cdefs.h> 321.1Sitohy__KERNEL_RCSID(0, "$NetBSD: ym_acpi.c,v 1.1 2006/08/14 09:34:43 itohy Exp $"); 331.1Sitohy 341.1Sitohy#include "mpu_ym.h" 351.1Sitohy 361.1Sitohy#include <sys/param.h> 371.1Sitohy#include <machine/bus.h> 381.1Sitohy 391.1Sitohy#include <dev/acpi/acpivar.h> 401.1Sitohy 411.1Sitohy#include <dev/audio_if.h> 421.1Sitohy 431.1Sitohy#include <dev/ic/ad1848reg.h> 441.1Sitohy#include <dev/isa/ad1848var.h> 451.1Sitohy 461.1Sitohy#include <dev/ic/opl3sa3reg.h> 471.1Sitohy#include <dev/isa/wssreg.h> 481.1Sitohy#include <dev/isa/ymvar.h> 491.1Sitohy 501.1Sitohy 511.1Sitohystatic int ym_acpi_match(struct device *, struct cfdata *, void *); 521.1Sitohystatic void ym_acpi_attach(struct device *, struct device *, void *); 531.1Sitohy 541.1SitohyCFATTACH_DECL(ym_acpi, sizeof(struct ym_softc), ym_acpi_match, 551.1Sitohy ym_acpi_attach, NULL, NULL); 561.1Sitohy 571.1Sitohy/* 581.1Sitohy * ym_acpi_match: autoconf(9) match routine 591.1Sitohy */ 601.1Sitohystatic int 611.1Sitohyym_acpi_match(struct device *parent, struct cfdata *match, void *aux) 621.1Sitohy{ 631.1Sitohy struct acpi_attach_args *aa = aux; 641.1Sitohy 651.1Sitohy if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 661.1Sitohy return 0; 671.1Sitohy /* Yamaha OPL3-SA2 or OPL3-SA3 */ 681.1Sitohy if (strcmp("YMH0021", aa->aa_node->ad_devinfo->HardwareId.Value)) 691.1Sitohy return 0; 701.1Sitohy 711.1Sitohy return 1; 721.1Sitohy} 731.1Sitohy 741.1Sitohy/* 751.1Sitohy * ym_acpi_attach: autoconf(9) attach routine 761.1Sitohy */ 771.1Sitohystatic void 781.1Sitohyym_acpi_attach(struct device *parent, struct device *self, void *aux) 791.1Sitohy{ 801.1Sitohy struct ym_softc *sc = (struct ym_softc *)self; 811.1Sitohy struct acpi_attach_args *aa = aux; 821.1Sitohy struct acpi_resources res; 831.1Sitohy struct acpi_io *sb_io, *codec_io, *opl_io, *control_io; 841.1Sitohy#if NMPU_YM > 0 851.1Sitohy struct acpi_io *mpu_io; 861.1Sitohy#endif 871.1Sitohy struct acpi_irq *irq; 881.1Sitohy struct acpi_drq *playdrq, *recdrq; 891.1Sitohy struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848; 901.1Sitohy ACPI_STATUS rv; 911.1Sitohy 921.1Sitohy aprint_naive("\n"); 931.1Sitohy aprint_normal("\n"); 941.1Sitohy 951.1Sitohy /* Parse our resources */ 961.1Sitohy rv = acpi_resource_parse(&sc->sc_ad1848.sc_ad1848.sc_dev, 971.1Sitohy aa->aa_node->ad_handle, "_CRS", &res, 981.1Sitohy &acpi_resource_parse_ops_default); 991.1Sitohy if (ACPI_FAILURE(rv)) 1001.1Sitohy return; 1011.1Sitohy 1021.1Sitohy /* 1031.1Sitohy * sc_sb_ioh @ 0 1041.1Sitohy * sc_ioh @ 1 1051.1Sitohy * sc_opl_ioh @ 2 1061.1Sitohy * sc_mpu_ioh @ 3 1071.1Sitohy * sc_controlioh @ 4 1081.1Sitohy */ 1091.1Sitohy 1101.1Sitohy /* Find and map our i/o registers */ 1111.1Sitohy sc->sc_iot = aa->aa_iot; 1121.1Sitohy sb_io = acpi_res_io(&res, 0); 1131.1Sitohy codec_io = acpi_res_io(&res, 1); 1141.1Sitohy opl_io = acpi_res_io(&res, 2); 1151.1Sitohy#if NMPU_YM > 0 1161.1Sitohy mpu_io = acpi_res_io(&res, 3); 1171.1Sitohy#endif 1181.1Sitohy control_io = acpi_res_io(&res, 4); 1191.1Sitohy 1201.1Sitohy if (sb_io == NULL || codec_io == NULL || opl_io == NULL || 1211.1Sitohy#if NMPU_YM > 0 1221.1Sitohy mpu_io == NULL || 1231.1Sitohy#endif 1241.1Sitohy control_io == NULL) { 1251.1Sitohy aprint_error("%s: unable to find i/o registers resource\n", 1261.1Sitohy self->dv_xname); 1271.1Sitohy goto out; 1281.1Sitohy } 1291.1Sitohy if (bus_space_map(sc->sc_iot, sb_io->ar_base, sb_io->ar_length, 1301.1Sitohy 0, &sc->sc_sb_ioh) != 0) { 1311.1Sitohy aprint_error("%s: unable to map i/o registers (sb)\n", 1321.1Sitohy self->dv_xname); 1331.1Sitohy goto out; 1341.1Sitohy } 1351.1Sitohy if (bus_space_map(sc->sc_iot, codec_io->ar_base, codec_io->ar_length, 1361.1Sitohy 0, &sc->sc_ioh) != 0) { 1371.1Sitohy aprint_error("%s: unable to map i/o registers (codec)\n", 1381.1Sitohy self->dv_xname); 1391.1Sitohy goto out; 1401.1Sitohy } 1411.1Sitohy if (bus_space_map(sc->sc_iot, opl_io->ar_base, opl_io->ar_length, 1421.1Sitohy 0, &sc->sc_opl_ioh) != 0) { 1431.1Sitohy aprint_error("%s: unable to map i/o registers (opl)\n", 1441.1Sitohy self->dv_xname); 1451.1Sitohy goto out; 1461.1Sitohy } 1471.1Sitohy#if NMPU_YM > 0 1481.1Sitohy if (bus_space_map(sc->sc_iot, mpu_io->ar_base, mpu_io->ar_length, 1491.1Sitohy 0, &sc->sc_mpu_ioh) != 0) { 1501.1Sitohy aprint_error("%s: unable to map i/o registers (mpu)\n", 1511.1Sitohy self->dv_xname); 1521.1Sitohy goto out; 1531.1Sitohy } 1541.1Sitohy#endif 1551.1Sitohy if (bus_space_map(sc->sc_iot, control_io->ar_base, 1561.1Sitohy control_io->ar_length, 0, &sc->sc_controlioh) != 0) { 1571.1Sitohy aprint_error("%s: unable to map i/o registers (control)\n", 1581.1Sitohy self->dv_xname); 1591.1Sitohy goto out; 1601.1Sitohy } 1611.1Sitohy 1621.1Sitohy sc->sc_ic = aa->aa_ic; 1631.1Sitohy 1641.1Sitohy /* Find our IRQ */ 1651.1Sitohy irq = acpi_res_irq(&res, 0); 1661.1Sitohy if (irq == NULL) { 1671.1Sitohy aprint_error("%s: unable to find irq resource\n", 1681.1Sitohy self->dv_xname); 1691.1Sitohy /* XXX bus_space_unmap */ 1701.1Sitohy goto out; 1711.1Sitohy } 1721.1Sitohy sc->ym_irq = irq->ar_irq; 1731.1Sitohy 1741.1Sitohy /* Find our playback and record DRQs */ 1751.1Sitohy playdrq = acpi_res_drq(&res, 0); 1761.1Sitohy recdrq = acpi_res_drq(&res, 1); 1771.1Sitohy if (playdrq == NULL) { 1781.1Sitohy aprint_error("%s: unable to find drq resources\n", 1791.1Sitohy self->dv_xname); 1801.1Sitohy /* XXX bus_space_unmap */ 1811.1Sitohy goto out; 1821.1Sitohy } 1831.1Sitohy if (recdrq == NULL) { 1841.1Sitohy /* half-duplex mode */ 1851.1Sitohy sc->ym_recdrq = sc->ym_playdrq = playdrq->ar_drq; 1861.1Sitohy } else { 1871.1Sitohy sc->ym_playdrq = playdrq->ar_drq; 1881.1Sitohy sc->ym_recdrq = recdrq->ar_drq; 1891.1Sitohy } 1901.1Sitohy 1911.1Sitohy ac->sc_iot = sc->sc_iot; 1921.1Sitohy if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, 1931.1Sitohy AD1848_NPORT, &ac->sc_ioh)) { 1941.1Sitohy aprint_error("%s: bus_space_subregion failed\n", 1951.1Sitohy self->dv_xname); 1961.1Sitohy /* XXX cleanup */ 1971.1Sitohy goto out; 1981.1Sitohy } 1991.1Sitohy 2001.1Sitohy aprint_normal("%s", self->dv_xname); 2011.1Sitohy 2021.1Sitohy ac->mode = 2; 2031.1Sitohy ac->MCE_bit = MODE_CHANGE_ENABLE; 2041.1Sitohy 2051.1Sitohy sc->sc_ad1848.sc_ic = sc->sc_ic; 2061.1Sitohy 2071.1Sitohy /* Attach our ym device */ 2081.1Sitohy ym_attach(sc); 2091.1Sitohy 2101.1Sitohy out: 2111.1Sitohy acpi_resource_cleanup(&res); 2121.1Sitohy} 213