Configuring ALSA to drive the OPL3-SA2

The Yamaha OPL3-SA2 was a popular ISA sound card in desktop machines about 2 years ago and is also found in many laptop machines (such as the Toshiba Tecra 780). There are two distinct flavours of the card; the version found in deskotp machines is generally a pnp card, while that in the laptops is configured from the BIOS setup.

As I have had experience with both varieties, I will describe the procedure for setting up ALSA to drive them. The description here relates to ALSA 0.4.1x. I don't believe anything here is distribution specific, but the desktop machine has SuSE 6.1 while the laptop has SuSE 6.2.
WARNING -- This material applies to version 0.4.x of ALSA, I'll update it for the Laptop when I get around to upgrading it. I no longer have the OPL3-SA2 in a desktop.

Compiling ALSA

ALSA is actually pretty simple to compile, however you do need to have the kernel sources (or at least the include files) available.

You need to download the drivers, libraries and utils packages from the ALSA ftp site. The unpack the tar files and build and install in the order: drivers, libraries, utils.

Driver

Compile the driver first. If you have only one sound card and know that it is an OPL3-SA2 then you can configure with:
./configure --with-cards=card-opl3sa2 --with-oss --with-sequencer
I only used the sequencer option on the desktop machine (not sure if it actually works or not). I wasn't able to persuade the built-in isapnp support to work on my machine so I decided to stick with isapnptools.

Then run (assuming you're not already running as root):

make
su -c 'make install'
su -c './snddevices'

Libraries

This should be a straightforward:
./configure
make
su -c 'make install'

Utils

Again a straight forward procedure of configure, compile and install.

This provides several mixers: amixer, gamix, alsamixer and xmixer2; a command line player aplay and an advanced control tool alsactl (I've never used it so I don't really know what it does).

Configuring

On both machines I define the modules in /etc/conf.modules, and set up the mixer settings from /sbin/init.d/boot.local (on some systems this may be in /etc).

Card Initialization

PnP configuration

On the desktop machine, I initialise the card using isapnptools. The relevant part of my /etc/isapnp.conf is:
# $Id: pnpdump.c,v 1.18 1999/02/14 22:47:18 fox Exp $
# This is free software, see the sources for details.
# This software has NO WARRANTY, use at your OWN RISK
#
# For details of this file format, see isapnp.conf(5)
#
# For latest information and FAQ on isapnp and pnpdump see:
# http://www.roestock.demon.co.uk/isapnptools/
#
# Compiler flags: -DREALTIME -DNEEDSETSCHEDULER -DABORT_ONRESERR
#
# Trying port address 0203
# Board 1 has serial identifier 96 ff ff ff ff 01 08 a8 65

# (DEBUG)
(READPORT 0x0203)
(ISOLATE PRESERVE)
(IDENTIFY *)
(VERBOSITY 2)
(CONFLICT (IO FATAL)(IRQ FATAL)(DMA FATAL)(MEM FATAL)) # or WARNING

# Card 1: (serial identifier 96 ff ff ff ff 01 08 a8 65)
# Vendor Id YMH0801, No Serial Number (-1), checksum 0x96.
# Version 1.0, Vendor version 0.0
# ANSI string -->OPL3-SA2 Sound Board<--
#
# Logical device id YMH0021
#
# Edit the entries below to uncomment out the configuration required.
# Note that only the first value of any range is given, this may be changed if required
# Don't forget to uncomment the activate (ACT Y) when happy

(CONFIGURE YMH0801/-1 (LD 0

# Multiple choice time, choose one only !

#     Start dependent functions: priority preferred
#       Logical device decodes 16 bit IO address lines
#             Minimum IO base address 0x0220
#             Maximum IO base address 0x0220
#             IO base alignment 16 bytes
#             Number of IO addresses required: 16
  (IO 0 (SIZE 16) (BASE 0x0220))
#       Logical device decodes 16 bit IO address lines
#             Minimum IO base address 0x0530
#             Maximum IO base address 0x0530
#             IO base alignment 8 bytes
#             Number of IO addresses required: 8
  (IO 1 (SIZE 8) (BASE 0x0530))
#       Logical device decodes 16 bit IO address lines
#             Minimum IO base address 0x0388
#             Maximum IO base address 0x0388
#             IO base alignment 8 bytes
#             Number of IO addresses required: 8
  (IO 2 (SIZE 8) (BASE 0x0388))
#       Logical device decodes 16 bit IO address lines
#             Minimum IO base address 0x0330
#             Maximum IO base address 0x0330
#             IO base alignment 2 bytes
#             Number of IO addresses required: 2
  (IO 3 (SIZE 2) (BASE 0x0330))
#       Logical device decodes 16 bit IO address lines
#             Minimum IO base address 0x0370
#             Maximum IO base address 0x0370
#             IO base alignment 2 bytes
#             Number of IO addresses required: 2
  (IO 4 (SIZE 2) (BASE 0x0370))
#       IRQ 5.
#             High true, edge sensitive interrupt
  (INT 0 (IRQ 5 (MODE +E)))
#       First DMA channel 0.
#             8 bit DMA only
#             Logical device is not a bus master
#             DMA may execute in count by byte mode
#             DMA may not execute in count by word mode
#             DMA channel speed type F
  (DMA 0 (CHANNEL 0))
#       Next DMA channel 1.
#             8 bit DMA only
#             Logical device is not a bus master
#             DMA may execute in count by byte mode
#             DMA may not execute in count by word mode
#             DMA channel speed type F
  (DMA 1 (CHANNEL 1))

#     End dependent functions
 (NAME "YMH0801/-1[0]{OPL3-SA2 Sound Board}")
  (ACT Y)
))
#
# Logical device id YMH0022
#
# Edit the entries below to uncomment out the configuration required.
# Note that only the first value of any range is given, this may be changed if required
# Don't forget to uncomment the activate (ACT Y) when happy

(CONFIGURE YMH0801/-1 (LD 1
#     Compatible device id PNPb02f

# Multiple choice time, choose one only !

#     Start dependent functions: priority preferred
#       Logical device decodes 16 bit IO address lines
#             Minimum IO base address 0x0201
#             Maximum IO base address 0x0201
#             IO base alignment 1 bytes
#             Number of IO addresses required: 1
  (IO 0 (SIZE 1) (BASE 0x0201))

#     End dependent functions
 (NAME "YMH0801/-1[1]{OPL3-SA2 Sound Board}")
  (ACT Y)
))
# End tag... Checksum 0x00 (OK)

# Returns all cards to the "Wait for Key" state
(WAITFORKEY)

BIOS Setup

On the Tecra laptop, the initialization of the card is done by the BIOS, according to the paramters chosen in the BIOS menu (accessed by holding down the escape key on power up and the giving the supervisor password at the boot password prompt). I think the settings here are the defaults:

Modules

For both machines, I define the appropriate aliases for the modules and let the kernel's module loading handle the rest, I do not have any explicit modprobe. calls anywhere.

Desktop

alias char-major-116 snd
options snd snd_major=116 snd_cards_limit=1

alias char-major-14 soundcore

alias snd-card-0 snd-card-opl3sa2
options snd-card-opl3sa2 snd_index=1 snd_id="OPL3SA2" \
    snd_port=0x370 \	
    snd_wss_port=0x530 \
    snd_midi_port=-1 \
    snd_fm_port=0x388 \
    snd_irq=5 \
    snd_dma1=0 \
    snd_dma2=1

alias sound-slot-0 snd-card-0
alias sound-service-0-0 snd-mixer-oss 
alias sound-service-0-1 snd-seq-oss
alias sound-service-0-3 snd-pcm1-oss
alias sound-service-0-12 snd-pcm1-oss

Laptop

# ALSA Configuration.

alias char-major-116 snd
options snd snd_major=116 snd_cards_limit=1
alias char-major-14  soundcore

alias snd-card-0 snd-card-opl3sa2
options snd-card-opl3sa2 \
	snd_port=0x538 \
	snd_wss_port=0x530 \
	snd_midi_port=-1 \
	snd_fm_port=0x388 \
	snd_irq=5 \
	snd_dma1=1 \
	snd_dma2=0
	
alias sound-slot-0 snd-card-0

alias sound-service-0-0 snd-mixer-oss
alias sound-service-0-1  off
alias sound-service-0-3  snd-pcm1-oss
alias sound-service-0-12 snd-pcm1-oss

Mixer settings

Desktop

#!/bin/sh

# A reasonable set of ALSA mixer settings to start up with.
# We can always pick better ones for specific cases with the 
# GUI mixers

AMIX='/usr/bin/amixer -q'

$AMIX set Master 100% unmute
$AMIX set PCM 85% unmute
$AMIX set 'Input Gain' 40%
$AMIX set Line 40% unmute capture

Laptop

#!/bin/sh
	# Next set the mixer settings

/usr/bin/amixer -q set Master 90% unmute
/usr/bin/amixer -q set PCM 90% unmute
/usr/bin/amixer -q set Line 60% unmute capture
/usr/bin/amixer -q set CD  60% unmute
/usr/bin/amixer -q set 'Input Gain' 50%
/usr/bin/amixer -q set FM 60% unmute

	# Finally play something to show we're here

/usr/bin/aplay -q /usr/share/sounds/au/linus-english.au
N.B. It is not advisable to unmute the microphone on a Tecra 780 as the built-in microphone is very close to the built-in speaker and so if you half-close the lcd panel with an unmuted microphone, you'll get a horrible feedback loop [has the designer been fired yet? -- or merely made to listen to the results].

Mysteries

Mixer channels
There are substantially different settings available from the mixers on the 2 systems, more than can be explained by my having enabled sequencer on one and not the other. Since they are mostly (if not all) in the direction of extra features in the (more recent) laptop, this is probably just a consequence of additional features being added with time.
Digital Output
On both cards, the mixers list a digital output channel, however I don't know where this is physically located. Can anyone help.
The ALSA GUI mixer
This is the GUI mixer gamix for the Laptop. The wide-narrow control and the treble and bass are not present on the desktop machine.

Written: 29/10/99 by James Tappin, your comments, improvements etc. are welcome.