Subject: kern/5722: ym driver lacks an isa attachment
To: None <gnats-bugs@gnats.netbsd.org>
From: Daniel Carosone <dan@geek.com.au>
List: netbsd-bugs
Date: 07/08/1998 20:47:27
>Number:         5722
>Category:       kern
>Synopsis:       add a (minimal) isa attachment for the ym driver
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Jul  8 03:50:00 1998
>Last-Modified:
>Originator:     Daniel Carosone
>Organization:
Evil Geniuses for a Better Tomorrow.
>Release:        Jun 22, 1998
>Environment:
	
System: NetBSD noisy 1.3F NetBSD 1.3F (_noisy_) #24: Wed Jul 8 20:16:53 EST 1998 dan@noisy:/usr/src/sys/arch/i386/compile/_noisy_ i386


>Description:

My toshiba laptop, for reasons unknown, fails to probe the isapnp
"bus" and/or the Yamaha OPL3 chip via PnP, leaving me without useful
audio.  This could be because of something strange in the machine, or
some unknown bug in the isapnp routines.

The addresses of the card's registers, IRQ, DRQs, etc are all
configurable from the BIOS setup screen of this machine, so I decided
to bypass the PnP issues and create a direct isa attachment for this
driver.

XXX: There are some issues with this attachment, use it only if the
PnP version is not working for you. Issues include:
 * I have no docs for the chip, so I was unable to create a useful
   match routine to probe for its presence.  The ym_isa_match()
   function in this patch basically assumes the chip is there and
   returns a match, therefore only configure "ym0 at isa? .." if
   you're sure you actually have one. 
 * Similarly, it has no smarts for wildcard matching, so configure
   everything hardwired in your config file.
 * There is a second control IO port at another address, given by
   YM_ISA_CONTROLIO in dev/isa/ymvar.h -- override if you need to,
   there's no nice way to pass this through from config.
 * This attachment does not block out the ports used for the SBPro
   emulation mode of the OPL3, therefore I'd advise against having an
   sb driver configured in the same kernel if you're going to use "ym0
   at isa? .." because the sb driver may well find an SBPro on the
   same chip.  I haven't bothered trying this.
 * I get slightly odd behaviour when playing mp3 files with mpg123
   from pkgsrc - the driver seems to be looping on an empty buffer,
   clicking 2-3 times a second, from the time that the program opens
   the audio device until the time it starts feeding real audio data.
   This may be a bug in the main ym or ad1848 driver or even in
   mpg123, does anyone else get this?
 * For reasons unknown, amp (also from pkgsrc) fails to configure the
   audio parameters for this driver to its satisfaction, and doesn't
   work. Again, I doubt this is due to the isa attachment, but I have
   no other reference.

In my kernel config, I attach the device as follows:

ym0     at isa? port 0x530 irq 5 drq 1 drq2 0   # Yamaha OPL3-SA3 audio


>How-To-Repeat:
	try to use the "ym? at isapnp?" attachment and fail for unknown reasons
>Fix:

The following patch contributes (minimal) attachment code for "ym0 at isa? .."

*** files.isa~	Sat Jun  6 21:20:15 1998
--- files.isa	Wed Jul  8 17:58:40 1998
***************
*** 282,287 ****
--- 282,290 ----
  device	ym: audio, isadma, ad1848, auconv
  file	dev/isa/ym.c			ym needs-flag
  
+ attach	ym at isa with ym_isa
+ file	dev/isa/ym_isa.c		ym_isa needs-flag
+ 
  # Gravis UltraSound & UltraSound MAX.
  # Use the "flags" keyword in a config file to specify an extra DMA
  # channel for full-duplex operation. 
*** ymvar.h~	Thu May 21 21:12:19 1998
--- ymvar.h	Wed Jul  8 19:39:06 1998
***************
*** 70,75 ****
--- 70,83 ----
  #define YM_MONITOR_CLASS        21
  
  
+ /* 
+  * XXX Hardwired location for control register - used only in ISA
+  * attachment, until a better way is found.
+  */
+ #ifndef YM_ISA_CONTROLIO
+ #define YM_ISA_CONTROLIO	0x370
+ #endif
+ 
  struct ym_softc {
  	struct	device sc_dev;		/* base device */
  	struct	isadev sc_id;		/* ISA device */
*** /dev/null	Wed Jul  8 20:18:57 1998
--- ym_isa.c	Wed Jul  8 20:16:08 1998
***************
*** 0 ****
--- 1,155 ----
+ /* $NetBSD$ */
+ /* From: NetBSD: ym_isapnp.c,v 1.3 1998/06/09 00:05:20 thorpej Exp */
+ 
+ 
+ /*
+  * Copyright (c) 1991-1993 Regents of the University of California.
+  * 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. Redistributions in binary form must reproduce the above copyright
+  *    notice, this list of conditions and the following disclaimer in the
+  *    documentation and/or other materials provided with the distribution.
+  * 3. All advertising materials mentioning features or use of this software
+  *    must display the following acknowledgement:
+  *	This product includes software developed by the Computer Systems
+  *	Engineering Group at Lawrence Berkeley Laboratory.
+  * 4. Neither the name of the University nor of the Laboratory may be used
+  *    to endorse or promote products derived from this software without
+  *    specific prior written permission.
+  *
+  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
+  *
+  */
+ 
+ /*
+  *  Driver for the Yamaha OPL3-SA3 chipset. This is found on many laptops
+  *  and Pentium (II) motherboards.
+  *
+  *  Original code from OpenBSD.
+  */
+ 
+ /*
+  * ISA ym attachment for NetBSD
+  * Daniel Carosone, dan@geek.com.au, 1997-06-08
+  *
+  */
+ 
+ #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 <sys/audioio.h>
+ #include <dev/audio_if.h>
+ 
+ #include <dev/isa/isavar.h>
+ #include <dev/isa/isadmavar.h>
+ 
+ #include <dev/ic/ad1848reg.h>
+ #include <dev/isa/ad1848var.h>
+ 
+ #include <dev/ic/cs4231reg.h>
+ #include <dev/isa/cs4231var.h>
+ 
+ #include <dev/isa/wssreg.h>
+ #include <dev/isa/ymvar.h>
+ 
+ int	ym_isa_match __P((struct device *, struct cfdata *, void *));
+ void	ym_isa_attach __P((struct device *, struct device *, void *));
+ 
+ struct cfattach ym_isa_ca = {
+ 	sizeof(struct ym_softc), ym_isa_match, ym_isa_attach
+ };
+ 
+ 
+ /*
+  * Probe / attach routines.
+  */
+ 
+ /*
+  * Probe for the Yamaha hardware.
+  */
+ int
+ ym_isa_match(parent, match, aux)
+ 	struct device *parent;
+ 	struct cfdata *match;
+ 	void *aux;
+ {
+         struct isa_attach_args *ia = aux; 
+  
+         /* XXX Cheat and assume it's there, for testing.  Need docs to
+ 	 *     find a better probe. Could use the WSS one, at least.
+ 	 */
+ 
+ 	ia->ia_iosize = WSS_NPORT;
+ 	return 1;
+ }
+ 
+ /*
+  * Attach hardware to driver, attach hardware driver to audio
+  * pseudo-device driver.
+  */
+ void
+ ym_isa_attach(parent, self, aux)
+ 	struct device *parent, *self;
+ 	void *aux;
+ {
+ 	struct ym_softc *sc = (struct ym_softc *)self;
+ 	struct isa_attach_args *ia = aux;
+ 
+ 	/* printf("\n"); */
+ 
+ 	sc->sc_iot = ia->ia_iot;
+ 	sc->sc_ic = ia->ia_ic;
+ 
+         if (bus_space_map(sc->sc_iot, ia->ia_iobase, WSS_NPORT, 0,
+ 			  &sc->sc_ioh)) {
+                 printf("ym: can't map i/o space 0x%x/%d in probe\n",
+                     ia->ia_iobase, WSS_NPORT);
+                 return;
+         }
+ 
+ 	sc->ym_irq = ia->ia_irq;
+ 	sc->ym_drq = ia->ia_drq;
+ 	sc->ym_recdrq = ia->ia_drq2;
+ 	
+ 	if (bus_space_map(sc->sc_iot, YM_ISA_CONTROLIO, 1, 0,
+ 			  &sc->sc_controlioh)) {
+                 printf("ym: can't map i/o space 0x%x/%d in probe\n",
+                     YM_ISA_CONTROLIO, 1);
+                 return;
+         }
+ 	sc->sc_ad1848.sc_ic  = sc->sc_ic;
+ 	sc->sc_ad1848.sc_iot = sc->sc_iot;
+ 	sc->sc_ad1848.sc_ioh = sc->sc_ioh;
+ 	sc->sc_ad1848.sc_iooffs = WSS_CODEC;
+ 	sc->sc_ad1848.mode = 2;
+ 	sc->sc_ad1848.MCE_bit = MODE_CHANGE_ENABLE;
+ 	sc->sc_ad1848.chip_name = "OPL3-SA3";
+ 
+ 	/*	
+ 	 * printf("%s: %s %s", sc->sc_dev.dv_xname, ipa->ipa_devident,
+          *	ipa->ipa_devclass);
+ 	 */
+ 
+ 	ym_attach(sc);
+ }
+ 


>Audit-Trail:
>Unformatted: