ym_acpi.c revision 1.14
11.14Stsutsui/* $NetBSD: ym_acpi.c,v 1.14 2011/06/02 14:12:25 tsutsui 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.14Stsutsui__KERNEL_RCSID(0, "$NetBSD: ym_acpi.c,v 1.14 2011/06/02 14:12:25 tsutsui Exp $"); 331.1Sitohy 341.1Sitohy#include <sys/param.h> 351.11Sjruoho#include <sys/systm.h> 361.1Sitohy 371.1Sitohy#include <dev/acpi/acpivar.h> 381.1Sitohy 391.1Sitohy#include <dev/audio_if.h> 401.1Sitohy 411.1Sitohy#include <dev/ic/ad1848reg.h> 421.11Sjruoho#include <dev/ic/opl3sa3reg.h> 431.11Sjruoho 441.1Sitohy#include <dev/isa/ad1848var.h> 451.1Sitohy#include <dev/isa/wssreg.h> 461.1Sitohy#include <dev/isa/ymvar.h> 471.1Sitohy 481.1Sitohy 491.8Sceggerstatic int ym_acpi_match(device_t, cfdata_t, void *); 501.8Sceggerstatic void ym_acpi_attach(device_t, device_t, void *); 511.1Sitohy 521.14StsutsuiCFATTACH_DECL_NEW(ym_acpi, sizeof(struct ym_softc), ym_acpi_match, 531.1Sitohy ym_acpi_attach, NULL, NULL); 541.1Sitohy 551.1Sitohy/* 561.1Sitohy * ym_acpi_match: autoconf(9) match routine 571.1Sitohy */ 581.1Sitohystatic int 591.8Sceggerym_acpi_match(device_t parent, cfdata_t match, void *aux) 601.1Sitohy{ 611.1Sitohy struct acpi_attach_args *aa = aux; 621.1Sitohy 631.1Sitohy if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 641.1Sitohy return 0; 651.12Sgsutre if (!(aa->aa_node->ad_devinfo->Valid & ACPI_VALID_HID)) 661.12Sgsutre return 0; 671.10Sjmcneill if (!aa->aa_node->ad_devinfo->HardwareId.String) 681.10Sjmcneill return 0; 691.1Sitohy /* Yamaha OPL3-SA2 or OPL3-SA3 */ 701.9Sjmcneill if (strcmp("YMH0021", aa->aa_node->ad_devinfo->HardwareId.String)) 711.1Sitohy return 0; 721.1Sitohy 731.1Sitohy return 1; 741.1Sitohy} 751.1Sitohy 761.1Sitohy/* 771.1Sitohy * ym_acpi_attach: autoconf(9) attach routine 781.1Sitohy */ 791.1Sitohystatic void 801.8Sceggerym_acpi_attach(device_t parent, device_t self, void *aux) 811.1Sitohy{ 821.14Stsutsui struct ym_softc *sc = device_private(self); 831.1Sitohy struct acpi_attach_args *aa = aux; 841.1Sitohy struct acpi_resources res; 851.1Sitohy struct acpi_io *sb_io, *codec_io, *opl_io, *control_io; 861.1Sitohy#if NMPU_YM > 0 871.1Sitohy struct acpi_io *mpu_io; 881.1Sitohy#endif 891.1Sitohy struct acpi_irq *irq; 901.1Sitohy struct acpi_drq *playdrq, *recdrq; 911.1Sitohy struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848; 921.1Sitohy ACPI_STATUS rv; 931.1Sitohy 941.14Stsutsui ac->sc_dev = self; 951.1Sitohy /* Parse our resources */ 961.14Stsutsui rv = acpi_resource_parse(self, 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.5Scegger aprint_error_dev(self, "unable to find i/o registers resource\n"); 1261.1Sitohy goto out; 1271.1Sitohy } 1281.1Sitohy if (bus_space_map(sc->sc_iot, sb_io->ar_base, sb_io->ar_length, 1291.1Sitohy 0, &sc->sc_sb_ioh) != 0) { 1301.5Scegger aprint_error_dev(self, "unable to map i/o registers (sb)\n"); 1311.1Sitohy goto out; 1321.1Sitohy } 1331.1Sitohy if (bus_space_map(sc->sc_iot, codec_io->ar_base, codec_io->ar_length, 1341.1Sitohy 0, &sc->sc_ioh) != 0) { 1351.5Scegger aprint_error_dev(self, "unable to map i/o registers (codec)\n"); 1361.1Sitohy goto out; 1371.1Sitohy } 1381.1Sitohy if (bus_space_map(sc->sc_iot, opl_io->ar_base, opl_io->ar_length, 1391.1Sitohy 0, &sc->sc_opl_ioh) != 0) { 1401.5Scegger aprint_error_dev(self, "unable to map i/o registers (opl)\n"); 1411.1Sitohy goto out; 1421.1Sitohy } 1431.1Sitohy#if NMPU_YM > 0 1441.1Sitohy if (bus_space_map(sc->sc_iot, mpu_io->ar_base, mpu_io->ar_length, 1451.1Sitohy 0, &sc->sc_mpu_ioh) != 0) { 1461.5Scegger aprint_error_dev(self, "unable to map i/o registers (mpu)\n"); 1471.1Sitohy goto out; 1481.1Sitohy } 1491.1Sitohy#endif 1501.1Sitohy if (bus_space_map(sc->sc_iot, control_io->ar_base, 1511.1Sitohy control_io->ar_length, 0, &sc->sc_controlioh) != 0) { 1521.5Scegger aprint_error_dev(self, "unable to map i/o registers (control)\n"); 1531.1Sitohy goto out; 1541.1Sitohy } 1551.1Sitohy 1561.1Sitohy sc->sc_ic = aa->aa_ic; 1571.1Sitohy 1581.1Sitohy /* Find our IRQ */ 1591.1Sitohy irq = acpi_res_irq(&res, 0); 1601.1Sitohy if (irq == NULL) { 1611.5Scegger aprint_error_dev(self, "unable to find irq resource\n"); 1621.1Sitohy /* XXX bus_space_unmap */ 1631.1Sitohy goto out; 1641.1Sitohy } 1651.1Sitohy sc->ym_irq = irq->ar_irq; 1661.1Sitohy 1671.1Sitohy /* Find our playback and record DRQs */ 1681.1Sitohy playdrq = acpi_res_drq(&res, 0); 1691.1Sitohy recdrq = acpi_res_drq(&res, 1); 1701.1Sitohy if (playdrq == NULL) { 1711.5Scegger aprint_error_dev(self, "unable to find drq resources\n"); 1721.1Sitohy /* XXX bus_space_unmap */ 1731.1Sitohy goto out; 1741.1Sitohy } 1751.1Sitohy if (recdrq == NULL) { 1761.1Sitohy /* half-duplex mode */ 1771.1Sitohy sc->ym_recdrq = sc->ym_playdrq = playdrq->ar_drq; 1781.1Sitohy } else { 1791.1Sitohy sc->ym_playdrq = playdrq->ar_drq; 1801.1Sitohy sc->ym_recdrq = recdrq->ar_drq; 1811.1Sitohy } 1821.1Sitohy 1831.1Sitohy ac->sc_iot = sc->sc_iot; 1841.1Sitohy if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, 1851.1Sitohy AD1848_NPORT, &ac->sc_ioh)) { 1861.5Scegger aprint_error_dev(self, "bus_space_subregion failed\n"); 1871.1Sitohy /* XXX cleanup */ 1881.1Sitohy goto out; 1891.1Sitohy } 1901.1Sitohy 1911.5Scegger aprint_normal_dev(self, ""); 1921.1Sitohy 1931.1Sitohy ac->mode = 2; 1941.1Sitohy ac->MCE_bit = MODE_CHANGE_ENABLE; 1951.1Sitohy 1961.1Sitohy sc->sc_ad1848.sc_ic = sc->sc_ic; 1971.1Sitohy 1981.1Sitohy /* Attach our ym device */ 1991.1Sitohy ym_attach(sc); 2001.1Sitohy 2011.1Sitohy out: 2021.1Sitohy acpi_resource_cleanup(&res); 2031.1Sitohy} 204