Subject: kern/33991: patch for ym @ acpi
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <jasper@pointless.net>
List: netbsd-bugs
Date: 07/13/2006 13:00:01
>Number:         33991
>Category:       kern
>Synopsis:       Patch for ym @ acpi
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul 13 13:00:00 +0000 2006
>Originator:     jasper@pointless.net
>Release:        NetBSD 3.99.21
>Organization:
-- 
[http://pointless.net/]                                   [0x2ECA0975]
>Environment:
System: NetBSD jellycat 3.0.0_STABLE NetBSD 3.0.0_STABLE (JELLYCAT) #2: Fri Mar 31 20:45:08 BST 2006 jasper@meep-meep:/usr/obj/sys/arch/i386/compile/JELLYCAT i386
Architecture: i386
Machine: i386
>Description:
	There's no ym attachment @ acpi
>How-To-Repeat:
	try to run an acpi kernel on a toughbook CF-71
>Fix:
	see attached patch - the ym_acpi.c was hacked up from a copy
of wss_acpi.c and ym_pnpbios.c, playing mp3's works at least.

Index: files.acpi
===================================================================
RCS file: /cvsroot/src/sys/dev/acpi/files.acpi,v
retrieving revision 1.38
diff -u -r1.38 files.acpi
--- files.acpi	8 Jul 2006 20:23:53 -0000	1.38
+++ files.acpi	12 Jul 2006 23:59:42 -0000
@@ -88,3 +88,7 @@
 # AT Timer
 attach	attimer at acpi with attimer_acpi
 file	dev/acpi/attimer_acpi.c		attimer_acpi
+
+# NeoMagic 256AV audio ym flavour
+attach	ym at acpi with ym_acpi
+file	dev/acpi/ym_acpi.c		ym_acpi


Index: ym_acpi.c
===================================================================
diff -u ym_acpi.c
--- /dev/null	12 Jul 2006 23:59:42 -0000
+++ ym_acpi.c	12 Jul 2006 23:59:42 -0000
@@ -0,0 +1,221 @0
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 2006 Jasper Wallace <jasper@pointless.net>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Derived from wss_acpi.c 1.15:
+ * 	Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca>
+ *
+ * and ym_pnpbios.c 1.11:
+ *	Copyright (c) 1999
+ *	Matthias Drochner.  All rights reserved.
+ *	Soren S. Jorvang.  All rights reserved.
+ * 
+ */
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD$");
+
+#include "mpu_ym.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/ioctl.h>
+#include <sys/syslog.h>
+#include <sys/device.h>
+#include <sys/proc.h>
+
+#include <machine/bus.h>
+
+#include <sys/audioio.h>
+#include <dev/audio_if.h>
+
+#include <dev/isa/isavar.h>
+#include <dev/isa/isadmavar.h>
+
+#include <dev/acpi/acpica.h>
+#include <dev/acpi/acpireg.h>
+#include <dev/acpi/acpivar.h>
+
+#include <dev/ic/ad1848reg.h> 
+#include <dev/isa/ad1848var.h>
+
+#include <dev/ic/cs4231reg.h>
+#include <dev/isa/cs4231var.h>
+
+#include <dev/ic/opl3sa3reg.h>
+#include <dev/isa/wssreg.h>
+#include <dev/isa/ymvar.h>
+
+
+static int	ym_acpi_match(struct device *, struct cfdata *, void *);
+static void	ym_acpi_attach(struct device *, struct device *, void *);
+
+CFATTACH_DECL(ym_acpi, sizeof(struct ym_softc), ym_acpi_match,
+    ym_acpi_attach, NULL, NULL);
+
+/*
+ * ym_acpi_match: autoconf(9) match routine
+ */
+static int
+ym_acpi_match(struct device *parent, struct cfdata *match, void *aux)
+{
+	struct acpi_attach_args *aa = aux;
+
+	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+		return 0;
+	/* According to dmidecode the on board audio is a "Yamaha 715E" */
+	if (strcmp("YMH0021", aa->aa_node->ad_devinfo->HardwareId.Value))
+		return 0;
+
+	return 1;
+}
+
+/*
+ * ym_acpi_attach: autoconf(9) attach routine
+ */
+static void
+ym_acpi_attach(struct device *parent, struct device *self, void *aux)
+{
+	struct ym_softc *sc = (struct ym_softc *)self;
+	struct acpi_attach_args *aa = aux;
+	struct acpi_resources res;
+	struct acpi_io *sb_io, *io_io, *opl_io, *control_io;
+#if NMPU_YM > 0
+	struct acpi_io *mpu_io;
+#endif
+	struct acpi_irq *irq;
+	struct acpi_drq *playdrq, *recdrq;
+	struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
+	ACPI_STATUS rv;
+
+	aprint_naive(": Yamaha 715E audio\n");
+	aprint_normal(": Yamaha 715E audio\n");
+
+	/* Parse our resources */
+	rv = acpi_resource_parse(&sc->sc_ad1848.sc_ad1848.sc_dev,
+	    aa->aa_node->ad_handle, "_CRS", &res,
+	    &acpi_resource_parse_ops_default);
+	if (ACPI_FAILURE(rv))
+		return;
+
+	/*
+	 * sc_sb_ioh 	 @ 0
+	 * sc_ioh	 @ 1
+	 * sc_opl_ioh	 @ 2
+	 * sc_mpu_ioh	 @ 3
+	 * sc_controlioh @ 4
+	 */
+
+	/* Find and map our i/o registers */
+	sc->sc_iot = aa->aa_iot;
+	sb_io 	= acpi_res_io(&res, 0);
+	io_io 	= acpi_res_io(&res, 1);
+	opl_io 	= acpi_res_io(&res, 2);
+#if NMPU_YM > 0
+	mpu_io 	= acpi_res_io(&res, 3);
+#endif
+	control_io = acpi_res_io(&res, 4);
+
+	if (sb_io == NULL || io_io == NULL || opl_io == NULL || control_io == NULL) {
+		aprint_error("%s: unable to find i/o registers resource\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		goto out;
+	}
+	if (bus_space_map(sc->sc_iot, sb_io->ar_base, sb_io->ar_length,
+	    0, &sc->sc_sb_ioh) != 0) {
+		aprint_error("%s: unable to map i/o registers (sb)\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		goto out;
+	}
+	if (bus_space_map(sc->sc_iot, io_io->ar_base, io_io->ar_length,
+	    0, &sc->sc_ioh) != 0) {
+		aprint_error("%s: unable to map i/o registers (io)\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		goto out;
+	}
+#if NMPU_YM > 0
+	if (bus_space_map(sc->sc_iot, mpu_io->ar_base, mpu_io->ar_length,
+	    0, &sc->sc_mpu_ioh) != 0) {
+		aprint_error("%s: unable to map i/o registers (mpu)\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		goto out;
+	}
+#endif
+	if (bus_space_map(sc->sc_iot, control_io->ar_base, control_io->ar_length,
+	    0, &sc->sc_controlioh) != 0) {
+		aprint_error("%s: unable to map i/o registers (control)\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		goto out;
+	}
+
+	sc->sc_ic = aa->aa_ic;
+
+	/* Find our IRQ */
+	irq = acpi_res_irq(&res, 0);
+	if (irq == NULL) {
+		aprint_error("%s: unable to find irq resource\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		/* XXX bus_space_unmap */
+		goto out;
+	}
+	sc->ym_irq = irq->ar_irq;
+
+	/* Find our playback and record DRQs */
+	/* XXX mine just has one drq ?!?! */
+	playdrq = acpi_res_drq(&res, 0);
+	recdrq = acpi_res_drq(&res, 1);
+	if (playdrq == NULL) {
+		aprint_error("%s: unable to find drq resources\n",
+		    sc->sc_ad1848.sc_ad1848.sc_dev.dv_xname);
+		/* XXX bus_space_unmap */
+		goto out;
+	}
+	if (recdrq == NULL) {
+		sc->ym_recdrq = sc->ym_playdrq = playdrq->ar_drq;
+	} else {
+		sc->ym_playdrq = playdrq->ar_drq;
+		sc->ym_recdrq = recdrq->ar_drq;
+	}
+
+	ac->sc_iot = sc->sc_iot;
+	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, AD1848_NPORT,
+	    &ac->sc_ioh)) {
+	    aprint_error("%s: bus_space_subregion failed\n", self->dv_xname);
+	    goto out;
+	}
+	
+	ac->mode = 2;
+	ac->MCE_bit = MODE_CHANGE_ENABLE;
+	
+	sc->sc_ad1848.sc_ic = sc->sc_ic;
+
+	/* Attach our ym device */
+	ym_attach(sc);
+
+ out:
+	acpi_resource_cleanup(&res);
+}
+